Open History to see the last commit
1// @effect-diagnostics nodeBuiltinImport:off
2import { expect, it } from "@effect/vitest";
3import * as NodeFS from "node:fs";
4import * as NodeServices from "@effect/platform-node/NodeServices";
5import * as NodeOS from "node:os";
6import * as NodePath from "node:path";
7import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts";
8import * as HostProcess from "@t3tools/shared/HostProcess";
9import * as Crypto from "effect/Crypto";
10import * as Deferred from "effect/Deferred";
11import * as Effect from "effect/Effect";
12import * as Fiber from "effect/Fiber";
13import * as Sink from "effect/Sink";
14import * as Stream from "effect/Stream";
15import * as HttpClient from "effect/http/HttpClient";
16import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
17import * as ProviderLatestVersions from "./ProviderLatestVersions.ts";
18import {
19 createProviderVersionAdvisory,
20 makeTargetedProviderUpdateAction,
21 enrichProviderSnapshotWithVersionAdvisory,
22 homebrewOwnershipFromCommandPath,
23 invalidateLatestProviderVersion,
24 makeCachedProviderMaintenanceResolution,
25 makePackageManagedProviderMaintenanceResolver,
26 makeProviderMaintenanceCapabilities,
27 normalizeCommandPath,
28 npmGlobalPrefixFromCommandPath,
29 parseHomebrewLatestVersion,
30 resolveLatestProviderVersion,
31 resolvePackageManagedProviderMaintenance,
32 resolveProviderMaintenanceCapabilitiesEffect,
33 type PackageManagedProviderMaintenanceDefinition,
34 type ProviderMaintenanceCapabilities,
35} from "./maintenanceResolver.ts";
36import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
37
38const driver = (value: string) => ProviderDriverKind.make(value);
39// Shell stubs use POSIX paths; Windows temp paths cannot split on colon.
40const windowsHost = HostProcess.Platform.defaultValue() === "win32";
41const makeTempDir = (name: string) =>
42 Crypto.Crypto.pipe(
43 Effect.flatMap((crypto) => crypto.randomUUIDv4()),
44 Effect.map((id) => NodePath.join(NodeFS.realpathSync(NodeOS.tmpdir()), `${name}-${id}`)),
45 );
46const isNativeTestCommandPath =
47 (expectedPathSegment: string) =>
48 (commandPath: string): boolean =>
49 normalizeCommandPath(commandPath).includes(expectedPathSegment);
50const packageToolUpdate = makePackageManagedProviderMaintenanceResolver({
51 provider: driver("packageTool"),
52 npmPackageName: "@example/package-tool",
53 nativeUpdate: null,
54});
55const nativePackageToolUpdate = makePackageManagedProviderMaintenanceResolver({
56 provider: driver("nativePackageTool"),
57 npmPackageName: "@example/native-package-tool",
58 nativeUpdate: {
59 args: ["update"],
60 isCommandPath: isNativeTestCommandPath("/.local/bin/native-package-tool"),
61 },
62});
63const installedPackageToolProvider: ServerProvider = {
64 instanceId: ProviderInstanceId.make("packageTool"),
65 driver: driver("packageTool"),
66 enabled: true,
67 installed: true,
68 version: "1.0.0",
69 status: "ready",
70 auth: { status: "authenticated" },
71 checkedAt: "2026-04-10T00:00:00.000Z",
72 models: [],
73 slashCommands: [],
74 skills: [],
75};
76const manualPackageTool: ProviderMaintenanceCapabilities = {
77 provider: driver("packageTool"),
78 packageName: "@example/package-tool",
79 update: null,
80};
81
82function writeExecutable(path: string) {
83 NodeFS.mkdirSync(NodePath.dirname(path), { recursive: true });
84 NodeFS.writeFileSync(path, "#!/bin/sh\n");
85 NodeFS.chmodSync(path, 0o755);
86}
87
88function linkIntoPackage(tempDir: string, name: string, packageSegments: ReadonlyArray<string>) {
89 const target = NodePath.join(tempDir, ...packageSegments, "bin", `${name}.js`);
90 writeExecutable(target);
91 const link = NodePath.join(tempDir, "bin", name);
92 NodeFS.mkdirSync(NodePath.dirname(link), { recursive: true });
93 NodeFS.symlinkSync(target, link);
94 return link;
95}
96
97const noSpawn = ChildProcessSpawner.make(() =>
98 Effect.die("maintenance resolution should not spawn a process here"),
99);
100
101function stdoutSpawner(
102 onSpawn: (command: string, args: ReadonlyArray<string>) => string,
103 exitCodeOf: (args: ReadonlyArray<string>) => number = () => 0,
104) {
105 return ChildProcessSpawner.make((command) => {
106 const { command: executable, args } = command as unknown as {
107 readonly command: string;
108 readonly args: ReadonlyArray<string>;
109 };
110 return Effect.succeed(
111 ChildProcessSpawner.makeHandle({
112 pid: ChildProcessSpawner.ProcessId(1),
113 exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(exitCodeOf(args))),
114 isRunning: Effect.succeed(false),
115 kill: () => Effect.void,
116 unref: Effect.succeed(Effect.void),
117 stdin: Sink.drain,
118 stdout: Stream.encodeText(Stream.make(onSpawn(executable, args))),
119 stderr: Stream.empty,
120 all: Stream.empty,
121 getInputFd: () => Sink.drain,
122 getOutputFd: () => Stream.empty,
123 }),
124 );
125 });
126}
127
128it.layer(NodeServices.layer)("providerMaintenance", (it) => {
129 it.effect("prefers the installer's own latest version over the npm registry", () =>
130 resolveLatestProviderVersion({ ...manualPackageTool, latestVersion: "1.2.0" }).pipe(
131 Effect.provide(ProviderLatestVersions.layer),
132 Effect.provideService(
133 HttpClient.HttpClient,
134 HttpClient.make(() =>
135 Effect.die("installer-reported latest should not make an HTTP request"),
136 ),
137 ),
138 Effect.map((version) => {
139 expect(version).toBe("1.2.0");
140 }),
141 ),
142 );
143
144 it.effect("does not fetch latest provider versions when update checks are disabled", () =>
145 enrichProviderSnapshotWithVersionAdvisory(
146 { ...installedPackageToolProvider, installedVersion: "1.1.0" },
147 manualPackageTool,
148 { enableProviderUpdateChecks: false },
149 ).pipe(
150 Effect.provide(ProviderLatestVersions.layer),
151 Effect.provideService(
152 HttpClient.HttpClient,
153 HttpClient.make(() =>
154 Effect.die("disabled provider update checks should not make an HTTP request"),
155 ),
156 ),
157 Effect.map((provider) => {
158 expect(provider.versionAdvisory).toMatchObject({
159 status: "unknown",
160 currentVersion: "1.1.0",
161 latestVersion: null,
162 checkedAt: "2026-04-10T00:00:00.000Z",
163 });
164 }),
165 ),
166 );
167
168 it("pins the advertised stable version in a pnpm-global update command", () => {
169 const advisoryFor = (
170 maintenanceCapabilities: ReturnType<typeof makeProviderMaintenanceCapabilities>,
171 latestVersion: string,
172 ) =>
173 createProviderVersionAdvisory({
174 driver: driver("packageTool"),
175 currentVersion: "1.0.0",
176 latestVersion,
177 maintenanceCapabilities,
178 }).updateCommand;
179 const pnpmTool = makeProviderMaintenanceCapabilities({
180 provider: driver("packageTool"),
181 packageName: "@example/package-tool",
182 updateExecutable: "pnpm",
183 updateArgs: [
184 "add",
185 "-g",
186 "--allow-build=@example/package-tool",
187 "@example/package-tool@latest",
188 ],
189 updateLockKey: "pnpm-global",
190 });
191
192 expect(advisoryFor(pnpmTool, "1.1.0")).toBe(
193 "pnpm add -g --allow-build=@example/package-tool @example/package-tool@1.1.0",
194 );
195 // A prerelease cannot be pinned safely, so pnpm keeps @latest.
196 expect(advisoryFor(pnpmTool, "1.1.0-beta.1")).toBe(
197 "pnpm add -g --allow-build=@example/package-tool @example/package-tool@latest",
198 );
199 // Only pnpm's minimumReleaseAge skips fresh releases; npm keeps @latest.
200 expect(
201 advisoryFor(
202 makeProviderMaintenanceCapabilities({
203 provider: driver("packageTool"),
204 packageName: "@example/package-tool",
205 updateExecutable: "npm",
206 updateArgs: ["install", "-g", "@example/package-tool@latest"],
207 updateLockKey: "npm-global:/opt/node",
208 }),
209 "1.1.0",
210 ),
211 ).toBe("npm install -g @example/package-tool@latest");
212 });
213
214 it("names the install to update when it is behind but unowned", () => {
215 expect(
216 createProviderVersionAdvisory({
217 driver: driver("packageTool"),
218 currentVersion: "2.1.110",
219 latestVersion: "2.1.117",
220 maintenanceCapabilities: {
221 ...manualPackageTool,
222 installPath: "/Applications/Tool.app/Contents/Resources/bin/package-tool",
223 },
224 }),
225 ).toMatchObject({
226 status: "behind_latest",
227 latestVersion: "2.1.117",
228 updateCommand: null,
229 canUpdate: false,
230 message:
231 "Version 2.1.117 is out. T3 Code runs /Applications/Tool.app/Contents/Resources/bin/package-tool; update it with the app or tool that installed it.",
232 });
233 });
234
235 it("offers the update when an owned install is behind", () => {
236 expect(
237 createProviderVersionAdvisory({
238 driver: driver("packageTool"),
239 currentVersion: "2.1.110",
240 latestVersion: "2.1.117",
241 maintenanceCapabilities: makeProviderMaintenanceCapabilities({
242 provider: driver("packageTool"),
243 packageName: "@example/package-tool",
244 updateExecutable: "npm",
245 updateArgs: ["install", "-g", "@example/package-tool@latest"],
246 updateLockKey: "npm-global:/usr/local",
247 }),
248 }),
249 ).toMatchObject({
250 status: "behind_latest",
251 canUpdate: true,
252 message: "Install the update now or review provider settings.",
253 });
254 });
255
256 it.effect("stays manual-only when the binary cannot be located", () =>
257 resolveProviderMaintenanceCapabilitiesEffect(packageToolUpdate, {
258 binaryPath: "package-tool",
259 env: { PATH: "" },
260 }).pipe(
261 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn),
262 Effect.map((capabilities) => {
263 expect(capabilities).toEqual(manualPackageTool);
264 }),
265 ),
266 );
267
268 it.effect.skipIf(!symlinksSupported)(
269 "pins npm updates to the global prefix that owns the package",
270 () =>
271 Effect.gen(function* () {
272 const tempDir = yield* makeTempDir("t3-npm-capabilities");
273 const link = linkIntoPackage(tempDir, "package-tool", [
274 "lib",
275 "node_modules",
276 "@example",
277 "package-tool",
278 ]);
279
280 const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(
281 packageToolUpdate,
282 {
283 binaryPath: link,
284 env: { PATH: "" },
285 },
286 ).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn));
287
288 expect(capabilities).toEqual({
289 provider: driver("packageTool"),
290 packageName: "@example/package-tool",
291 update: {
292 command: `npm install -g --prefix ${tempDir} --allow-scripts=@example/package-tool @example/package-tool@latest`,
293 executable: "npm",
294 args: [
295 "install",
296 "-g",
297 "--prefix",
298 tempDir,
299 "--allow-scripts=@example/package-tool",
300 "@example/package-tool@latest",
301 ],
302 lockKey: `npm-global:${normalizeCommandPath(tempDir)}`,
303 },
304 });
305 }),
306 );
307
308 it("derives the npm prefix only from the global lib/node_modules layout", () => {
309 expect(
310 npmGlobalPrefixFromCommandPath(
311 "/usr/local/lib/node_modules/@openai/codex/bin/codex.js",
312 "@openai/codex",
313 ),
314 ).toBe("/usr/local");
315 expect(
316 npmGlobalPrefixFromCommandPath(
317 "/usr/local/lib/node_modules/other/node_modules/@openai/codex/bin/codex.js",
318 "@openai/codex",
319 ),
320 ).toBeNull();
321 expect(
322 npmGlobalPrefixFromCommandPath(
323 "/lib/node_modules/@openai/codex/bin/codex.js",
324 "@openai/codex",
325 ),
326 ).toBe("/");
327 expect(
328 npmGlobalPrefixFromCommandPath(
329 "/work/app/node_modules/@openai/codex/bin/codex.js",
330 "@openai/codex",
331 ),
332 ).toBeNull();
333 });
334
335 // The Windows Codex bin junction resolves into CODEX_HOME/packages/standalone/current/bin.
336 it.effect("recognizes a Windows standalone install through its junctioned bin dir", () =>
337 Effect.gen(function* () {
338 const visiblePath =
339 "C:\\Users\\Theo\\AppData\\Local\\Programs\\OpenAI\\Codex\\bin\\codex.exe";
340 const realPath =
341 "C:\\Users\\Theo\\.codex\\packages\\standalone\\releases\\0.120.0-x86_64\\bin\\codex.exe";
342 const capabilities = yield* resolvePackageManagedProviderMaintenance(
343 {
344 provider: driver("codex"),
345 npmPackageName: "@openai/codex",
346 nativeUpdate: {
347 args: ["update"],
348 isCommandPath: isNativeTestCommandPath("/packages/standalone/"),
349 },
350 },
351 {
352 binaryPath: "codex",
353 resolvedCommandPath: visiblePath,
354 realCommandPath: realPath,
355 env: {},
356 platform: "win32",
357 },
358 ).pipe(Effect.provideService(HostProcess.Platform, "win32"));
359
360 expect(capabilities.update).toMatchObject({
361 executable: visiblePath,
362 args: ["update"],
363 lockKey: "codex-native",
364 });
365 }),
366 );
367
368 it.effect(
369 "keeps an unrecognized install manual-only when the native updater requires its path",
370 () =>
371 Effect.gen(function* () {
372 const systemPath =
373 "/usr/local/lib/codex/releases/rust-v0.162.1-x86_64-unknown-linux-musl/bin/codex";
374 const capabilities = yield* resolvePackageManagedProviderMaintenance(
375 {
376 provider: driver("codex"),
377 npmPackageName: "@openai/codex",
378 nativeUpdate: {
379 args: ["update"],
380 isCommandPath: isNativeTestCommandPath("/packages/standalone/"),
381 requiresCommandPath: true,
382 },
383 },
384 {
385 binaryPath: "codex",
386 resolvedCommandPath: "/usr/local/bin/codex",
387 realCommandPath: systemPath,
388 env: {},
389 platform: "linux",
390 },
391 ).pipe(
392 Effect.provideService(HostProcess.Platform, "linux"),
393 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn),
394 );
395
396 expect(capabilities.update).toBeNull();
397 expect(capabilities.installPath).toBe(systemPath);
398 }),
399 );
400
401 const claudeUpdate = {
402 provider: driver("claudeAgent"),
403 npmPackageName: "@anthropic-ai/claude-code",
404 nativeUpdate: {
405 args: ["update"],
406 isCommandPath: isNativeTestCommandPath("/.local/bin/claude"),
407 },
408 };
409 const otherProviderUpdate = {
410 provider: driver("nativePackageTool"),
411 npmPackageName: "@example/native-package-tool",
412 nativeUpdate: {
413 args: ["update"],
414 isCommandPath: isNativeTestCommandPath("/.local/bin/native-package-tool"),
415 },
416 };
417 const resolveInstall = (input: {
418 readonly definition: PackageManagedProviderMaintenanceDefinition;
419 readonly resolved: string;
420 readonly real: string;
421 readonly platform?: NodeJS.Platform;
422 }) =>
423 resolvePackageManagedProviderMaintenance(input.definition, {
424 binaryPath: "claude",
425 resolvedCommandPath: input.resolved,
426 realCommandPath: input.real,
427 env: {},
428 platform: input.platform ?? "win32",
429 }).pipe(
430 Effect.provideService(HostProcess.Platform, input.platform ?? "win32"),
431 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn),
432 );
433 const userWinGetLink = "C:\\Users\\me\\AppData\\Local\\Microsoft\\WinGet\\Links\\claude.exe";
434 const userWinGetPackage =
435 "C:\\Users\\me\\AppData\\Local\\Microsoft\\WinGet\\Packages\\Anthropic.ClaudeCode_Microsoft.Winget.Source_8wekyb3d8bbwe\\claude.exe";
436 const machineWinGetLink = "C:\\Program Files\\WinGet\\Links\\claude.exe";
437 const machineWinGetPackage =
438 "C:\\Program Files\\WinGet\\Packages\\Anthropic.ClaudeCode_Microsoft.Winget.Source_8wekyb3d8bbwe\\claude.exe";
439 const nativeClaude = "C:\\Users\\me\\.local\\bin\\claude.exe";
440
441 it.effect.each([
442 { name: "a user-scope link", resolved: userWinGetLink, real: userWinGetPackage },
443 { name: "a user-scope package", resolved: userWinGetPackage, real: userWinGetPackage },
444 { name: "a machine-scope package", resolved: machineWinGetPackage, real: machineWinGetPackage },
445 { name: "a machine-scope link alone", resolved: machineWinGetLink, real: machineWinGetLink },
446 {
447 name: "a mixed-case link",
448 resolved: "c:\\USERS\\me\\appdata\\local\\MICROSOFT\\winget\\links\\Claude.EXE",
449 real: userWinGetPackage.toUpperCase(),
450 },
451 { name: "a native-looking alias", resolved: nativeClaude, real: userWinGetPackage },
452 ] as const)("keeps a WinGet Claude install manual-only through $name", (fixture) =>
453 Effect.gen(function* () {
454 const capabilities = yield* resolveInstall({ definition: claudeUpdate, ...fixture });
455
456 expect(capabilities.update).toBeNull();
457 }),
458 );
459
460 it.effect.each([
461 {
462 name: "a native install",
463 definition: claudeUpdate,
464 resolved: nativeClaude,
465 real: nativeClaude,
466 },
467 {
468 name: "a WinGet-shaped path off Windows",
469 definition: claudeUpdate,
470 resolved: "/home/me/winget/links/claude.exe",
471 real: "/home/me/winget/links/claude.exe",
472 platform: "linux",
473 },
474 {
475 name: "a WinGet-named folder outside the WinGet roots",
476 definition: claudeUpdate,
477 resolved: "C:\\Work\\WinGet\\Links\\claude.exe",
478 real: "C:\\Work\\WinGet\\Links\\claude.exe",
479 },
480 {
481 name: "a WinGet-named folder inside another directory",
482 definition: claudeUpdate,
483 resolved: "C:\\Work\\Microsoft\\WinGet\\Links\\claude.exe",
484 real: "C:\\Work\\Microsoft\\WinGet\\Links\\claude.exe",
485 },
486 {
487 name: "another provider in WinGet",
488 definition: otherProviderUpdate,
489 resolved: userWinGetLink,
490 real: userWinGetPackage,
491 },
492 {
493 name: "another WinGet package",
494 definition: claudeUpdate,
495 resolved: userWinGetPackage.replace("ClaudeCode_", "ClaudeCodeOther_"),
496 real: userWinGetPackage.replace("ClaudeCode_", "ClaudeCodeOther_"),
497 },
498 ] as const)("keeps the native updater for $name", (fixture) =>
499 Effect.gen(function* () {
500 const capabilities = yield* resolveInstall(fixture);
501
502 expect(capabilities.update).toMatchObject({
503 executable: fixture.resolved,
504 args: ["update"],
505 lockKey: `${fixture.definition.provider}-native`,
506 });
507 }),
508 );
509
510 it.effect.each([
511 {
512 name: "the default home",
513 resolved: "/Users/theo/.vite-plus/bin/claude",
514 real: "/Users/theo/.vite-plus/current/bin/vp",
515 platform: "darwin",
516 },
517 {
518 name: "the XDG home",
519 resolved: "/home/theo/.local/share/vite-plus/bin/claude",
520 real: "/home/theo/.local/share/vite-plus/current/bin/vp",
521 platform: "linux",
522 },
523 {
524 name: "the Windows home",
525 resolved: "C:\\Users\\Theo\\AppData\\Local\\vite-plus\\bin\\claude.cmd",
526 real: "C:\\Users\\Theo\\AppData\\Local\\vite-plus\\packages\\@anthropic-ai\\claude-code\\lib\\node_modules\\@anthropic-ai\\claude-code\\cli.js",
527 platform: "win32",
528 },
529 ] as const)("updates a Vite+ global install in $name with vp", (fixture) =>
530 Effect.gen(function* () {
531 const capabilities = yield* resolveInstall({ definition: claudeUpdate, ...fixture });
532
533 expect(capabilities.update).toMatchObject({
534 command: "vp i -g @anthropic-ai/claude-code",
535 lockKey: "vite-plus-global",
536 });
537 }),
538 );
539
540 it.effect("keeps a project folder named vite-plus manual-only", () =>
541 Effect.gen(function* () {
542 const capabilities = yield* resolveInstall({
543 definition: claudeUpdate,
544 resolved: "/work/vite-plus/bin/claude",
545 real: "/work/vite-plus/node_modules/@anthropic-ai/claude-code/cli.js",
546 platform: "linux",
547 });
548
549 expect(capabilities.update).toBeNull();
550 }),
551 );
552
553 it.effect("proves Windows npm ownership from the package manifest beside the shim", () =>
554 Effect.gen(function* () {
555 const tempDir = yield* makeTempDir("t3-npm-windows-capabilities");
556 const shim = NodePath.join(tempDir, "package-tool.cmd");
557 NodeFS.mkdirSync(tempDir, { recursive: true });
558 NodeFS.writeFileSync(shim, "@echo off\r\n");
559 NodeFS.mkdirSync(NodePath.join(tempDir, "node_modules", "@example", "package-tool"), {
560 recursive: true,
561 });
562 NodeFS.writeFileSync(
563 NodePath.join(tempDir, "node_modules", "@example", "package-tool", "package.json"),
564 "{}",
565 );
566
567 const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(packageToolUpdate, {
568 binaryPath: shim,
569 env: { PATH: "", PATHEXT: ".COM;.EXE;.BAT;.CMD" },
570 }).pipe(
571 Effect.provideService(HostProcess.Platform, "win32"),
572 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn),
573 );
574
575 expect(capabilities.update).toMatchObject({
576 executable: "npm",
577 args: ["install", "-g", "--prefix", tempDir, expect.any(String), expect.any(String)],
578 });
579
580 const script = NodePath.join(tempDir, "package-tool");
581 writeExecutable(script);
582 const posix = yield* resolveProviderMaintenanceCapabilitiesEffect(packageToolUpdate, {
583 binaryPath: script,
584 env: { PATH: "" },
585 }).pipe(
586 Effect.provideService(HostProcess.Platform, "linux"),
587 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn),
588 );
589 expect(posix.update).toBeNull();
590 }),
591 );
592
593 it.effect.skipIf(!symlinksSupported)(
594 "switches to pnpm updates when the real path lives in pnpm's global store",
595 () =>
596 Effect.gen(function* () {
597 const tempDir = yield* makeTempDir("t3-pnpm-capabilities");
598 const link = linkIntoPackage(tempDir, "package-tool", [
599 ".local",
600 "share",
601 "pnpm",
602 "global",
603 "5",
604 "node_modules",
605 "@example",
606 "package-tool",
607 ]);
608
609 const updateCommand = (spawner: ChildProcessSpawner.ChildProcessSpawner["Service"]) =>
610 resolveProviderMaintenanceCapabilitiesEffect(packageToolUpdate, {
611 binaryPath: link,
612 env: { PATH: "" },
613 }).pipe(
614 Effect.map((capabilities) => capabilities.update),
615 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
616 );
617 const pnpmVersion = (version: string) =>
618 stdoutSpawner((command, args) => {
619 expect([command, ...args].join(" ")).toMatch(/pnpm(\.cmd)?"? --version$/);
620 return `${version}
621`;
622 });
623
624 expect(yield* updateCommand(pnpmVersion("11.1.3"))).toMatchObject({
625 command: "pnpm add -g --allow-build=@example/package-tool @example/package-tool@latest",
626 lockKey: "pnpm-global",
627 });
628 expect((yield* updateCommand(pnpmVersion("10.3.0")))?.command).toBe(
629 "pnpm add -g @example/package-tool@latest",
630 );
631 expect((yield* updateCommand(noSpawn))?.command).toBe(
632 "pnpm add -g @example/package-tool@latest",
633 );
634 }),
635 );
636
637 it.effect.each([
638 {
639 case: "the eligible release",
640 outdated: { "@example/package-tool": { current: "1.0.0", latest: "1.1.0" } },
641 exitCode: 1,
642 expected: "1.1.0",
643 },
644 { case: "no update during cooldown", outdated: {}, exitCode: 0, expected: "1.0.0" },
645 {
646 case: "the npm fallback when the pnpm probe fails",
647 outdated: { "@example/package-tool": { current: "1.0.0", latest: "1.1.0" } },
648 exitCode: 2,
649 expected: "9.9.9",
650 },
651 ])(
652 "advertises $case for pnpm-global installs",
653 (fixture) =>
654 Effect.gen(function* () {
655 const tempDir = yield* makeTempDir("t3-pnpm-latest");
656 const pnpmBinDir = NodePath.join(tempDir, "pnpm-bin");
657 writeExecutable(NodePath.join(pnpmBinDir, "pnpm"));
658 const link = linkIntoPackage(tempDir, "package-tool", [
659 ".local",
660 "share",
661 "pnpm",
662 "global",
663 "5",
664 "node_modules",
665 "@example",
666 "package-tool",
667 ]);
668
669 const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(
670 packageToolUpdate,
671 { binaryPath: link, env: { PATH: "" } },
672 ).pipe(
673 Effect.provideService(HostProcess.Environment, { PATH: pnpmBinDir }),
674 Effect.provideService(
675 ChildProcessSpawner.ChildProcessSpawner,
676 stdoutSpawner(
677 (_command, args) =>
678 args[0] === "outdated"
679 ? JSON.stringify(fixture.outdated)
680 : JSON.stringify([
681 { dependencies: { "@example/package-tool": { version: "1.0.0" } } },
682 ]),
683 (args) => (args[0] === "outdated" ? fixture.exitCode : 0),
684 ),
685 ),
686 );
687
688 const provider = yield* enrichProviderSnapshotWithVersionAdvisory(
689 installedPackageToolProvider,
690 capabilities,
691 ).pipe(
692 Effect.provideServiceEffect(
693 ProviderLatestVersions.ProviderLatestVersions,
694 ProviderLatestVersions.make([["@example/package-tool", "9.9.9"]]),
695 ),
696 Effect.provideService(
697 HttpClient.HttpClient,
698 HttpClient.make(() => Effect.die("the npm version is already cached")),
699 ),
700 );
701 expect(provider.versionAdvisory).toMatchObject({
702 status: fixture.expected === "1.0.0" ? "current" : "behind_latest",
703 currentVersion: "1.0.0",
704 latestVersion: fixture.expected,
705 });
706 }),
707 { skip: !symlinksSupported || windowsHost },
708 );
709
710 it.effect.skipIf(windowsHost)(
711 "switches to bun updates when the resolved binary lives in bun's global bin",
712 () =>
713 Effect.gen(function* () {
714 const tempDir = yield* makeTempDir("t3-bun-capabilities");
715 const bunBinDir = NodePath.join(tempDir, ".bun", "bin");
716 writeExecutable(NodePath.join(bunBinDir, "package-tool"));
717
718 const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(
719 packageToolUpdate,
720 {
721 binaryPath: "package-tool",
722 env: { PATH: bunBinDir },
723 },
724 ).pipe(
725 Effect.provideService(HostProcess.Platform, "darwin"),
726 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn),
727 );
728
729 expect(capabilities.update).toMatchObject({
730 command: "bun i -g @example/package-tool@latest",
731 lockKey: "bun-global",
732 });
733 }),
734 );
735
736 it.effect.skipIf(windowsHost)("switches to native updates and runs the resolved executable", () =>
737 Effect.gen(function* () {
738 const tempDir = yield* makeTempDir("t3-native-capabilities");
739 const nativeBinDir = NodePath.join(tempDir, ".local", "bin");
740 const nativePath = NodePath.join(nativeBinDir, "native-package-tool");
741 writeExecutable(nativePath);
742
743 const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(
744 nativePackageToolUpdate,
745 {
746 binaryPath: "native-package-tool",
747 env: { PATH: nativeBinDir },
748 },
749 ).pipe(
750 Effect.provideService(HostProcess.Platform, "darwin"),
751 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn),
752 );
753
754 expect(capabilities).toEqual({
755 provider: driver("nativePackageTool"),
756 packageName: "@example/native-package-tool",
757 update: {
758 command: `${nativePath} update`,
759 executable: nativePath,
760 args: ["update"],
761 lockKey: "nativePackageTool-native",
762 },
763 });
764 }),
765 );
766
767 it.effect.each(["wrapper", "symlink"])(
768 "keeps a mise-owned %s in a native install location manual-only",
769 (launcher, { skip }) => {
770 if (windowsHost || (launcher === "symlink" && !symlinksSupported)) skip();
771 return Effect.gen(function* () {
772 const tempDir = yield* makeTempDir("t3-native-mise");
773 const nativePath = NodePath.join(tempDir, ".local", "bin", "native-package-tool");
774 if (launcher === "wrapper") {
775 writeExecutable(nativePath);
776 NodeFS.writeFileSync(
777 nativePath,
778 '#!/bin/sh\nexec mise x native-package-tool -- native-package-tool "$@"\n',
779 );
780 } else {
781 const target = NodePath.join(
782 tempDir,
783 "mise",
784 "installs",
785 "native-package-tool",
786 "1.0.0",
787 "native-package-tool",
788 );
789 writeExecutable(target);
790 NodeFS.mkdirSync(NodePath.dirname(nativePath), { recursive: true });
791 NodeFS.symlinkSync(target, nativePath);
792 }
793
794 const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(
795 nativePackageToolUpdate,
796 { binaryPath: nativePath, env: { PATH: "" } },
797 ).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn));
798
799 expect(capabilities.update).toBeNull();
800 });
801 },
802 );
803
804 it.effect.skipIf(!symlinksSupported)(
805 "prefers npm ownership over the Node keg the package lives under",
806 () =>
807 Effect.gen(function* () {
808 const tempDir = yield* makeTempDir("t3-homebrew-node-capabilities");
809 const keg = NodePath.join(tempDir, "Cellar", "node", "22.1.0");
810 const target = NodePath.join(
811 keg,
812 "lib",
813 "node_modules",
814 "@example",
815 "package-tool",
816 "bin",
817 "package-tool.js",
818 );
819 writeExecutable(target);
820 const link = NodePath.join(tempDir, "bin", "package-tool");
821 NodeFS.mkdirSync(NodePath.dirname(link), { recursive: true });
822 NodeFS.symlinkSync(target, link);
823
824 const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(
825 packageToolUpdate,
826 {
827 binaryPath: link,
828 env: { PATH: "" },
829 },
830 ).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn));
831
832 expect(capabilities.update).toMatchObject({
833 executable: "npm",
834 args: expect.arrayContaining(["--prefix", keg]),
835 lockKey: `npm-global:${normalizeCommandPath(keg)}`,
836 });
837 }),
838 );
839
840 it("quotes copyable command words the shell would split", () => {
841 const posix = makeProviderMaintenanceCapabilities({
842 provider: driver("packageTool"),
843 packageName: "@example/package-tool",
844 updateExecutable: "npm",
845 updateArgs: [
846 "install",
847 "-g",
848 "--prefix",
849 "/Users/Jane Doe/.npm-global",
850 "@example/package-tool@latest",
851 ],
852 updateLockKey: "npm-global",
853 platform: "darwin",
854 });
855 expect(posix.update?.command).toBe(
856 "npm install -g --prefix '/Users/Jane Doe/.npm-global' @example/package-tool@latest",
857 );
858 const windows = makeProviderMaintenanceCapabilities({
859 provider: driver("packageTool"),
860 packageName: null,
861 updateExecutable: "C:\\Program Files\\Tool\\tool.exe",
862 updateArgs: ["update"],
863 updateLockKey: "tool",
864 platform: "win32",
865 });
866 expect(windows.update?.command).toBe("& 'C:\\Program Files\\Tool\\tool.exe' update");
867 });
868
869 it.effect.skipIf(windowsHost)("carries the native updater's environment into the action", () =>
870 Effect.gen(function* () {
871 const tempDir = yield* makeTempDir("t3-native-env");
872 const nativePath = NodePath.join(tempDir, ".local", "bin", "native-package-tool");
873 writeExecutable(nativePath);
874 const resolver = makePackageManagedProviderMaintenanceResolver({
875 provider: driver("nativePackageTool"),
876 npmPackageName: "@example/native-package-tool",
877 nativeUpdate: {
878 args: ["update"],
879 isCommandPath: isNativeTestCommandPath("/.local/bin/native-package-tool"),
880 env: { TOOL_HOME: tempDir },
881 },
882 });
883
884 const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(resolver, {
885 binaryPath: nativePath,
886 env: { PATH: "" },
887 }).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn));
888
889 expect(capabilities.update?.env).toEqual({ TOOL_HOME: tempDir });
890 }),
891 );
892
893 it("recognizes Homebrew kegs and casks from the real executable path", () => {
894 expect(
895 homebrewOwnershipFromCommandPath("/opt/homebrew/Cellar/claude-code@latest/2.1.0/bin/claude"),
896 ).toEqual({ kind: "formula", name: "claude-code@latest", prefix: "/opt/homebrew" });
897 expect(homebrewOwnershipFromCommandPath("/usr/local/Caskroom/codex/0.148.0/codex")).toEqual({
898 kind: "cask",
899 name: "codex",
900 prefix: "/usr/local",
901 });
902 expect(homebrewOwnershipFromCommandPath("/usr/local/bin/codex")).toBeNull();
903 expect(homebrewOwnershipFromCommandPath("/srv/Cellar/claude/1.0.0/bin/claude")).toMatchObject({
904 prefix: "/srv",
905 });
906 });
907
908 it.effect("shares installer lookups only for the same executable and update target", () =>
909 Effect.gen(function* () {
910 let lookups = 0;
911 const capabilities = (executable: string, args: ReadonlyArray<string>, version: string) =>
912 makeProviderMaintenanceCapabilities({
913 provider: driver("packageTool"),
914 packageName: "@example/package-tool",
915 updateExecutable: executable,
916 updateArgs: args,
917 updateLockKey: "homebrew",
918 latestVersion: null,
919 lookupLatestVersion: Effect.sync(() => {
920 lookups += 1;
921 return version;
922 }),
923 });
924
925 const formula = capabilities("/opt/homebrew/bin/brew", ["upgrade", "package-tool"], "2.0.0");
926 const cask = capabilities(
927 "/opt/homebrew/bin/brew",
928 ["upgrade", "--cask", "package-tool"],
929 "3.0.0",
930 );
931 const otherBrew = capabilities("/usr/local/bin/brew", ["upgrade", "package-tool"], "4.0.0");
932
933 expect(yield* resolveLatestProviderVersion(formula)).toBe("2.0.0");
934 expect(yield* resolveLatestProviderVersion(cask)).toBe("3.0.0");
935 expect(yield* resolveLatestProviderVersion(otherBrew)).toBe("4.0.0");
936 const refreshed = capabilities(
937 "/opt/homebrew/bin/brew",
938 ["upgrade", "package-tool"],
939 "5.0.0",
940 );
941 expect(yield* resolveLatestProviderVersion(refreshed)).toBe("2.0.0");
942 expect(lookups).toBe(3);
943
944 yield* invalidateLatestProviderVersion(refreshed);
945 expect(yield* resolveLatestProviderVersion(refreshed)).toBe("5.0.0");
946 expect(yield* resolveLatestProviderVersion(cask)).toBe("3.0.0");
947 expect(yield* resolveLatestProviderVersion(otherBrew)).toBe("4.0.0");
948 expect(lookups).toBe(4);
949 }).pipe(
950 Effect.provide(ProviderLatestVersions.layer),
951 Effect.provideService(
952 HttpClient.HttpClient,
953 HttpClient.make(() => Effect.die("Homebrew's latest should not come from npm")),
954 ),
955 ),
956 );
957
958 it.effect(
959 "refreshes installer versions without letting an older lookup overwrite the result",
960 () =>
961 Effect.gen(function* () {
962 const started = yield* Deferred.make<void>();
963 const release = yield* Deferred.make<string>();
964 let lookups = 0;
965 const capabilities = makeProviderMaintenanceCapabilities({
966 provider: driver("packageTool"),
967 packageName: "@example/package-tool",
968 updateExecutable: "/opt/homebrew/bin/brew",
969 updateArgs: ["upgrade", "package-tool"],
970 updateLockKey: "homebrew",
971 latestVersion: null,
972 lookupLatestVersion: Effect.suspend(() =>
973 ++lookups === 1
974 ? Deferred.succeed(started, undefined).pipe(Effect.andThen(Deferred.await(release)))
975 : Effect.succeed("2.0.0"),
976 ),
977 });
978 const pending = yield* resolveLatestProviderVersion(capabilities).pipe(Effect.forkChild);
979 yield* Deferred.await(started);
980 yield* invalidateLatestProviderVersion(capabilities);
981 expect(yield* resolveLatestProviderVersion(capabilities)).toBe("2.0.0");
982
983 yield* Deferred.succeed(release, "1.0.0");
984 expect(yield* Fiber.join(pending)).toBe("1.0.0");
985 expect(yield* resolveLatestProviderVersion(capabilities)).toBe("2.0.0");
986 expect(lookups).toBe(2);
987 }).pipe(
988 Effect.provide(ProviderLatestVersions.layer),
989 Effect.provideService(
990 HttpClient.HttpClient,
991 HttpClient.make(() => Effect.die("Homebrew's latest should not come from npm")),
992 ),
993 ),
994 );
995
996 it.effect.skipIf(windowsHost)(
997 "stays manual-only when the keg is not under the resolved brew's prefix",
998 () =>
999 Effect.gen(function* () {
1000 const tempDir = yield* makeTempDir("t3-homebrew-foreign-prefix");
1001 const brewBinDir = NodePath.join(tempDir, "brew-bin");
1002 writeExecutable(NodePath.join(brewBinDir, "brew"));
1003 const kegBinary = NodePath.join(
1004 tempDir,
1005 "elsewhere",
1006 "Cellar",
1007 "package-tool",
1008 "1.0.0",
1009 "bin",
1010 "package-tool",
1011 );
1012 writeExecutable(kegBinary);
1013
1014 const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(
1015 packageToolUpdate,
1016 {
1017 binaryPath: kegBinary,
1018 env: { PATH: brewBinDir },
1019 },
1020 ).pipe(
1021 Effect.provideService(HostProcess.Platform, "darwin"),
1022 Effect.provideService(
1023 ChildProcessSpawner.ChildProcessSpawner,
1024 stdoutSpawner(() => "/opt/homebrew\n"),
1025 ),
1026 );
1027
1028 expect(capabilities).toEqual({
1029 ...manualPackageTool,
1030 installPath: NodeFS.realpathSync(kegBinary),
1031 });
1032 }),
1033 );
1034
1035 it("reads the stable formula version from brew info", () => {
1036 const info = JSON.stringify({ formulae: [{ versions: { stable: "2.1.5" } }] });
1037 const formula = { kind: "formula", name: "claude-code", prefix: "/opt/homebrew" } as const;
1038 expect(parseHomebrewLatestVersion(info, formula)).toBe("2.1.5");
1039 expect(parseHomebrewLatestVersion("not json", formula)).toBeNull();
1040 });
1041
1042 it("treats Homebrew's latest cask version as unknown", () => {
1043 const info = JSON.stringify({ casks: [{ version: "latest" }] });
1044 const cask = { kind: "cask", name: "package-tool", prefix: "/opt/homebrew" } as const;
1045 expect(parseHomebrewLatestVersion(info, cask)).toBeNull();
1046 });
1047
1048 it.effect.skipIf(windowsHost)(
1049 "disables one-click updates for explicit custom binary paths it cannot safely map",
1050 () =>
1051 Effect.gen(function* () {
1052 const tempDir = yield* makeTempDir("t3-custom-capabilities");
1053 const customPath = NodePath.join(tempDir, "tools", "package-tool");
1054 writeExecutable(customPath);
1055
1056 const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(
1057 packageToolUpdate,
1058 {
1059 binaryPath: customPath,
1060 env: { PATH: "" },
1061 },
1062 ).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn));
1063
1064 expect(capabilities).toEqual({
1065 ...manualPackageTool,
1066 installPath: NodeFS.realpathSync(customPath),
1067 });
1068 }),
1069 );
1070
1071 it.effect.skipIf(windowsHost)(
1072 "falls back to the provider's own updater when no installer is proven",
1073 () =>
1074 Effect.gen(function* () {
1075 const tempDir = yield* makeTempDir("t3-self-update-fallback");
1076 const customPath = NodePath.join(tempDir, "tools", "package-tool");
1077 writeExecutable(customPath);
1078 const selfUpdating = makePackageManagedProviderMaintenanceResolver({
1079 provider: driver("packageTool"),
1080 npmPackageName: "@example/package-tool",
1081 nativeUpdate: { args: ["update", "--self"] },
1082 });
1083
1084 const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(selfUpdating, {
1085 binaryPath: customPath,
1086 env: { PATH: "" },
1087 }).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn));
1088 expect(capabilities.update).toMatchObject({
1089 executable: customPath,
1090 args: ["update", "--self"],
1091 lockKey: "packageTool-native",
1092 });
1093
1094 const misePath = NodePath.join(tempDir, "mise", "installs", "package-tool", "1.0.0", "bin");
1095 writeExecutable(NodePath.join(misePath, "package-tool"));
1096 const mise = yield* resolveProviderMaintenanceCapabilitiesEffect(selfUpdating, {
1097 binaryPath: NodePath.join(misePath, "package-tool"),
1098 env: { PATH: "" },
1099 }).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn));
1100 expect(mise.update).toBeNull();
1101 }),
1102 );
1103
1104 it.effect.skipIf(!symlinksSupported)("updates Yarn global installs with yarn", () =>
1105 Effect.gen(function* () {
1106 const tempDir = yield* makeTempDir("t3-yarn-capabilities");
1107 const link = linkIntoPackage(tempDir, "package-tool", [
1108 ".config",
1109 "yarn",
1110 "global",
1111 "node_modules",
1112 "@example",
1113 "package-tool",
1114 ]);
1115
1116 const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(packageToolUpdate, {
1117 binaryPath: link,
1118 env: { PATH: "" },
1119 }).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn));
1120
1121 expect(capabilities.update).toMatchObject({
1122 command: "yarn global add @example/package-tool@latest",
1123 lockKey: "yarn-global",
1124 });
1125 expect(makeTargetedProviderUpdateAction(capabilities, "2.0.0")?.args).toEqual([
1126 "global",
1127 "add",
1128 "@example/package-tool@2.0.0",
1129 ]);
1130 }),
1131 );
1132
1133 it.effect.skipIf(!symlinksSupported)(
1134 "updates Volta installs only when Volta has the package",
1135 () =>
1136 Effect.gen(function* () {
1137 const voltaHome = NodePath.join(yield* makeTempDir("t3-volta-capabilities"), ".volta");
1138 const shim = NodePath.join(voltaHome, "bin", "volta-shim");
1139 writeExecutable(shim);
1140 const link = NodePath.join(voltaHome, "bin", "package-tool");
1141 NodeFS.symlinkSync(shim, link);
1142 const resolve = resolveProviderMaintenanceCapabilitiesEffect(packageToolUpdate, {
1143 binaryPath: link,
1144 env: { PATH: "" },
1145 }).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn));
1146
1147 expect((yield* resolve).update).toBeNull();
1148 NodeFS.mkdirSync(
1149 NodePath.join(voltaHome, "tools", "image", "packages", "@example", "package-tool"),
1150 { recursive: true },
1151 );
1152 expect((yield* resolve).update).toMatchObject({
1153 command: "volta install @example/package-tool@latest",
1154 lockKey: "volta",
1155 });
1156 }),
1157 );
1158
1159 it.effect.skipIf(windowsHost)("upgrades with the keg's own brew when brew is not on PATH", () =>
1160 Effect.gen(function* () {
1161 const tempDir = yield* makeTempDir("t3-homebrew-keg-brew");
1162 const brewPath = NodePath.join(tempDir, "bin", "brew");
1163 writeExecutable(brewPath);
1164 const kegBinary = NodePath.join(tempDir, "Cellar", "package-tool", "1.0.0", "bin", "tool");
1165 writeExecutable(kegBinary);
1166
1167 const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(packageToolUpdate, {
1168 binaryPath: kegBinary,
1169 env: { PATH: "" },
1170 }).pipe(
1171 Effect.provideService(HostProcess.Platform, "darwin"),
1172 Effect.provideService(
1173 ChildProcessSpawner.ChildProcessSpawner,
1174 stdoutSpawner((_command, args) => (args[0] === "--prefix" ? `${tempDir}\n` : "{}")),
1175 ),
1176 );
1177
1178 expect(capabilities.update).toMatchObject({
1179 executable: brewPath,
1180 args: ["upgrade", "package-tool"],
1181 lockKey: "homebrew",
1182 });
1183 }),
1184 );
1185
1186 it.effect("starts a fresh read instead of joining the resolution already running", () =>
1187 Effect.gen(function* () {
1188 const releaseStale = yield* Deferred.make<void>();
1189 let resolutions = 0;
1190 const resolve = yield* makeCachedProviderMaintenanceResolution(
1191 Effect.suspend(() => {
1192 resolutions += 1;
1193 return resolutions === 1
1194 ? Deferred.await(releaseStale).pipe(Effect.as(manualPackageTool))
1195 : Effect.succeed(manualPackageTool);
1196 }),
1197 );
1198
1199 const advisory = yield* Effect.forkChild(resolve(), { startImmediately: true });
1200 const fresh = yield* Effect.forkChild(resolve({ fresh: true }), { startImmediately: true });
1201 expect(resolutions).toBe(2);
1202 expect(fresh.pollUnsafe()).toBeDefined();
1203 yield* Deferred.succeed(releaseStale, undefined);
1204 expect(yield* Fiber.join(fresh)).toEqual(manualPackageTool);
1205 yield* Fiber.join(advisory);
1206 }),
1207 );
1208
1209 it.effect("resolves again after the first read is interrupted", () =>
1210 Effect.gen(function* () {
1211 const release = yield* Deferred.make<void>();
1212 let resolutions = 0;
1213 const resolve = yield* makeCachedProviderMaintenanceResolution(
1214 Effect.suspend(() => {
1215 resolutions += 1;
1216 return resolutions === 1
1217 ? Effect.never
1218 : Deferred.await(release).pipe(Effect.as(manualPackageTool));
1219 }),
1220 );
1221
1222 const first = yield* Effect.forkChild(resolve(), { startImmediately: true });
1223 yield* Fiber.interrupt(first);
1224
1225 const owner = yield* Effect.forkChild(resolve(), { startImmediately: true });
1226 const waiter = yield* Effect.forkChild(resolve(), { startImmediately: true });
1227 yield* Fiber.interrupt(owner);
1228 yield* Deferred.succeed(release, undefined);
1229 expect(yield* Fiber.join(waiter)).toEqual(manualPackageTool);
1230 expect(yield* resolve()).toEqual(manualPackageTool);
1231 expect(resolutions).toBe(2);
1232 }),
1233 );
1234});
1235
1236it("pins only owned package-manager installs and preserves their execution context", () => {
1237 const capabilities = makeProviderMaintenanceCapabilities({
1238 provider: driver("codex"),
1239 packageName: "@openai/codex",
1240 updateExecutable: "npm",
1241 updateLockKey: "npm-global:/opt/node",
1242 updateArgs: [
1243 "install",
1244 "-g",
1245 "--prefix",
1246 "/opt/node",
1247 "--allow-scripts=@openai/codex",
1248 "@openai/codex@latest",
1249 ],
1250 env: { PATH: "/opt/node/bin" },
1251 });
1252 const pinned = makeTargetedProviderUpdateAction(capabilities, "2.0.0");
1253 expect(pinned).toMatchObject({
1254 executable: "npm",
1255 lockKey: capabilities.update?.lockKey,
1256 env: capabilities.update?.env,
1257 args: [
1258 "install",
1259 "-g",
1260 "--prefix",
1261 "/opt/node",
1262 "--allow-scripts=@openai/codex",
1263 "@openai/codex@2.0.0",
1264 ],
1265 });
1266 expect(pinned?.command).toContain("@openai/codex@2.0.0");
1267 for (const lockKey of ["codex-native", "homebrew", "manual"]) {
1268 expect(
1269 makeTargetedProviderUpdateAction(
1270 { ...capabilities, update: { ...capabilities.update!, lockKey } },
1271 "2.0.0",
1272 ),
1273 ).toBeNull();
1274 }
1275 expect(makeTargetedProviderUpdateAction(capabilities, "2.0.0; rm -rf /")).toBeNull();
1276});