Files
msd-core/tests/golden-parity-single-source.test.cjs
sim 7dd9e59f6b test(#3090): stop exempting violations under categories that do not fit
An allow-test-rule annotation citing a category that does not apply is worse
than no annotation, because it reads as reviewed. Eight were confirmed by
reading the assertions each one covered, and auditing the rest found five more
plus one refutation — a converter test whose wording described the wrong
mechanism while the covered assertion genuinely was deployed-text.

The instructive one used the CANONICAL string for the same mistake: STATE.md
command output labelled as a deployed artifact. A canonical string is not
evidence the category fits, which is why normalising strings alone would have
laundered the problem rather than fixed it. Every mapping the audit had inferred
rather than code-verified was spot-checked before rewriting, and the ones that
turned out not to fit were re-annotated rather than relabelled.

Fourteen STATE.md assertions had a typed extractor available all along and now
use it; their annotations came out because nothing needs exempting. Eight
assertions genuinely need a production change first — CLI stdout and stderr with
no structured mode — and are tagged pending-migration-to-typed-ir citing #3090,
which is what that category is for. It had zero real uses before this, while one
file carried a real citation to migration issue #2974 under a non-canonical tag.

Six annotations covered assertions that do no text matching at all. An exemption
for a violation that does not exist is noise that makes the real ones harder to
audit; those are removed.

atomic-write-coverage gains the annotation it always warranted — its own
docstring describes a structural-regression-guard while the file carried none.

Fifty-nine non-canonical strings across roughly thirty files are normalised, and
the allow-test-rule allowlist is regenerated to match. 472 annotations became
463: every one now uses a canonical category, and the two remaining
non-canonical strings are ESLint RuleTester fixtures, not annotations.

Refs #3057

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-05 17:20:56 -04:00

106 lines
4.9 KiB
JavaScript

'use strict';
/**
* golden-parity-single-source.test.cjs — anti-divergence guard (#2266, carried
* forward by #2724 / ADR-2719 Phase 4).
*
* tests/golden-install-parity.test.cjs and scripts/gen-golden-install-parity-zcode.cjs
* used to each carry their OWN inline copy of buildParityManifest plus its 4
* exclusion constants (VOLATILE_FILES, HOOK_CONFIG_FILES,
* HOOK_CONFIG_RELATIVE_PATHS, EXCLUDED_PREFIXES). The two copies drifted —
* the generator's copy was missing the realpath/`<HOME>` normalization the
* test harness's copy had — and shipped broken fixtures three times (#2086,
* #2095, #2100). Phase 1 of the golden-install-parity redesign (#2266)
* consolidated both call sites onto a single canonical implementation in
* tests/helpers/install-shared.cjs. ADR-2264 Phase 1 (that consolidation) is
* explicitly RETAINED by ADR-2719 — #2724 deletes the two ORIGINAL consumers
* (golden-install-parity.test.cjs, gen-golden-install-parity-zcode.cjs), but
* their two REPLACEMENTS (tests/helpers/emitted-runtime.cjs's currentManifests
* and tests/helpers/emitted-provenance.cjs's loadManifests) import
* buildParityManifest the exact same way, so the divergence risk this guard
* exists for is unchanged — only the consumer names moved.
*
* This guard (mirrors the ADR-2121 anti-divergence pattern) enforces that
* consolidation stays consolidated:
* 1. install-shared.cjs actually exports a working buildParityManifest +
* the 4 exclusion constants with the expected shapes.
* 2. No downstream consumer re-declares its own inline copy of the builder
* function or the exclusion constants.
*/
const { test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const ROOT = path.join(__dirname, '..');
test('install-shared.cjs exports the canonical buildParityManifest + exclusion constants (#2266)', () => {
const installShared = require('./helpers/install-shared.cjs');
assert.equal(
typeof installShared.buildParityManifest,
'function',
'install-shared.cjs must export buildParityManifest as the single source of truth'
);
assert.ok(
installShared.VOLATILE_FILES instanceof Set,
'VOLATILE_FILES must be a Set'
);
assert.ok(
installShared.HOOK_CONFIG_FILES instanceof Set,
'HOOK_CONFIG_FILES must be a Set'
);
assert.ok(
installShared.HOOK_CONFIG_RELATIVE_PATHS instanceof Set,
'HOOK_CONFIG_RELATIVE_PATHS must be a Set'
);
assert.ok(
Array.isArray(installShared.EXCLUDED_PREFIXES),
'EXCLUDED_PREFIXES must be an array'
);
assert.ok(
installShared.EXCLUDED_PREFIXES.includes('gsd-core/bin/lib/'),
"EXCLUDED_PREFIXES must include 'gsd-core/bin/lib/' (compiled runtime artifacts, build-environment-dependent)"
);
});
// The anti-divergence check below reads the two downstream .cjs source files
// as plain text to prove they no longer re-declare the builder/constants
// inline — the runtime-contract-under-test IS the source text (whether a
// second inline copy exists), not behavior a require() could exercise.
//
// ALL FIVE identifiers are guarded, not just buildParityManifest + VOLATILE_FILES:
// the drift that shipped broken fixtures was a MISSING exclusion-constant entry
// (#2100 = generator's HOOK_CONFIG_FILES copy lacked settings.local.json; #2095 =
// kimi's HOOK_CONFIG_RELATIVE_PATHS entry), so a re-declared HOOK_CONFIG_FILES /
// HOOK_CONFIG_RELATIVE_PATHS / EXCLUDED_PREFIXES is exactly the failure class this
// guard exists to prevent — checking only two of four would leave that gap open.
const FORBIDDEN_INLINE = [
{ label: 'buildParityManifest', re: /function\s+buildParityManifest/ },
{ label: 'VOLATILE_FILES', re: /const\s+VOLATILE_FILES\s*=\s*new\s+Set/ },
{ label: 'HOOK_CONFIG_FILES', re: /const\s+HOOK_CONFIG_FILES\s*=\s*new\s+Set/ },
{ label: 'HOOK_CONFIG_RELATIVE_PATHS', re: /const\s+HOOK_CONFIG_RELATIVE_PATHS\s*=\s*new\s+Set/ },
{ label: 'EXCLUDED_PREFIXES', re: /const\s+EXCLUDED_PREFIXES\s*=\s*\[/ },
];
const CONSUMERS = [
{ name: 'tests/helpers/emitted-runtime.cjs', rel: ['tests', 'helpers', 'emitted-runtime.cjs'], from: './install-shared.cjs' },
{ name: 'tests/helpers/emitted-provenance.cjs', rel: ['tests', 'helpers', 'emitted-provenance.cjs'], from: './install-shared.cjs' },
];
for (const consumer of CONSUMERS) {
test(`${consumer.name} does not re-declare an inline buildParityManifest or any exclusion constant (#2266)`, () => {
// allow-test-rule: source-text-is-the-product (see #2266)
// Source text is the product for this anti-divergence check.
const content = fs.readFileSync(path.join(ROOT, ...consumer.rel), 'utf8');
for (const { label, re } of FORBIDDEN_INLINE) {
assert.ok(
!re.test(content),
`${consumer.name} must import ${label} from ${consumer.from}, not re-declare it inline`
);
}
});
}