cli: extract run from mini package (#37737)

This commit is contained in:
Simon Klee
2026-07-19 11:11:03 +02:00
committed by GitHub
parent cf6e5b3604
commit 3f5ad8441f
15 changed files with 500 additions and 50 deletions
@@ -5,10 +5,13 @@
// an isolated test provider config under the fixture's temp home.
import { describe, expect } from "bun:test"
import { Effect } from "effect"
import path from "node:path"
import { reply } from "../../lib/llm-server"
import { cliIt } from "../../lib/cli-process"
import { testProviderConfig } from "../../lib/test-provider"
const opencodeRoot = path.resolve(import.meta.dir, "../../..")
describe("opencode run (non-interactive subprocess)", () => {
// Happy path: prompt completes, output reaches stdout, process exits 0.
// If this fails, all the others likely will too — debug here first.
@@ -367,9 +370,12 @@ describe("opencode run (non-interactive subprocess)", () => {
({ llm, opencode }) =>
Effect.gen(function* () {
yield* llm.text("variant response")
const result = yield* opencode.spawn(["run", "--model", "test/test-model", "--variant", "default", "use the model"], {
config: { ...testProviderConfig(llm.url), model: "test/test-model" },
})
const result = yield* opencode.spawn(
["run", "--model", "test/test-model", "--variant", "default", "use the model"],
{
config: { ...testProviderConfig(llm.url), model: "test/test-model" },
},
)
opencode.expectExit(result, 0)
expect(result.stdout).toBe("variant response\n")
@@ -382,7 +388,15 @@ describe("opencode run (non-interactive subprocess)", () => {
({ home, llm, opencode }) =>
Effect.gen(function* () {
const source = `${home}/image.png`
yield* Effect.promise(() => Bun.write(source, Buffer.from("iVBORw0KGgo=", "base64")))
yield* Effect.promise(() =>
Bun.write(
source,
Buffer.from(
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=",
"base64",
),
),
)
yield* llm.text("attachment received")
const config = testProviderConfig(llm.url)
config.provider.test.models["test-model"].attachment = true
@@ -395,7 +409,7 @@ describe("opencode run (non-interactive subprocess)", () => {
opencode.expectExit(result, 0)
const input = JSON.stringify(yield* llm.inputs)
expect(input).toContain("image/png")
expect(input).not.toContain("<file name=\\\"image.png\\\">")
expect(input).not.toContain('<file name=\\"image.png\\">')
}),
60_000,
)
@@ -422,6 +436,26 @@ describe("opencode run (non-interactive subprocess)", () => {
60_000,
)
cliIt.live(
"attach mode without --dir uses the remote server location",
({ home, llm, opencode }) =>
Effect.gen(function* () {
expect(home).not.toBe(opencodeRoot)
yield* llm.text("remote location used")
const server = yield* opencode.serve()
const result = yield* opencode.run("use the server location", {
extraArgs: ["--attach", server.url],
})
opencode.expectExit(result, 0)
const input = JSON.stringify(yield* llm.inputs)
expect(input).toContain(`Working directory: ${opencodeRoot}`)
expect(input).not.toContain(`Working directory: ${home}`)
}),
60_000,
)
cliIt.concurrent(
"attach mode rejects local directories before prompt admission",
({ home, opencode }) =>