Repository navigation
fix(verify): demo-video のテストが実の $HOME に作業場所を作らないようにし、env-clean の誤った不合格を防ぐ - #3486
Merged
Merged
Conversation
…3479) ## 原因((a)〜(c) のどれでもなく、(d) ワーカー自身のまだ動いていたテスト) 記録で確かめた: - wait-3395.log: env-clean は検証の先頭(1.0s)で走り、`.commandmate-demo-vitest-36552 [unattributed]`。 同じ run の tmux 行は「attributed to another worktree」を出しており、#2954 以降の帰属つきのサーバーだった((b) ではない)。 work-evidence は commits=0 / uncommitted=56 で、ワーカーはまだ作業中だった。 - 3395 のワーカーの転写(~/.claude/projects/...-commandmate-issue-3395): 07:36:30Z に `npx vitest run ... tests/unit/skills ...` を起動し、120 秒で背景に移った(bf0ktuuzb)。その出力は `Start at 16:37:22`・`Duration 161.67s`(16:40:04 JST まで)。tests/unit/skills は demo-video/env-scripts.test.ts を含む。 - 07:38:47Z に Stop hook が発火(背景のテストを待つ間にターンが終わった)→ wait が hook_stop で完了 → 検証開始。 つまり env-clean の時点で pid 36552 は生きており、cwd は 3395 の worktree 自身。コミットは 16:41:49。 - attributeHomeEntry を env-clean-gate.test.ts の形で直接呼んで確認(resolver を注入、サーバー等は起動せず): cwd=3395 自身 → unattributed / cwd 不明 → unattributed / cwd=別 worktree → other。 attributeAnchor は自 worktree 内を self とし、home-entries では self も unattributed になる。設計どおりの判定だった。 「検証がコミットの前に走る」側は #3430(requireCommit)で塞がれている。 ## 直し方(第一案) env-scripts.test.ts の SCRATCH_HOME を `os.homedir()` の下から `realpath(os.tmpdir())` の下へ移した。 env-up.sh が要求するのは「状態ディレクトリが(子の)$HOME の下」と「$HOME がログインホームではない」の 2 つで、 子の $HOME は SCRATCH_HOME 自身。スタブのサーバーは validateDbPath を通らない(STUB_NAMESPACE の DB も better-sqlite3 で直接開く)。src/lib/db/db-path-resolver.ts と env-up.sh は変えていない(本番の制限は緩めない)。 realpath は macOS の /var → /private/var で、スクリプトの `pwd -P` と比較が揃うようにするため。 beforeAll の残骸の掃除(#3025)も実の HOME ではなく一時ディレクトリを対象にした(テストが実の HOME に一切触れない)。 テスト: - 陽性対照: env-scripts.test.ts「scratch location (Issue #3479)」— 直す前の実装で赤を確認 (HOME を scratchpad に差し替えて実行。isPathWithin(SCRATCH_HOME, os.homedir()) が true)。 - no-home-leftovers.test.ts: 子に TMPDIR も渡し、$HOME に何も作らないこと・一時ディレクトリに残骸が無いことを追加。 既存の it は消さず名前も変えていない。 - env-clean-gate.test.ts の「still counts a pid that is not alive」は変えずに緑(死んだ pid を other にする変更はしない)。 - env-clean-gate.ts は帰属のコードを変えず、コメントだけ「#3479 より古いチェックアウトのために残す」に直した。 orchestrate.md 3-4 の 2 か所(並行テストの demo-vitest、合図の前に始まった検証)を直した後の状態に合わせた。 tests/unit/tasks/orchestrate-*.test.ts は期待値を変えずに緑。 確認: HOME を scratchpad に差し替えて `npx vitest run tests/unit/skills/demo-video`(15 files / 770 passed、HOME は空のまま)、 `npx vitest run tests/unit/tasks tests/unit/verification tests/unit/guards tests/unit/docs`(84 files passed)、 npm run lint、npx tsc --noEmit、node scripts/changelog-fragments.mjs check。 ## 対になる場所を探した結果 - `commandmate-demo-vitest` を git grep: 作るのは env-scripts.test.ts だけ。stale-scratch.ts のコメントを直した。 - 同じく validateDbPath を理由に $HOME の下へ作るテスト: 他に無し(demo-video 配下を確認)。 - 本文に無い指摘: docs/design/task-contract.md:656 `deadDemoVitestEntries` の行が 「env-scripts.test.ts が死んだ pid の残骸を($HOME で)掃除する(#3025)」と書いているが、#3479 から HOME は掃除しない(scope 外)。 - 本文に無い指摘: .claude/skills/demo-video/scripts/env-up.sh:8 のコメントは実際のデモ実行についての説明で今も正しい(変更不要)。 - 本文に無い指摘: 早すぎる hook_stop(背景のテストを待つ間のターン終了)で検証が作業中に始まる問題そのものは、 #3430 の requireCommit で不合格にはなるが、env-clean 以外のゲートも作業中のツリーを測る(scope 外)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
Closes #3479
契約の検証の
env-cleanが~/.commandmate-demo-vitest-<pid>で不合格になる問題の原因を特定し、テストが実の$HOMEに作業場所を作らないようにした。原因(Issue の (a)〜(c) のどれでもなかった)
tests/unit/skillsを含むテストを起動して背景に回し、待つ間にターンが終わった(Stop の hook)。waitがそれを完了と読み、検証が始まった。その時点で pid 36552 は生きていて、cwd は chore(api): capture --json の 3 欄(isComplete・isGenerating・thinkingMessage)を消す(告知の次のマイナーで) #3395 の worktree 自身だったattributeHomeEntryは設計どおりunattributedと判定した(自分の worktree の pid は除外しない)。帰属の仕組み(fix(verify): env-clean が別の worktree のテストの一時ディレクトリ(.commandmate-demo-vitest-<pid>)を違反に数える #2954)に誤りは無い。サーバーも fix(verify): env-clean が別の worktree のテストの一時ディレクトリ(.commandmate-demo-vitest-<pid>)を違反に数える #2954 以降のビルドだったrequireCommit)で、背景の作業を残した Stop は fix(hooks): Claude がバックグラウンドの作業を残した Stop を自己再開として報告する #3448 で扱われている直し方
tests/unit/skills/demo-video/env-scripts.test.tsの作業場所を、実の$HOMEの下からrealpath(os.tmpdir())の下へ移した。env-up.shが求める条件(状態ディレクトリが子の$HOMEの下・$HOMEがログインホームではない)は保たれる。src/lib/db/db-path-resolver.tsとenv-up.shは変えていない(本番の制限は緩めない)no-home-leftovers.test.tsに、$HOMEに何も作らないこと・一時ディレクトリに残骸が無いことを足した(既存の it は消していない)env-clean-gate.tsは判定を変えず、コメントだけ直した。still counts a pid that is not aliveは変えずに緑確かめたこと
tests/unit/skills/demo-video(15 files / 770 passed、HOME は空のまま)本文に無い指摘の処置
docs/design/task-contract.md:656のdeadDemoVitestEntriesの説明(HOME の掃除)が古くなる → この run の最後の docs の PR で直す🤖 Generated with Claude Code