@devries-cameron20 / t3code-1 / commits / 8eb1a5eb2b
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(provider-grok): grok update targets the GROK_HOME that owns binaryPath (#37918)

Julius Marminge committed Nov 16, 2026 at 22:13 UTC 8eb1a5eb2bf6284441df2ba08c53d46f43c53cfd
2 files changed +72 -1
packages/provider-grok/src/server/driver.test.ts
+53
@@ -172,6 +172,59 @@ it.layer(layerTest)("GrokDriver", (it) => {
172 });
173 }
174
175 + // `grok update` installs into `$GROK_HOME/bin`, so an instance GROK_HOME that does not own
176 + // binaryPath would update a different copy and leave the verified binary outdated.
177 + // `target` is where `bin/grok` links; null is a copied binary, as the Windows installer leaves.
178 + const scriptInstallCases = [
179 + { target: "grok-1.0.77", downloads: false, owner: ".grok" },
180 + { target: "../downloads/grok-linux-x86_64", downloads: true, owner: ".grok" },
181 + { target: "../downloads/grok-1.0.88-linux-x86_64", downloads: true, owner: ".grok" },
182 + { target: null, downloads: true, owner: ".grok" },
183 + { target: null, downloads: false, owner: ".grok-hub" },
184 + ] as const;
185 + for (const { target, downloads, owner } of scriptInstallCases) {
186 + it.effect.skipIf(windowsHost)(
187 + `runs grok update with GROK_HOME=${owner} for bin/grok -> ${target ?? "copy"}${downloads ? " beside downloads" : ""}`,
188 + () =>
189 + Effect.gen(function* () {
190 + const fs = yield* FileSystem.FileSystem;
191 + const path = yield* Path.Path;
192 + const home = yield* fs.realPath(
193 + yield* fs.makeTempDirectoryScoped({ prefix: "t3-grok-home-" }),
194 + );
195 + const scriptHome = path.join(home, ".grok");
196 + const binaryPath = path.join(scriptHome, "bin", "grok");
197 + const targetPath = path.resolve(path.dirname(binaryPath), target ?? "grok");
198 + yield* fs.makeDirectory(path.dirname(binaryPath), { recursive: true });
199 + if (downloads) {
200 + yield* fs.makeDirectory(path.join(scriptHome, "downloads"), { recursive: true });
201 + }
202 + yield* fs.writeFileString(targetPath, "#!/bin/sh\n");
203 + yield* fs.chmod(targetPath, 0o755);
204 + if (target) yield* fs.symlink(target, binaryPath);
205 +
206 + const instance = yield* GrokDriver.create({
207 + instanceId: ProviderInstanceId.make("grok-separate-home"),
208 + displayName: "Grok test",
209 + enabled: false,
210 + environment: [
211 + { name: "GROK_HOME", value: path.join(home, ".grok-hub"), sensitive: false },
212 + ],
213 + config: { ...GrokDriver.defaultConfig(), binaryPath },
214 + });
215 + const { update } = yield* instance.snapshot.resolveMaintenance();
216 +
217 + expect(update).toEqual(
218 + expect.objectContaining({
219 + executable: binaryPath,
220 + args: ["update"],
221 + env: expect.objectContaining({ GROK_HOME: path.join(home, owner) }),
222 + }),
223 + );
224 + }).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawner)),
225 + );
226 + }
227 +
228 // An `npx t3` server inherits npm_config_user_agent, which Grok ranks above `[cli] installer`.
229 it.effect.skipIf(windowsHost)("keeps a script install off the npm updater under npx", () =>
230 Effect.gen(function* () {
packages/provider-grok/src/server/driver.ts
+19 -1
@@ -51,7 +51,6 @@ const decodeGrokSettings = Schema.decodeSync(GrokSettings);
51 const DRIVER_KIND = ProviderDriverKind.make("grok");
52 // npm latest matches the stable channel installed by grok update.
53 const GROK_NPM_PACKAGE = "@xai-official/grok";
54 -// `grok update` installs under `GROK_HOME` from the resolved executable and instance environment.
54 // npm 12 blocks the postinstall that moves the new binary in, yet exits 0, so allow it by env.
55 // Mise and Homebrew casks upgrade through their manager; `grok update` would install a second
56 // copy, so a cask its brew cannot vouch for stays manual, as does a Nix store install.
@@ -92,6 +91,24 @@ const UPDATE: ProviderMaintenanceCapabilitiesResolver = {
91 })
92 );
93 }
94 + const path = yield* Path.Path;
95 + const fileSystem = yield* FileSystem.FileSystem;
96 + const name = path.basename(context.realCommandPath).toLowerCase();
97 + const installDir = path.dirname(context.realCommandPath);
98 + const installDirName = path.basename(installDir).toLowerCase();
99 + const home = path.dirname(installDir);
100 + // `grok update` installs under `$GROK_HOME`, so a script install keeps its own home even if the
101 + // instance sets another: `<home>/bin/grok` links into `<home>/downloads`, or on Windows is a copy
102 + // beside it. Only an install script creates `downloads`, so a bare `bin/grok` elsewhere is not one.
103 + const isScriptInstall =
104 + (installDirName === "downloads" && name.startsWith("grok-")) ||
105 + (installDirName === "bin" &&
106 + (/^grok-\d/.test(name) ||
107 + ((name === "grok" || name === "grok.exe") &&
108 + (yield* fileSystem
109 + .exists(path.join(home, "downloads"))
110 + .pipe(Effect.orElseSucceed(() => false))))));
111 + const scriptHome = isScriptInstall ? { GROK_HOME: home } : {};
112 return makeProviderMaintenanceCapabilities({
113 provider: DRIVER_KIND,
114 packageName: GROK_NPM_PACKAGE,
@@ -101,6 +118,7 @@ const UPDATE: ProviderMaintenanceCapabilitiesResolver = {
118 platform: context.platform,
119 env: {
120 ...context.env,
121 + ...scriptHome,
122 npm_config_allow_scripts: GROK_NPM_PACKAGE,
123 // An npx-launched server's npm_config_user_agent outranks Grok's `[cli] installer`, steering
124 // a script install to npm. The runner extends process.env; only undefined removes a key.