Repository navigation
Commit 1ef5916
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
- installation
- server/routes
- test
- installation
- install
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
133 | 137 | | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
141 | 143 | | |
| 144 | + | |
142 | 145 | | |
143 | 146 | | |
144 | 147 | | |
| |||
181 | 184 | | |
182 | 185 | | |
183 | 186 | | |
| 187 | + | |
184 | 188 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
192 | 194 | | |
| 195 | + | |
193 | 196 | | |
194 | 197 | | |
195 | 198 | | |
196 | 199 | | |
197 | | - | |
| 200 | + | |
198 | 201 | | |
199 | 202 | | |
200 | 203 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
50 | 54 | | |
51 | 55 | | |
52 | 56 | | |
| |||
0 commit comments