From 02f12b927a17615150d6e1126d1b841c5dca648b Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Wed, 15 Jul 2026 06:34:25 +0000 Subject: [PATCH] fix: address setup, upgrade, and process test regressions --- scripts/verify-package.mjs | 5 ++-- src/application/Setup.ts | 44 +++++++++++++++++++++++++++--------- src/application/Upgrade.ts | 3 +-- tests/processCapture.test.ts | 4 ++-- tests/setup.test.ts | 29 ++++++++++++++++++++++-- tests/setupConfig.test.ts | 6 +++++ 6 files changed, 72 insertions(+), 19 deletions(-) diff --git a/scripts/verify-package.mjs b/scripts/verify-package.mjs index c28fdee8a..65598341f 100644 --- a/scripts/verify-package.mjs +++ b/scripts/verify-package.mjs @@ -421,10 +421,11 @@ try { alignedExecution.status !== (status === "ready" ? 0 : 1) || aligned.plannedActions.length !== 0 || aligned.appliedActions.length !== 0 || - second.appliedActions.length !== 0 + !second.plannedActions.some(({ kind }) => kind === "install_hopper") || + !second.appliedActions.includes("installed_hopper") ) throw new Error( - `packaged setup was not ready and idempotent without confirmation: ${JSON.stringify({ first, aligned, second })}`, + `packaged setup did not preserve idempotent defaults and explicit Hopper reinstall behavior: ${JSON.stringify({ first, aligned, second })}`, ); for (const configPath of [claudeConfig, cursorConfig]) { const config = json(await readFile(configPath, "utf8")); diff --git a/src/application/Setup.ts b/src/application/Setup.ts index 80dc20b9d..4d06275d6 100644 --- a/src/application/Setup.ts +++ b/src/application/Setup.ts @@ -6,6 +6,7 @@ import { rm, writeFile, } from "node:fs/promises"; +import { constants as fsConstants } from "node:fs"; import { homedir } from "node:os"; import { dirname, resolve } from "node:path"; import { z } from "zod"; @@ -143,8 +144,13 @@ export const runSetup = async ( const unsupported = await hostRemediation(host); if (unsupported !== undefined) return fail(unsupported); let hopperPath = await host.hopperPath(); - const discovery = await discoverSetupActions(host, hopperPath); - const { detectedClients, installHopper, installSkill } = discovery; + const discovery = await discoverSetupActions( + host, + hopperPath, + options.installHopper, + ); + const { installHopper, installSkill } = discovery; + let { detectedClients } = discovery; plannedActions = discovery.plannedActions; let approved = options.approved || plannedActions.length === 0; let interactiveApproval = false; @@ -177,6 +183,12 @@ export const runSetup = async ( }; hopperPath = installed.launcherPath; appliedActions.push("installed_hopper"); + detectedClients = await filterClientsNeedingConfigure( + host, + detectedClients, + hopperPath, + registrationCommand(), + ); } const clientFailure = await configureDetectedClients({ host, @@ -215,6 +227,7 @@ export const runSetup = async ( const discoverSetupActions = async ( host: SetupHost, hopperPath: string | undefined, + forceHopperInstall: boolean, ) => { const initialDoctor = await host.doctor(); const linuxHopperRepairNeeded = initialDoctor.checks.some( @@ -223,7 +236,8 @@ const discoverSetupActions = async ( (name === "hopper-demo-runtime" || (name === "hopper-version" && detail === "/opt/hopper/bin/Hopper")), ); - const installHopper = hopperPath === undefined || linuxHopperRepairNeeded; + const installHopper = + forceHopperInstall || hopperPath === undefined || linuxHopperRepairNeeded; const [detectedClients, installSkill] = await Promise.all([ host.detectedClients(), host.skillNeedsInstall(), @@ -387,11 +401,8 @@ export const configureJsonClient = async ( let backupPath: string | undefined; if (original !== undefined) { backupPath = `${client.configPath}.rea.backup`; - try { - await copyFile(transactionPath, backupPath); - } catch { + if (!(await preserveConfigBackup(transactionPath, backupPath))) return { status: "failed", reason: "backup" }; - } } document.mcpServers = { ...servers, @@ -470,11 +481,11 @@ export const configureTomlClient = async ( return { status: "unchanged" }; const backupPath = original === undefined ? undefined : `${client.configPath}.rea.backup`; - try { - if (backupPath !== undefined) await copyFile(transactionPath, backupPath); - } catch { + if ( + backupPath !== undefined && + !(await preserveConfigBackup(transactionPath, backupPath)) + ) return { status: "failed", reason: "backup" }; - } document.mcp_servers = { ...servers, [PRODUCT_IDENTITY.mcpServerKey]: desired, @@ -516,6 +527,17 @@ const exists = async (path: string): Promise => { return false; } }; +const preserveConfigBackup = async ( + source: string, + destination: string, +): Promise => { + try { + await copyFile(source, destination, fsConstants.COPYFILE_EXCL); + return true; + } catch (cause: unknown) { + return cause instanceof Error && "code" in cause && cause.code === "EEXIST"; + } +}; const objectSchema = z.record(z.string(), z.unknown()); const parseOptionalObject = (value: unknown): Record => value === undefined ? {} : objectSchema.parse(value); diff --git a/src/application/Upgrade.ts b/src/application/Upgrade.ts index 756c5d5e4..f3d51abf3 100644 --- a/src/application/Upgrade.ts +++ b/src/application/Upgrade.ts @@ -208,8 +208,7 @@ const runCommand = ( ): Promise => new Promise((resolveResult) => { const child = spawn(command, [...arguments_], { - stdio: - output === "human" ? "inherit" : ["inherit", process.stderr, "inherit"], + stdio: output === "human" ? "inherit" : ["inherit", "ignore", "inherit"], }); child.once("error", () => resolveResult(false)); child.once("exit", (code) => resolveResult(code === 0)); diff --git a/tests/processCapture.test.ts b/tests/processCapture.test.ts index 6309d9c24..5d64a20e6 100644 --- a/tests/processCapture.test.ts +++ b/tests/processCapture.test.ts @@ -967,7 +967,7 @@ describe("process capture adapter", () => { } finally { await rm(root, { recursive: true, force: true }); } - }); + }, 20_000); it("does not follow or disclose symlink targets outside declared roots", async () => { const root = await mkdtemp(join(tmpdir(), "rea-symlink-test-")); @@ -1186,5 +1186,5 @@ describe("process capture adapter", () => { const { stdout } = await execFileAsync("ps", ["-axo", "command="]); expect(stdout).not.toContain(`${processFixture} tree-child`); expect(stdout).not.toContain(`${processFixture} tree-grandchild`); - }); + }, 20_000); }); diff --git a/tests/setup.test.ts b/tests/setup.test.ts index c3e1830aa..670c79912 100644 --- a/tests/setup.test.ts +++ b/tests/setup.test.ts @@ -24,6 +24,7 @@ class FakeSetupHost implements SetupHost { hopperInstalls = 0; configurations = 0; skillInstalls = 0; + checkedHopperPaths: Array = []; doctorHealthy: boolean | undefined; linuxDemoRuntimeMissing = false; unsupportedHopperVersion = false; @@ -63,10 +64,15 @@ class FakeSetupHost implements SetupHost { this.clientResults.get(client.name) ?? { status: "configured" }, ); }; - clientNeedsConfigure = (client: SetupClient): Promise => - Promise.resolve( + clientNeedsConfigure = ( + client: SetupClient, + hopperPath: string | undefined, + ): Promise => { + this.checkedHopperPaths.push(hopperPath); + return Promise.resolve( this.clientResults.get(client.name)?.status !== "unchanged", ); + }; skillNeedsInstall = (): Promise => Promise.resolve(this.skill !== "unchanged"); installSkill = (): Promise<"installed" | "unchanged" | "failed"> => { @@ -227,6 +233,25 @@ describe("setup workflow", () => { expect(host.hopperInstalls).toBe(0); }); + it("reinstalls existing Hopper when explicitly requested", async () => { + const host = new FakeSetupHost(); + host.hopper = "/Applications/Hopper"; + host.skill = "unchanged"; + host.clients = [{ name: "codex", configPath: "/codex.toml" }]; + host.clientResults.set("codex", { status: "unchanged" }); + + const result = await runSetup(options(true, true), host); + + expect(result.plannedActions.map(({ kind }) => kind)).toEqual([ + "install_hopper", + "configure_client", + ]); + expect(result.appliedActions).toEqual(["installed_hopper"]); + expect(host.hopperInstalls).toBe(1); + expect(host.configurations).toBe(0); + expect(host.checkedHopperPaths).toEqual(["/manual/Hopper"]); + }); + it("omits an aligned managed skill from an otherwise empty plan", async () => { const host = new FakeSetupHost(); host.hopper = "/Applications/Hopper"; diff --git a/tests/setupConfig.test.ts b/tests/setupConfig.test.ts index 9dd9516ed..292d05ddd 100644 --- a/tests/setupConfig.test.ts +++ b/tests/setupConfig.test.ts @@ -123,6 +123,8 @@ describe("JSON client configuration transaction", () => { const configPath = join(directory, "mcp.json"); const hopperPath = "/Applications/Hopper v6.app/Contents/MacOS/hopper"; const client = { name: "cursor", configPath }; + const original = "{}\n"; + await writeFile(configPath, original); expect(await configureJsonClient(client, hopperPath)).toMatchObject({ status: "configured", }); @@ -138,6 +140,10 @@ describe("JSON client configuration transaction", () => { expect(await configureJsonClient(client, hopperPath)).toEqual({ status: "unchanged", }); + expect( + await configureJsonClient(client, "/opt/hopper/bin/Hopper"), + ).toMatchObject({ status: "configured" }); + expect(await readFile(`${configPath}.rea.backup`, "utf8")).toBe(original); }); it("refuses malformed existing JSON without overwriting it", async () => {