Repository navigation
Description
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: choreParent 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
beforeAllandafterAll. - 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.txttests/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 testAllowed 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
squne121 commentedon Jun 1, 2026
結論: 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 を満たせない可能性があります。修正案:
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.mdpnpm test全体は AC5 で別途維持してよいですが、cleanup の局所検証は対象テストファイルに絞ったほうが原因切り分けが明確です。Blocker 3: AC1 の grep が形式だけで、cleanup の実体を保証しない
AC1 は
afterAll|afterEach|rmSync|unlinkSync|tmpdirの grep です。([GitHub]2) これはコメントや import だけでも pass します。さらにtmpdirが出てくるだけで、legacy repo path を消しているかは判定できません。修正案:
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のみで済むためです。推奨パッチの形:
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 本文への具体的修正案
以下を追加・置換してください。
Verification Commands は次に置換。
最終判定
Issue #559 は問題設定としては正しいですが、契約はまだ甘いです。
LOOP_VERDICT:この修正を入れれば、1 Issue = 1 PR で安全に実装できます。
squne121 commentedon Jun 2, 2026
Contract Review: BLOCKED (2026-06-02T01:46:30Z)
不足項目
VC preflight が
status: blockedです。対象 VC(AC1 line 4):
classification: unexpected_passcategory: unexpected_passdecision: blockedexit_code: 0(baseline で既に pass)原因: このコマンドは
tests/agent-session-manifest-check.test.ts内のwriteFileSync呼び出しにある既存のパス参照(L144, L153, L162)に match するため、baseline で exit 0 になります。「cleanup 後始末が追加されているか」を検証するはずの VC が、実装前後で区別できません。stdout_excerpt:
推奨アクション
VC を以下のいずれかに修正することで解消できます。
Option A: この VC を
# preflight-scope: pr_review_onlyに変更する(cleanup 確認はrmSync|unlinkSyncVC で十分)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.tsissue-refinement-loopの起動を推奨します(承認後に実行可能)。squne121 commentedon Jun 2, 2026
#559 (comment)
原因は impl-review-loop 側の誤停止ではなく、Issue 契約がまだ
issue-contract-reviewを通っていなかったためです。なぜ block したか
Issue #559 の現在の VC は AC1 がこうなっています。GitHub 上でも確認できます。(GitHub)
問題は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 では未合格だった、という状態です。
直接原因
直接原因はこれです。
加えて、運用上の原因として、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 に置き換えるべきです。例:
ただし、これでも
temp-*単独が弱いので、より良いのは cleanup helper を前提化することです。現実的には正規表現が brittle なので、AC1 は
pr_review_onlyとし、実体保証は AC2/AC3 の runtime test 後 artifact 不在確認に寄せるのが安定です。再発防止策
1. refinement-loop の完了条件を「本文編集完了」ではなく「contract review go」にする
issue-refinement-loopの終了条件を次に固定するべきです。needs-fix が解消したように見える、最後の blocker を手で直した、reviewer が Done と言ったは完了条件にしない。2.
preflight-scopeは「各$コマンド直前」に正規化する今回の再発源は、コメントがブロック全体に効くという誤認です。Issue 生成・修正時に必ずこうする。
悪い例:
# preflight-scope: pr_review_only $ cmd1 $ cmd2 $ cmd3良い例:
これを reviewer の自然言語判断に任せず、formatter で機械的に補正するべきです。
3. baseline で pass するコマンドを contract blocker にする
baseline_vc_preflightの役割は、「実装前から通る VC」を弾くことです。今回のrg temp-unsupported...はまさに baseline で通るため、VC として不適切でした。VC 設計ルールを追加するべきです。
4. issue-refinement-loop 内で impl-review-loop と同じ preflight を呼ぶ
refinement-loop の reviewer が独自に判断すると、impl-review-loop の preparation で初めて落ちます。今回もそれです。
issue-refinement-loopの最終ステップに、最低限この同一コマンドを入れるべきです。さらに
check_blockers.sh、check_product_spec_contract.pyも impl-review-loop preparation と同一セットで呼ぶ。5. human_escalation 後の「追加手修正」は必ず full review に戻す
今回、3 iteration で
human_escalationになった後、AC2 の marker だけを直しました。しかしこれは局所修正であり、全体契約が通った保証ではありません。運用ルールとしてはこうです。
6. issue-reviewer に「VC は baseline 差分性を検査せよ」を明示する
今回の reviewer は形式エラーは拾いましたが、
rg temp-*が既存 writeFileSync にマッチする問題を refinement 中に潰し切れていません。reviewer の checklist に追加するべき項目:
結論
impl-review-loop が止まった理由は、AC1 の VC が baseline で既に成功するうえ、
pr_review_onlymarker が該当コマンド直前に無かったためです。再発防止の本丸は、
issue-refinement-loopの最後に impl-review-loop と同じ contract review / baseline preflight を必ず実行し、CONTRACT_REVIEW_RESULT_V1 status: goを完了条件にすることです。これを入れない限り、refinement-loop と impl-review-loop の判定差で同種の停止が再発します。squne121 commentedon Jun 2, 2026
Contract Snapshot (2026-06-02T02:18:00Z)
tests/agent-session-manifest-check.test.tsをpnpm testで実行した後にtests/fixtures/agent-session-manifest/配下へ temp artifact が残らない状態でコミットされている。pnpm test実行後にtemp-unsupported.txtが存在しないpnpm test実行後にtemp-invalid-no-markers.mdが存在しないpnpm testが PASS するtests/agent-session-manifest-check.test.ts.claude/worktrees/issue-559-agent-session-manifest-check-temp-fixturworktree-issue-559-agent-session-manifest-check-temp-fixtursqune121 commentedon Jun 2, 2026
implement-issue: 実装完了 (2026-06-02T02:20:34Z)
.claude/worktrees/issue-559-agent-session-manifest-check-temp-fixturworktree-issue-559-agent-session-manifest-check-temp-fixturchore(#559): add afterAll cleanup for temp fixtures in manifest-check…