test: remove duplicate result assertions before throwing guards

This commit is contained in:
morluto 2026-10-09 02:33:01 +08:00
parent 5945915f91
commit a1b7d40bb0
33 changed files with 0 additions and 62 deletions

View File

@ -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)

View File

@ -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];

View File

@ -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" },

View File

@ -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",

View File

@ -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,

View File

@ -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,

View File

@ -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");
});

View File

@ -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",

View File

@ -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(

View File

@ -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);

View File

@ -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 }] }],

View File

@ -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");

View File

@ -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);

View File

@ -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");

View File

@ -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(

View File

@ -216,7 +216,6 @@ it("retains APK identity, original input, raw producer data and normalized obser
const outcome = await service.execute("inspect_android_package", {
path: apk,
});
expect(outcome.ok).toBe(true);
if (!outcome.ok) throw outcome.error;
const result = androidResultSchemas.inspect_android_package.parse(
outcome.value.normalized_result,

View File

@ -56,7 +56,6 @@ describe("CDP target inventory", () => {
allowed_origins: ["https://allowed.example"],
});
expect(result.ok).toBe(true);
if (!result.ok) throw result.error;
expect(result.value.targets).toHaveLength(targets.length);
expect(result.value.targets[0]?.target_id).toBe("target-0000");

View File

@ -25,7 +25,6 @@ describe("CdpBrowserProvider navigation timeline", () => {
}),
);
expect(result.ok).toBe(true);
if (!result.ok) throw result.error;
expect(result.value.timeline).toHaveLength(additionalEvents + 6);
expect(result.value.completeness.truncated_sections).not.toContain(

View File

@ -281,7 +281,6 @@ describe("runtime lifecycle and invalid producer data", () => {
},
},
);
expect(result.ok).toBe(false);
if (result.ok)
throw new Error("Cancellation must not produce successful evidence");
expect(result.error._tag).toBe("AnalysisCancelledError");
@ -297,7 +296,6 @@ describe("runtime lifecycle and invalid producer data", () => {
unsupportedMethods: ["Profiler.stopPreciseCoverage"],
});
const result = await provider.observeExecution(execution);
expect(result.ok).toBe(false);
if (result.ok) throw new Error("Failed cleanup must not return success");
expect(result.error.cleanupIncomplete).toBe(true);
expect(

View File

@ -523,7 +523,6 @@ describe("iOS-style app bundle targets", () => {
await chmod(wrapper, 0o000);
try {
const result = await parseBinaryTarget(app, directory, "arm64");
expect(result.ok).toBe(false);
if (result.ok) throw new Error("Expected a permission denial");
expect(result.error.message).toContain("permission denied");
} finally {
@ -564,7 +563,6 @@ describe("iOS-style app bundle targets", () => {
await writeFile(join(app, "Info.plist"), plist("Escaping"));
await symlink(outside, join(app, "Escaping"));
const result = await parseBinaryTarget(app, directory, "arm64");
expect(result.ok).toBe(false);
if (result.ok) throw new Error("Expected an escaping program file");
expect(result.error.message).toContain("leaves the bundle root");
},

View File

@ -337,7 +337,6 @@ describe("reference source import behavior", () => {
message: "fixture",
});
const result = await importTree(root);
expect(result.ok).toBe(true);
if (!result.ok) throw result.error;
expect(result.value.vcs).toEqual({ kind: "git", head: oid, dirty: null });
} finally {

View File

@ -176,7 +176,6 @@ describe("captured script publication failures and cleanup", () => {
const { input } = await setup();
await writeFile(input.capture_path, bytes);
const result = await exportWebScripts(input);
expect(result.ok).toBe(false);
if (result.ok) throw new Error("Expected invalid input");
expect(result.error._tag).toBe("AnalysisInputError");
await expect(access(input.output_directory)).rejects.toMatchObject({
@ -195,7 +194,6 @@ describe("captured script publication failures and cleanup", () => {
process.platform === "win32" ? "junction" : "dir",
);
const result = await exportWebScripts(input);
expect(result.ok).toBe(false);
if (result.ok) throw new Error("Expected exclusive output failure");
expect(result.error.userMessage).toContain("already exists");
expect(await readFile(marker, "utf8")).toBe("keep");
@ -229,7 +227,6 @@ describe("captured script publication failures and cleanup", () => {
const controller = new AbortController();
controller.abort();
const result = await exportWebScripts(input, { signal: controller.signal });
expect(result.ok).toBe(false);
if (result.ok) throw new Error("Expected cancellation");
expect(result.error._tag).toBe("AnalysisCancelledError");
await expect(
@ -249,7 +246,6 @@ describe("captured script publication failures and cleanup", () => {
...input,
capture_path: `${input.capture_path}.missing`,
});
expect(missing.ok).toBe(false);
if (missing.ok) throw new Error("Expected unavailable input");
expect(missing.error.userMessage).toContain(
`${input.capture_path}.missing`,
@ -258,7 +254,6 @@ describe("captured script publication failures and cleanup", () => {
...input,
capture_path: "capture.json",
});
expect(relative.ok).toBe(false);
if (relative.ok) throw new Error("Expected host path error");
expect(relative.error._tag).toBe("AnalysisInputError");
});

View File

@ -22,7 +22,6 @@ test("keeps unresolved target identity unknown while matching verified loaded sc
try {
await writeFile(entry, "export const fixture = true;\n");
const analysis = await analyzeJavaScriptApplication({ input_path: root });
expect(analysis.ok).toBe(true);
if (!analysis.ok) throw analysis.error;
const provider = new V8InspectorProvider();
const input = {
@ -31,7 +30,6 @@ test("keeps unresolved target identity unknown while matching verified loaded sc
observation_ms: 10,
};
const observed = await provider.observe(input);
expect(observed.ok).toBe(true);
if (!observed.ok) throw observed.error;
const evidence = createJavaScriptRuntimeObservationEvidence(
"observe_javascript_runtime",

View File

@ -71,7 +71,6 @@ describe.skipIf(process.platform !== "linux" || process.arch !== "x64")(
path: fixture.path,
output_directory: fixture.output,
});
expect(result.ok).toBe(false);
if (result.ok) throw new Error("expected boundary failure");
const error = projectAnalysisError(result.error);
expect(["execution_failure", "unreadable_output"]).toContain(
@ -91,7 +90,6 @@ describe.skipIf(process.platform !== "linux" || process.arch !== "x64")(
path: fixture.path,
output_directory: fixture.output,
});
expect(result.ok).toBe(false);
if (result.ok) throw new Error("expected invalid UTF-8 boundary");
expect(JSON.stringify(projectAnalysisError(result.error))).toContain(
"UTF-8 byte range",
@ -131,7 +129,6 @@ describe.skipIf(process.platform !== "linux" || process.arch !== "x64")(
path: fixture.path,
output_directory: fixture.output,
});
expect(result.ok).toBe(false);
if (result.ok) throw new Error("expected existing-output rejection");
expect(projectAnalysisError(result.error)).toMatchObject({
code: "invalid_request",

View File

@ -98,7 +98,6 @@ describe("enhanced MCP tools", () => {
);
expect(calls).toBe(1);
expect(result.ok).toBe(false);
if (result.ok) throw new Error("expected cancellation");
expect(result.error._tag).toBe("AnalysisCancelledError");
});

View File

@ -253,7 +253,6 @@ itWithCaptureCapability(
cleanupHost,
);
expect(result.ok).toBe(false);
if (result.ok) throw new Error("expected cleanup-incomplete failure");
if (!(result.error instanceof ProcessCaptureError)) throw result.error;
const partial = result.error.partialObservation;
@ -455,7 +454,6 @@ itWithCaptureCapability(
}),
controller.signal,
);
expect(cancelled.ok).toBe(false);
if (cancelled.ok) throw new Error("expected cancellation");
expect(cancelled.error.message).toContain("cancelled");
},
@ -486,7 +484,6 @@ itWithCaptureCapability(
signal,
);
expect(result.ok).toBe(false);
if (result.ok) throw new Error("expected initial snapshot cancellation");
expect(result.error).toMatchObject({
reason: "cancelled",
@ -522,7 +519,6 @@ itWithCaptureCapability(
);
const result = await resultPromise;
expect(result.ok).toBe(false);
if (result.ok) throw new Error("expected final snapshot cancellation");
expect(initialSnapshotCompleted).toBe(true);
expect(result.error).toMatchObject({
@ -560,7 +556,6 @@ itWithCaptureCapability(
captureSnapshot,
);
expect(result.ok).toBe(false);
if (result.ok) throw new Error("expected filesystem observation failure");
expect(result.error).toMatchObject({
reason: "capture_failed",

View File

@ -15,7 +15,6 @@ it.each([0x01c0, 0x01c2, 0x01c4])(
const path = join(directory, "fixture.exe");
await writeFile(path, bytes);
const parsed = await parseBinaryTarget(path);
expect(parsed.ok).toBe(true);
if (!parsed.ok) throw parsed.error;
expect(parsed.value).toMatchObject({
kind: "executable",
@ -31,7 +30,6 @@ it.each([0x01c0, 0x01c2, 0x01c4])(
"inspect_managed_native_boundaries",
] as const) {
const observed = await client.execute(operation, {});
expect(observed.ok).toBe(true);
if (!observed.ok) throw observed.error;
expect(observed.value.subject).toMatchObject({
path,

View File

@ -86,7 +86,6 @@ describe("native signature target identity", () => {
const result = await new NativeMacOSProvider(runner, "darwin")
.createClient(target)
.execute("inspect_signature", {});
expect(result.ok).toBe(false);
if (result.ok) throw new Error("Expected target-change failure");
expect(projectAnalysisError(result.error)).toMatchObject({
code: "artifact_changed",
@ -113,7 +112,6 @@ describe("native signature target identity", () => {
const result = await new NativeMacOSProvider(runner, "darwin")
.createClient(target)
.execute("inspect_signature", {});
expect(result.ok).toBe(false);
if (result.ok) throw new Error("Expected target-change failure");
expect(projectAnalysisError(result.error)).toMatchObject({
code: "artifact_changed",
@ -132,7 +130,6 @@ describe("native signature target identity", () => {
const result = await new NativeMacOSProvider(runner, "darwin")
.createClient(target)
.execute("inspect_signature", {});
expect(result.ok).toBe(false);
if (result.ok) throw new Error("Expected access denial");
expect(projectAnalysisError(result.error)).toMatchObject({
code: "access_denied",
@ -156,7 +153,6 @@ describe("native signature target identity", () => {
const result = await new NativeMacOSProvider(runner, "darwin")
.createClient(target)
.execute("inspect_signature", {});
expect(result.ok).toBe(false);
if (result.ok) throw new Error("Expected access denial");
expect(projectAnalysisError(result.error)).toMatchObject({
code: "access_denied",

View File

@ -70,7 +70,6 @@ it("accepts a byte-order mark before plist JSON", () => {
const parsed = parsePlistJson(
'\uFEFF{"CFBundleIdentifier":"com.owned.fixture"}',
);
expect(parsed.ok).toBe(true);
if (!parsed.ok) throw new Error("expected plist JSON to parse");
expect(parsed.value.bundle.identifier).toBe("com.owned.fixture");
});

View File

@ -61,7 +61,6 @@ async function createCompleteAppleProjection() {
inventory_evidence: fragments,
});
expect(result.ok).toBe(true);
if (!result.ok) throw new TypeError("Could not project fixture inventory");
const projection = appleApplicationProjectionResultSchema.parse(
result.value.normalized_result,

View File

@ -200,7 +200,6 @@ describe("managed application graph coverage", () => {
managed_members: parserPartialEvidence,
});
expect(parserPartialProjection.ok).toBe(true);
if (!parserPartialProjection.ok)
throw new Error("partial projection failed");
const parserPartialResult = managedApplicationGraphResultSchema.parse(

View File

@ -43,7 +43,6 @@ describe("IDA provider composition", () => {
diagnostics: { live_connection_probed: false },
});
const resolution = await provider.resolveAnalysisProfile(target);
expect(resolution.ok).toBe(true);
if (!resolution.ok) throw resolution.error;
expect(resolution.value.profile.parameters).toMatchObject({
engine_version: null,
@ -75,7 +74,6 @@ describe("IDA provider composition", () => {
const first = await session.execute("procedure_pseudo_code", query);
expect(first.ok && first.value.result).toContain("42");
const snapshot = session.exportAnalysisSnapshot();
expect(snapshot.ok).toBe(true);
if (!snapshot.ok) throw snapshot.error;
expect(snapshot.value.entries).toEqual([]);
const profile = session.analysisProfile();

View File

@ -42,7 +42,6 @@ describe("MCP response budget configuration", () => {
"9007199254740992",
])("rejects malformed or unusable budgets: %j", (value) => {
const parsed = parseMcpResponseBudget(value);
expect(parsed.ok).toBe(false);
if (parsed.ok) throw new Error("Expected invalid budget");
expect(parsed.error.message).toContain("REA_MCP_MAX_RESPONSE_BYTES");
});