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 21, 16:00 UTC
fix(server): npm provider updates only offer versions npm will install (#24062)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Craig Davison committed
Nov 14, 2026 at 16:38 UTC
d2bdd58eef0410f08de0cfd1e48de51c6893acd0
4 files changed
+226
-57
apps/server/src/provider/Drivers/ClaudeMaintenance.test.ts
+47
-7
@@ -24,6 +24,8 @@ import * as Stream from "effect/Stream";
24
import * as TestClock from "effect/testing/TestClock";
25
import * as HttpClient from "effect/http/HttpClient";
26
import * as HttpClientResponse from "effect/http/HttpClientResponse";
27
+import * as Sink from "effect/Sink";
28
+import * as ChildProcess from "effect/process/ChildProcess";
29
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
30
import { makeClaudeMaintenanceResolution } from "./ClaudeMaintenance.ts";
31
@@ -77,6 +79,13 @@ const fixture = Effect.fn("ClaudeMaintenance.test.fixture")(function* (
79
: platform === "darwin"
80
? "/Library/Application Support/ClaudeCode"
81
: "/etc/claude-code";
82
+ const npmPath = path.join(directory, "bin/npm");
83
+ if (install === "npm") {
84
+ yield* fs.makeDirectory(path.dirname(npmPath), { recursive: true });
85
+ yield* fs.writeFileString(npmPath, "#!/bin/sh\n");
86
+ yield* fs.chmod(npmPath, 0o755);
87
+ }
88
+ const npmProbes: Array<ReadonlyArray<string>> = [];
89
let installationReads = 0;
90
const testFs = FileSystem.makeNoop({
91
...fs,
@@ -105,11 +114,37 @@ const fixture = Effect.fn("ClaudeMaintenance.test.fixture")(function* (
114
managed,
115
managedDirectory,
116
settingsPath,
117
+ npmProbes,
118
installationReads: () => installationReads,
109
- makeResolution: makeClaudeMaintenanceResolution({ binaryPath, env: { PATH: "" } }).pipe(
119
+ makeResolution: makeClaudeMaintenanceResolution({
120
+ binaryPath,
121
+ env: { PATH: install === "npm" ? path.dirname(npmPath) : "" },
122
+ }).pipe(
123
Effect.provideService(
124
ChildProcessSpawner.ChildProcessSpawner,
112
- ChildProcessSpawner.make(() => Effect.die("version checks must not run a subprocess")),
125
+ ChildProcessSpawner.make((command) => {
126
+ if (!ChildProcess.isStandardCommand(command) || command.command !== npmPath) {
127
+ return Effect.die("version checks may only ask npm");
128
+ }
129
+ npmProbes.push(command.args.map(String));
130
+ return Effect.succeed(
131
+ ChildProcessSpawner.makeHandle({
132
+ pid: ChildProcessSpawner.ProcessId(1),
133
+ exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(1)),
134
+ isRunning: Effect.succeed(false),
135
+ kill: () => Effect.void,
136
+ unref: Effect.succeed(Effect.void),
137
+ stdin: Sink.drain,
138
+ stdout: Stream.encodeText(
139
+ Stream.make(JSON.stringify({ "@anthropic-ai/claude-code": { latest: "2.1.316" } })),
140
+ ),
141
+ stderr: Stream.empty,
142
+ all: Stream.empty,
143
+ getInputFd: () => Sink.drain,
144
+ getOutputFd: () => Stream.empty,
145
+ }),
146
+ );
147
+ }),
148
),
149
Effect.provideService(FileSystem.FileSystem, testFs),
150
Effect.provideService(HostProcess.Platform, platform),
@@ -233,12 +268,17 @@ it.layer(NodeServices.layer)("ClaudeMaintenance", (it) => {
268
status: row.advisory,
269
latestVersion: row.expected,
270
});
236
- expect(requests).toHaveLength(1);
237
- expect(requests[0]).toMatch(
238
- row.npm ? /registry\.npmjs\.org/ : new RegExp(`claude-code-releases/${row.channel}$`),
239
- );
271
+ // npm installs ask `npm outdated`, which applies npm's release-age settings.
272
+ const lookups = row.npm ? f.npmProbes : requests;
273
+ expect(lookups).toHaveLength(1);
274
+ if (row.npm) {
275
+ expect(requests).toEqual([]);
276
+ expect(f.npmProbes[0]?.[0]).toBe("outdated");
277
+ } else {
278
+ expect(requests[0]).toMatch(new RegExp(`claude-code-releases/${row.channel}$`));
279
+ }
280
yield* enrich;
241
- expect(requests).toHaveLength(1);
281
+ expect(lookups).toHaveLength(1);
282
}),
283
);
284
apps/server/src/provider/Drivers/CodexDriver.test.ts
+14
-5
@@ -729,6 +729,7 @@ it.layer(layerTest)("CodexDriver", (it) => {
729
const shimDir = NodePath.join(tempDir, fixture.dataRoot, "shims");
730
const npmPrefix = NodePath.join(tempDir, "mise", "installs", "node", "24.13.0");
731
const npmBin = NodePath.join(npmPrefix, "bin");
732
+ const npmPath = NodePath.join(npmBin, "npm");
733
const npmEntry = NodePath.join(
734
npmPrefix,
735
"lib",
@@ -738,7 +739,7 @@ it.layer(layerTest)("CodexDriver", (it) => {
739
"bin",
740
"codex.js",
741
);
741
- for (const file of [brewPath, misePath, npmEntry]) {
742
+ for (const file of [brewPath, misePath, npmPath, npmEntry]) {
743
yield* fs.makeDirectory(NodePath.dirname(file), { recursive: true });
744
yield* fs.writeFileString(file, "#!/bin/sh\n");
745
yield* fs.chmod(file, 0o755);
@@ -753,12 +754,20 @@ it.layer(layerTest)("CodexDriver", (it) => {
754
].join(NodePath.delimiter);
755
const probes: Array<ReadonlyArray<string>> = [];
756
const metadataSpawner = ChildProcessSpawner.make((command) => {
756
- if (!ChildProcess.isStandardCommand(command) || command.command !== brewPath) {
757
+ const isNpmOutdated =
758
+ ChildProcess.isStandardCommand(command) &&
759
+ command.command === npmPath &&
760
+ command.args[0] === "outdated";
761
+ if (
762
+ !ChildProcess.isStandardCommand(command) ||
763
+ (command.command !== brewPath && !isNpmOutdated)
764
+ ) {
765
return Effect.die("Provider resolution must not execute a provider or updater");
766
}
759
- probes.push(command.args.map(String));
760
- const stdout =
761
- command.args[0] === "--prefix"
767
+ if (!isNpmOutdated) probes.push(command.args.map(String));
768
+ const stdout = isNpmOutdated
769
+ ? JSON.stringify({ "@openai/codex": { latest: "0.153.4" } })
770
+ : command.args[0] === "--prefix"
771
? brewPrefix
772
: JSON.stringify({ formulae: [{ versions: { stable: "2026.9.1" } }] });
773
return Effect.succeed(
packages/provider-core/src/server/maintenanceResolver.test.ts
+102
-16
@@ -356,12 +356,11 @@ it.layer(
356
),
357
);
358
359
+ // npm-global installs ask `npm outdated` instead; see the npm-global cases below.
360
it.effect.each([
361
{ install: "native", stdout: '"1.2.0"', exitCode: 0, latest: "1.2.0" },
362
{ install: "manual", stdout: '["1.2.0"]', exitCode: 0, latest: "1.2.0" },
362
- { install: "npm", stdout: '"1.2.0"', exitCode: 0, latest: "1.2.0" },
363
{ install: "native", stdout: "", exitCode: 1, latest: null },
364
- { install: "npm", stdout: '"1.2.0"', exitCode: 1, latest: null },
364
{ install: "native", stdout: "not json", exitCode: 0, latest: null },
365
{ install: "manual", stdout: '["1.2.0", "1.3.0"]', exitCode: 0, latest: null },
366
{ install: "manual", stdout: '""', exitCode: 0, latest: null },
@@ -372,20 +371,12 @@ it.layer(
371
const tempDir = yield* makeTempDir("t3-registry-version");
372
const npmBinDir = NodePath.join(tempDir, "npm-bin");
373
writeExecutable(NodePath.join(npmBinDir, "npm"));
375
- const binaryPath =
376
- fixture.install === "npm"
377
- ? linkIntoPackage(tempDir, "package-tool", [
378
- "lib",
379
- "node_modules",
380
- "@example",
381
- "package-tool",
382
- ])
383
- : NodePath.join(tempDir, ".local/bin/native-package-tool");
384
- if (fixture.install !== "npm") writeExecutable(binaryPath);
374
+ const binaryPath = NodePath.join(tempDir, ".local/bin/native-package-tool");
375
+ writeExecutable(binaryPath);
376
let probes = 0;
377
const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(
378
fixture.install === "native" ? nativePackageToolUpdate : packageToolUpdate,
388
- { binaryPath, env: { PATH: fixture.install === "npm" ? npmBinDir : "" } },
379
+ { binaryPath, env: { PATH: "" } },
380
).pipe(
381
Effect.provideService(HostProcess.Environment, { PATH: npmBinDir }),
382
Effect.provideService(
@@ -397,7 +388,6 @@ it.layer(
388
expect(args).toEqual([
389
"view",
390
"--global",
400
- ...(fixture.install === "npm" ? ["--prefix", tempDir] : []),
391
"--json",
392
`${capabilities.packageName}@latest`,
393
"version",
@@ -540,7 +530,7 @@ it.layer(
530
ChildProcessSpawner.ChildProcessSpawner,
531
stdoutSpawner(() => {
532
probes++;
543
- return JSON.stringify(version);
533
+ return JSON.stringify({ "@example/package-tool": { latest: version } });
534
}),
535
),
536
Effect.tap((capabilities) =>
@@ -596,7 +586,7 @@ it.layer(
586
expect(advisoryFor(pnpmTool, "1.1.0-beta.1")).toBe(
587
"pnpm add -g --allow-build=@example/package-tool @example/package-tool@latest",
588
);
599
- // Only pnpm's minimumReleaseAge skips fresh releases; npm keeps @latest.
589
+ // npm keeps @latest; its outdated probe already reports what that resolves to.
590
expect(
591
advisoryFor(
592
makeProviderMaintenanceCapabilities({
@@ -710,6 +700,9 @@ it.layer(
700
expect(capabilities).toEqual({
701
provider: driver("packageTool"),
702
packageName: "@example/package-tool",
703
+ latestVersion: null,
704
+ lookupLatestVersion: expect.anything(),
705
+ latestVersionCacheKey: expect.any(String),
706
update: {
707
command: `npm install -g --prefix ${tempDir} --allow-scripts=@example/package-tool @example/package-tool@latest`,
708
executable: "npm",
@@ -1424,6 +1417,99 @@ it.layer(
1417
{ skip: !symlinksSupported || windowsHost },
1418
);
1419
1420
+ it.effect.each([
1421
+ {
1422
+ case: "the eligible release",
1423
+ outdated: { "@example/package-tool": { current: "1.0.0", wanted: "1.1.0", latest: "1.1.0" } },
1424
+ exitCode: 1,
1425
+ status: "behind_latest",
1426
+ latestVersion: "1.1.0",
1427
+ },
1428
+ {
1429
+ case: "no update during cooldown",
1430
+ outdated: {},
1431
+ exitCode: 0,
1432
+ status: "current",
1433
+ latestVersion: "1.0.0",
1434
+ },
1435
+ {
1436
+ case: "no update during cooldown beside a broken global",
1437
+ outdated: {},
1438
+ exitCode: 0,
1439
+ listExitCode: 1,
1440
+ status: "current",
1441
+ latestVersion: "1.0.0",
1442
+ },
1443
+ {
1444
+ case: "no registry version when npm cannot reach the registry",
1445
+ outdated: { error: { code: "ECONNREFUSED" } },
1446
+ exitCode: 1,
1447
+ status: "unknown",
1448
+ latestVersion: null,
1449
+ },
1450
+ ])(
1451
+ "advertises $case for npm-global installs",
1452
+ (fixture) =>
1453
+ Effect.gen(function* () {
1454
+ const tempDir = yield* makeTempDir("t3-npm-latest");
1455
+ const npmBinDir = NodePath.join(tempDir, "npm-bin");
1456
+ const npmPath = NodePath.join(npmBinDir, "npm");
1457
+ writeExecutable(npmPath);
1458
+ const link = linkIntoPackage(tempDir, "package-tool", [
1459
+ "lib",
1460
+ "node_modules",
1461
+ "@example",
1462
+ "package-tool",
1463
+ ]);
1464
+
1465
+ const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(
1466
+ packageToolUpdate,
1467
+ { binaryPath: link, env: { PATH: npmBinDir } },
1468
+ ).pipe(
1469
+ // The updater's npm comes from the provider's PATH.
1470
+ Effect.provideService(HostProcess.Environment, { PATH: "" }),
1471
+ Effect.provideService(
1472
+ ChildProcessSpawner.ChildProcessSpawner,
1473
+ stdoutSpawner(
1474
+ (command, args) => {
1475
+ expect(command).toBe(npmPath);
1476
+ expect(args.slice(1, 4)).toEqual(["-g", "--prefix", tempDir]);
1477
+ return JSON.stringify(
1478
+ args[0] === "outdated"
1479
+ ? fixture.outdated
1480
+ : {
1481
+ dependencies: { "@example/package-tool": { version: "1.0.0" } },
1482
+ },
1483
+ );
1484
+ },
1485
+ (args) => (args[0] === "outdated" ? fixture.exitCode : (fixture.listExitCode ?? 0)),
1486
+ ),
1487
+ ),
1488
+ );
1489
+
1490
+ const provider = yield* enrichProviderSnapshotWithVersionAdvisory(
1491
+ installedPackageToolProvider,
1492
+ capabilities,
1493
+ ).pipe(
1494
+ Effect.provideServiceEffect(
1495
+ ProviderLatestVersions.ProviderLatestVersions,
1496
+ ProviderLatestVersions.make([["@example/package-tool", "9.9.9"]]),
1497
+ ),
1498
+ Effect.provideService(
1499
+ HttpClient.HttpClient,
1500
+ HttpClient.make(() => Effect.die("the npm version is already cached")),
1501
+ ),
1502
+ );
1503
+ expect(provider.versionAdvisory).toMatchObject({
1504
+ status: fixture.status,
1505
+ currentVersion: "1.0.0",
1506
+ latestVersion: fixture.latestVersion,
1507
+ updateCommand: expect.stringMatching(/@example\/package-tool@latest$/),
1508
+ });
1509
+ }),
1510
+ { skip: !symlinksSupported || windowsHost },
1511
+ );
1512
+
1513
it.effect.each([
1514
{
1515
case: "the eligible release under minimumReleaseAge",
packages/provider-core/src/server/maintenanceResolver.ts
+63
-29
@@ -431,24 +431,22 @@ const runProbe = Effect.fn("runProbe")(function* (
431
);
432
});
433
434
-const decodePnpmOutdated = Schema.decodeUnknownOption(
434
+const decodeOutdated = Schema.decodeUnknownOption(
435
Schema.fromJsonString(
436
Schema.Record(Schema.String, Schema.Struct({ latest: Schema.optional(Schema.String) })),
437
),
438
);
439
-const decodePnpmList = Schema.decodeUnknownOption(
440
- Schema.fromJsonString(
441
- Schema.Array(
442
- Schema.Struct({
443
- dependencies: Schema.optional(
444
- Schema.Record(Schema.String, Schema.Struct({ version: Schema.optional(Schema.String) })),
445
- ),
446
- }),
447
- ),
439
+const GlobalPackageList = Schema.Struct({
440
+ dependencies: Schema.optional(
441
+ Schema.Record(Schema.String, Schema.Struct({ version: Schema.optional(Schema.String) })),
442
),
443
+});
444
+const decodePnpmList = Schema.decodeUnknownOption(
445
+ Schema.fromJsonString(Schema.Array(GlobalPackageList)),
446
);
447
+const decodeNpmList = Schema.decodeUnknownOption(Schema.fromJsonString(GlobalPackageList));
448
451
-// Unlike npm's latest tag, pnpm outdated respects minimumReleaseAge and its excludes.
449
+// Unlike the registry's latest tag, pnpm outdated respects minimumReleaseAge and its excludes.
450
const resolvePnpmGlobalLatestVersion = Effect.fn("resolvePnpmGlobalLatestVersion")(function* (
451
packageName: string,
452
env: NodeJS.ProcessEnv,
@@ -466,9 +464,7 @@ const resolvePnpmGlobalLatestVersion = Effect.fn("resolvePnpmGlobalLatestVersion
464
// pnpm outdated exits 1 when updates are available.
465
[0, 1],
466
);
469
- const outdatedEntries = outdated
470
- ? Option.getOrUndefined(decodePnpmOutdated(outdated))
471
- : undefined;
467
+ const outdatedEntries = outdated ? Option.getOrUndefined(decodeOutdated(outdated)) : undefined;
468
if (!outdatedEntries) return null;
469
const latest = nonEmptyString(outdatedEntries[packageName]?.latest);
470
if (latest) return latest;
@@ -482,6 +478,41 @@ const resolvePnpmGlobalLatestVersion = Effect.fn("resolvePnpmGlobalLatestVersion
478
return nonEmptyString(listedEntries?.[0]?.dependencies?.[packageName]?.version);
479
});
480
481
+// Unlike `npm view`, `outdated` applies min-release-age, before and their excludes.
482
+const resolveNpmGlobalLatestVersion = Effect.fn("resolveNpmGlobalLatestVersion")(function* (
483
+ packageName: string,
484
+ npmPrefix: string,
485
+ env: NodeJS.ProcessEnv,
486
+) {
487
+ // Match the updater's npm and environment.
488
+ const npmPath = yield* resolveCommandPath("npm", {
489
+ env: { ...(yield* HostProcess.Environment), ...env },
490
+ });
491
+ if (!npmPath) return null;
492
+ const outdated = yield* runProbe(
493
+ npmPath,
494
+ ["outdated", "-g", "--prefix", npmPrefix, "--json", packageName],
495
+ env,
496
+ // npm outdated exits 1 when updates are available.
497
+ [0, 1],
498
+ );
499
+ const outdatedEntries = outdated ? Option.getOrUndefined(decodeOutdated(outdated)) : undefined;
500
+ // npm prints failures such as an unreachable registry as `{"error": ...}`, also exiting 1.
501
+ if (!outdatedEntries || "error" in outdatedEntries) return null;
502
+ const latest = nonEmptyString(outdatedEntries[packageName]?.latest);
503
+ if (latest) return latest;
504
+ // An empty result means the installed version is still the eligible release.
505
+ const listed = yield* runProbe(
506
+ npmPath,
507
+ ["ls", "-g", "--prefix", npmPrefix, "--depth", "0", "--json", packageName],
508
+ env,
509
+ // npm ls still prints the tree but exits 1 when other globals have problems.
510
+ [0, 1],
511
+ );
512
+ const listedEntries = listed ? Option.getOrUndefined(decodeNpmList(listed)) : undefined;
513
+ return nonEmptyString(listedEntries?.dependencies?.[packageName]?.version);
514
+});
515
+
516
// npm names the tarball `${name}-${version}.tgz`, dropping a scope's `@` and its `/`.
517
function parseNpmPackVersion(stdout: string, packageName: string): string | null {
518
const prefix = `${packageName.replace(/^@/, "").replace("/", "-")}-`;
@@ -933,8 +964,9 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
964
// npm proof outranks a containing Homebrew keg; Homebrew Node globals still belong to npm.
965
const npmPrefix = yield* resolveNpmGlobalPrefix(context, packageName);
966
if (npmPrefix) {
967
+ const services = yield* Effect.context<ProviderMaintenanceResolverServices>();
968
// npm 12 requires script approval to install native binaries; older npm only warns about the flag.
937
- return makeProviderMaintenanceCapabilities({
969
+ const capabilities = makeProviderMaintenanceCapabilities({
970
provider: definition.provider,
971
packageName,
972
updateExecutable: "npm",
@@ -948,7 +980,22 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
980
],
981
updateLockKey: `npm-global:${normalizeCommandPath(npmPrefix)}`,
982
env: context.env,
983
+ // Inside min-release-age `@latest` installs an older release than the
984
+ // registry's tag, so only npm's own answer is worth advertising.
985
+ latestVersion: null,
986
+ lookupLatestVersion: resolveNpmGlobalLatestVersion(packageName, npmPrefix, context.env).pipe(
987
+ Effect.provideContext(services),
988
+ ),
989
});
990
+ return {
991
+ ...capabilities,
992
+ latestVersionCacheKey: [
993
+ "npm-global",
994
+ normalizeCommandPath(npmPrefix),
995
+ packageName,
996
+ environmentCacheKey(context.env),
997
+ ].join("\0"),
998
+ };
999
}
1000
1001
const homebrew = homebrewOwnershipFromCommandPath(context.realCommandPath);
@@ -1146,21 +1193,9 @@ const withConfiguredNpmVersionLookup = Effect.fn("withConfiguredNpmVersionLookup
1193
const npmPath = yield* resolveCommandPath("npm", { env });
1194
if (!npmPath) return capabilities;
1195
const services = yield* Effect.context<ProviderMaintenanceResolverServices>();
1149
- const update = capabilities.update;
1150
- const prefixIndex = update?.lockKey.startsWith("npm-global:")
1151
- ? update.args.indexOf("--prefix")
1152
- : -1;
1153
- const prefix = prefixIndex >= 0 ? update?.args[prefixIndex + 1] : undefined;
1196
const lookup = runProbe(
1197
npmPath,
1156
- [
1157
- "view",
1158
- "--global",
1159
- ...(prefix ? ["--prefix", prefix] : []),
1160
- "--json",
1161
- `${packageName}@latest`,
1162
- "version",
1163
- ],
1198
+ ["view", "--global", "--json", `${packageName}@latest`, "version"],
1199
env,
1200
).pipe(
1201
Effect.map((stdout) => {
@@ -1182,7 +1217,6 @@ const withConfiguredNpmVersionLookup = Effect.fn("withConfiguredNpmVersionLookup
1217
"configured-npm",
1218
npmPath,
1219
packageName,
1185
- prefix ?? "",
1220
environmentCacheKey(env),
1221
installerLatestVersionKey(capabilities) ?? "",
1222
].join("\0"),