refactor(flags): move bash timeout to runtime flags (#27607)

This commit is contained in:
Shoubhit Dash
2026-05-15 02:49:14 +05:30
committed by GitHub
parent 34198f422c
commit f202226bbc
5 changed files with 64 additions and 5 deletions

View File

@@ -44,17 +44,49 @@ describe("RuntimeFlags", () => {
it.effect("layer accepts partial test overrides and fills defaults from Config definitions", () =>
Effect.gen(function* () {
const flags = yield* readFlags.pipe(Effect.provide(RuntimeFlags.layer({ disableDefaultPlugins: true })))
const flags = yield* readFlags.pipe(
Effect.provide(RuntimeFlags.layer({ disableDefaultPlugins: true, bashDefaultTimeoutMs: 1_000 })),
)
expect(flags.pure).toBe(false)
expect(flags.disableDefaultPlugins).toBe(true)
expect(flags.disableClaudeCodeSkills).toBe(false)
expect(flags.enableExa).toBe(false)
expect(flags.bashDefaultTimeoutMs).toBe(1_000)
expect(flags.enableExperimentalModels).toBe(false)
expect(flags.client).toBe("cli")
}),
)
for (const input of [
{ name: "absent", config: {}, expected: undefined },
{
name: "valid positive integer",
config: { OPENCODE_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS: "1234" },
expected: 1234,
},
{
name: "invalid string",
config: { OPENCODE_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS: "nope" },
expected: undefined,
},
{ name: "zero", config: { OPENCODE_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS: "0" }, expected: undefined },
{ name: "negative", config: { OPENCODE_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS: "-1" }, expected: undefined },
{
name: "non-integer",
config: { OPENCODE_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS: "1.5" },
expected: undefined,
},
]) {
it.effect(`parses bashDefaultTimeoutMs from config: ${input.name}`, () =>
Effect.gen(function* () {
const flags = yield* readFlags.pipe(Effect.provide(fromConfig(input.config)))
expect(flags.bashDefaultTimeoutMs).toBe(input.expected)
}),
)
}
it.effect("layer ignores the active ConfigProvider for omitted test overrides", () =>
Effect.gen(function* () {
const flags = yield* readFlags.pipe(
@@ -66,6 +98,7 @@ describe("RuntimeFlags", () => {
OPENCODE_DISABLE_DEFAULT_PLUGINS: "true",
OPENCODE_EXPERIMENTAL: "true",
OPENCODE_ENABLE_EXA: "true",
OPENCODE_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS: "1234",
OPENCODE_CLIENT: "desktop",
}),
),
@@ -76,6 +109,7 @@ describe("RuntimeFlags", () => {
expect(flags.disableDefaultPlugins).toBe(false)
expect(flags.disableClaudeCodeSkills).toBe(false)
expect(flags.enableExa).toBe(false)
expect(flags.bashDefaultTimeoutMs).toBeUndefined()
expect(flags.client).toBe("cli")
}),
)

View File

@@ -17,6 +17,7 @@ import { AppFileSystem } from "@opencode-ai/core/filesystem"
import { Plugin } from "../../src/plugin"
import { testEffect } from "../lib/effect"
import { Tool } from "@/tool/tool"
import { RuntimeFlags } from "@/effect/runtime-flags"
const shellLayer = Layer.mergeAll(
CrossSpawnSpawner.defaultLayer,
@@ -25,6 +26,7 @@ const shellLayer = Layer.mergeAll(
Truncate.defaultLayer,
Config.defaultLayer,
Agent.defaultLayer,
RuntimeFlags.defaultLayer,
)
const it = testEffect(shellLayer)
type ShellTestServices =
@@ -1077,6 +1079,23 @@ describe("tool.shell abort", () => {
15_000,
)
it.live(
"uses RuntimeFlags bashDefaultTimeoutMs when timeout is omitted",
() =>
runIn(
projectRoot,
Effect.gen(function* () {
const result = yield* run({
command: `echo started && sleep 60`,
description: "Default timeout test",
})
expect(result.output).toContain("started")
expect(result.output).toContain("exceeding timeout 500 ms")
}),
).pipe(Effect.provide(RuntimeFlags.layer({ bashDefaultTimeoutMs: 500 }))),
15_000,
)
if (process.platform !== "win32") {
it.live("captures stderr in output", () =>
runIn(