Files
reverse-engineering-anything/tests/evaluation/providerLifecycleCoverage.test.ts
T
morluto c475a6fac0 test(lifecycle): map every registered provider to its lifecycle regressions or explicit gaps (#11464)
* test(lifecycle): map every registered provider to its lifecycle regressions or explicit gaps

* test(lifecycle): track the web module and source-map processes and resolve test files against the repository URL

* test(lifecycle): record gaps where named tests did not exercise the claimed stage

* test(lifecycle): cover objdump cleanup and command-provider cleanup retry (#11487)

Close five provider lifecycle gaps: objdump cleanup and retry, sigrok and tshark process cleanup retry, and WABT retry (an existing literal-titled regression).
2026-11-16 05:18:36 +08:00

75 lines
2.4 KiB
TypeScript

import { readFile } from "node:fs/promises";
import { expect, it } from "vitest";
import { CAPABILITY_DECLARATIONS } from "../../src/composition/capabilityDeclarations.js";
import {
LIFECYCLE_STAGES,
PROVIDER_LIFECYCLE_COVERAGE,
PROVIDER_LIFECYCLE_GAPS,
} from "../support/providerLifecycleCoverage.js";
const repositoryRoot = new URL("../../", import.meta.url);
const registeredProviderIds = () =>
[
...new Set(
Object.values(CAPABILITY_DECLARATIONS).flatMap((declaration) =>
declaration.providers.map((provider) => provider.identity.id),
),
),
].sort();
const tableGaps = () =>
Object.entries(PROVIDER_LIFECYCLE_COVERAGE).flatMap(([id, entry]) =>
LIFECYCLE_STAGES.filter((stage) => entry.stages[stage].kind === "gap").map(
(stage) => `${id}:${stage}`,
),
);
it("has exactly one entry per registered provider id", () => {
expect(Object.keys(PROVIDER_LIFECYCLE_COVERAGE).sort()).toEqual(
registeredProviderIds(),
);
});
it("names an existing test file and literal test title for every covered stage", async () => {
const missing: string[] = [];
const sources = new Map<string, Promise<string | undefined>>();
const source = (path: string) => {
let pending = sources.get(path);
if (pending === undefined) {
pending = readFile(new URL(path, repositoryRoot), "utf8").catch(
(cause: unknown) => {
if ((cause as NodeJS.ErrnoException).code === "ENOENT")
return undefined;
throw cause;
},
);
sources.set(path, pending);
}
return pending;
};
for (const [id, entry] of Object.entries(PROVIDER_LIFECYCLE_COVERAGE)) {
for (const stage of LIFECYCLE_STAGES) {
const coverage = entry.stages[stage];
if (coverage.kind !== "covered") continue;
for (const { path, title } of coverage.tests) {
const text = await source(path);
if (!path.endsWith(".test.ts") || text === undefined) {
missing.push(`${id}:${stage} missing file ${path}`);
continue;
}
const literal = ['"', "'", "`"].some((quote) =>
text.includes(`${quote}${title}${quote}`),
);
if (!literal)
missing.push(`${id}:${stage} missing title in ${path}: ${title}`);
}
}
}
expect(missing).toEqual([]);
});
it("lists exactly the gap stages in the shrink-only gap list", () => {
expect([...PROVIDER_LIFECYCLE_GAPS].sort()).toEqual(tableGaps().sort());
});