| ... | @@ -2,7 +2,6 @@ import { assert, it } from "@effect/vitest"; | ... | @@ -2,7 +2,6 @@ import { assert, it } from "@effect/vitest"; |
| 2 | import { Effect, Layer, Sink, Stream } from "effect"; | 2 | import { Effect, Layer, Sink, Stream } from "effect"; |
| 3 | import * as PlatformError from "effect/PlatformError"; | 3 | import * as PlatformError from "effect/PlatformError"; |
| 4 | import { ChildProcessSpawner } from "effect/unstable/process"; | 4 | import { ChildProcessSpawner } from "effect/unstable/process"; |
| 5 | import { expect } from "vitest"; | | |
| 6 | | 5 | |
| 7 | import { checkCodexProviderStatus, parseAuthStatusFromOutput } from "./ProviderHealth"; | 6 | import { checkCodexProviderStatus, parseAuthStatusFromOutput } from "./ProviderHealth"; |
| 8 | | 7 | |
| ... | @@ -56,17 +55,13 @@ function failingSpawnerLayer(description: string) { | ... | @@ -56,17 +55,13 @@ function failingSpawnerLayer(description: string) { |
| 56 | // ── Tests ─────────────────────────────────────────────────────────── | 55 | // ── Tests ─────────────────────────────────────────────────────────── |
| 57 | | 56 | |
| 58 | it.effect("returns ready when codex is installed and authenticated", () => | 57 | it.effect("returns ready when codex is installed and authenticated", () => |
| 59 | checkCodexProviderStatus.pipe( | 58 | Effect.gen(function* () { |
| 60 | Effect.map((status) => { | 59 | const status = yield* checkCodexProviderStatus; |
| 61 | expect(status).toEqual( | 60 | assert.strictEqual(status.provider, "codex"); |
| 62 | expect.objectContaining({ | 61 | assert.strictEqual(status.status, "ready"); |
| 63 | provider: "codex", | 62 | assert.strictEqual(status.available, true); |
| 64 | status: "ready", | 63 | assert.strictEqual(status.authStatus, "authenticated"); |
| 65 | available: true, | 64 | }).pipe( |
| 66 | authStatus: "authenticated", | | |
| 67 | }), | | |
| 68 | ); | | |
| 69 | }), | | |
| 70 | Effect.provide( | 65 | Effect.provide( |
| 71 | mockSpawnerLayer((args) => { | 66 | mockSpawnerLayer((args) => { |
| 72 | const joined = args.join(" "); | 67 | const joined = args.join(" "); |
| ... | @@ -79,35 +74,28 @@ it.effect("returns ready when codex is installed and authenticated", () => | ... | @@ -79,35 +74,28 @@ it.effect("returns ready when codex is installed and authenticated", () => |
| 79 | ); | 74 | ); |
| 80 | | 75 | |
| 81 | it.effect("returns unavailable when codex is missing", () => | 76 | it.effect("returns unavailable when codex is missing", () => |
| 82 | checkCodexProviderStatus.pipe( | 77 | Effect.gen(function* () { |
| 83 | Effect.map((status) => { | 78 | const status = yield* checkCodexProviderStatus; |
| 84 | expect(status).toEqual( | 79 | assert.strictEqual(status.provider, "codex"); |
| 85 | expect.objectContaining({ | 80 | assert.strictEqual(status.status, "error"); |
| 86 | provider: "codex", | 81 | assert.strictEqual(status.available, false); |
| 87 | status: "error", | 82 | assert.strictEqual(status.authStatus, "unknown"); |
| 88 | available: false, | 83 | assert.strictEqual(status.message, "Codex CLI (`codex`) is not installed or not on PATH."); |
| 89 | authStatus: "unknown", | 84 | }).pipe(Effect.provide(failingSpawnerLayer("spawn codex ENOENT"))), |
| 90 | message: "Codex CLI (`codex`) is not installed or not on PATH.", | | |
| 91 | }), | | |
| 92 | ); | | |
| 93 | }), | | |
| 94 | Effect.provide(failingSpawnerLayer("spawn codex ENOENT")), | | |
| 95 | ), | | |
| 96 | ); | 85 | ); |
| 97 | | 86 | |
| 98 | it.effect("returns unauthenticated when auth probe reports login required", () => | 87 | it.effect("returns unauthenticated when auth probe reports login required", () => |
| 99 | checkCodexProviderStatus.pipe( | 88 | Effect.gen(function* () { |
| 100 | Effect.map((status) => { | 89 | const status = yield* checkCodexProviderStatus; |
| 101 | expect(status).toEqual( | 90 | assert.strictEqual(status.provider, "codex"); |
| 102 | expect.objectContaining({ | 91 | assert.strictEqual(status.status, "error"); |
| 103 | provider: "codex", | 92 | assert.strictEqual(status.available, true); |
| 104 | status: "error", | 93 | assert.strictEqual(status.authStatus, "unauthenticated"); |
| 105 | available: true, | 94 | assert.strictEqual( |
| 106 | authStatus: "unauthenticated", | 95 | status.message, |
| 107 | message: "Codex CLI is not authenticated. Run `codex login` and try again.", | 96 | "Codex CLI is not authenticated. Run `codex login` and try again.", |
| 108 | }), | 97 | ); |
| 109 | ); | 98 | }).pipe( |
| 110 | }), | | |
| 111 | Effect.provide( | 99 | Effect.provide( |
| 112 | mockSpawnerLayer((args) => { | 100 | mockSpawnerLayer((args) => { |
| 113 | const joined = args.join(" "); | 101 | const joined = args.join(" "); |
| ... | @@ -121,43 +109,44 @@ it.effect("returns unauthenticated when auth probe reports login required", () = | ... | @@ -121,43 +109,44 @@ it.effect("returns unauthenticated when auth probe reports login required", () = |
| 121 | ), | 109 | ), |
| 122 | ); | 110 | ); |
| 123 | | 111 | |
| 124 | it.effect("returns unauthenticated when login status output includes 'not logged in'", () => | 112 | it.effect( |
| 125 | checkCodexProviderStatus.pipe( | 113 | "returns unauthenticated when login status output includes 'not logged in'", |
| 126 | Effect.map((status) => { | 114 | () => |
| 127 | expect(status).toEqual( | 115 | Effect.gen(function* () { |
| 128 | expect.objectContaining({ | 116 | const status = yield* checkCodexProviderStatus; |
| 129 | provider: "codex", | 117 | assert.strictEqual(status.provider, "codex"); |
| 130 | status: "error", | 118 | assert.strictEqual(status.status, "error"); |
| 131 | available: true, | 119 | assert.strictEqual(status.available, true); |
| 132 | authStatus: "unauthenticated", | 120 | assert.strictEqual(status.authStatus, "unauthenticated"); |
| 133 | message: "Codex CLI is not authenticated. Run `codex login` and try again.", | 121 | assert.strictEqual( |
| 134 | }), | 122 | status.message, |
| | 123 | "Codex CLI is not authenticated. Run `codex login` and try again.", |
| 135 | ); | 124 | ); |
| 136 | }), | 125 | }).pipe( |
| 137 | Effect.provide( | 126 | Effect.provide( |
| 138 | mockSpawnerLayer((args) => { | 127 | mockSpawnerLayer((args) => { |
| 139 | const joined = args.join(" "); | 128 | const joined = args.join(" "); |
| 140 | if (joined === "--version") return { stdout: "codex 1.0.0\n", stderr: "", code: 0 }; | 129 | if (joined === "--version") return { stdout: "codex 1.0.0\n", stderr: "", code: 0 }; |
| 141 | if (joined === "login status") return { stdout: "Not logged in\n", stderr: "", code: 1 }; | 130 | if (joined === "login status") |
| 142 | throw new Error(`Unexpected args: ${joined}`); | 131 | return { stdout: "Not logged in\n", stderr: "", code: 1 }; |
| 143 | }), | 132 | throw new Error(`Unexpected args: ${joined}`); |
| | 133 | }), |
| | 134 | ), |
| 144 | ), | 135 | ), |
| 145 | ), | | |
| 146 | ); | 136 | ); |
| 147 | | 137 | |
| 148 | it.effect("returns warning when login status command is unsupported", () => | 138 | it.effect("returns warning when login status command is unsupported", () => |
| 149 | checkCodexProviderStatus.pipe( | 139 | Effect.gen(function* () { |
| 150 | Effect.map((status) => { | 140 | const status = yield* checkCodexProviderStatus; |
| 151 | expect(status).toEqual( | 141 | assert.strictEqual(status.provider, "codex"); |
| 152 | expect.objectContaining({ | 142 | assert.strictEqual(status.status, "warning"); |
| 153 | provider: "codex", | 143 | assert.strictEqual(status.available, true); |
| 154 | status: "warning", | 144 | assert.strictEqual(status.authStatus, "unknown"); |
| 155 | available: true, | 145 | assert.strictEqual( |
| 156 | authStatus: "unknown", | 146 | status.message, |
| 157 | message: "Codex CLI authentication status command is unavailable in this Codex version.", | 147 | "Codex CLI authentication status command is unavailable in this Codex version.", |
| 158 | }), | 148 | ); |
| 159 | ); | 149 | }).pipe( |
| 160 | }), | | |
| 161 | Effect.provide( | 150 | Effect.provide( |
| 162 | mockSpawnerLayer((args) => { | 151 | mockSpawnerLayer((args) => { |
| 163 | const joined = args.join(" "); | 152 | const joined = args.join(" "); |