* fix: require fresh phase verification before transition * no-mistakes(review): Fix canonical verification closeout gates * no-mistakes(review): Fix verify-work frontmatter promotion command * no-mistakes(review): Fix stale verification gates * no-mistakes(review): Fix canonical verification routing gates * no-mistakes(review): Fix verification dependency and runtime routing gates * no-mistakes(review): Block stale verification bypasses * fix: handle large init manager outputs in verification workflows * chore: update changeset pr number * fix(verify-work): use fresh verification.status for stale gate The stale check after UAT used phase_completion.verification_status from session-start INIT while human_needed promotion already queried fresh verification.status. Align the stale gate with the canonical query so mid-session verification refresh is not ignored. * fix(init): skip roadmap-checked phases when selecting next_phase Roadmap-only phases without a disk directory were still promoted to next_phase when their checkbox was already checked. Exclude checkboxComplete phases so progress routing does not point at work the roadmap already marks done. * fix: gaps_found not overridden by stale, transition uses canonical verification - verification.cts: check gaps_found before stale so gap-closure routing is not masked by a newer summary mtime - phase.cts: remove redundant findStaleVerificationSummary — readVerificationStatus already handles stale detection - transition.md: replace raw grep on file content with verification.status query to avoid false-positive blocks from body text matching * ci: retrigger tests after rebase * fix(transition): replace gsd_run advisory check with awk frontmatter extraction The runtime launcher is not defined until the update_roadmap_and_state step bash block (~line 165). The early verify_completion block used gsd_run to query verification.status, which violated the runtime-launcher-parity test: 'preamble appears AFTER the first gsd_run reference'. Replace the gsd_run call with an awk-based frontmatter extractor that reads only the status: field between the two --- fences. This avoids both the preamble-ordering constraint and the original false-positive grep bug where body text like 'previous_status: gaps_found' would match a full-text regex. The phase.complete gate at update_roadmap_and_state is the canonical enforcement point; this early check is advisory only. Also update workflow-size-baseline.json for the updated transition.md size. Fixes: runtime-launcher-parity test (B) Co-authored-by: Codesmith <codesmith-bot@users.noreply.github.com> * fix: re-check verification under planning lock in phase complete Move readVerificationStatus into withPlanningLock so stale verification cannot slip through when a SUMMARY.md is written between the gate and the roadmap/state mutation. Return the blocked status from the lock callback and emit the error after release to avoid leaving .lock behind. * fix(transition): gate on canonical verification.status including stale Replace awk frontmatter read with verification.status query so transition blocks when summaries are newer than VERIFICATION.md, matching phase.complete and other workflows (autonomous, progress, verify-work). * Fix workflow verification gates for yolo transition and stale routing Require VERIFY_STATUS passed before yolo/interactive transition advance. Route stale verification recovery to verify-work, matching canonical projection. * fix(transition): use verification.status query for stale-aware advisory check The awk-based check read raw frontmatter status: passed, which misses the stale case where summaries are newer than the VERIFICATION.md file even though the frontmatter still says passed. The stale status is computed from file modification times, not stored in frontmatter. Move the preamble to the verify_completion bash block (the first block with a gsd_run call) so gsd_run query verification.status can be used for the advisory check. This gives the full readVerificationStatus logic including mtime-based staleness detection, matching the enforcement gate at phase.complete. Capture full JSON (VERIFY_JSON) so next_action can be included in the advisory output alongside the status. Also update workflow-size-baseline.json for the updated transition.md size. Co-authored-by: Codesmith <codesmith-bot@users.noreply.github.com> * ci: trigger test matrix for 525b946 Co-authored-by: Codesmith <codesmith-bot@users.noreply.github.com> * fix(transition): restore awk frontmatter extraction for pre-shim verification check The gsd_run launcher shim is not defined until line ~163 of transition.md, so the verification debt check at line ~80 cannot use gsd_run. Restore the awk-based frontmatter extraction that correctly reads status without needing the runtime, and restore the shim at its proper location before phase.complete. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(#1522): clarify transition verification gate wording * fix(#1522): update transition workflow size baseline * fix(#1522): update workflow-size-baseline after rebase onto next Co-authored-by: Codesmith <codesmith-bot@users.noreply.github.com> * fix(#1522): guard findStaleVerificationSummary FS calls + thread opts.fs seam (review) Address review blocker B1 on #1548: findStaleVerificationSummary ran fs.readdirSync and two fs.statSync calls unguarded between readVerificationStatus's try/catch sections, so a TOCTOU race (a SUMMARY listed by scanPhasePlans then removed before statSync) or any FS error threw uncaught into callers NOT under the planning lock (init.manager / init.progress / uat-predicate). Wrap the body in try/catch degrading to 'not stale', and thread the injectable opts.fs seam (add statSync to FsLike, pass fsImpl from the caller) for parity with readVerificationStatus's no-throw contract and testability. Also adds the Verification Module glossary entry to CONTEXT.md (review B3). --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Codesmith <codesmith-bot@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Tom Boucher <trekkie@nomorestars.com>
111 lines
4.5 KiB
JavaScript
111 lines
4.5 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Regression test for #3588 — production dependency tree must not carry
|
|
* high or moderate npm-audit advisories.
|
|
*
|
|
* Strategy: run `npm audit --omit=dev --json` against both the root
|
|
* workspace and the embedded SDK package and assert that the metadata
|
|
* vulnerability counts are zero across info/low/moderate/high/critical.
|
|
*
|
|
* The test is intentionally strict — any advisory of any severity (other
|
|
* than 'low' if the maintainer accepts it; that branch is left explicit
|
|
* here) blocks CI. If a future advisory lands without an upstream patch,
|
|
* either bump the patched transitive (preferred), or annotate the
|
|
* acceptance below with a justification AND a link to the upstream tracker.
|
|
*
|
|
* Skips automatically when `node_modules/` is absent (a fresh checkout
|
|
* before `npm install`) so the test does not falsely report on developer
|
|
* machines mid-setup.
|
|
*/
|
|
|
|
const { test, describe } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const path = require('node:path');
|
|
const fs = require('node:fs');
|
|
const { execFileSync } = require('node:child_process');
|
|
|
|
const ROOT = path.resolve(__dirname, '..');
|
|
const SDK = path.join(ROOT, 'sdk');
|
|
const AUDIT_TIMEOUT_MS = 180_000;
|
|
const TEST_TIMEOUT_MS = AUDIT_TIMEOUT_MS + 30_000;
|
|
|
|
function auditProductionVulns(cwd) {
|
|
if (!fs.existsSync(path.join(cwd, 'package.json'))) {
|
|
return null; // signal "skip" to caller
|
|
}
|
|
if (!fs.existsSync(path.join(cwd, 'node_modules'))) {
|
|
return null; // signal "skip" to caller
|
|
}
|
|
const isWindows = process.platform === 'win32';
|
|
const npmCandidates = isWindows ? ['npm.cmd', 'npm'] : ['npm'];
|
|
const args = ['audit', '--omit=dev', '--json'];
|
|
let out;
|
|
let lastErr = null;
|
|
for (const npmCmd of npmCandidates) {
|
|
try {
|
|
out = execFileSync(
|
|
npmCmd,
|
|
args,
|
|
{
|
|
cwd,
|
|
encoding: 'utf-8',
|
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
timeout: AUDIT_TIMEOUT_MS,
|
|
shell: isWindows,
|
|
}
|
|
);
|
|
lastErr = null;
|
|
break;
|
|
} catch (e) {
|
|
// `npm audit` exits non-zero when advisories are present; the JSON is
|
|
// still on stdout in that case. Recover and let the assertion classify.
|
|
if (e && typeof e.stdout !== 'undefined' && e.stdout !== undefined && e.stdout !== null) {
|
|
out = Buffer.isBuffer(e.stdout) ? e.stdout.toString('utf-8') : String(e.stdout);
|
|
lastErr = null;
|
|
break;
|
|
}
|
|
lastErr = e;
|
|
}
|
|
}
|
|
if (lastErr) throw lastErr;
|
|
const parsed = JSON.parse(out);
|
|
// `null` is reserved for the "node_modules missing → skip" signal above.
|
|
// Any other unexpected JSON shape is a real failure of the audit harness
|
|
// (npm changed its output format, audit aborted before metadata, etc.) —
|
|
// throw so the test fails loudly instead of skipping silently.
|
|
if (parsed && parsed.metadata && parsed.metadata.vulnerabilities) {
|
|
return parsed.metadata.vulnerabilities;
|
|
}
|
|
throw new Error(`Unexpected npm audit JSON shape in ${cwd}: missing metadata.vulnerabilities`);
|
|
}
|
|
|
|
describe('#3588: npm audit --omit=dev reports zero advisories', () => {
|
|
test('root workspace production tree has no advisories', { timeout: TEST_TIMEOUT_MS }, (t) => {
|
|
const vulns = auditProductionVulns(ROOT);
|
|
if (vulns === null) {
|
|
t.skip('auditable npm package not present or node_modules/ missing');
|
|
return;
|
|
}
|
|
assert.strictEqual(vulns.critical, 0, `expected 0 critical; got ${vulns.critical}`);
|
|
assert.strictEqual(vulns.high, 0, `expected 0 high; got ${vulns.high}`);
|
|
assert.strictEqual(vulns.moderate, 0, `expected 0 moderate; got ${vulns.moderate}`);
|
|
// Low advisories are not explicitly forbidden by the #3588 acceptance
|
|
// criterion but the issue listed only high/moderate as actual findings —
|
|
// tighten if any future low advisory is introduced.
|
|
assert.strictEqual(vulns.low, 0, `expected 0 low; got ${vulns.low}`);
|
|
});
|
|
|
|
test('sdk/ production tree has no advisories', { timeout: TEST_TIMEOUT_MS }, (t) => {
|
|
const vulns = auditProductionVulns(SDK);
|
|
if (vulns === null) {
|
|
t.skip('sdk/ is not an auditable npm package or sdk/node_modules/ is missing');
|
|
return;
|
|
}
|
|
assert.strictEqual(vulns.critical, 0, `expected 0 critical; got ${vulns.critical}`);
|
|
assert.strictEqual(vulns.high, 0, `expected 0 high; got ${vulns.high}`);
|
|
assert.strictEqual(vulns.moderate, 0, `expected 0 moderate; got ${vulns.moderate}`);
|
|
assert.strictEqual(vulns.low, 0, `expected 0 low; got ${vulns.low}`);
|
|
});
|
|
});
|