test(tests): antagonistic tier — fast-check property tests + Stryker mutation testing (PR-gated) (#461)
* feat(#454): add antagonistic tier — fast-check property tests + Stryker mutation config Adds property-based testing (fast-check v4) and mutation testing scaffolding (Stryker v8) as the antagonistic validation tier for lib/*.cjs pure logic. ## Files added ### Shared setup - tests/helpers/fast-check-setup.cjs — configureGlobal({ numRuns:200, seed:42 }) for deterministic CI; override locally with GSD_FC_SEED ### Property test suites (node:test + fast-check) - tests/context-utilization.property.test.cjs — boundary at 60%/70% thresholds (exact Math.ceil boundary, not Math.floor), TypeError on all invalid inputs, overflow clamping to 100%/critical, shape invariants (7 tests, all pass) - tests/prompt-budget.property.test.cjs — estimateTokens monotonicity + ceil(len/4) exactness; applyBudget shape invariant, instructions/roadmap verbatim, budget envelope, omit tracking (11 tests, all pass) - tests/frontmatter.property.test.cjs — extractFrontmatter/reconstructFrontmatter/ spliceFrontmatter never-throw + type shape + splice→extract round-trip (9 tests) - tests/adr-parser.property.test.cjs — shouldRejectAdrStatus boundary (3 statuses only), parseAdrMarkdown shape + title trim invariant (discovered: parser trims trailing whitespace) (9 tests, all pass) - tests/config-schema.property.test.cjs — isValidConfigKey never throws, returns boolean, accepts all VALID/RUNTIME_STATE_KEYS, rejects empty/null/unknown (8 tests) ### Stryker mutation config - stryker.config.mjs — testRunner:'command', mutate bin/lib/**/*.cjs minus 13 generated files, coverageAnalysis:'off', thresholds {high:80,low:60,break:50}, incremental:true, reporters html+clear-text+progress ### CI workflow - .github/workflows/mutation.yml — PR-gating job (pull_request + workflow_dispatch), runs stryker --incremental --since origin/next (changed files only), uploads HTML artifact; SINCE_REF via env not interpolation (injection-safe) ### Package config - package.json: +test:mutation, +test:mutation:since scripts - .gitignore: +.stryker-tmp/, +.stryker-incremental.json, +reports/mutation/ - package-lock.json: fast-check@4.8.0, @stryker-mutator/core@9.6.1 ## Verified node --test on all 5 property test files: 44 tests, 0 failures. Stryker NOT run (slow; reserved for CI). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(#454): pin upload-artifact to v7.0.1 SHA used across repo (bad SHA ea165f8d) The SHA ea165f8d65b6e75b540449d3ec4f5dde0c5a4e1 (labeled v4.6.2) does not resolve on GitHub Actions. All other workflows in this repo pin 043fb46d1a93c77aae656e7c1c64a875d1fc6a0a (v7.0.1) — align mutation.yml. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(#454): mutation workflow — replace invalid --since flag with changed-core-files --mutate scoping Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: CI Rebase Check <ci@gsd-redux> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
212
tests/adr-parser.property.test.cjs
Normal file
212
tests/adr-parser.property.test.cjs
Normal file
@@ -0,0 +1,212 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Property-based tests for adr-parser.cjs
|
||||
*
|
||||
* Module: get-shit-done/bin/lib/adr-parser.cjs
|
||||
* Exported: parseAdrMarkdown(markdown, options), shouldRejectAdrStatus(status)
|
||||
*
|
||||
* Properties tested:
|
||||
* (a) shouldRejectAdrStatus: boundary — rejects exactly the known 3 statuses
|
||||
* (b) shouldRejectAdrStatus: never throws on any input
|
||||
* (c) parseAdrMarkdown: never throws on any string (including binary/unicode)
|
||||
* (d) parseAdrMarkdown: always returns the required typed shape
|
||||
* (e) parseAdrMarkdown: title extracted from H1 heading when present
|
||||
* (f) parseAdrMarkdown: status is always a string (never null/undefined)
|
||||
*/
|
||||
|
||||
const { describe, test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fc = require('./helpers/fast-check-setup.cjs');
|
||||
|
||||
const {
|
||||
parseAdrMarkdown,
|
||||
shouldRejectAdrStatus,
|
||||
} = require('../get-shit-done/bin/lib/adr-parser.cjs');
|
||||
|
||||
// Required output keys
|
||||
const REQUIRED_KEYS = [
|
||||
'title', 'status', 'context', 'decisions', 'options_considered',
|
||||
'consequences_positive', 'consequences_negative', 'out_of_scope',
|
||||
'deferred', 'dependencies', 'updates', 'source_path', 'key_files',
|
||||
'plan_sequence', 'format', 'unmapped_headers',
|
||||
];
|
||||
|
||||
// Known reject-statuses
|
||||
const REJECT_STATUSES = ['superseded', 'rejected', 'deprecated'];
|
||||
const ACCEPT_STATUSES = ['accepted', 'proposed', 'active', 'draft', ''];
|
||||
|
||||
describe('adr-parser: shouldRejectAdrStatus properties', () => {
|
||||
// (a) Boundary: exactly the 3 known reject statuses return true
|
||||
test('property: reject statuses return true, others return false', () => {
|
||||
for (const status of REJECT_STATUSES) {
|
||||
assert.equal(shouldRejectAdrStatus(status), true, `${status} should be rejected`);
|
||||
}
|
||||
for (const status of ACCEPT_STATUSES) {
|
||||
assert.equal(shouldRejectAdrStatus(status), false, `${status} should not be rejected`);
|
||||
}
|
||||
});
|
||||
|
||||
// (b) Never throws on any input
|
||||
test('property: shouldRejectAdrStatus never throws on any input', () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.oneof(
|
||||
fc.constant(null),
|
||||
fc.constant(undefined),
|
||||
fc.constant(NaN),
|
||||
fc.constant(0),
|
||||
fc.constant(''),
|
||||
fc.string({ unit: 'binary', maxLength: 50 }),
|
||||
fc.string({ unit: 'grapheme-composite', maxLength: 50 }),
|
||||
fc.string({ maxLength: 50 }),
|
||||
fc.boolean(),
|
||||
fc.constant([]),
|
||||
fc.constant({})
|
||||
),
|
||||
(input) => {
|
||||
assert.doesNotThrow(
|
||||
() => shouldRejectAdrStatus(input),
|
||||
`shouldRejectAdrStatus threw on: ${JSON.stringify(input)}`
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
test('property: shouldRejectAdrStatus always returns boolean', () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.string({ maxLength: 100 }),
|
||||
(status) => {
|
||||
const result = shouldRejectAdrStatus(status);
|
||||
assert.ok(typeof result === 'boolean', `Expected boolean got ${typeof result} for ${JSON.stringify(status)}`);
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
// Additional boundary: case variations should not reject (function is case-sensitive)
|
||||
test('property: uppercase variants of reject statuses are NOT rejected (case-sensitive)', () => {
|
||||
for (const status of REJECT_STATUSES) {
|
||||
const upper = status.toUpperCase();
|
||||
// The parser normalizes status to lowercase internally, but shouldRejectAdrStatus
|
||||
// is meant to receive an already-normalized status. If it receives uppercase,
|
||||
// it should return false (or true — we just want it not to throw).
|
||||
assert.doesNotThrow(() => shouldRejectAdrStatus(upper));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('adr-parser: parseAdrMarkdown properties', () => {
|
||||
// (c) Never throws on any string input
|
||||
test('property: parseAdrMarkdown never throws on any string input', () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.oneof(
|
||||
fc.string({ unit: 'binary', maxLength: 500 }),
|
||||
fc.string({ unit: 'grapheme-composite', maxLength: 500 }),
|
||||
fc.string({ maxLength: 500 }),
|
||||
fc.constant(''),
|
||||
fc.constant('# My ADR\n\n## Status\nAccepted\n\n## Decision\n- Do the thing.\n'),
|
||||
fc.constant('---\n# Not a real ADR\n---'),
|
||||
fc.constant('## No title\n\n## Status\nProposed')
|
||||
),
|
||||
(markdown) => {
|
||||
assert.doesNotThrow(
|
||||
() => parseAdrMarkdown(markdown),
|
||||
`parseAdrMarkdown threw on: ${JSON.stringify(markdown.slice(0, 80))}`
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
// (d) Always returns the required typed shape
|
||||
test('property: parseAdrMarkdown always returns required typed shape', () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.string({ maxLength: 500 }),
|
||||
(markdown) => {
|
||||
const result = parseAdrMarkdown(markdown);
|
||||
|
||||
assert.ok(typeof result === 'object' && result !== null, 'result must be object');
|
||||
|
||||
for (const key of REQUIRED_KEYS) {
|
||||
assert.ok(
|
||||
Object.prototype.hasOwnProperty.call(result, key),
|
||||
`missing required key: ${key}`
|
||||
);
|
||||
}
|
||||
|
||||
assert.ok(typeof result.title === 'string', 'title must be string');
|
||||
assert.ok(typeof result.status === 'string', 'status must be string');
|
||||
assert.ok(typeof result.context === 'string', 'context must be string');
|
||||
assert.ok(Array.isArray(result.decisions), 'decisions must be array');
|
||||
assert.ok(Array.isArray(result.options_considered), 'options_considered must be array');
|
||||
assert.ok(Array.isArray(result.consequences_positive), 'consequences_positive must be array');
|
||||
assert.ok(Array.isArray(result.consequences_negative), 'consequences_negative must be array');
|
||||
assert.ok(Array.isArray(result.updates), 'updates must be array');
|
||||
assert.ok(Array.isArray(result.unmapped_headers), 'unmapped_headers must be array');
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
// (e) Title extracted from H1 heading
|
||||
// The parser applies .trim() to the heading text, so the expected title must also be trimmed.
|
||||
test('property: H1 heading at line start is extracted as trimmed title', () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.stringMatching(/^[A-Za-z0-9][A-Za-z0-9 _-]{0,49}$/),
|
||||
(titleText) => {
|
||||
const markdown = `# ${titleText}\n\n## Status\nAccepted\n`;
|
||||
const result = parseAdrMarkdown(markdown);
|
||||
const expected = titleText.trim(); // parser trims heading text
|
||||
assert.equal(
|
||||
result.title,
|
||||
expected,
|
||||
`Expected title="${expected}" got "${result.title}"`
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
// (f) Status is always a non-null string
|
||||
test('property: status is always a string (never null/undefined)', () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.string({ maxLength: 300 }),
|
||||
(markdown) => {
|
||||
const result = parseAdrMarkdown(markdown);
|
||||
assert.ok(
|
||||
typeof result.status === 'string',
|
||||
`status must be string, got ${typeof result.status}`
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
// Robustness: sourcePath option with arbitrary strings
|
||||
test('property: arbitrary sourcePath option never causes throws', () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.string({ maxLength: 200 }),
|
||||
fc.oneof(
|
||||
fc.string({ maxLength: 100 }),
|
||||
fc.string({ unit: 'binary', maxLength: 50 }),
|
||||
fc.constant(null),
|
||||
fc.constant(undefined)
|
||||
),
|
||||
(markdown, sourcePath) => {
|
||||
assert.doesNotThrow(
|
||||
() => parseAdrMarkdown(markdown, { sourcePath }),
|
||||
`parseAdrMarkdown threw with sourcePath=${JSON.stringify(sourcePath)}`
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user