test: remove duplicate result assertions before throwing guards

This commit is contained in:
morluto
2026-10-09 02:58:03 +08:00
parent 5945915f91
commit a1b7d40bb0
33 changed files with 0 additions and 62 deletions
@@ -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,
@@ -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");
@@ -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(
@@ -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(
@@ -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");
},
@@ -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 {
@@ -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");
});
@@ -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",
@@ -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",
@@ -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");
});
@@ -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",
@@ -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,
@@ -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",
@@ -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");
});
@@ -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,
@@ -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(
-2
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();
@@ -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");
});