Skip to content

Commit 11635eb

Browse files
juliusmarmingecodex
andcommitted
test(server): cover OpenCode config precedence
Co-authored-by: codex <[email protected]>
1 parent 7d0858e commit 11635eb

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
3+
import { resolveOpenCodeConfigContent } from "./opencodeRuntime.ts";
4+
5+
describe("resolveOpenCodeConfigContent", () => {
6+
it("prefers the caller environment over the inherited environment", () => {
7+
expect(
8+
resolveOpenCodeConfigContent(
9+
{ OPENCODE_CONFIG_CONTENT: '{"source":"caller"}' },
10+
{ OPENCODE_CONFIG_CONTENT: '{"source":"process"}' },
11+
),
12+
).toBe('{"source":"caller"}');
13+
});
14+
15+
it("falls back to the inherited environment and then an empty config", () => {
16+
expect(
17+
resolveOpenCodeConfigContent(undefined, {
18+
OPENCODE_CONFIG_CONTENT: '{"source":"process"}',
19+
}),
20+
).toBe('{"source":"process"}');
21+
expect(resolveOpenCodeConfigContent(undefined, {})).toBe("{}");
22+
});
23+
});

‎apps/server/src/provider/opencodeRuntime.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ import { resolveSpawnCommand } from "@t3tools/shared/shell";
3737
const encodeUnknownJsonStringExit = Schema.encodeUnknownExit(Schema.fromJsonString(Schema.Unknown));
3838
const OPENCODE_EMPTY_CONFIG_CONTENT = "{}";
3939

40+
export function resolveOpenCodeConfigContent(
41+
inputEnvironment: Readonly<Record<string, string | undefined>> | undefined,
42+
inheritedEnvironment: Readonly<Record<string, string | undefined>> = process.env,
43+
): string {
44+
return (
45+
inputEnvironment?.OPENCODE_CONFIG_CONTENT ??
46+
inheritedEnvironment.OPENCODE_CONFIG_CONTENT ??
47+
OPENCODE_EMPTY_CONFIG_CONTENT
48+
);
49+
}
50+
4051
const OPENCODE_SERVER_READY_PREFIX = "opencode server listening";
4152
const DEFAULT_OPENCODE_SERVER_TIMEOUT_MS = 30_000;
4253
const DEFAULT_HOSTNAME = "127.0.0.1";
@@ -474,10 +485,7 @@ const makeOpenCodeRuntime = Effect.gen(function* () {
474485
// providers/models. The value is set explicitly (rather than
475486
// relying on inheritance) because `extendEnv` is false whenever
476487
// `input.environment` is provided.
477-
OPENCODE_CONFIG_CONTENT:
478-
input.environment?.OPENCODE_CONFIG_CONTENT ??
479-
process.env.OPENCODE_CONFIG_CONTENT ??
480-
OPENCODE_EMPTY_CONFIG_CONTENT,
488+
OPENCODE_CONFIG_CONTENT: resolveOpenCodeConfigContent(input.environment),
481489
},
482490
extendEnv: input.environment === undefined,
483491
}),

0 commit comments

Comments
 (0)