Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions packages/provider-opencode/src/server/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as NodeAssert from "node:assert/strict";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { it } from "@effect/vitest";
import * as Deferred from "effect/Deferred";
import * as Duration from "effect/Duration";
import * as Effect from "effect/Effect";
import * as Fiber from "effect/Fiber";
import * as FileSystem from "effect/FileSystem";
Expand Down Expand Up @@ -169,6 +170,7 @@ const runtimeMock = {
state: {
runVersionError: null as Error | null,
runVersionPending: false,
runVersionDelay: null as Duration.Input | null,
versionStdout: DEFAULT_VERSION_STDOUT,
inventoryError: null as Error | null,
connectionError: null as Error | null,
Expand All @@ -188,6 +190,7 @@ const runtimeMock = {
reset() {
this.state.runVersionError = null;
this.state.runVersionPending = false;
this.state.runVersionDelay = null;
this.state.versionStdout = DEFAULT_VERSION_STDOUT;
this.state.inventoryError = null;
this.state.connectionError = null;
Expand Down Expand Up @@ -260,7 +263,11 @@ const OpenCodeRuntimeTestDouble: OpenCodeRuntime.OpenCodeRuntimeShape = {
cause: runtimeMock.state.runVersionError,
}),
)
: Effect.succeed({ stdout: runtimeMock.state.versionStdout, stderr: "", code: 0 }),
: runtimeMock.state.runVersionDelay
? Effect.succeed({ stdout: runtimeMock.state.versionStdout, stderr: "", code: 0 }).pipe(
Effect.delay(runtimeMock.state.runVersionDelay),
)
: Effect.succeed({ stdout: runtimeMock.state.versionStdout, stderr: "", code: 0 }),
createOpenCodeSdkClient: (input) => {
runtimeMock.state.sdkClientInputs.push(input);
return {} as unknown as ReturnType<
Expand Down Expand Up @@ -388,18 +395,33 @@ it.layer(layerTest)("checkOpenCodeProviderStatus", (it) => {
const probeFiber = yield* checkProvider(makeOpenCodeSettings()).pipe(Effect.forkChild);

yield* Effect.yieldNow;
yield* TestClock.adjust("4 seconds");
yield* TestClock.adjust("10 seconds");
const snapshot = yield* Fiber.join(probeFiber);

NodeAssert.equal(snapshot.status, "error");
NodeAssert.equal(snapshot.installed, true);
NodeAssert.equal(
snapshot.message,
"Failed to execute OpenCode CLI health check: OpenCode CLI version probe timed out after 4 seconds.",
"Failed to execute OpenCode CLI health check: OpenCode CLI version probe timed out after 10 seconds.",
);
}).pipe(Effect.provide(TestClock.layer())),
);

it.effect("waits for a slow but healthy local CLI version probe", () =>
Effect.gen(function* () {
runtimeMock.state.runVersionDelay = "6 seconds";
const probeFiber = yield* checkProvider(makeOpenCodeSettings()).pipe(Effect.forkChild);

yield* Effect.yieldNow;
yield* TestClock.adjust("6 seconds");
const snapshot = yield* Fiber.join(probeFiber);

NodeAssert.notEqual(snapshot.status, "error");
NodeAssert.equal(snapshot.installed, true);
NodeAssert.equal(snapshot.version, "1.14.19");
}).pipe(Effect.provide(TestClock.layer())),
);

it.effect("emits OpenCode variant defaults so trait picker can resolve a visible selection", () =>
Effect.gen(function* () {
runtimeMock.state.inventory = {
Expand Down
3 changes: 2 additions & 1 deletion packages/provider-opencode/src/server/versionProbe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export interface ProbedOpenCode {
readonly version: string;
}

const OPENCODE_VERSION_PROBE_TIMEOUT = "4 seconds";
// Meant to stop a hung `--version`; wrapped installs can take several seconds to start cold.
const OPENCODE_VERSION_PROBE_TIMEOUT = "10 seconds";
const OPENCODE_SERVER_PROBE_TIMEOUT = "5 seconds";
// 2.x's own CLI decodes `{version, pid}` from `/api/info`; requiring both keeps unrelated JSON out.
const decodeApiInfo = Schema.decodeUnknownOption(
Expand Down
Loading