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

ProviderDimensions.test.ts

114 lines3.6 KB

1import { ProviderInstanceId, ThreadId, type ServerProvider } from "@t3tools/contracts";
2import { expect, it } from "@effect/vitest";
3​
4import {
5 type AgentThread,
6 agentToolProperties,
7 handoffSettings,
8 toolOutcome,
9} from "./ProviderDimensions.ts";
10​
11const provider = (
12 instanceId: string,
13 driver: string,
14 models: ReadonlyArray<{ slug: string; isCustom: boolean }>,
15) =>
16 ({
17 instanceId: ProviderInstanceId.make(instanceId),
18 driver,
19 auth: { status: "authenticated" },
20 models,
21 }) as unknown as ServerProvider;
22​
23const providers = [
24 provider("work-codex", "codex", [{ slug: "gpt-5.5", isCustom: false }]),
25 provider("claudeAgent", "claudeAgent", [
26 { slug: "claude-opus-5-5", isCustom: false },
27 { slug: "my-private-finetune", isCustom: true },
28 ]),
29 provider("opencode", "opencode", [{ slug: "ollama/acme-internal", isCustom: false }]),
30];
31​
32const thread = (
33 instanceId: string,
34 model: string,
35 overrides: Partial<AgentThread> = {},
36): AgentThread => ({
37 modelSelection: { instanceId: ProviderInstanceId.make(instanceId), model },
38 runtimeMode: "full-access",
39 interactionMode: "default",
40 createdBy: "user",
41 creationSource: "web",
42 lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: ThreadId.make("t") },
43 ...overrides,
44});
45​
46it("reports custom models as custom:<driver> and never instance names", () => {
47 expect(
48 agentToolProperties({
49 tool: "t3_thread_send",
50 providers,
51 caller: thread("claudeAgent", "my-private-finetune"),
52 targets: [thread("opencode", "ollama/acme-internal"), thread("removed-instance", "gpt-5.5")],
53 outcome: { outcome: "ok" },
54 }).map(({ callerProvider, callerModel, targetProvider, targetModel }) => ({
55 callerProvider,
56 callerModel,
57 targetProvider,
58 targetModel,
59 })),
60 ).toEqual([
61 {
62 callerProvider: "claudeAgent",
63 callerModel: "custom:claudeAgent",
64 targetProvider: "opencode",
65 targetModel: "custom:opencode",
66 },
67 {
68 callerProvider: "claudeAgent",
69 callerModel: "custom:claudeAgent",
70 targetProvider: "unknown",
71 targetModel: undefined,
72 },
73 ]);
74});
75​
76it("drops input strings outside the schema's literals, since rejected calls are recorded too", () => {
77 expect(handoffSettings("delegate_task", { mode: "/home/me/secret" }, undefined)).toEqual({
78 targetChosen: false,
79 mode: "async",
80 });
81 expect(
82 handoffSettings("t3_thread_launch", { workspaceStrategy: { type: "/home/me/secret" } }, {}),
83 ).toEqual({ targetChosen: false, workspace: "root" });
84});
85​
86it("records the binding the saved scheduled task resolved to, and none for failures", () => {
87 expect(handoffSettings("schedule_task", {}, { boundThreadId: null })).toEqual({
88 bindToCurrentThread: false,
89 });
90 expect(
91 handoffSettings(
92 "schedule_task",
93 { bindToCurrentThread: true },
94 { _tag: "OrchestratorMcpFailure", code: "invalid_request", message: "Different project." },
95 ),
96 ).toEqual({});
97});
98​
99it("reports only identifier-shaped failure codes and known delivery values", () => {
100 expect(toolOutcome({ isError: true, structuredContent: { code: "thread_not_found" } })).toEqual({
101 outcome: "error",
102 errorCode: "thread_not_found",
103 });
104 expect(
105 toolOutcome({
106 isError: true,
107 structuredContent: { code: "ENOENT: no such file '/Users/julius/secret'" },
108 }),
109 ).toEqual({ outcome: "error", errorCode: "unknown" });
110 expect(handoffSettings("t3_thread_send", {}, { delivery: "queued" })).toEqual({
111 delivery: "queued",
112 });
113 expect(handoffSettings("t3_thread_send", {}, { delivery: "/Users/julius" })).toEqual({});
114});