* test(#3003): failing-first suite for declared deletions in cleanup-wave Binds the guard's opt-in before it exists, so the suite is RED against next. The rows that carry the weight are the over-authorization set: a directory declaration must not authorize its children, a glob declaration must authorize nothing, and a declaration must not act as a string prefix of another path. Each of those BLOCKS, and each would PASS under a prefix, glob, or startsWith matcher — which is how a path list quietly degrades into the boolean opt-in #3003 explicitly rejected. The glob row matters most: declaredScopePrefix already returns null ("matches everything") for a glob-leading pattern, correct for the advisory it serves and catastrophic for a gate. Also pinned: a failed deletion check blocks on its own reason rather than being filtered into a pass; the block detail names only the undeclared residue so the operator is not misdirected by paths that were fine; an entry with no declaration blocks exactly as before; junk and non-array declarations do not authorize; and a blocked entry still isolates rather than aborting the wave (#2852, which must stay fixed). Two advisory rows cover an interaction found while designing: git diff --name-only includes deleted paths, so without unioning the declaration into the #2596 scope check, authorizing a deletion would raise SCOPE_OUT_OF_DECLARED against the very path just authorized. A seeded property states the whole invariant the three over-authorization rows sample: a deletion merges iff its normalized path is in the declared set. * feat(#3003): declared deletions opt-in for the cleanup-wave guard The deletions guard blocked the merge-back of any executor branch whose diff removed a file, with no way to say a removal was intended. A plan that folded one test file into a sibling could not be merged by the tool meant to merge it, forcing a manual --no-ff outside the tool -- strictly less safe than what the guard protects against. A plan now declares removals in its own frontmatter (files_deleted), and that list rides the same path files_modified already travels: plan-document parse -> phase plan JSON -> the per-plan worktree gate -> record-agent/create --deletions -> declared_deletions on the manifest entry -> the guard. The guard blocks only the deletions NOT in that list. A path list rather than a boolean, per the pinned decision: a boolean disarms the guard for the whole entry, so an unexpected deletion riding along with a declared one would pass unnoticed. Matching is exact after the module's shared normalizer -- never a prefix, never a glob. Both would let one declaration authorize a whole set, which is the mass-deletion accident the guard exists to catch. That also means declaredScopePrefix is deliberately NOT reused here: it returns null ("matches everything") for a glob-leading pattern, which is right for the advisory it serves and would silently disarm a gate. The block detail now carries only the undeclared residue, so an operator is not sent looking at paths that were fine. A failed deletion check still blocks on its own reason and is never filtered into a pass. A blocked entry still isolates rather than aborting the wave (#2852). The #2596 scope advisory unions the declaration into its declared set -- git diff --name-only includes deleted paths, so without that, authorizing a deletion would immediately warn that the same path was out of declared scope. Optional and additive throughout: files_deleted is absent from PLAN_REQUIRED_FIELDS, a manifest entry without declared_deletions keeps the original unconditional block, and omitting --deletions leaves the on-disk entry shape untouched. Supersedes the spent #2856 emitted-drift ack entry for execute-phase.md, the same supersede that entry performed on #3370 and #3370 on #3324. * fix(#3003): wire --deletions on every dispatch surface, not just one Review found the feature inert on two of three dispatch paths. execute-phase.md (harness inline) passed --deletions, but the orchestrator-worktree path (executor-isolation-dispatch.md, worktree.create) and the Fleet-parallel batch path (capabilities/claude-orchestration/fragments/execute-wave-pre.md, worktree.record-agent) still passed only --files. A plan declaring files_deleted would have merged on one path and been blocked on the other two -- the exact bug #3003 exists to fix, left unfixed where most of the isolation actually runs. Worse, per-plan-worktree-gate.md already claimed --deletions was passed 'on the same worktree.record-agent / worktree.create calls', which was false for both untouched sites. A doc asserting coverage that does not exist is how a gap survives review. All four surfaces now pass the flag, verified by sweeping every .md under gsd-core/, capabilities/, commands/, skills/ and agents/ that invokes worktree.record-agent or worktree.create: each one that passes --files now also passes --deletions. The isolation-dispatch note explains why this flag, unlike --files, is not advisory -- omitting it does not skip a check, it blocks a merge the plan declared. Regenerates capability-registry.cjs, which the fragment edit made stale. Neither newly-grown file needs an emitted-drift ack: executor-isolation-dispatch.md sits under workflows/execute-phase/steps/ and execute-wave-pre.md under capabilities/, both outside currentSizes()'s non-recursive scan of gsd-core/workflows/ and agents/. * docs(#3003): document files_deleted where a plan author will actually find it The feature's entire user surface is one plan-frontmatter field, and the canonical reference for that frontmatter -- docs/reference/plan-md.md, the table that documents every other key -- never mentioned it. A field nobody can discover ships as a field nobody uses. Adds the files_deleted row and an example entry in all five locales (en, ja-JP, zh-CN, ko-KR, pt-BR), stating the property that makes the opt-in safe: matching is exact per path after separator normalization, with no globs and no directory prefixes, so a declaration can never authorize more than it literally lists, and omitting the field keeps the guard's original unconditional block. Also corrects two claims in the scope-conformance how-to that this change made false. Its opening paragraph described the recorded declared scope as files_modified alone; declared_deletions is now unioned into that comparison. Its "Renames are not detected specially" bullet asserted the deletions guard blocks any entry whose diff contains a deletion, full stop -- which was the whole point of #3003 and is no longer true. Reworked to say what now decides a rename's fate: declare the old path in files_deleted and both halves become ordinary paths for the advisory check, which is also why the old path needs no separate files_modified entry. Documentation that describes the pre-change behavior of the thing being changed is worse than no documentation, because a reader trusts it. * fix(#3003): close every review finding on the declared-deletions opt-in Two independent isolated reviewers, correctness and security. Neither found a blocker; both found real defects, and the directive treats a finding at any severity as blocking. All of them are fixed here. MAJOR -- the submodule worktree gate could not see a deletion-only plan. per-plan-worktree-gate.md intersected $SUBMODULE_PATHS against $PLAN_FILES alone, while $PLAN_DELETIONS was extracted and then never used. Before files_deleted existed, a path had to appear in files_modified to be planned at all, so the gate saw it; the new field plus the new docs telling authors a deleted path needs no files_modified entry opened a hole where a plan whose only submodule touch is a removal kept worktree isolation on -- the exact case #2772 disabled it for. Both channels now feed the intersection. Note the posture is deliberately the OPPOSITE of the cleanup-wave guard: there the channels stay apart because a deletion AUTHORIZATION must never be inferred; here they merge because a safety fallback must never MISS a touch. MAJOR -- same-wave conflict detection could not see a deletion. The planner's implicit-dependency rule compared files_modified only, so plan A editing src/x.ts and plan B declaring files_deleted: [src/x.ts] scored as conflict-free and ran in parallel: one branch removing what the other is writing, which is the sharpest conflict there is. Overlap is now computed across both channels. MINOR (both reviewers, one root cause) -- the advisory union gave one field two matching rules. declared_deletions was unioned into the scope list handed to planWaveScopeConformance, which reads it with prefix-and-glob semantics. So a field that is exact-match-only at the gate silently became wider at the advisory: ["*.md"], inert at the gate, yielded a null prefix meaning "matches everything" and muted the advisory completely, and ["src"] muted all of src/. The union also activated the advisory on plans that declared no modification scope at all, warning on every modified path. Replaced with subtraction from the findings, gated on files_modified alone. One field, one rule, everywhere. MINOR -- core.quotepath made the feature silently inert for non-ASCII paths. git emits "tests/\303\251.ts" C-escaped and quoted, which never equals the declared plain path, so a correctly declared deletion of tests/é.ts would block forever with nothing pointing at the encoding. Both diffs now pass -c core.quotepath=false. NIT -- flag() consumed a following flag as a value, so --deletions --files x swallowed --files and dropped both. Now treated as a missing declaration, which fails closed. Fixed at both call sites; the helper is duplicated verbatim in cmdWorktreeRecordAgent and cmdWorktreeCreate and leaving one would reintroduce it. TEST -- one test passed for the wrong reason. "a declared deletion is in scope for the advisory" asserted only that warnings omit the deleted path; under a full revert the entry blocks first, warnings come back empty, and the negative assertion passes anyway. It now asserts the entry actually merged, which is the load-bearing half. Four regressions added, one per fix above. Docs corrected rather than extended. The rename bullet in the scope-conformance how-to claimed a rename whose delete side is undeclared never reaches the advisory. Verified false: git's rename detection is on by default, so a pure rename is a single R entry that appears in no --diff-filter=D output and was never gated, before or after #3003. Only a rename that edits enough to fall below the similarity threshold decomposes into add+delete. The pre-existing sentence made the same wrong claim; this restates it correctly instead of sharpening the error. The localized plan-md.md reference edits are reverted: the PR template requires docs content added here to be English, and the translations already lag by three fields, so English-only is the repo's standing posture, not an oversight. Agent-file size caps respected: gsd-planner.md is XL-tier by bytes but carries a separate 49152-LF-CHAR cap asserted by four suites, so its edit is deliberately terse and lands at 49141 with 11 chars of headroom, with the rationale moved to docs/reference/plan-md.md, which has no cap. gsd-plan-checker.md lands at 49107 bytes, 45 under the LARGE cap. Both acks merged into the existing fragments that already name those paths, since two ack sources may never name the same path. * fix(#3003): decode git's path quoting instead of changing the git argv The previous commit's non-ASCII fix turned the remote suite red: 44 failures, 42 of them "unexpected git call: -c core.quotepath=false diff --diff-filter=D --name-only ...". The suite's git mocks match on exact argv, so adding two flags to the deletions diff and the advisory diff invalidated every existing fixture in tests/worktree-safety.test.cjs. Rewriting dozens of fixtures to accommodate one flag would be paying a large Hyrum's-law bill to fix a small defect. Both execGit calls are reverted to their original argv. The C-quoting is now decoded in normalizeScopePath instead, via a new decodeGitQuotedPath helper. That is the better fix on its own merits, not merely the cheaper one: the git argv is untouched so no fixture moves, the decode lands on the ONE normalizer already applied to both sides of the comparison so the declared and reported paths cannot disagree, and it holds regardless of the user's own core.quotepath setting rather than only when we remember to override it. A value not wrapped in a leading AND trailing quote is returned completely untouched, so the plain-ASCII path -- the overwhelmingly common case -- is byte-identical to before. Escapes decode to BYTES collected into a Buffer and UTF-8 decoded only at the end, because \303\251 is two bytes forming one character and decoding them separately yields mojibake. Malformed input never throws: a trailing lone backslash or a short octal escape degrades to the literal character, since one bad path must not take down a cleanup wave. Caught while reviewing the helper: the non-escape branch pushed a UTF-16 code unit rather than UTF-8 bytes. Git always escapes non-ASCII so its own output was fine, but this normalizer runs on the DECLARED side too, and an author may write a quoted path holding a literal é -- pushing 0xE9 alone is invalid UTF-8, so the declaration would decode to a replacement character and silently stop matching. That is precisely the failure this change removes, reintroduced on the other side of the comparison. Now converts whole code points, surrogate pairs intact. The other 2 failures: tests/parallel-dependent-plans.test.cjs pins the exact unbackticked substring "files_modified overlap" in gsd-planner.md, and rewording that comment to "declared-scope overlap" deleted it. The comment is restored verbatim and the files_deleted change rides in the pseudocode and the Rule sentence instead. Recorded in the ack fragment so the next contributor does not rediscover it the same way. Four regression tests cover the decode through the public cleanup-wave seam (the helper is module-private): a declared non-ASCII deletion merges against a C-quoted git report, the symmetric case where the DECLARATION is the quoted form, an undeclared non-ASCII deletion still blocks with the residue naming the decoded path an operator can act on, and a path merely containing a quote is left alone. Plain ASCII was already covered and is not duplicated. * fix(#3003): revert the leading-dash flag guard, the review nit was wrong The remote suite came back with 2 failures, down from 44, and both point at the same thing: tests/worktree-safety.test.cjs:7045 already pins the opposite contract, deliberately. test('a flag-shaped --files value is not re-parsed as a flag', ...) recordAgent(['--files', '--branch']) -> files_modified === ['--branch'] -> branch === 'worktree-agent-a1' ("the real --branch value must be untouched") So consuming the next argv element positionally, whatever its shape, is the tested intent of this parser, not an oversight. The security reviewer's nit claimed --deletions --files x would "swallow --files and drop both". It does not: each flag runs its own indexOf, so --deletions records the literal '--files' while --files independently still resolves to x. And that literal is a path git never reports as deleted, so it authorizes nothing -- already fail-closed with no guard at all. The guard bought no safety and silently changed --files behavior along the way, outside this issue's scope. Reverted at both call sites, which are byte-identical again, along with the test asserting the reverted behavior and the docs sentence describing it. The nit is recorded as REJECTED in the review artifact with the reasoning above, rather than as fixed -- a finding that turns out to be wrong should leave a trace of why, or the next reviewer files it again. docs/CLI-TOOLS.md now states the positional-read behavior plainly instead, so the next person meets it as documented intent rather than rediscovering it through a red suite. * chore(#3003): backfill changeset pr number to 3757 * test(#3003): cover parsePlanDocument's filesDeleted branch to clear the mutation gate CI's Stryker shard for plan-document failed at 73.28 against a break threshold of 75: 170 killed, 62 survived, 232 total. Eight of those survivors are the filesDeleted block this issue added to parsePlanDocument, which shipped with no direct coverage at all -- the field was exercised end to end through the cleanup-wave tests, but the parser itself was never called with a plan that declares it, so every mutant in the block lived. Four tests, each pinned to specific mutants rather than written for coverage percentage: - absent key yields exactly [] -- kills the array-literal seed (["Stryker was here"]) and the `fmDeleted = true` conditional, which would otherwise produce ["true"] - a scalar underscore `files_deleted:` wraps into a one-element array -- kills `fmDeleted = false`, the `&&` logical-operator swap, the `fm[""]` string mutation on the first operand, the emptied if-block, and the ternary's non-array branch - an array-valued hyphenated `files-deleted:` maps element-wise -- kills the `fm[""]` mutation on the SECOND operand (only reachable when the legacy hyphen alias is the one carrying the value) and the ternary's array branch - an empty list yields [] -- boundary case, and a genuinely distinct one from the absent key: [] is truthy in JS so it ENTERS the if, and only Array.isArray's true branch mapping over nothing produces the same [] Threshold arithmetic: 174 of 232 are needed for 75%, and these take it to about 178, so the shard clears with margin rather than landing on the line. Every expected value was confirmed by executing the built parser before being asserted, not inferred from reading the source. --------- Co-authored-by: sim <sim@local>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": 1,
|
||||
"paths": {
|
||||
"gsd-plan-checker.md": "#1954: Dimension 3 gains sub-dimension 3b (undeclared / temporal coupling), plus one success-criteria line. Growth is the new sub-dimension only — no existing text was rewritten. The addition is deliberately dense rather than extracted: ADR-1610 Decision 4 names eager `@`-import relocation as proxy-gaming (it shrinks the measured file while leaving loaded context unchanged or larger), legitimate extraction is Read-at-step lazy, and this agent has no lazy-read seam; issue #1954's approved scope is also explicitly 'No new files'. After the change the file sits at 48810 bytes against the LARGE tier hard cap of 49152 (tests/agent-size-budget.test.cjs), i.e. 342 bytes of headroom. That is deliberate and disclosed: the cap is not crossed and is not raised, but the next contributor who needs room in this agent must do a lazy extraction rather than add prose. Content justification: Dimension 3 proves declared dependency edges resolve and are acyclic, and execute-phase's intra-wave guard proves same-wave plans do not overlap in files_modified — neither axis sees an undeclared edge, so two same-wave plans coupled through a shared config key, table, migration, env var, singleton or cache (or through one plan's produced state) pass plan-check and fail intermittently under parallel execution. 3b is advisory only (WARNING, never blocker, per the issue's rejected-alternatives list) and reuses the existing dependency_correctness finding key so no consumer sees a new dimension. — #2401 append (merged into this fragment because two ack sources may never name the same path): the Verify Command Path Resolvability dimension is now a short stub pointing at the extracted gsd-core/references/verify-command-path-resolvability.md (the full dimension body — including the {VERIFY_PATHS} probe-consumption rules and severity/reason table — moved out to stay under the LARGE cap). The file is now 49064 bytes, 88 bytes of headroom under the same 49152 LARGE cap."
|
||||
"gsd-plan-checker.md": "#1954: Dimension 3 gains sub-dimension 3b (undeclared / temporal coupling), plus one success-criteria line. Growth is the new sub-dimension only — no existing text was rewritten. The addition is deliberately dense rather than extracted: ADR-1610 Decision 4 names eager `@`-import relocation as proxy-gaming (it shrinks the measured file while leaving loaded context unchanged or larger), legitimate extraction is Read-at-step lazy, and this agent has no lazy-read seam; issue #1954's approved scope is also explicitly 'No new files'. After the change the file sits at 48810 bytes against the LARGE tier hard cap of 49152 (tests/agent-size-budget.test.cjs), i.e. 342 bytes of headroom. That is deliberate and disclosed: the cap is not crossed and is not raised, but the next contributor who needs room in this agent must do a lazy extraction rather than add prose. Content justification: Dimension 3 proves declared dependency edges resolve and are acyclic, and execute-phase's intra-wave guard proves same-wave plans do not overlap in files_modified — neither axis sees an undeclared edge, so two same-wave plans coupled through a shared config key, table, migration, env var, singleton or cache (or through one plan's produced state) pass plan-check and fail intermittently under parallel execution. 3b is advisory only (WARNING, never blocker, per the issue's rejected-alternatives list) and reuses the existing dependency_correctness finding key so no consumer sees a new dimension. — #2401 append (merged into this fragment because two ack sources may never name the same path): the Verify Command Path Resolvability dimension is now a short stub pointing at the extracted gsd-core/references/verify-command-path-resolvability.md (the full dimension body — including the {VERIFY_PATHS} probe-consumption rules and severity/reason table — moved out to stay under the LARGE cap). The file is now 49064 bytes, 88 bytes of headroom under the same 49152 LARGE cap. — #3003 append (merged into this fragment because two ack sources may never name the same path): Dimension 3b's description of what the wave guard already covers now names both declared-scope channels (`files_modified`/`files_deleted`), so a delete-vs-modify pair between same-wave plans is attributed once on the file axis rather than re-reported as undeclared coupling. +43 bytes, landing at 49107 with 45 bytes of headroom under the same cap — the 88-byte warning above still stands and is now tighter."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"version": 1,
|
||||
"paths": {
|
||||
"gsd-planner.md": {
|
||||
"reason": "#2775: the STRIDE supply-chain row for npm/pip/cargo installs was rewritten from 'slopcheck + blocking human checkpoint for [ASSUMED]/[SUS]' to 'package-legitimacy gate + blocking human checkpoint for [ASSUMED]/[SUS]', matching ADR-0656 (registry-API verdicts are the gate; slopcheck is an optional escalate-only adapter no shipped configuration wires). The +14 bytes is the corrected mitigation description agents read at plan time, not incidental prose growth. #3565 appends the fenced `## Return Markers` section (~1.2 KB) enumerating the six exact stall-watch dispatch markers plan-phase.md matches on — the new registry lint requires every declared marker to be emitted in-fence by its producer, and the planner previously documented none of them anywhere. #2401 append (merged into this fragment because two ack sources may never name the same path): the 'Inherit the command that already worked' paragraph is now a short pointer to the extracted gsd-core/references/planner-verify-command-grounding.md (prior_verify_commands inheritance, npm --prefix grounding rules, and the guessing prohibition all moved to the reference). The file is now 49274 bytes, well under the XL tier's 57344-byte cap, and 49077 chars (LF-normalized) under the separate 49152-char cap asserted by tests/planner-decomposition.test.cjs, tests/precondition-element.test.cjs, tests/reversibility-tagging.test.cjs, and tests/security.test.cjs."
|
||||
"reason": "#2775: the STRIDE supply-chain row for npm/pip/cargo installs was rewritten from 'slopcheck + blocking human checkpoint for [ASSUMED]/[SUS]' to 'package-legitimacy gate + blocking human checkpoint for [ASSUMED]/[SUS]', matching ADR-0656 (registry-API verdicts are the gate; slopcheck is an optional escalate-only adapter no shipped configuration wires). The +14 bytes is the corrected mitigation description agents read at plan time, not incidental prose growth. #3565 appends the fenced `## Return Markers` section (~1.2 KB) enumerating the six exact stall-watch dispatch markers plan-phase.md matches on — the new registry lint requires every declared marker to be emitted in-fence by its producer, and the planner previously documented none of them anywhere. #2401 append (merged into this fragment because two ack sources may never name the same path): the 'Inherit the command that already worked' paragraph is now a short pointer to the extracted gsd-core/references/planner-verify-command-grounding.md (prior_verify_commands inheritance, npm --prefix grounding rules, and the guessing prohibition all moved to the reference). The file is now 49274 bytes, well under the XL tier's 57344-byte cap, and 49077 chars (LF-normalized) under the separate 49152-char cap asserted by tests/planner-decomposition.test.cjs, tests/precondition-element.test.cjs, tests/reversibility-tagging.test.cjs, and tests/security.test.cjs. #3003 append (merged into this fragment because two ack sources may never name the same path): the implicit-dependency wave rule now computes same-wave overlap over files_modified PLUS files_deleted, so a plan deleting a file another same-wave plan edits is pushed to a later wave instead of racing it -- one branch removing what the other is writing is the sharpest conflict there is, and reading files_modified alone scored that pair conflict-free. Deliberately terse (+56 LF chars, landing at 49133 against the 49152-char cap named above, 19 chars of headroom). The `# Implicit dependency: files_modified overlap forces a later wave.` comment is left VERBATIM: tests/parallel-dependent-plans.test.cjs matches that exact unbackticked substring, so rewording it to name the new channel reds the suite -- the files_deleted addition rides in the pseudocode and the Rule sentence instead: the rationale is carried in docs/reference/plan-md.md, which has no cap. The next contributor who needs room in this agent must extract, not add prose."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"version": 1,
|
||||
"paths": {
|
||||
"execute-phase.md": {
|
||||
"reason": "#2856 \u2014 step 5.75 now dispatches every `kind == \"step\"` at execute:wave:post. That point previously dispatched only contribution and gate, so any registered step was declared and silently never run; the capability validator refuses to generate a registry containing such a step. Also adds the validate-ref.command-before-shell warning matching the sibling gate-dispatch line. Supersedes the spent #3370 fragment entry (merged into next, so its ripple is already absorbed at the base and it can no longer clear anything), which also named execute-phase.md and would otherwise double-ack the same path \u2014 the same supersede that entry itself performed on the spent #3324 fragment. #3659 corrects the auto-degrade paragraph's restore-advice to the orchestrator/harness split (+~300B): worktree.baseRef:\"head\" restores parallel execution only where GSD itself creates worktrees; harness-isolated runtimes do not read the setting (#48, upstream claude-code#44965). Deliberate growth."
|
||||
}
|
||||
}
|
||||
}
|
||||
7
tests/emitted-drift-acks/3003-declared-deletions.json
Normal file
7
tests/emitted-drift-acks/3003-declared-deletions.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"$comment": "Growth ack (#2914 fragment). Reason: #3003 threads a plan-declared deletion list from plan frontmatter to the cleanup-wave deletions guard. execute-phase.md gains --deletions \"$PLAN_DELETIONS\" on the record-agent call; 92326 -> 92356 LF bytes (+30). Supersedes the spent #2856 fragment entry (tests/emitted-drift-acks/2856-live-dom-uat.json, merged into next so its ripple is already absorbed at the base and it can no longer clear anything), which also named execute-phase.md and would otherwise double-ack the same path — the same supersede that entry itself performed on the spent #3370 fragment, which had performed it on #3324. Only this path needs an entry: currentSizes() (tests/helpers/emitted-runtime.cjs:916-929) reads gsd-core/workflows/ and agents/ with a NON-recursive readdirSync that skips directories, so the two other grown shipped files are outside the growth ratchet — gsd-core/workflows/execute-phase/steps/per-plan-worktree-gate.md (+885) sits in a subdirectory and gsd-core/templates/phase-prompt.md (+285) is under templates/. Their emitted-hash ripples are attributable to this diff and need no acknowledgment.",
|
||||
"version": 1,
|
||||
"paths": {
|
||||
"execute-phase.md": "gsd-core/workflows/execute-phase.md +30B: pass --deletions \"$PLAN_DELETIONS\" to worktree.record-agent so a plan-declared deletion reaches the cleanup-wave guard (#3003)"
|
||||
}
|
||||
}
|
||||
@@ -273,6 +273,28 @@ describe('plan-document — frontmatter scheduling metadata', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('plan-document — frontmatter filesDeleted', () => {
|
||||
test('no frontmatter at all defaults filesDeleted to []', () => {
|
||||
const parsed = parsePlanDocument('plain body, no frontmatter');
|
||||
assert.deepStrictEqual(parsed.filesDeleted, []);
|
||||
});
|
||||
|
||||
test('scalar files_deleted (underscore key) is wrapped into a one-element array', () => {
|
||||
const parsed = parsePlanDocument(frontmatterDoc(['files_deleted: src/gone.ts'], ['body']));
|
||||
assert.deepStrictEqual(parsed.filesDeleted, ['src/gone.ts']);
|
||||
});
|
||||
|
||||
test('array files-deleted (hyphen key) is mapped element-wise', () => {
|
||||
const parsed = parsePlanDocument(frontmatterDoc(['files-deleted: [a.ts, b.ts]'], ['body']));
|
||||
assert.deepStrictEqual(parsed.filesDeleted, ['a.ts', 'b.ts']);
|
||||
});
|
||||
|
||||
test('empty files_deleted list yields []', () => {
|
||||
const parsed = parsePlanDocument(frontmatterDoc(['files_deleted: []'], ['body']));
|
||||
assert.deepStrictEqual(parsed.filesDeleted, []);
|
||||
});
|
||||
});
|
||||
|
||||
describe('plan-document — planIdFromFile / TASK_KIND', () => {
|
||||
test('strips the -PLAN.md suffix from a root-form plan file', () => {
|
||||
assert.strictEqual(planIdFromFile('1-01-PLAN.md'), '1-01');
|
||||
|
||||
@@ -7131,3 +7131,351 @@ describe('#2596 --files on the record-agent and create verbs', () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// ══ #3003 — declared deletions for the cleanup-wave guard ═══════════════════════════════
|
||||
//
|
||||
// The deletions guard blocked ANY deletion in an executor branch, unconditionally. A plan
|
||||
// whose stated scope includes removing a file (folding a test into a sibling suite) could
|
||||
// not be merged by the tool meant to merge it, forcing a manual --no-ff outside the tool —
|
||||
// strictly less safe than what the guard protects against.
|
||||
//
|
||||
// #3003's pinned decision: an optional `declared_deletions` PATH LIST on the manifest entry.
|
||||
// A path list, not a boolean, precisely so an unexpected deletion riding along with a
|
||||
// declared one still blocks. These tests exist mostly to hold that line — the rows that
|
||||
// matter are the OVER-AUTHORIZATION set, because every way of loosening the matcher
|
||||
// (prefix, glob, startsWith) silently rebuilds the boolean opt-in that was rejected.
|
||||
//
|
||||
// Matching is EXACT after normalization. No globs, no prefixes. That is deliberate
|
||||
// Greenspun-avoidance: `declaredScopePrefix` already exists for the ADVISORY and returns
|
||||
// null ("matches everything") for a glob-leading pattern — correct there, because a false
|
||||
// alarm costs more than a miss for an advisory. For a GATE that same rule would let
|
||||
// `["*.ts"]` disarm the guard completely.
|
||||
//
|
||||
// See https://github.com/open-gsd/gsd-core/issues/3003
|
||||
|
||||
describe('#3003 — declared deletions: authorization is exact set membership', () => {
|
||||
const REPO = '/repo/main';
|
||||
const WT = '/repo/.claude/worktrees/agent-a1';
|
||||
const BR = 'worktree-agent-a1';
|
||||
|
||||
/** A wave-cleanup git double whose deletion list and per-key overrides are injectable. */
|
||||
function makeDeletionGit({ deletions = '', deletionExit = 0, changed = null } = {}) {
|
||||
return (args) => {
|
||||
const key = args.join(' ');
|
||||
const ok = (stdout = '') => ({ exitCode: 0, stdout, stderr: '', signal: null, error: null, timedOut: false });
|
||||
if (key === `-C ${WT} rev-parse --abbrev-ref HEAD`) return ok(BR);
|
||||
if (key === `merge-base HEAD ${BR}`) return ok('abc123');
|
||||
if (key === `diff --diff-filter=D --name-only HEAD...${BR}`) {
|
||||
return deletionExit === 0
|
||||
? ok(deletions)
|
||||
: { exitCode: deletionExit, stdout: '', stderr: 'fatal: bad revision', signal: null, error: null, timedOut: false };
|
||||
}
|
||||
if (key === `diff --name-only HEAD...${BR}`) return ok(changed === null ? deletions : changed);
|
||||
if (key === `-C ${WT} status --porcelain --untracked-files=all`) return ok('');
|
||||
return ok();
|
||||
};
|
||||
}
|
||||
|
||||
function runWave(entry, gitOpts) {
|
||||
return executeWorktreeWaveCleanupPlan(
|
||||
{
|
||||
ok: true,
|
||||
repoRoot: REPO,
|
||||
action: 'cleanup_wave',
|
||||
discovery: 'manifest',
|
||||
entries: [{ agent_id: 'a1', worktree_path: WT, branch: BR, expected_base: 'abc123', ...entry }],
|
||||
},
|
||||
{ execGit: makeDeletionGit(gitOpts) },
|
||||
);
|
||||
}
|
||||
|
||||
const firstEntry = (result) => result.entries[0];
|
||||
const blockedOnDeletions = (result) => firstEntry(result).reason === 'branch_contains_deletions';
|
||||
|
||||
// ── backward compatibility: these must pass BEFORE the change too ──────────────────────
|
||||
|
||||
test('no deletions proceeds', () => {
|
||||
const result = runWave({}, { deletions: '' });
|
||||
assert.notEqual(firstEntry(result).reason, 'branch_contains_deletions');
|
||||
});
|
||||
|
||||
test('absent declaration keeps the unconditional block', () => {
|
||||
const result = runWave({}, { deletions: 'tests/a.test.ts\n' });
|
||||
assert.ok(blockedOnDeletions(result), 'an entry with no declaration must block exactly as before');
|
||||
});
|
||||
|
||||
// ── the feature ────────────────────────────────────────────────────────────────────────
|
||||
|
||||
test('a fully declared deletion merges', () => {
|
||||
const result = runWave(
|
||||
{ declared_deletions: ['tests/a.test.ts'] },
|
||||
{ deletions: 'tests/a.test.ts\n' },
|
||||
);
|
||||
assert.ok(!blockedOnDeletions(result), `expected merge, got ${firstEntry(result).reason}`);
|
||||
});
|
||||
|
||||
test('an undeclared deletion still blocks, and names only the residue', () => {
|
||||
const result = runWave(
|
||||
{ declared_deletions: ['tests/a.test.ts'] },
|
||||
{ deletions: 'tests/a.test.ts\nsrc/billing.ts\n' },
|
||||
);
|
||||
assert.ok(blockedOnDeletions(result));
|
||||
const detail = firstEntry(result).stderr;
|
||||
assert.match(detail, /src\/billing\.ts/, 'the undeclared path must be named');
|
||||
assert.doesNotMatch(detail, /tests\/a\.test\.ts/,
|
||||
'a declared path must NOT appear in the block detail — it would misdirect the operator');
|
||||
});
|
||||
|
||||
test('an over-declaration is inert', () => {
|
||||
const result = runWave(
|
||||
{ declared_deletions: ['tests/a.test.ts', 'never/deleted.ts'] },
|
||||
{ deletions: 'tests/a.test.ts\n' },
|
||||
);
|
||||
assert.ok(!blockedOnDeletions(result));
|
||||
});
|
||||
|
||||
test('an empty declaration is not an authorization', () => {
|
||||
const result = runWave({ declared_deletions: [] }, { deletions: 'tests/a.test.ts\n' });
|
||||
assert.ok(blockedOnDeletions(result));
|
||||
});
|
||||
|
||||
test('a broken deletion check is never an authorization', () => {
|
||||
const result = runWave(
|
||||
{ declared_deletions: ['tests/a.test.ts'] },
|
||||
{ deletions: '', deletionExit: 128 },
|
||||
);
|
||||
assert.equal(firstEntry(result).reason, 'deletion_check_failed',
|
||||
'a failed check must block on its own reason, never be filtered into a pass');
|
||||
});
|
||||
|
||||
// ── the over-authorization set: each of these BLOCKS, and each would PASS under a
|
||||
// prefix / glob / startsWith matcher. This is the line the design exists to hold. ────
|
||||
|
||||
test('a directory declaration does not authorize its children', () => {
|
||||
const result = runWave({ declared_deletions: ['tests'] }, { deletions: 'tests/a.test.ts\n' });
|
||||
assert.ok(blockedOnDeletions(result),
|
||||
'prefix matching would authorize a mass deletion — the exact accident the guard catches');
|
||||
});
|
||||
|
||||
test('a glob declaration authorizes nothing', () => {
|
||||
const result = runWave({ declared_deletions: ['*.ts'] }, { deletions: 'tests/a.test.ts\n' });
|
||||
assert.ok(blockedOnDeletions(result),
|
||||
'a glob-leading declaration must not disarm the guard (declaredScopePrefix returns null here)');
|
||||
});
|
||||
|
||||
test('a declaration is not a string prefix of another path', () => {
|
||||
const result = runWave({ declared_deletions: ['tests/a.ts'] }, { deletions: 'tests/ab.ts\n' });
|
||||
assert.ok(blockedOnDeletions(result), 'startsWith would leak tests/a.ts -> tests/ab.ts');
|
||||
});
|
||||
|
||||
// ── normalization: both sides meet in the same shape ───────────────────────────────────
|
||||
|
||||
test('a backslash declaration normalizes on any OS', () => {
|
||||
const result = runWave({ declared_deletions: ['tests\\a.test.ts'] }, { deletions: 'tests/a.test.ts\n' });
|
||||
assert.ok(!blockedOnDeletions(result));
|
||||
});
|
||||
|
||||
test('leading ./ and trailing slash normalize', () => {
|
||||
const result = runWave({ declared_deletions: ['./tests/a.test.ts'] }, { deletions: 'tests/a.test.ts\n' });
|
||||
assert.ok(!blockedOnDeletions(result));
|
||||
});
|
||||
|
||||
test('a duplicated declaration is inert', () => {
|
||||
const result = runWave(
|
||||
{ declared_deletions: ['tests/a.test.ts', 'tests/a.test.ts'] },
|
||||
{ deletions: 'tests/a.test.ts\n' },
|
||||
);
|
||||
assert.ok(!blockedOnDeletions(result));
|
||||
});
|
||||
|
||||
test('non-string and blank declarations are dropped', () => {
|
||||
const result = runWave(
|
||||
{ declared_deletions: [null, 0, '', ' ', [], 'tests/a.test.ts'] },
|
||||
{ deletions: 'tests/a.test.ts\n' },
|
||||
);
|
||||
assert.ok(!blockedOnDeletions(result), 'junk elements drop; the one real path still authorizes');
|
||||
});
|
||||
|
||||
test('a non-array declaration is treated as absent', () => {
|
||||
for (const bogus of ['tests/a.test.ts', {}, 0, true]) {
|
||||
const result = runWave({ declared_deletions: bogus }, { deletions: 'tests/a.test.ts\n' });
|
||||
assert.ok(blockedOnDeletions(result), `non-array ${JSON.stringify(bogus)} must not authorize`);
|
||||
}
|
||||
});
|
||||
|
||||
// ── the advisory interaction the design nearly missed ──────────────────────────────────
|
||||
|
||||
test('a declared deletion is in scope for the advisory', () => {
|
||||
// `git diff --name-only` includes deleted paths, and the #2596 advisory compares that
|
||||
// against files_modified ALONE. Without subtracting the declaration out, authorizing a
|
||||
// deletion produces a SCOPE_OUT_OF_DECLARED warning for the very path just authorized.
|
||||
const result = runWave(
|
||||
{ files_modified: ['src/keep.ts'], declared_deletions: ['tests/a.test.ts'] },
|
||||
{ deletions: 'tests/a.test.ts\n', changed: 'src/keep.ts\ntests/a.test.ts\n' },
|
||||
);
|
||||
// The merge assertion is load-bearing: without it a revert blocks the entry, warnings
|
||||
// come back empty, and the path-absence assertion below passes for the wrong reason.
|
||||
assert.ok(!blockedOnDeletions(result), `expected merge, got ${firstEntry(result).reason}`);
|
||||
const paths = firstEntry(result).warnings.map((w) => w.path);
|
||||
assert.ok(!paths.includes('tests/a.test.ts'),
|
||||
'a declared deletion must not be reported out-of-scope');
|
||||
});
|
||||
|
||||
test('the advisory does not activate on declarations alone', () => {
|
||||
// Before this fix, gating unioned files_modified + declared_deletions into the scope
|
||||
// list, so a plan that declared ONLY a deletion (no files_modified) still produced a
|
||||
// non-empty scope list, and every modified path warned as out-of-declared-scope on a
|
||||
// plan that had declared no modification scope at all. Gating on files_modified alone
|
||||
// keeps the advisory as silent as it was pre-#2596 when nothing was declared modified.
|
||||
const result = runWave(
|
||||
{ declared_deletions: ['src/gone.ts'] },
|
||||
{ deletions: 'src/gone.ts\n', changed: 'src/gone.ts\nsrc/other.ts\n' },
|
||||
);
|
||||
assert.ok(!blockedOnDeletions(result), `expected merge, got ${firstEntry(result).reason}`);
|
||||
assert.deepEqual(firstEntry(result).warnings, [], 'no files_modified means no advisory scope at all');
|
||||
});
|
||||
|
||||
test('a glob in declared_deletions does not mute the advisory', () => {
|
||||
// `declaredScopePrefix` returns null for a glob-leading pattern, meaning "matches
|
||||
// everything" — correct for the advisory's OWN matcher, but under the old UNION this
|
||||
// silenced the advisory entirely for a modified path that has nothing to do with the
|
||||
// glob. Exact-match subtraction gives declared_deletions one rule on every surface.
|
||||
const result = runWave(
|
||||
{ files_modified: ['src/kept.ts'], declared_deletions: ['*.md'] },
|
||||
{ deletions: '', changed: 'src/kept.ts\nsrc/stray.ts\n' },
|
||||
);
|
||||
assert.ok(!blockedOnDeletions(result), `expected merge, got ${firstEntry(result).reason}`);
|
||||
const paths = firstEntry(result).warnings.map((w) => w.path);
|
||||
assert.ok(paths.includes('src/stray.ts'), 'a glob declaration must not disarm the advisory');
|
||||
});
|
||||
|
||||
test('a bare directory in declared_deletions does not mute the advisory for its children', () => {
|
||||
// Same trap as the glob case: a directory-shaped declared_deletions entry authorizes
|
||||
// nothing at the gate (exact match only), but under the old UNION it would have widened
|
||||
// the advisory's own prefix matching to cover everything under that directory.
|
||||
const result = runWave(
|
||||
{ files_modified: ['src/kept.ts'], declared_deletions: ['src'] },
|
||||
{ deletions: '', changed: 'src/kept.ts\nsrc/stray.ts\n' },
|
||||
);
|
||||
assert.ok(!blockedOnDeletions(result), `expected merge, got ${firstEntry(result).reason}`);
|
||||
const paths = firstEntry(result).warnings.map((w) => w.path);
|
||||
assert.ok(paths.includes('src/stray.ts'), 'a bare directory declaration must not mute the advisory for its children');
|
||||
});
|
||||
|
||||
test('the advisory still fires for a genuinely out-of-scope path', () => {
|
||||
const result = runWave(
|
||||
{ files_modified: ['src/keep.ts'], declared_deletions: ['tests/a.test.ts'] },
|
||||
{ deletions: 'tests/a.test.ts\n', changed: 'src/keep.ts\ntests/a.test.ts\nsrc/rogue.ts\n' },
|
||||
);
|
||||
const paths = firstEntry(result).warnings.map((w) => w.path);
|
||||
assert.ok(paths.includes('src/rogue.ts'), 'the advisory must not be blunted by this change');
|
||||
});
|
||||
|
||||
// ── git C-quoting decode: both sides meet in the same shape ────────────────────────────
|
||||
|
||||
test('a declared non-ASCII deletion merges even though git C-quotes the path', () => {
|
||||
// With core.quotepath at its git default, a non-ASCII deleted path comes back from
|
||||
// `git diff --diff-filter=D --name-only` wrapped in double quotes and C-escaped:
|
||||
// `tests/é.ts` is reported as the literal string built here with String.raw so the
|
||||
// runtime value actually contains backslash-3-0-3 / backslash-2-5-1 sequences, not a
|
||||
// JS-interpreted escape. Confirmed via `raw.length === 19` and `raw.includes('\\303')`.
|
||||
// Without decodeGitQuotedPath this quoted form can never equal the plainly-declared
|
||||
// path below, so the entry would block forever.
|
||||
const quoted = String.raw`"tests/\303\251.ts"`;
|
||||
const result = runWave(
|
||||
{ declared_deletions: ['tests/é.ts'] },
|
||||
{ deletions: `${quoted}\n` },
|
||||
);
|
||||
assert.ok(!blockedOnDeletions(result), `expected merge, got ${firstEntry(result).reason}`);
|
||||
});
|
||||
|
||||
test('a declaration written in git-quoted form also matches a plainly reported path', () => {
|
||||
// The reverse direction: normalizeScopePath runs on BOTH sides, so a declaration
|
||||
// authored in the quoted-and-escaped form must still match a plain git report. This
|
||||
// pins the symmetry so a future one-sided decode (only on the git side) is caught.
|
||||
const quoted = String.raw`"tests/\303\251.ts"`;
|
||||
const result = runWave(
|
||||
{ declared_deletions: [quoted] },
|
||||
{ deletions: 'tests/é.ts\n' },
|
||||
);
|
||||
assert.ok(!blockedOnDeletions(result), `expected merge, got ${firstEntry(result).reason}`);
|
||||
});
|
||||
|
||||
test('an undeclared non-ASCII deletion still blocks, and the residue names the decoded path', () => {
|
||||
// The path must not be declared, so the guard blocks — and the operator-facing detail
|
||||
// must show the DECODED path (the one they can actually act on), not the raw escaped
|
||||
// quoted form git emitted.
|
||||
const quoted = String.raw`"tests/\303\251.ts"`;
|
||||
const result = runWave(
|
||||
{ declared_deletions: ['src/keep.ts'] },
|
||||
{ deletions: `${quoted}\n` },
|
||||
);
|
||||
assert.ok(blockedOnDeletions(result));
|
||||
const detail = firstEntry(result).stderr;
|
||||
assert.match(detail, /tests\/é\.ts/, 'the block detail must name the decoded path, not the raw escaped form');
|
||||
assert.doesNotMatch(detail, /\\303\\251/, 'the raw C-escaped bytes must not leak into the operator-facing detail');
|
||||
});
|
||||
|
||||
test('a path merely containing a quote is not decoded', () => {
|
||||
// `tests/a"b.ts` is not wrapped in a leading-and-trailing quote pair, so the
|
||||
// startsWith('"') && endsWith('"') guard must leave it completely untouched — declaring
|
||||
// that exact literal string must still merge.
|
||||
const result = runWave(
|
||||
{ declared_deletions: ['tests/a"b.ts'] },
|
||||
{ deletions: 'tests/a"b.ts\n' },
|
||||
);
|
||||
assert.ok(!blockedOnDeletions(result), `expected merge, got ${firstEntry(result).reason}`);
|
||||
});
|
||||
|
||||
// NOTE: "a fully declared deletion merges" (above) already covers a plain ASCII declared
|
||||
// deletion merging — no additional plain-ASCII regression test added here to avoid
|
||||
// duplicating it.
|
||||
|
||||
// ── #2852 regression: a block isolates, it does not abort the wave ─────────────────────
|
||||
|
||||
test('a blocked entry does not abort the rest of the wave', () => {
|
||||
const second = { agent_id: 'a2', worktree_path: '/repo/.claude/worktrees/agent-a2', branch: 'worktree-agent-a2', expected_base: 'abc123' };
|
||||
const result = executeWorktreeWaveCleanupPlan(
|
||||
{
|
||||
ok: true,
|
||||
repoRoot: REPO,
|
||||
action: 'cleanup_wave',
|
||||
discovery: 'manifest',
|
||||
entries: [
|
||||
{ agent_id: 'a1', worktree_path: WT, branch: BR, expected_base: 'abc123', declared_deletions: ['tests/a.test.ts'] },
|
||||
second,
|
||||
],
|
||||
},
|
||||
{ execGit: makeDeletionGit({ deletions: 'tests/a.test.ts\nsrc/billing.ts\n' }) },
|
||||
);
|
||||
assert.equal(result.entries[0].reason, 'branch_contains_deletions');
|
||||
assert.equal(result.entries.length, 2, 'the second entry must still have been processed');
|
||||
assert.deepEqual(result.pending, [], 'nothing may be left pending — that would be an aborted wave');
|
||||
});
|
||||
|
||||
// ── property: authorization is exactly set membership ──────────────────────────────────
|
||||
|
||||
test('property: a deletion merges iff its normalized path is in the declared set', () => {
|
||||
const PATHS = ['a.ts', 'src/b.ts', 'tests/c.test.ts', 'deep/nested/d.ts', 'e.md'];
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.subarray(PATHS, { minLength: 1 }),
|
||||
fc.subarray(PATHS, { minLength: 1 }),
|
||||
(deleted, declared) => {
|
||||
const result = runWave(
|
||||
{ declared_deletions: declared },
|
||||
{ deletions: `${deleted.join('\n')}\n` },
|
||||
);
|
||||
const everyDeletionDeclared = deleted.every((p) => declared.includes(p));
|
||||
assert.equal(
|
||||
!blockedOnDeletions(result),
|
||||
everyDeletionDeclared,
|
||||
`deleted=${JSON.stringify(deleted)} declared=${JSON.stringify(declared)}`,
|
||||
);
|
||||
},
|
||||
),
|
||||
{ seed: 3003, numRuns: 200 },
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user