Skip to content

Commit 1ef5916

Browse files
saravmajesticclaude
andcommitted
fix: establish ownership before acting; stop leaking diagnostics; correct package identities (#1305)
Three-model consensus review plus cubic/CodeRabbit found nine issues in the previous round, five of them introduced by this branch. Each was verified against the code first. **Bun global upgrades were refused outright.** `bun pm bin -g` reports the SHIM directory (~/.bun/bin) while packages live in a sibling tree (~/.bun/install/global/node_modules). The ownership check treated the shim dir as the package root, so the real executable was never "inside" it. `globalLayout()` now returns `packageRoot` and `writable` separately — ownership is decided against the package tree, permissions against what the upgrade writes. **Ownership is now established before any consumer receives an actionable identity.** A path match is a hypothesis: a project-local node_modules is shaped exactly like a global one. `Installation.method()` confirms it with the manager and downgrades to `unknown` when the running binary is not in that manager's global tree. This matters because `cli/cmd/uninstall.ts` acts on the answer destructively and never runs the upgrade preflight. It also stops us mutating the wrong tree when a different `npm` is first on PATH — its `npm root -g` will not contain our executable, so we refuse rather than upgrade someone else's install. **Containment was unsound in both directions.** The lowercased `startsWith` matched `/prefix/lib/node_modules-other` against `/prefix/lib/node_modules`, resolved symlinks on only one side, and mis-compared on case-sensitive filesystems. Replaced with a separator-aware `path.relative` check. Its own test then caught a further bug: resolving only paths that exist compares /var against /private/var, so `realpathOr` now resolves the deepest existing ancestor and re-appends the remainder. **Diagnostics are redacted before they reach any sink.** The previous round logged package-manager stdout/stderr verbatim, justified by the log file staying local. That was wrong: `Logging.loggers()` adds a stderr logger under OPENCODE_PRINT_LOGS=1, and `Otlp.loggers()` ships records to a remote collector when OTEL_EXPORTER_OTLP_ENDPOINT is set — neither redacts, and npm error output routinely carries registry `_authToken` values. The message also no longer promises a log artifact that an ERROR log level would discard. **scoop/choco no longer resolve to an actionable method.** `latest()`/`upgrade()` still query and install the upstream `opencode` package, so an Altimate install resolving to those methods would pull in a different package. The old probe loop self-limited by requiring `scoop list opencode` to match; path matching has no such guard. Notify-only until those commands carry Altimate identities. **`uninstall` targeted upstream packages.** It ran `npm uninstall -g opencode-ai` and `brew uninstall opencode`, able to remove an unrelated upstream install while leaving Altimate in place. Pre-existing, but widened by this branch. **`yarn` is rejected where it was unhandled.** `Installation.upgrade()` has no `yarn` case; `cli/upgrade.ts` already routed it to notify, but `cli/cmd/upgrade.ts` and the HTTP upgrade route guarded only `unknown` and would have surfaced an opaque failure. Also: narrowed the pnpm/yarn patterns to real layouts instead of any `pnpm`/`yarn` path segment; excluded `dlx` caches alongside npx; renamed `ResolvedInstall.root` to `binDir` with an accurate description of what it holds. **Tests.** A previous guard asserted `INSTALLATION_SRC.toContain(".local")` against the whole file, which cannot detect the regression it claims to prevent — `.local` appears in three nearby comments, so deleting the regex alternation left it green. It now asserts against the regex line, verified by simulating the removal and watching it fail. Added ownership/containment coverage for the bun layout, prefix-sibling rejection, symlinked parents, and non-existent paths. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent d0cac98 commit 1ef5916

7 files changed

Lines changed: 297 additions & 88 deletions

File tree

‎packages/opencode/src/cli/cmd/uninstall.ts‎

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,18 @@ async function showRemovalSummary(targets: RemovalTargets, method: Installation.
130130
}
131131

132132
if (method !== "curl" && method !== "unknown") {
133+
// altimate_change start — #1305: these targeted upstream's `opencode-ai` / `opencode`,
134+
// so an uninstall could remove an unrelated upstream package while leaving Altimate
135+
// installed. scoop/choco are omitted: Installation.method() no longer returns them
136+
// (their commands still reference upstream identities), so they are unreachable here.
133137
const cmds: Record<string, string> = {
134-
npm: "npm uninstall -g opencode-ai",
135-
pnpm: "pnpm uninstall -g opencode-ai",
136-
bun: "bun remove -g opencode-ai",
137-
yarn: "yarn global remove opencode-ai",
138-
brew: "brew uninstall opencode",
139-
choco: "choco uninstall opencode",
140-
scoop: "scoop uninstall opencode",
138+
npm: "npm uninstall -g @altimateai/altimate-code",
139+
pnpm: "pnpm uninstall -g @altimateai/altimate-code",
140+
bun: "bun remove -g @altimateai/altimate-code",
141+
yarn: "yarn global remove @altimateai/altimate-code",
142+
brew: "brew uninstall altimate-code",
141143
}
144+
// altimate_change end
142145
prompts.log.info(` ✓ Package: ${cmds[method] || method}`)
143146
}
144147
}
@@ -181,20 +184,20 @@ async function executeUninstall(method: Installation.Method, targets: RemovalTar
181184
}
182185

183186
if (method !== "curl" && method !== "unknown") {
187+
// altimate_change start — #1305: Altimate package identities, not upstream's.
184188
const cmds: Record<string, string[]> = {
185-
npm: ["npm", "uninstall", "-g", "opencode-ai"],
186-
pnpm: ["pnpm", "uninstall", "-g", "opencode-ai"],
187-
bun: ["bun", "remove", "-g", "opencode-ai"],
188-
yarn: ["yarn", "global", "remove", "opencode-ai"],
189-
brew: ["brew", "uninstall", "opencode"],
190-
choco: ["choco", "uninstall", "opencode"],
191-
scoop: ["scoop", "uninstall", "opencode"],
189+
npm: ["npm", "uninstall", "-g", "@altimateai/altimate-code"],
190+
pnpm: ["pnpm", "uninstall", "-g", "@altimateai/altimate-code"],
191+
bun: ["bun", "remove", "-g", "@altimateai/altimate-code"],
192+
yarn: ["yarn", "global", "remove", "@altimateai/altimate-code"],
193+
brew: ["brew", "uninstall", "altimate-code"],
192194
}
195+
// altimate_change end
193196

194197
const cmd = cmds[method]
195198
if (cmd) {
196199
spinner.start(`Running ${cmd.join(" ")}...`)
197-
const result = await Process.run(method === "choco" ? ["choco", "uninstall", "opencode", "-y", "-r"] : cmd, {
200+
const result = await Process.run(cmd, {
198201
nothrow: true,
199202
})
200203
if (result.code !== 0) {

‎packages/opencode/src/cli/cmd/upgrade.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ export const UpgradeCommand = {
4646
// altimate_change end
4747
const detectedMethod = await Installation.method()
4848
const method = (args.method as Installation.Method) ?? detectedMethod
49-
if (method === "unknown") {
49+
// altimate_change start — #1305: Installation.upgrade()'s switch has no `yarn` case, so
50+
// yarn reaches `default` and dies with "Unknown installation method: yarn". cli/upgrade.ts
51+
// already routes yarn to notify for the same reason; this is the explicit-command path.
52+
if (method === "unknown" || method === "yarn") {
53+
// altimate_change end
5054
// altimate_change start — branding
5155
prompts.log.error(`altimate is installed to ${process.execPath} and may be managed by a package manager`)
5256
// altimate_change end

0 commit comments

Comments
 (0)