test: remove duplicate result assertions before throwing guards
This commit is contained in:
@@ -139,7 +139,6 @@ describe("analysis provider registry: binding failures and cancellation", () =>
|
||||
const unsupported = await new AnalysisProviderRegistry([
|
||||
candidate("alpha", { available: false }).provider,
|
||||
]).select(ARTIFACT_TARGET, "alpha");
|
||||
expect(unsupported.ok).toBe(false);
|
||||
if (unsupported.ok)
|
||||
throw new Error("expected unsupported target rejection");
|
||||
expect(unsupported.error).toBeInstanceOf(ProviderSelectionError);
|
||||
@@ -181,7 +180,6 @@ describe("analysis provider registry: binding failures and cancellation", () =>
|
||||
});
|
||||
}
|
||||
const explicit = await automatic.select(ARTIFACT_TARGET, "alpha");
|
||||
expect(explicit.ok).toBe(false);
|
||||
if (explicit.ok) throw new Error("expected provider selection rejection");
|
||||
expect(explicit.error).toBeInstanceOf(ProviderSelectionError);
|
||||
if (explicit.error instanceof ProviderSelectionError)
|
||||
@@ -213,7 +211,6 @@ describe("analysis provider registry: binding failures and cancellation", () =>
|
||||
const explicit = await new AnalysisProviderRegistry([
|
||||
failed.provider,
|
||||
]).select(DATABASE_TARGET, "failed");
|
||||
expect(explicit.ok).toBe(false);
|
||||
if (explicit.ok) throw new Error("expected provider selection rejection");
|
||||
expect(explicit.error).toBeInstanceOf(ProviderSelectionError);
|
||||
if (explicit.error instanceof ProviderSelectionError)
|
||||
|
||||
@@ -230,7 +230,6 @@ describe("analysis snapshot cache partitioning", () => {
|
||||
ANALYSIS_SNAPSHOT_PROFILE,
|
||||
createEvidenceBundle([evidence]),
|
||||
);
|
||||
expect(exported.ok).toBe(true);
|
||||
if (!exported.ok) throw new Error("snapshot export failed");
|
||||
const tampered = structuredClone(exported.value);
|
||||
const tamperedEntry = tampered.entries[0];
|
||||
|
||||
@@ -43,7 +43,6 @@ describe("JavaScript analysis cancellation before publication", () => {
|
||||
},
|
||||
);
|
||||
expect(requested).toBe(true);
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok)
|
||||
throw new Error("Cancelled analysis must not publish Evidence");
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
@@ -68,7 +67,6 @@ describe("JavaScript analysis cancellation before publication", () => {
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("Expected cancellation before admission");
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
details: { reason: "cancelled" },
|
||||
|
||||
@@ -30,7 +30,6 @@ describe("JavaScript application failure diagnostics", () => {
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("Expected analysis failure");
|
||||
expect(result.error.cause).toBe(cause);
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
@@ -59,7 +58,6 @@ describe("JavaScript application failure diagnostics", () => {
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("Expected analysis failure");
|
||||
expect(result.error.cause).toBe(cause);
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
@@ -84,7 +82,6 @@ describe("JavaScript application failure diagnostics", () => {
|
||||
input_path: join(root, "missing"),
|
||||
format: "directory",
|
||||
});
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("Expected missing artifact failure");
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "artifact_operation_failed",
|
||||
@@ -107,7 +104,6 @@ describe("JavaScript application failure diagnostics", () => {
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("Expected analysis failure");
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "execution_failure",
|
||||
@@ -140,7 +136,6 @@ describe("JavaScript application failure diagnostics", () => {
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("Expected analysis failure");
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "execution_failure",
|
||||
|
||||
@@ -61,7 +61,6 @@ describe("source-relative file URL paths", () => {
|
||||
input_path: root,
|
||||
format: "directory",
|
||||
});
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) throw result.error;
|
||||
const { graph } = javascriptApplicationAnalysisResultSchema.parse(
|
||||
result.value.normalized_result,
|
||||
|
||||
@@ -124,7 +124,6 @@ describe("ESM module URL decoding", () => {
|
||||
input_path: root,
|
||||
format: "directory",
|
||||
});
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) throw result.error;
|
||||
const { graph } = javascriptApplicationAnalysisResultSchema.parse(
|
||||
result.value.normalized_result,
|
||||
@@ -235,7 +234,6 @@ describe("package exports URL paths", () => {
|
||||
input_path: root,
|
||||
format: "directory",
|
||||
});
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) throw result.error;
|
||||
const { graph } = javascriptApplicationAnalysisResultSchema.parse(
|
||||
result.value.normalized_result,
|
||||
|
||||
@@ -111,7 +111,6 @@ describe("JavaScript recovery workflow", () => {
|
||||
),
|
||||
});
|
||||
const result = await service.recover(input);
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("expected invalid port output");
|
||||
expect(result.error._tag).toBe("AnalysisOutputError");
|
||||
});
|
||||
|
||||
@@ -198,7 +198,6 @@ describe("PlaywrightBrowserScenarioProvider", () => {
|
||||
const result = await provider.captureScenario(
|
||||
scenario({ events: ["frames"] }),
|
||||
);
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.completeness).toMatchObject({
|
||||
status: "incomplete",
|
||||
|
||||
@@ -82,7 +82,6 @@ describe("runtime configuration", () => {
|
||||
describe("runtime target configuration", () => {
|
||||
it("rejects invalid target kinds with actionable environment diagnostics", () => {
|
||||
const result = parseConfig({ HOPPER_TARGET_KIND: "archive" });
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("Expected invalid target kind");
|
||||
expect(result.error.message).toContain("Invalid REA environment");
|
||||
});
|
||||
@@ -121,7 +120,6 @@ describe("runtime collection configuration", () => {
|
||||
HOPPER_TARGET_PATH: "/tmp/a",
|
||||
HOPPER_LOADER_ARGS_JSON: encoded,
|
||||
});
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok)
|
||||
throw new Error("expected malformed loader arguments to fail");
|
||||
expect(result.error.message).toContain(
|
||||
|
||||
@@ -5,7 +5,6 @@ import { safeParseJson } from "./safeJson.js";
|
||||
it("keeps the original JSON parse failure as the cause", () => {
|
||||
const parsed = safeParseJson("{");
|
||||
|
||||
expect(parsed.ok).toBe(false);
|
||||
if (parsed.ok) throw new Error("expected invalid JSON to fail");
|
||||
expect(parsed.error).toContain("JSON");
|
||||
expect(parsed.cause).toBeInstanceOf(SyntaxError);
|
||||
|
||||
@@ -185,7 +185,6 @@ describe("Ghidra jump-table mapping contract", () => {
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(parsed.ok).toBe(true);
|
||||
if (!parsed.ok) throw parsed.error;
|
||||
const output = functionDossierSchema.parse(parsed.value).native_api;
|
||||
if (output?.available !== true)
|
||||
@@ -218,7 +217,6 @@ describe("Ghidra jump-table mapping contract", () => {
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(parsed.ok).toBe(true);
|
||||
if (!parsed.ok) throw parsed.error;
|
||||
expect(functionDossierSchema.parse(parsed.value).native_api).toMatchObject({
|
||||
jump_tables: [{ default_targets: [], mappings: [{ case_value: null }] }],
|
||||
|
||||
@@ -428,7 +428,6 @@ describe("Ghidra client projection", () => {
|
||||
executableTarget("elf", "x86_64"),
|
||||
);
|
||||
|
||||
expect(resolved.ok).toBe(true);
|
||||
if (!resolved.ok) throw resolved.error;
|
||||
if (resolved.value.profile === null)
|
||||
throw new Error("Expected a bound Ghidra profile");
|
||||
|
||||
@@ -163,7 +163,6 @@ describe("attached IDA function observations", () => {
|
||||
const result = await client.execute("analyze_function", {
|
||||
procedure: "0x1004",
|
||||
});
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) throw result.error;
|
||||
const dossier = functionDossierSchema.parse(result.value.result);
|
||||
expect(dossier.procedure.address).toBe("0x1000");
|
||||
@@ -367,7 +366,6 @@ describe("headless IDA session ownership and cleanup", () => {
|
||||
const result = await client.execute("analyze_function", {
|
||||
procedure: "main",
|
||||
});
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) throw result.error;
|
||||
expect(producer.inputPath).not.toBe(target.path);
|
||||
expect(await readFile(producer.inputPath)).toEqual(original);
|
||||
|
||||
@@ -500,7 +500,6 @@ it("fails closed on Windows before resolving or launching scenario paths", async
|
||||
working_directory: "Z:/missing/working-directory",
|
||||
});
|
||||
const result = await captureProcessScenario(scenario, undefined, "win32");
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("expected Windows ownership refusal");
|
||||
if (!(result.error instanceof AnalysisCapabilityUnavailableError))
|
||||
throw new Error("expected a capability-unavailable outcome");
|
||||
|
||||
@@ -15,7 +15,6 @@ describe("MCP result encoding budget", () => {
|
||||
{ result: "x".repeat(8191) + "😀" + '中文\n"'.repeat(20000) },
|
||||
])("counts actual UTF-8 structured and escaped text bytes", (candidate) => {
|
||||
const encoded = encodeToolResult(candidate);
|
||||
expect(encoded.ok).toBe(true);
|
||||
if (!encoded.ok) throw new Error("Expected complete encoding");
|
||||
expect(encoded.text).toBe(JSON.stringify(candidate));
|
||||
expect(encoded.bytes).toBe(
|
||||
|
||||
Reference in New Issue
Block a user