| ... | @@ -3,8 +3,10 @@ import * as NodeAssert from "node:assert/strict"; | ... | @@ -3,8 +3,10 @@ import * as NodeAssert from "node:assert/strict"; |
| 3 | import * as NodeServices from "@effect/platform-node/NodeServices"; | 3 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 4 | import { it } from "@effect/vitest"; | 4 | import { it } from "@effect/vitest"; |
| 5 | import * as Effect from "effect/Effect"; | 5 | import * as Effect from "effect/Effect"; |
| | 6 | import * as Fiber from "effect/Fiber"; |
| 6 | import * as Layer from "effect/Layer"; | 7 | import * as Layer from "effect/Layer"; |
| 7 | import * as Schema from "effect/Schema"; | 8 | import * as Schema from "effect/Schema"; |
| | 9 | import * as TestClock from "effect/testing/TestClock"; |
| 8 | import { beforeEach } from "vite-plus/test"; | 10 | import { beforeEach } from "vite-plus/test"; |
| 9 | | 11 | |
| 10 | import { OpenCodeSettings } from "@t3tools/contracts"; | 12 | import { OpenCodeSettings } from "@t3tools/contracts"; |
| ... | @@ -34,6 +36,7 @@ const DEFAULT_VERSION_STDOUT = "opencode 1.14.19\n"; | ... | @@ -34,6 +36,7 @@ const DEFAULT_VERSION_STDOUT = "opencode 1.14.19\n"; |
| 34 | const runtimeMock = { | 36 | const runtimeMock = { |
| 35 | state: { | 37 | state: { |
| 36 | runVersionError: null as Error | null, | 38 | runVersionError: null as Error | null, |
| | 39 | runVersionPending: false, |
| 37 | versionStdout: DEFAULT_VERSION_STDOUT, | 40 | versionStdout: DEFAULT_VERSION_STDOUT, |
| 38 | inventoryError: null as Error | null, | 41 | inventoryError: null as Error | null, |
| 39 | connectionError: null as Error | null, | 42 | connectionError: null as Error | null, |
| ... | @@ -52,6 +55,7 @@ const runtimeMock = { | ... | @@ -52,6 +55,7 @@ const runtimeMock = { |
| 52 | }, | 55 | }, |
| 53 | reset() { | 56 | reset() { |
| 54 | this.state.runVersionError = null; | 57 | this.state.runVersionError = null; |
| | 58 | this.state.runVersionPending = false; |
| 55 | this.state.versionStdout = DEFAULT_VERSION_STDOUT; | 59 | this.state.versionStdout = DEFAULT_VERSION_STDOUT; |
| 56 | this.state.inventoryError = null; | 60 | this.state.inventoryError = null; |
| 57 | this.state.connectionError = null; | 61 | this.state.connectionError = null; |
| ... | @@ -114,15 +118,17 @@ const OpenCodeRuntimeTestDouble: OpenCodeRuntimeShape = { | ... | @@ -114,15 +118,17 @@ const OpenCodeRuntimeTestDouble: OpenCodeRuntimeShape = { |
| 114 | }; | 118 | }; |
| 115 | }), | 119 | }), |
| 116 | runOpenCodeCommand: () => | 120 | runOpenCodeCommand: () => |
| 117 | runtimeMock.state.runVersionError | 121 | runtimeMock.state.runVersionPending |
| 118 | ? Effect.fail( | 122 | ? Effect.never |
| 119 | new OpenCodeRuntimeError({ | 123 | : runtimeMock.state.runVersionError |
| 120 | operation: "runOpenCodeCommand", | 124 | ? Effect.fail( |
| 121 | detail: runtimeMock.state.runVersionError.message, | 125 | new OpenCodeRuntimeError({ |
| 122 | cause: runtimeMock.state.runVersionError, | 126 | operation: "runOpenCodeCommand", |
| 123 | }), | 127 | detail: runtimeMock.state.runVersionError.message, |
| 124 | ) | 128 | cause: runtimeMock.state.runVersionError, |
| 125 | : Effect.succeed({ stdout: runtimeMock.state.versionStdout, stderr: "", code: 0 }), | 129 | }), |
| | 130 | ) |
| | 131 | : Effect.succeed({ stdout: runtimeMock.state.versionStdout, stderr: "", code: 0 }), |
| 126 | createOpenCodeSdkClient: (input) => { | 132 | createOpenCodeSdkClient: (input) => { |
| 127 | runtimeMock.state.sdkClientInputs.push(input); | 133 | runtimeMock.state.sdkClientInputs.push(input); |
| 128 | return {} as unknown as ReturnType<OpenCodeRuntimeShape["createOpenCodeSdkClient"]>; | 134 | return {} as unknown as ReturnType<OpenCodeRuntimeShape["createOpenCodeSdkClient"]>; |
| ... | @@ -218,6 +224,24 @@ it.layer(testLayer)("checkOpenCodeProviderStatus", (it) => { | ... | @@ -218,6 +224,24 @@ it.layer(testLayer)("checkOpenCodeProviderStatus", (it) => { |
| 218 | }), | 224 | }), |
| 219 | ); | 225 | ); |
| 220 | | 226 | |
| | 227 | it.effect("times out a hanging local CLI version probe", () => |
| | 228 | Effect.gen(function* () { |
| | 229 | runtimeMock.state.runVersionPending = true; |
| | 230 | const probeFiber = yield* checkProvider(makeOpenCodeSettings()).pipe(Effect.forkChild); |
| | 231 | |
| | 232 | yield* Effect.yieldNow; |
| | 233 | yield* TestClock.adjust("4 seconds"); |
| | 234 | const snapshot = yield* Fiber.join(probeFiber); |
| | 235 | |
| | 236 | NodeAssert.equal(snapshot.status, "error"); |
| | 237 | NodeAssert.equal(snapshot.installed, true); |
| | 238 | NodeAssert.equal( |
| | 239 | snapshot.message, |
| | 240 | "Failed to execute OpenCode CLI health check: OpenCode CLI version probe timed out after 4 seconds.", |
| | 241 | ); |
| | 242 | }).pipe(Effect.provide(TestClock.layer())), |
| | 243 | ); |
| | 244 | |
| 221 | it.effect("emits OpenCode variant defaults so trait picker can resolve a visible selection", () => | 245 | it.effect("emits OpenCode variant defaults so trait picker can resolve a visible selection", () => |
| 222 | Effect.gen(function* () { | 246 | Effect.gen(function* () { |
| 223 | runtimeMock.state.inventory = { | 247 | runtimeMock.state.inventory = { |