enhance(#3118): close the dead injectables and the shell projection follow-on — Wave 4 (#3124)

* test(#3118): failing-first coverage for the dead injectables and the shell projection

Adds the counter-tests Wave 4 closes against, before any fix:

- antigravityWatermark had zero test references. The four existing tests
  that look like watermark coverage hand the fallback a literal mark and
  never call the producer, so nothing pinned whether a real run's mark is
  correct. Covers all six branches plus the non-object cache classes.
- Pins the fail-open: a transcript read that throws reports lines:0,
  indistinguishable from a genuinely empty transcript, and the consumer
  then replays a previous run's review as this run's.
- Pins the export-line escaping across the repair, persist and win32 bash
  lanes, including the parity assertion that they must not diverge.
- sliceCurrentPositionSection: empty-vs-absent, fenced heading, second
  occurrence, H3, CRLF.
- Proves deps.progressProvider is inert by supplying a throwing stub to
  all ten transition intents.

Verification through the remote runner only.

Refs #3118

* fix(#3118): distinguish an unreadable transcript from an empty one

antigravityWatermark's final read can throw on a transcript that
indisputably exists. It returned lines:0, which is the same value a
genuinely empty transcript produces, so the caller could not tell the
two apart.

antigravityTranscriptFallback derives its skip from that count. A mark
of {convId:'c1', lines:0} for a conversation that pre-dates the run
makes it skip nothing and return the last PLANNER_RESPONSE in a
transcript written before this run started — a previous review
presented as this one's, which is exactly what the function's own
'never stale' docstring promises cannot happen.

The unreadable case now sets unreadable:true and the fallback declines
for a same-conv-id unreadable mark. An absent or empty transcript is
untouched: those genuinely have zero prior lines.

* fix(#3118): escape the export line for the file it lands in, not the echo

Three lanes emit export PATH="<dir>:$PATH". repair escaped it with
escapePosixDoubleQuoted; persist and the win32 Git Bash lane escaped it
with escapeSingleQuotedShellLiteral instead.

The single-quoting is correct for the echo, so nothing runs when the
user pastes the command. But the bytes appended to ~/.bashrc are the
export line itself, and inside double quotes in an rc file a $(...) or
a backtick in the directory name is command substitution that runs on
every new shell. Those characters are legal in a path on both POSIX and
Windows, so the path was reachable.

projectPathExportLine is now the single source of that line and escapes
for its final rc-file context; each lane still applies its own transport
escaping on top. fish keeps the single-quote escaper — its value really
does stay single-quoted.

The cmd.exe lane interpolated into a cmd double-quoted string with no
cmd-level escaping, so a quote closed the region and &cmd& ran. A quote
is reserved on Windows and cannot appear in a real path, so there is no
correct command to suggest: the win32 lanes now fail closed for one.

Metacharacter-free paths render byte-identically on every lane.

* fix(#3118): drop a stray carriage return and a deps field nobody reads

locateCurrentPosition subtracted a fixed one byte to exclude the newline
before the next heading, which assumes LF. On a CRLF document the slice
kept an unpaired trailing carriage return. It now walks back over the
newline and over a preceding carriage return if there is one.

StateTransitionDeps also required a progressProvider that 33 sites
supplied and no site ever called. A required field nothing reads widens
the module's interface without changing its implementation, which is the
shape epic #3051 cites as its reason for refusing blanket injection.
Removed along with the ProgressRecord alias that existed only as its
return type; state-document.cts's unrelated interface of the same name
is untouched.

* fix(#3118): stop an empty span duplicating bytes, and name the empty results

Three findings from the isolated review pass.

locateCurrentPosition could return end < start when the section was
empty and the next heading followed with no blank line between. Every
mutator splices with slice(0,start) + body + slice(end), so an inverted
span duplicated the region between them — a blank line silently
inserted into STATE.md on every transition, two bytes on CRLF. The span
is now clamped, and an empty section is a zero-length span, which is
what it always meant.

The win32 fail-closed path left the installer printing 'Add it with one
of:' with nothing under it. An empty shellActions folded two different
facts together, so projectPathActionProjection now carries a frozen
PATH_ACTION_REASON and the installer branches on it. Two empty results
with different causes staying distinguishable is the subject of the
epic this belongs to.

fish_add_path parses a leading dash as an option, so a directory named
-v printed 'No paths to add' instead of being added. Verified against
fish 4.8.1: the end-of-options separator fixes it.

Replaces the console-prose test the second fix first arrived with — a
regex over captured stdout is what CONTRIBUTING prohibits, and the
typed reason is the surface it asks for instead.

* fix(#3118): escape TOML control characters, and stop a test name overstating

Five findings from the two review axes.

escapeTomlDoubleQuotedString escaped only backslash and quote. TOML
basic strings also require U+0000-U+0008, U+000A-U+001F and U+007F to be
escaped, so a value carrying a raw newline or NUL wrote a config.toml no
parser accepts — rejecting the whole file, not just that value. Four of
its call sites write real config. Tab stays raw; the grammar exempts it.

The byte-identity test claimed every lane was unchanged for an ordinary
path, which is false: fish now takes the end-of-options separator on
every path, not only hostile ones. Renamed, and the one intended delta
now has its own named test instead of hiding inside a claim that read
as broader than it was.

Also: exact-equality assertions in place of substring checks that could
pass on a subtly wrong escape, newline and null-byte cases for all five
quoting primitives, and a temp dir registered with t.after so it is
removed when an assertion fails.

* docs(#3118): add the changeset fragments

* fix(#3118): degrade instead of throwing on a null conversation cache

A cache file whose whole content is the literal null — what a truncated
or zeroed write leaves behind — made both antigravityWatermark and
antigravityTranscriptFallback throw. JSON.parse('null') succeeds, so the
try/catch wrapping the parse never fired, and resolveConvId then called
hasOwnProperty on null.

Both functions advertise the opposite; the existing test next to them is
named 'a missing cache or transcript degrades to empty, never throws'.
Parsing successfully is not the same fact as the payload being usable,
and a guard that only wraps the parse cannot tell them apart.

resolveConvId is now total for any non-object input, so one guard covers
both callers. Caught by the null case in this wave's own cache matrix.

* test(#3118): correct a stale fish expectation and a parity comparison

The pre-existing 'POSIX persist mode escapes single quotes' test pinned
fish_add_path without the end-of-options separator this wave adds, so it
asserted behavior that is no longer correct. A repo-wide scan found one
such hardcoded expectation; every other site derives its expectation
from the projection.

The new parity test compared the token from a POSIX path against the
win32 lane, which posix-normalizes its input first — two different
inputs, so the tokens differed for a reason that had nothing to do with
the parity it claims to check. It now derives the win32 expectation from
the same input the lane receives.

* docs(#3118): reword a comment the injection scanner reads as an instruction

The scanner pattern act\s+as\s+(?:a|an|the)\s+ carries no word
boundary, so 'the same fact as the payload' matched on the tail of
'fact'. Reworded per the documented remedy for this collision.

The missing boundary is a scanner defect rather than a prose problem —
any contributor writing 'fact as the' trips it — but the pattern is
gate plumbing, which the sibling epic owns, so it is surfaced rather
than changed here.

* chore(#3118): backfill changeset pr number to 3124

* chore(#3118): backfill changeset pr number to 3124

* fix(#2784): make the negation scan single-pass and index it correctly

Three defects in the negation suppression added by #3127, all in one
block, none of which had a test.

The pair scan was verbs.some(nouns.some(...)) with a slice and a split
per pair, so it grew cubically with clause length: 1.1ms before that PR
and 8462ms after, on 800 verb+noun pairs in one clause. api-coverage's
property test generates documents large enough to reach the runner's
600s file cap, which is why it hangs as 'fail 0, cancelled 1' rather
than failing an assertion. Every (verb, noun) window is a subset of the
single widest one, so one scan of that window answers the same question
in a linear pass. Verified equivalent against the old predicate over
20,000 generated clauses.

Both checks also subtracted clause.start from offsets that collectTerm-
Matches already returns clause-local. The first clause on a line has
start 0 so it worked there and nowhere else: later clauses went
negative, and slice reads a negative index from the end, so suppression
silently examined unrelated text.

The comment claimed 'without any API integration' was suppressed. It is
not — the qualifier sits outside the two-word lookback and the noun
precedes the verb. Widening the window would trade a false positive
that costs one declaration line for a false negative that slips a real
integration past a blocking gate, so the behavior stands and the
comment now says so. Pinned by a test.

The qualifier sets were also rebuilt for every line of every document.
This commit is contained in:
Tom Boucher
2026-08-06 23:57:05 -04:00
committed by GitHub
parent 0ccc18dd3c
commit 0e6fa2e2cf
20 changed files with 1296 additions and 86 deletions

View File

@@ -17,6 +17,7 @@ const {
FIELD_CLASSIFICATION,
getFieldClassification,
STATE_MD_SECTIONS,
sliceCurrentPositionSection,
} = require('../gsd-core/bin/lib/state-transition.cjs');
const { stateExtractField } = require('../gsd-core/bin/lib/state-document.cjs');
@@ -26,8 +27,6 @@ const fixedClock = Object.freeze({
nowIso: () => '2026-06-27T12:00:00.000Z',
});
const noProgress = () => null;
describe('ADR-1769 substrate: field-classification table', () => {
const allowedSources = new Set(['body', 'disk', 'external', 'curated', 'free']);
const allowedPreservation = new Set([
@@ -140,7 +139,7 @@ describe('ADR-1769 Phase 1: beginPhase transition — tracer bullet', () => {
const result = transitionCore(
input,
{ kind: 'beginPhase', phaseNumber: 3, phaseName: 'Test Phase', planCount: 5 },
{ clock: fixedClock, progressProvider: noProgress },
{ clock: fixedClock },
);
assert.ok(result.updated.includes('Status'), `updated should include Status; got ${JSON.stringify(result.updated)}`);
@@ -181,7 +180,7 @@ function firstTimeBody() {
describe('ADR-1769 Phase 1: beginPhase first-time body field updates', () => {
const intent = { kind: 'beginPhase', phaseNumber: 3, phaseName: 'Test Phase', planCount: 5 };
const deps = { clock: fixedClock, progressProvider: noProgress };
const deps = { clock: fixedClock };
test('updates Current Phase to N', () => {
const result = transitionCore(firstTimeBody(), intent, deps);
@@ -260,7 +259,7 @@ function resumeBody() {
describe('ADR-1769 Phase 1: #3127 idempotency guard — resume path', () => {
const intent = { kind: 'beginPhase', phaseNumber: 3, phaseName: 'Test Phase', planCount: 5 };
const deps = { clock: fixedClock, progressProvider: noProgress };
const deps = { clock: fixedClock };
test('Status is still refreshed on resume (Last Activity Date tracks execute-phase runs)', () => {
const result = transitionCore(resumeBody(), intent, deps);
@@ -299,7 +298,7 @@ describe('ADR-1769 Phase 1: #3127 idempotency guard — resume path', () => {
describe('ADR-1769 Phase 1: Current Position section mutation (first-time begin)', () => {
const intent = { kind: 'beginPhase', phaseNumber: 3, phaseName: 'Test Phase', planCount: 5 };
const deps = { clock: fixedClock, progressProvider: noProgress };
const deps = { clock: fixedClock };
test('Current Position Phase line reflects the new phase (EXECUTING)', () => {
const result = transitionCore(firstTimeBody(), intent, deps);
@@ -356,7 +355,7 @@ describe('ADR-1769 Phase 1: Current Position section mutation (first-time begin)
describe('ADR-1769 Phase 1: Current Position section mutation (resume path)', () => {
const intent = { kind: 'beginPhase', phaseNumber: 3, phaseName: 'Test Phase', planCount: 5 };
const deps = { clock: fixedClock, progressProvider: noProgress };
const deps = { clock: fixedClock };
test('Resume updates only the Last activity line in Current Position (preserves Plan, Phase, Status)', () => {
const result = transitionCore(resumeBody(), intent, deps);
@@ -372,7 +371,7 @@ describe('ADR-1769 Phase 1: Current Position section mutation (resume path)', ()
});
describe('ADR-1769 Phase 1: property tests (RULESET.TESTS.property-based-testing)', () => {
const deps = { clock: fixedClock, progressProvider: noProgress };
const deps = { clock: fixedClock };
test('for any non-negative integer phaseNumber and any STATE.md body with a non-whitespace Status value, beginPhase produces content whose body Status carries "Executing Phase N"', () => {
// Note: filters out whitespace-only statusSuffix because state-document.cjs's
@@ -419,7 +418,7 @@ describe('ADR-1769 Phase 1: property tests (RULESET.TESTS.property-based-testing
});
describe('ADR-1769 Phase 2: advancePlan transition', () => {
const deps = { clock: fixedClock, progressProvider: noProgress };
const deps = { clock: fixedClock };
test('advances Current Plan from N to N+1 (legacy format)', () => {
const input = [
@@ -483,7 +482,7 @@ describe('ADR-1769 Phase 2: advancePlan transition', () => {
});
describe('ADR-1769 Phase 2: advancePlan with frontmatter (#1255 pattern — codex review)', () => {
const deps = { clock: fixedClock, progressProvider: noProgress };
const deps = { clock: fixedClock };
test('advances plan correctly when STATE.md has YAML frontmatter (body Status not YAML status)', () => {
const input = [
@@ -560,7 +559,7 @@ const ROADMAP_3_OF_5 = [
].join('\n');
describe('ADR-1769 Phase 3: completePhase transition — body field updates', () => {
const deps = { clock: fixedClock, progressProvider: noProgress, roadmapProvider: () => ROADMAP_3_OF_5 };
const deps = { clock: fixedClock, roadmapProvider: () => ROADMAP_3_OF_5 };
test('Current Phase advances to nextPhaseNum, preserving "of total" and appending the next name', () => {
const intent = {
@@ -645,7 +644,7 @@ describe('ADR-1769 Phase 3: completePhase transition — body field updates', ()
});
describe('ADR-1769 Phase 3: completePhase progress derivation (roadmap)', () => {
const deps = { clock: fixedClock, progressProvider: noProgress, roadmapProvider: () => ROADMAP_3_OF_5 };
const deps = { clock: fixedClock, roadmapProvider: () => ROADMAP_3_OF_5 };
test('Completed Phases is re-derived from the roadmap progress table', () => {
const result = transitionCore(
@@ -667,7 +666,7 @@ describe('ADR-1769 Phase 3: completePhase progress derivation (roadmap)', () =>
});
test('when roadmapProvider yields null, existing Completed Phases / Progress are preserved (no crash)', () => {
const nullDeps = { clock: fixedClock, progressProvider: noProgress, roadmapProvider: () => null };
const nullDeps = { clock: fixedClock, roadmapProvider: () => null };
const result = transitionCore(
completePhaseBody(),
{ kind: 'completePhase', phaseNum: '3', nextPhaseNum: '4', nextPhaseName: null, isLastPhase: false, planCount: 3, summaryCount: 3 },
@@ -685,7 +684,7 @@ describe('ADR-1769 Phase 3: completePhase progress derivation (roadmap)', () =>
// 'updated' even when nothing changed.
test('FAILURE path (roadmap unavailable): Completed Phases / Progress are NOT marked updated — left-as-is is distinguishable from recomputed', () => {
const nullDeps = { clock: fixedClock, progressProvider: noProgress, roadmapProvider: () => null };
const nullDeps = { clock: fixedClock, roadmapProvider: () => null };
const result = transitionCore(
completePhaseBody(),
{ kind: 'completePhase', phaseNum: '3', nextPhaseNum: '4', nextPhaseName: null, isLastPhase: false, planCount: 3, summaryCount: 3 },
@@ -716,7 +715,7 @@ describe('ADR-1769 Phase 3: completePhase progress derivation (roadmap)', () =>
});
describe('ADR-1769 Phase 3: completePhase edge cases', () => {
const deps = { clock: fixedClock, progressProvider: noProgress, roadmapProvider: () => ROADMAP_3_OF_5 };
const deps = { clock: fixedClock, roadmapProvider: () => ROADMAP_3_OF_5 };
test('falls back to the "Phase:" field when "Current Phase:" is absent (stateReplaceFieldWithFallback)', () => {
const input = [
@@ -813,7 +812,7 @@ function plannedPhaseBody() {
}
describe('ADR-1769 Phase 4: plannedPhase transition — body field updates', () => {
const deps = { clock: fixedClock, progressProvider: noProgress };
const deps = { clock: fixedClock };
test('Status advances to "Ready to execute" when the existing value is a template default (Planning)', () => {
const result = transitionCore(plannedPhaseBody(), { kind: 'plannedPhase', phaseNumber: 3, planCount: 4 }, deps);
@@ -888,7 +887,7 @@ describe('ADR-1769 Phase 4: plannedPhase transition — body field updates', ()
});
describe('ADR-1769 Phase 4: milestoneSwitch transition — milestone reset', () => {
const deps = { clock: fixedClock, progressProvider: noProgress };
const deps = { clock: fixedClock };
function milestoneBody() {
return [
@@ -963,7 +962,7 @@ describe('ADR-1769 Phase 4: milestoneSwitch transition — milestone reset', ()
// ADR-1769 Phase 5: milestoneComplete
describe('ADR-1769 Phase 5: milestoneComplete transition — closure write', () => {
const deps = { clock: fixedClock, progressProvider: noProgress };
const deps = { clock: fixedClock };
const intent = { kind: 'milestoneComplete', version: 'v1.0', nextMilestoneCommand: '/gsd:new-milestone' };
function preCloseBody() {
@@ -1095,7 +1094,7 @@ describe('ADR-1769 Phase 5: milestoneComplete transition — closure write', ()
// ADR-1769 Phase 6: patch
describe('ADR-1769 Phase 6: patch transition — field updates', () => {
const deps = { clock: fixedClock, progressProvider: noProgress };
const deps = { clock: fixedClock };
test('applies each patched field and reports the updated set', () => {
const input = [
@@ -1148,7 +1147,7 @@ describe('ADR-1769 Phase 6: patch transition — field updates', () => {
// ADR-1769 Phase 7: update, prune, sync
describe('ADR-1769 Phase 7: update transition — single body field', () => {
const deps = { clock: fixedClock, progressProvider: noProgress };
const deps = { clock: fixedClock };
test('replaces a body field and reports updated:true', () => {
const input = '# Project State\n\n**Status:** Planning\n**Current Plan:** 2\n';
@@ -1173,7 +1172,7 @@ describe('ADR-1769 Phase 7: update transition — single body field', () => {
});
describe('ADR-1769 Phase 7: prune transition — section pruning', () => {
const deps = { clock: fixedClock, progressProvider: noProgress };
const deps = { clock: fixedClock };
test('archives Decisions entries at or below the cutoff phase', () => {
const input = [
@@ -1223,7 +1222,7 @@ describe('ADR-1769 Phase 7: prune transition — section pruning', () => {
});
describe('ADR-1769 Phase 7: sync transition — body writes + #1761', () => {
const deps = { clock: fixedClock, progressProvider: noProgress };
const deps = { clock: fixedClock };
test('updates Total Plans in Phase + Progress bar + Last Activity when bounded', () => {
const input = [
@@ -1660,3 +1659,375 @@ describe('bug #21 — STATE.md template must carry YAML frontmatter', () => {
});
});
}
// ────────────────────────────────────────────────────────────────────────
// #3118: sliceCurrentPositionSection — locator characterization tests.
// ────────────────────────────────────────────────────────────────────────
describe('sliceCurrentPositionSection (#3118)', () => {
test('slices the section up to the following heading', () => {
const body = [
'# Project State',
'',
'## Current Position',
'',
'Phase: 3 (Test Phase) — EXECUTING',
'',
'## Accumulated Context',
'',
'- A decision worth keeping.',
'',
].join('\n');
const result = sliceCurrentPositionSection(body);
assert.ok(result.includes('Phase: 3 (Test Phase) — EXECUTING'));
assert.ok(!result.includes('A decision worth keeping'));
});
test('slices to end of document for a trailing section', () => {
const body = [
'# Project State',
'',
'## Accumulated Context',
'',
'- Earlier decision.',
'',
'## Current Position',
'',
'Phase: 5 (Final Phase) — EXECUTING',
'',
].join('\n');
const result = sliceCurrentPositionSection(body);
assert.ok(result.includes('Phase: 5 (Final Phase) — EXECUTING'));
});
test('returns null when the section is absent', () => {
const body = [
'# Project State',
'',
'## Accumulated Context',
'',
'- Some decision.',
'',
'## Deferred Items',
'',
'- Something deferred.',
'',
].join('\n');
assert.strictEqual(sliceCurrentPositionSection(body), null);
});
test('matches the heading case- and space-insensitively', () => {
const body = [
'# Project State',
'',
'## CURRENT POSITION',
'',
'Phase: 2 — EXECUTING',
'',
].join('\n');
assert.notStrictEqual(sliceCurrentPositionSection(body), null);
});
test('ignores a Current Position heading inside a code fence', () => {
// The locator is fence-aware via `tokenizeHeadings` — a `##` line inside
// a ``` fence is not a real heading, so this document has zero *real*
// Current Position headings.
const body = [
'# Project State',
'',
'## Accumulated Context',
'',
'```markdown',
'## Current Position',
'',
'Phase: 9 — should not be seen',
'```',
'',
].join('\n');
assert.strictEqual(sliceCurrentPositionSection(body), null);
});
test('distinguishes an empty section from an absent one', () => {
// An empty section and an absent one are different answers, and a caller
// that folds them together reintroduces the collapse this epic removes.
const body = [
'# Project State',
'',
'## Current Position',
'## Accumulated Context',
'',
'- A decision.',
'',
].join('\n');
const result = sliceCurrentPositionSection(body);
assert.strictEqual(typeof result, 'string');
assert.notStrictEqual(result, null);
assert.strictEqual(result.trim(), '');
});
test('does not match an H3 Current Position', () => {
const body = [
'# Project State',
'',
'### Current Position',
'',
'Phase: 2 — EXECUTING',
'',
].join('\n');
assert.strictEqual(sliceCurrentPositionSection(body), null);
});
test('slices the first Current Position when the document has two', () => {
// `findIndex` picks the first heading match and nothing pinned that
// behavior down before this test.
const body = [
'# Project State',
'',
'## Current Position',
'',
'Phase: 3 — FIRST OCCURRENCE',
'',
'## Accumulated Context',
'',
'- unrelated',
'',
'## Current Position',
'',
'Phase: 9 — SECOND OCCURRENCE',
'',
].join('\n');
const result = sliceCurrentPositionSection(body);
assert.ok(result.includes('FIRST OCCURRENCE'));
assert.ok(!result.includes('SECOND OCCURRENCE'));
});
test('returns null for an empty document', () => {
assert.strictEqual(sliceCurrentPositionSection(''), null);
});
test('slices a CRLF document identically', () => {
// Only `\n` in a regex/split is the recurring CRLF defect class in this
// repo (#1658 and successors) — verify the CRLF fixture, normalized back
// to LF, matches the LF fixture's result byte-for-byte.
const lines = [
'# Project State',
'',
'## Current Position',
'',
'Phase: 3 (Test Phase) — EXECUTING',
'',
'## Accumulated Context',
'',
'- A decision worth keeping.',
'',
];
const lfResult = sliceCurrentPositionSection(lines.join('\n'));
const crlfResult = sliceCurrentPositionSection(lines.join('\r\n'));
// Strict form (#3118): normalize CRLF->LF and require exact equality with
// the LF result. The looser `.replace(/\r/g, '')` form (previously used
// here) strips ALL `\r` bytes including a stray unpaired trailing `\r`
// left by the pre-fix `end = hs[j].offset - 1` slice — that loose
// assertion is what let the CRLF-slice-defect ship undetected.
assert.strictEqual(crlfResult.replace(/\r\n/g, '\n'), lfResult);
});
test('returns an empty string when the section is empty and the next heading follows immediately', () => {
const body = ['# STATE', '', '## Current Position', '## Next Section', 'content'].join('\n');
const result = sliceCurrentPositionSection(body);
assert.strictEqual(result, '');
});
test('does not duplicate bytes when a transition mutates an empty adjacent section', () => {
// Regression for #3118 review MAJOR: `locateCurrentPosition`'s newline
// walk-back could land `end` before `start` when the section is empty
// and the next heading follows with no blank line between. Every
// mutator's `body.slice(0, start) + sectionBody + body.slice(end)`
// reassembly then duplicated the bytes in the inverted `[end, start)`
// range — a spurious blank line (LF) or `\r\n` (CRLF) inserted into
// STATE.md on every transition.
const lfBody = ['# STATE', '', '## Current Position', '## Next Section', 'content'].join('\n');
const lfResult = transitionCore(
lfBody,
{ kind: 'beginPhase', phaseNumber: 3, phaseName: null, planCount: null },
{ clock: fixedClock },
);
assert.ok(
!lfResult.content.includes('## Current Position\n\n## Next Section'),
`expected no inserted blank line; got ${JSON.stringify(lfResult.content)}`,
);
assert.strictEqual(
lfResult.content,
'# STATE\n\n## Current Position\n## Next Section\ncontent',
);
assert.strictEqual(lfResult.content.length, lfBody.length);
const crlfBody = ['# STATE', '', '## Current Position', '## Next Section', 'content'].join('\r\n');
const crlfResult = transitionCore(
crlfBody,
{ kind: 'beginPhase', phaseNumber: 3, phaseName: null, planCount: null },
{ clock: fixedClock },
);
assert.ok(
!crlfResult.content.includes('## Current Position\r\n\r\n## Next Section'),
`expected no inserted CRLF; got ${JSON.stringify(crlfResult.content)}`,
);
assert.strictEqual(
crlfResult.content,
'# STATE\r\n\r\n## Current Position\r\n## Next Section\r\ncontent',
);
assert.strictEqual(crlfResult.content.length, crlfBody.length);
});
});
// ────────────────────────────────────────────────────────────────────────
// #3118: deps.progressProvider is a required StateTransitionDeps field with
// 33 supply sites and zero call sites, and is being removed. Prove it
// behaviorally: no transition ever invokes it.
// ────────────────────────────────────────────────────────────────────────
describe('state transitions do not consult a progress provider (#3118)', () => {
test('no transition invokes deps.progressProvider', () => {
// An exploding stub is the behavioral form of "this field is inert";
// asserting the declaration is absent would be source-grep theater.
const exploding = () => { throw new Error('progressProvider must never be called'); };
const clock = fixedClock;
assert.doesNotThrow(() => transitionCore(
firstTimeBody(),
{ kind: 'beginPhase', phaseNumber: 3, phaseName: 'Test Phase', planCount: 5 },
{ clock, progressProvider: exploding },
));
assert.doesNotThrow(() => transitionCore(
[
'# Project State',
'',
'**Current Plan:** 02',
'**Total Plans in Phase:** 05',
'**Status:** Executing Phase 3',
'**Last Activity:** 2026-06-26',
'',
'## Current Position',
'',
'Plan: 2 of 5',
'Status: Executing Phase 3',
'',
].join('\n'),
{ kind: 'advancePlan' },
{ clock, progressProvider: exploding },
));
assert.doesNotThrow(() => transitionCore(
completePhaseBody(),
{ kind: 'completePhase', phaseNum: '3', nextPhaseNum: '4', nextPhaseName: 'Design Phase', isLastPhase: false, planCount: 3, summaryCount: 3 },
{ clock, progressProvider: exploding, roadmapProvider: () => ROADMAP_3_OF_5 },
));
assert.doesNotThrow(() => transitionCore(
plannedPhaseBody(),
{ kind: 'plannedPhase', phaseNumber: 3, planCount: 4 },
{ clock, progressProvider: exploding },
));
const milestoneBody = [
'---',
'gsd_state_version: 1.0',
'milestone: v1.0',
'milestone_name: Old Milestone',
'status: executing',
'current_phase: "3"',
'progress:',
' total_phases: 5',
' completed_phases: 2',
' percent: 40',
'---',
'',
'# Project State',
'',
'## Current Position',
'',
'Phase: 3 — EXECUTING',
'Plan: 2 of 5',
'Status: Executing Phase 3',
'Last activity: 2026-06-20 — mid-flight',
'',
].join('\n');
assert.doesNotThrow(() => transitionCore(
milestoneBody,
{ kind: 'milestoneSwitch', version: 'v2.0', name: 'New Milestone' },
{ clock, progressProvider: exploding },
));
const preCloseBody = [
'# Project State',
'',
'**Status:** Executing Phase 5',
'**Last Activity:** 2026-06-20',
'**Last Activity Description:** mid-flight',
'',
'## Current Position',
'',
'Phase: 5 — EXECUTING',
'Plan: 2 of 3',
'Status: Executing Phase 5',
'Last activity: 2026-06-20 — running',
'',
'## Operator Next Steps',
'',
'- Re-run /gsd:complete-milestone v1.0',
'',
].join('\n');
assert.doesNotThrow(() => transitionCore(
preCloseBody,
{ kind: 'milestoneComplete', version: 'v1.0', nextMilestoneCommand: '/gsd:new-milestone' },
{ clock, progressProvider: exploding },
));
assert.doesNotThrow(() => transitionCore(
[
'# Project State',
'',
'**Status:** Planning',
'**Current Plan:** 2',
'**Total Plans in Phase:** 5',
'',
].join('\n'),
{ kind: 'patch', patches: { Status: 'Paused', 'Current Plan': '3' } },
{ clock, progressProvider: exploding },
));
assert.doesNotThrow(() => transitionCore(
'# Project State\n\n**Status:** Planning\n**Current Plan:** 2\n',
{ kind: 'update', field: 'Current Plan', value: '3' },
{ clock, progressProvider: exploding },
));
assert.doesNotThrow(() => transitionCore(
[
'# Session State',
'',
'## Decisions',
'',
'- [Phase 1]: Old',
'- [Phase 3]: Older',
'- [Phase 9]: Recent',
'',
].join('\n'),
{ kind: 'prune', cutoff: 7 },
{ clock, progressProvider: exploding },
));
assert.doesNotThrow(() => transitionCore(
[
'# Project State',
'',
'**Total Plans in Phase:** 2',
'**Last Activity:** 2026-06-20',
'**Progress:** [████░░░░░░] 40%',
'',
].join('\n'),
{ kind: 'sync', totalPlansInPhase: 5, percent: 60 },
{ clock, progressProvider: exploding },
));
});
});