* test(6): reproduce W007 + phaseVariants + W006 drift between CJS verify and SDK validate Adds tests/6-validate-cjs-drift-regression.test.cjs with 5 RED tests covering the three drift items from issue #6 between verify.cjs (Check 8) and validate.ts (Check 8): 1. W007 activeDiskPhases — verify.cjs uses diskPhases (includes archived) for W007; archived phase "1" absent from current ROADMAP fires false W007. validate.ts: activeDiskPhases (active phasesDir only) correctly excludes archives. 2. phaseVariants() normalization — ROADMAP says "01A", disk has "1A-foo". verify.cjs parseInt("01A")=1 → padded "01" (drops letter suffix) → miss. validate.ts phaseVariants("01A") = {"01A","1A","01A"} → "1A" matched. Both W006 and W007 fire as false positives in verify.cjs. 3. W006 letter-suffix padding mismatch — ROADMAP says "3B", disk has "03B-foo". verify.cjs parseInt("3B")=3 → padded "03" (drops "B") → diskPhases.has("03B") missed. W006 and W007 fire as false positives. All 5 tests RED on origin/main. Will turn GREEN after generator + verify.cjs migration. References: - Issue #6 (open-gsd/get-shit-done-redux) — maintainer acceptance criteria: "Port all three items to verify.cjs; add parity tests confirming identical output for all three cases on both paths" - ADR-3524 (docs/adr/3524-cjs-sdk-hard-seam.md) - PR #154 (issue #4) — precedent for the generator pattern Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore(6): add sdk/scripts/gen-validate.mjs generator Extracts phaseVariants() from sdk/dist/query/validate.js via brace-balanced source-text parsing (phaseVariants is a closure inside validateHealth, not a module export, so Function.prototype.toString() is unavailable). Emits get-shit-done/bin/lib/validate.generated.cjs with three pure helpers: - phaseVariants(phase): normalized Set of padded/unpadded/letter-suffix variants - buildRoadmapPhaseVariants(content): {roadmapPhases, roadmapPhaseVariants} - buildNotStartedPhaseVariants(content): Set of unchecked-phase variants These three helpers directly address the three drift items in issue #6. Follows the gen-phase-lifecycle-policy.mjs extraction pattern from PR #154. References: - Issue #6 (open-gsd/get-shit-done-redux) - ADR-3524 (docs/adr/3524-cjs-sdk-hard-seam.md) - PR #154 (issue #4) — generator pattern precedent Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore(6): add sdk/scripts/check-validate-fresh.mjs freshness check Mirrors check-phase-lifecycle-policy-fresh.mjs from PR #154: imports buildValidateCjs() directly, regenerates in-memory, and diffs against the committed validate.generated.cjs. Exits 1 if stale (CI gate). References: - Issue #6 (open-gsd/get-shit-done-redux) - ADR-3524 (docs/adr/3524-cjs-sdk-hard-seam.md) - PR #154 (issue #4) — precedent Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore(6): emit validate.generated.cjs from validate.ts Generated by: node sdk/scripts/gen-validate.mjs Exports three pure helpers extracted from sdk/src/query/validate.ts Check 8: - phaseVariants(phase): Set of normalized variants {"01A","1A"} etc. - buildRoadmapPhaseVariants(content): {roadmapPhases, roadmapPhaseVariants} - buildNotStartedPhaseVariants(content): Set of unchecked-phase variants Freshness check: node sdk/scripts/check-validate-fresh.mjs → FRESH References: - Issue #6 (open-gsd/get-shit-done-redux) - ADR-3524 (docs/adr/3524-cjs-sdk-hard-seam.md) - PR #154 (issue #4) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(6): migrate verify.cjs to consume validate.generated.cjs helpers (GREEN) Check 8 in verify.cjs now uses three generated helpers from validate.generated.cjs: 1. buildRoadmapPhaseVariants(roadmapContent) — replaces hand-rolled roadmapPhases Set. Produces both roadmapPhases (raw, for W006 message) and roadmapPhaseVariants (all variants, for W007 membership check). Fixes false W007 for letter-suffix phases with padding mismatch. 2. activeDiskPhases — now uses collectDiskPhases() WITHOUT forEachArchivedPhaseToken. W007 iterates activeDiskPhases, not diskPhases, so archived phases absent from current ROADMAP no longer trigger false W007. 3. buildNotStartedPhaseVariants(roadmapContent) — replaces raw+parseInt-padded notStartedPhases population. Uses phaseVariants() expansion so zero-padded letter-suffix unchecked entries (e.g. "03B") correctly suppress W006 for their un-padded counterpart ("3B") and vice versa. 4. phaseVariants() in W006 loop — replaces parseInt-padded disk-existence check. "3B" now matches disk dir "03B-foo" via variant expansion. Also updates test fixture for drift item 1 to use two milestone archives (v1.0 + v1.1), accurately reproducing the scenario where forEachArchivedPhaseToken walks ALL archives while getActiveMilestoneArchiveDir returns only the most recent one. All 5 tests GREEN. Confirmed RED on pre-fix code (git stash test). References: - Issue #6 (open-gsd/get-shit-done-redux) — maintainer acceptance criteria: "Port all three items to verify.cjs; add parity tests confirming identical output" - ADR-3524 (docs/adr/3524-cjs-sdk-hard-seam.md) - PR #154 (issue #4) — generator pattern precedent Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * ci(6): wire validate freshness check into test workflow Adds 'SDK generated validate artifact drift check' step to .github/workflows/test.yml, mirroring the pattern used by all PR #154 generator freshness checks. Runs on ubuntu-latest/node-24 only (same as other artifact drift checks). Placement: after workstream-name-policy check, before Shared Module hand-sync drift check. References: - Issue #6 (open-gsd/get-shit-done-redux) - ADR-3524 (docs/adr/3524-cjs-sdk-hard-seam.md) - PR #154 (issue #4) — precedent Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore(6): wire gen:validate into sdk/package.json, root package.json, and allowlist sdk/package.json: adds gen:validate and check:validate-fresh npm scripts. package.json: adds check:validate-fresh script (mirrors other check:*-fresh entries). scripts/shared-module-handsync-allowlist.json: updates verify.cjs justification to note that Check 8 W006/W007 helpers are now generated from validate.ts via gen-validate.mjs (issue #6), with freshness check at check-validate-fresh.mjs. References: - Issue #6 (open-gsd/get-shit-done-redux) - ADR-3524 (docs/adr/3524-cjs-sdk-hard-seam.md) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * docs(6): amend ADR-3524 — validate.ts now uses generator pattern Adds 2026-05-23 amendment section to docs/adr/3524-cjs-sdk-hard-seam.md documenting: - Generator/artifact/freshness-check/CI paths - Three drift items resolved (W007 activeDiskPhases, phaseVariants normalization, W006 unchecked-phase variant skip) - phaseVariants extraction technique (brace-balanced source-text parsing) - Parity test coverage (5 tests, RED→GREEN) - Allowlist classification preserved (cooperating-sibling) References: - Issue #6 (open-gsd/get-shit-done-redux) - ADR-3524 (docs/adr/3524-cjs-sdk-hard-seam.md) - PR #154 (issue #4) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore(6): add changeset fragment for validate.ts/verify.cjs generator migration Touches get-shit-done/bin/lib/validate.generated.cjs and verify.cjs which match USER_FACING_PREFIXES. Required by the fix-template checklist + the changeset-lint CI workflow. Refs #6 #156 * docs(6): register validate.generated.cjs in INVENTORY + manifest INVENTORY parity test demanded a row for the new generated CJS surface and a matching entry in INVENTORY-MANIFEST.json. Headline count bumped from 74 → 75. Refs #6 --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
305 lines
12 KiB
JavaScript
305 lines
12 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Regression tests for issue #6 (open-gsd/get-shit-done-redux):
|
|
* Three validation behaviors present in validate.ts are missing from verify.cjs,
|
|
* producing silent false negatives on the CJS production path.
|
|
*
|
|
* Three drift items fixed by porting phaseVariants() and activeDiskPhases to verify.cjs:
|
|
*
|
|
* 1. W007 activeDiskPhases — verify.cjs uses diskPhases (includes archived) for the
|
|
* W007 check; validate.ts uses activeDiskPhases (active phasesDir only). Archived
|
|
* phases absent from current ROADMAP trigger false W007 in verify.cjs.
|
|
*
|
|
* 2. phaseVariants() normalization — validate.ts has a phaseVariants() function
|
|
* generating padded/unpadded/letter-suffix variants for matching. verify.cjs uses
|
|
* only parseInt→padded (drops letter suffix), causing false W006/W007 for
|
|
* letter-suffix phases with padding mismatch between ROADMAP and disk.
|
|
*
|
|
* 3. W006 unchecked-phase variant skip — same phaseVariants() gap causes false W006
|
|
* for phases with padding mismatch: ROADMAP says "3B", disk has "03B-foo", but
|
|
* verify.cjs padded("3B") = "03" (drops letter) → "03B" on disk not matched.
|
|
*
|
|
* References:
|
|
* - ADR-3524 (docs/adr/3524-cjs-sdk-hard-seam.md)
|
|
* - Issue #6 (open-gsd/get-shit-done-redux)
|
|
* - PR #154 (issue #4) — precedent for the generator pattern
|
|
*/
|
|
|
|
const { describe, test, before, after } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const os = require('node:os');
|
|
|
|
const { runGsdTools } = require('./helpers.cjs');
|
|
|
|
// ── Fixture helpers ──────────────────────────────────────────────────────────
|
|
|
|
function mkplanning(base) {
|
|
const planningDir = path.join(base, '.planning');
|
|
const phasesDir = path.join(planningDir, 'phases');
|
|
fs.mkdirSync(phasesDir, { recursive: true });
|
|
return { planningDir, phasesDir };
|
|
}
|
|
|
|
function writeProjectMd(planningDir) {
|
|
fs.writeFileSync(
|
|
path.join(planningDir, 'PROJECT.md'),
|
|
'# Project\n\n## What This Is\nTest.\n\n## Core Value\nTest.\n\n## Requirements\nTest.\n',
|
|
);
|
|
}
|
|
|
|
function writeStateMd(planningDir, phase = '2') {
|
|
fs.writeFileSync(
|
|
path.join(planningDir, 'STATE.md'),
|
|
`# State\n\n**Current Phase:** ${phase}\n**Status:** In progress\n`,
|
|
);
|
|
}
|
|
|
|
function writeConfigJson(planningDir) {
|
|
fs.writeFileSync(
|
|
path.join(planningDir, 'config.json'),
|
|
JSON.stringify({ model_profile: 'balanced' }),
|
|
);
|
|
}
|
|
|
|
// ── Drift Item 1: W007 activeDiskPhases ────────────────────────────────────
|
|
//
|
|
// Project has a shipped milestone archive (milestones/v1.0-phases/) with old phase
|
|
// "1" inside, and active phasesDir with phase "2". Current ROADMAP only mentions
|
|
// Phase 2 (v1.0 phases were shipped and removed from ROADMAP).
|
|
//
|
|
// validate.ts: activeDiskPhases = phases from active phasesDir only (not archived).
|
|
// "1" is only in diskPhases (via forEachArchivedPhaseToken), not activeDiskPhases.
|
|
// W007 iterates activeDiskPhases → "1" never checked → no false W007.
|
|
//
|
|
// verify.cjs pre-fix: diskPhases = collectDiskPhases() + forEachArchivedPhaseToken().
|
|
// diskPhases includes "1" (from old archive). W007 iterates diskPhases → "1" not
|
|
// in roadmapPhases → W007 fires for "1". False positive.
|
|
|
|
describe('Drift item 1 — W007 activeDiskPhases: no false W007 for archived phases', () => {
|
|
let tmpDir;
|
|
|
|
before(() => {
|
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-6-d1-'));
|
|
const { planningDir, phasesDir } = mkplanning(tmpDir);
|
|
writeProjectMd(planningDir);
|
|
writeStateMd(planningDir);
|
|
writeConfigJson(planningDir);
|
|
|
|
fs.writeFileSync(
|
|
path.join(planningDir, 'ROADMAP.md'),
|
|
[
|
|
'# Roadmap',
|
|
'',
|
|
'- [x] **Phase 2:** API',
|
|
'',
|
|
'### Phase 2: API',
|
|
'',
|
|
'## Progress',
|
|
'| Phase | Status |',
|
|
'|-------|--------|',
|
|
'| 2 | Complete |',
|
|
].join('\n'),
|
|
);
|
|
|
|
// Active phasesDir: only phase 2
|
|
fs.mkdirSync(path.join(phasesDir, '2-api'), { recursive: true });
|
|
|
|
// Current active milestone archive: v1.1-phases contains phase 2 (in ROADMAP)
|
|
fs.mkdirSync(
|
|
path.join(planningDir, 'milestones', 'v1.1-phases', '2-api'),
|
|
{ recursive: true },
|
|
);
|
|
|
|
// Old shipped milestone archive: v1.0-phases contains phase 1 (no longer in ROADMAP)
|
|
// v1.0 sorts before v1.1 so getActiveMilestoneArchiveDir returns v1.1.
|
|
// forEachArchivedPhaseToken walks BOTH v1.0 and v1.1, so diskPhases gets "1".
|
|
// collectDiskPhases (activeDiskPhases) only uses v1.1 (active archive) — "1" excluded.
|
|
fs.mkdirSync(
|
|
path.join(planningDir, 'milestones', 'v1.0-phases', '1-foundation'),
|
|
{ recursive: true },
|
|
);
|
|
});
|
|
|
|
after(() => {
|
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
});
|
|
|
|
test('no W007 for archived phase "1" absent from current ROADMAP', () => {
|
|
// validate.ts: activeDiskPhases has only "2" (from active phasesDir + v1.1 archive).
|
|
// "1" is in diskPhases (forEachArchivedPhaseToken walks v1.0) but NOT activeDiskPhases.
|
|
// W007 iterates activeDiskPhases → "1" never checked → no false W007. Correct.
|
|
// verify.cjs pre-fix: diskPhases = collectDiskPhases + forEachArchivedPhaseToken.
|
|
// diskPhases includes "1" (from v1.0 archive). W007 iterates diskPhases → "1" not
|
|
// in roadmapPhases → W007 fires for "1". False positive.
|
|
const result = runGsdTools(['validate', 'health', '--json'], tmpDir);
|
|
assert.strictEqual(result.success, true, `unexpected failure: ${result.error}`);
|
|
const data = JSON.parse(result.output);
|
|
const w007 = (data.warnings ?? []).filter((w) => w.code === 'W007');
|
|
// Filter to W007 that mentions only phase "1" (not "1A", "01A", etc.)
|
|
const w007Phase1 = w007.filter(
|
|
(w) => /\bPhase 1\b/i.test(w.message) && !/\b1[A-Z]\b/i.test(w.message),
|
|
);
|
|
assert.strictEqual(
|
|
w007Phase1.length,
|
|
0,
|
|
`Expected no W007 for archived phase 1 (v1.0 archive), got: ${JSON.stringify(w007)}`,
|
|
);
|
|
});
|
|
});
|
|
|
|
// ── Drift Item 2: phaseVariants() normalization ────────────────────────────
|
|
//
|
|
// ROADMAP has "### Phase 01A:" (zero-padded letter-suffix heading).
|
|
// Disk has directory "1A-foo" (unpadded letter-suffix form).
|
|
// These should match because phaseVariants("01A") = {"01A", "1A", "01A"}.
|
|
//
|
|
// validate.ts: diskPhases has "1A". phaseVariants("01A") includes "1A" → match → no W006.
|
|
// activeDiskPhases has "1A". phaseVariants("1A") includes "01A" → roadmapPhaseVariants
|
|
// has "01A" → match → no W007.
|
|
//
|
|
// verify.cjs pre-fix:
|
|
// W006 loop for "01A": padded = String(parseInt("01A",10)).padStart(2,'0') = "01".
|
|
// diskPhases.has("01A")? NO. diskPhases.has("01")? NO. → W006 fires. Bug.
|
|
// W007 loop for "1A": unpadded = String(parseInt("1A",10)) = "1".
|
|
// roadmapPhases.has("1A")? NO. roadmapPhases.has("1")? NO. → W007 fires. Bug.
|
|
|
|
describe('Drift item 2 — phaseVariants() normalization: letter-suffix zero-padding mismatch', () => {
|
|
let tmpDir;
|
|
|
|
before(() => {
|
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-6-d2-'));
|
|
const { planningDir, phasesDir } = mkplanning(tmpDir);
|
|
writeProjectMd(planningDir);
|
|
writeStateMd(planningDir);
|
|
writeConfigJson(planningDir);
|
|
|
|
// ROADMAP: Phase 01A (zero-padded + letter suffix)
|
|
fs.writeFileSync(
|
|
path.join(planningDir, 'ROADMAP.md'),
|
|
[
|
|
'# Roadmap',
|
|
'',
|
|
'- [x] **Phase 01A:** Suffix Phase',
|
|
'',
|
|
'### Phase 01A: Suffix Phase',
|
|
'',
|
|
'## Progress',
|
|
'| Phase | Status |',
|
|
'|-------|--------|',
|
|
'| 01A | Complete |',
|
|
].join('\n'),
|
|
);
|
|
|
|
// Disk: unpadded form "1A-foo"
|
|
fs.mkdirSync(path.join(phasesDir, '1A-suffix-phase'), { recursive: true });
|
|
});
|
|
|
|
after(() => {
|
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
});
|
|
|
|
test('no false W006 when ROADMAP says 01A and disk has 1A-... (phaseVariants normalizes)', () => {
|
|
const result = runGsdTools(['validate', 'health', '--json'], tmpDir);
|
|
assert.strictEqual(result.success, true, `unexpected failure: ${result.error}`);
|
|
const data = JSON.parse(result.output);
|
|
const w006 = (data.warnings ?? []).filter((w) => w.code === 'W006');
|
|
assert.strictEqual(
|
|
w006.length,
|
|
0,
|
|
`Expected no W006 (01A == 1A after normalization), got: ${JSON.stringify(w006)}`,
|
|
);
|
|
});
|
|
|
|
test('no false W007 when disk has 1A and ROADMAP says 01A (phaseVariants normalizes)', () => {
|
|
const result = runGsdTools(['validate', 'health', '--json'], tmpDir);
|
|
assert.strictEqual(result.success, true, `unexpected failure: ${result.error}`);
|
|
const data = JSON.parse(result.output);
|
|
const w007 = (data.warnings ?? []).filter((w) => w.code === 'W007');
|
|
assert.strictEqual(
|
|
w007.length,
|
|
0,
|
|
`Expected no W007 (1A on disk matches 01A in ROADMAP), got: ${JSON.stringify(w007)}`,
|
|
);
|
|
});
|
|
});
|
|
|
|
// ── Drift Item 3: W006 false positive when disk uses zero-padded letter form ─
|
|
//
|
|
// ROADMAP has "### Phase 3B:" (unpadded letter-suffix heading).
|
|
// Disk has directory "03B-feature" (zero-padded letter-suffix form).
|
|
//
|
|
// validate.ts:
|
|
// diskPhases has "03B". phaseVariants("3B") = {"3B","3B","03B"}.
|
|
// existsOnDisk = diskPhases.has("03B") = TRUE → no W006.
|
|
// activeDiskPhases has "03B". phaseVariants("03B") = {"03B","3B","03B"}.
|
|
// roadmapPhaseVariants has {"3B","3B","03B"} → "03B" found → no W007.
|
|
//
|
|
// verify.cjs pre-fix:
|
|
// W006 for "3B": padded = parseInt("3B")=3 → "03" (drops "B").
|
|
// diskPhases.has("3B")? NO. diskPhases.has("03")? NO (dir is "03B" not "03"). → W006 fires.
|
|
// W007 for "03B": unpadded = String(parseInt("03B",10)) = "3".
|
|
// roadmapPhases.has("03B")? NO. roadmapPhases.has("3")? NO (ROADMAP has "3B" not "3"). → W007.
|
|
|
|
describe('Drift item 3 — W006 false positive when disk has zero-padded letter form', () => {
|
|
let tmpDir;
|
|
|
|
before(() => {
|
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-6-d3-'));
|
|
const { planningDir, phasesDir } = mkplanning(tmpDir);
|
|
writeProjectMd(planningDir);
|
|
writeStateMd(planningDir, '3B');
|
|
writeConfigJson(planningDir);
|
|
|
|
// ROADMAP: Phase 3B (unpadded in heading)
|
|
fs.writeFileSync(
|
|
path.join(planningDir, 'ROADMAP.md'),
|
|
[
|
|
'# Roadmap',
|
|
'',
|
|
'- [x] **Phase 3B:** Feature Extension',
|
|
'',
|
|
'### Phase 3B: Feature Extension',
|
|
'',
|
|
'## Progress',
|
|
'| Phase | Status |',
|
|
'|-------|--------|',
|
|
'| 3B | Complete |',
|
|
].join('\n'),
|
|
);
|
|
|
|
// Disk: "03B-feature" (zero-padded letter-suffix form)
|
|
fs.mkdirSync(path.join(phasesDir, '03B-feature'), { recursive: true });
|
|
});
|
|
|
|
after(() => {
|
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
});
|
|
|
|
test('no false W006 when ROADMAP says 3B and disk has 03B-... (phaseVariants covers zero-padded)', () => {
|
|
const result = runGsdTools(['validate', 'health', '--json'], tmpDir);
|
|
assert.strictEqual(result.success, true, `unexpected failure: ${result.error}`);
|
|
const data = JSON.parse(result.output);
|
|
const w006 = (data.warnings ?? []).filter((w) => w.code === 'W006');
|
|
assert.strictEqual(
|
|
w006.length,
|
|
0,
|
|
`Expected no W006 (3B == 03B after normalization), got: ${JSON.stringify(w006)}`,
|
|
);
|
|
});
|
|
|
|
test('no false W007 when disk has 03B and ROADMAP says 3B (phaseVariants covers both forms)', () => {
|
|
const result = runGsdTools(['validate', 'health', '--json'], tmpDir);
|
|
assert.strictEqual(result.success, true, `unexpected failure: ${result.error}`);
|
|
const data = JSON.parse(result.output);
|
|
const w007 = (data.warnings ?? []).filter((w) => w.code === 'W007');
|
|
assert.strictEqual(
|
|
w007.length,
|
|
0,
|
|
`Expected no W007 (03B on disk matches 3B in ROADMAP), got: ${JSON.stringify(w007)}`,
|
|
);
|
|
});
|
|
});
|