Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

CodexDriver.test.ts

636 lines25.5 KB

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