From 92954a66d30066b7108c43ac8477c5c31161191d Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 17:07:45 +0100 Subject: [PATCH 1/3] chore(guard): the tool guard reads a literal variable, lets stash reads and the typecheck through, and worktree.sh takes --prepare in any place A body file named through a variable the call sets once, to a literal, in a command of its own is read as that path. git stash list and show only read. pnpm typecheck joins the tests agents run. worktree.sh --detach read a --prepare before the commit as the commit. --- .agents/scripts/shell-words.mjs | 99 ++++++++++++++++++++------ .agents/scripts/tool-guard.mjs | 18 +++-- .agents/scripts/worktree.sh | 27 +++++-- .claude/agents/implementer.md | 1 + docs/internal/agent-rules/toolchain.md | 3 +- src/tool-guard.test.ts | 53 ++++++++++++++ src/worktree-script.test.ts | 34 ++++++++- 7 files changed, 197 insertions(+), 38 deletions(-) diff --git a/.agents/scripts/shell-words.mjs b/.agents/scripts/shell-words.mjs index 670c1075b..4f7cfec13 100644 --- a/.agents/scripts/shell-words.mjs +++ b/.agents/scripts/shell-words.mjs @@ -5,13 +5,48 @@ // `$VAR` the guard cannot read, `stdin` is a heredoc or here-string body (null when none), and // `redirects` are `{ op, target }` pairs. The words of a `$(…)` or backtick substitution become // commands of their own. A `$(cat <<'EOF' … EOF)` inside a word is read as its heredoc body. It -// never throws: input it cannot follow ends the command it is in. `commandWords(cmd)` is a +// never throws: input it cannot follow ends the command it is in. A `$VAR` or `${VAR}` reads as +// its value when the call sets VAR once, to a literal, in a command of its own before the use +// (`F=/tmp/body.md; gh pr comment 5 --body-file "$F"`). `commandWords(cmd)` is a // command's words from the program name on, without leading `VAR=value` assignments, wrappers // (`env`, `time`, ...) or a `timeout `. export function parseShell(command) { - const commands = []; - parseInto(String(command ?? ""), commands); - return commands; + const src = String(command ?? ""); + const scan = { commands: [], once: new Set(), vars: new Map() }; + parseInto(src, scan); + const ctx = { commands: [], once: setOnce(scan.commands), vars: new Map() }; + parseInto(src, ctx); + return ctx.commands; +} + +const NAME_SETTERS = new Set([ + "for", + "select", + "read", + "local", + "declare", + "typeset", + "readonly", + "getopts", + "mapfile", + "readarray", + "unset", +]); + +// why: a name the call sets twice, or through `read`, a loop or a declaration, has a value only +// the shell knows; one set once has the value its assignment shows. +function setOnce(commands) { + const count = new Map(); + const bump = (name, by) => count.set(name, (count.get(name) ?? 0) + by); + for (const { words } of commands) { + const declares = words.some((w) => NAME_SETTERS.has(w)); + for (const word of words) { + const name = /^(\w+)\+?=/.exec(word)?.[1]; + if (name !== undefined) bump(name, 1); + else if (declares && /^\w+$/.test(word)) bump(word, 2); + } + } + return new Set([...count].filter(([, n]) => n === 1).map(([name]) => name)); } const WRAPPERS = new Set(["time", "nice", "env", "command", "exec", "nohup"]); @@ -33,15 +68,15 @@ const SCANNERS = [ { at: (p) => p.src[p.i] === "'", scan: singleQuoted }, { at: (p) => p.src[p.i] === '"', - scan: (p) => (p.i = readDoubleQuoted(p.src, p.i + 1, current(p), p.commands)), + scan: (p) => (p.i = readDoubleQuoted(p.src, p.i + 1, current(p), p.ctx)), }, { at: (p) => p.src[p.i] === "$", - scan: (p) => (p.i = readDollar(p.src, p.i, current(p), p.commands)), + scan: (p) => (p.i = readDollar(p.src, p.i, current(p), p.ctx)), }, { at: (p) => p.src[p.i] === "`", - scan: (p) => (p.i = readBacktick(p.src, p.i, current(p), p.commands)), + scan: (p) => (p.i = readBacktick(p.src, p.i, current(p), p.ctx)), }, { at: (p) => p.src.startsWith("<<<", p.i), scan: hereString }, { at: (p) => p.src.startsWith("<<", p.i), scan: heredoc }, @@ -49,8 +84,8 @@ const SCANNERS = [ { at: (p) => ";|&()".includes(p.src[p.i]), scan: separator }, ]; -function parseInto(src, commands) { - const p = { src, commands, i: 0, cmd: newCommand(), word: null, redirectOp: null, pending: [] }; +function parseInto(src, ctx) { + const p = { src, ctx, i: 0, cmd: newCommand(), word: null, redirectOp: null, pending: [] }; while (p.i < src.length) { const scanner = SCANNERS.find((s) => s.at(p)); if (scanner === undefined) current(p).text += src[p.i++]; @@ -80,10 +115,23 @@ function endCommand(p) { endWord(p); p.redirectOp = null; const { cmd } = p; - if (cmd.words.length > 0 || cmd.redirects.length > 0 || cmd.stdin !== null) p.commands.push(cmd); + rememberAssignments(p.ctx, cmd); + if (cmd.words.length > 0 || cmd.redirects.length > 0 || cmd.stdin !== null) + p.ctx.commands.push(cmd); p.cmd = newCommand(); } +// why: `F=x` alone on a command sets a shell variable; before a program it sets only that +// program's environment, after the shell has expanded the command's own `$F`. +function rememberAssignments(ctx, cmd) { + const from = cmd.words[0] === "export" ? 1 : 0; + const assigned = cmd.words.slice(from).map((word) => /^(\w+)=([\s\S]*)$/.exec(word)); + if (assigned.includes(null)) return; + assigned.forEach((found, i) => { + if (ctx.once.has(found[1]) && !cmd.dynamic[from + i]) ctx.vars.set(found[1], found[2]); + }); +} + function newline(p) { endCommand(p); p.i++; @@ -184,16 +232,16 @@ function newCommand() { return { words: [], dynamic: [], stdin: null, stdinDynamic: false, redirects: [] }; } -function readDoubleQuoted(src, i, word, commands) { +function readDoubleQuoted(src, i, word, ctx) { while (i < src.length && src[i] !== '"') { const c = src[i]; if (c === "\\" && /[$`"\\\n]/.test(src[i + 1] ?? "")) { if (src[i + 1] !== "\n") word.text += src[i + 1]; i += 2; } else if (c === "$") { - i = readDollar(src, i, word, commands); + i = readDollar(src, i, word, ctx); } else if (c === "`") { - i = readBacktick(src, i, word, commands); + i = readBacktick(src, i, word, ctx); } else { word.text += c; i++; @@ -213,15 +261,15 @@ const DOLLARS = [ { at: (next) => /[\w@*#?$!-]/.test(next), read: dollarName }, ]; -function readDollar(src, i, word, commands) { +function readDollar(src, i, word, ctx) { const next = src[i + 1] ?? ""; const reader = DOLLARS.find((d) => d.at(next)); - if (reader !== undefined) return reader.read(src, i, word, commands); + if (reader !== undefined) return reader.read(src, i, word, ctx); word.text += "$"; return i + 1; } -function dollarParen(src, i, word, commands) { +function dollarParen(src, i, word, ctx) { const doc = CAT_HEREDOC.exec(src.slice(i)); if (doc !== null) { word.text += doc[3]; @@ -229,7 +277,7 @@ function dollarParen(src, i, word, commands) { return i + doc[0].length; } const end = matchingParen(src, i + 2); - parseInto(src.slice(i + 2, end), commands); + parseInto(src.slice(i + 2, end), ctx); word.dynamic = true; return end + 1; } @@ -247,22 +295,27 @@ function ansiQuoted(src, i, word) { return j + 1; } -function dollarBrace(src, i, word) { +function dollarBrace(src, i, word, ctx) { const end = src.indexOf("}", i); - word.dynamic = true; + expand(word, ctx, end === -1 ? "" : src.slice(i + 2, end)); return end === -1 ? src.length : end + 1; } -function dollarName(src, i, word) { +function dollarName(src, i, word, ctx) { let j = i + 2; if (/\w/.test(src[i + 1])) while (/\w/.test(src[j] ?? "")) j++; - word.dynamic = true; + expand(word, ctx, src.slice(i + 1, j)); return j; } -function readBacktick(src, i, word, commands) { +function expand(word, ctx, name) { + if (ctx.vars.has(name)) word.text += ctx.vars.get(name); + else word.dynamic = true; +} + +function readBacktick(src, i, word, ctx) { const end = src.indexOf("`", i + 1); - parseInto(src.slice(i + 1, end === -1 ? src.length : end), commands); + parseInto(src.slice(i + 1, end === -1 ? src.length : end), ctx); word.dynamic = true; return end === -1 ? src.length : end + 1; } diff --git a/.agents/scripts/tool-guard.mjs b/.agents/scripts/tool-guard.mjs index 46469d906..4f9cbc61f 100644 --- a/.agents/scripts/tool-guard.mjs +++ b/.agents/scripts/tool-guard.mjs @@ -24,7 +24,8 @@ // `protocol:` and REVIEW.md's text; a stage agent with a `model`; a `code-reviewer` // off Opus on a diff that touches a strict area (REVIEW.md, "Routing"), outside a // replay; or a sub-agent starts a helper that is not `run_in_background: false`. -// git a sub-agent runs `git stash`, `git rebase` (or `pull --rebase`), or a push that +// git a sub-agent runs `git stash` (but `list` or `show`), `git rebase` (or `pull +// --rebase`), or a push that // rewrites or deletes a remote branch (`+`, `:`, `--force`, `--delete`). // gh a sub-agent opens a PR without `--draft` (or a REST create without // `draft=true`), opens one from a `-repro` branch, runs `gh pr ready`, or adds @@ -34,7 +35,8 @@ // session assigns an issue by hand instead of through `claim.mjs`. // body any session posts a body or comment (`gh issue|pr comment|create|edit|close`, // `gh api ... body=`) that `body-rules.mjs` rejects, or one the guard cannot read -// (built by `$(...)`, a backtick or a variable: use `--body-file`). +// (built by `$(...)`, a backtick or a variable the call does not set once to a +// literal: use `--body-file`). // slow lane any session runs vitest on an `e2e/slow-*` file, or the e2e project without a // `!slow` tags filter; a sub-agent runs `pnpm test:e2e:slow` (or a physical lane); // an agent other than `hardware-verifier` and `implementer` runs `slow-e2e.sh` @@ -55,7 +57,6 @@ const SCRIPTS = new Set([ "check", "test", "test:timing", - "typecheck", "typecheck:e2e", "typecheck:e2e:types", "lint", @@ -284,12 +285,14 @@ function trackWrites(state, cmd) { } } +const STASH_READS = new Set(["list", "show"]); const GIT_RULES = [ { - when: (g) => g.sub === "stash", + when: (g) => g.sub === "stash" && !STASH_READS.has(g.rest.find((w) => !w.startsWith("-"))), reason: "Refused: never `git stash` in a delivery stage: every worktree shares one stash list, so " + - "a pop can take another agent's changes. Commit the work instead.", + "a pop can take another agent's changes. Commit the work instead. `git stash list` and " + + "`git stash show` only read, and pass.", }, { when: (g) => @@ -479,7 +482,8 @@ function unreadable() { refuse( "Refused: the guard cannot read a body built by `$(...)`, a backtick or a variable, so it " + "cannot check its shape (delivery rule 12). Write the body to a file and pass " + - "`--body-file ` (`-F body=@` for `gh api`).", + "`--body-file ` (`-F body=@` for `gh api`). A variable reads fine when this " + + "call sets it once, to a literal path, in a command of its own before the use.", ); } @@ -752,7 +756,7 @@ if (tool === "Bash" && subAgent) { `Refused: \`${found}\` is under "Checks agents never run" in toolchain.md. The commit ` + "hook runs lint, the comment lint and typecheck; the push hook runs Fallow and the e2e " + "typecheck; CI runs the rest. Their errors show in the commit or push output. Run only " + - 'the commands under "Tests agents run".', + 'the commands under "Tests agents run"; for types that is `pnpm typecheck`.', ); } } diff --git a/.agents/scripts/worktree.sh b/.agents/scripts/worktree.sh index 22c4c9b82..a786647dd 100755 --- a/.agents/scripts/worktree.sh +++ b/.agents/scripts/worktree.sh @@ -6,7 +6,8 @@ # .agents/scripts/worktree.sh --detach [--prepare] # a new detached worktree at , in a # fresh folder under $TMPDIR (a review lens's or -# a probe's); --prepare installs into it +# a probe's); --prepare installs into it, and +# may come before or after # echo '{"name":""}' | .agents/scripts/worktree.sh # # The stdin form is what Claude Code's WorktreeCreate hook uses (.claude/settings.json): the @@ -57,23 +58,37 @@ EOF ) } -if [ "${1:-}" = "--prepare" ]; then +detach= +case " $* " in + *" --detach "*) detach=1 ;; +esac + +if [ -z "$detach" ] && [ "${1:-}" = "--prepare" ]; then prepare "${2:?usage: worktree.sh --prepare }" exit 0 fi # why: a folder picked by hand (/tmp/rv1222-claims) already held the last round's commit, and the # reviewer read it as the new one; a fresh folder and a checked HEAD rule that out. -if [ "${1:-}" = "--detach" ]; then - commit=$(git rev-parse --verify --quiet "${2:?usage: worktree.sh --detach [--prepare]}^{commit}") \ - || { echo "worktree.sh: $2 is not a commit here; fetch it first" >&2; exit 1; } +if [ -n "$detach" ]; then + install= + rev= + for arg in "$@"; do + case $arg in + --detach) ;; + --prepare) install=1 ;; + *) rev=$arg ;; + esac + done + commit=$(git rev-parse --verify --quiet "${rev:?usage: worktree.sh --detach [--prepare]}^{commit}") \ + || { echo "worktree.sh: $rev is not a commit here; fetch it first" >&2; exit 1; } tmp=${TMPDIR:-/tmp} dir=$(mktemp -d "${tmp%/}/wt-$(echo "$commit" | cut -c1-9).XXXXXX") rmdir "$dir" git worktree add -q --detach "$dir" "$commit" >&2 [ "$(git -C "$dir" rev-parse HEAD)" = "$commit" ] \ || { echo "worktree.sh: $dir is not at $commit" >&2; exit 1; } - [ "${3:-}" != "--prepare" ] || prepare "$dir" + [ -z "$install" ] || prepare "$dir" echo "$dir" exit 0 fi diff --git a/.claude/agents/implementer.md b/.claude/agents/implementer.md index 266ef09ce..82b3b603c 100644 --- a/.claude/agents/implementer.md +++ b/.claude/agents/implementer.md @@ -22,6 +22,7 @@ you run are copied below, so you need not open it for them. | --------------------------------------------------- | -------------------------------------------------------------------------------------------------- | | Unit tests that import what the branch changed | `pnpm test:changed` | | One unit test file | `pnpm exec vitest run --project unit ` | +| Types across the project, before a commit | `pnpm typecheck` | | One console DOM test file (`*.dom.test.tsx`) | `pnpm exec vitest run --project ui-dom ` | | One timing file (`*.timing.test.ts`) | `pnpm exec vitest run --project timing ` | | Fast e2e files (builds first) | `pnpm test:e2e ` | diff --git a/docs/internal/agent-rules/toolchain.md b/docs/internal/agent-rules/toolchain.md index 5dc208fe9..35e13d7f0 100644 --- a/docs/internal/agent-rules/toolchain.md +++ b/docs/internal/agent-rules/toolchain.md @@ -10,6 +10,7 @@ copies "Tests agents run"; change both together (a repo test compares them). | ---------------------------------------------- | -------------------------------------------- | | Unit tests that import what the branch changed | `pnpm test:changed` | | One unit test file | `pnpm exec vitest run --project unit ` | +| Types across the project, before a commit | `pnpm typecheck` | | One console DOM test file (`*.dom.test.tsx`) | `pnpm exec vitest run --project ui-dom ` | | One timing file (`*.timing.test.ts`) | `pnpm exec vitest run --project timing ` | | Fast e2e files (builds first) | `pnpm test:e2e ` | @@ -37,7 +38,7 @@ pages; it compares nothing. Open the pictures the change touched. Hooks and CI run these. Never run them by hand, and never the tools behind them (from `node_modules/.bin` or any other path): `pnpm check`, `pnpm test`, -`pnpm test:timing`, `pnpm typecheck`, `pnpm typecheck:e2e`, `pnpm typecheck:e2e:types`, `pnpm lint`, `pnpm lint:comments`, `pnpm lint:tests`, +`pnpm test:timing`, `pnpm typecheck:e2e`, `pnpm typecheck:e2e:types`, `pnpm lint`, `pnpm lint:comments`, `pnpm lint:tests`, `pnpm format`, `pnpm format:check`, `pnpm fallow`, `pnpm mutate` (outside the `harden-tests` routine and a refactor's `--touched-by` run, below), the whole diff --git a/src/tool-guard.test.ts b/src/tool-guard.test.ts index c49b014e0..49e9e2184 100644 --- a/src/tool-guard.test.ts +++ b/src/tool-guard.test.ts @@ -83,6 +83,8 @@ describe("tool-guard.mjs", () => { it.each([ "pnpm test:changed", + "pnpm typecheck", + "pnpm run typecheck", "pnpm exec vitest run --project unit src/a.test.ts", "pnpm test:e2e e2e/http-api.test.ts", "pnpm test:console --project=chromium e2e/console/sign-in.spec.ts", @@ -183,6 +185,10 @@ describe("tool-guard.mjs", () => { expect(result.stderr).toContain("timeout: 600000"); }); + it("names the typecheck command when it refuses a sub-agent's tsc", () => { + expect(bash("pnpm exec tsc --noEmit").stderr).toContain("for types that is `pnpm typecheck`"); + }); + it.each([ ["git stash push -u", "never `git stash`"], ["git stash", "never `git stash`"], @@ -205,6 +211,8 @@ describe("tool-guard.mjs", () => { "git push -u origin task/1", "git push origin HEAD:task/1", "git merge origin/main", + "git stash list", + "git -C ../x stash show -p stash@{0}", 'git commit -m "test: never git stash or git rebase (#1)"', ])("lets a sub-agent run %s", (command) => { expect(bash(command, "a1", "implementer")).toEqual(OK); @@ -570,4 +578,49 @@ describe("tool-guard.mjs", () => { expect(bash(command, null).stderr).toContain("pass `--body-file `"); } }); + + it("reads a body file named through a variable the call sets once, to a literal, before the use", () => { + const good = `Done.\n\n${FOOTER}`; + const file = bodyFile(good); + const scratch = join(mkdtempSync(join(tmpdir(), "tool-guard-")), "new.md"); + + expect(bash(`F=${file}; gh issue comment 9 --body-file "$F"`, null)).toEqual(OK); + expect(bash(`export F="${file}"\ngh issue comment 9 --body-file \${F}`, null)).toEqual(OK); + expect( + bash(`D=${dirname(file)} && F="$D/body.md" && gh pr edit 9 --body-file "$F"`, null), + ).toEqual(OK); + expect( + bash(`F=${scratch}; cat > "$F" <<'EOF'\n${good}\nEOF\ngh pr edit 9 --body-file "$F"`, null), + ).toEqual(OK); + expect( + bash(`F=${bodyFile("Done.\n")}; gh issue comment 9 --body-file "$F"`, null).stderr, + ).not.toContain("pass `--body-file `"); + }); + + it.each([ + [ + "sets twice", + (file: string) => `F=/tmp/other.md; F=${file}; gh issue comment 9 --body-file "$F"`, + ], + ["sets from a command", () => 'F=$(mktemp); gh issue comment 9 --body-file "$F"'], + [ + "sets only for the program", + (file: string) => `F=${file} gh issue comment 9 --body-file "$F"`, + ], + ["sets after the use", (file: string) => `gh issue comment 9 --body-file "$F"; F=${file}`], + [ + "sets in a loop", + (file: string) => `for F in ${file}; do :; done; gh issue comment 9 --body-file "$F"`, + ], + ["reads from input", () => 'read -r F; gh issue comment 9 --body-file "$F"'], + [ + "expands with a default", + (file: string) => `F=${file}; gh issue comment 9 --body-file "\${F:-x}"`, + ], + ])("refuses a body file named through a variable the call %s", (_what, command) => { + const result = bash(command(bodyFile(`Done.\n\n${FOOTER}`)), null); + + expect(result.status).toBe(2); + expect(result.stderr).toContain("pass `--body-file `"); + }); }); diff --git a/src/worktree-script.test.ts b/src/worktree-script.test.ts index 3c94e9dfd..22d612360 100644 --- a/src/worktree-script.test.ts +++ b/src/worktree-script.test.ts @@ -1,5 +1,5 @@ import { execFileSync } from "node:child_process"; -import { mkdtempSync, realpathSync, writeFileSync } from "node:fs"; +import { mkdirSync, mkdtempSync, readFileSync, realpathSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; @@ -86,4 +86,36 @@ describe("worktree.sh", () => { expect(git(c, "rev-parse", "HEAD")).toBe(second); expect(() => run(main, "--detach", "0000000")).toThrow(); }); + + it("--detach takes --prepare before or after the commit, and installs into the new worktree", () => { + const { root, main } = fixture(); + const bin = join(root, "bin"); + const installs = join(root, "installs"); + mkdirSync(bin); + writeFileSync( + join(bin, "pnpm"), + `#!/bin/sh\n[ "$1" = --version ] && { echo 1.2.3; exit 0; }\npwd >> "${installs}"\n`, + { mode: 0o755 }, + ); + writeFileSync( + join(main, "package.json"), + JSON.stringify({ devEngines: { packageManager: { name: "pnpm", version: "1.2.3" } } }), + ); + git(main, "add", "package.json"); + git(main, "commit", "-qm", "package.json"); + const head = git(main, "rev-parse", "HEAD"); + const detach = (...args: string[]) => + execFileSync("sh", [SCRIPT, "--detach", ...args], { + cwd: main, + encoding: "utf8", + env: { ...process.env, PATH: `${bin}:${process.env.PATH}` }, + }).trim(); + + const after = detach(head, "--prepare"); + const before = detach("--prepare", head); + + expect(git(after, "rev-parse", "HEAD")).toBe(head); + expect(git(before, "rev-parse", "HEAD")).toBe(head); + expect(readFileSync(installs, "utf8").trim().split("\n")).toEqual([after, before]); + }); }); From abf6d17ee06cd3c5ce5ca5897d9edad45801721d Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 17:13:14 +0100 Subject: [PATCH 2/3] fix(e2e): the slow lane's check leaves a running lane alone, and a delivery run checks the machine at its start check cleaned up leftovers with no look at the lock, so a second verifier's check stopped the processes and removed the home of a lane another PR was running (#1626's lane failed this way on 2026-11-16). With the lock held it now only checks the machine. deliver runs the check when a run starts, so an unfit machine shows before the first build ends, not after review. --- .claude/skills/deliver/SKILL.md | 5 +++++ scripts/slow-e2e.sh | 7 +++++-- src/slow-e2e.test.ts | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/.claude/skills/deliver/SKILL.md b/.claude/skills/deliver/SKILL.md index 3db66ef04..b8890a63d 100644 --- a/.claude/skills/deliver/SKILL.md +++ b/.claude/skills/deliver/SKILL.md @@ -149,6 +149,11 @@ gh issue view --json number,title,labels,assignees,body - Anything else, or assigned to someone else: stop and say why (rule 1). +When a Done when line of an issue in the run needs the slow lane, and the +run has no `no-hardware`: run the lane script's `check` (`toolchain.md`) +once, now. What it prints as unfit does not stop the run: say it in one +line, so the machine can be fixed while the first build runs. + ## 2. Deliver one issue Claim it: `node .agents/scripts/claim.mjs `; a refusal says why the diff --git a/scripts/slow-e2e.sh b/scripts/slow-e2e.sh index 039146c1c..23e533041 100755 --- a/scripts/slow-e2e.sh +++ b/scripts/slow-e2e.sh @@ -8,7 +8,8 @@ # the log has been quiet; or the last run's log and exit code # scripts/slow-e2e.sh stop stops the running lane and what it started, and frees the lock # scripts/slow-e2e.sh clean stops what earlier runs left behind (refused while a lane runs) -# scripts/slow-e2e.sh check the checks a run starts with: clean, then free disk and builds +# scripts/slow-e2e.sh check the checks a run starts with: clean (not while a run holds the +# lock), then free disk and builds # # Vitest arguments pass through: `-t ` runs one test, `--bail=1` stops at the first # failure. A run prints its log path and exits at once; it writes its exit code to <log>.exit @@ -140,7 +141,9 @@ if command == "clean": clean() elif command == "check": - clean() + # why: a running lane's processes and home are not leftovers; cleaning under it fails its tests. + if not holder(): + clean() problems = [] # why: a lane worker an aborted run left is already killed by clean(), so a live holder here is a worker outside the lane (ADR 0059 §4). try: diff --git a/src/slow-e2e.test.ts b/src/slow-e2e.test.ts index ad5030064..c4a148423 100644 --- a/src/slow-e2e.test.ts +++ b/src/slow-e2e.test.ts @@ -191,6 +191,22 @@ describe("scripts/slow-e2e.sh", () => { expect(result.stderr).toContain(`busy: a slow-lane run holds the lock (pid ${runner})`); }); + it("check stops nothing and keeps the lane's home while a run holds the lock", async () => { + const { lane, lock, run } = machine(); + mkdirSync(lane, { recursive: true }); + const runner = idleNode(process.env); + mkdirSync(lock); + writeFileSync(join(lock, "pid"), String(runner)); + const daemon = idleNode({ ...process.env, SIMLOCK_HOME: join(lane, "simlock-e2e-abc") }); + await new Promise((resolve) => setTimeout(resolve, 300)); + + const result = run("check"); + + expect(result.status).toBe(0); + expect(alive(daemon)).toBe(true); + expect(existsSync(lane)).toBe(true); + }); + it("stop ends the running lane's process group, writes exit 143 to its log and frees the lock", () => { const { dir, lock, run } = machine(); const runner = idleNode(process.env, true); From 48f8c84f1b0ffbd900349b215676609d45ebc5d1 Mon Sep 17 00:00:00 2001 From: Szymon Chmal <szymon@chmal.it> Date: Tue, 17 Nov 2026 17:25:53 +0100 Subject: [PATCH 3/3] fix(e2e): the lane check passes the running lane's own worker; three guard test rows fail for the reason they name Review R2: with a lane running, check stopped at the worker lock the lane's own daemon holds and told the caller to stop it. R3: the loop, read and program-only rows were refused whatever the parser did; each now sets the variable to a literal first, so only the rule under test refuses it. R4: toolchain.md names the lane script's check. --- docs/internal/agent-rules/toolchain.md | 3 +++ scripts/slow-e2e.sh | 13 +++++++------ src/slow-e2e.test.ts | 14 ++++++++++---- src/tool-guard.test.ts | 10 +++++++--- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/docs/internal/agent-rules/toolchain.md b/docs/internal/agent-rules/toolchain.md index 35e13d7f0..e45357b48 100644 --- a/docs/internal/agent-rules/toolchain.md +++ b/docs/internal/agent-rules/toolchain.md @@ -196,6 +196,9 @@ Tests that start real simulators or emulators. Run them only through - It first stops what earlier runs left behind. By hand: `scripts/slow-e2e.sh clean` (refused while a run holds the lock). Never stop a simulator, emulator or daemon any other way. +- `scripts/slow-e2e.sh check`: the checks a run starts with, without a + run. Exit 69 with why when the machine is unfit. While a lane runs it + stops nothing and checks only free disk and the other tools. - `scripts/slow-e2e.sh status`: the running test, the counts so far, how long the log has been quiet, and each failure. `scripts/slow-e2e.sh stop` ends the running lane and what it started. diff --git a/scripts/slow-e2e.sh b/scripts/slow-e2e.sh index 23e533041..4778beaed 100755 --- a/scripts/slow-e2e.sh +++ b/scripts/slow-e2e.sh @@ -8,8 +8,8 @@ # the log has been quiet; or the last run's log and exit code # scripts/slow-e2e.sh stop stops the running lane and what it started, and frees the lock # scripts/slow-e2e.sh clean stops what earlier runs left behind (refused while a lane runs) -# scripts/slow-e2e.sh check the checks a run starts with: clean (not while a run holds the -# lock), then free disk and builds +# scripts/slow-e2e.sh check the checks a run starts with: clean and the worker lock (neither +# while a run holds the lane lock), then free disk and builds # # Vitest arguments pass through: `-t <title>` runs one test, `--bail=1` stops at the first # failure. A run prints its log path and exits at once; it writes its exit code to <log>.exit @@ -141,14 +141,15 @@ if command == "clean": clean() elif command == "check": - # why: a running lane's processes and home are not leftovers; cleaning under it fails its tests. - if not holder(): + # why: a running lane's processes, home and worker are its own, not leftovers; cleaning under it fails its tests. + running = holder() + if not running: clean() problems = [] - # why: a lane worker an aborted run left is already killed by clean(), so a live holder here is a worker outside the lane (ADR 0059 §4). + # why: with no lane running, a lane worker an aborted run left is already killed by clean(), so a live holder is a worker outside the lane (ADR 0059 §4). try: owner = json.loads(read(os.path.join(worker_lock, "owner.json"), "{}")) - if alive(owner["pid"]): + if not running and alive(owner["pid"]): print(f"not fit: a Simlock worker holds this machine (pid {owner['pid']}, folder {owner['folder']}); stop it first: SIMLOCK_HOME={owner['folder']} simlock daemon stop", file=sys.stderr) sys.exit(69) except (ValueError, KeyError, TypeError): diff --git a/src/slow-e2e.test.ts b/src/slow-e2e.test.ts index c4a148423..2e488678c 100644 --- a/src/slow-e2e.test.ts +++ b/src/slow-e2e.test.ts @@ -191,18 +191,24 @@ describe("scripts/slow-e2e.sh", () => { expect(result.stderr).toContain(`busy: a slow-lane run holds the lock (pid ${runner})`); }); - it("check stops nothing and keeps the lane's home while a run holds the lock", async () => { - const { lane, lock, run } = machine(); + it("check stops nothing, keeps the lane's home and passes the lane's own worker while a run holds the lock", async () => { + const { dir, lane, lock, run } = machine(); mkdirSync(lane, { recursive: true }); const runner = idleNode(process.env); mkdirSync(lock); writeFileSync(join(lock, "pid"), String(runner)); - const daemon = idleNode({ ...process.env, SIMLOCK_HOME: join(lane, "simlock-e2e-abc") }); + const home = join(lane, "simlock-e2e-abc"); + const daemon = idleNode({ ...process.env, SIMLOCK_HOME: home }); + mkdirSync(join(dir, "worker.lock")); + writeFileSync( + join(dir, "worker.lock", "owner.json"), + JSON.stringify({ folder: home, pid: daemon, startedAt: "t0" }), + ); await new Promise((resolve) => setTimeout(resolve, 300)); const result = run("check"); - expect(result.status).toBe(0); + expect([result.status, result.stderr]).toEqual([0, ""]); expect(alive(daemon)).toBe(true); expect(existsSync(lane)).toBe(true); }); diff --git a/src/tool-guard.test.ts b/src/tool-guard.test.ts index 49e9e2184..3f6bbfc80 100644 --- a/src/tool-guard.test.ts +++ b/src/tool-guard.test.ts @@ -605,14 +605,18 @@ describe("tool-guard.mjs", () => { ["sets from a command", () => 'F=$(mktemp); gh issue comment 9 --body-file "$F"'], [ "sets only for the program", - (file: string) => `F=${file} gh issue comment 9 --body-file "$F"`, + (file: string) => `F=${file} true; gh issue comment 9 --body-file "$F"`, ], ["sets after the use", (file: string) => `gh issue comment 9 --body-file "$F"; F=${file}`], [ "sets in a loop", - (file: string) => `for F in ${file}; do :; done; gh issue comment 9 --body-file "$F"`, + (file: string) => + `F=${file}; for F in /tmp/other.md; do :; done; gh issue comment 9 --body-file "$F"`, + ], + [ + "reads from input", + (file: string) => `F=${file}; read -r F; gh issue comment 9 --body-file "$F"`, ], - ["reads from input", () => 'read -r F; gh issue comment 9 --body-file "$F"'], [ "expands with a default", (file: string) => `F=${file}; gh issue comment 9 --body-file "\${F:-x}"`,