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

providerOptions.test.ts

100 lines2.9 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import type { ModelCapabilities } from "@t3tools/contracts";
4​
5import {
6 applyProviderOptionMenuEvent,
7 buildProviderOptionMenuActions,
8 providerOptionsConfigurationLabel,
9 resolveProviderOptionDescriptors,
10} from "./providerOptions";
11​
12const CODEX_CAPABILITIES: ModelCapabilities = {
13 optionDescriptors: [
14 {
15 id: "reasoningEffort",
16 label: "Reasoning",
17 type: "select",
18 options: [
19 { id: "medium", label: "Medium", isDefault: true },
20 { id: "high", label: "High" },
21 ],
22 currentValue: "medium",
23 },
24 {
25 id: "serviceTier",
26 label: "Service Tier",
27 type: "select",
28 options: [
29 { id: "default", label: "Standard", isDefault: true },
30 { id: "priority", label: "Fast" },
31 ],
32 currentValue: "default",
33 },
34 ],
35};
36​
37describe("mobile provider options", () => {
38 it("renders the option descriptors advertised by the selected model", () => {
39 const descriptors = resolveProviderOptionDescriptors({
40 capabilities: CODEX_CAPABILITIES,
41 selections: undefined,
42 });
43​
44 expect(buildProviderOptionMenuActions(descriptors)).toMatchObject([
45 {
46 title: "Reasoning",
47 subtitle: "Medium",
48 subactions: [
49 { title: "Medium (default)", state: "on" },
50 { title: "High", state: undefined },
51 ],
52 },
53 {
54 title: "Service Tier",
55 subtitle: "Standard",
56 subactions: [
57 { title: "Standard (default)", state: "on" },
58 { title: "Fast", state: undefined },
59 ],
60 },
61 ]);
62 expect(providerOptionsConfigurationLabel(descriptors)).toBe("Medium · Standard");
63 });
64​
65 it("updates generic select options without knowing provider-specific ids", () => {
66 const descriptors = resolveProviderOptionDescriptors({
67 capabilities: CODEX_CAPABILITIES,
68 selections: undefined,
69 });
70 const actions = buildProviderOptionMenuActions(descriptors);
71 const fastEvent = actions[1]?.subactions?.[1]?.id;
72​
73 expect(fastEvent).toBeDefined();
74 expect(applyProviderOptionMenuEvent(descriptors, fastEvent!)).toEqual([
75 { id: "reasoningEffort", value: "medium" },
76 { id: "serviceTier", value: "priority" },
77 ]);
78 });
79​
80 it("treats an unspecified boolean capability as off", () => {
81 const descriptors = resolveProviderOptionDescriptors({
82 capabilities: {
83 optionDescriptors: [{ id: "fastMode", label: "Fast Mode", type: "boolean" }],
84 },
85 selections: undefined,
86 });
87​
88 expect(buildProviderOptionMenuActions(descriptors)).toMatchObject([
89 {
90 title: "Fast Mode",
91 subtitle: "Off",
92 subactions: [
93 { title: "Off", state: "on" },
94 { title: "On", state: undefined },
95 ],
96 },
97 ]);
98 expect(providerOptionsConfigurationLabel(descriptors)).toBe("Configuration");
99 });
100});