fix(6): retire validate.ts/verify.cjs cooperating-sibling, fix W007/phaseVariants/W006 drift via generator (#156)
* 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>
This commit is contained in:
71
get-shit-done/bin/lib/validate.generated.cjs
Normal file
71
get-shit-done/bin/lib/validate.generated.cjs
Normal file
@@ -0,0 +1,71 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* GENERATED FILE — DO NOT EDIT.
|
||||
*
|
||||
* Source: sdk/src/query/validate.ts
|
||||
* Regenerate: cd sdk && npm run gen:validate
|
||||
*
|
||||
* Validate Helpers — pure computation helpers for phase variant normalization,
|
||||
* roadmap phase variant set construction, and unchecked-phase skip set construction.
|
||||
* No I/O. No async. No filesystem operations.
|
||||
*
|
||||
* These three helpers cure the three drift items from issue #6:
|
||||
* 1. phaseVariants() — replaces parseInt-based padded/unpadded check in verify.cjs
|
||||
* Check 8 (W006 disk-existence and W007 roadmap-membership checks).
|
||||
* 2. buildRoadmapPhaseVariants() — replaces raw roadmapPhases set in W007 loop.
|
||||
* 3. buildNotStartedPhaseVariants() — replaces raw+zero-padded notStartedPhases
|
||||
* in W006 skip logic.
|
||||
*
|
||||
* I/O adapter pattern (ADR-3524 §4): pure transforms extracted from the SDK.
|
||||
*
|
||||
* References:
|
||||
* - ADR-3524 (docs/adr/3524-cjs-sdk-hard-seam.md)
|
||||
* - Issue #6 (open-gsd/get-shit-done-redux)
|
||||
* - PR #154 (issue #4) — generator pattern precedent
|
||||
*/
|
||||
|
||||
function phaseVariants(phase) {
|
||||
|
||||
const variants = new Set([phase]);
|
||||
const dotIdx = phase.indexOf('.');
|
||||
const head = dotIdx === -1 ? phase : phase.slice(0, dotIdx);
|
||||
const tail = dotIdx === -1 ? '' : phase.slice(dotIdx);
|
||||
const headMatch = head.match(/^(\d+)([A-Z]?)$/i);
|
||||
if (!headMatch)
|
||||
return variants;
|
||||
const numericHead = headMatch[1];
|
||||
const letterSuffix = headMatch[2] || '';
|
||||
variants.add(`${String(parseInt(numericHead, 10))}${letterSuffix}${tail}`);
|
||||
variants.add(`${numericHead.padStart(2, '0')}${letterSuffix}${tail}`);
|
||||
return variants;
|
||||
|
||||
}
|
||||
|
||||
function buildRoadmapPhaseVariants(roadmapContent) {
|
||||
const roadmapPhases = new Set();
|
||||
const roadmapPhaseVariants = new Set();
|
||||
const phasePattern = /#{2,4}\s*Phase\s+(\d+[A-Z]?(?:\.\d+)*)\s*:/gi;
|
||||
let m;
|
||||
while ((m = phasePattern.exec(roadmapContent)) !== null) {
|
||||
roadmapPhases.add(m[1]);
|
||||
for (const variant of phaseVariants(m[1])) roadmapPhaseVariants.add(variant);
|
||||
}
|
||||
return { roadmapPhases, roadmapPhaseVariants };
|
||||
}
|
||||
|
||||
function buildNotStartedPhaseVariants(roadmapContent) {
|
||||
const notStartedPhases = new Set();
|
||||
const uncheckedPattern = /-\s*\[\s\]\s*\*{0,2}Phase\s+(\d+[A-Z]?(?:\.\d+)*)[:\s*]/gi;
|
||||
let um;
|
||||
while ((um = uncheckedPattern.exec(roadmapContent)) !== null) {
|
||||
for (const variant of phaseVariants(um[1])) notStartedPhases.add(variant);
|
||||
}
|
||||
return notStartedPhases;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
phaseVariants,
|
||||
buildRoadmapPhaseVariants,
|
||||
buildNotStartedPhaseVariants,
|
||||
};
|
||||
@@ -2,6 +2,8 @@
|
||||
* Verify — Verification suite, consistency, and health validation
|
||||
*/
|
||||
|
||||
const { phaseVariants, buildRoadmapPhaseVariants, buildNotStartedPhaseVariants } = require('./validate.generated.cjs');
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
@@ -854,48 +856,63 @@ function cmdValidateHealth(cwd, options, raw) {
|
||||
// archive (completed + archived). forEachArchivedPhaseToken is therefore
|
||||
// called below to add archived dirs to diskPhases so W006 does not fire
|
||||
// for them. (#3652, #3806)
|
||||
//
|
||||
// Fix #6 (three drift items vs sdk/src/query/validate.ts Check 8):
|
||||
// 1. activeDiskPhases: separate from diskPhases; only active phasesDir phases.
|
||||
// W007 uses activeDiskPhases so archived phases don't produce false W007.
|
||||
// 2. phaseVariants() + buildRoadmapPhaseVariants(): W006 disk-existence check
|
||||
// and W007 roadmap-membership check now use full variant sets, fixing
|
||||
// false W006/W007 for letter-suffix phases with padding mismatch.
|
||||
// 3. buildNotStartedPhaseVariants(): replaces raw+parseInt-padded notStartedPhases
|
||||
// with phaseVariants() expansion, fixing W006 unchecked-phase skip for
|
||||
// zero-padded letter-suffix forms.
|
||||
if (fs.existsSync(roadmapPath)) {
|
||||
const roadmapContentRaw = fs.readFileSync(roadmapPath, 'utf-8');
|
||||
const roadmapContent = extractCurrentMilestone(roadmapContentRaw, cwd);
|
||||
const roadmapPhases = new Set();
|
||||
const phasePattern = /#{2,4}\s*Phase\s+(\d+[A-Z]?(?:\.\d+)*)\s*:/gi;
|
||||
let m;
|
||||
while ((m = phasePattern.exec(roadmapContent)) !== null) {
|
||||
roadmapPhases.add(m[1]);
|
||||
}
|
||||
|
||||
// Build roadmapPhases (raw) and roadmapPhaseVariants (all normalized variants).
|
||||
// roadmapPhases: used for W006 disk-existence check (preserve original for message).
|
||||
// roadmapPhaseVariants: used for W007 roadmap-membership check.
|
||||
const { roadmapPhases, roadmapPhaseVariants } = buildRoadmapPhaseVariants(roadmapContent);
|
||||
|
||||
// diskPhases: active phasesDir + archived milestone dirs (for W006 — archived phases
|
||||
// are valid on-disk locations for historical ROADMAP phases).
|
||||
const diskPhases = collectDiskPhases(planBase);
|
||||
// Include archived milestone phase directories as valid on-disk locations.
|
||||
// Mirrors forEachArchivedPhaseToken call in sdk/src/query/validate.ts
|
||||
// Check 8. (#3806)
|
||||
// Mirrors forEachArchivedPhaseToken call in sdk/src/query/validate.ts Check 8. (#3806)
|
||||
forEachArchivedPhaseToken(planBase, (token) => diskPhases.add(token));
|
||||
|
||||
// Build a set of phases explicitly marked not-yet-started in the ROADMAP
|
||||
// summary list (- [ ] **Phase N:**). These phases are intentionally absent
|
||||
// from disk -- W006 must not fire for them (#2009).
|
||||
const notStartedPhases = new Set();
|
||||
const uncheckedPattern = /-\s*\[\s\]\s*\*{0,2}Phase\s+(\d+[A-Z]?(?:\.\d+)*)[:\s*]/gi;
|
||||
let um;
|
||||
while ((um = uncheckedPattern.exec(roadmapContent)) !== null) {
|
||||
notStartedPhases.add(um[1]);
|
||||
// Also add zero-padded variant so 1 and 01 both match
|
||||
notStartedPhases.add(String(parseInt(um[1], 10)).padStart(2, '0'));
|
||||
}
|
||||
// activeDiskPhases: only phases from the active phasesDir (NOT archived).
|
||||
// Used for W007: archived phases should not trigger W007 even if absent from
|
||||
// current ROADMAP (they were shipped in a prior milestone). (#6 drift item 1)
|
||||
const activeDiskPhases = collectDiskPhases(planBase);
|
||||
|
||||
// Phases in ROADMAP but not on disk
|
||||
// Build a set of all variants of phases explicitly marked not-yet-started in
|
||||
// the ROADMAP summary list (- [ ] **Phase N:**). These phases are intentionally
|
||||
// absent from disk — W006 must not fire for them. (#2009, #6 drift item 3)
|
||||
// buildNotStartedPhaseVariants() uses phaseVariants() so zero-padded letter-suffix
|
||||
// forms like "03B" are recognized even when the unchecked entry says "3B".
|
||||
const notStartedPhases = buildNotStartedPhaseVariants(roadmapContent);
|
||||
|
||||
// Phases in ROADMAP but not on disk (W006)
|
||||
// Uses phaseVariants() for disk-existence check so "3B" matches disk dir "03B-foo".
|
||||
for (const p of roadmapPhases) {
|
||||
const padded = String(parseInt(p, 10)).padStart(2, '0');
|
||||
if (!diskPhases.has(p) && !diskPhases.has(padded)) {
|
||||
const variants = phaseVariants(p);
|
||||
const existsOnDisk = [...variants].some((v) => diskPhases.has(v));
|
||||
if (!existsOnDisk) {
|
||||
// Skip phases explicitly flagged as not-yet-started in the summary list
|
||||
if (notStartedPhases.has(p) || notStartedPhases.has(padded)) continue;
|
||||
const isNotStarted = [...variants].some((v) => notStartedPhases.has(v));
|
||||
if (isNotStarted) continue;
|
||||
addIssue('warning', 'W006', `Phase ${p} in ROADMAP.md but no directory on disk`, 'Create phase directory or remove from roadmap');
|
||||
}
|
||||
}
|
||||
|
||||
// Phases on disk but not in ROADMAP
|
||||
for (const p of diskPhases) {
|
||||
const unpadded = String(parseInt(p, 10));
|
||||
if (!roadmapPhases.has(p) && !roadmapPhases.has(unpadded)) {
|
||||
// Phases on disk but not in ROADMAP (W007)
|
||||
// Uses activeDiskPhases (no archived) and roadmapPhaseVariants (all variants)
|
||||
// so neither archived phases nor padding-mismatch phases trigger false W007.
|
||||
for (const p of activeDiskPhases) {
|
||||
const variants = phaseVariants(p);
|
||||
if (![...variants].some((v) => roadmapPhaseVariants.has(v))) {
|
||||
addIssue('warning', 'W007', `Phase ${p} exists on disk but not in ROADMAP.md`, 'Add to roadmap or remove directory');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user