Skip to content

Commit 36cfa45

Browse files
author
Test User
committed
fix(desktop): require explicit prebuilt channel
Prebuilt CLI manifests do not record their channel. Reject missing OPENCODE_CHANNEL before preparing Desktop build resources.
1 parent 319538a commit 36cfa45

4 files changed

Lines changed: 25 additions & 11 deletions

File tree

‎packages/desktop/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ Both read the same environment as every other release package:
2323

2424
| Variable | Meaning |
2525
| ------------------ | --------------------------------------------------------------------------------------------------------------- |
26-
| `OPENCODE_CHANNEL` | `dev` (default), `beta`, or `latest`/`prod`. Picks the app identity, icons and bundled CLI. |
26+
| `OPENCODE_CHANNEL` | `dev` (download default), `beta`, or `latest`/`prod`. Picks the app identity, icons and bundled CLI. |
2727
| `OPENCODE_VERSION` | Version stamped into the app and its packages. |
2828
| `OPENCODE_TARGET` | `darwin-arm64`, `darwin-x64`, `windows-arm64`, `windows-x64`, `linux-x64`, `linux-arm64`. Defaults to the host. |
2929

30-
For a prebuilt CLI, build it and Desktop with the same `OPENCODE_CHANNEL`. `latest` and `prod` use the production
31-
app identity but separate service registrations.
30+
For a prebuilt CLI, set `OPENCODE_CHANNEL` explicitly to the channel used to build it. `latest` and `prod` use
31+
the production app identity but separate service registrations.
3232

3333
The CLI is placed outside `app.asar` in the application's resources directory, and packaging fails if it is missing.
3434
`bun run build` uses `packages/cli/dist` when that holds the target's CLI. Otherwise `dev` (and `local`, unset or unrecognized)

‎packages/desktop/script/build.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ const cli = path.resolve(dir, "../cli/dist")
1414

1515
const channel = resolveChannel()
1616

17-
process.chdir(dir)
18-
19-
await $`bun ./script/copy-icons.ts ${channel}`
20-
21-
await $`bun ./script/copy-metainfo.ts ${channel}`
22-
2317
const built = await exists(path.join(cli, getCurrentCli().package.replace("@opencode/", "")))
2418

2519
if (channel === "prod" && !built)
2620
throw new Error(`Production desktop builds bundle the CLI from ${cli}; build it first`)
2721

2822
const cliChannel = resolveCliChannel(built)
2923

24+
process.chdir(dir)
25+
26+
await $`bun ./script/copy-icons.ts ${channel}`
27+
28+
await $`bun ./script/copy-metainfo.ts ${channel}`
29+
3030
if (built) await copyBuiltCliToResources(cli)
3131

3232
if (!built) await downloadCliToResources(cliChannel)

‎packages/desktop/script/utils.test.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@ test.each([
55
{ channel: "preview-a", built: false, expected: "dev" },
66
{ channel: "preview-a", built: true, expected: "preview-a" },
77
{ channel: "beta", built: false, expected: "beta" },
8+
{ channel: undefined, built: false, expected: "dev" },
9+
{ channel: undefined, built: true, error: true },
10+
{ channel: "", built: true, error: true },
811
])("selects the bundled CLI channel for $channel (built=$built)", (input) => {
912
const previous = process.env.OPENCODE_CHANNEL
10-
process.env.OPENCODE_CHANNEL = input.channel
13+
if (input.channel === undefined) delete process.env.OPENCODE_CHANNEL
14+
else process.env.OPENCODE_CHANNEL = input.channel
1115

1216
try {
17+
if (input.error) {
18+
expect(() => resolveCliChannel(input.built)).toThrow(Error)
19+
return
20+
}
21+
1322
expect(resolveCliChannel(input.built)).toBe(input.expected)
1423
} finally {
1524
if (previous === undefined) delete process.env.OPENCODE_CHANNEL

‎packages/desktop/script/utils.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ export function resolveChannel(): Channel {
2020
}
2121

2222
export function resolveCliChannel(built: boolean) {
23-
return built ? process.env.OPENCODE_CHANNEL || "dev" : resolveChannel()
23+
if (!built) return resolveChannel()
24+
25+
const channel = process.env.OPENCODE_CHANNEL
26+
if (!channel) throw new Error("Set OPENCODE_CHANNEL to the channel used to build the prebuilt CLI")
27+
28+
return channel
2429
}
2530

2631
export const CLI_BINARIES: Array<{ target: string; package: string; os: string; cpu: string }> = [

0 commit comments

Comments
 (0)