| ... | ... | @@ -1,8 +1,19 @@ |
| 1 | | import { describe, expect, it } from "vite-plus/test"; |
| 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | 2 | import { ProviderDriverKind, type ModelCapabilities } from "@t3tools/contracts"; |
| 3 | import { HostProcessPlatform } from "@t3tools/shared/hostProcess"; |
| 3 | 4 | import { createModelCapabilities } from "@t3tools/shared/model"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Layer from "effect/Layer"; |
| 7 | import * as PlatformError from "effect/PlatformError"; |
| 8 | import * as Sink from "effect/Sink"; |
| 9 | import * as Stream from "effect/Stream"; |
| 10 | import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"; |
| 4 | 11 | |
| 5 | | import { providerModelsFromSettings } from "./providerSnapshot.ts"; |
| 12 | import { |
| 13 | isCommandMissingCause, |
| 14 | providerModelsFromSettings, |
| 15 | spawnAndCollect, |
| 16 | } from "./providerSnapshot.ts"; |
| 6 | 17 | |
| 7 | 18 | const OPENCODE_CUSTOM_MODEL_CAPABILITIES: ModelCapabilities = createModelCapabilities({ |
| 8 | 19 | optionDescriptors: [ |
| ... | ... | @@ -42,3 +53,66 @@ describe("providerModelsFromSettings", () => { |
| 42 | 53 | ]); |
| 43 | 54 | }); |
| 44 | 55 | }); |
| 56 | |
| 57 | describe("ProviderCommandNotFoundError", () => { |
| 58 | it("classifies normalized platform failures without parsing messages", () => { |
| 59 | expect( |
| 60 | isCommandMissingCause( |
| 61 | PlatformError.systemError({ |
| 62 | _tag: "NotFound", |
| 63 | module: "ChildProcess", |
| 64 | method: "spawn", |
| 65 | description: "arbitrary host detail", |
| 66 | }), |
| 67 | ), |
| 68 | ).toBe(true); |
| 69 | expect(isCommandMissingCause(new Error("spawn provider ENOENT"))).toBe(false); |
| 70 | }); |
| 71 | |
| 72 | it.effect("retains safe failed-command diagnostics without process output", () => { |
| 73 | const stderr = "'codex' is not recognized: secret-token-value"; |
| 74 | const spawner = ChildProcessSpawner.make(() => |
| 75 | Effect.succeed( |
| 76 | ChildProcessSpawner.makeHandle({ |
| 77 | pid: ChildProcessSpawner.ProcessId(1), |
| 78 | exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(9009)), |
| 79 | isRunning: Effect.succeed(false), |
| 80 | kill: () => Effect.void, |
| 81 | unref: Effect.succeed(Effect.void), |
| 82 | stdin: Sink.drain, |
| 83 | stdout: Stream.empty, |
| 84 | stderr: Stream.encodeText(Stream.make(stderr)), |
| 85 | all: Stream.empty, |
| 86 | getInputFd: () => Sink.drain, |
| 87 | getOutputFd: () => Stream.empty, |
| 88 | }), |
| 89 | ), |
| 90 | ); |
| 91 | return Effect.gen(function* () { |
| 92 | const error = yield* spawnAndCollect( |
| 93 | "C:\\tools\\codex.cmd", |
| 94 | ChildProcess.make("codex", ["--version"]), |
| 95 | ).pipe( |
| 96 | Effect.provide(Layer.succeed(ChildProcessSpawner.ChildProcessSpawner, spawner)), |
| 97 | Effect.provideService(HostProcessPlatform, "win32"), |
| 98 | Effect.flip, |
| 99 | ); |
| 100 | |
| 101 | if (error._tag !== "ProviderCommandNotFoundError") { |
| 102 | throw new Error(`Unexpected error: ${error._tag}`); |
| 103 | } |
| 104 | |
| 105 | expect(error.binaryPath).toBe("C:\\tools\\codex.cmd"); |
| 106 | expect(error.exitCode).toBe(9009); |
| 107 | expect(error.stdoutLength).toBe(0); |
| 108 | expect(error.stderrLength).toBe(stderr.length); |
| 109 | expect(error.message).toBe( |
| 110 | "Provider command C:\\tools\\codex.cmd was not found (exit code 9009).", |
| 111 | ); |
| 112 | expect(isCommandMissingCause(error)).toBe(true); |
| 113 | expect(error).not.toHaveProperty("stdout"); |
| 114 | expect(error).not.toHaveProperty("stderr"); |
| 115 | expect(error.message).not.toContain("secret-token-value"); |
| 116 | }); |
| 117 | }); |
| 118 | }); |