Files
msd-core/tests/write-set.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

98 lines
3.5 KiB
JavaScript

'use strict';
/**
* Behavioral tests for write-set.cjs
*
* Module: msd-core/bin/lib/write-set.cjs
* Exports: writeSetComplete (Result<T> is a pure type re-exported at compile
* time only — nothing to assert on it at runtime beyond markdown-table.cjs's
* own re-export continuing to work, covered by tests/markdown-table.test.cjs).
*
* Covers (ADR-2143 §5/§6):
* - writeSetComplete happy path: all-applied → true, one-not-applied → false
* - BOUNDARY coverage: empty write-set (0 outcomes), single outcome, two outcomes
* - an empty write-set is never "complete" (no vacuous-true on a no-op)
* - fast-check property: writeSetComplete(ws) === (ws.length > 0 && every applied)
*/
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const fc = require('./helpers/fast-check-setup.cjs');
const { writeSetComplete } = require('../msd-core/bin/lib/write-set.cjs');
describe('writeSetComplete', () => {
test('every surface applied → true', () => {
assert.equal(
writeSetComplete([
{ surface: 'checkbox', applied: true },
{ surface: 'traceability', applied: true },
]),
true,
);
});
test('one surface not applied → false (AND across surfaces, never OR)', () => {
assert.equal(
writeSetComplete([
{ surface: 'checkbox', applied: true },
{ surface: 'traceability', applied: false },
]),
false,
);
});
test('no surfaces applied → false', () => {
assert.equal(
writeSetComplete([
{ surface: 'checkbox', applied: false },
{ surface: 'traceability', applied: false },
]),
false,
);
});
// BOUNDARY: 0 outcomes (limit-1 relative to the smallest real set), 1 outcome
// (limit), 2 outcomes (limit+1) — the write-set shape has no upper bound, but
// the meaningful boundary here is "is there anything to be complete about".
test('BOUNDARY: empty write-set (0 outcomes) is never complete', () => {
assert.equal(writeSetComplete([]), false,
'an empty write-set must not vacuously report complete — that would let a ' +
'no-op masquerade as full success, the exact OR-into-one-flag class ADR-2143 §6 prohibits');
});
test('BOUNDARY: single-outcome write-set (1 outcome) — applied true is complete', () => {
assert.equal(writeSetComplete([{ surface: 'checkbox', applied: true }]), true);
});
test('BOUNDARY: single-outcome write-set (1 outcome) — applied false is not complete', () => {
assert.equal(writeSetComplete([{ surface: 'checkbox', applied: false }]), false);
});
test('BOUNDARY: two-outcome write-set (2 outcomes) — both true is complete', () => {
assert.equal(
writeSetComplete([
{ surface: 'checkbox', applied: true },
{ surface: 'traceability', applied: true },
]),
true,
);
});
// ─── Property test ───────────────────────────────────────────────────────────
const outcomeArb = fc.record({
surface: fc.string({ minLength: 1, maxLength: 12 }),
applied: fc.boolean(),
});
test('property: writeSetComplete(ws) === (ws.length > 0 && every outcome applied)', () => {
fc.assert(
fc.property(fc.array(outcomeArb, { maxLength: 8 }), (ws) => {
const expected = ws.length > 0 && ws.every((o) => o.applied);
assert.equal(writeSetComplete(ws), expected);
}),
);
});
});