Skip to content

Commit f0bba10

Browse files
authored
fix(e2e): fail fast on config dependency installs (anomalyco#17280)
1 parent d961981 commit f0bba10

5 files changed

Lines changed: 40 additions & 16 deletions

File tree

packages/app/script/e2e-local.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const serverEnv = {
7373
OPENCODE_E2E_MESSAGE: "Seeded for UI e2e",
7474
OPENCODE_E2E_MODEL: "opencode/gpt-5-nano",
7575
OPENCODE_CLIENT: "app",
76+
OPENCODE_STRICT_CONFIG_DEPS: "true",
7677
} satisfies Record<string, string>
7778

7879
const runnerEnv = {

packages/opencode/script/seed-e2e.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,20 @@ const now = Date.now()
1010
const seed = async () => {
1111
const { Instance } = await import("../src/project/instance")
1212
const { InstanceBootstrap } = await import("../src/project/bootstrap")
13+
const { Config } = await import("../src/config/config")
1314
const { Session } = await import("../src/session")
1415
const { MessageID, PartID } = await import("../src/session/schema")
1516
const { Project } = await import("../src/project/project")
1617
const { ModelID, ProviderID } = await import("../src/provider/schema")
18+
const { ToolRegistry } = await import("../src/tool/registry")
1719

1820
await Instance.provide({
1921
directory: dir,
2022
init: InstanceBootstrap,
2123
fn: async () => {
24+
await Config.waitForDependencies()
25+
await ToolRegistry.ids()
26+
2227
const session = await Session.create({ title })
2328
const messageID = MessageID.ascending()
2429
const partID = PartID.ascending()

packages/opencode/src/bun/index.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Log } from "../util/log"
44
import path from "path"
55
import { Filesystem } from "../util/filesystem"
66
import { NamedError } from "@opencode-ai/util/error"
7-
import { text } from "node:stream/consumers"
87
import { Lock } from "../util/lock"
98
import { PackageRegistry } from "./registry"
109
import { proxied } from "@/util/proxied"
@@ -13,32 +12,29 @@ import { Process } from "../util/process"
1312
export namespace BunProc {
1413
const log = Log.create({ service: "bun" })
1514

16-
export async function run(cmd: string[], options?: Process.Options) {
15+
export async function run(cmd: string[], options?: Process.RunOptions) {
16+
const full = [which(), ...cmd]
1717
log.info("running", {
18-
cmd: [which(), ...cmd],
18+
cmd: full,
1919
...options,
2020
})
21-
const result = Process.spawn([which(), ...cmd], {
22-
...options,
23-
stdout: "pipe",
24-
stderr: "pipe",
21+
const result = await Process.run(full, {
22+
cwd: options?.cwd,
23+
abort: options?.abort,
24+
kill: options?.kill,
25+
timeout: options?.timeout,
26+
nothrow: options?.nothrow,
2527
env: {
2628
...process.env,
2729
...options?.env,
2830
BUN_BE_BUN: "1",
2931
},
3032
})
31-
const code = await result.exited
32-
const stdout = result.stdout ? await text(result.stdout) : undefined
33-
const stderr = result.stderr ? await text(result.stderr) : undefined
3433
log.info("done", {
35-
code,
36-
stdout,
37-
stderr,
34+
code: result.code,
35+
stdout: result.stdout.toString(),
36+
stderr: result.stderr.toString(),
3837
})
39-
if (code !== 0) {
40-
throw new Error(`Command failed with exit code ${code}`)
41-
}
4238
return result
4339
}
4440

packages/opencode/src/config/config.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { iife } from "@/util/iife"
3636
import { Account } from "@/account"
3737
import { ConfigPaths } from "./paths"
3838
import { Filesystem } from "@/util/filesystem"
39+
import { Process } from "@/util/process"
3940

4041
export namespace Config {
4142
const ModelId = z.string().meta({ $ref: "https://models.dev/model-schema.json#/$defs/Model" })
@@ -296,6 +297,26 @@ export namespace Config {
296297
],
297298
{ cwd: dir },
298299
).catch((err) => {
300+
if (err instanceof Process.RunFailedError) {
301+
const detail = {
302+
dir,
303+
cmd: err.cmd,
304+
code: err.code,
305+
stdout: err.stdout.toString(),
306+
stderr: err.stderr.toString(),
307+
}
308+
if (Flag.OPENCODE_STRICT_CONFIG_DEPS) {
309+
log.error("failed to install dependencies", detail)
310+
throw err
311+
}
312+
log.warn("failed to install dependencies", detail)
313+
return
314+
}
315+
316+
if (Flag.OPENCODE_STRICT_CONFIG_DEPS) {
317+
log.error("failed to install dependencies", { dir, error: err })
318+
throw err
319+
}
299320
log.warn("failed to install dependencies", { dir, error: err })
300321
})
301322
}

packages/opencode/src/flag/flag.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export namespace Flag {
6363
export const OPENCODE_MODELS_PATH = process.env["OPENCODE_MODELS_PATH"]
6464
export const OPENCODE_DISABLE_CHANNEL_DB = truthy("OPENCODE_DISABLE_CHANNEL_DB")
6565
export const OPENCODE_SKIP_MIGRATIONS = truthy("OPENCODE_SKIP_MIGRATIONS")
66+
export const OPENCODE_STRICT_CONFIG_DEPS = truthy("OPENCODE_STRICT_CONFIG_DEPS")
6667

6768
function number(key: string) {
6869
const value = process.env[key]

0 commit comments

Comments
 (0)