diff --git a/CLAUDE.md b/CLAUDE.md index 8c1de22..c8d2105 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -231,13 +231,19 @@ taxonomy and reads as `test:`. prevents is bounded because the glob, not the workflow, enumerates suites). - Container-side root logic lives in `lib/*.sh` and is INJECTED per run via `dc exec ... sh -c "$script" ` — a runtime input: no - rebuild, no fingerprint entry unless it is also COPYed - (`tests/test-volume-chown-guard.sh` pins the volume-perms driver line). + rebuild, no fingerprint entry unless it is also COPYed. The `` + operand is load-bearing and was itself unguarded: without it the first mount + point becomes `$0` and is silently never chowned + (`test: tests/test-volume-chown-guard.sh` pins the driver line, reads the + executed injection line, and asserts the argv0 is present). - `setup()` runs on EVERY cold start (gated only on `is_running`), so its steps must be idempotent and cheap. The named-volume chown is guarded by one owner+group stat, sound because `chown -R` is post-order: an interrupted - walk leaves the mount point root-owned and retries next start - (`tests/test-volume-chown-guard.sh`). + walk leaves the mount point root-owned and retries next start. That the + chown is *called* from `setup()` at all is part of the invariant and was + mutable-green until the audit — the suite exercised the lib without checking + production reached it (`test: tests/test-volume-chown-guard.sh`, which now + extracts `setup()`'s body and asserts the call). - Lock discipline: per-worktree lock on fd 9, repo-scoped build lock on fd 8; any helper backgrounded inside the locked region must be spawned with `9>&-` or it holds the worktree lock forever (`test: diff --git a/tests/lib/shellsrc.sh b/tests/lib/shellsrc.sh new file mode 100644 index 0000000..28ad5fa --- /dev/null +++ b/tests/lib/shellsrc.sh @@ -0,0 +1,102 @@ +# shellcheck shell=bash +# Shared reading of bash SOURCES for the guards that assert wiring — "production +# actually calls this" — rather than behaviour. +# +# Same rationale as tests/lib/dockerfile.sh and tests/lib/workflow-paths.sh: the +# hand-rolled form fails OPEN, so there is one implementation and a fix lands +# everywhere. Here the hand-rolled form is `grep -q '' dev/foo`, which +# matches the literal inside a COMMENT. Commenting a call out is the most common +# way code gets disabled, so the assertion stays green precisely when the wiring +# it guards has been turned off. +# +# Proven three times on this repo: `# chown_named_volume_targets (disabled)` +# passed the setup() check at 25/0; a commented-out `check-gitignore-agents` +# call passed the setup-worktree wiring check at 16/0; and prefixing the +# volume-perms driver line with `# disabled for now: ` passed at 21/0 — all with +# `tests/run-all` green. +# +# Comment stripping is deliberately naive: a `#` at line start or after +# whitespace ends the line. It can therefore truncate a line whose `#` sits +# inside a quoted string. That direction is safe — the pattern then fails to +# match and the assertion goes RED, never green — but if you hit a false FAIL on +# such a line, match a shorter prefix of it rather than reaching back for a raw +# `grep` on the unstripped file. + +# shell_strip_comments ... +# +# Emit the file with `#` comments removed, so a match means the text is not in a +# comment. NOT that it is live code — see the scope note above. +# +# Strips only `#` at line start or after whitespace. Bash actually begins a +# comment at any word-initial `#`, so `:;#real_call args` is dead code this +# leaves intact; that spelling is unnatural but it is a genuine false-pass +# direction, not merely the fail-closed truncation documented above. +shell_strip_comments() { + sed -e 's/^[[:space:]]*#.*$//' -e 's/[[:space:]]#.*$//' "$@" +} + +# assert_shell_wired