GeezerVison is showing github.com — fix(keyring): target-platform path rules for packaged addon candidate… · lidge-jun/opencodex@540af24
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/lib/keyring-native.ts +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import { existsSync } from "node:fs"; |
2 | 2 | import { createRequire } from "node:module"; |
3 | | -import { basename, dirname, join, resolve } from "node:path"; |
| 3 | +import { posix, win32 } from "node:path"; |
4 | 4 | import { isStandaloneBinary, standaloneRoot } from "./standalone"; |
5 | 5 |
|
6 | 6 | export interface KeyringBinding { |
@@ -74,6 +74,9 @@ export function packagedKeyringCandidates({ |
74 | 74 | if (root === undefined) return []; |
75 | 75 | const asset = runtimeAsset(platform, arch); |
76 | 76 | if (!asset) return []; |
| 77 | + // Paths follow the target platform's rules rather than the host's, so a candidate list is the |
| 78 | + // same whether it is computed on that platform or simulated from another one. |
| 79 | + const { basename, dirname, join, resolve } = platform === "win32" ? win32 : posix; |
77 | 80 | const executableDir = resolve(root); |
78 | 81 | const adjacent = join(executableDir, "keyring", asset.filename); |
79 | 82 | if (platform === "linux") { |
|
Collapse file
Copy file name to clipboardExpand all lines: tests/ci-workflows/keyring-smoke.test.ts +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -199,6 +199,13 @@ describe("packaged keyring native binding", () => { |
199 | 199 | .toEqual(["/opt/ocx/keyring/keyring.linux-x64-gnu.node"]); |
200 | 200 | }); |
201 | 201 |
|
| 202 | + test("candidate paths follow the target platform's rules on any host", () => { |
| 203 | + expect(packagedKeyringCandidates({ root: "C:\\Program Files\\OpenCodex", platform: "win32", arch: "x64" })) |
| 204 | + .toEqual(["C:\\Program Files\\OpenCodex\\keyring\\keyring.win32-x64-msvc.node"]); |
| 205 | + expect(packagedKeyringCandidates({ root: "/opt/ocx", platform: "linux", arch: "x64" })) |
| 206 | + .toEqual(["/opt/ocx/keyring/keyring.linux-x64-gnu.node"]); |
| 207 | + }); |
| 208 | + |
202 | 209 | test("loads only an existing deterministic packaged path and never consults cwd", () => { |
203 | 210 | const binding = { Entry: class {}, AsyncEntry: class {} } as unknown as KeyringBinding; |
204 | 211 | const calls: string[] = []; |
|