'use strict';
/**
* runtime-brand-swap-parity.test.cjs — DEFECT.GENERATIVE-FIX family parity
* guard for the #2284(b) protected-region fix.
*
* `applyClaudeCodeBrandSwap` (src/runtime-artifact-conversion.cts) rewrites
* bare "Claude Code" self-references to a runtime's brand name EXCEPT inside
* `...` blocks, which must
* survive byte-for-byte verbatim (a runtime-comparison table that says
* "Claude Code" is describing Claude Code's own behavior, not this
* runtime's — brand-swapping it mislabels the comparison). Every
* markdown/agent converter that performs a "Claude Code" -> brand swap needs
* the SAME fix (#2284b follow-up).
*
* A per-converter regression test would only catch a REintroduction in the
* converter it targets — the exact shape of divergence CONTEXT.md's
* DEFECT.GENERATIVE-FIX names. This file instead drives every brand-swapping
* converter through ONE assertion body from a declarative table, so a NEW
* runtime converter that skips `applyClaudeCodeBrandSwap` and reintroduces a
* naive `.replace(/\bClaude Code\b/g, brand)` fails the moment it is added
* to the table below — and the floor test catches an entry silently dropped
* from the table itself.
*/
process.env.MSD_TEST_MODE = '1';
const { describe, test } = require('node:test');
const assert = require('node:assert/strict');
const conv = require('../msd-core/bin/lib/runtime-artifact-conversion.cjs');
/**
* Every runtime converter in src/runtime-artifact-conversion.cts that
* performs a "Claude Code" -> brand swap, normalized to a uniform
* `(content) => string` shape regardless of the underlying function's real
* signature.
*/
const BRAND_SWAP_CONVERTERS = [
{ name: 'cursor', brand: 'Cursor', convert: (content) => conv.convertClaudeToCursorMarkdown(content) },
];
// Floor, not an exact count (mirrors MINIMUM_MANIFEST_FAMILIES in
// tests/helpers/install-shared.cjs): the point of this table is that a NEW
// brand-swapping converter must be added here explicitly and reviewably.
// Lowering it is a deliberate act; this only guards it from silently
// shrinking underneath a refactor.
const MINIMUM_BRAND_SWAP_CONVERTER_COUNT = 1;
const PROTECTED_BLOCK =
'\n| Runtime | Claude Code | Other |\n|---|---|---|\n| x | Claude Code native | y |\n';
function buildFixture() {
return `Before: mentions Claude Code here.\n\n${PROTECTED_BLOCK}\n\nAfter: also mentions Claude Code here.\n`;
}
describe('everyRuntimeMarkdownConverterPreservesRuntimeCompatibilityBlocks', () => {
test('the brand-swap converter table has not silently shrunk below its floor', () => {
assert.ok(
BRAND_SWAP_CONVERTERS.length >= MINIMUM_BRAND_SWAP_CONVERTER_COUNT,
`expected at least ${MINIMUM_BRAND_SWAP_CONVERTER_COUNT} brand-swapping converters in the table, `
+ `got ${BRAND_SWAP_CONVERTERS.length}`,
);
});
for (const { name, brand, convert } of BRAND_SWAP_CONVERTERS) {
test(`${name}: block is preserved verbatim while outside text is brand-swapped`, () => {
// Guard the table entry itself before trusting the assertions below —
// an undefined brand (a descriptor lookup that silently returned
// nothing) would make every `includes()` check below vacuously
// meaningless.
assert.strictEqual(typeof brand, 'string', `${name}: table entry must declare a string brand`);
assert.ok(brand.length > 0, `${name}: table entry brand must be non-empty`);
const result = convert(buildFixture());
assert.ok(
result.includes(PROTECTED_BLOCK),
`${name}: block must survive byte-for-byte verbatim`,
);
assert.ok(
result.includes(`Before: mentions ${brand} here.`),
`${name}: text BEFORE the protected block must be brand-swapped to "${brand}"`,
);
assert.ok(
result.includes(`After: also mentions ${brand} here.`),
`${name}: text AFTER the protected block must be brand-swapped to "${brand}"`,
);
// The protected block's OWN "Claude Code" occurrences must not have
// been swapped anywhere in the output — a stronger form of the
// verbatim-block assertion above, independent of exact block framing.
const claudeCodeOccurrencesInResult = (result.match(/Claude Code/g) || []).length;
assert.strictEqual(
claudeCodeOccurrencesInResult, 2,
`${name}: expected exactly the 2 "Claude Code" occurrences inside the protected block to survive `
+ `(got ${claudeCodeOccurrencesInResult} — outside occurrences must be brand-swapped away)`,
);
});
}
});