* fix: bind identity and coverage to the producing rule Logical paths, container families, examined bytes, path-segment conventions, destination collisions, file-id leases, Mach-O CPU selection, and firmware cleanup now follow the observation that owns each rule. * fix: fail unmatched Mach-O slices and keep firmware roots independent A fat target whose architecture lipo did not list now stops before slice tools run. Chained fixups still count unread LC_DYLD_INFO rebase bytes, and a firmware cleanup failure no longer blocks the next workspace. * test: cover path identity and runtime families at the projection boundary NFC joins and segment conventions are now asserted by the path resolver, the Apple projection, and a real APK inventory instead of helper unit tests. * test: expect unread dyld rebase bytes in the Apple dispatch fixture The legacy LC_DYLD_INFO fixture keeps a rebase range this reader does not decode, so the public CLI and MCP check now requires that partial coverage beside the bind opcodes. --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
99 lines
2.9 KiB
TypeScript
99 lines
2.9 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
|
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
|
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
|
import { err, ok } from "../domain/result.js";
|
|
import { firmwareRequestSchema } from "../domain/firmware/firmwareAnalysis.js";
|
|
import { finishFirmwareWorkspace } from "./FirmwareProvider.js";
|
|
|
|
const request = firmwareRequestSchema.parse({
|
|
operation: "extract_firmware",
|
|
input: {
|
|
path: "/tmp/firmware.bin",
|
|
output_directory: "/tmp/extracted",
|
|
},
|
|
});
|
|
|
|
const execution = ok({
|
|
result: { files: ["kept"] },
|
|
rawResult: null,
|
|
provider: { id: "unblob", name: "unblob", version: "1" },
|
|
limitations: [],
|
|
locations: [],
|
|
subject: null,
|
|
});
|
|
|
|
describe("firmware workspace cleanup", () => {
|
|
it("returns the completed extraction beside a cleanup failure and does not delete the leaked root", async () => {
|
|
const close = vi.fn(async () => {
|
|
throw new Error("cleanup failed");
|
|
});
|
|
const finished = await finishFirmwareWorkspace(
|
|
{ path: "/tmp/runtime", close },
|
|
execution,
|
|
"unblob",
|
|
request,
|
|
);
|
|
expect(close).toHaveBeenCalledOnce();
|
|
if (finished.ok || !(finished.error instanceof ProviderAdapterError))
|
|
throw new Error("Expected cleanup failure");
|
|
expect(finished.error.cleanupResources).toEqual([
|
|
"/tmp/runtime",
|
|
"/tmp/extracted",
|
|
]);
|
|
expect(finished.error.partialObservation).toEqual({
|
|
kind: "firmware",
|
|
result: { files: ["kept"] },
|
|
});
|
|
expect(finished.error.diagnostics).toEqual({ reason: "cleanup failed" });
|
|
expect(projectAnalysisError(finished.error).details).toMatchObject({
|
|
partial_observation: {
|
|
kind: "firmware",
|
|
result: { files: ["kept"] },
|
|
},
|
|
});
|
|
});
|
|
|
|
it("does not replay a cleanup failure for a later workspace", async () => {
|
|
const failed = await finishFirmwareWorkspace(
|
|
{
|
|
path: "/tmp/runtime",
|
|
close: async () => {
|
|
throw new Error("cleanup failed");
|
|
},
|
|
},
|
|
execution,
|
|
"unblob",
|
|
request,
|
|
);
|
|
expect(failed.ok).toBe(false);
|
|
const next = await finishFirmwareWorkspace(
|
|
{ path: "/tmp/next", close: async () => undefined },
|
|
execution,
|
|
"unblob",
|
|
request,
|
|
);
|
|
expect(next).toBe(execution);
|
|
});
|
|
|
|
it("leaves an uncertain workspace recorded and does not remove it", async () => {
|
|
const close = vi.fn(async () => undefined);
|
|
const cleanup = new ProviderCleanupError(
|
|
"unblob",
|
|
["/tmp/runtime"],
|
|
{ reason: "ownership uncertain" },
|
|
{ operation: "extract_firmware" },
|
|
);
|
|
const outcome = err(cleanup);
|
|
const finished = await finishFirmwareWorkspace(
|
|
{ path: "/tmp/runtime", close },
|
|
outcome,
|
|
"unblob",
|
|
request,
|
|
);
|
|
expect(close).not.toHaveBeenCalled();
|
|
expect(finished).toBe(outcome);
|
|
});
|
|
});
|