mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
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).
This commit is contained in:
1 parent
64e6caeca2
commit
c475a6fac0
6 files changed
+2212
-1
No files matched your search
@@ -876,7 +876,12 @@ holds a late handshake or in-flight work at a boundary and releases it with a
|
||||
value or a rejection, `phaseArrival` marks a boundary whose work waits on
|
||||
something else (an abort, another owner), `cancelDuringCleanup`
|
||||
cancels from inside final cleanup, and `controlledCleanup` gives children
|
||||
refused or confirmed outcomes with counted retries. Check server
|
||||
refused or confirmed outcomes with counted retries.
|
||||
`tests/support/providerLifecycleCoverage.ts` maps every registered provider id
|
||||
to its launch, handshake, operation, cancellation, cleanup and retry
|
||||
regressions, a not-applicable reason, or an explicit gap. Name the test file
|
||||
and literal title when a change adds or moves a provider lifecycle regression;
|
||||
the shrink-only gap list closes as stages gain coverage. Check server
|
||||
settlement and retained resources even if the MCP SDK rejects the client promise
|
||||
before the handler finishes. A cancellation during active execution does not
|
||||
cover cancellation during final cleanup.
|
||||
|
||||
@@ -62,6 +62,7 @@ else { if(readFileSync('capture', 'utf8') !== 'recording bytes') throw Error('wr
|
||||
const controller = new AbortController();
|
||||
let calls = 0;
|
||||
let mayClean = !failCleanup;
|
||||
let mayStopDecoder = mode !== "process-cleanup";
|
||||
const acquired = createDeferred<void>();
|
||||
const release = createDeferred<void>();
|
||||
const provider = new TsharkCaptureProvider(
|
||||
@@ -99,6 +100,15 @@ else { if(readFileSync('capture', 'utf8') !== 'recording bytes') throw Error('wr
|
||||
});
|
||||
if (mode === "wait" && !input.arguments.includes("--version"))
|
||||
spawned.process.stdout?.once("data", () => controller.abort());
|
||||
if (mode === "process-cleanup" && !input.arguments.includes("--version"))
|
||||
return {
|
||||
...spawned,
|
||||
// The decoder exits by itself; only the cleanup proof is withheld.
|
||||
cleanup: async () =>
|
||||
mayStopDecoder
|
||||
? { cleaned: true, signaled: false }
|
||||
: { cleaned: false, reason: "decoder owner remains unverified" },
|
||||
};
|
||||
return spawned;
|
||||
},
|
||||
async () => {
|
||||
@@ -140,6 +150,7 @@ else { if(readFileSync('capture', 'utf8') !== 'recording bytes') throw Error('wr
|
||||
onTestFinished(async () => {
|
||||
release.resolve();
|
||||
mayClean = true;
|
||||
mayStopDecoder = true;
|
||||
await provider.close();
|
||||
});
|
||||
const service = new PacketCaptureService(provider);
|
||||
@@ -153,6 +164,7 @@ else { if(readFileSync('capture', 'utf8') !== 'recording bytes') throw Error('wr
|
||||
release: () => release.resolve(),
|
||||
allowCleanup: () => {
|
||||
mayClean = true;
|
||||
mayStopDecoder = true;
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -547,6 +559,27 @@ it("retains a completed observation and cleanup ownership for retry", async () =
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it("releases a retained decoder process cleanup before the next inspection completes", async () => {
|
||||
const f = await fixture("process-cleanup");
|
||||
const input = { path: f.path, fields: ["ip.addr"] };
|
||||
const first = await f.service.inspect(input);
|
||||
if (first.ok) throw new Error("Expected retained process cleanup");
|
||||
expect(first.error.cleanupIncomplete).toBe(true);
|
||||
expect(first.error.cleanupResources).toContainEqual(
|
||||
expect.stringMatching(/^process-group:\d+$/),
|
||||
);
|
||||
const launches = f.calls();
|
||||
const blocked = await f.service.inspect(input);
|
||||
if (blocked.ok) throw new Error("Expected the retained owner to block");
|
||||
expect(blocked.error.cleanupIncomplete).toBe(true);
|
||||
expect(f.calls()).toBe(launches);
|
||||
f.allowCleanup();
|
||||
const retried = await f.service.inspect(input);
|
||||
expect(retried.ok).toBe(true);
|
||||
expect(first.error.cleanupIncomplete).toBe(false);
|
||||
expect(f.calls()).toBeGreaterThan(launches);
|
||||
});
|
||||
|
||||
it("rejects cancelled and invalid requests before any provider work", async () => {
|
||||
const f = await fixture();
|
||||
for (const input of [
|
||||
|
||||
@@ -107,6 +107,7 @@ const fixture = async (
|
||||
const controller = new AbortController();
|
||||
let calls = 0;
|
||||
let mayClean = !failCleanup;
|
||||
let mayStopDecoder = mode !== "process-cleanup";
|
||||
const acquired = createDeferred<void>();
|
||||
const release = createDeferred<void>();
|
||||
const provider = new SigrokRecordingProvider(
|
||||
@@ -145,6 +146,15 @@ const fixture = async (
|
||||
});
|
||||
if (mode === "wait" && !input.arguments.includes("--version"))
|
||||
spawned.process.stdout?.once("data", () => controller.abort());
|
||||
if (mode === "process-cleanup" && !input.arguments.includes("--version"))
|
||||
return {
|
||||
...spawned,
|
||||
// The decoder exits by itself; only the cleanup proof is withheld.
|
||||
cleanup: async () =>
|
||||
mayStopDecoder
|
||||
? { cleaned: true, signaled: false }
|
||||
: { cleaned: false, reason: "decoder owner remains unverified" },
|
||||
};
|
||||
return spawned;
|
||||
},
|
||||
async () => {
|
||||
@@ -184,6 +194,7 @@ const fixture = async (
|
||||
onTestFinished(async () => {
|
||||
release.resolve();
|
||||
mayClean = true;
|
||||
mayStopDecoder = true;
|
||||
await provider.close();
|
||||
});
|
||||
const service = new SignalRecordingService(provider);
|
||||
@@ -197,6 +208,7 @@ const fixture = async (
|
||||
release: () => release.resolve(),
|
||||
allowCleanup: () => {
|
||||
mayClean = true;
|
||||
mayStopDecoder = true;
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -1033,6 +1045,27 @@ it("retains a completed observation and cleanup ownership for retry", async () =
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it("releases a retained decoder process cleanup before the next decode completes", async () => {
|
||||
const f = await fixture("process-cleanup");
|
||||
const input = { path: f.path, decoders: "uart" };
|
||||
const first = await f.service.decode(input);
|
||||
if (first.ok) throw new Error("Expected retained process cleanup");
|
||||
expect(first.error.cleanupIncomplete).toBe(true);
|
||||
expect(first.error.cleanupResources).toContainEqual(
|
||||
expect.stringMatching(/^process-group:\d+$/),
|
||||
);
|
||||
const launches = f.calls();
|
||||
const blocked = await f.service.decode(input);
|
||||
if (blocked.ok) throw new Error("Expected the retained owner to block");
|
||||
expect(blocked.error.cleanupIncomplete).toBe(true);
|
||||
expect(f.calls()).toBe(launches);
|
||||
f.allowCleanup();
|
||||
const retried = await f.service.decode(input);
|
||||
expect(retried.ok).toBe(true);
|
||||
expect(first.error.cleanupIncomplete).toBe(false);
|
||||
expect(f.calls()).toBeGreaterThan(launches);
|
||||
});
|
||||
|
||||
it("rejects cancelled and invalid requests before any provider work", async () => {
|
||||
const f = await fixture();
|
||||
for (const input of [
|
||||
|
||||
@@ -838,6 +838,69 @@ it("releases a retained provider owner after cleanup succeeds", async () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("retains an objdump command's unverified process owner until a later inspection stops it", async () => {
|
||||
const { directory, path } = await createArtifact();
|
||||
let stopped = false;
|
||||
const cleanupOwner = {
|
||||
stop: vi.fn(async () =>
|
||||
stopped
|
||||
? { status: "verified-cleanup" as const }
|
||||
: { status: "incomplete" as const, reason: "objdump group remains" },
|
||||
),
|
||||
} as unknown as ProviderProcessSupervisor;
|
||||
const runOwned = vi
|
||||
.fn<typeof runOwnedCommand>()
|
||||
.mockRejectedValueOnce(
|
||||
new OwnedCommandFailure(
|
||||
"process",
|
||||
"objdump cleanup could not be verified",
|
||||
providerSnapshot({ exitCode: null }),
|
||||
"objdump group remains",
|
||||
undefined,
|
||||
["run-id", "pid:42"],
|
||||
cleanupOwner,
|
||||
),
|
||||
)
|
||||
.mockResolvedValue(providerSnapshot());
|
||||
const service = new ReverseEngineeringService({ runOwned });
|
||||
|
||||
try {
|
||||
const first = await service.inspectWithObjdump({
|
||||
path,
|
||||
operation: "symbols",
|
||||
});
|
||||
if (first.ok) throw new Error("Expected retained objdump cleanup");
|
||||
expect(first.error.cleanupIncomplete).toBe(true);
|
||||
expect(first.error.cleanup).toMatchObject({
|
||||
reason: "objdump group remains",
|
||||
resources: ["run-id", "pid:42"],
|
||||
});
|
||||
|
||||
const blocked = await service.inspectWithObjdump({
|
||||
path,
|
||||
operation: "symbols",
|
||||
});
|
||||
expect(blocked).toMatchObject({
|
||||
ok: false,
|
||||
error: { cleanupIncomplete: true },
|
||||
});
|
||||
expect(runOwned).toHaveBeenCalledOnce();
|
||||
|
||||
stopped = true;
|
||||
const recovered = await service.inspectWithObjdump({
|
||||
path,
|
||||
operation: "symbols",
|
||||
});
|
||||
if (!recovered.ok) throw recovered.error;
|
||||
expect(first.error.cleanupIncomplete).toBe(false);
|
||||
expect(cleanupOwner.stop).toHaveBeenCalledTimes(2);
|
||||
expect(runOwned).toHaveBeenCalledTimes(2);
|
||||
} finally {
|
||||
await service.close().catch(() => undefined);
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("retains a capability failure when its injected owned runner also reports incomplete cleanup", async () => {
|
||||
const { directory, path } = await createArtifact();
|
||||
const capability = new AnalysisCapabilityUnavailableError(
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
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());
|
||||
});
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user