| ... | @@ -8,7 +8,10 @@ import { HostProcessPlatform } from "@t3tools/shared/hostProcess"; | ... | @@ -8,7 +8,10 @@ import { HostProcessPlatform } from "@t3tools/shared/hostProcess"; |
| 8 | import * as Effect from "effect/Effect"; | 8 | import * as Effect from "effect/Effect"; |
| 9 | import * as FileSystem from "effect/FileSystem"; | 9 | import * as FileSystem from "effect/FileSystem"; |
| 10 | import * as Layer from "effect/Layer"; | 10 | import * as Layer from "effect/Layer"; |
| | 11 | import * as Sink from "effect/Sink"; |
| | 12 | import * as Stream from "effect/Stream"; |
| 11 | import { HttpClient } from "effect/unstable/http"; | 13 | import { HttpClient } from "effect/unstable/http"; |
| | 14 | import * as ChildProcess from "effect/unstable/process/ChildProcess"; |
| 12 | import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner"; | 15 | import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner"; |
| 13 | | 16 | |
| 14 | import * as BackgroundPolicy from "../../background/BackgroundPolicy.ts"; | 17 | import * as BackgroundPolicy from "../../background/BackgroundPolicy.ts"; |
| ... | @@ -17,6 +20,11 @@ import { ServerSettingsService } from "../../serverSettings.ts"; | ... | @@ -17,6 +20,11 @@ import { ServerSettingsService } from "../../serverSettings.ts"; |
| 17 | import { layerTest as codexResetCreditLayerTest } from "../Layers/codexResetCredit.ts"; | 20 | import { layerTest as codexResetCreditLayerTest } from "../Layers/codexResetCredit.ts"; |
| 18 | import { NoOpProviderEventLoggers, ProviderEventLoggers } from "../Layers/ProviderEventLoggers.ts"; | 21 | import { NoOpProviderEventLoggers, ProviderEventLoggers } from "../Layers/ProviderEventLoggers.ts"; |
| 19 | import * as ModelManifest from "../ModelManifest.ts"; | 22 | import * as ModelManifest from "../ModelManifest.ts"; |
| | 23 | import { |
| | 24 | createProviderVersionAdvisory, |
| | 25 | ProviderVersionCache, |
| | 26 | resolveLatestProviderVersion, |
| | 27 | } from "../providerMaintenance.ts"; |
| 20 | import { CodexDriver } from "./CodexDriver.ts"; | 28 | import { CodexDriver } from "./CodexDriver.ts"; |
| 21 | | 29 | |
| 22 | const testLayer = ServerConfig.layerTest(process.cwd(), { | 30 | const testLayer = ServerConfig.layerTest(process.cwd(), { |
| ... | @@ -218,4 +226,147 @@ it.layer(testLayer)("CodexDriver", (it) => { | ... | @@ -218,4 +226,147 @@ it.layer(testLayer)("CodexDriver", (it) => { |
| 218 | ), | 226 | ), |
| 219 | ); | 227 | ); |
| 220 | } | 228 | } |
| | 229 | |
| | 230 | it.effect.each([ |
| | 231 | { |
| | 232 | name: "conventional shim", |
| | 233 | dataRoot: "mise", |
| | 234 | commandName: "codex", |
| | 235 | version: "0.153.4", |
| | 236 | nodeFirst: false, |
| | 237 | }, |
| | 238 | { |
| | 239 | name: "custom data directory", |
| | 240 | dataRoot: "custom-tool-data", |
| | 241 | commandName: "codex", |
| | 242 | version: "0.153.4", |
| | 243 | nodeFirst: false, |
| | 244 | }, |
| | 245 | { |
| | 246 | name: "renamed configured command", |
| | 247 | dataRoot: "mise", |
| | 248 | commandName: "custom-codex", |
| | 249 | version: "0.153.4", |
| | 250 | nodeFirst: false, |
| | 251 | }, |
| | 252 | { |
| | 253 | name: "outdated provider", |
| | 254 | dataRoot: "mise", |
| | 255 | commandName: "codex", |
| | 256 | version: "0.153.3", |
| | 257 | nodeFirst: false, |
| | 258 | }, |
| | 259 | { |
| | 260 | name: "npm before shim", |
| | 261 | dataRoot: "mise", |
| | 262 | commandName: "codex", |
| | 263 | version: "0.153.4", |
| | 264 | nodeFirst: true, |
| | 265 | }, |
| | 266 | ])( |
| | 267 | "does not mistake Homebrew mise for Codex's installer: $name", |
| | 268 | (fixture) => |
| | 269 | Effect.gen(function* () { |
| | 270 | const fs = yield* FileSystem.FileSystem; |
| | 271 | const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-codex-mise-shim-" }); |
| | 272 | const brewPrefix = NodePath.join(tempDir, "homebrew"); |
| | 273 | const brewPath = NodePath.join(brewPrefix, "bin", "brew"); |
| | 274 | const misePath = NodePath.join(brewPrefix, "Cellar", "mise", "2026.9.1", "bin", "mise"); |
| | 275 | const shimDir = NodePath.join(tempDir, fixture.dataRoot, "shims"); |
| | 276 | const npmPrefix = NodePath.join(tempDir, "mise", "installs", "node", "24.13.0"); |
| | 277 | const npmBin = NodePath.join(npmPrefix, "bin"); |
| | 278 | const npmEntry = NodePath.join( |
| | 279 | npmPrefix, |
| | 280 | "lib", |
| | 281 | "node_modules", |
| | 282 | "@openai", |
| | 283 | "codex", |
| | 284 | "bin", |
| | 285 | "codex.js", |
| | 286 | ); |
| | 287 | for (const file of [brewPath, misePath, npmEntry]) { |
| | 288 | yield* fs.makeDirectory(NodePath.dirname(file), { recursive: true }); |
| | 289 | yield* fs.writeFileString(file, "#!/bin/sh\n"); |
| | 290 | yield* fs.chmod(file, 0o755); |
| | 291 | } |
| | 292 | yield* fs.makeDirectory(shimDir, { recursive: true }); |
| | 293 | yield* fs.makeDirectory(npmBin, { recursive: true }); |
| | 294 | yield* fs.symlink(misePath, NodePath.join(shimDir, fixture.commandName)); |
| | 295 | yield* fs.symlink(npmEntry, NodePath.join(npmBin, fixture.commandName)); |
| | 296 | const lookupPath = [ |
| | 297 | ...(fixture.nodeFirst ? [npmBin, shimDir] : [shimDir, npmBin]), |
| | 298 | NodePath.dirname(brewPath), |
| | 299 | ].join(NodePath.delimiter); |
| | 300 | const probes: Array<ReadonlyArray<string>> = []; |
| | 301 | const metadataSpawner = ChildProcessSpawner.make((command) => { |
| | 302 | if (!ChildProcess.isStandardCommand(command) || command.command !== brewPath) { |
| | 303 | return Effect.die("Provider resolution must not execute a provider or updater"); |
| | 304 | } |
| | 305 | probes.push(command.args); |
| | 306 | const stdout = |
| | 307 | command.args[0] === "--prefix" |
| | 308 | ? brewPrefix |
| | 309 | : JSON.stringify({ formulae: [{ versions: { stable: "2026.9.1" } }] }); |
| | 310 | return Effect.succeed( |
| | 311 | ChildProcessSpawner.makeHandle({ |
| | 312 | pid: ChildProcessSpawner.ProcessId(1), |
| | 313 | exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)), |
| | 314 | isRunning: Effect.succeed(false), |
| | 315 | kill: () => Effect.void, |
| | 316 | unref: Effect.succeed(Effect.void), |
| | 317 | stdin: Sink.drain, |
| | 318 | stdout: Stream.encodeText(Stream.make(stdout)), |
| | 319 | stderr: Stream.empty, |
| | 320 | all: Stream.empty, |
| | 321 | getInputFd: () => Sink.drain, |
| | 322 | getOutputFd: () => Stream.empty, |
| | 323 | }), |
| | 324 | ); |
| | 325 | }); |
| | 326 | const instance = yield* CodexDriver.create({ |
| | 327 | instanceId: ProviderInstanceId.make("codex-mise-shim"), |
| | 328 | displayName: "Codex shim test", |
| | 329 | enabled: false, |
| | 330 | environment: [{ name: "PATH", value: lookupPath, sensitive: false }], |
| | 331 | config: { |
| | 332 | ...CodexDriver.defaultConfig(), |
| | 333 | binaryPath: fixture.commandName, |
| | 334 | homePath: NodePath.join(tempDir, "codex-home"), |
| | 335 | }, |
| | 336 | }).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, metadataSpawner)); |
| | 337 | const capabilities = yield* instance.snapshot.resolveMaintenance(); |
| | 338 | const latestVersion = yield* resolveLatestProviderVersion(capabilities).pipe( |
| | 339 | Effect.provideService( |
| | 340 | ProviderVersionCache, |
| | 341 | new Map([ |
| | 342 | ["@openai/codex", { expiresAt: Number.MAX_SAFE_INTEGER, version: "0.153.4" }], |
| | 343 | ]), |
| | 344 | ), |
| | 345 | ); |
| | 346 | expect(probes).toEqual([]); |
| | 347 | expect(latestVersion).toBe("0.153.4"); |
| | 348 | expect( |
| | 349 | createProviderVersionAdvisory({ |
| | 350 | driver: CodexDriver.driverKind, |
| | 351 | currentVersion: fixture.version, |
| | 352 | latestVersion, |
| | 353 | maintenanceCapabilities: capabilities, |
| | 354 | }), |
| | 355 | ).toMatchObject({ |
| | 356 | status: fixture.version === "0.153.4" ? "current" : "behind_latest", |
| | 357 | currentVersion: fixture.version, |
| | 358 | latestVersion: "0.153.4", |
| | 359 | canUpdate: fixture.nodeFirst, |
| | 360 | }); |
| | 361 | if (fixture.nodeFirst) { |
| | 362 | expect(capabilities.update).toMatchObject({ |
| | 363 | executable: "npm", |
| | 364 | args: expect.arrayContaining(["--prefix", npmPrefix, "@openai/codex@latest"]), |
| | 365 | }); |
| | 366 | } else { |
| | 367 | expect(capabilities.update).toBeNull(); |
| | 368 | } |
| | 369 | }).pipe(Effect.scoped), |
| | 370 | { skip: windowsHost }, |
| | 371 | ); |
| 221 | }); | 372 | }); |