Open History to see the last commit
1import * as CodexInstallation from "../CodexInstallation.ts";
2import * as CodexManagedTokenBroker from "../CodexManagedTokenBroker.ts";
3import * as ServerSecretStore from "../../auth/ServerSecretStore.ts";
4import * as ServerEnvironment from "../../environment/ServerEnvironment.ts";
5// @effect-diagnostics nodeBuiltinImport:off
6import * as NodeServices from "@effect/platform-node/NodeServices";
7import * as NodePath from "node:path";
8import { expect, it } from "@effect/vitest";
9import { EnvironmentId, ProviderInstanceId, ProviderSessionId, ThreadId } from "@t3tools/contracts";
10import * as HostProcess from "@t3tools/shared/HostProcess";
11import * as Effect from "effect/Effect";
12import * as Exit from "effect/Exit";
13import * as Deferred from "effect/Deferred";
14import * as Fiber from "effect/Fiber";
15import * as FileSystem from "effect/FileSystem";
16import * as Layer from "effect/Layer";
17import * as Option from "effect/Option";
18import * as PlatformError from "effect/PlatformError";
19import * as Schema from "effect/Schema";
20import * as Sink from "effect/Sink";
21import * as Stream from "effect/Stream";
22import { HttpClient, HttpClientResponse } from "effect/http";
23import * as ChildProcess from "effect/process/ChildProcess";
24import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
25
26import * as BackgroundPolicy from "../../background/BackgroundPolicy.ts";
27import * as ServerConfig from "../../config.ts";
28import * as ServerSettings from "../../serverSettings.ts";
29import * as ResetCreditCoordinator from "../resetCreditCoordinator.ts";
30import * as ProviderLatestVersions from "@t3tools/provider-core/server/ProviderLatestVersions";
31import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
32import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers";
33import * as ModelManifest from "../ModelManifest.ts";
34import {
35 createProviderVersionAdvisory,
36 resolveLatestProviderVersion,
37} from "@t3tools/provider-core/server/maintenanceResolver";
38import { CodexDriver } from "./CodexDriver.ts";
39import * as CodexAdapterV2 from "../../orchestration-v2/Adapters/CodexAdapterV2.ts";
40import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
41import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
42import * as ProviderCredentialStore from "../ProviderCredentialStore.ts";
43import * as ProviderHostLive from "../ProviderHostLive.ts";
44
45const layerDeps = ServerConfig.layerTest(process.cwd(), {
46 prefix: "t3-codex-driver-maintenance-",
47}).pipe(
48 Layer.provideMerge(NodeServices.layer),
49 Layer.provideMerge(IdAllocator.layer),
50 Layer.provideMerge(McpProviderSessions.layer),
51 Layer.provideMerge(
52 Layer.mock(CodexAdapterV2.CodexAppServerClientFactory)({
53 open: () => Effect.die("Maintenance resolution must not open a Codex session"),
54 }),
55 ),
56 Layer.provideMerge(
57 Layer.mock(CodexInstallation.CodexInstallation)({
58 managedDirectory: "unused-managed-installation",
59 }),
60 ),
61 Layer.provideMerge(Layer.mock(ServerSecretStore.ServerSecretStore)({})),
62 Layer.provideMerge(
63 Layer.mock(CodexManagedTokenBroker.CodexManagedTokenBroker)({
64 endpoint: Effect.succeed("unused-private-pipe"),
65 awaitIdle: Effect.void,
66 }),
67 ),
68 Layer.provideMerge(
69 Layer.succeed(ServerEnvironment.ServerEnvironmentIdentity, {
70 getEnvironmentId: Effect.succeed(EnvironmentId.make("00000000-0000-4000-8000-000000000001")),
71 }),
72 ),
73 Layer.provideMerge(ServerSettings.layerTest()),
74 Layer.provideMerge(ModelManifest.layerTest),
75 Layer.provideMerge(ResetCreditCoordinator.layerTest),
76 Layer.provideMerge(
77 Layer.mock(BackgroundPolicy.BackgroundPolicy)({
78 shouldRunScopeWork: () => Effect.succeed(false),
79 }),
80 ),
81 Layer.provideMerge(
82 Layer.succeed(
83 ProviderEventLoggers.ProviderEventLoggers,
84 ProviderEventLoggers.NoOpProviderEventLoggers,
85 ),
86 ),
87 Layer.provideMerge(ProviderLatestVersions.layer),
88 Layer.provideMerge(
89 Layer.succeed(
90 HttpClient.HttpClient,
91 HttpClient.make(() => Effect.die("Disabled Codex must not make an HTTP request")),
92 ),
93 ),
94);
95const layerTest = ProviderHostLive.layer.pipe(Layer.provideMerge(layerDeps));
96
97// The `#!/bin/sh` stub below cannot be resolved as an executable on Windows.
98const windowsHost = HostProcess.Platform.defaultValue() === "win32";
99
100const noSpawn = ChildProcessSpawner.make(() =>
101 Effect.die("Disabled Codex must not spawn a process"),
102);
103const encodeCredentials = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
104
105it.layer(layerTest)("CodexDriver", (it) => {
106 const checkManagedAccount = (replacementTiming: "unchanged" | "during-probe") =>
107 Effect.gen(function* () {
108 const instanceId = ProviderInstanceId.make("restored-managed-account");
109 const credentials = new Map<string, Uint8Array>();
110 const catalogTokens: Array<string | undefined> = [];
111 const probeEntered = yield* Deferred.make<void>();
112 const resumeProbe = yield* Deferred.make<void>();
113 const secrets = ServerSecretStore.ServerSecretStore.of({
114 get: (key) => Effect.sync(() => Option.fromUndefinedOr(credentials.get(key))),
115 set: (key, value) =>
116 Effect.sync(() => {
117 credentials.set(key, value);
118 }),
119 remove: (key) =>
120 Effect.sync(() => {
121 credentials.delete(key);
122 }),
123 create: () => Effect.die("unused"),
124 getOrCreateRandom: () => Effect.die("unused"),
125 });
126 yield* Effect.gen(function* () {
127 const store = yield* ProviderCredentialStore.make("codex-chatgpt", instanceId);
128 const json = yield* encodeCredentials({
129 clientId: "oaiapp_test",
130 accessToken: "dummy-owned-access",
131 refreshToken: "dummy-refresh",
132 expiresAt: Number.MAX_SAFE_INTEGER,
133 earliestRefreshAt: null,
134 scopes: ["chatgpt.tokens.use.direct"],
135 subject: "test-user",
136 email: "account@example.test",
137 });
138 yield* store.set(new TextEncoder().encode(json));
139 const replacement = yield* encodeCredentials({
140 clientId: "oaiapp_replacement",
141 subject: "replacement-user",
142 email: "replacement@example.test",
143 accessToken: "replacement-access",
144 refreshToken: "replacement-refresh",
145 expiresAt: Number.MAX_SAFE_INTEGER,
146 earliestRefreshAt: null,
147 scopes: ["chatgpt.tokens.use.direct"],
148 });
149 const replaceAccount = store.set(new TextEncoder().encode(replacement)).pipe(Effect.orDie);
150 const executable = {
151 executablePath: "/user/bin/codex",
152 managedVersionDirectory: null,
153 source: "local" as const,
154 version: "0.156.1",
155 };
156 const installation = yield* CodexInstallation.CodexInstallation;
157 const serverConfig = yield* ServerConfig.ServerConfig;
158 const sharedHome = NodePath.join(serverConfig.stateDir, "shared-codex-home");
159 const launches: Array<
160 Parameters<CodexAdapterV2.CodexAppServerClientFactoryShape["open"]>[0]
161 > = [];
162
163 let interruptedChecks = 0;
164 let failAcquire = false;
165 const startupChecksInterrupted = yield* Deferred.make<void>();
166 const acquire = () =>
167 Effect.suspend(() => {
168 if (failAcquire)
169 return Effect.fail(
170 new CodexInstallation.CodexInstallationError({
171 operation: "acquire",
172 detail: "The fixture runtime is unavailable",
173 }),
174 );
175 if (interruptedChecks === 2) return Effect.succeed(executable);
176 interruptedChecks += 1;
177 return (
178 interruptedChecks === 2
179 ? Deferred.succeed(startupChecksInterrupted, undefined)
180 : Effect.void
181 ).pipe(Effect.andThen(Effect.interrupt));
182 });
183 const instance = yield* CodexDriver.create({
184 instanceId,
185 displayName: "Restored account",
186 enabled: true,
187 environment: [{ name: "OPENAI_API_KEY", value: "ambient-key", sensitive: true }],
188 config: { ...CodexDriver.defaultConfig(), setupMode: "managed", homePath: sharedHome },
189 }).pipe(
190 Effect.provideService(
191 CodexAdapterV2.CodexAppServerClientFactory,
192 CodexAdapterV2.CodexAppServerClientFactory.of({
193 open: (launch) =>
194 Effect.sync(() => launches.push(launch)).pipe(
195 Effect.andThen(Effect.die("The fixture stops after recording the launch")),
196 ),
197 }),
198 ),
199 Effect.provideService(
200 CodexInstallation.CodexInstallation,
201 CodexInstallation.CodexInstallation.of({
202 ...installation,
203 managedDirectory: "unused-managed-installation",
204 resolve: () => Effect.succeed(executable),
205 acquire,
206 }),
207 ),
208 Effect.provideService(
209 ChildProcessSpawner.ChildProcessSpawner,
210 ChildProcessSpawner.make(() =>
211 Effect.gen(function* () {
212 if (replacementTiming === "during-probe") {
213 yield* Deferred.succeed(probeEntered, undefined);
214 yield* Deferred.await(resumeProbe);
215 }
216 return yield* PlatformError.badArgument({
217 module: "ChildProcessSpawner",
218 method: "spawn",
219 description: "The fixture app-server is unavailable",
220 });
221 }),
222 ),
223 ),
224 );
225 const observedAccount = yield* Deferred.make<void>();
226 const disconnected = yield* instance.snapshot.streamChanges.pipe(
227 Stream.tap((provider) =>
228 provider.auth.status === "authenticated"
229 ? Deferred.succeed(observedAccount, undefined).pipe(Effect.asVoid)
230 : Effect.void,
231 ),
232 Stream.filter((provider) => provider.auth.status === "unauthenticated"),
233 Stream.runHead,
234 Effect.forkScoped,
235 );
236 yield* Deferred.await(startupChecksInterrupted);
237 const refresh = yield* instance.snapshot.refresh.pipe(Effect.forkChild);
238 if (replacementTiming === "during-probe") {
239 yield* Deferred.await(probeEntered);
240 yield* replaceAccount;
241 yield* Deferred.succeed(resumeProbe, undefined);
242 }
243 const restored = yield* Fiber.join(refresh);
244 if (replacementTiming === "during-probe") {
245 expect(catalogTokens).toEqual([]);
246 expect(restored.models).toEqual([]);
247 expect(restored.auth.email).toBe("replacement@example.test");
248 expect(restored.auth.profileId).toBe("oaiapp_replacement");
249 return;
250 }
251 expect(catalogTokens).toEqual(["Bearer dummy-owned-access"]);
252 expect(restored.auth.email).toBe("account@example.test");
253 expect(restored.runtimePaths?.homePath).toBe(sharedHome);
254 expect(restored.runtimePaths?.shadowHomePath).toContain(
255 `providers/codex/${instanceId}/shadow`,
256 );
257 // The fixture app-server cannot start, so the workspace scan fails
258 // instead of passing the machine snapshot off as the workspace's skills.
259 const scan = yield* instance.snapshotForCwd!(serverConfig.stateDir).pipe(Effect.exit);
260 expect(Exit.isFailure(scan)).toBe(true);
261 // The account is still signed in, so a runtime that cannot start is a
262 // failed scan too, not the machine snapshot's inventory.
263 failAcquire = true;
264 const runtimeScan = yield* instance.snapshotForCwd!(serverConfig.stateDir).pipe(
265 Effect.exit,
266 );
267 failAcquire = false;
268 expect(Exit.isFailure(runtimeScan)).toBe(true);
269 yield* Deferred.await(observedAccount);
270
271 const threadId = ThreadId.make("managed-account-thread");
272 yield* instance.orchestrationAdapter
273 .openSession({
274 threadId,
275 providerSessionId: ProviderSessionId.make("managed-account-session"),
276 modelSelection: { instanceId, model: "gpt-5.4" },
277 runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
278 runtimeMode: "full-access",
279 interactionMode: "default",
280 cwd: serverConfig.stateDir,
281 }),
282 })
283 .pipe(Effect.scoped, Effect.exit);
284 expect(launches).toHaveLength(1);
285 const launch = launches[0]!;
286 expect(launch.settings.binaryPath).toBe(executable.executablePath);
287 expect(launch.settings.launchArgs).toContain("openai_token_sharing");
288 expect(launch.environment.ACCESS_TOKEN).toBeUndefined();
289 expect(launch.settings.launchArgs).toContain("__managed-chatgpt-token");
290 expect(launch.settings.launchArgs).not.toContain("dummy-owned-access");
291 expect(launch.environment.OPENAI_API_KEY).toBeUndefined();
292 expect(launch.environment.CODEX_HOME).toBe(launch.settings.homePath);
293 const before = yield* instance.auth!.subscribe("test-owner").pipe(Stream.runHead);
294 expect(Option.getOrThrow(before).phase).toBe("idle");
295 yield* instance.auth!.logout(Effect.void);
296 const after = Option.getOrThrow(yield* Fiber.join(disconnected));
297 expect(after.auth.status).toBe("unauthenticated");
298 expect(after.auth.email).toBeUndefined();
299 expect(after.installed).toBe(true);
300 expect(after.models).toEqual([]);
301 expect(Option.isNone(yield* store.get)).toBe(true);
302 // Signed out, there is no runtime to scan with, so the machine
303 // snapshot's empty inventory stands instead of a failed scan.
304 const signedOutScan = yield* instance.snapshotForCwd!(serverConfig.stateDir);
305 expect(signedOutScan.skills).toEqual([]);
306 }).pipe(
307 Effect.provideService(ServerSecretStore.ServerSecretStore, secrets),
308 Effect.provideService(
309 HttpClient.HttpClient,
310 HttpClient.make((request) =>
311 Effect.sync(() => {
312 expect([
313 "https://auth.openai.com/.well-known/openid-configuration",
314 "https://auth.openai.com/revoke",
315 "https://api.openai.com/v1/models",
316 ]).toContain(request.url);
317 if (request.url.endsWith("/models")) {
318 catalogTokens.push(request.headers.authorization);
319 return HttpClientResponse.fromWeb(request, Response.json({ models: [] }));
320 }
321 return HttpClientResponse.fromWeb(
322 request,
323 request.url.endsWith("/revoke")
324 ? new Response(null, { status: 200 })
325 : Response.json({
326 issuer: "https://auth.openai.com",
327 authorization_endpoint: "https://auth.openai.com/api/accounts/authorize",
328 token_endpoint: "https://auth.openai.com/api/accounts/oauth/token",
329 jwks_uri: "https://auth.openai.com/jwks",
330 revocation_endpoint: "https://auth.openai.com/revoke",
331 }),
332 );
333 }),
334 ),
335 ),
336 );
337 }).pipe(Effect.scoped);
338 // regression: a sign-in that replaces the account mid-probe must not label the old
339 // account's catalog with the new identity.
340 it.effect.each(["unchanged", "during-probe"] as const)(
341 "managed catalog keeps its account label and token together: %s",
342 checkManagedAccount,
343 );
344
345 it.effect.skipIf(windowsHost)(
346 "runs the standalone updater against the shared home, not the shadow home",
347 () =>
348 Effect.gen(function* () {
349 const fs = yield* FileSystem.FileSystem;
350 const tempDir = yield* fs
351 .makeTempDirectoryScoped({ prefix: "t3-codex-driver-" })
352 .pipe(Effect.flatMap((directory) => fs.realPath(directory)));
353 const sharedHome = NodePath.join(tempDir, "codex-home");
354 const shadowHome = NodePath.join(tempDir, "codex-shadow");
355 const binaryPath = NodePath.join(sharedHome, "packages", "standalone", "bin", "codex");
356 yield* fs.makeDirectory(NodePath.dirname(binaryPath), { recursive: true });
357 yield* fs.writeFileString(binaryPath, "#!/bin/sh\n");
358 yield* fs.chmod(binaryPath, 0o755);
359
360 const instance = yield* CodexDriver.create({
361 instanceId: ProviderInstanceId.make("codex-shadow"),
362 displayName: "Codex test",
363 enabled: false,
364 environment: [],
365 config: {
366 ...CodexDriver.defaultConfig(),
367 binaryPath,
368 homePath: sharedHome,
369 shadowHomePath: shadowHome,
370 },
371 });
372
373 const capabilities = yield* instance.snapshot.resolveMaintenance();
374 expect(capabilities.update).toMatchObject({
375 executable: binaryPath,
376 args: ["update"],
377 lockKey: "codex-native",
378 env: { CODEX_HOME: sharedHome },
379 });
380 }).pipe(
381 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn),
382 Effect.scoped,
383 ),
384 );
385
386 for (const fixture of [
387 {
388 name: "leaves mise npm-backend installations manual-only",
389 installSegments: ["mise", "installs", "npm-openai-codex", "0.110.0"],
390 npmOwned: false,
391 },
392 {
393 name: "leaves mise tool aliases backed by npm manual-only",
394 installSegments: ["mise", "installs", "codex", "0.110.0"],
395 npmOwned: false,
396 },
397 {
398 name: "keeps npm updates for globals in a mise Node installation",
399 installSegments: ["mise", "installs", "node", "24.0.0"],
400 npmOwned: true,
401 },
402 {
403 name: "keeps npm updates for ordinary global installations",
404 installSegments: ["npm-global"],
405 npmOwned: true,
406 },
407 ] as const) {
408 it.effect.skipIf(windowsHost)(fixture.name, () =>
409 Effect.gen(function* () {
410 const fs = yield* FileSystem.FileSystem;
411 const tempDir = yield* fs
412 .makeTempDirectoryScoped({ prefix: "t3-codex-installer-" })
413 .pipe(Effect.flatMap((directory) => fs.realPath(directory)));
414 const installPath = NodePath.join(tempDir, ...fixture.installSegments);
415 const realBinaryPath = NodePath.join(
416 installPath,
417 "lib",
418 "node_modules",
419 "@openai",
420 "codex",
421 "bin",
422 "codex.js",
423 );
424 const binaryPath = NodePath.join(tempDir, "bin", "codex");
425 yield* fs.makeDirectory(NodePath.dirname(realBinaryPath), { recursive: true });
426 yield* fs.makeDirectory(NodePath.dirname(binaryPath), { recursive: true });
427 yield* fs.writeFileString(realBinaryPath, "#!/bin/sh\n");
428 yield* fs.chmod(realBinaryPath, 0o755);
429 yield* fs.symlink(realBinaryPath, binaryPath);
430
431 const instance = yield* CodexDriver.create({
432 instanceId: ProviderInstanceId.make("codex-installer"),
433 displayName: "Codex installer test",
434 enabled: false,
435 environment: [],
436 config: {
437 ...CodexDriver.defaultConfig(),
438 binaryPath,
439 homePath: NodePath.join(tempDir, "codex-home"),
440 },
441 });
442
443 const update = (yield* instance.snapshot.resolveMaintenance()).update;
444 if (fixture.npmOwned) {
445 expect(update).toMatchObject({
446 executable: "npm",
447 args: [
448 "install",
449 "-g",
450 "--prefix",
451 installPath,
452 "--allow-scripts=@openai/codex",
453 "@openai/codex@latest",
454 ],
455 });
456 } else {
457 expect(update).toBeNull();
458 }
459 }).pipe(
460 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn),
461 Effect.scoped,
462 ),
463 );
464 }
465
466 for (const {} of ["direct", "wrapper"] as const) {
467 }
468
469 it.effect.each([
470 {
471 name: "conventional shim",
472 dataRoot: "mise",
473 commandName: "codex",
474 version: "0.153.4",
475 nodeFirst: false,
476 },
477 {
478 name: "custom data directory",
479 dataRoot: "custom-tool-data",
480 commandName: "codex",
481 version: "0.153.4",
482 nodeFirst: false,
483 },
484 {
485 name: "renamed configured command",
486 dataRoot: "mise",
487 commandName: "custom-codex",
488 version: "0.153.4",
489 nodeFirst: false,
490 },
491 {
492 name: "outdated provider",
493 dataRoot: "mise",
494 commandName: "codex",
495 version: "0.153.3",
496 nodeFirst: false,
497 },
498 {
499 name: "npm before shim",
500 dataRoot: "mise",
501 commandName: "codex",
502 version: "0.153.4",
503 nodeFirst: true,
504 },
505 ])(
506 "does not mistake Homebrew mise for Codex's installer: $name",
507 (fixture) =>
508 Effect.gen(function* () {
509 const fs = yield* FileSystem.FileSystem;
510 const tempDir = yield* fs
511 .makeTempDirectoryScoped({ prefix: "t3-codex-mise-shim-" })
512 .pipe(Effect.flatMap((directory) => fs.realPath(directory)));
513 const brewPrefix = NodePath.join(tempDir, "homebrew");
514 const brewPath = NodePath.join(brewPrefix, "bin", "brew");
515 const misePath = NodePath.join(brewPrefix, "Cellar", "mise", "2026.9.1", "bin", "mise");
516 const shimDir = NodePath.join(tempDir, fixture.dataRoot, "shims");
517 const npmPrefix = NodePath.join(tempDir, "mise", "installs", "node", "24.13.0");
518 const npmBin = NodePath.join(npmPrefix, "bin");
519 const npmEntry = NodePath.join(
520 npmPrefix,
521 "lib",
522 "node_modules",
523 "@openai",
524 "codex",
525 "bin",
526 "codex.js",
527 );
528 for (const file of [brewPath, misePath, npmEntry]) {
529 yield* fs.makeDirectory(NodePath.dirname(file), { recursive: true });
530 yield* fs.writeFileString(file, "#!/bin/sh\n");
531 yield* fs.chmod(file, 0o755);
532 }
533 yield* fs.makeDirectory(shimDir, { recursive: true });
534 yield* fs.makeDirectory(npmBin, { recursive: true });
535 yield* fs.symlink(misePath, NodePath.join(shimDir, fixture.commandName));
536 yield* fs.symlink(npmEntry, NodePath.join(npmBin, fixture.commandName));
537 const lookupPath = [
538 ...(fixture.nodeFirst ? [npmBin, shimDir] : [shimDir, npmBin]),
539 NodePath.dirname(brewPath),
540 ].join(NodePath.delimiter);
541 const probes: Array<ReadonlyArray<string>> = [];
542 const metadataSpawner = ChildProcessSpawner.make((command) => {
543 if (!ChildProcess.isStandardCommand(command) || command.command !== brewPath) {
544 return Effect.die("Provider resolution must not execute a provider or updater");
545 }
546 probes.push(command.args);
547 const stdout =
548 command.args[0] === "--prefix"
549 ? brewPrefix
550 : JSON.stringify({ formulae: [{ versions: { stable: "2026.9.1" } }] });
551 return Effect.succeed(
552 ChildProcessSpawner.makeHandle({
553 pid: ChildProcessSpawner.ProcessId(1),
554 exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)),
555 isRunning: Effect.succeed(false),
556 kill: () => Effect.void,
557 unref: Effect.succeed(Effect.void),
558 stdin: Sink.drain,
559 stdout: Stream.encodeText(Stream.make(stdout)),
560 stderr: Stream.empty,
561 all: Stream.empty,
562 getInputFd: () => Sink.drain,
563 getOutputFd: () => Stream.empty,
564 }),
565 );
566 });
567 const instance = yield* CodexDriver.create({
568 instanceId: ProviderInstanceId.make("codex-mise-shim"),
569 displayName: "Codex shim test",
570 enabled: false,
571 environment: [{ name: "PATH", value: lookupPath, sensitive: false }],
572 config: {
573 ...CodexDriver.defaultConfig(),
574 binaryPath: fixture.commandName,
575 homePath: NodePath.join(tempDir, "codex-home"),
576 },
577 }).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, metadataSpawner));
578 const capabilities = yield* instance.snapshot.resolveMaintenance();
579 const latestVersion = yield* resolveLatestProviderVersion(capabilities).pipe(
580 Effect.provideServiceEffect(
581 ProviderLatestVersions.ProviderLatestVersions,
582 ProviderLatestVersions.make([["@openai/codex", "0.153.4"]]),
583 ),
584 );
585 expect(probes).toEqual([]);
586 expect(latestVersion).toBe("0.153.4");
587 expect(
588 createProviderVersionAdvisory({
589 driver: CodexDriver.driverKind,
590 currentVersion: fixture.version,
591 latestVersion,
592 maintenanceCapabilities: capabilities,
593 }),
594 ).toMatchObject({
595 status: fixture.version === "0.153.4" ? "current" : "behind_latest",
596 currentVersion: fixture.version,
597 latestVersion: "0.153.4",
598 canUpdate: fixture.nodeFirst,
599 });
600 if (fixture.nodeFirst) {
601 expect(capabilities.update).toMatchObject({
602 executable: "npm",
603 args: expect.arrayContaining([
604 "--prefix",
605 yield* fs.realPath(npmPrefix),
606 "@openai/codex@latest",
607 ]),
608 });
609 } else {
610 expect(capabilities.update).toBeNull();
611 }
612 }).pipe(Effect.scoped),
613 { skip: windowsHost },
614 );
615});