fix(server): respect inherited OPENCODE_CONFIG_CONTENT (#4242)
Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: codex <[email protected]>
This commit is contained in:
2 files changed
+42
-1
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { resolveOpenCodeConfigContent } from "./opencodeRuntime.ts";
|
||||
|
||||
describe("resolveOpenCodeConfigContent", () => {
|
||||
it("prefers the caller environment over the inherited environment", () => {
|
||||
expect(
|
||||
resolveOpenCodeConfigContent(
|
||||
{ OPENCODE_CONFIG_CONTENT: '{"source":"caller"}' },
|
||||
{ OPENCODE_CONFIG_CONTENT: '{"source":"process"}' },
|
||||
),
|
||||
).toBe('{"source":"caller"}');
|
||||
});
|
||||
|
||||
it("falls back to the inherited environment and then an empty config", () => {
|
||||
expect(
|
||||
resolveOpenCodeConfigContent(undefined, {
|
||||
OPENCODE_CONFIG_CONTENT: '{"source":"process"}',
|
||||
}),
|
||||
).toBe('{"source":"process"}');
|
||||
expect(resolveOpenCodeConfigContent(undefined, {})).toBe("{}");
|
||||
});
|
||||
});
|
||||
@@ -37,6 +37,17 @@ import { resolveSpawnCommand } from "@t3tools/shared/shell";
|
||||
const encodeUnknownJsonStringExit = Schema.encodeUnknownExit(Schema.fromJsonString(Schema.Unknown));
|
||||
const OPENCODE_EMPTY_CONFIG_CONTENT = "{}";
|
||||
|
||||
export function resolveOpenCodeConfigContent(
|
||||
inputEnvironment: Readonly<Record<string, string | undefined>> | undefined,
|
||||
inheritedEnvironment: Readonly<Record<string, string | undefined>> = process.env,
|
||||
): string {
|
||||
return (
|
||||
inputEnvironment?.OPENCODE_CONFIG_CONTENT ??
|
||||
inheritedEnvironment.OPENCODE_CONFIG_CONTENT ??
|
||||
OPENCODE_EMPTY_CONFIG_CONTENT
|
||||
);
|
||||
}
|
||||
|
||||
const OPENCODE_SERVER_READY_PREFIX = "opencode server listening";
|
||||
const DEFAULT_OPENCODE_SERVER_TIMEOUT_MS = 30_000;
|
||||
const DEFAULT_HOSTNAME = "127.0.0.1";
|
||||
@@ -467,7 +478,14 @@ const makeOpenCodeRuntime = Effect.gen(function* () {
|
||||
shell: spawnCommand.shell,
|
||||
env: {
|
||||
...input.environment,
|
||||
OPENCODE_CONFIG_CONTENT: OPENCODE_EMPTY_CONFIG_CONTENT,
|
||||
// Respect an OPENCODE_CONFIG_CONTENT provided by the caller or
|
||||
// the inherited process environment, only falling back to the
|
||||
// empty config when neither is set. Setting it unconditionally
|
||||
// previously clobbered the user's opencode config, hiding their
|
||||
// providers/models. The value is set explicitly (rather than
|
||||
// relying on inheritance) because `extendEnv` is false whenever
|
||||
// `input.environment` is provided.
|
||||
OPENCODE_CONFIG_CONTENT: resolveOpenCodeConfigContent(input.environment),
|
||||
},
|
||||
extendEnv: input.environment === undefined,
|
||||
}),
|
||||
|
||||
Reference in new issue
Block a user