Co-authored-by: codex <[email protected]> Co-authored-by: JustYannicc <[email protected]> Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
83 lines
2.6 KiB
TypeScript
83 lines
2.6 KiB
TypeScript
import type { ProviderKind } from "@t3tools/contracts";
|
|
import { it, assert, vi } from "@effect/vitest";
|
|
import { assertFailure } from "@effect/vitest/utils";
|
|
|
|
import { Effect, Layer, Stream } from "effect";
|
|
|
|
import { ClaudeAdapter, ClaudeAdapterShape } from "../Services/ClaudeAdapter.ts";
|
|
import { CodexAdapter, CodexAdapterShape } from "../Services/CodexAdapter.ts";
|
|
import { ProviderAdapterRegistry } from "../Services/ProviderAdapterRegistry.ts";
|
|
import { ProviderAdapterRegistryLive } from "./ProviderAdapterRegistry.ts";
|
|
import { ProviderUnsupportedError } from "../Errors.ts";
|
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
|
|
const fakeCodexAdapter: CodexAdapterShape = {
|
|
provider: "codex",
|
|
capabilities: { sessionModelSwitch: "in-session" },
|
|
startSession: vi.fn(),
|
|
sendTurn: vi.fn(),
|
|
interruptTurn: vi.fn(),
|
|
respondToRequest: vi.fn(),
|
|
respondToUserInput: vi.fn(),
|
|
stopSession: vi.fn(),
|
|
listSessions: vi.fn(),
|
|
hasSession: vi.fn(),
|
|
readThread: vi.fn(),
|
|
rollbackThread: vi.fn(),
|
|
stopAll: vi.fn(),
|
|
streamEvents: Stream.empty,
|
|
};
|
|
|
|
const fakeClaudeAdapter: ClaudeAdapterShape = {
|
|
provider: "claudeAgent",
|
|
capabilities: { sessionModelSwitch: "in-session" },
|
|
startSession: vi.fn(),
|
|
sendTurn: vi.fn(),
|
|
interruptTurn: vi.fn(),
|
|
respondToRequest: vi.fn(),
|
|
respondToUserInput: vi.fn(),
|
|
stopSession: vi.fn(),
|
|
listSessions: vi.fn(),
|
|
hasSession: vi.fn(),
|
|
readThread: vi.fn(),
|
|
rollbackThread: vi.fn(),
|
|
stopAll: vi.fn(),
|
|
streamEvents: Stream.empty,
|
|
};
|
|
|
|
const layer = it.layer(
|
|
Layer.mergeAll(
|
|
Layer.provide(
|
|
ProviderAdapterRegistryLive,
|
|
Layer.mergeAll(
|
|
Layer.succeed(CodexAdapter, fakeCodexAdapter),
|
|
Layer.succeed(ClaudeAdapter, fakeClaudeAdapter),
|
|
),
|
|
),
|
|
NodeServices.layer,
|
|
),
|
|
);
|
|
|
|
layer("ProviderAdapterRegistryLive", (it) => {
|
|
it.effect("resolves a registered provider adapter", () =>
|
|
Effect.gen(function* () {
|
|
const registry = yield* ProviderAdapterRegistry;
|
|
const codex = yield* registry.getByProvider("codex");
|
|
const claude = yield* registry.getByProvider("claudeAgent");
|
|
assert.equal(codex, fakeCodexAdapter);
|
|
assert.equal(claude, fakeClaudeAdapter);
|
|
|
|
const providers = yield* registry.listProviders();
|
|
assert.deepEqual(providers, ["codex", "claudeAgent"]);
|
|
}),
|
|
);
|
|
|
|
it.effect("fails with ProviderUnsupportedError for unknown providers", () =>
|
|
Effect.gen(function* () {
|
|
const registry = yield* ProviderAdapterRegistry;
|
|
const adapter = yield* registry.getByProvider("unknown" as ProviderKind).pipe(Effect.result);
|
|
assertFailure(adapter, new ProviderUnsupportedError({ provider: "unknown" }));
|
|
}),
|
|
);
|
|
});
|