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