Skip to content

Commit e0ae1d7

Browse files
committed
Preserve effective Codex home during updates
1 parent 4c9c792 commit e0ae1d7

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

‎apps/server/src/provider/Drivers/CodexDriver.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export const CodexDriver: ProviderDriver<CodexSettings, CodexDriverEnv> = {
161161
const legacyMaintenanceCapabilities = maintenanceResolution.capabilities;
162162
const maintenanceEnvironment = makeCodexMaintenanceEnvironment({
163163
environment: processEnv,
164+
effectiveHomePath: effectiveConfig.homePath || null,
164165
realExecutablePath:
165166
maintenanceResolution.realCommandPath ?? maintenanceResolution.resolvedCommandPath,
166167
sharedHomePath: homeLayout.sharedHomePath,

‎apps/server/src/provider/codexMaintenance.test.ts‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ describe("codexMaintenance", () => {
136136
};
137137
expect(
138138
makeCodexMaintenanceEnvironment({
139-
environment,
139+
environment: { PATH: environment.PATH },
140+
effectiveHomePath: environment.CODEX_HOME,
140141
realExecutablePath: "/home/test/.codex/packages/standalone/releases/0.129.0/codex",
141142
sharedHomePath: "/home/test/.codex",
142143
}),
@@ -146,14 +147,33 @@ describe("codexMaintenance", () => {
146147
});
147148
});
148149

149-
it("does not override CODEX_HOME for non-standalone installations", () => {
150+
it("uses the effective instance home for non-standalone updates", () => {
150151
const environment = {
152+
PATH: "/test/bin",
153+
CODEX_HOME: "/unrelated/server/codex-home",
154+
};
155+
expect(
156+
makeCodexMaintenanceEnvironment({
157+
environment,
158+
effectiveHomePath: "/home/test/.codex-work",
159+
realExecutablePath: "/opt/homebrew/bin/codex",
160+
sharedHomePath: "/home/test/.codex",
161+
}),
162+
).toEqual({
151163
PATH: "/test/bin",
152164
CODEX_HOME: "/home/test/.codex-work",
165+
});
166+
});
167+
168+
it("preserves the provider environment when no home path is configured", () => {
169+
const environment = {
170+
PATH: "/test/bin",
171+
CODEX_HOME: "/provider/environment/codex-home",
153172
};
154173
expect(
155174
makeCodexMaintenanceEnvironment({
156175
environment,
176+
effectiveHomePath: null,
157177
realExecutablePath: "/opt/homebrew/bin/codex",
158178
sharedHomePath: "/home/test/.codex",
159179
}),

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,27 @@ const LEGACY_ONLY_UPDATE_EXECUTABLES = new Set(["pnpm", "vp"]);
1313

1414
export function makeCodexMaintenanceEnvironment(input: {
1515
readonly environment: NodeJS.ProcessEnv;
16+
readonly effectiveHomePath: string | null;
1617
readonly realExecutablePath: string | null;
1718
readonly sharedHomePath: string;
1819
}): NodeJS.ProcessEnv {
20+
const environment = input.effectiveHomePath
21+
? {
22+
...input.environment,
23+
CODEX_HOME: input.effectiveHomePath,
24+
}
25+
: input.environment;
1926
if (!input.realExecutablePath) {
20-
return input.environment;
27+
return environment;
2128
}
2229
const executablePath = normalizeCommandPath(input.realExecutablePath);
2330
const sharedHomePath = normalizeCommandPath(input.sharedHomePath).replace(/\/+$/, "");
2431
const standaloneReleasesPath = `${sharedHomePath}/packages/standalone/releases/`;
2532
if (!executablePath.startsWith(standaloneReleasesPath)) {
26-
return input.environment;
33+
return environment;
2734
}
2835
return {
29-
...input.environment,
36+
...environment,
3037
CODEX_HOME: input.sharedHomePath,
3138
};
3239
}

0 commit comments

Comments
 (0)