Files
msd-core/tests/issue-2828-flat-roadmap-total-phases.test.cjs
sim 7dd9e59f6b test(#3090): stop exempting violations under categories that do not fit
An allow-test-rule annotation citing a category that does not apply is worse
than no annotation, because it reads as reviewed. Eight were confirmed by
reading the assertions each one covered, and auditing the rest found five more
plus one refutation — a converter test whose wording described the wrong
mechanism while the covered assertion genuinely was deployed-text.

The instructive one used the CANONICAL string for the same mistake: STATE.md
command output labelled as a deployed artifact. A canonical string is not
evidence the category fits, which is why normalising strings alone would have
laundered the problem rather than fixed it. Every mapping the audit had inferred
rather than code-verified was spot-checked before rewriting, and the ones that
turned out not to fit were re-annotated rather than relabelled.

Fourteen STATE.md assertions had a typed extractor available all along and now
use it; their annotations came out because nothing needs exempting. Eight
assertions genuinely need a production change first — CLI stdout and stderr with
no structured mode — and are tagged pending-migration-to-typed-ir citing #3090,
which is what that category is for. It had zero real uses before this, while one
file carried a real citation to migration issue #2974 under a non-canonical tag.

Six annotations covered assertions that do no text matching at all. An exemption
for a violation that does not exist is noise that makes the real ones harder to
audit; those are removed.

atomic-write-coverage gains the annotation it always warranted — its own
docstring describes a structural-regression-guard while the file carried none.

Fifty-nine non-canonical strings across roughly thirty files are normalised, and
the allow-test-rule allowlist is regenerated to match. 472 annotations became
463: every one now uses a canonical category, and the two remaining
non-canonical strings are ESLint RuleTester fixtures, not annotations.

Refs #3057

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-05 17:20:56 -04:00

95 lines
3.7 KiB
JavaScript

'use strict';
// Regression guard for #2828: on a flat unmilestoned roadmap (no versioned milestone
// heading), `state-snapshot`/`state record-session` reported progress.total_phases as
// the on-disk phase-dir count (1) instead of the authoritative roadmap count (6). The
// read-path disk-scan cache fell back to phaseDirs.length when milestoneBounded was
// false, even though roadmapPhaseCount (6) was correct for a flat roadmap (no sibling
// milestones to conflate). Fix: use roadmapPhaseCount as the floor when > 0.
const { test, describe, beforeEach, afterEach } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
const { runGsdTools, createTempProject, cleanup } = require('./helpers.cjs');
describe('#2828 — total_phases uses the roadmap count on a flat unmilestoned roadmap', () => {
let tmpDir;
beforeEach(() => {
tmpDir = createTempProject('gsd-2828-');
const planningDir = path.join(tmpDir, '.planning');
// Flat unmilestoned roadmap with 6 phases (no versioned milestone heading).
fs.writeFileSync(
path.join(planningDir, 'ROADMAP.md'),
[
'# Roadmap',
'',
'### Phase 1: Foundation',
'### Phase 2: Core API',
'### Phase 3: UI Layer',
'### Phase 4: Integration',
'### Phase 5: Polish',
'### Phase 6: Release',
'',
].join('\n'),
);
// Only phase 1 has been discussed → 1 phase dir on disk.
const phaseDir = path.join(planningDir, 'phases', '01-foundation');
fs.mkdirSync(phaseDir, { recursive: true });
fs.writeFileSync(path.join(phaseDir, 'CONTEXT.md'), '# Phase 1 Context\n');
// Minimal STATE.md with a milestone set (so milestoneBounded is computed) but no
// versioned heading to bound it to → the flat-roadmap unbounded case.
fs.writeFileSync(
path.join(planningDir, 'STATE.md'),
[
'---',
'status: executing',
'milestone: v1.0',
'milestone_name: milestone',
'---',
'',
'# Project State',
'',
'**Current Phase:** 01',
'**Status:** In progress',
'',
].join('\n'),
);
});
afterEach(() => cleanup(tmpDir));
test('state sync writes progress.total_phases === 6 (roadmap count), not 1 (phase-dir count) (#2828)', () => {
// `state sync` derives progress.total_phases from the disk-scan cache (the read path
// #2828 fixes) and writes it to STATE.md frontmatter. Pre-fix this wrote 1.
const result = runGsdTools(['state', 'sync'], tmpDir);
assert.ok(result.success, `state sync failed: ${result.error}`);
const stateMd = fs.readFileSync(path.join(tmpDir, '.planning', 'STATE.md'), 'utf8');
// Parse the `progress:` YAML block line-by-line (ReDoS-safe: avoids a nested-quantifier
// regex over the whole block). Find total_phases among the block's indented children.
const lines = stateMd.split(/\r?\n/);
let inProgress = false;
let totalPhases = null;
for (const line of lines) {
if (/^progress:\s*$/.test(line)) { inProgress = true; continue; }
if (inProgress) {
// A new top-level (column-0) key ends the progress block.
if (/^\S/.test(line)) { inProgress = false; continue; }
const tp = line.match(/^\s+total_phases:\s*(\d+)/);
if (tp) { totalPhases = Number(tp[1]); break; }
}
}
assert.ok(
totalPhases !== null,
`progress.total_phases must be written by state sync. STATE.md:\n${stateMd}`,
);
assert.strictEqual(
totalPhases,
6,
`progress.total_phases must be the roadmap count (6) for a flat unmilestoned roadmap, not the on-disk phase-dir count (1). Got: ${totalPhases}`,
);
});
});