mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 14:05:49 +00:00
fix(mcp): report target after failed open (#8613)
* fix(mcp): report target after failed open * test(session): cover failed open receipt ownership * test(session): verify restored target receipt * test(mcp): retain target on snapshot mismatch * test(mcp): retain oversized open failure receipts * test(cli): avoid continuing session receipt in one-shot errors * fix(mcp): report provider after failed switch * test(ghidra): verify failed open preserves annotations * test(mcp): join queued receipt request before cleanup * test(session): assert open failure receipts in lifecycle suites * test(session): keep open-failure receipt checks within function limits Move the provider-collision case and snapshot fixture setup out of the functions that grew when both failure receipts were asserted. --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
1 parent
3395c9e6b3
commit
56be61191e
17 files changed
+375
-43
No files matched your search
@@ -39,6 +39,7 @@ import type {
|
||||
OpenSelectionReceipt,
|
||||
SavedAnalysisSnapshot,
|
||||
} from "./BinarySessionPort.js";
|
||||
import { binaryTargetSummary } from "./BinaryTargetSummary.js";
|
||||
import {
|
||||
SessionProviderRouter,
|
||||
type SessionProviderRoute,
|
||||
@@ -537,9 +538,17 @@ export class BinarySession
|
||||
);
|
||||
};
|
||||
const result = await attempt();
|
||||
return result.ok
|
||||
? result
|
||||
: { ...result, selection: this.#openSelectionReceipt() };
|
||||
if (result.ok) return result;
|
||||
return {
|
||||
...result,
|
||||
selection: this.#openSelectionReceipt(),
|
||||
targetAtCompletion:
|
||||
this.#active === undefined
|
||||
? null
|
||||
: binaryTargetSummary(this.#active.target),
|
||||
providerIdAtCompletion:
|
||||
this.#active?.route.binding?.identity.id ?? null,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -137,6 +137,18 @@ it("opens a resource-only bundle without executable identity and keeps snapshot
|
||||
expect(session.allowsSnapshotReplay("inspect_plist")).toBe(false);
|
||||
expect(opened.value.executableSha256).toBeNull();
|
||||
expect(openedRoot).toBe(opened.value.canonicalPath);
|
||||
const rejectedBinary = await session.open(join(rootPath, "missing-binary"));
|
||||
if (rejectedBinary.ok) throw new Error("Expected a failed binary open");
|
||||
expect(rejectedBinary.targetAtCompletion).toBeNull();
|
||||
expect(rejectedBinary.providerIdAtCompletion).toBeNull();
|
||||
expect(rejectedBinary.selection).toEqual({
|
||||
kind: "resources",
|
||||
path: opened.value.canonicalPath,
|
||||
caller_path: opened.value.callerPath,
|
||||
});
|
||||
expect(session.activeBundleResourceRoot()?.canonicalPath).toBe(
|
||||
opened.value.canonicalPath,
|
||||
);
|
||||
expect(
|
||||
bundleResourceRootSchema.parse({
|
||||
caller_path: opened.value.callerPath,
|
||||
@@ -157,13 +169,6 @@ it("opens a resource-only bundle without executable identity and keeps snapshot
|
||||
session_kind: "bundle_resources",
|
||||
resource_root: { canonical_path: opened.value.canonicalPath },
|
||||
});
|
||||
const rejectedBinary = await session.open(join(rootPath, "missing-binary"));
|
||||
if (rejectedBinary.ok) throw new Error("Expected a missing binary refusal");
|
||||
expect(rejectedBinary.selection).toEqual({
|
||||
kind: "resources",
|
||||
path: opened.value.canonicalPath,
|
||||
caller_path: opened.value.callerPath,
|
||||
});
|
||||
const snapshot = session.exportAnalysisSnapshot();
|
||||
if (snapshot.ok)
|
||||
throw new Error("resource session exported a binary snapshot");
|
||||
|
||||
@@ -18,6 +18,7 @@ import type { EvidenceIntegrityError } from "../../domain/evidenceErrors.js";
|
||||
import type { AnalysisSnapshotLoader } from "./BinarySessionOpen.js";
|
||||
import type { WorkflowSnapshotRecordInput } from "./BinarySessionRecords.js";
|
||||
import type { ResolvedAppBundleResourceRoot } from "../AppBundleExecutable.js";
|
||||
import type { binaryTargetSummary } from "./BinaryTargetSummary.js";
|
||||
|
||||
import type {
|
||||
AnalysisExecution,
|
||||
@@ -40,12 +41,17 @@ export type OpenSelectionReceipt =
|
||||
}
|
||||
| { readonly kind: "none" };
|
||||
|
||||
/** A failure retains its original error and both selection receipts. */
|
||||
export type BinaryOpenResult =
|
||||
| { readonly ok: true; readonly value: BinaryTarget }
|
||||
| {
|
||||
readonly ok: false;
|
||||
readonly error: AnalysisError;
|
||||
readonly selection: OpenSelectionReceipt;
|
||||
readonly targetAtCompletion: ReturnType<
|
||||
typeof binaryTargetSummary
|
||||
> | null;
|
||||
readonly providerIdAtCompletion: string | null;
|
||||
};
|
||||
|
||||
/** Target lifecycle used by CLI and MCP without exposing a concrete provider. */
|
||||
|
||||
@@ -10,11 +10,85 @@ import { err, ok } from "../../domain/result.js";
|
||||
import { createAnalysisExecution } from "../AnalysisProvider.js";
|
||||
import { AnalysisProviderRegistry } from "./AnalysisProviderRegistry.js";
|
||||
import { BinarySession } from "./BinarySession.js";
|
||||
import { binaryTargetSummary } from "./BinaryTargetSummary.js";
|
||||
import {
|
||||
SessionProviderRouter,
|
||||
type SessionProviderRoute,
|
||||
} from "./SessionProviderRouter.js";
|
||||
|
||||
it("reports the previous selection after a failed switch restores its provider", async () => {
|
||||
const session = new BinarySession(
|
||||
SessionProviderRouter.selectable(new AnalysisProviderRegistry([]), []),
|
||||
);
|
||||
const identity = {
|
||||
id: "restoration-test",
|
||||
name: "Restoration test",
|
||||
version: "1",
|
||||
};
|
||||
const failure = new AnalysisOutputError(
|
||||
"health",
|
||||
"Selected target could not start",
|
||||
);
|
||||
let previousStarts = 0;
|
||||
let previousCloses = 0;
|
||||
let failedCloses = 0;
|
||||
const route: SessionProviderRoute = {
|
||||
identity,
|
||||
capabilities: new Map(),
|
||||
profile: createAnalysisProfile(identity, { fixture: "original" }),
|
||||
binding: null,
|
||||
selection: undefined,
|
||||
createClient: () => {
|
||||
previousStarts += 1;
|
||||
return {
|
||||
execute: async () => ok(createAnalysisExecution(null, identity)),
|
||||
close: async () => {
|
||||
previousCloses += 1;
|
||||
return ok(null);
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
try {
|
||||
const target = await session.resolveTarget(process.execPath);
|
||||
if (!target.ok) throw target.error;
|
||||
expect(
|
||||
(await session.openResolvedTarget({ target: target.value, route })).ok,
|
||||
).toBe(true);
|
||||
const result = await session.openResolvedTarget({
|
||||
target: target.value,
|
||||
route: {
|
||||
...route,
|
||||
profile: createAnalysisProfile(identity, { fixture: "selected" }),
|
||||
createClient: () => ({
|
||||
execute: async () => err(failure),
|
||||
close: async () => {
|
||||
failedCloses += 1;
|
||||
return ok(null);
|
||||
},
|
||||
}),
|
||||
},
|
||||
});
|
||||
if (result.ok) throw new Error("Expected failed switch");
|
||||
expect(result.error).toBe(failure);
|
||||
expect(result.targetAtCompletion).toEqual(
|
||||
binaryTargetSummary(target.value),
|
||||
);
|
||||
expect(session.activeTarget()).toEqual(target.value);
|
||||
expect({ previousStarts, previousCloses, failedCloses }).toEqual({
|
||||
previousStarts: 2,
|
||||
previousCloses: 1,
|
||||
failedCloses: 1,
|
||||
});
|
||||
expect((await session.close()).ok).toBe(true);
|
||||
expect(result.targetAtCompletion).toEqual(
|
||||
binaryTargetSummary(target.value),
|
||||
);
|
||||
} finally {
|
||||
await session.close();
|
||||
}
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ cancelled: false, cleanupFails: false },
|
||||
{ cancelled: true, cleanupFails: false },
|
||||
@@ -98,6 +172,8 @@ it.each([
|
||||
);
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) return;
|
||||
expect(result.targetAtCompletion).toBeNull();
|
||||
expect(result.providerIdAtCompletion).toBeNull();
|
||||
expect(result.selection).toEqual({ kind: "none" });
|
||||
expect(session.activeTarget()).toBeUndefined();
|
||||
expect(await session.status()).toMatchObject({
|
||||
@@ -113,6 +189,7 @@ it.each([
|
||||
});
|
||||
expect((await session.close()).ok).toBe(true);
|
||||
expect(restorationCloseCalls).toBe(cleanupFails ? 2 : 1);
|
||||
expect(result.targetAtCompletion).toBeNull();
|
||||
expect(await session.status()).toMatchObject({
|
||||
open: false,
|
||||
cleanup_pending: false,
|
||||
|
||||
Reference in new issue
Block a user