fix(hopper): recover provenance-verified Spotlight exits

Verify the native helper's sealed identifier and pinned Apple signing team in BridgeLauncher, then carry that provenance to HopperClient. Only a verified native helper's complete not-found exit confirms no document handoff, allowing runtime and target-lease cleanup and retry; wrappers retain unknown document state.

Share publisher identity with setup through the domain contract. Correct fixture teardown ordering and parameterized MCP coverage. Validation: 54 focused tests passed across boundary, CLI, MCP acceptance, diagnostics and installer coverage (one Linux-only case skipped); check:fast passed. Real codesign verification accepted the installed official Hopper helper; Spotlight failures and bridge recovery used process fixtures.
This commit is contained in:
morluto
2026-10-14 06:19:47 +08:00
parent 4d98123279
commit 4acda94b76
13 changed files with 286 additions and 112 deletions
@@ -1,6 +1,6 @@
import { chmod, copyFile, rm } from "node:fs/promises";
import { describe, expect, onTestFinished } from "vitest";
import { describe, expect } from "vitest";
import { z } from "zod";
import { workspaceCliTest } from "../../support/cli/workspaceCliFixture.js";
@@ -39,7 +39,57 @@ describe("Hopper launcher failure through the one-shot CLI", () => {
const targetPath = workspace.path("probe");
await copyFile("/usr/bin/true", targetPath);
const loaderArgs = ["--probe"];
onTestFinished(async () => {
try {
for (const attempt of ["first", "retry"]) {
const result = await cli.run({
arguments: [
"analyze",
targetPath,
"--provider",
"hopper",
"--json",
],
environment: {
...workspace.environment,
HOPPER_LAUNCHER_PATH: launcherPath,
HOPPER_LOADER_ARGS_JSON: JSON.stringify(loaderArgs),
REA_LOG_LEVEL: "silent",
},
timeoutMs: 45_000,
});
const retained = RetainedRuntime.safeParse(result.json);
if (retained.success)
await rm(
retained.data.details.diagnostics.cleanup_error.details
.diagnostics.runtime_root,
{ recursive: true, force: true },
);
expect(result.exitCode, attempt).toBe(1);
expect(result.json, attempt).toMatchObject({
code: "cleanup_incomplete",
details: {
cleanup: "incomplete",
diagnostics: {
primary_error: {
code: "provider_unavailable",
details: {
stage: "launch",
launcher: {
exit_code: 2,
stderr: {
text: expect.stringContaining(
"Document state is unknown",
),
},
},
},
},
},
},
});
}
} finally {
const recovered = await acquireHopperTargetLease({
targetPath,
targetKind: "executable",
@@ -48,50 +98,6 @@ describe("Hopper launcher failure through the one-shot CLI", () => {
});
expect(recovered.acquired).toBe(true);
if (recovered.acquired) await recovered.lease.release();
});
for (const attempt of ["first", "retry"]) {
const result = await cli.run({
arguments: ["analyze", targetPath, "--provider", "hopper", "--json"],
environment: {
...workspace.environment,
HOPPER_LAUNCHER_PATH: launcherPath,
HOPPER_LOADER_ARGS_JSON: JSON.stringify(loaderArgs),
REA_LOG_LEVEL: "silent",
},
timeoutMs: 45_000,
});
const retained = RetainedRuntime.safeParse(result.json);
if (retained.success)
await rm(
retained.data.details.diagnostics.cleanup_error.details.diagnostics
.runtime_root,
{ recursive: true, force: true },
);
expect(result.exitCode, attempt).toBe(1);
expect(result.json, attempt).toMatchObject({
code: "cleanup_incomplete",
details: {
cleanup: "incomplete",
diagnostics: {
primary_error: {
code: "provider_unavailable",
details: {
stage: "launch",
launcher: {
exit_code: 2,
stderr: {
text: expect.stringContaining(
"Document state is unknown",
),
},
},
},
},
},
},
});
}
},
);