Files
msd-core/tests/add-todo.test.cjs
Tom Boucher a875372f18 test(#3335): fold the workflow-content & phase-lifecycle fix-* cluster — Wave 3 (#3373)
* test(#3335): fold the workflow-content & phase-lifecycle fix-* cluster — Wave 3

Folds 13 legacy fix-*.test.cjs regression files (131 test() blocks) into
their module's main suite, per H3 (#3315) of the test-hygiene epic (#3053):

- 6 files with no prior target coverage: renamed (git mv) into new suites
  (spike-manifest-scoping, ship-note, add-todo, workflow-jq-dependency,
  resolve-execution-dynamic-routing, clock)
- 7 files merged into 5 pre-existing suites (worktree-base-ref x2,
  model-resolver, phase-locator x2, frontmatter, verification-status),
  deduplicated against existing coverage

Zero net test-coverage loss: every source assertion preserved or verified
as a genuine pre-existing duplicate. No production code changed.

Last fix-* wave (Wave 1 #3341, Wave 2 #3342 already merged); 4 issue-*
waves remain in #3315.

* test(#3335): fix orthogonal-review findings — Wave 3 fold

Standards-axis review + Memtrace graph pass found real defects in the
just-folded suites, all fixed here:

- phase-locator.test.cjs: pinned an unseeded fast-check property test
  (CONTRIBUTING.md determinism requirement), matching the sibling test's
  seed:7 convention.
- phase-locator.test.cjs: added assert.ok() presence guards after 9
  data.plans.find() calls that were dereferenced unguarded, inconsistent
  with 5 sibling tests in the same file that already guard correctly.
  Latent robustness gap — an omitted plan would throw an opaque TypeError
  instead of a clear assertion failure.
- Standardized the fold-wrapper convention (block-scoped __foldDescribe)
  across worktree-base-ref.test.cjs, verification-status.test.cjs, and
  phase-locator.test.cjs to match the pattern already established in
  frontmatter.test.cjs and model-resolver.test.cjs from earlier folds.
- worktree-base-ref.test.cjs: moved a mid-file require to the top-of-file
  require block.
- Eliminated duplicated env-isolation helpers: model-resolver.test.cjs and
  phase-locator.test.cjs each reimplemented GSD_WORKSTREAM/GSD_PROJECT
  save-restore independently; factored a shared isolateWorkstreamEnv()/
  restoreWorkstreamEnv() into tests/helpers.cjs and pointed both call
  sites at it.

No test() count changed in any file. No production code touched.

---------

Co-authored-by: sim <sim@local>
2026-08-11 22:23:55 -04:00

65 lines
2.9 KiB
JavaScript

// allow-test-rule: source-text-is-the-product #2337
//
// The add-todo.md workflow IS the runtime contract an agent follows when
// capturing a todo. #2337: it had no severity step and no severity frontmatter
// field, so severity discipline depended on an out-of-band convention the agent
// had to remember — and production todos landed with no `severity:` at all.
//
// These assertions guard the specific must-haves (issue #2337 acceptance
// criteria 1): a confirm-based `infer_severity` step positioned BEFORE the todo
// is written, and a `severity` field in the create_file frontmatter template.
// The golden-install-parity hash catches ANY change to this file, but not
// WHICH change — this test pins the two structural guarantees so a future edit
// can't silently drop the step while still updating the golden.
'use strict';
const { describe, test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const ADD_TODO = path.join(__dirname, '..', 'gsd-core', 'workflows', 'add-todo.md');
describe('add-todo.md severity capture (#2337)', () => {
const md = fs.readFileSync(ADD_TODO, 'utf8');
test('defines an infer_severity step', () => {
assert.match(md, /<step name="infer_severity">/,
'add-todo.md must define an infer_severity step');
});
test('infer_severity runs before the file is written (create_file)', () => {
const sev = md.indexOf('<step name="infer_severity">');
const create = md.indexOf('<step name="create_file">');
assert.ok(sev !== -1 && create !== -1, 'both steps must exist');
assert.ok(sev < create,
'infer_severity must precede create_file so severity is confirmed before write');
});
test('infer_severity confirms with the user — never a silent auto-assignment', () => {
const stepStart = md.indexOf('<step name="infer_severity">');
const stepEnd = md.indexOf('</step>', stepStart);
const step = md.slice(stepStart, stepEnd);
assert.match(step, /AskUserQuestion/,
'severity must be confirmed via AskUserQuestion (with the TEXT_MODE fallback), not auto-assigned');
assert.match(step, /TEXT_MODE/,
'must provide the non-Claude-runtime numbered-list fallback');
});
test('the create_file frontmatter template carries a severity field', () => {
assert.match(md, /^severity:\s*\[blocker\|major\|minor\|cosmetic/m,
'create_file frontmatter template must include a severity field');
});
test('severity taxonomy matches verify-work.md (blocker/major/minor/cosmetic)', () => {
const stepStart = md.indexOf('<step name="infer_severity">');
const stepEnd = md.indexOf('</step>', stepStart);
const step = md.slice(stepStart, stepEnd);
for (const level of ['blocker', 'major', 'minor', 'cosmetic']) {
assert.match(step, new RegExp(level),
`severity taxonomy must include "${level}" to stay aligned with verify-work.md's severity_inference`);
}
});
});