chore(#1671): fragmentize plan-phase.md and repair flag forwarding to the init bundle — Phase 6.2 (#3019)
* chore(#2993): fragmentize plan-phase.md onto the fragment model Epic #1671 Phase 6.2. plan-phase.md is the largest workflow in the repo and carried zero markers; it was deferred out of the Phase 3 pilot for two reasons, both now dead. The 36-byte PRE_PHASE6 headroom was never the blocker it looked like — fragmentizing is net-negative on host source, so the trim is what creates the room. The --mvp interleaving was resolved by measurement in #2992 and no sub-line mechanism is built. - widen WHEN_VOCABULARY 14 -> 19 via a second coordinated ADR-1671 amendment: flag:--ingest, flag:--prd, flag:--research-phase, flag:--reviews, state:chunked-mode - state:chunked-mode is `--chunked` OR config workflow.plan_chunked, and that disjunction is resolved in the FACT, never in the grammar, so a compound condition never becomes an operator - parse the new flags on the plan-phase route; extract six gated bodies to gsd-core/workflows/plan-phase/steps/ behind manifest-gated stubs - prd-express-path.md was already extracted but read unconditionally; its wrapper is now gated, so the existing extraction finally pays off plan-phase.md 94,483 -> 87,575 bytes (cap 94,519): headroom goes from 36 bytes to 6,944. Also closes a surfaced docs gap: five real plan-phase flags (--chunked, --skip-ui, --bounce, --skip-bounce, --granularity) were documented in neither the argument-hint nor help. Making --chunked load-bearing without fixing its siblings would leave the defect class half-open. Refs #2993 * fix(#2993): forward flags to the init bundle so section gating actually fires Blocker found by the correctness review, confirmed directly, and missed by both the isolated reviewer and every test in this branch. Neither workflow forwarded its flags to the init CLI: plan-phase.md:71 INIT=$(gsd_run query init.plan-phase "$PHASE" $GRAN_PARAM) execute-phase.md:84 INIT=$(gsd_run query init.execute-phase "${PHASE_ARG}") So every flag: atom was permanently false in production and its section permanently excluded. For plan-phase that made the PRD express path UNREACHABLE — a regression, since it was an unconditional read before. For execute-phase this is PRE-EXISTING: #2932 shipped `flag:--wave` gating that has never once been true, so `--wave` silently dropped its own wave-filtering guidance. Fixed here under the no-defer rule. Why every test missed it: they drive the init CLI directly with flags, which works. Production goes through the workflow's bash line, which did not pass them — the exact "assert against the shape production uses" trap this branch's own test matrix warns about. - parse and forward --prd/--ingest/--research-phase/--reviews/--chunked (plan-phase) and --wave (execute-phase), using the anchored regex idiom the neighbouring GRAN_PARAM line already uses - add a regression guard DERIVED FROM THE MANIFEST: for every flag:--X section, the owning workflow's init line must forward --X. It fails against the pre-fix files and covers any future atom, rather than spot-checking today's six. Verified through the workflow shape, not the CLI shape: `3 --prd spec.md` now yields ["prd-express-gate"] (was []), `2 --wave 2` yields ["partial-wave"] (was []). Refs #2993 * test(#2993): acknowledge the execute-phase ripple and regenerate install-tree fixtures Remote matrix was red with 46 unique failures, identical on both lanes. Both causes are mechanical consequences of changing shipped workflow content, and neither is visible to any local gate. - emitted-attribution: execute-phase.md grew 163 bytes from the WAVE_PARAM forwarding fix and was unacknowledged, while the ack fragment named plan-phase.md, which SHRANK and therefore needed no ack at all — a stale entry is itself a failure. The reason now names the real ripple. The entry had to merge into the existing 2930 fragment: the ack linter does unconditional cross-fragment duplicate-key detection with no spent/live exception, so a second fragment declaring execute-phase.md collides even when the first is already merged and inert. Resolved per the linter's own guidance and that file's precedent of appending successive ripple reasons to one entry. - golden-install-tree: tests/fixtures/install-tree/*.json are committed and deliberately excluded from the ADR-2719 attribution cutover, so they must be regenerated when shipped tree content changes. Regenerated after build:lib per the ordering landmine. 19 runtimes each gained exactly the six new plan-phase step files; zero paths removed, which is the absolute failure shape those fixtures exist to catch. Refs #2993 * fix(#2993): restore the launcher preamble in an extracted step and follow moved content in its drift guards Second red run: 26 unique failures, identical on both lanes, in two classes. RUNTIME BUG (runtime-launcher-parity, 7 failures) — chunked-planning-mode.md calls gsd_run but carried no canonical launcher preamble, which is what DEFINES gsd_run(). On any non-Claude runtime that step would fail outright. The preamble is now copied verbatim from the canonical source of truth, gsd-core/workflows/_runtime-launcher.snippet.sh, and the fence dedented to column 0 to match the prd-express-path.md sibling (a list-continuation indent breaks the byte-equal preamble match). prd-express-path.md already had a correct one. This is the same defect #2932 hit when it extracted steps; the parity test caught a real bug, not a stale assertion. DRIFT GUARDS (plan-phase-drift-guard, issue-2762-plan-reviews-chunked, skill-frontmatter-contract) — these assert plan-phase.md contains content this branch moved into step files. Retargeted at where the content now lives, with the asserted property unchanged; the ALL-RUNTIMES label COUNT test now reads host + every step file so the count is preserved across the split rather than reduced. Each retargeted guard was verified to still fail when its step file is stripped, so none was weakened into vacuity. No emitted-drift ack was needed: currentSizes() enumerates gsd-core/workflows/*.md non-recursively, so files under plan-phase/steps/ are never in the size ratchet's scope. Refs #2993 * chore(#2993): backfill changeset pr number to 3019 --------- Co-authored-by: sim <sim@local>
This commit is contained in:
@@ -29,12 +29,18 @@ const {
|
||||
REASON,
|
||||
} = require('../gsd-core/bin/lib/workflow-fragments.cjs');
|
||||
const { composeWithinBudget } = require('../gsd-core/bin/lib/context-composer.cjs');
|
||||
const { selectSections } = require('../gsd-core/bin/lib/section-manifest.cjs');
|
||||
|
||||
const measureBytes = (text) => Buffer.byteLength(text, 'utf8');
|
||||
|
||||
/** Compose a document string from an array of lines, joined with '\n'. */
|
||||
const doc = (...lines) => lines.join('\n');
|
||||
|
||||
/** Minimal InvocationFacts factory for the real-plan-phase.md D4 test below. */
|
||||
function facts(overrides) {
|
||||
return { flags: new Set(), phaseNumber: null, hasPriorPhases: false, ...overrides };
|
||||
}
|
||||
|
||||
// ─── Row 1: unmarked document (the 88/89 production shape) ─────────────────
|
||||
|
||||
describe('unmarked document round trip', () => {
|
||||
@@ -182,6 +188,126 @@ describe('real execute-phase.md', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ─── #2993 (epic #1671 Phase 6.2): real plan-phase.md — C1/D1/D4/D5 ───────
|
||||
|
||||
describe('real plan-phase.md (#2993)', () => {
|
||||
const PLAN_PHASE_PATH = path.join(__dirname, '..', 'gsd-core', 'workflows', 'plan-phase.md');
|
||||
const STEPS_DIR = path.join(__dirname, '..', 'gsd-core', 'workflows', 'plan-phase', 'steps');
|
||||
|
||||
// The 6 sections the #2993 design survey names, in document order.
|
||||
const EXPECTED_SECTIONS = Object.freeze([
|
||||
{ id: 'reviews-prerequisite', when: 'flag:--reviews' },
|
||||
{ id: 'prd-express-gate', when: 'flag:--prd' },
|
||||
{ id: 'adr-ingest-express-path', when: 'flag:--ingest' },
|
||||
{ id: 'research-only-modifiers', when: 'flag:--research-phase' },
|
||||
{ id: 'research-only-early-exit', when: 'flag:--research-phase' },
|
||||
{ id: 'chunked-planning-mode', when: 'state:chunked-mode' },
|
||||
]);
|
||||
|
||||
test('parsesExactlySixSectionsInDocumentOrder (row C1)', () => {
|
||||
const source = fs.readFileSync(PLAN_PHASE_PATH, 'utf8');
|
||||
const sections = parseWorkflowSections(source, PLAN_PHASE_PATH);
|
||||
const explicitSections = sections.filter((s) => s.explicit);
|
||||
assert.deepEqual(
|
||||
explicitSections.map((s) => ({ id: s.id, when: s.when })),
|
||||
[...EXPECTED_SECTIONS],
|
||||
);
|
||||
});
|
||||
|
||||
test('parsesAndRendersWithoutThrowingAndStripsEveryMarker', () => {
|
||||
const source = fs.readFileSync(PLAN_PHASE_PATH, 'utf8');
|
||||
const composed = composeWorkflow(source, { sourcePath: PLAN_PHASE_PATH });
|
||||
assert.equal(composed.includes('gsd:section'), false);
|
||||
assert.ok(Buffer.byteLength(composed, 'utf8') < Buffer.byteLength(source, 'utf8'));
|
||||
});
|
||||
|
||||
test('everyExtractedStepFileExistsIsNonEmptyAndTheHostNoLongerCarriesItsBody (row D1)', () => {
|
||||
// Behavioral, never a source-grep substring match: for each of the 6
|
||||
// sections, the step file on disk (1) exists, (2) is non-empty, and (3)
|
||||
// is EXACTLY the section's own parsed body (the bytes the marker pair
|
||||
// wraps in the host) is a stub/reference line, not a re-paste of the
|
||||
// step file's content — the host's marker body and the step file's
|
||||
// content are two DIFFERENT, disjoint pieces of text after the move.
|
||||
const source = fs.readFileSync(PLAN_PHASE_PATH, 'utf8');
|
||||
const sections = parseWorkflowSections(source, PLAN_PHASE_PATH);
|
||||
const byId = new Map(sections.filter((s) => s.explicit).map((s) => [s.id, s]));
|
||||
|
||||
for (const { id } of EXPECTED_SECTIONS) {
|
||||
const stepPath = path.join(STEPS_DIR, `${id}.md`);
|
||||
assert.ok(fs.existsSync(stepPath), `expected step file to exist: ${stepPath}`);
|
||||
const stepContent = fs.readFileSync(stepPath, 'utf8');
|
||||
assert.ok(stepContent.length > 0, `expected non-empty step file: ${stepPath}`);
|
||||
|
||||
const hostSection = byId.get(id);
|
||||
assert.ok(hostSection, `expected an explicit host section for id="${id}"`);
|
||||
// The host's marker body is a short stub (the conditional read-and-execute
|
||||
// instruction), never the step file's own moved content — proves the
|
||||
// body actually left the host rather than being duplicated in place.
|
||||
assert.ok(
|
||||
hostSection.body.length < stepContent.length,
|
||||
`expected host stub body for "${id}" to be shorter than the extracted step file`,
|
||||
);
|
||||
assert.equal(
|
||||
hostSection.body.includes(stepContent.trim()),
|
||||
false,
|
||||
`host stub body for "${id}" must not still contain the moved step file's content verbatim`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('prdExpressPathIsReadOnlyWhenPrdSectionIsIncluded (row D4)', () => {
|
||||
// prd-express-path.md was previously read unconditionally; the #2993
|
||||
// wrapper (prd-express-gate, when="flag:--prd") is what now actually
|
||||
// gates it. Prove the gate via the real evaluator: absent --prd excludes
|
||||
// prd-express-gate; present --prd includes it.
|
||||
const source = fs.readFileSync(PLAN_PHASE_PATH, 'utf8');
|
||||
const sections = parseWorkflowSections(source, PLAN_PHASE_PATH).filter((s) => s.explicit);
|
||||
const withoutPrd = selectSections(sections, facts({}));
|
||||
assert.ok(withoutPrd.excluded.includes('prd-express-gate'), 'prd-express-gate must be excluded when --prd is absent');
|
||||
assert.ok(!withoutPrd.included.includes('prd-express-gate'));
|
||||
|
||||
const withPrd = selectSections(sections, facts({ flags: new Set(['--prd']) }));
|
||||
assert.ok(withPrd.included.includes('prd-express-gate'), 'prd-express-gate must be included when --prd is present');
|
||||
assert.ok(!withPrd.excluded.includes('prd-express-gate'));
|
||||
|
||||
// The host's marker body is a stub that reads plan-phase/steps/prd-express-gate.md
|
||||
// ONLY when the section is included; THAT step file (nested, one hop
|
||||
// further — the reachability shape gen-section-manifest.cjs's own
|
||||
// "nested step reference" precedent covers) is what references
|
||||
// prd-express-path.md — proving the express-path read is reachable only
|
||||
// through the now-conditional wrapper, never as a second, independent
|
||||
// unconditional read site elsewhere in the host.
|
||||
const gateSection = sections.find((s) => s.id === 'prd-express-gate');
|
||||
assert.ok(gateSection.body.includes('prd-express-gate.md'), 'prd-express-gate\'s host stub must read its own step file');
|
||||
const gateStepContent = fs.readFileSync(path.join(STEPS_DIR, 'prd-express-gate.md'), 'utf8');
|
||||
assert.ok(
|
||||
gateStepContent.includes('prd-express-path.md'),
|
||||
'prd-express-gate.md must be the (nested) step that references prd-express-path.md',
|
||||
);
|
||||
});
|
||||
|
||||
test('skipIfProseAppearsExactlyOnceAcrossHostAndStepFile (row D5)', () => {
|
||||
// For each section, the "Skip if:" gating prose must live in exactly ONE
|
||||
// place — either the host stub or the step file — never duplicated in
|
||||
// both after the move.
|
||||
const source = fs.readFileSync(PLAN_PHASE_PATH, 'utf8');
|
||||
const sections = parseWorkflowSections(source, PLAN_PHASE_PATH);
|
||||
const byId = new Map(sections.filter((s) => s.explicit).map((s) => [s.id, s]));
|
||||
|
||||
for (const { id } of EXPECTED_SECTIONS) {
|
||||
const stepContent = fs.readFileSync(path.join(STEPS_DIR, `${id}.md`), 'utf8');
|
||||
const hostBody = byId.get(id).body;
|
||||
const hostHasSkipIf = /Skip if:/.test(hostBody);
|
||||
const stepHasSkipIf = /Skip if:/.test(stepContent);
|
||||
assert.notEqual(
|
||||
hostHasSkipIf && stepHasSkipIf,
|
||||
true,
|
||||
`"Skip if:" prose for "${id}" must not appear in BOTH the host stub and the step file`,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Row 5/6: fence negative space ──────────────────────────────────────────
|
||||
|
||||
describe('marker lookalikes inside fences', () => {
|
||||
@@ -483,6 +609,12 @@ describe('frozen when= vocabulary', () => {
|
||||
// for an array only reflects index positions '0','1',... and would not
|
||||
// catch a value being silently renamed). See the dispatch report for
|
||||
// this deliberate deviation from the test matrix's literal wording.
|
||||
//
|
||||
// #2993 (epic #1671 Phase 6.2, matrix row A3) widens this lock 14 -> 19:
|
||||
// flag:--ingest, flag:--prd, flag:--research-phase, flag:--reviews,
|
||||
// state:chunked-mode. This is the row the lock exists to force — a
|
||||
// deliberate, coordinated update, never a silent drift (Greenspun's
|
||||
// Tenth Rule / ADR-1671:69).
|
||||
assert.equal(Object.isFrozen(WHEN_VOCABULARY), true);
|
||||
assert.deepEqual(
|
||||
[...WHEN_VOCABULARY].sort(),
|
||||
@@ -492,10 +624,15 @@ describe('frozen when= vocabulary', () => {
|
||||
'flag:--discuss',
|
||||
'flag:--forensic',
|
||||
'flag:--full',
|
||||
'flag:--ingest',
|
||||
'flag:--prd',
|
||||
'flag:--research',
|
||||
'flag:--research-phase',
|
||||
'flag:--reset-phase-numbers',
|
||||
'flag:--reviews',
|
||||
'flag:--validate',
|
||||
'flag:--wave',
|
||||
'state:chunked-mode',
|
||||
'state:gap-closure-phase',
|
||||
'state:has-prior-phases',
|
||||
'state:needs-codebase-map',
|
||||
@@ -506,6 +643,63 @@ describe('frozen when= vocabulary', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ─── #2993 (epic #1671 Phase 6.2): widened when= vocabulary (19 atoms) ─────
|
||||
// 50-test-matrix.md rows A1/A6.
|
||||
|
||||
describe('widened when= vocabulary (#2993)', () => {
|
||||
// The 5 net-new atoms shipped by #2993, fragmentizing plan-phase.md.
|
||||
const NET_NEW_ATOMS_2993 = Object.freeze([
|
||||
'flag:--ingest',
|
||||
'flag:--prd',
|
||||
'flag:--research-phase',
|
||||
'flag:--reviews',
|
||||
'state:chunked-mode',
|
||||
]);
|
||||
|
||||
test('everyNetNewAtomIsInWhenVocabulary', () => {
|
||||
for (const atom of NET_NEW_ATOMS_2993) {
|
||||
assert.ok(WHEN_VOCABULARY.includes(atom), `expected "${atom}" in WHEN_VOCABULARY`);
|
||||
}
|
||||
});
|
||||
|
||||
test('acceptsEveryWidenedAtom (row A1)', () => {
|
||||
for (const when of NET_NEW_ATOMS_2993) {
|
||||
const source = `<!-- gsd:section id="x" when="${when}" -->\nbody\n<!-- /gsd:section -->`;
|
||||
const sections = parseWorkflowSections(source);
|
||||
const explicitSections = sections.filter((s) => s.explicit);
|
||||
assert.equal(explicitSections.length, 1, `expected acceptance for when="${when}"`);
|
||||
assert.equal(explicitSections[0].when, when);
|
||||
assert.equal(composeWorkflow(source), 'body\n');
|
||||
}
|
||||
});
|
||||
|
||||
test('researchPhaseAndResearchAreDistinctAtomsAtTheParserLevel (row A6)', () => {
|
||||
// flag:--research-phase (net-new, #2993) and flag:--research (pre-existing,
|
||||
// #2992) are DISTINCT vocabulary entries — the parser must accept both,
|
||||
// as different `when` values, on sections that sit side by side, and must
|
||||
// never conflate one for the other (e.g. via prefix-matching or a shared
|
||||
// token derivation). See section-manifest.test.cjs for the predicate-level
|
||||
// half of this guard (no aliasing at evaluation time).
|
||||
const source = doc(
|
||||
'<!-- gsd:section id="research-section" when="flag:--research" -->',
|
||||
'researchBody',
|
||||
'<!-- /gsd:section -->',
|
||||
'<!-- gsd:section id="research-phase-section" when="flag:--research-phase" -->',
|
||||
'researchPhaseBody',
|
||||
'<!-- /gsd:section -->',
|
||||
);
|
||||
const sections = parseWorkflowSections(source);
|
||||
const explicitSections = sections.filter((s) => s.explicit);
|
||||
assert.deepEqual(
|
||||
explicitSections.map((s) => ({ id: s.id, when: s.when })),
|
||||
[
|
||||
{ id: 'research-section', when: 'flag:--research' },
|
||||
{ id: 'research-phase-section', when: 'flag:--research-phase' },
|
||||
],
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── #2992 (epic #1671 Phase 6.1): widened when= vocabulary (14 atoms) ─────
|
||||
// 50-test-matrix.md rows A2/A5/A6/A14/A19.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user