Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 31 additions & 24 deletions lib/fixture-matrix/fixtures.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import {

export function discoverFixtures(root, options = {}) {
const requestedRoot = root || options.fixtureRoot || options.fixture_root;
if (isSymlink(requestedRoot)) {
throw new Error(`fixtureRoot must not be a symbolic link: ${requestedRoot}`);
const fixtureRoot = path.resolve(requestedRoot || '.');
const rootInspection = inspectFixtureDirectories(fixtureRoot, options);
if (rootInspection.exclusions[0]?.reason && ['root_missing', 'root_not_directory', 'root_symlink'].includes(rootInspection.exclusions[0].reason)) {
return [];
}
const fixtureRoot = requiredDirectory(requestedRoot, 'fixtureRoot');
const searchRoots = resolveFixtureSearchRoots(fixtureRoot);
const entrypoint = options.entrypoint || 'index.html';
const maxDepth = finiteNumber(options.maxDepth ?? options.max_depth, 2);
Expand Down Expand Up @@ -199,14 +200,6 @@ function isRealDirectory(directory) {
}
}

function isSymlink(target) {
try {
return fs.lstatSync(target).isSymbolicLink();
} catch {
return false;
}
}

function corpusLabelForSearchRoot(searchRoot, fixtureRoot) {
const normalizedSearchRoot = path.resolve(searchRoot);
const normalizedFixtureRoot = path.resolve(fixtureRoot);
Expand Down Expand Up @@ -248,7 +241,16 @@ export function createFixtureMatrix(input = {}) {
// directories and their authored metadata rather than a separately maintained
// fixture count.
export function buildFixtureCoverage(root, options = {}, selectedFixtures = [], filter = null) {
const fixtureRoot = requiredDirectory(root, 'fixtureRoot');
const fixtureRoot = path.resolve(root || '.');
const rootInspection = inspectFixtureDirectories(fixtureRoot, options);
if (rootInspection.exclusions[0]?.reason && ['root_missing', 'root_not_directory', 'root_symlink'].includes(rootInspection.exclusions[0].reason)) {
return {
schema: 'static-site-importer/fixture-matrix-coverage/v1',
active: coverageInventoryFromInspection('active', rootInspection, options),
solved: emptyCoverageInventory('solved', path.join(fixtureRoot, 'solved'), options),
gate: { status: 'passed', reasons: [] },
};
}
const searchRoots = resolveFixtureSearchRoots(fixtureRoot);
const selectedIds = new Set(selectedFixtures.map((fixture) => fixture.id));
const inventories = searchRoots.map((searchRoot) => {
Expand All @@ -274,18 +276,7 @@ export function buildFixtureCoverage(root, options = {}, selectedFixtures = [],
...eligible.filter((fixture) => !selectedIds.has(fixture.id)).map(({ id }) => ({ id, reason: filter ? 'filter_mismatch' : 'omitted' })),
...inspection.exclusions.map(({ id, reason }) => ({ id, reason })),
].sort((left, right) => left.id.localeCompare(right.id) || left.reason.localeCompare(right.reason));
return {
corpus,
root: inspection.root,
entrypoint: inspection.entrypoint,
discovered_fixture_ids: inspection.selected_ids,
eligible_fixture_ids: eligible.map((fixture) => fixture.id),
selected,
skipped,
malformed: inspection.malformed.map((fixture) => coverageRow({ corpus, root: inspection.root, fixture })),
duplicates: [...inspection.duplicates.map((fixture) => coverageRow({ corpus, root: inspection.root, fixture })), ...crossCorpusDuplicates]
.sort((left, right) => left.id.localeCompare(right.id) || left.corpus.localeCompare(right.corpus) || left.path.localeCompare(right.path)),
};
return coverageInventoryFromInspection(corpus, inspection, options, { eligible, selected, skipped, crossCorpusDuplicates });
});
const active = coverageInventories.find((inventory) => inventory.corpus === 'active') || emptyCoverageInventory('active', fixtureRoot, options);
const solved = coverageInventories.find((inventory) => inventory.corpus === 'solved') || emptyCoverageInventory('solved', path.join(fixtureRoot, 'solved'), options);
Expand All @@ -302,6 +293,22 @@ export function buildFixtureCoverage(root, options = {}, selectedFixtures = [],
};
}

function coverageInventoryFromInspection(corpus, inspection, options, overrides = {}) {
const eligible = overrides.eligible || inspection.eligible;
return {
corpus,
root: inspection.root,
entrypoint: inspection.entrypoint || options.entrypoint || 'index.html',
discovered_fixture_ids: inspection.selected_ids,
eligible_fixture_ids: eligible.map((fixture) => fixture.id),
selected: overrides.selected || [],
skipped: overrides.skipped || inspection.exclusions.map(({ id, reason }) => ({ id, reason })),
malformed: inspection.malformed.map((fixture) => coverageRow({ corpus, root: inspection.root, fixture })),
duplicates: [...inspection.duplicates.map((fixture) => coverageRow({ corpus, root: inspection.root, fixture })), ...(overrides.crossCorpusDuplicates || [])]
.sort((left, right) => left.id.localeCompare(right.id) || left.corpus.localeCompare(right.corpus) || left.path.localeCompare(right.path)),
};
}

function coverageRow({ corpus, root, fixture, reason = fixture.reason }) {
return {
id: fixture.id,
Expand Down
22 changes: 20 additions & 2 deletions tools/fixture-matrix.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3573,7 +3573,7 @@ test('fixture selection fails closed for execution and keeps empty dry-run plann
assert.equal(planned.summary.fixture_count, 0);
await assert.rejects(
runFixtureMatrix({ fixtureRoot, outputDirectory: path.join(root, 'executed'), staticSiteImporterPath: staticSiteImporter, tag: 'absent', run: true }),
/requires at least one executable fixture/,
/requires a complete eligible fixture inventory/,
);

const nonDirectoryRoot = path.join(root, 'not-a-directory');
Expand All @@ -3592,6 +3592,24 @@ test('fixture selection fails closed for execution and keeps empty dry-run plann
assert.equal(JSON.parse(dryRun.stdout).fixture_selection.status, 'planning_empty');
});

test('missing and top-level symlink roots retain planning-empty selection semantics', () => {
const root = mkdtempSync(path.join(tmpdir(), 'ssi-invalid-root-planning-'));
const staticSiteImporter = path.join(root, 'static-site-importer');
const externalRoot = path.join(root, 'external-fixtures');
const symlinkRoot = path.join(root, 'symlinked-fixtures');
mkdirSync(staticSiteImporter, { recursive: true });
mkdirSync(path.join(externalRoot, 'site'), { recursive: true });
writeFileSync(path.join(externalRoot, 'site', 'index.html'), '<h1>External</h1>');
symlinkSync(externalRoot, symlinkRoot);

for (const [fixtureRoot, reason] of [[path.join(root, 'missing-fixtures'), 'root_missing'], [symlinkRoot, 'root_symlink']]) {
const plan = buildFixtureMatrixRunPlan({ staticSiteImporter, fixtureRoot });
assert.equal(plan.execution_eligible, false);
assert.equal(plan.fixture_selection.status, 'planning_empty');
assert.equal(plan.fixture_selection.exclusions[0].reason, reason);
}
});

test('fixture selection reports one executable fixture and rejects typoed targets', () => {
const root = mkdtempSync(path.join(tmpdir(), 'ssi-one-selection-'));
const staticSiteImporter = path.join(root, 'static-site-importer');
Expand Down Expand Up @@ -3690,7 +3708,7 @@ test('top-level symlink fixture roots stay planning-empty and never stage an ext
assert.equal(existsSync(path.join(outputDirectory, 'external-site', 'artifact.json')), false);
await assert.rejects(
runFixtureMatrix({ fixtureRoot, outputDirectory, staticSiteImporterPath: staticSiteImporter, run: true }),
/requires at least one executable fixture/,
/requires a complete eligible fixture inventory/,
);
});

Expand Down
Loading