From 0d5f78b44f2ce85f0aab42f87df3d765eeee55e6 Mon Sep 17 00:00:00 2001 From: bchanot Date: Tue, 27 Oct 2026 20:12:34 +0100 Subject: [PATCH] =?UTF-8?q?chore(memory):=20LRN-235=20=E2=80=94=20feat=20e?= =?UTF-8?q?xtract-hardening,=20contract=20+=20plan=20+=20TODO=20follow-ups?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .claude/memory/journal.md | 1 + .claude/memory/learnings.md | 5 + .claude/tasks/TODO.md | 5 +- .../2026-10-27-extract-hardening-1838.md | 37 ++++++ .../2026-10-27-extract-hardening-1838.md | 115 ++++++++++++++++++ 5 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 .claude/tasks/contracts/2026-10-27-extract-hardening-1838.md create mode 100644 .claude/tasks/plans/2026-10-27-extract-hardening-1838.md diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index 1ba99a3..ebd2e25 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -664,3 +664,4 @@ rules: - /feat rules-h3-extract (feature/rules-h3-extract): extract takes `'### title'`, sections --depth 3, split S4/S0 rows; 3 lenses SOLID/CONCERNS(2)/CONCERNS(1) + confirmation FATAL(2) (LC_COLLATE glob order, re-emission leaked to ##) → r3; feater DONE 116/116; GATE 0 MET; verifier ECARTS(1 floor: SC2016 suppression) → CONFORME 8/8; auditor PASS (3 pre-existing MEDIUM queued); ab5049e. LRN-234. Merge on user go, then 0b. - Phase 0b run (10 repos, faunosteo excluded: on the user's feature branch): 3 splits on chore/claude-md-split, merge on user go — zenquality 4 rules (Memory files 19.4k → 14.5k, project row 10k → 5k), game 2 rules (16k → 14.9k), angelscar356 1 rule (16.2k → 15.4k); 7 keep-everything (overview/stack/commands/structure/conventions only, S4 rule). `gitflow start` refreshed zenquality's own .githooks → S0 STOP on a dirty tree, committed as chore ed10340, re-dispatched. Three onboarder runs in parallel, one repo each, all clean first pass. - faunosteo split on the user's feature branch (user choice): 11 rules (10 ### under Project conventions + Docker), Memory files 31.9k → 27.2k, project row 22.3k → 17.7k, 7a75974. Phase 0b done: 4 repos split, 7 keep everything. +- /feat extract-hardening (feature/extract-hardening 14a93e3 + docs 9160ce2): `_rules_out_path_ok` (absolute, `..`, exists or dangling link → rc 2, reason on stderr), mkdir + rule-write rc checked before the source rewrite, S0.3 prose in lib case order, 116 → 139 checks. Plan r1 `if ! { … } > "$out"` blind to a failed redirect (2 BLOCKER, bash 5.3.9 probe) → `|| { …; return 2; }`; r2 confirmation CONCERNS(1) (GNU mkdir stderr also says "cannot create"). Verifier CONFORME 8/8, security PASS. LRN-235. Three follow-ups in TODO (emit rc, rewrite keeps $tmp, lexical `..`). Merge on user go. diff --git a/.claude/memory/learnings.md b/.claude/memory/learnings.md index 0578dba..b51844b 100644 --- a/.claude/memory/learnings.md +++ b/.claude/memory/learnings.md @@ -250,6 +250,7 @@ rules: | LRN-232 | 2026-10-27 | Path rules load inside sub-agents (agent_id in hook log); a "does X load" proof prompt must name the Read tool call | per-repo split pass, any load proof | | LRN-233 | 2026-10-27 | Bash under pipefail: head after producer = rc 141, blanked PATH hides bash (rc 127), unchecked mktemp+rewrite chain = rc 0 with source unchanged; compgen -G no braces, dotglob over-matches, globstar skips symlinks under ** | any bash lib with pipes, temp files, globs | | LRN-234 | 2026-10-27 | Bash glob order follows LC_COLLATE, make test pins no locale: tests count or name files, never assert a listing; a new-case behaviour fix is gated on the case and proven by an old-vs-new differential on real files | any test listing a dir; any change to a lib with an existing output contract | +| LRN-235 | 2026-10-27 | bash `!` on a redirected compound command is blind to the redirect failure (rc 1 before `!`): catch with `cmd || { …; return 2; }`; a guard whose only observable is a stderr line is asserted on that line, anchored on the lib prefix | any `if ! { … } > f`; any test on a stderr reason | --- @@ -1922,3 +1923,7 @@ Rule: when editing a doctrine file under structure locks, grep the test's lock s ## LRN-234 — Glob order follows LC_COLLATE; gate a new-case fix on the case, prove the old contract by differential - **Context**: feat rules-h3-extract 2026-10-27. Confirmation challenger ran the planned suite under en_US.UTF-8: `printf '%s ' *` gave `sub2.md sub.md `, want `sub.md sub2.md ` (punctuation ignored in UTF-8 collation; C order differs). `make test` (Makefile) pins no `LC_ALL`. Same pass: `###` separator re-emission written as `RLENGTH - 1 < lvl` also fired for `##` ended by an H1 → 5 of 2,162 `##` extracts on this repo's md files changed vs develop, against the immutable REQUEST "`##` behaviour unchanged"; the suite (T7-T13) stayed green either way. - **Apply**: a test never asserts a glob listing order: count (`printf '%s\n' * | wc -l`), name files, or pin `LC_ALL=C` in the recipe. A fix for a new case is gated on that case (`lvl == 3 && …`) so the existing contract stays byte-identical, and the proof is an old-vs-new differential on real inputs (every `##` of every tracked md), not the suite alone. Also: a `# shellcheck disable` in a diff trips the floor guard unless the contract authorizes it; build the offending literal instead (`printf '\140\140\140'` for backticks). Links [[LRN-233]], [[BDR-128]], [[LRN-096]]. + +## LRN-235 — bash `!` blind to a failed redirect on a compound command; assert guards on their stderr line, anchored +- **Context**: feat extract-hardening 2026-10-27. Plan r1 wrote `if ! { printf …; body; } > "$out"; then … return 2`. Two challengers + own probe on bash 5.3.9: redirect fails → bash returns 1 BEFORE applying `!`, `if` sees false, source rewritten, rc 0 = the bug unchanged. `! { echo a; } > bad; echo $?` → 1. shellcheck clean, floor guard blind. LRN-233 form works only because its redirects sit INSIDE the group. Same pass: `grep -c 'cannot create'` on captured stderr = 2 on GNU coreutils (mkdir prints `mkdir: cannot create directory …`), 1 on uutils (this host) → host-dependent test. mkdir rc check + write rc check give same rc and same fs state; only the stderr line tells them apart. +- **Apply**: a redirected group is checked as `{ a && b; } > f || { cleanup; echo … >&2; return 2; }` (chain inside with `&&`, else the last command masks printf). Never `if ! { … } > f`. A guard whose only observable is a message gets a test on that message, `grep -c '^project-rules: …'` anchored on the lib's own prefix, never a bare word a system tool may also print. A fixture escape (`../x` from the fixture root, `ln -s /nonexistent`) runs from a subdir of the fixture and links inside it. Links [[LRN-233]], [[LRN-096]], [[BDR-128]]. diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index fd88b9c..bbf810f 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -23,7 +23,10 @@ Shared rules for every phase: - [ ] Phase 2 folds: narrow the pre-commit `.claude/**` exemption so a rules-only commit cannot land on develop/main (deferred 2026-10-26). - [x] **Phase 0b, per-repo pass** (2026-10-27: 10 repos classified; split on branches awaiting the user's merge: zenquality 1942dcf 4 rules 46%, game 527bdcc 2 rules, angelscar356 ab75ecd 1 rule; keep-everything verdict, no branch: config, integration_alphalink, robin_petier, trucks_at_work, bchanot-cv, for_you, nuit-folle (all sections always-on by the S4 rule); faunosteo 7a75974 11 rules on the user's feature branch, 31.9k → 27.2k; zenquality/game/angelscar356 merged 0ff05f1/d9be6b1/853b55b; proof per repo = the user's next session there) (after phase 0 merges; via `/onboard split`, one `chore/claude-md-split` per repo off develop, approval per repo, never an automatic merge; `/context` before/after in that repo's journal). Order by size: faunosteo 52,322 chars (on feature/v1-1-clients-animals with 5 dirty files: finish or stash first, S1 refuses otherwise), zenquality 23,378, game 14,918 (on feature/replay-hint), robin_petier 12,895, config 4,990, integration_alphalink 4,249. None has `.claude/rules/` yet; all use the `.claude/*` file form (BDR-003). Sections a sub-agent needs stay always-on unless the phase 0 sub-agent proof says path rules load there (proof 2026-10-26: they do; verify per repo). - [x] Before faunosteo: `###` granularity shipped 2026-10-27 (feature/rules-h3-extract ab5049e: `extract '### title'`, `sections --depth 3`, split rows `### `). Was: decide `###` granularity (STEP 6 review 2026-10-26). - - [ ] /hotfix after 0b, lib/project-rules.sh `extract` (security gate 2026-10-27, pre-existing, non-blocking): check the `> "$out"` group and `mkdir -p` rc before rewriting `$src` (today a failed rule write still removes the section, rc 0); `[ -e "$out" ] || [ -L "$out" ]` and refuse `..`/absolute `<out>`; onboarder S0.3 says `####x` is a bare title but the lib rejects it (align the prose). Its path-bound content (i18n, Schemas, Stores, PDF, Supabase, Storage, 12.6 KB) sits in `###` subsections of the always-on `## Project conventions`; `##`-only extract moves ~1.5% of the file. Option: `extract` accepts a `###` heading (section ends at the next heading of the same or higher level), `sections --depth 3`. User decides; `game` also has a `'` in `## 4. POINTS D'ATTENTION…` (S4 refuses it until renamed, or extract by index). + - [x] /feat extract-hardening (2026-10-27, 14a93e3: `_rules_out_path_ok` refuses absolute, `..`, existing or dangling-link out; mkdir and rule-write rc checked before the source rewrite; S0.3 prose in the lib case order; 139 checks). Was: /hotfix after 0b, lib/project-rules.sh `extract` (security gate 2026-10-27, pre-existing, non-blocking): check the `> "$out"` group and `mkdir -p` rc before rewriting `$src` (today a failed rule write still removes the section, rc 0); `[ -e "$out" ] || [ -L "$out" ]` and refuse `..`/absolute `<out>`; onboarder S0.3 says `####x` is a bare title but the lib rejects it (align the prose). Its path-bound content (i18n, Schemas, Stores, PDF, Supabase, Storage, 12.6 KB) sits in `###` subsections of the always-on `## Project conventions`; `##`-only extract moves ~1.5% of the file. Option: `extract` accepts a `###` heading (section ends at the next heading of the same or higher level), `sections --depth 3`. User decides; `game` also has a `'` in `## 4. POINTS D'ATTENTION…` (S4 refuses it until renamed, or extract by index). + - [ ] `emit`: reuse `_rules_out_path_ok` (today `-e` only, a dangling link at the target is followed) and check the `mkdir -p` and `> "$2"` rc (today "emitted" rc 0 on a failed write). + - [ ] `extract` rewrite failure mid-`cat` (ENOSPC/EIO after the truncation of `$src`): keep `$tmp` and name it on stderr instead of `rm -f` (today "$src not rewritten" can be false, the two copies gone; onboarder S1 rollback covers the split path, not direct lib use). + - [ ] shortcut `_rules_out_path_ok`: the `..` check is lexical, a symlinked parent component (`.claude` or `.claude/rules` pointing elsewhere) is not resolved; upgrade = `cd -P` on the parent dir, compare with `$PWD` (no portable `realpath -m`). - [ ] **Phase 4a, memory v2 write side: shell, no mod** (shrunk 2026-10-25: the measured recall channels never read Meta; the measured status bug is a reconcile parser bug) - Facts 2026-10-24 (scratchpad memeval, 434 entries): registries ~1M chars, never in always-on context, read only by /feat /bugfix /ship-feature (analyze-before-plan); Index drift 6 rows; status in 3 places (title tag, body Status line, Index column) → reconcile false-open BLK-032..034; no single writer (Edit needs a Read of a 357k file, so real writes are ad hoc python/bash); 8 projects on this machine hold v1 registries. Verified 2026-10-25: `lib/reconcile.sh:60-67` drops the entry's OWN header while BLK-032..034 carry `[resolved]` there (the false-open); nothing machine-reads `## Index` (analyze-before-plan.md:42, reconcile.sh:9, test T1); 1 of 1,290 entries across the 8 projects above a 1% accent ratio. diff --git a/.claude/tasks/contracts/2026-10-27-extract-hardening-1838.md b/.claude/tasks/contracts/2026-10-27-extract-hardening-1838.md new file mode 100644 index 0000000..ec6c6d6 --- /dev/null +++ b/.claude/tasks/contracts/2026-10-27-extract-hardening-1838.md @@ -0,0 +1,37 @@ +# CONTRACT — extract-hardening +- date: 2026-10-27 | flow: feat | branch: feature/extract-hardening (off develop 06012ea) +- status: active + +## REQUEST (verbatim — IMMUTABLE) +lib/project-rules.sh `extract` hardening (TODO.md line 26, security gate 2026-10-27 follow-up): (1) check the rc of the `> "$out"` rule write group and of `mkdir -p` before rewriting `$src`, so a failed rule write leaves the source untouched and returns rc 2 (today the section is still removed with rc 0); (2) refuse an `<out>` that already exists (`[ -e "$out" ] || [ -L "$out" ]`), is absolute, or contains a `..` component, rc 2 with nothing written; (3) align agents/onboarder.md MODE: split S0.3 prose with the lib (`####x` is rejected, not a bare title). Tests in lib/tests/project-rules.test.sh for each refusal and for the untouched source on a failed write. + +## CLARIFICATIONS +(pass A: none — request complete) + +## ACCEPTANCE CRITERIA +1. `extract` whose `mkdir -p "$(dirname "$out")"` fails (a file sits where the parent dir must be) is rc 2, nothing written, source unchanged. +2. `extract` whose rule write (`{ … } > "$out"`) fails (parent dir not writable) is rc 2, no rule file left behind, source unchanged: the heading still occurs once. + CHECK: bash lib/tests/project-rules.test.sh | tail -1 + EXPECT: FAIL=0 + EVIDENCE: MET exit=0 marker-found :: PASS=139 FAIL=0 +3. `extract` refuses, rc 2 and nothing written: an absolute `<out>`, an `<out>` with a `..` component (`a/../b`, `../b`, `a/..`), an `<out>` that exists, an `<out>` that is a dangling symlink (`-L` true, `-e` false). The refusal names the reason on stderr. Each refusal runs before any glob check or temp file. +4. Every pre-existing extract contract holds: T7-T13 of the suite unchanged and green; `##` behaviour byte-identical (no change to the awk helpers). +5. `agents/onboarder.md` MODE: split S0.3 follows the lib's case order, refusal first: a heading starting with `# ` or `####` (space or not) is refused by the lib (rc 2, STOP with the row); a row starting with `## ` → STOP (a bare row carries no `## `); then `### ` is a subsection; then any other leading `#` (`#1 priority`) is a bare `##` title. A sequential reader can no longer land `####x` on the bare-title clause. No other prose change. + CHECK: grep -q '####' agents/onboarder.md && echo H4-NAMED + EXPECT: H4-NAMED + EVIDENCE: MET exit=0 marker-found :: H4-NAMED +6. `lib/project-rules.sh` stays shellcheck clean, every line ≤ 80 chars, functions ≤ 25 logic lines and ≤ 5 locals; no `# shellcheck disable` added. + CHECK: shellcheck lib/project-rules.sh lib/tests/project-rules.test.sh && [ -z "$(awk 'length > 80' lib/project-rules.sh)" ] && ! grep -q 'shellcheck disable' lib/project-rules.sh && echo WIDTH-OK + EXPECT: WIDTH-OK + EVIDENCE: MET exit=0 marker-found :: WIDTH-OK +7. `make test` all GREEN. + CHECK: make test 2>&1 | tail -1 + EXPECT: all suites green + EVIDENCE: MET exit=0 marker-found :: all suites green +8. `bash lib/project-rules.sh check` still prints `4 rule(s) ok` on this repo. + CHECK: bash lib/project-rules.sh check | tail -1 + EXPECT: project-rules: 4 rule(s) ok + EVIDENCE: MET exit=0 marker-found :: project-rules: 4 rule(s) ok + +## FILE SCOPE +lib/project-rules.sh, lib/tests/project-rules.test.sh, agents/onboarder.md (§ MODE: split S0.3 only) diff --git a/.claude/tasks/plans/2026-10-27-extract-hardening-1838.md b/.claude/tasks/plans/2026-10-27-extract-hardening-1838.md new file mode 100644 index 0000000..3799354 --- /dev/null +++ b/.claude/tasks/plans/2026-10-27-extract-hardening-1838.md @@ -0,0 +1,115 @@ +# PLAN — extract-hardening (feat, 2026-10-27, r2 after the 3-lens challenge) +Contract: `.claude/tasks/contracts/2026-10-27-extract-hardening-1838.md` + +## Files +- `lib/project-rules.sh` — `project_rules_extract` (lines 185-205); one new helper `_rules_out_path_ok` placed right before it. +- `lib/tests/project-rules.test.sh` — new blocks `T9o`..`T9z` after T9k (line ~184), before T10. +- `agents/onboarder.md` — MODE: split S0.3, lines 213-215 (the heading sentence only). + +## Approach +1. New helper, same shape as `_rules_heading_line` (stderr message + rc 2). The `..` check is lexical, on the argument string; a symlinked component is not resolved (no GNU-only `realpath -m`), named by a `shortcut:` comment: + ```bash + _rules_out_path_ok() { # <out> → rc 2 when absolute, has a .. part, or exists + # shortcut: lexical only, a symlinked component is not resolved (no + # portable realpath -m); upgrade = resolve the parent dir with cd -P + case "$1" in + /*) echo "project-rules: out must be relative: $1" >&2; return 2 ;; + ..|../*|*/..|*/../*) + echo "project-rules: out must not contain ..: $1" >&2; return 2 ;; + esac + if [ -e "$1" ] || [ -L "$1" ]; then + echo "project-rules: $1 exists" >&2; return 2 + fi + } + ``` + `a/../b`, `../b`, `a/..` and `..` each match one of the four patterns; `a/..b` or `..a` do not (ordinary names). Keep the existing `$out exists` wording so T8c reads the same. +2. In `project_rules_extract`, replace line 191 (`[ -e "$out" ] && …`) by `_rules_out_path_ok "$out" || return 2`, same position: after the heading-count check, before `_rules_globs_all_match` (no glob check, no temp file before a refusal). +3. `mkdir -p` checked in the file's one-statement idiom (line 194 form), before `mktemp`: + ```bash + mkdir -p "$(dirname "$out")" \ + || { echo "project-rules: cannot create $(dirname "$out")" >&2; return 2; } + ``` +4. The rule write becomes a checked statement. NOT `if ! { …; } > "$out"`: when the redirection of a compound command fails, bash returns 1 before applying `!`, so the failure is missed (probed on bash 5.3.9: `if ! { echo hi; } > /proc/nowhere/x` prints MISSED). The `||` form catches it (probed: rc 2). `printf` and the body are chained with `&&` so a failed printf is not masked by an empty body: + ```bash + { printf -- '---\npaths: %s\n---\n\n# %s\n' "$globs" "${hline#* }" \ + && _rules_section_body "$src" "$hline"; } > "$out" \ + || { rm -f "$tmp" "$out" + echo "project-rules: $out not written, $src untouched" >&2 + return 2; } + ``` + Then the existing source rewrite block (lines 197-202), unchanged. The three awk helpers are not touched (`##` behaviour byte-identical). +5. Logic-line budget: the helper absorbs the three path refusals; `project_rules_extract` stays ≤ 25 logic lines and 5 locals (`src out globs hline tmp`). Every line ≤ 80 chars (the `||` lines above are ≤ 79). No `# shellcheck disable`. +6. `agents/onboarder.md` S0.3: replace + `a heading whose leading `#` run is followed by a space starts with `### `; any other leading `#` is a bare `##` title (`#1 priority`);` + by the lib's case order, refusal first: + `a heading starting with `# ` or `####` (space or not) is refused by the lib (rc 2): STOP with the row; one starting with `## ` → STOP too (a bare row carries no `## `); one starting with `### ` is a subsection; any other leading `#` is a bare `##` title (`#1 priority`);` + Nothing else in the file changes. (The lib passes `'## '*` through as written; a row written that way would be looked up as `## ## Foo` at S0.4, so S0.3 stops it, as today's prose does.) + +## Edge cases +- Dangling symlink as `<out>`: `-e` false, `-L` true → refused, the link stays. +- `mkdir -p` ENOTDIR: a regular file where the parent dir must be; the stderr line `cannot create` is what distinguishes this guard from the write check (both give rc 2 and an untouched source), so the test asserts it. +- Write failure independent of root: `<out>` with a trailing slash (`.claude/rules/beta.md/`) passes the path helper, `mkdir -p .claude/rules` succeeds, the open fails with EISDIR; nothing is created. The chmod-based case (`ro/`) stays as the second probe, with the LRN-233 root limit. +- `rm -f "$tmp"` on the write-failure path: `$tmp` exists at that point (mktemp ran before the write). +- All refusals rc 2, never 1. Each new refusal is asserted by its stderr reason, not by rc alone (rc 2 is shared). + +## Tests (lib/tests/project-rules.test.sh, after T9k, in the `$FIX` root where CLAUDE.md holds `## Beta` once; `src/app.ts` exists there) +```bash +# T9o extract refuses an absolute, a .. or a symlinked <out>, before any write, +# each refusal named on stderr +err=$(bash "$PR" extract CLAUDE.md 'Beta' "$FIX/abs.md" '["nowhere/**"]' 2>&1 >/dev/null) +check T9o-absolute-out-rc "$?" 2 +check T9o2-absolute-reason-before-globs "$(printf '%s\n' "$err" | grep -c 'must be relative')" 1 +check T9p-absolute-nothing-written "$([ -e "$FIX/abs.md" ] && echo yes || echo no)" no +err=$(bash "$PR" extract CLAUDE.md 'Beta' .claude/rules/../escape.md '["src/**"]' 2>&1 >/dev/null) +check T9q-dotdot-out-rc "$?" 2 +check T9q2-dotdot-reason "$(printf '%s\n' "$err" | grep -c 'must not contain')" 1 +check T9r-dotdot-nothing-written "$([ -e .claude/escape.md ] && echo yes || echo no)" no +bash "$PR" extract CLAUDE.md 'Beta' nope/.. '["src/**"]' 2>/dev/null +check T9r2-trailing-dotdot-rc "$?" 2 +check T9r3-trailing-dotdot-no-dir "$([ -e nope ] && echo yes || echo no)" no +mkdir -p "$FIX/sub/src" && cd "$FIX/sub" || exit 1 +echo x > src/a.ts +printf '## Beta\nbbb\n' > CLAUDE.md +bash "$PR" extract CLAUDE.md 'Beta' ../escape.md '["src/**"]' 2>/dev/null +check T9s-leading-dotdot-rc "$?" 2 +check T9s2-leading-dotdot-nothing-written "$([ -e "$FIX/escape.md" ] && echo yes || echo no)" no +cd "$FIX" || exit 1 +ln -s "$FIX/absent.md" .claude/rules/dangling.md +err=$(bash "$PR" extract CLAUDE.md 'Beta' .claude/rules/dangling.md '["src/**"]' 2>&1 >/dev/null) +check T9t-dangling-symlink-rc "$?" 2 +check T9t2-dangling-reason "$(printf '%s\n' "$err" | grep -c 'exists')" 1 +check T9u-dangling-still-link "$([ -L .claude/rules/dangling.md ] && echo yes || echo no)" yes +rm -f .claude/rules/dangling.md +check T9v-refusals-keep-beta "$(grep -c '^## Beta' CLAUDE.md)" 1 + +# T9w a failed mkdir (named on stderr) or a failed rule write is rc 2, the +# source untouched and no rule left behind; the trailing-slash case holds as root +touch .claude/rules/notadir +err=$(bash "$PR" extract CLAUDE.md 'Beta' .claude/rules/notadir/beta.md '["src/**"]' 2>&1 >/dev/null) +check T9w-mkdir-fails-rc "$?" 2 +check T9w2-mkdir-fails-reason "$(printf '%s\n' "$err" | grep -c '^project-rules: cannot create')" 1 +check T9x-mkdir-fails-beta-kept "$(grep -c '^## Beta' CLAUDE.md)" 1 +bash "$PR" extract CLAUDE.md 'Beta' .claude/rules/beta.md/ '["src/**"]' 2>/dev/null +check T9x2-eisdir-write-rc "$?" 2 +check T9x3-eisdir-beta-kept "$(grep -c '^## Beta' CLAUDE.md)" 1 +check T9x4-eisdir-nothing-written "$([ -e .claude/rules/beta.md ] && echo yes || echo no)" no +mkdir .claude/rules/ro && chmod a-w .claude/rules/ro +bash "$PR" extract CLAUDE.md 'Beta' .claude/rules/ro/beta.md '["src/**"]' 2>/dev/null +check T9y-write-fails-rc "$?" 2 +check T9z-write-fails-beta-kept "$(grep -c '^## Beta' CLAUDE.md)" 1 +check T9z2-write-fails-no-rule "$([ -e .claude/rules/ro/beta.md ] && echo yes || echo no)" no +chmod u+w .claude/rules/ro +``` +Lines over 80 chars in the test file follow the file's existing practice (T9e already exceeds it); the width limit in AC6 applies to the lib. `err` reuses the T5h variable (line 78); every use follows its own assignment. No `ls`, no `wc` (SC2012, BSD padding). Suite total: 116 + 23 = 139 checks, FAIL=0, if the count differs the names above are the reference, not the number. + +## Follow-ups (TODO.md, not this run; REQUEST is extract-only) +- `emit`: reuse `_rules_out_path_ok`, check `mkdir -p` and the `> "$2"` write rc (today "emitted" rc 0 on failure, `-e` only so a dangling link is followed). +- `extract` rewrite failure mid-`cat` (ENOSPC/EIO after truncation): keep `$tmp` and name it on stderr instead of `rm -f` (today the message "$src not rewritten" can be false). +- `_rules_out_path_ok` shortcut: `..` check is lexical, a symlinked component (`.claude` or `.claude/rules` pointing elsewhere) is not resolved; upgrade = `cd -P` on the parent dir, compare against `$PWD`. +- The main loop writes these three lines under TODO.md at CAPITALIZE; the executor touches no file outside FILE SCOPE. + +## Disposition +- honors LRN-233 by: redirection failures caught with `cmd || { …; return 2; }` (the `if ! { …; } > f` form proven blind on bash 5.3.9), `printf && body` chained, one failure-path test per new rc check with its stderr reason, `mktemp` still checked. +- honors LRN-234 by: no glob listing order asserted, no `# shellcheck disable`, the awk helpers untouched so `##` stays byte-identical. +- honors LRN-096 by: every new guard has a flip test that goes red when the guard is removed (reason on stderr, file state), never rc 2 alone. +- honors BDR-128 by: refusals stay in the one oracle, rc 2, culprit named on stderr; `/onboard split` prose follows the lib's case order.