Skip to content

実装: agent-session-manifest-check テストが生成する temp fixture を afterAll で後始末する #559

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "agent-session-manifest-check テストが生成する temp fixture を後始末し、tests/fixtures/ 配下に untracked artifact を残さない"
change_kind: chore

Parent Issue

なし(単独改善 / PR #555 の post-merge-cleanup 観察由来の follow-up)

Parent Goal Ref

なし(standalone)。テスト実行が作業ツリーを汚さない状態を保つ test-hygiene 改善。

Current Validated Scope

  • tests/agent-session-manifest-check.test.ts が実行時に writeFileSync で生成する temp fixture(temp-unsupported.txt / temp-invalid-no-markers.md)を、テスト終了後に削除する後始末を追加する。
  • 後始末は原則として repo fixtures 配下の既知 temp path を cleanup する beforeAll + afterAll での rmSync(path, { force: true }) とする。os.tmpdir() 配下へ書く方式を採る場合でも、legacy repo fixture path(temp-unsupported.txt / temp-invalid-no-markers.md)を beforeAll または afterAll で rmSync(path, { force: true }) することを必須とする(AC2/AC3 は repo 配下 artifact の不在を要求するため、書き込み先を変えるだけでは既存 stale artifact が残る)。

Remaining Parent Gaps

なし。

Outcome

tests/agent-session-manifest-check.test.ts を pnpm test で実行した後に、tests/fixtures/agent-session-manifest/ 配下へ temp-unsupported.txt / temp-invalid-no-markers.md の untracked artifact が残らない状態でコミットされている(テストが自身の生成物を後始末する)。既存のテスト assertion(exit code・stderr メッセージ)は変更しない。

背景

PR #555(Issue #553, GitHub Actions の Node24 対応)の post-merge-cleanup で worktree 削除時に untracked file tests/fixtures/agent-session-manifest/temp-unsupported.txt が阻害要因となり、git worktree remove --force が必要になった。

原因は tests/agent-session-manifest-check.test.ts が以下の temp fixture を writeFileSync で生成するが、afterEach / afterAll での後始末が無いため、テスト実行のたびに作業ツリーへ untracked artifact が残ること:

  • L144-145: temp-invalid-no-markers.md
  • L153-154 / L162-163: temp-unsupported.txt(2 ケースで生成)

現状の import は writeFileSync, mkdirSync(fs)のみで、unlinkSync / rmSync は未使用。lifecycle hook は beforeAll のみ。

In Scope

  • tests/agent-session-manifest-check.test.ts に temp fixture の後始末処理を追加する(afterAll での削除、または os.tmpdir() 配下への書き込みへ変更)。
  • 対象 temp fixture: temp-unsupported.txt と temp-invalid-no-markers.md の両方。

Implementation Constraint

Preferred implementation:

  • Keep temp fixture paths under tests/fixtures/agent-session-manifest/.
  • Add a shared cleanupTempFixtures() helper.
  • Call it from both beforeAll and afterAll.
  • Use rmSync(path, { force: true }) for idempotent cleanup.

os.tmpdir() is allowed only if the implementation also removes the legacy repo fixture paths in beforeAll and afterAll:

  • tests/fixtures/agent-session-manifest/temp-unsupported.txt
  • tests/fixtures/agent-session-manifest/temp-invalid-no-markers.md

Rationale: AC2/AC3 are about absence of repo-local untracked artifacts after test execution. Moving future writes to OS temp does not by itself remove already-created repo-local artifacts.

Out of Scope

  • 既存テストの assertion(expect(result.exitCode).toBe(1)、stderr の unsupported file type / no supported manifest files / marker 判定)の変更。
  • 永続 fixture(valid-basic.json 等、writeFileSync で生成していない既存ファイル)の変更・削除。
  • src/ 配下の実装変更。
  • 他テストファイルの後始末追加(本 Issue は当該 1 ファイルに限定)。
  • 既に作業ツリーに残っている temp fixture の手動削除(テスト修正後の再実行で自然に解消するため別作業としない)。

Acceptance Criteria

  • AC1: tests/agent-session-manifest-check.test.ts に temp fixture を後始末する仕組み(afterAll / afterEach + rmSync / unlinkSync、または os.tmpdir() 利用)が追加されている。
  • AC2: pnpm test 実行後に tests/fixtures/agent-session-manifest/temp-unsupported.txt が存在しない。
  • AC3: pnpm test 実行後に tests/fixtures/agent-session-manifest/temp-invalid-no-markers.md が存在しない。
  • AC4: 既存の assertion 文字列(unsupported file type / no supported manifest files / marker)が当該テストファイルに保持されている。
  • AC5: pnpm test が PASS する(回帰なし)。

Verification Commands

# AC1
# preflight-scope: pr_review_only
$ rg -n 'afterAll|afterEach|onTestFinished|beforeAll' tests/agent-session-manifest-check.test.ts
$ rg -n 'rmSync.*temp-unsupported|rmSync.*temp-invalid|unlinkSync.*temp-unsupported|unlinkSync.*temp-invalid' tests/agent-session-manifest-check.test.ts
$ rg -n 'rmSync|unlinkSync' tests/agent-session-manifest-check.test.ts
# AC2
# preflight-scope: runtime_only
$ rm -f tests/fixtures/agent-session-manifest/temp-unsupported.txt
# preflight-scope: runtime_only
$ rm -f tests/fixtures/agent-session-manifest/temp-invalid-no-markers.md
# preflight-scope: runtime_only
$ pnpm test -- tests/agent-session-manifest-check.test.ts
# preflight-scope: runtime_only
$ test ! -f tests/fixtures/agent-session-manifest/temp-unsupported.txt
# AC3
# preflight-scope: runtime_only
$ test ! -f tests/fixtures/agent-session-manifest/temp-invalid-no-markers.md
# AC4
# preflight-scope: pr_review_only
$ rg -n 'unsupported file type|no supported manifest files|marker' tests/agent-session-manifest-check.test.ts
# AC5
# preflight-scope: runtime_only
$ pnpm test

Allowed Paths

  • tests/agent-session-manifest-check.test.ts

Stop Conditions

実装中にこれらの状況が発生したら直ちに作業を停止し、Issue comment に状況を記録して人間の判断を待つ。

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合

Runtime Verification Applicability

  • decision: not_applicable
  • reason: 変更対象は tests/agent-session-manifest-check.test.ts のみ。pnpm test(unit test)で AC1/AC4 の静的検証と AC5 の回帰確認が完結する。AC2/AC3 の artifact 不在確認は unit test 実行後のファイル存在チェックであり、プロセス起動・ネットワーク通信・外部サービス依存はない。

Required Skills

  • TypeScript / Vitest(lifecycle hook: afterAll/afterEach, fs unlink/rmSync)

Delivery Rule

  • 1 Issue = 1 PR。
  • worktree: .claude/worktrees/issue-<N>-<slug>、Draft PR 既定。

Source

dedupe_key: "test-hygiene:agent-session-manifest-check:temp-unsupported-txt"
source:
  kind: post_merge_cleanup
  origin_pr: "https://github.com/squne121/loop-protocol/pull/555"
  note_url: "https://github.com/squne121/loop-protocol/pull/555#issuecomment-4593107187"

Activity

  1. squne121 commented on Jun 1, 2026

    @squne121
    OwnerAuthor

    結論: Issue #559 は REQUEST_CHANGES 相当

    目的は妥当です。tests/agent-session-manifest-check.test.ts が temp-invalid-no-markers.md と temp-unsupported.txt を writeFileSync で作成し、現状は beforeAll だけで cleanup hook がない、という問題設定は実ファイルと整合しています。対象ファイルは現在 writeFileSync, mkdirSync のみを import し、Vitest hook も beforeAll のみです。([GitHub]1) 該当 temp fixture の生成箇所も確認できます。([GitHub]1)

    ただし、Issue 契約としては 実装経路に穴があります。このままだと AI 実装者が os.tmpdir() 方式を選んだ場合に AC2/AC3 を満たさない PR を出せます。

    Blocker 1: os.tmpdir() 方式を許可しているのに legacy path cleanup を要求していない

    Issue は cleanup 実装として、afterAll / try/finally による rmSync / unlinkSync、または os.tmpdir() 配下へ書く方式を許可しています。([GitHub]2) しかし AC2/AC3 は、tests/fixtures/agent-session-manifest/temp-unsupported.txt と temp-invalid-no-markers.md が pnpm test 後に存在しないことを要求しています。([GitHub]2)

    この組み合わせが危険です。os.tmpdir() へ新規生成先を移すだけの実装は、過去のテスト実行で既に repo fixtures 配下に残っている temp file を消しません。さらに Issue は「既に作業ツリーに残っている temp fixture の手動削除」を Out of Scope にしています。([GitHub]2) つまり、許可された実装経路の一つが AC2/AC3 を満たせない可能性があります。

    修正案:

    後始末方式は原則として repo fixtures 配下の既知 temp path を cleanup する `beforeAll + afterAll` とする。
    `os.tmpdir()` 方式を採用する場合でも、legacy path:
    - tests/fixtures/agent-session-manifest/temp-unsupported.txt
    - tests/fixtures/agent-session-manifest/temp-invalid-no-markers.md
    を `beforeAll` または `afterAll` で `rmSync(path, { force: true })` することを必須とする。

    Node の rmSync は force: true のとき対象が存在しない場合の例外を無視できるため、既知ファイルの冪等 cleanup に向いています。([nodejs.org]3) unlinkSync を使うなら、existsSync ガードまたは try/catch が必要です。

    Blocker 2: Verification Commands が順序依存を明示していない

    AC2/AC3 の検証コマンドは単に test ! -f ... です。([GitHub]2) これだけだと、pnpm test を実行していない状態でも pass します。逆に stale artifact が残っている場合、修正後テストを実行する前に fail します。検証として弱いです。

    修正案:

    rm -f tests/fixtures/agent-session-manifest/temp-unsupported.txt \
          tests/fixtures/agent-session-manifest/temp-invalid-no-markers.md
    
    pnpm test -- tests/agent-session-manifest-check.test.ts
    
    test ! -f tests/fixtures/agent-session-manifest/temp-unsupported.txt
    test ! -f tests/fixtures/agent-session-manifest/temp-invalid-no-markers.md

    pnpm test 全体は AC5 で別途維持してよいですが、cleanup の局所検証は対象テストファイルに絞ったほうが原因切り分けが明確です。

    Blocker 3: AC1 の grep が形式だけで、cleanup の実体を保証しない

    AC1 は afterAll|afterEach|rmSync|unlinkSync|tmpdir の grep です。([GitHub]2) これはコメントや import だけでも pass します。さらに tmpdir が出てくるだけで、legacy repo path を消しているかは判定できません。

    修正案:

    rg -n 'rmSync\(.*temp-unsupported\.txt|rmSync\(.*temp-invalid-no-markers\.md|unlinkSync\(.*temp-unsupported\.txt|unlinkSync\(.*temp-invalid-no-markers\.md' tests/agent-session-manifest-check.test.ts
    rg -n 'afterAll|afterEach|onTestFinished|beforeAll.*return' tests/agent-session-manifest-check.test.ts

    Vitest 公式は、afterAll は suite 内の全テスト後に一度実行される hook と説明しています。([vitest.dev]4) また、テスト内で生成したリソースには onTestFinished で作成箇所の近くに cleanup を登録するパターンも提示されています。([main.vitest.dev]5) 今回は対象ファイルが固定名なので beforeAll + afterAll が最小ですが、将来同種の temp fixture が増えるなら onTestFinished のほうが局所性は高いです。

    推奨実装方針

    Issue の意図に最も合うのは、os.tmpdir() 移行ではなく 既存 repo fixture path の固定 cleanup です。理由は、既存 test assertion と manifest checker の path 入力の性質を変えず、Allowed Paths も tests/agent-session-manifest-check.test.ts のみで済むためです。

    推奨パッチの形:

    import { writeFileSync, mkdirSync, rmSync } from 'fs'
    import { describe, expect, it, beforeAll, afterAll } from 'vitest'
    
    const TEMP_FIXTURE_PATHS = [
      resolve(FIXTURES_DIR, 'temp-invalid-no-markers.md'),
      resolve(FIXTURES_DIR, 'temp-unsupported.txt'),
    ]
    
    function cleanupTempFixtures(): void {
      for (const path of TEMP_FIXTURE_PATHS) {
        rmSync(path, { force: true })
      }
    }
    
    beforeAll(() => {
      mkdirSync(FIXTURES_DIR, { recursive: true })
      cleanupTempFixtures()
    })
    
    afterAll(() => {
      cleanupTempFixtures()
    })

    beforeAll も入れる理由は、PR #555 の post-merge cleanup で既に untracked artifact が観測されているためです。Issue #559 自体も、PR #555 / Issue #553 の post-merge-cleanup 観察由来だと明記しています。([GitHub]2) PR #555 側では CI は全 pass していたため、この問題は CI failure ではなく worktree hygiene の欠陥として扱うべきです。([GitHub]6)

    os.tmpdir() 方式を採る場合の条件

    os.tmpdir() は OS の default temp directory を返す API なので、repo 配下を汚さない設計には使えます。([nodejs.org]7) ただし固定ファイル名を単に temp directory に置くのではなく、mkdtempSync でテスト用一時ディレクトリを作るほうが安全です。Node は fs.mkdtempSync(prefix) が作成した directory path を返すと説明しています。([nodejs.org]3)

    ただし #559 では os.tmpdir() 移行は過剰です。manifest checker の明示 target path テストなので、path を変えるとテスト意図まで薄くなります。現 issue では rmSync(path, { force: true }) に寄せるべきです。

    Issue 本文への具体的修正案

    以下を追加・置換してください。

    ### Implementation Constraint
    
    Preferred implementation:
    - Keep temp fixture paths under `tests/fixtures/agent-session-manifest/`.
    - Add a shared `cleanupTempFixtures()` helper.
    - Call it from both `beforeAll` and `afterAll`.
    - Use `rmSync(path, { force: true })` for idempotent cleanup.
    
    `os.tmpdir()` is allowed only if the implementation also removes the legacy repo fixture paths:
    - `tests/fixtures/agent-session-manifest/temp-unsupported.txt`
    - `tests/fixtures/agent-session-manifest/temp-invalid-no-markers.md`
    
    Rationale: AC2/AC3 are about absence of repo-local untracked artifacts after test execution. Moving future writes to OS temp does not by itself remove already-created repo-local artifacts.

    Verification Commands は次に置換。

    # AC1: cleanup hook and exact temp paths are wired
    rg -n 'afterAll|afterEach|onTestFinished|beforeAll' tests/agent-session-manifest-check.test.ts
    rg -n 'temp-unsupported\.txt|temp-invalid-no-markers\.md' tests/agent-session-manifest-check.test.ts
    rg -n 'rmSync|unlinkSync' tests/agent-session-manifest-check.test.ts
    
    # AC2/AC3: local artifact hygiene after the target test
    rm -f tests/fixtures/agent-session-manifest/temp-unsupported.txt \
          tests/fixtures/agent-session-manifest/temp-invalid-no-markers.md
    pnpm test -- tests/agent-session-manifest-check.test.ts
    test ! -f tests/fixtures/agent-session-manifest/temp-unsupported.txt
    test ! -f tests/fixtures/agent-session-manifest/temp-invalid-no-markers.md
    
    # AC4
    rg -n 'unsupported file type|no supported manifest files|marker' tests/agent-session-manifest-check.test.ts
    
    # AC5
    pnpm test

    最終判定

    Issue #559 は問題設定としては正しいですが、契約はまだ甘いです。

    LOOP_VERDICT:

    verdict: REQUEST_CHANGES
    blockers:
      - os.tmpdir strategy can satisfy AC1 while failing AC2/AC3 when legacy repo-local temp artifacts already exist
      - verification commands do not force the test-before-absence sequence
      - AC1 grep is too weak and can be satisfied by non-functional mentions
    recommended_implementation:
      - beforeAll cleanup for stale artifacts
      - afterAll cleanup for artifacts generated by this run
      - rmSync(path, { force: true }) over unlinkSync unless unlinkSync is guarded
    merge_readiness_after_fix: READY_FOR_IMPLEMENTATION

    この修正を入れれば、1 Issue = 1 PR で安全に実装できます。

  2. squne121 commented on Jun 2, 2026

    @squne121
    OwnerAuthor

    Contract Review: BLOCKED (2026-06-02T01:46:30Z)

    不足項目

    VC preflight が status: blocked です。

    対象 VC(AC1 line 4):

    rg -n 'temp-unsupported\.txt|temp-invalid-no-markers\.md' tests/agent-session-manifest-check.test.ts
    
    • classification: unexpected_pass
    • category: unexpected_pass
    • decision: blocked
    • exit_code: 0(baseline で既に pass)

    原因: このコマンドは tests/agent-session-manifest-check.test.ts 内の writeFileSync 呼び出しにある既存のパス参照(L144, L153, L162)に match するため、baseline で exit 0 になります。「cleanup 後始末が追加されているか」を検証するはずの VC が、実装前後で区別できません。

    stdout_excerpt:

    144:    const tempFixturePath = resolve(FIXTURES_DIR, 'temp-invalid-no-markers.md')
    153:    const tempTxtPath = resolve(FIXTURES_DIR, 'temp-unsupported.txt')
    162:    const tempTxtPath = resolve(FIXTURES_DIR, 'temp-unsupported.txt')
    

    推奨アクション

    VC を以下のいずれかに修正することで解消できます。

    Option A: この VC を # preflight-scope: pr_review_only に変更する(cleanup 確認は rmSync|unlinkSync VC で十分)

    # AC1
    # preflight-scope: pr_review_only
    $ rg -n 'afterAll|afterEach|onTestFinished|beforeAll' tests/agent-session-manifest-check.test.ts
    # preflight-scope: pr_review_only
    $ rg -n 'temp-unsupported\.txt|temp-invalid-no-markers\.md' tests/agent-session-manifest-check.test.ts
    $ rg -n 'rmSync|unlinkSync' tests/agent-session-manifest-check.test.ts

    Option B: cleanup 対象を明示する grep に絞る(baseline では fail すべき)

    $ rg -n 'rmSync.*temp-unsupported|rmSync.*temp-invalid|unlinkSync.*temp-unsupported|unlinkSync.*temp-invalid' tests/agent-session-manifest-check.test.ts

    issue-refinement-loop の起動を推奨します(承認後に実行可能)。


    CONTRACT_REVIEW_RESULT_V1:
      status: blocked
      generated_at: "2026-06-02T01:46:30Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/559
      checks:
        template_compliance: pass
        state_label: ok
        allowed_paths_present: pass
        vc_present: pass
        stop_conditions_complete: pass
        vc_preflight:
          passed: false
          vc_failed_as_expected: 1
          vc_passed_unexpectedly: 1
          vc_unrunnable: 0
          vc_expected_pass: 0
          vc_skipped: 8
          classifications:
            - ac: AC1
              command: "rg -n 'afterAll|afterEach|onTestFinished|beforeAll' tests/agent-session-manifest-check.test.ts"
              exit_code: null
              classification: skipped
              category: preflight_scope_pr_review_only
              scope_class: pr_review_only
              confidence: low
              decision: go
              verification_owner: pr-review-judge
              deferred_reason: "VC marked pr_review_only; verification deferred to PR review"
              runtime_verification_required: false
            - ac: AC1
              command: "rg -n 'temp-unsupported\\.txt|temp-invalid-no-markers\\.md' tests/agent-session-manifest-check.test.ts"
              exit_code: 0
              classification: unexpected_pass
              category: unexpected_pass
              scope_class: baseline_fail_expected
              confidence: medium
              decision: blocked
              evidence:
                stdout_excerpt: "144: resolve(FIXTURES_DIR, 'temp-invalid-no-markers.md') / 153,162: resolve(FIXTURES_DIR, 'temp-unsupported.txt')"
            - ac: AC1
              command: "rg -n 'rmSync|unlinkSync' tests/agent-session-manifest-check.test.ts"
              exit_code: 1
              classification: expected_fail
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              decision: go
            - ac: AC2
              command: "rm -f tests/fixtures/agent-session-manifest/temp-unsupported.txt"
              exit_code: null
              classification: skipped
              category: preflight_scope_runtime_only
              scope_class: runtime_only
              confidence: low
              decision: go
              verification_owner: impl-review-loop
              runtime_verification_required: true
            - ac: AC2
              command: "rm -f tests/fixtures/agent-session-manifest/temp-invalid-no-markers.md"
              exit_code: null
              classification: skipped
              category: preflight_scope_runtime_only
              scope_class: runtime_only
              confidence: low
              decision: go
              verification_owner: impl-review-loop
              runtime_verification_required: true
            - ac: AC2
              command: "pnpm test -- tests/agent-session-manifest-check.test.ts"
              exit_code: null
              classification: skipped
              category: preflight_scope_runtime_only
              scope_class: runtime_only
              confidence: low
              decision: go
              verification_owner: impl-review-loop
              runtime_verification_required: true
            - ac: AC2
              command: "test ! -f tests/fixtures/agent-session-manifest/temp-unsupported.txt"
              exit_code: null
              classification: skipped
              category: preflight_scope_runtime_only
              scope_class: runtime_only
              confidence: low
              decision: go
              verification_owner: impl-review-loop
              runtime_verification_required: true
            - ac: AC3
              command: "test ! -f tests/fixtures/agent-session-manifest/temp-invalid-no-markers.md"
              exit_code: null
              classification: skipped
              category: preflight_scope_runtime_only
              scope_class: runtime_only
              confidence: low
              decision: go
              verification_owner: impl-review-loop
              runtime_verification_required: true
            - ac: AC4
              command: "rg -n 'unsupported file type|no supported manifest files|marker' tests/agent-session-manifest-check.test.ts"
              exit_code: null
              classification: skipped
              category: preflight_scope_pr_review_only
              scope_class: pr_review_only
              confidence: low
              decision: go
              verification_owner: pr-review-judge
              runtime_verification_required: false
            - ac: AC5
              command: "pnpm test"
              exit_code: null
              classification: skipped
              category: preflight_scope_runtime_only
              scope_class: runtime_only
              confidence: low
              decision: go
              verification_owner: impl-review-loop
              runtime_verification_required: true
        ac_verifiability: pass
        product_spec_check:
          applicability: not_applicable
          decision: pass
          triggers:
            docs_product_allowed_paths: false
            tasks_md_mentioned: false
            specify_artifact_mentioned: false
            generated_task_mentioned: false
            product_spec_context_present: false
        worktree_branch_collision: clear
      next_action: propose_refinement_loop
      blocked_reasons:
        - "VC preflight blocked: AC1 VC 'rg temp-unsupported.txt|temp-invalid-no-markers.md' passes at baseline (unexpected_pass) because these strings already exist in writeFileSync calls"
      warnings: []
  3. squne121 commented on Jun 2, 2026

    @squne121
    OwnerAuthor

    #559 (comment)

    原因は impl-review-loop 側の誤停止ではなく、Issue 契約がまだ issue-contract-review を通っていなかったためです。

    なぜ block したか

    Issue #559 の現在の VC は AC1 がこうなっています。GitHub 上でも確認できます。(GitHub)

    # AC1
    # preflight-scope: pr_review_only
    $ rg -n 'afterAll|afterEach|onTestFinished|beforeAll' tests/agent-session-manifest-check.test.ts
    $ rg -n 'temp-unsupported\.txt|temp-invalid-no-markers\.md' tests/agent-session-manifest-check.test.ts
    $ rg -n 'rmSync|unlinkSync' tests/agent-session-manifest-check.test.ts

    問題は2つあります。

    1つ目は、preflight-scope が 1つ目の $ コマンドにしか効いていない可能性が高いことです。issue-refinement-loop 内でも「preflight-scope: runtime_only は各 $ コマンドの直前行に必要」と判定されており、AC2 だけはその形式に直しましたが、AC1 の2行目・3行目には同じ修正が入っていません。ログ上も、残ブロッカー修正では AC2 にだけ # preflight-scope: runtime_only を追加しています。

    2つ目は、AC1 のこのコマンドが 実装前 baseline でも成功する非差分検証になっていたことです。

    $ rg -n 'temp-unsupported\.txt|temp-invalid-no-markers\.md' tests/agent-session-manifest-check.test.ts

    これは cleanup 実装の存在ではなく、既存の writeFileSync 対象パス文字列にマッチします。したがって baseline で exit 0 になり、baseline_vc_preflight が unexpected_pass として block しました。ログにも、block 理由は「AC1 の VC が baseline で既に pass、writeFileSync 既存参照に match」と明記されています。

    つまり、refinement は人間コメントの3 blockerを概ね取り込んだが、最終的に impl-review-loop が使う同一の contract preflight では未合格だった、という状態です。

    直接原因

    直接原因はこれです。

    AC1 の2つ目の rg が pr_review_only として扱われず、baseline VC として評価された。
    その rg は既存コードでも成功するため、unexpected_pass で block した。
    

    加えて、運用上の原因として、issue-refinement-loop は一度 human_escalation で終わり、その後に手動で「最後の1 blocker」を修正しましたが、その後の最終 issue-contract-review / baseline_vc_preflight 完走確認がされないまま /impl-review-loop 559 に移行しています。ログでは「最終確認レビューを実行します」の直後に /clear され、その後 impl-review-loop が開始されています。

    直すならどちらか

    推奨は Option B です。temp-* の存在確認 grep は削除または弱め、cleanup 実体に結びつく grep に置き換えるべきです。

    例:

    # AC1
    # preflight-scope: pr_review_only
    $ rg -n 'afterAll|afterEach|onTestFinished' tests/agent-session-manifest-check.test.ts
    # preflight-scope: pr_review_only
    $ rg -n 'rmSync|unlinkSync' tests/agent-session-manifest-check.test.ts
    # preflight-scope: pr_review_only
    $ rg -n 'cleanupTempFixtures|temp-unsupported\.txt|temp-invalid-no-markers\.md' tests/agent-session-manifest-check.test.ts

    ただし、これでも temp-* 単独が弱いので、より良いのは cleanup helper を前提化することです。

    # AC1
    # preflight-scope: pr_review_only
    $ rg -n 'function cleanupTempFixtures|const cleanupTempFixtures' tests/agent-session-manifest-check.test.ts
    # preflight-scope: pr_review_only
    $ rg -n 'afterAll\(.*cleanupTempFixtures|afterAll\(\(\) => cleanupTempFixtures\(\)\)' tests/agent-session-manifest-check.test.ts
    # preflight-scope: pr_review_only
    $ rg -n 'rmSync\(.*temp-unsupported\.txt|rmSync\(.*temp-invalid-no-markers\.md' tests/agent-session-manifest-check.test.ts

    現実的には正規表現が brittle なので、AC1 は pr_review_only とし、実体保証は AC2/AC3 の runtime test 後 artifact 不在確認に寄せるのが安定です。

    再発防止策

    1. refinement-loop の完了条件を「本文編集完了」ではなく「contract review go」にする

    issue-refinement-loop の終了条件を次に固定するべきです。

    Issue body edited
    → issue-contract-review 実行
    → baseline_vc_preflight 実行
    → CONTRACT_REVIEW_RESULT_V1 status: go コメント確認
    → refinement-loop 完了
    

    needs-fix が解消したように見える、最後の blocker を手で直した、reviewer が Done と言ったは完了条件にしない。

    2. preflight-scope は「各 $ コマンド直前」に正規化する

    今回の再発源は、コメントがブロック全体に効くという誤認です。Issue 生成・修正時に必ずこうする。

    悪い例:

    # preflight-scope: pr_review_only
    $ cmd1
    $ cmd2
    $ cmd3

    良い例:

    # preflight-scope: pr_review_only
    $ cmd1
    # preflight-scope: pr_review_only
    $ cmd2
    # preflight-scope: pr_review_only
    $ cmd3

    これを reviewer の自然言語判断に任せず、formatter で機械的に補正するべきです。

    3. baseline で pass するコマンドを contract blocker にする

    baseline_vc_preflight の役割は、「実装前から通る VC」を弾くことです。今回の rg temp-unsupported... はまさに baseline で通るため、VC として不適切でした。

    VC 設計ルールを追加するべきです。

    implementation VC は、未実装 baseline で fail し、実装後に pass すること。
    既存文字列・既存ファイル・既存 assertion の存在確認は pr_review_only に限定する。
    

    4. issue-refinement-loop 内で impl-review-loop と同じ preflight を呼ぶ

    refinement-loop の reviewer が独自に判断すると、impl-review-loop の preparation で初めて落ちます。今回もそれです。

    issue-refinement-loop の最終ステップに、最低限この同一コマンドを入れるべきです。

    uv run python3 .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py \
      --issue 559 \
      --repo squne121/loop-protocol

    さらに check_blockers.sh、check_product_spec_contract.py も impl-review-loop preparation と同一セットで呼ぶ。

    5. human_escalation 後の「追加手修正」は必ず full review に戻す

    今回、3 iteration で human_escalation になった後、AC2 の marker だけを直しました。しかしこれは局所修正であり、全体契約が通った保証ではありません。

    運用ルールとしてはこうです。

    human_escalation 後に Issue 本文を1文字でも変更したら、
    必ず issue-contract-review を最初から再実行する。
    

    6. issue-reviewer に「VC は baseline 差分性を検査せよ」を明示する

    今回の reviewer は形式エラーは拾いましたが、rg temp-* が既存 writeFileSync にマッチする問題を refinement 中に潰し切れていません。

    reviewer の checklist に追加するべき項目:

    各 Verification Command について:
    - baseline で pass しないか
    - 既存文字列への grep だけで AC を満たした扱いになっていないか
    - 実装後の状態変化に結びつくか
    - pr_review_only / runtime_only が各 command 直前にあるか
    

    結論

    impl-review-loop が止まった理由は、AC1 の VC が baseline で既に成功するうえ、pr_review_only marker が該当コマンド直前に無かったためです。

    再発防止の本丸は、issue-refinement-loop の最後に impl-review-loop と同じ contract review / baseline preflight を必ず実行し、CONTRACT_REVIEW_RESULT_V1 status: go を完了条件にすることです。これを入れない限り、refinement-loop と impl-review-loop の判定差で同種の停止が再発します。

  4. squne121 commented on Jun 2, 2026

    @squne121
    OwnerAuthor

    Contract Snapshot (2026-06-02T02:18:00Z)

    • Outcome: tests/agent-session-manifest-check.test.ts を pnpm test で実行した後に tests/fixtures/agent-session-manifest/ 配下へ temp artifact が残らない状態でコミットされている。
    • Acceptance Criteria:
      1. AC1: temp fixture を後始末する仕組み(afterAll + rmSync/unlinkSync)が追加されている
      2. AC2: pnpm test 実行後に temp-unsupported.txt が存在しない
      3. AC3: pnpm test 実行後に temp-invalid-no-markers.md が存在しない
      4. AC4: 既存の assertion 文字列が保持されている
      5. AC5: pnpm test が PASS する
    • Allowed Paths: tests/agent-session-manifest-check.test.ts
    • Worktree: .claude/worktrees/issue-559-agent-session-manifest-check-temp-fixtur
    • Branch: worktree-issue-559-agent-session-manifest-check-temp-fixtur
    • VC preflight: baseline fail = 2, 想定外 pass = 0, 実行不可 = 0, skipped (pr_review_only/runtime_only) = 8
    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-06-02T02:18:00Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/559
      checks:
        template_compliance: pass
        state_label: ok
        allowed_paths_present: pass
        vc_present: pass
        stop_conditions_complete: pass
        vc_preflight:
          passed: true
          vc_failed_as_expected: 2
          vc_passed_unexpectedly: 0
          vc_unrunnable: 0
          vc_expected_pass: 0
          vc_skipped: 8
          classifications:
            - ac: AC1
              command: "rg -n 'afterAll|afterEach|onTestFinished|beforeAll' tests/agent-session-manifest-check.test.ts"
              exit_code: null
              classification: skipped
              category: preflight_scope_pr_review_only
              scope_class: pr_review_only
              confidence: low
              decision: go
              verification_owner: pr-review-judge
              deferred_reason: "VC marked pr_review_only; verification deferred to PR review"
              runtime_verification_required: false
            - ac: AC1
              command: "rg -n 'rmSync.*temp-unsupported|rmSync.*temp-invalid|unlinkSync.*temp-unsupported|unlinkSync.*temp-invalid' tests/agent-session-manifest-check.test.ts"
              exit_code: 1
              classification: expected_fail
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              decision: go
            - ac: AC1
              command: "rg -n 'rmSync|unlinkSync' tests/agent-session-manifest-check.test.ts"
              exit_code: 1
              classification: expected_fail
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              decision: go
            - ac: AC2
              command: "rm -f tests/fixtures/agent-session-manifest/temp-unsupported.txt"
              exit_code: null
              classification: skipped
              category: preflight_scope_runtime_only
              scope_class: runtime_only
              confidence: low
              decision: go
              verification_owner: impl-review-loop
              runtime_verification_required: true
            - ac: AC2
              command: "rm -f tests/fixtures/agent-session-manifest/temp-invalid-no-markers.md"
              exit_code: null
              classification: skipped
              category: preflight_scope_runtime_only
              scope_class: runtime_only
              confidence: low
              decision: go
              verification_owner: impl-review-loop
              runtime_verification_required: true
            - ac: AC2
              command: "pnpm test -- tests/agent-session-manifest-check.test.ts"
              exit_code: null
              classification: skipped
              category: preflight_scope_runtime_only
              scope_class: runtime_only
              confidence: low
              decision: go
              verification_owner: impl-review-loop
              runtime_verification_required: true
            - ac: AC2
              command: "test ! -f tests/fixtures/agent-session-manifest/temp-unsupported.txt"
              exit_code: null
              classification: skipped
              category: preflight_scope_runtime_only
              scope_class: runtime_only
              confidence: low
              decision: go
              verification_owner: impl-review-loop
              runtime_verification_required: true
            - ac: AC3
              command: "test ! -f tests/fixtures/agent-session-manifest/temp-invalid-no-markers.md"
              exit_code: null
              classification: skipped
              category: preflight_scope_runtime_only
              scope_class: runtime_only
              confidence: low
              decision: go
              verification_owner: impl-review-loop
              runtime_verification_required: true
            - ac: AC4
              command: "rg -n 'unsupported file type|no supported manifest files|marker' tests/agent-session-manifest-check.test.ts"
              exit_code: null
              classification: skipped
              category: preflight_scope_pr_review_only
              scope_class: pr_review_only
              confidence: low
              decision: go
              verification_owner: pr-review-judge
              runtime_verification_required: false
            - ac: AC5
              command: "pnpm test"
              exit_code: null
              classification: skipped
              category: preflight_scope_runtime_only
              scope_class: runtime_only
              confidence: low
              decision: go
              verification_owner: impl-review-loop
              runtime_verification_required: true
        ac_verifiability: pass
        product_spec_check:
          applicability: not_applicable
          decision: pass
          triggers:
            docs_product_allowed_paths: false
            tasks_md_mentioned: false
            specify_artifact_mentioned: false
            generated_task_mentioned: false
            product_spec_context_present: false
        worktree_branch_collision: clear
      next_action: implement_issue
      blocked_reasons: []
      warnings: []
  5. squne121 commented on Jun 2, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-06-02T02:20:34Z)

    • PR: chore(#559): add afterAll cleanup for temp fixtures in manifest-check tests #562
    • Worktree: .claude/worktrees/issue-559-agent-session-manifest-check-temp-fixtur
    • Branch: worktree-issue-559-agent-session-manifest-check-temp-fixtur
    • Verification: 4/4 PASS (typecheck / lint / test 313 passed / build)
    • AC2 runtime VC: PASS (temp-unsupported.txt absent after test)
    • AC3 runtime VC: PASS (temp-invalid-no-markers.md absent after test)
    • 後続: PR レビュー(pr-review-judge)→ マージ → post-merge-cleanup
  6. added a commit that references this issue on Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    phase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions