'],
cwd: tmp3,
});
assert.equal(session.fallback, undefined, session.reason);
// The exact field failure: the agent kept the seeded block and
// appended its own second top-level
`);
const broken = compileCheckVariants('gate0001', tmp3);
assert.equal(broken.ok, false);
assert.equal(broken.checked, 1);
assert.match(broken.failures[0].message, /single top-level/);
assert.match(broken.failures[0].file, /gate0001\/v1\.svelte/);
assert.equal(typeof broken.failures[0].line, 'number');
// Merged into one block: the gate opens.
write(tmp3, join(session.componentDir, 'v1.svelte'), `
`;
it('keeps a superseded selector whose class is still used outside the replaced region', () => {
const tmp4 = realpathSync(mkdtempSync(join(tmpdir(), 'impeccable-shared-class-')));
try {
mkdirSync(join(tmp4, 'node_modules'), { recursive: true });
try {
symlinkSync(join(REPO_NODE_MODULES, 'svelte'), join(tmp4, 'node_modules', 'svelte'), 'dir');
} catch {
cpSync(join(REPO_NODE_MODULES, 'svelte'), join(tmp4, 'node_modules', 'svelte'), { recursive: true });
}
write(tmp4, 'package.json', JSON.stringify({ name: 'app' }));
write(tmp4, 'src/lib/Shared.svelte', SHARED_SOURCE);
// Pick the
block. Its items use .card, and so does
// the intro div OUTSIDE the pick.
const lines = SHARED_SOURCE.split('\n');
const startLine = lines.findIndex((l) => l.includes('class="list"')) + 1;
const endLine = lines.findIndex((l) => l.trim() === '
') + 1;
const originalLines = lines.slice(startLine - 1, endLine);
const session = scaffoldSvelteComponentSession({
id: 'shared01',
count: 1,
sourceFile: 'src/lib/Shared.svelte',
sourceStartLine: startLine,
sourceEndLine: endLine,
originalLines,
cwd: tmp4,
});
assert.equal(session.fallback, undefined, session.reason);
assert.equal(session.manifest.seededSelectors.includes('.card'), true, 'the pick uses .card, so it seeds');
// The variant re-declares .list but NOT .card.
write(tmp4, join(session.componentDir, 'v1.svelte'), `
{#each items as item}
{item.name}
{/each}
`);
const manifest = findSvelteComponentManifest('shared01', tmp4);
const result = inlineSvelteComponentAccept(manifest, 1, null, tmp4);
assert.equal(result.handled, true, result.error);
const out = readFileSync(join(tmp4, 'src/lib/Shared.svelte'), 'utf-8');
// .card is shared with the intro div outside the replaced region:
// removing it would strip styling from markup this accept never
// touched, so it must survive despite not being re-declared.
assert.match(out, /\.card \{ border: 1px solid #999; border-radius: 8px; \}/);
assert.equal(result.css.superseded.includes('.card'), false);
// The re-declared .list took the variant's shape.
assert.match(out, /\.list \{ display: flex/);
} finally {
rmSync(tmp4, { recursive: true, force: true });
}
});
});