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

ProviderDimensions.test.ts

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