Skip to content

Commit a5f1c51

Browse files
authored
fix(provider): expand a leading ~ in GROK_HOME for provider and terminal spawns (pingdotgg#32560)
Signed-off-by: Yordis Prieto <[email protected]>
1 parent 1f6d9e7 commit a5f1c51

5 files changed

Lines changed: 32 additions & 8 deletions

File tree

‎apps/server/src/terminal/Manager.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,6 +1990,20 @@ it.layer(
19901990
}),
19911991
);
19921992

1993+
it.effect("expands a provider home named in any case on Windows", () =>
1994+
Effect.gen(function* () {
1995+
const path = yield* Path.Path;
1996+
const home = yield* HostProcess.HomeDirectory;
1997+
const { manager, ptyAdapter } = yield* createManager(5, {
1998+
env: { GROK_HOME: "C:\\inherited-grok" },
1999+
});
2000+
2001+
yield* manager.open(openInput({ env: { grok_home: "~/.grok-work" } }));
2002+
2003+
expect(ptyAdapter.spawnInputs[0]?.env.GROK_HOME).toBe(path.join(home, ".grok-work"));
2004+
}).pipe(Effect.provide(layerWithHostPlatform("win32"))),
2005+
);
2006+
19932007
it.effect("fails closed when a provider instance is missing", () =>
19942008
Effect.gen(function* () {
19952009
const providerInstanceId = ProviderInstanceId.make("deleted_instance");

‎apps/server/src/terminal/Manager.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ import { makeClaudeEnvironment } from "../provider/Drivers/ClaudeHome.ts";
7070
import { deriveProviderInstanceConfigMap } from "../provider/ProviderInstanceRegistryHydration.ts";
7171
import * as ServerSettings from "../serverSettings.ts";
7272
import { increment, terminalSessionsTotal } from "../observability/Metrics.ts";
73-
import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion";
73+
import { expandHomeVariable } from "@t3tools/provider-core/server/pathExpansion";
7474
import * as ProcessRunner from "../processRunner.ts";
7575
import * as PortScanner from "../preview/PortScanner.ts";
7676
import * as NativeTelemetryClient from "../resourceTelemetry/NativeTelemetryClient.ts";
@@ -1380,8 +1380,11 @@ function createTerminalSpawnEnv(
13801380
platform === "win32"
13811381
? Object.keys(spawnEnv).find((candidate) => candidate.toLowerCase() === key.toLowerCase())
13821382
: undefined;
1383-
spawnEnv[existingKey ?? key] =
1384-
key === "CODEX_HOME" || key === "CLAUDE_CONFIG_DIR" ? expandHomePath(value, home) : value;
1383+
spawnEnv[existingKey ?? key] = expandHomeVariable(
1384+
platform === "win32" ? key.toUpperCase() : key,
1385+
value,
1386+
home,
1387+
);
13851388
}
13861389
}
13871390
if (!spawnEnv.COLORTERM && runtimeEnv?.COLORTERM === undefined) {

‎packages/provider-core/src/server/instanceEnvironment.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ describe("mergeProviderInstanceEnvironment", () => {
1717
const baseEnv = {
1818
CODEX_HOME: "~/.inherited-codex",
1919
CLAUDE_CONFIG_DIR: "~/.inherited-claude",
20+
GROK_HOME: "~/.inherited-grok",
2021
};
2122
const environment = yield* mergeProviderInstanceEnvironment(
2223
[
2324
{ name: "CODEX_HOME", value, sensitive: false },
2425
{ name: "CLAUDE_CONFIG_DIR", value, sensitive: false },
26+
{ name: "GROK_HOME", value, sensitive: false },
2527
{ name: "CUSTOM_VALUE", value, sensitive: false },
2628
],
2729
baseEnv,
@@ -30,11 +32,13 @@ describe("mergeProviderInstanceEnvironment", () => {
3032
expect(environment).toEqual({
3133
CODEX_HOME: path.join("/home/ada", tail),
3234
CLAUDE_CONFIG_DIR: path.join("/home/ada", tail),
35+
GROK_HOME: path.join("/home/ada", tail),
3336
CUSTOM_VALUE: value,
3437
});
3538
expect(baseEnv).toEqual({
3639
CODEX_HOME: "~/.inherited-codex",
3740
CLAUDE_CONFIG_DIR: "~/.inherited-claude",
41+
GROK_HOME: "~/.inherited-grok",
3842
});
3943
}).pipe(
4044
Effect.provideService(HostProcess.HomeDirectory, "/home/ada"),

‎packages/provider-core/src/server/instanceEnvironment.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ProviderInstanceEnvironment } from "@t3tools/contracts";
22
import * as HostProcess from "@t3tools/shared/HostProcess";
33
import * as Effect from "effect/Effect";
44

5-
import { expandHomePath } from "./pathExpansion.ts";
5+
import { expandHomeVariable } from "./pathExpansion.ts";
66

77
export const mergeProviderInstanceEnvironment = Effect.fn(function* (
88
environment: ProviderInstanceEnvironment | undefined,
@@ -27,10 +27,7 @@ export const mergeProviderInstanceEnvironment = Effect.fn(function* (
2727
if (inherited.toUpperCase() === name) delete next[inherited];
2828
}
2929
}
30-
next[name] =
31-
name === "CODEX_HOME" || name === "CLAUDE_CONFIG_DIR"
32-
? expandHomePath(variable.value, home)
33-
: variable.value;
30+
next[name] = expandHomeVariable(name, variable.value, home);
3431
}
3532
return next;
3633
});

‎packages/provider-core/src/server/pathExpansion.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ export function expandHomePath(value: string, home: string): string {
1010
}
1111
return value;
1212
}
13+
14+
const HOME_PATH_VARIABLES = new Set(["CODEX_HOME", "CLAUDE_CONFIG_DIR", "GROK_HOME"]);
15+
16+
export function expandHomeVariable(name: string, value: string, home: string): string {
17+
return HOME_PATH_VARIABLES.has(name) ? expandHomePath(value, home) : value;
18+
}

0 commit comments

Comments
 (0)