Files
get-shit-done/tests/anti-pattern-enforcement.test.cjs
Tom Boucher 2703422be8 refactor(tests): standardize to node:assert/strict and t.after() per CONTRIBUTING.md (#1675)
* refactor(tests): standardize to node:assert/strict and t.after() per CONTRIBUTING.md

- Replace require('node:assert') with require('node:assert/strict') across
  all 73 test files to enforce strict equality (no type coercion)
- Replace try/finally cleanup blocks with t.after() hooks in core.test.cjs
  and hooks-opt-in.test.cjs per the test lifecycle standards
- Utility functions in codex-config and security-scan retain try/finally
  as that is appropriate for per-function resource guards, not lifecycle hooks

Closes #1674

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* perf(tests): add --test-concurrency=4 to test runner for parallel file execution

Node.js --test-concurrency controls how many test files run as parallel child
processes. Set to 4 by default, configurable via TEST_CONCURRENCY env var.
Fixes tests at a known level rather than inheriting os.availableParallelism()
which varies across CI environments.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(security): allowlist verify.test.cjs in prompt-injection scanner

tests/verify.test.cjs uses <human>...</human> as GSD phase task-type
XML (meaning "a human should verify this step"), which matches the
scanner's fake-message-boundary pattern for LLM APIs. This is a
false positive — add it to the allowlist alongside the other test files
that legitimately contain injection-adjacent patterns.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-04 14:29:03 -04:00

177 lines
7.0 KiB
JavaScript

'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, '..', 'get-shit-done', 'workflows', 'pause-work.md');
const DISCUSS_PHASE = path.join(__dirname, '..', 'get-shit-done', 'workflows', 'discuss-phase.md');
const EXECUTE_PHASE = path.join(__dirname, '..', 'get-shit-done', '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'
);
});
});