Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

OpenCodeRuntime.environment.test.ts

52 lines1.7 KB

1import type { OpencodeClient } from "@opencode-ai/sdk/v2";
2import { it as effectIt } from "@effect/vitest";
3import * as Effect from "effect/Effect";
4import { describe, expect, it } from "vite-plus/test";
5​
6import * as OpenCodeRuntime from "./OpenCodeRuntime.ts";
7​
8describe("resolveOpenCodeServerPassword", () => {
9 it("uses the settings password when local settings and environment differ", () => {
10 expect(
11 OpenCodeRuntime.resolveOpenCodeServerPassword(
12 {
13 external: false,
14 serverPassword: "settings-password",
15 environment: { OPENCODE_SERVER_PASSWORD: "environment-password" },
16 },
17 {},
18 ),
19 ).toBe("settings-password");
20 });
21​
22 it("does not send an inherited local password to an external server", () => {
23 expect(
24 OpenCodeRuntime.resolveOpenCodeServerPassword(
25 { external: true, environment: { OPENCODE_SERVER_PASSWORD: "local-secret" } },
26 { OPENCODE_SERVER_PASSWORD: "inherited-secret" },
27 ),
28 ).toBeUndefined();
29 });
30});
31​
32function makeHealthClient(
33 result: (options?: { readonly signal?: AbortSignal }) => Promise<unknown>,
34): OpencodeClient {
35 return {
36 global: {
37 health: result,
38 },
39 } as unknown as OpencodeClient;
41​
42describe("verifyOpenCodeServerVersion", () => {
43 effectIt.effect("rejects a server below the supported version", () =>
44 Effect.gen(function* () {
45 const error = yield* OpenCodeRuntime.verifyOpenCodeServerVersion(
46 makeHealthClient(() => Promise.resolve({ data: { healthy: true, version: "1.14.18" } })),
47 ).pipe(Effect.flip);
48 expect(error).toBeInstanceOf(OpenCodeRuntime.OpenCodeRuntimeError);
49 expect(error.detail).toContain("v1.14.18 is too old");
50 }),
51 );
52});