Files
rea/tests/fixtures/hopperLaunchAdmission.mjs
T
4d98123279 fix(hopper): recover from a Spotlight not-found launch (#2795)
* fix(hopper): recover from a Spotlight not-found launch

Hopper's native launcher locates the application through a fixed Spotlight
query before any Apple event. With indexing disabled it exits 3 with a
not-found report, but REA treated the external document as unconfirmed,
retained the runtime and failed every later open_binary until the server
restarted. Recognize the complete report as a pre-handoff failure, confirm
no document exists, and tell the caller to enable Spotlight indexing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(hopper): require empty stdout for native launch signatures

* fix(hopper): retain ownership after unverified Spotlight reports

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
2026-10-14 06:08:31 +08:00

35 lines
1.5 KiB
JavaScript

import { readFile, writeFile } from "node:fs/promises";
// Model the native helper's external GUI handoff independently of its lifetime.
const [modePath, receiptPath] = process.argv.slice(2, 4);
const mode = await readFile(modePath, "utf8");
const bootstrapIndex = process.argv.indexOf("-Y") + 1;
if (bootstrapIndex === 0) throw new Error("Missing Hopper bootstrap argument");
const bootstrapPath = process.argv[bootstrapIndex];
await writeFile(receiptPath, bootstrapPath);
if (mode === "denied" || mode === "denied-after-handoff") {
process.stderr.write(
"Cannot launch Hopper!\nNot authorized to send Apple events to Hopper Disassembler.\n",
async () => {
if (mode === "denied-after-handoff") {
// A real native helper can create a document before emitting this same
// diagnostic when caller literals alter its AppleScript construction.
await writeFile(`${receiptPath}.document-created`, "unconfirmed");
}
process.exit(2);
},
);
} else if (mode === "not-found") {
// The native helper's Spotlight lookup fails before any Apple event.
process.stderr.write(
"Hopper has not been found.\nPlease make sure that Spotlight is active in order for this tool to find Hopper's executable.\n",
() => process.exit(3),
);
} else if (mode === "handoff") {
process.exit(0);
} else if (mode === "bridge") {
await import("./fakeLauncher.mjs");
} else {
throw new Error(`Unknown Hopper launch admission fixture mode: ${mode}`);
}