test: consolidate failure guards and trim unused fixture APIs

This commit is contained in:
morluto 2026-10-09 03:13:43 +08:00
parent 81ae838567
commit ffd9611308
38 changed files with 90 additions and 203 deletions

View File

@ -154,8 +154,7 @@ describe("residual unknown dependency histories", () => {
input("Does detached state remain intact?"),
mutation("detached-unknown"),
);
expect(created.ok).toBe(true);
if (!created.ok) return;
if (!created.ok) throw created.error;
Reflect.set(created.value, "status", "resolved");
const listed = store.listUnknowns();
@ -185,8 +184,7 @@ describe("residual unknown dependency histories", () => {
input(" Is branch live? "),
mutation("one"),
);
expect(first.ok).toBe(true);
if (!first.ok) return;
if (!first.ok) throw first.error;
expect(first.value.unknown_id).toMatch(/^unk_[a-f0-9]{64}$/u);
expect(first.value.revision).toBe(1);
expect(store.listUnknowns({ severity: "high" })).toHaveLength(1);

View File

@ -76,7 +76,6 @@ it("keeps dynamic calls explicit and returns complete deterministic results", ()
const seedNodeId = graph.relations.find(
({ relation }) => relation === "defines",
)?.source_node_id;
expect(seedNodeId).toBeDefined();
if (seedNodeId === undefined) throw new Error("Expected a definition seed");
const first = queryJavaScriptSemanticGraph(graph, {

View File

@ -151,8 +151,7 @@ describe("managed decompiler reconstruction import", () => {
it("wraps imported reconstruction in Evidence", () => {
const evidence = importManagedReconstructionEvidence(exampleInput());
expect(evidence.ok).toBe(true);
if (!evidence.ok) return;
if (!evidence.ok) throw evidence.error;
expect(evidence.value).toMatchObject({
operation: "import_managed_reconstruction",
provider: { id: "rea-dotnet-workflows" },

View File

@ -220,8 +220,7 @@ describe("native UI action trace", () => {
const result = await tools.execute("trace_native_ui_action", {
action: "buildTapped:",
});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
const trace = nativeInvestigationTraceSchema.parse(result.value);
expect(trace.start).toBe("action");
expect(trace.nodes.map(({ id }) => id)).toContain("native:function:0x1000");
@ -297,8 +296,7 @@ describe("bounded native UI tracing", () => {
{ action: "buildTapped:", max_depth: 3 },
);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(
nativeInvestigationTraceSchema
.parse(result.value)
@ -337,8 +335,7 @@ describe("native UI query outcomes", () => {
const result = await tools.execute("trace_native_ui_action", {
action: "button",
});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value).toMatchObject({ start: "action" });
});
@ -385,8 +382,7 @@ describe("native UI query outcomes", () => {
const result = await tools.execute("trace_native_ui_action", {
action: "buildTapped:",
});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value).toMatchObject({
reason: "action_selector_matches_multiple_ui_connections",
nodes: [{ id: "action" }, { id: "second-action" }],

View File

@ -212,8 +212,7 @@ describe("PlaywrightBrowserScenarioProvider", () => {
open: () => Promise.resolve(session),
});
const result = await provider.captureScenario(scenario({ actions: 129 }));
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.scenario.action_count).toBe(129);
expect(result.value.steps).toHaveLength(130);
expect(result.value.steps.at(-1)?.step_id).toBe("wait_128");
@ -227,8 +226,7 @@ describe("PlaywrightBrowserScenarioProvider", () => {
const result = await provider.captureScenario(
scenario({ captures: ["screenshot", "dom"] }),
);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.completeness).toMatchObject({
status: "truncated",
equality_eligible: false,
@ -243,8 +241,7 @@ describe("PlaywrightBrowserScenarioProvider", () => {
open: () => Promise.resolve(session),
});
const result = await provider.captureScenario(scenario({ actions: 2 }));
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.steps.map(({ status }) => status)).toEqual([
"completed",
"failed",
@ -266,8 +263,7 @@ describe("PlaywrightBrowserScenarioProvider", () => {
const result = await provider.captureScenario(
scenario({ mode: "connect" }),
);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.browser).toMatchObject({
process_ownership: "external",
cleanup: "disconnected-external",
@ -317,8 +313,7 @@ describe("PlaywrightBrowserScenarioProvider", () => {
const result = await provider.captureScenario(scenario(), {
signal: controller.signal,
});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.steps[1]?.status).toBe("cancelled");
expect(session.closeCalls).toBe(1);
});

View File

@ -69,7 +69,6 @@ it("coarsens format issue pointers without creating replacement coordinates", ()
],
);
const result = redactExplicitFailure(error, ["private/~", "private"]);
expect(result).toBeInstanceOf(AnalysisInputError);
if (!(result instanceof AnalysisInputError))
throw new Error("Input error required");
expect(result.issues[0]?.path).toEqual(["capture_path", "/metadata"]);

View File

@ -320,7 +320,6 @@ it("retains observations and both causes when process cleanup is unverifiable",
if (!(cause instanceof ProcessCaptureError)) throw cause;
error = cause;
}
expect(error).toBeDefined();
if (error === undefined) throw new Error("expected cleanup-incomplete error");
const projection = projectAnalysisError(error);
@ -391,7 +390,6 @@ it("projects execution and cleanup failures when capture never completed", () =>
if (!(cause instanceof ProcessCaptureError)) throw cause;
error = cause;
}
expect(error).toBeDefined();
if (error === undefined) throw new Error("expected cleanup-incomplete error");
expect(error.partialObservation).toBeUndefined();
@ -425,7 +423,6 @@ it("retains completed observations when finalization fails after clean cleanup",
if (!(cause instanceof ProcessCaptureError)) throw cause;
error = cause;
}
expect(error).toBeDefined();
if (error === undefined) throw new Error("expected capture failure");
expect(error).toMatchObject({
@ -477,7 +474,6 @@ it("preserves cancellation while projecting observations and successful cleanup"
if (!(cause instanceof ProcessCaptureError)) throw cause;
error = cause;
}
expect(error).toBeDefined();
if (error === undefined) throw new Error("expected cancellation");
expect(projectAnalysisError(error)).toMatchObject({

View File

@ -58,7 +58,6 @@ describe("additional client configuration dialects", () => {
const client = getClients(home).find(
(candidate) => candidate.name === name,
);
expect(client).toBeDefined();
if (client === undefined) throw new Error(`missing ${name} client`);
await mkdir(client.markerPath ?? home, { recursive: true });
@ -126,7 +125,6 @@ describe("additional client configuration dialects", () => {
it("preserves OpenCode JSONC comments and sibling registrations during update and removal", async () => {
const home = await createTestTempDirectory("rea-opencode-jsonc-");
const client = getClients(home).find(({ name }) => name === "opencode");
expect(client).toBeDefined();
if (client === undefined) throw new Error("missing OpenCode client");
await mkdir(client.markerPath ?? home, { recursive: true });
const original = `{
@ -177,7 +175,6 @@ describe("additional client configuration dialects", () => {
it("rejects malformed OpenCode JSONC without creating a backup or changing bytes", async () => {
const home = await createTestTempDirectory("rea-opencode-invalid-");
const client = getClients(home).find(({ name }) => name === "opencode");
expect(client).toBeDefined();
if (client === undefined) throw new Error("missing OpenCode client");
await mkdir(client.markerPath ?? home, { recursive: true });
const invalid = '{ "mcp": { /* broken */ "rea": [ }';

View File

@ -506,8 +506,7 @@ describe("JavaScript runtime reconciliation local paths", () => {
],
});
expect(reconciled.ok).toBe(true);
if (!reconciled.ok) return;
if (!reconciled.ok) throw reconciled.error;
const result = javascriptRuntimeReconciliationResultSchema.parse(
reconciled.value.normalized_result,
);

View File

@ -56,8 +56,7 @@ it("distinguishes computed require member values from literal members in source
caller: "reference-require-members-test",
policy: { secretPatterns: [] },
});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
const graph = result.value;
expect(graph.parse_failures).toEqual([]);
expect(graph.relationships).toEqual([

View File

@ -29,8 +29,7 @@ it("imports Dockerfile-prefixed TypeScript with ordinary source evidence and unc
caller: "dockerfile-language-test",
policy: { secretPatterns: [] },
});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
const graph = result.value;
expect(graph.parse_failures).toEqual([]);
expect(graph.relationships).toHaveLength(sourcePaths.length * 3);
@ -88,8 +87,7 @@ it("retains parser failures and hashes for malformed Dockerfile-prefixed TypeScr
caller: "dockerfile-language-test",
policy: { secretPatterns: [] },
});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.relationships).toEqual([]);
expect(result.value.parse_failures).toEqual(
paths.map((path) => ({

View File

@ -30,8 +30,7 @@ it("resolves dynamic source imports while retaining computed targets as unknown"
caller: "reference-dynamic-import-test",
policy: { secretPatterns: [] },
});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.parse_failures).toEqual([]);
expect(result.value.relationships).toHaveLength(5);
for (const [to, kind] of [

View File

@ -123,8 +123,7 @@ describe("reference source symlink import", () => {
const imported = await importTree(root);
expect(imported.ok).toBe(true);
if (!imported.ok) return;
if (!imported.ok) throw imported.error;
expect(imported.value.entries).toContainEqual(
expect.objectContaining({
kind: "symlink",
@ -154,8 +153,7 @@ describe("reference source manifest inventory", () => {
]);
const result = await importTree(root);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.manifests).toEqual([
"CMakeLists.txt",
"src/CMakeLists.txt",
@ -210,8 +208,7 @@ describe("reference source import behavior", () => {
policy: { secretPatterns: [] },
});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
// The importer always reports one standing advisory about pathname races,
// so completeness is asserted per entry rather than globally.
const limited = result.value.entries.filter(
@ -262,8 +259,7 @@ describe("reference source import behavior", () => {
),
);
const result = await importTree(root);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.entries.map(({ path }) => path)).toEqual(paths);
const repeated = await importTree(root);
expect(repeated).toEqual(result);
@ -351,8 +347,7 @@ describe("reference source path selection", () => {
try {
const root = await fixture(parent, "tree");
const result = await importTree(root, undefined, []);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.entries).toContainEqual(
expect.objectContaining({
path: ".env",
@ -382,8 +377,7 @@ describe("reference source rooted module specifiers", () => {
"export const value = 1;\n",
);
const result = await importTree(root);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.relationships).toContainEqual({
from_path: "src/main.js",
to: "/outside/dep.js",

View File

@ -19,8 +19,7 @@ describe("readReferenceSource entries", () => {
const result = await readReferenceSource(root);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.entries.map(({ path }) => path)).toEqual([
"a.js",
"nested",
@ -53,8 +52,7 @@ describe("readReferenceSource entries", () => {
const result = await readReferenceSource(root);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.entries).toEqual([
{
status: "read",
@ -98,8 +96,7 @@ describe("readReferenceSource entries", () => {
const result = await readReferenceSource(root);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.bytesRead).toBe(size);
expect(result.value.entries).toContainEqual(
expect.objectContaining({
@ -120,8 +117,7 @@ describe("readReferenceSource entries", () => {
const result = await readReferenceSource(root);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
const path = [...segments, "deep.txt"].join("/");
expect(result.value.entries).toContainEqual(
expect.objectContaining({ status: "read", kind: "file", path }),
@ -145,8 +141,7 @@ describe("readReferenceSource failures and exclusions", () => {
},
});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(checked).toEqual(["ignored", "kept"]);
expect(result.value.entries.map(({ path }) => path)).toEqual(["kept"]);
});

View File

@ -44,8 +44,7 @@ it("preserves recovered diagnostics and file evidence through filesystem import"
caller: "reference-recovery-test",
policy: { secretPatterns: [] },
});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
const graph = result.value;
expect(historicalSourceGraphSchema.safeParse(graph).success).toBe(true);
expect(graph.entries.map(({ path }) => path)).toEqual([

View File

@ -28,8 +28,7 @@ it("imports test-suffixed filenames with unchanged paths, hashes, and languages"
caller: "reference-test-filenames-test",
policy: { secretPatterns: [] },
});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.entries).toHaveLength(files.length);
for (const [path, content, classifications, language] of files) {
expect(result.value.entries).toContainEqual({
@ -70,8 +69,7 @@ it("keeps parser failures and unknown dependencies visible for test filenames",
caller: "reference-test-parsing-test",
policy: { secretPatterns: [] },
});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.inventory_state).toBe("partial");
expect(result.value.relationships).toEqual([
{

View File

@ -36,8 +36,7 @@ it.each([
caller: "native-typescript-source",
policy: { secretPatterns: [] },
});
expect(imported.ok).toBe(true);
if (!imported.ok) return;
if (!imported.ok) throw imported.error;
expect(imported.value.relationships).toContainEqual({
from_path: from,
to: target,
@ -62,8 +61,7 @@ it.each(["main.ts", "main.js"])(
caller: "native-typescript-source",
policy: { secretPatterns: [] },
});
expect(imported.ok).toBe(true);
if (!imported.ok) return;
if (!imported.ok) throw imported.error;
expect(imported.value.relationships).toContainEqual(
expect.objectContaining({
from_path: from,
@ -85,8 +83,7 @@ it("does not substitute TypeScript sources for a JavaScript runtime import", asy
caller: "native-typescript-source",
policy: { secretPatterns: [] },
});
expect(imported.ok).toBe(true);
if (!imported.ok) return;
if (!imported.ok) throw imported.error;
expect(imported.value.relationships).toContainEqual(
expect.objectContaining({
from_path: "main.js",

View File

@ -43,8 +43,7 @@ describe("passive V8 Inspector provider", () => {
const listed = await new V8InspectorProvider().listTargets({
inspector_endpoint: fake.endpoint,
});
expect(listed.ok).toBe(true);
if (!listed.ok) return;
if (!listed.ok) throw listed.error;
expect(listed.value.targets).toHaveLength(206);
expect(listed.value.targets[0]?.target_id).toBe(fake.targetId);
} finally {
@ -63,8 +62,7 @@ describe("passive V8 Inspector provider", () => {
const result = await new V8InspectorProvider().listTargets({
inspector_endpoint: fake.endpoint,
});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.targets).toHaveLength(2);
expect(
result.value.targets.map(({ location }) => location),
@ -89,8 +87,7 @@ describe("passive V8 Inspector provider", () => {
const result = await new V8InspectorProvider().observe(
observeInput(fake.endpoint, fake.targetId, "node"),
);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.scripts.items).toHaveLength(3);
expect(result.value.scripts.excluded.unsupported_location).toBe(0);
expect(result.value.execution_contexts).toEqual([
@ -124,8 +121,7 @@ describe("passive V8 Inspector provider", () => {
const listed = await provider.listTargets({
inspector_endpoint: fake.endpoint,
});
expect(listed.ok).toBe(true);
if (!listed.ok) return;
if (!listed.ok) throw listed.error;
expect(listed.value.targets).toEqual([]);
const observed = await provider.observe(
@ -182,8 +178,7 @@ describe("complete Inspector script hashes", () => {
const result = await new V8InspectorProvider().observe(
observeInput(fake.endpoint, fake.targetId, "node"),
);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.scripts.items).toHaveLength(scriptHashes.length);
expect(
new Set(result.value.scripts.items.map(({ cdp_hash }) => cdp_hash)),
@ -205,8 +200,7 @@ describe("undeclared V8 runtime role", () => {
const input = observeInput(fake.endpoint, fake.targetId, "node");
delete input.runtime_kind;
const result = await new V8InspectorProvider().observe(input);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.target).toMatchObject({
protocol_type: "page",
runtime_kind: "unknown",
@ -230,8 +224,7 @@ describe("passive V8 Inspector evidence", () => {
...observeInput(fake.endpoint, fake.targetId, "node"),
};
const result = await new V8InspectorProvider().observe(input);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.scripts.items).toHaveLength(1);
expect(result.value.scripts.items[0]?.location).toMatchObject({
kind: "url",
@ -259,8 +252,7 @@ describe("passive V8 Inspector evidence", () => {
observation_ms: 1_000,
};
const result = await new V8InspectorProvider().observe(input);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.capture.truncated).toBe(false);
expect(result.value.capture.truncation_reasons).toEqual([]);
expect(result.value.capture.events_dropped).toBe(0);
@ -323,8 +315,7 @@ describe("passive V8 Inspector evidence", () => {
static_layers: JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE.static_layers,
runtime_observations: [runtimeEvidence],
});
expect(reconciled.ok).toBe(true);
if (!reconciled.ok) return;
if (!reconciled.ok) throw reconciled.error;
const result = javascriptRuntimeReconciliationResultSchema.parse(
reconciled.value.normalized_result,
);

View File

@ -35,8 +35,7 @@ test("lists and observes a Windows target without inventing a decoded path", asy
const listed = await provider.listTargets({
inspector_endpoint: fake.endpoint,
});
expect(listed.ok).toBe(true);
if (!listed.ok) return;
if (!listed.ok) throw listed.error;
expect(listed.value.targets).toMatchObject([
{
target_id: fake.targetId,
@ -66,8 +65,7 @@ test("lists and observes a Windows target without inventing a decoded path", asy
target_id: fake.targetId,
observation_ms: 10,
});
expect(observed.ok).toBe(true);
if (!observed.ok) return;
if (!observed.ok) throw observed.error;
expect(observed.value.target.location).toEqual(
listed.value.targets[0]?.location,
);
@ -97,8 +95,7 @@ test
const listed = await new V8InspectorProvider().listTargets({
inspector_endpoint: fake.endpoint,
});
expect(listed.ok).toBe(true);
if (!listed.ok) return;
if (!listed.ok) throw listed.error;
expect(listed.value.targets).toMatchObject([
{ location: { kind: "file", file_path: entry } },
]);
@ -116,8 +113,7 @@ test("keeps a lossy discovery name unresolved even when its underscore alias exi
const listed = await new V8InspectorProvider().listTargets({
inspector_endpoint: fake.endpoint,
});
expect(listed.ok).toBe(true);
if (!listed.ok) return;
if (!listed.ok) throw listed.error;
expect(listed.value.targets).toMatchObject([
{ location: { kind: "unresolved", reported_url: reported } },
]);
@ -137,8 +133,7 @@ test.each([
const listed = await new V8InspectorProvider().listTargets({
inspector_endpoint: fake.endpoint,
});
expect(listed.ok).toBe(true);
if (!listed.ok) return;
if (!listed.ok) throw listed.error;
expect(listed.value.targets).toEqual([]);
expect(listed.value.excluded.unsupported_location).toBe(1);
} finally {
@ -158,8 +153,7 @@ test.each([
const listed = await new V8InspectorProvider().listTargets({
inspector_endpoint: fake.endpoint,
});
expect(listed.ok).toBe(true);
if (!listed.ok) return;
if (!listed.ok) throw listed.error;
expect(listed.value.targets).toEqual([]);
expect(listed.value.excluded.unsupported_location).toBe(1);
} finally {
@ -183,8 +177,7 @@ test("does not reinterpret lossy discovery paths in script metadata", async () =
target_id: fake.targetId,
observation_ms: 10,
});
expect(observed.ok).toBe(true);
if (!observed.ok) return;
if (!observed.ok) throw observed.error;
expect(observed.value.scripts.items).toMatchObject([
{ location: { kind: "file", file_path: entry } },
]);

View File

@ -112,8 +112,7 @@ describe("Ghidra MCP evidence parity", () => {
"binary_overview",
{},
);
expect(directOverview.ok).toBe(true);
if (!directOverview.ok) return;
if (!directOverview.ok) throw directOverview.error;
expect(mcpOverview.normalized_result).toEqual(directOverview.value);
expect(mcpOverview).toMatchObject({
provider: { id: "rea-workflow" },
@ -191,8 +190,7 @@ describe("Ghidra MCP evidence parity", () => {
"analyze_function",
{ procedure: "fixture_main" },
);
expect(directAnalyzed.ok).toBe(true);
if (!directAnalyzed.ok) return;
if (!directAnalyzed.ok) throw directAnalyzed.error;
expect(analyzed.normalized_result).toEqual(directAnalyzed.value);
} finally {
await harness.close();

View File

@ -202,8 +202,7 @@ describe("GhidraClient", () => {
const client = clientFor(new FixtureLauncher("oversized_result"));
const result = await client.callTool("list_strings", { document: null });
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
if (!Array.isArray(result.value))
throw new TypeError("Ghidra fixture result was not an inventory array");
const first = result.value[0];

View File

@ -231,8 +231,7 @@ describe("Ghidra headless launcher", () => {
providerVersion: "12.1.4",
profileDigest: "a".repeat(64),
});
expect(launched.ok).toBe(true);
if (!launched.ok) return;
if (!launched.ok) throw launched.error;
const capturePath = join(runtimeRoot, "launch-capture.json");
await vi.waitFor(() => access(`${capturePath}.ready`), { timeout: 10_000 });
const capture = launchCaptureSchema.parse(

View File

@ -40,8 +40,7 @@ it.each([
await writeFile(leftPath, left);
await writeFile(rightPath, right);
const result = await compareManagedMemberPaths({ leftPath, rightPath });
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
const comparison = managedMemberComparisonResultSchema.parse(
result.value.normalized_result,
);
@ -83,8 +82,7 @@ describe("managed member comparison path workflow", () => {
right: observe(0xfe, "/tmp/partial-right.dll"),
});
const result = compareManagedMembersEvidenceValidated(input);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
const comparison = managedMemberComparisonResultSchema.parse(
result.value.normalized_result,
);
@ -114,8 +112,7 @@ describe("managed member comparison path workflow", () => {
rightPath,
});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value).toMatchObject({
operation: "compare_managed_members",
confidence: "inferred",

View File

@ -22,13 +22,11 @@ describe("managed static provider path boundary", () => {
const path = join(directory, "fixture.exe");
await writeFile(path, bytes);
const parsed = await parseBinaryTarget(path);
expect(parsed.ok).toBe(true);
if (!parsed.ok) return;
if (!parsed.ok) throw parsed.error;
const client = new ManagedStaticProvider().createClient(parsed.value);
const observed = await client.execute("inspect_managed_artifact", {});
expect(observed.ok).toBe(true);
if (!observed.ok) return;
if (!observed.ok) throw observed.error;
expect(asManagedResult(observed.value)).toMatchObject({
classification: { status: "managed", runtime_family: "modern-dotnet" },
artifact: { path, sha256: parsed.value.sha256, format: "pe" },
@ -37,8 +35,7 @@ describe("managed static provider path boundary", () => {
expect(observed.value.subject).toMatchObject({ path, format: "pe" });
const members = await client.execute("inspect_managed_members", {});
expect(members.ok).toBe(true);
if (!members.ok) return;
if (!members.ok) throw members.error;
expect(asManagedMemberResult(members.value)).toMatchObject({
artifact: { path, sha256: parsed.value.sha256, format: "pe" },
methods: [expect.objectContaining({ token: "0x06000001" })],
@ -60,8 +57,7 @@ describe("managed static provider path boundary", () => {
"inspect_managed_native_boundaries",
{},
);
expect(boundaries.ok).toBe(true);
if (!boundaries.ok) return;
if (!boundaries.ok) throw boundaries.error;
const boundaryResult = asManagedNativeBoundaryResult(boundaries.value);
expect(boundaryResult).toMatchObject({
artifact: { path, sha256: parsed.value.sha256, format: "pe" },
@ -116,16 +112,14 @@ describe("managed static provider path boundary", () => {
const path = join(directory, "fixture.exe");
await writeFile(path, bytes);
const parsed = await parseBinaryTarget(path);
expect(parsed.ok).toBe(true);
if (!parsed.ok) return;
if (!parsed.ok) throw parsed.error;
const client = new ManagedStaticProvider().createClient(parsed.value);
const execution = await client.execute(
"inspect_managed_native_boundaries",
{},
);
expect(execution.ok).toBe(true);
if (!execution.ok) return;
if (!execution.ok) throw execution.error;
const result = asManagedNativeBoundaryResult(execution.value);
expect(result.pinvoke_imports.length).toBeGreaterThan(0);
expect(execution.value.locations).toEqual(
@ -162,19 +156,16 @@ it("retains U+FEFF metadata through the filesystem target and provider", async (
}),
);
const parsed = await parseBinaryTarget(path);
expect(parsed.ok).toBe(true);
if (!parsed.ok) return;
if (!parsed.ok) throw parsed.error;
const client = new ManagedStaticProvider().createClient(parsed.value);
const artifact = await client.execute("inspect_managed_artifact", {});
expect(artifact.ok).toBe(true);
if (!artifact.ok) return;
if (!artifact.ok) throw artifact.error;
expect(asManagedResult(artifact.value)).toMatchObject({
references: [expect.objectContaining({ name: "\uFEFFSystem.Runtime" })],
target_frameworks: ["\uFEFF.NETCoreApp,Version=v8.0"],
});
const members = await client.execute("inspect_managed_members", {});
expect(members.ok).toBe(true);
if (!members.ok) return;
if (!members.ok) throw members.error;
expect(asManagedMemberResult(members.value)).toMatchObject({
types: [expect.objectContaining({ name: "\uFEFFProgram" })],
methods: [expect.objectContaining({ name: "\uFEFFMain" })],
@ -188,26 +179,22 @@ it("keeps non-CIL implementation bytes unknown through the real file provider",
const bytes = buildManagedPeFixture();
await writeFile(path, bytes);
const originalTarget = await parseBinaryTarget(path);
expect(originalTarget.ok).toBe(true);
if (!originalTarget.ok) return;
if (!originalTarget.ok) throw originalTarget.error;
const original = await new ManagedStaticProvider()
.createClient(originalTarget.value)
.execute("inspect_managed_members", {});
expect(original.ok).toBe(true);
if (!original.ok) return;
if (!original.ok) throw original.error;
const row = asManagedMemberResult(original.value).methods[0]?.row_offset;
expect(row).toBeDefined();
if (row === undefined) return;
bytes.writeUInt16LE(1, row + 4);
await writeFile(path, bytes);
const nativeTarget = await parseBinaryTarget(path);
expect(nativeTarget.ok).toBe(true);
if (!nativeTarget.ok) return;
if (!nativeTarget.ok) throw nativeTarget.error;
const native = await new ManagedStaticProvider()
.createClient(nativeTarget.value)
.execute("inspect_managed_members", {});
expect(native.ok).toBe(true);
if (!native.ok) return;
if (!native.ok) throw native.error;
const result = asManagedMemberResult(native.value);
expect(result.methods[0]?.body).toMatchObject({
status: "partial",
@ -220,13 +207,11 @@ it("keeps non-CIL implementation bytes unknown through the real file provider",
bytes.writeUInt32LE(0, row);
await writeFile(path, bytes);
const absentTarget = await parseBinaryTarget(path);
expect(absentTarget.ok).toBe(true);
if (!absentTarget.ok) return;
if (!absentTarget.ok) throw absentTarget.error;
const absent = await new ManagedStaticProvider()
.createClient(absentTarget.value)
.execute("inspect_managed_members", {});
expect(absent.ok).toBe(true);
if (!absent.ok) return;
if (!absent.ok) throw absent.error;
expect(asManagedMemberResult(absent.value).methods[0]?.body.status).toBe(
"absent",
);

View File

@ -30,8 +30,7 @@ describe("artifact directory diagnostics", () => {
await chmod(blockedPath, 0);
try {
const target = await parseBinaryTarget(appPath);
expect(target.ok).toBe(true);
if (!target.ok) return;
if (!target.ok) throw target.error;
const result = await new ArtifactProvider()
.createClient(target.value)
.execute("inventory_artifact", {});

View File

@ -81,8 +81,7 @@ describe("artifact extraction", () => {
output_root: output,
}),
);
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
const firstExtraction = artifactExtractionResultSchema.parse(
result.value.result,
);
@ -110,8 +109,7 @@ describe("artifact extraction", () => {
output_root: relocatedOutput,
}),
);
expect(relocated.ok).toBe(true);
if (!relocated.ok) return;
if (!relocated.ok) throw relocated.error;
expect(
artifactExtractionResultSchema.parse(relocated.value.result)
.extraction_manifest,

View File

@ -148,8 +148,7 @@ it("retains native inventory facts from captured Apple tool output", async () =>
"darwin",
).createClient(machoTarget("/private/fixture"));
const execution = await client.execute("inspect_macho", {});
expect(execution.ok).toBe(true);
if (!execution.ok) return;
if (!execution.ok) throw execution.error;
expect(execution.value.result).toMatchObject({
imports: {
items: [

View File

@ -99,8 +99,7 @@ it("limits thread-state entrypoints instead of reporting none silently", async (
nativeMachoTarget("/owned/legacy-fixture"),
);
const result = await client.execute("inspect_macho", {});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.result).toMatchObject({
entrypoints: {
items: [],

View File

@ -20,8 +20,7 @@ it("collects the actual Mach header alongside the native load commands", async (
nativeMachoTarget("/owned/fixture"),
);
const result = await client.execute("inspect_macho", {});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.result).toMatchObject({
file_type: "2",
flags: ["0x00200085"],

View File

@ -127,8 +127,7 @@ describe("native macOS provider inspection", () => {
machoTarget("/private/fixture"),
);
const execution = await client.execute("inspect_macho", {});
expect(execution.ok).toBe(true);
if (!execution.ok) return;
if (!execution.ok) throw execution.error;
expect(execution.value.provider.id).toBe("native-macos");
expect(execution.value.result).toMatchObject({
format: "mach-o",
@ -170,8 +169,7 @@ describe("native macOS provider inspection", () => {
const execution = await client.execute("inspect_macho", {});
expect(execution.ok).toBe(true);
if (!execution.ok) return;
if (!execution.ok) throw execution.error;
expect(execution.value.result).toMatchObject({
segments: {
items: [
@ -204,8 +202,7 @@ describe("native macOS provider inspection", () => {
const execution = await client.execute("inspect_macho", {});
expect(execution.ok).toBe(true);
if (!execution.ok) return;
if (!execution.ok) throw execution.error;
expect(execution.value.limitations).toEqual(
expect.arrayContaining([expect.stringMatching(/vtool.*unavailable/iu)]),
);
@ -329,8 +326,7 @@ describe("native signature entitlements", () => {
const signature = await client.execute("inspect_signature", {});
expect(signature.ok).toBe(true);
if (!signature.ok) return;
if (!signature.ok) throw signature.error;
expect(signature.value.result).toMatchObject({
entitlements: { "com.apple.security.app-sandbox": true },
});

View File

@ -15,8 +15,7 @@ it("retains native re-export dependencies alongside ordinary and identity comman
nativeMachoTarget("/owned/libOuter.dylib"),
);
const result = await client.execute("inspect_macho", {});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.result).toMatchObject({
dependencies: {
exhaustive: true,

View File

@ -28,8 +28,7 @@ it("does not attribute the first universal slice's UUID and segments to the sele
"darwin",
).createClient(nativeMachoTarget("/owned/universal"));
const result = await client.execute("inspect_macho", {});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.result).toMatchObject({
uuid: "01234567-89AB-CDEF-0123-456789ABCDEF",
architectures: { total: 2 },
@ -96,8 +95,7 @@ it.each([
const result = await client.execute("inspect_macho", {});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(result.value.result).toMatchObject({
uuid: "01234567-89AB-CDEF-0123-456789ABCDEF",
architectures: {

View File

@ -293,8 +293,7 @@ describe("Apple application projection completeness", () => {
const result = projectAppleApplicationEvidence({
inventory_evidence: [inventory],
});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
expect(
appleApplicationProjectionResultSchema.parse(
result.value.normalized_result,

View File

@ -552,8 +552,7 @@ describe("replay of exact immutable calls", () => {
).ok,
).toBe(true);
const snapshot = initial.exportAnalysisSnapshot();
expect(snapshot.ok).toBe(true);
if (!snapshot.ok) return;
if (!snapshot.ok) throw snapshot.error;
expect(snapshot.value.entries).toHaveLength(1);
await initial.close();

View File

@ -163,8 +163,7 @@ describe("Android application projection", () => {
inventory_evidence: [inventory],
});
expect(result.ok).toBe(true);
if (!result.ok) return;
if (!result.ok) throw result.error;
const projection = androidApplicationProjectionResultSchema.parse(
result.value.normalized_result,
);

View File

@ -205,8 +205,7 @@ describe("managed/native boundary verification", () => {
it("wraps verification in derived workflow Evidence", () => {
const evidence = verifyManagedNativeBoundariesEvidence(exampleInput());
expect(evidence.ok).toBe(true);
if (!evidence.ok) return;
if (!evidence.ok) throw evidence.error;
expect(evidence.value).toMatchObject({
operation: "verify_managed_native_boundaries",
provider: { id: "rea-dotnet-workflows" },

View File

@ -2,7 +2,6 @@ import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { TextReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
import { expect } from "vitest";
import { runProviderAnalysis } from "../../src/composition/directAnalysis.js";
import type { AnalysisError } from "../../src/domain/analysisErrorBase.js";
@ -14,7 +13,6 @@ import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
export const requireSuccessfulProjection = (
result: Result<Evidence, AnalysisError>,
): Evidence => {
expect(result.ok).toBe(true);
if (!result.ok)
throw new TypeError("Expected application projection to succeed");
return result.value;

View File

@ -1,11 +1,4 @@
import {
mkdir,
mkdtemp,
readFile,
realpath,
rm,
writeFile,
} from "node:fs/promises";
import { mkdir, mkdtemp, realpath, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
@ -13,12 +6,9 @@ import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
export interface TestWorkspace {
readonly root: string;
readonly home: string;
readonly xdgConfigHome: string;
readonly xdgCacheHome: string;
readonly environment: NodeJS.ProcessEnv;
path(...segments: readonly string[]): string;
mkdir(relativePath: string): Promise<string>;
read(relativePath: string): Promise<string>;
write(relativePath: string, contents: string | Uint8Array): Promise<string>;
}
@ -64,8 +54,6 @@ export const createTestWorkspace = async (
return {
root,
home,
xdgConfigHome,
xdgCacheHome,
environment: {
HOME: home,
XDG_CONFIG_HOME: xdgConfigHome,
@ -77,7 +65,6 @@ export const createTestWorkspace = async (
await mkdir(path, { recursive: true });
return path;
},
read: (relativePath) => readFile(resolvePath(relativePath), "utf8"),
write: async (relativePath, contents) => {
const path = resolvePath(relativePath);
await mkdir(dirname(path), { recursive: true });