fix: parseFrontmatter型バリデーション + repetition共有util抽出#70
Conversation
Move detectRepetition function and constants from processor.ts to a dedicated repetition.ts module. Test now imports production code instead of reimplementing the algorithm. Closes #69 (partial) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
parseFrontmatter() now checks fm.type is a valid Memory.Type value before casting. Invalid types return undefined instead of silently propagating through the system. Closes #69 (partial) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
There was a problem hiding this comment.
Pull request overview
This PR addresses remaining review items from PR #56 by adding runtime validation for user-editable memory frontmatter types and by extracting the repetition-detection logic into a shared production util that tests can import.
Changes:
- Add validation in
parseFrontmatter()to reject unknowntypevalues (based onMemory.TYPES). - Extract
detectRepetition(+ constants) intosrc/session/repetition.tsand reuse it fromSessionProcessorand tests. - Update/add tests to cover valid/invalid/missing memory
typeparsing and to import the shared repetition util.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/opencode/src/memory/file.ts | Validate frontmatter type against Memory.TYPES before casting. |
| packages/opencode/src/session/repetition.ts | New shared repetition-detection util + exported constants. |
| packages/opencode/src/session/processor.ts | Replace inlined repetition logic with imports from ./repetition. |
| packages/opencode/test/session/repetition.test.ts | Switch test to import production detectRepetition + constants. |
| packages/opencode/test/memory/file.test.ts | Add coverage for valid/invalid/missing frontmatter type. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { detectRepetition } from "../../src/session/repetition" | ||
| import { REPETITION_THRESHOLD, REPETITION_WINDOW } from "../../src/session/repetition" |
There was a problem hiding this comment.
These two imports come from the same module; consider combining them into a single import to reduce redundancy and keep imports easier to maintain.
| import { detectRepetition } from "../../src/session/repetition" | |
| import { REPETITION_THRESHOLD, REPETITION_WINDOW } from "../../src/session/repetition" | |
| import { detectRepetition, REPETITION_THRESHOLD, REPETITION_WINDOW } from "../../src/session/repetition" |
What
PR #56 のレビュー残り2件を修正。
Why
Closes #69
Changes
Review
Test plan