The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 03:00 UTC
fix(provider-core): pnpm-global updates approve the provider's build (#20796)
voida6 committed
Oct 19, 2026 at 07:03 UTC
a523b0036eb383faff1d7775ccd2e61f65dd43cd
2 files changed
+54
-22
packages/provider-core/src/server/maintenanceResolver.test.ts
+22
-8
@@ -549,18 +549,32 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => {
549
"package-tool",
550
]);
551
552
- const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(
553
- packageToolUpdate,
554
- {
552
+ const updateCommand = (spawner: ChildProcessSpawner.ChildProcessSpawner["Service"]) =>
553
+ resolveProviderMaintenanceCapabilitiesEffect(packageToolUpdate, {
554
binaryPath: link,
555
env: { PATH: "" },
557
- },
558
- ).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn));
559
-
560
- expect(capabilities.update).toMatchObject({
561
- command: "pnpm add -g @example/package-tool@latest",
556
+ }).pipe(
557
+ Effect.map((capabilities) => capabilities.update),
558
+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
559
+ );
560
+ const pnpmVersion = (version: string) =>
561
+ stdoutSpawner((command, args) => {
562
+ expect([command, ...args].join(" ")).toMatch(/pnpm(\.cmd)?"? --version$/);
563
+ return `${version}
564
+`;
565
+ });
566
+
567
+ expect(yield* updateCommand(pnpmVersion("11.1.3"))).toMatchObject({
568
+ command: "pnpm add -g --allow-build=@example/package-tool @example/package-tool@latest",
569
lockKey: "pnpm-global",
570
});
571
+ // Older pnpm rejects the unknown flag, and runs install scripts before 10.
572
+ expect((yield* updateCommand(pnpmVersion("10.3.0")))?.command).toBe(
573
+ "pnpm add -g @example/package-tool@latest",
574
+ );
575
+ expect((yield* updateCommand(noSpawn))?.command).toBe(
576
+ "pnpm add -g @example/package-tool@latest",
577
+ );
578
}),
579
);
580
packages/provider-core/src/server/maintenanceResolver.ts
+32
-14
@@ -11,10 +11,10 @@ import {
11
type ServerProvider,
12
type ServerProviderVersionAdvisory,
13
} from "@t3tools/contracts";
14
-import { compareSemverVersions } from "@t3tools/shared/semver";
14
+import { compareSemverVersions, satisfiesSemverRange } from "@t3tools/shared/semver";
15
import * as HostProcess from "@t3tools/shared/HostProcess";
16
import { causeErrorTag } from "@t3tools/shared/observability";
17
-import { resolveCommandPath } from "@t3tools/shared/shell";
17
+import { resolveCommandPath, resolveSpawnCommand } from "@t3tools/shared/shell";
18
import * as Cache from "effect/Cache";
19
import * as Config from "effect/Config";
20
import * as DateTime from "effect/DateTime";
@@ -34,8 +34,8 @@ import { collectUint8StreamText } from "./collectStreamText.ts";
34
import * as ProviderLatestVersions from "./ProviderLatestVersions.ts";
35
36
const LATEST_VERSION_TIMEOUT_MS = 4_000;
37
-const HOMEBREW_INFO_TIMEOUT_MS = 10_000;
38
-const HOMEBREW_INFO_MAX_BYTES = 256 * 1_024;
37
+const PROBE_TIMEOUT_MS = 10_000;
38
+const PROBE_MAX_BYTES = 256 * 1_024;
39
const MISE_WRAPPER_MAX_BYTES = 16 * 1_024;
40
const PROVIDER_UPDATE_ACTION_TOAST_MESSAGE = "Install the update now or review provider settings.";
41
@@ -310,19 +310,27 @@ export function parseHomebrewLatestVersion(
310
return version === "latest" ? null : version;
311
}
312
313
-const runHomebrew = Effect.fn("runHomebrew")(function* (
314
- brewPath: string,
313
+const runProbe = Effect.fn("runProbe")(function* (
314
+ command: string,
315
args: ReadonlyArray<string>,
316
env: NodeJS.ProcessEnv,
317
) {
318
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
319
const collect = Effect.gen(function* () {
320
- const child = yield* spawner.spawn(ChildProcess.make(brewPath, args, { env, extendEnv: true }));
320
+ // Windows package managers are `.cmd` shims that need the shell.
321
+ const resolved = yield* resolveSpawnCommand(command, args, { env, extendEnv: true });
322
+ const child = yield* spawner.spawn(
323
+ ChildProcess.make(resolved.command, resolved.args, {
324
+ env,
325
+ extendEnv: true,
326
+ shell: resolved.shell,
327
+ }),
328
+ );
329
yield* Effect.addFinalizer(() => child.kill().pipe(Effect.ignore));
322
- // stderr is drained so a chatty brew cannot block on a full pipe.
330
+ // stderr is drained so a chatty tool cannot block on a full pipe.
331
const [stdout, exitCode] = yield* Effect.all(
332
[
325
- collectUint8StreamText({ stream: child.stdout, maxBytes: HOMEBREW_INFO_MAX_BYTES }),
333
+ collectUint8StreamText({ stream: child.stdout, maxBytes: PROBE_MAX_BYTES }),
334
child.exitCode,
335
Stream.runDrain(child.stderr),
336
],
@@ -332,10 +340,11 @@ const runHomebrew = Effect.fn("runHomebrew")(function* (
340
});
341
return yield* collect.pipe(
342
Effect.scoped,
335
- Effect.timeoutOption(Duration.millis(HOMEBREW_INFO_TIMEOUT_MS)),
343
+ Effect.timeoutOption(Duration.millis(PROBE_TIMEOUT_MS)),
344
Effect.map(Option.getOrNull),
345
Effect.catchCause((cause) =>
338
- Effect.logWarning("Homebrew probe failed", {
346
+ Effect.logWarning("Maintenance probe failed", {
347
+ command,
348
subcommand: args[0],
349
errorTag: causeErrorTag(cause),
350
}).pipe(Effect.as(null)),
@@ -413,11 +422,20 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
422
});
423
}
424
if (commandPaths.some(isPnpmGlobalCommandPath)) {
425
+ // pnpm 10 skips unapproved install scripts and still exits 0, leaving a
426
+ // package whose postinstall finishes the install broken. Global installs
427
+ // can only approve on the command line, and pnpm before 10.4 rejects the
428
+ // flag as an unknown option.
429
+ const pnpmVersion = yield* runProbe("pnpm", ["--version"], context.env);
430
+ const allowBuild =
431
+ pnpmVersion !== null && satisfiesSemverRange(pnpmVersion, ">=10.4.0")
432
+ ? [`--allow-build=${packageName}`]
433
+ : [];
434
return makeProviderMaintenanceCapabilities({
435
provider: definition.provider,
436
packageName,
437
updateExecutable: "pnpm",
420
- updateArgs: ["add", "-g", `${packageName}@latest`],
438
+ updateArgs: ["add", "-g", ...allowBuild, `${packageName}@latest`],
439
updateLockKey: "pnpm-global",
440
});
441
}
@@ -488,7 +506,7 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
506
if (!brewPath) {
507
return fallback;
508
}
491
- const brewPrefix = nonEmptyString(yield* runHomebrew(brewPath, ["--prefix"], context.env));
509
+ const brewPrefix = nonEmptyString(yield* runProbe(brewPath, ["--prefix"], context.env));
510
const realBrewPrefix = brewPrefix
511
? yield* fileSystem.realPath(brewPrefix).pipe(Effect.orElseSucceed(() => brewPrefix))
512
: null;
@@ -502,7 +520,7 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
520
homebrew.kind === "cask" ? ["upgrade", "--cask", homebrew.name] : ["upgrade", homebrew.name];
521
// Homebrew lags npm by hours on every release, so compare against what
522
// `brew upgrade` can actually deliver.
505
- const info = yield* runHomebrew(brewPath, ["info", "--json=v2", homebrew.name], context.env);
523
+ const info = yield* runProbe(brewPath, ["info", "--json=v2", homebrew.name], context.env);
524
return makeProviderMaintenanceCapabilities({
525
provider: definition.provider,
526
packageName,