-
Notifications
You must be signed in to change notification settings - Fork 134
fix: resolve the install from the running binary; make upgrade failures diagnosable (#1305) #1306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
saravmajestic
wants to merge
1
commit into
main
Choose a base branch
from
fix/install-detection-and-upgrade-diagnostics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+422
−128
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
packages/opencode/test/installation/resolve-install.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /** | ||
| * Install resolution (#1305). | ||
| * | ||
| * `resolveInstall()` answers "which install produced THIS process", replacing a | ||
| * substring test on execPath plus a probe loop that asked each package manager | ||
| * whether it had the package at all. The second question picks arbitrarily when more | ||
| * than one install exists, which is the common case once a user has tried both the | ||
| * curl installer and npm. | ||
| * | ||
| * These cases are table-driven over fabricated paths because the real layouts cannot | ||
| * be created on a test machine. | ||
| */ | ||
| import { describe, test, expect } from "bun:test" | ||
| import { resolveInstall, type Method } from "../../src/installation" | ||
|
|
||
| const NPM_PREFIXED = "/usr/local/lib/node_modules/@altimateai/altimate-code" | ||
| const PLATFORM = "node_modules/@altimateai/altimate-code-darwin-arm64/bin/altimate-code" | ||
|
|
||
| describe("resolveInstall", () => { | ||
| const cases: Array<[string, string, Method]> = [ | ||
| // The npm bin/altimate shim spawns the PLATFORM package, so execPath is the nested | ||
| // platform binary rather than the wrapper — detection must match the -<os>-<arch> suffix. | ||
| ["npm, default prefix", `${NPM_PREFIXED}/${PLATFORM}`, "npm"], | ||
| // Regression: this is the layout the old `.local/bin` rule misread as "curl", which | ||
| // made `altimate upgrade` run `curl | bash` and orphan the npm install. | ||
| [ | ||
| "npm, prefix set to ~/.local", | ||
| "/home/u/.local/lib/node_modules/@altimateai/altimate-code/node_modules/@altimateai/altimate-code-linux-x64/bin/altimate-code", | ||
| "npm", | ||
| ], | ||
| [ | ||
| "pnpm, virtual store layout", | ||
| "/home/u/.local/share/pnpm/global/5/.pnpm/@altimateai+altimate-code@0.11.2/node_modules/@altimateai/altimate-code-linux-x64/bin/altimate-code", | ||
| "pnpm", | ||
| ], | ||
| [ | ||
| "pnpm, plain global link layout", | ||
| "/home/u/.local/share/pnpm/global/5/node_modules/@altimateai/altimate-code-linux-x64/bin/altimate-code", | ||
| "pnpm", | ||
| ], | ||
| [ | ||
| "bun global", | ||
| "/home/u/.bun/install/global/node_modules/@altimateai/altimate-code-linux-x64/bin/altimate-code", | ||
| "bun", | ||
| ], | ||
| ["yarn global", "/home/u/.yarn/global/node_modules/@altimateai/altimate-code-linux-x64/bin/altimate-code", "yarn"], | ||
| // Homebrew bin entries are symlinks into Cellar; realpath lands there. Matching the | ||
| // Cellar segment (not the prefix) keeps /usr/local from colliding with npm. | ||
| ["brew, apple silicon", "/opt/homebrew/Cellar/altimate-code/0.11.2/bin/altimate", "brew"], | ||
| ["brew, intel prefix", "/usr/local/Cellar/altimate-code/0.11.2/bin/altimate", "brew"], | ||
| ["standalone install", "/home/u/.altimate/bin/altimate", "curl"], | ||
| ["standalone, pre-v0.7.1 dir", "/home/u/.opencode/bin/altimate", "curl"], | ||
| ["scoop", "C:\\Users\\u\\scoop\\apps\\altimate-code\\current\\altimate.exe", "scoop"], | ||
| ["choco", "C:\\ProgramData\\chocolatey\\lib\\altimate-code\\tools\\altimate.exe", "choco"], | ||
| // A dev build or an unrecognised location must not be attributed to a package | ||
| // manager — "unknown" degrades to notify-only rather than running someone else's | ||
| // installer over it. | ||
| ["dev build", "/tmp/build/dist/altimate", "unknown"], | ||
| ] | ||
|
|
||
| for (const [name, execPath, expected] of cases) { | ||
| test(`${name} -> ${expected}`, () => { | ||
| expect(resolveInstall(execPath, {}).method).toBe(expected) | ||
| }) | ||
| } | ||
|
|
||
| test("a pinned ALTIMATE_CODE_BIN_PATH is never attributed to an installer", () => { | ||
| // The shim honours this ahead of everything else, so the running binary is whatever | ||
| // the user pointed at. Auto-upgrading it would overwrite a deliberate choice. | ||
| const env = { ALTIMATE_CODE_BIN_PATH: "/somewhere/custom/altimate" } | ||
| expect(resolveInstall(`${NPM_PREFIXED}/${PLATFORM}`, env).method).toBe("unknown") | ||
| }) | ||
|
|
||
| test("standalone resolution reports the directory the upgrade would write", () => { | ||
| expect(resolveInstall("/home/u/.altimate/bin/altimate", {}).root).toBe("/home/u/.altimate/bin") | ||
| }) | ||
|
|
||
| test("a plain user bin directory is not a standalone install", () => { | ||
| // `.local/bin` on its own carries no information about who installed the binary. | ||
| expect(resolveInstall("/home/u/.local/bin/altimate", {}).method).toBe("unknown") | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: The claimed brand guard does not actually scan the detection implementation. The
segmentwindow (line 59 toexport interface ResolvedInstall, line 78) covers only the regex-constant header, and themethodBlockwindow only covers themethod()wrapper that callsresolveInstall(). Detection logic now lives inresolveInstall()'s body (lines 88-108), which neithernot.toContain("opencode-ai")assertion covers. Extend the slice end marker so the resolvere body is included, so a stale upstream package-name path reintroduced inside the resolver is caught as the comment promises.Prompt for AI agents