Skip to content

fix: parseFrontmatter型バリデーション + repetition共有util抽出#70

Merged
terisuke merged 2 commits intodevfrom
fix/pr56-remaining
Apr 5, 2026
Merged

fix: parseFrontmatter型バリデーション + repetition共有util抽出#70
terisuke merged 2 commits intodevfrom
fix/pr56-remaining

Conversation

@terisuke
Copy link
Copy Markdown

@terisuke terisuke commented Apr 5, 2026

What

PR #56 のレビュー残り2件を修正。

Why

  • parseFrontmatter() が invalid type を無検証でキャストしていた
  • repetition.test.ts が production コードを import せず独自実装していた

Closes #69

Changes

  1. memory/file.ts: Memory.TYPES に対するバリデーション追加
  2. session/repetition.ts: 新規共有util
  3. session/processor.ts: import に置換
  4. test 更新

Review

  • code-reviewer Agent: CRITICAL/HIGH 0
  • Codex CLI: No issues in PR A

Test plan

  • bun test test/memory/file.test.ts — 19 pass
  • bun test test/session/repetition.test.ts — 8 pass
  • typecheck 13/13 pass

terisuke and others added 2 commits April 5, 2026 19:28
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>
Copilot AI review requested due to automatic review settings April 5, 2026 10:47
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 5, 2026

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

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.

@terisuke terisuke merged commit 45d8de3 into dev Apr 5, 2026
5 of 9 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 unknown type values (based on Memory.TYPES).
  • Extract detectRepetition (+ constants) into src/session/repetition.ts and reuse it from SessionProcessor and tests.
  • Update/add tests to cover valid/invalid/missing memory type parsing 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.

Comment on lines +2 to +3
import { detectRepetition } from "../../src/session/repetition"
import { REPETITION_THRESHOLD, REPETITION_WINDOW } from "../../src/session/repetition"
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two imports come from the same module; consider combining them into a single import to reduce redundancy and keep imports easier to maintain.

Suggested change
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"

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: PR #56 残り — parseFrontmatter型バリデーション + repetition test重複

2 participants