Files
msd-core/tests/anti-pattern-enforcement.test.cjs
Jakub Zych a9a7a328e6 refactor: hard-fork GSD -> MSD (Make Software Done)
Mechanical rename produced by scripts/msd-rename.cjs: gsd/Gsd/GSD -> msd/Msd/MSD
across contents and paths, upstream package/repo coordinates -> @golem15/msd-core
and golem15com/msd-core. Deep links into upstream history, sibling upstream
packages, the GSD-2 import feature, CHANGELOG.md and .changeset/ are kept as-is.

Hand edits on top: MSD block-letter banner and logos, LICENSE copyright line,
package/plugin identity, regenerated lockfile, install-tree fixtures, derived
registries and benchmark baseline; migration checksum baseline re-locked
(MSD keeps its own install state, so no install had applied the old sums);
sort-order and regex-escaped expectations in tests adjusted.
2026-10-06 01:47:40 +02:00

182 lines
7.2 KiB
JavaScript

// allow-test-rule: source-text-is-the-product
// Workflow .md / agent .md / command .md / reference .md files — their text
// IS what the runtime loads. Testing text content tests the deployed contract.
// Per CONTRIBUTING.md exception matrix.
'use strict';
/**
* Anti-Pattern Enforcement Tests (#1491)
*
* Validates that the handoff/resume system structurally enforces critical
* anti-patterns via severity levels and mandatory understanding checks.
*/
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
const PAUSE_WORK = path.join(__dirname, '..', 'msd-core', 'workflows', 'pause-work.md');
const DISCUSS_PHASE = path.join(__dirname, '..', 'msd-core', 'workflows', 'discuss-phase.md');
const EXECUTE_PHASE = path.join(__dirname, '..', 'msd-core', 'workflows', 'execute-phase.md');
describe('pause-work.md — severity column in Critical Anti-Patterns template', () => {
test('template includes a Severity column header in the anti-patterns table', () => {
const content = fs.readFileSync(PAUSE_WORK, 'utf-8');
assert.ok(
content.includes('Severity') || content.includes('severity'),
'pause-work.md template must include a Severity column in the anti-patterns table'
);
});
test('template documents "blocking" as a valid severity value', () => {
const content = fs.readFileSync(PAUSE_WORK, 'utf-8');
assert.ok(
content.includes('blocking'),
'pause-work.md must document "blocking" as a valid severity value'
);
});
test('template documents "advisory" as a valid severity value', () => {
const content = fs.readFileSync(PAUSE_WORK, 'utf-8');
assert.ok(
content.includes('advisory'),
'pause-work.md must document "advisory" as a valid severity value'
);
});
test('template explains that blocking anti-patterns trigger understanding check at resume', () => {
const content = fs.readFileSync(PAUSE_WORK, 'utf-8');
const hasExplanation =
(content.includes('blocking') && content.includes('understanding check')) ||
(content.includes('blocking') && content.includes('resume')) ||
(content.includes('blocking') && content.includes('understanding'));
assert.ok(
hasExplanation,
'pause-work.md must explain that blocking anti-patterns trigger an understanding check at resume'
);
});
});
describe('discuss-phase.md — blocking anti-pattern understanding check', () => {
test('workflow checks for .continue-here.md with blocking anti-patterns', () => {
const content = fs.readFileSync(DISCUSS_PHASE, 'utf-8');
const hasCheck =
content.includes('.continue-here.md') &&
(content.includes('blocking') || content.includes('anti-pattern'));
assert.ok(
hasCheck,
'discuss-phase.md must check for .continue-here.md blocking anti-patterns before proceeding'
);
});
test('workflow includes mandatory understanding verification for blocking anti-patterns', () => {
const content = fs.readFileSync(DISCUSS_PHASE, 'utf-8');
const hasVerification =
content.includes('understanding') ||
content.includes('understanding check') ||
content.includes('demonstrate understanding');
assert.ok(
hasVerification,
'discuss-phase.md must include a mandatory understanding verification step for blocking anti-patterns'
);
});
test('workflow specifies the three understanding check questions', () => {
const content = fs.readFileSync(DISCUSS_PHASE, 'utf-8');
// The three questions required by the issue
const hasWhatIs =
content.includes('What is this anti-pattern') ||
content.includes('what is this anti-pattern') ||
content.includes('What is the anti-pattern');
const hasHowManifest =
content.includes('How did it manifest') ||
content.includes('how did it manifest') ||
content.includes('manifest');
const hasPreventMechanism =
content.includes('structural mechanism') ||
content.includes('prevention') ||
content.includes('Prevention');
assert.ok(
hasWhatIs && hasHowManifest && hasPreventMechanism,
'discuss-phase.md must include the three understanding check questions: ' +
'"What is this anti-pattern?", "How did it manifest?", "What structural mechanism prevents it?"'
);
});
test('understanding check cannot be skipped (must be mandatory)', () => {
const content = fs.readFileSync(DISCUSS_PHASE, 'utf-8');
const hasMandatory =
content.includes('cannot be skipped') ||
content.includes('must not be skipped') ||
content.includes('mandatory') ||
content.includes('MANDATORY') ||
content.includes('required before');
assert.ok(
hasMandatory,
'discuss-phase.md must indicate that the blocking anti-pattern understanding check cannot be skipped'
);
});
});
describe('execute-phase.md — blocking anti-pattern understanding check', () => {
test('workflow checks for .continue-here.md with blocking anti-patterns', () => {
const content = fs.readFileSync(EXECUTE_PHASE, 'utf-8');
const hasCheck =
content.includes('.continue-here.md') &&
(content.includes('blocking') || content.includes('anti-pattern'));
assert.ok(
hasCheck,
'execute-phase.md must check for .continue-here.md blocking anti-patterns before proceeding'
);
});
test('workflow includes mandatory understanding verification for blocking anti-patterns', () => {
const content = fs.readFileSync(EXECUTE_PHASE, 'utf-8');
const hasVerification =
content.includes('understanding') ||
content.includes('understanding check') ||
content.includes('demonstrate understanding');
assert.ok(
hasVerification,
'execute-phase.md must include a mandatory understanding verification step for blocking anti-patterns'
);
});
test('workflow specifies the three understanding check questions', () => {
const content = fs.readFileSync(EXECUTE_PHASE, 'utf-8');
const hasWhatIs =
content.includes('What is this anti-pattern') ||
content.includes('what is this anti-pattern') ||
content.includes('What is the anti-pattern');
const hasHowManifest =
content.includes('How did it manifest') ||
content.includes('how did it manifest') ||
content.includes('manifest');
const hasPreventMechanism =
content.includes('structural mechanism') ||
content.includes('prevention') ||
content.includes('Prevention');
assert.ok(
hasWhatIs && hasHowManifest && hasPreventMechanism,
'execute-phase.md must include the three understanding check questions: ' +
'"What is this anti-pattern?", "How did it manifest?", "What structural mechanism prevents it?"'
);
});
test('understanding check cannot be skipped (must be mandatory)', () => {
const content = fs.readFileSync(EXECUTE_PHASE, 'utf-8');
const hasMandatory =
content.includes('cannot be skipped') ||
content.includes('must not be skipped') ||
content.includes('mandatory') ||
content.includes('MANDATORY') ||
content.includes('required before');
assert.ok(
hasMandatory,
'execute-phase.md must indicate that the blocking anti-pattern understanding check cannot be skipped'
);
});
});