|
1 | 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | +import { ProviderDriverKind, type ModelCapabilities } from "@t3tools/contracts"; |
2 | 3 |
|
3 | 4 | import { |
| 5 | + DESCRIPTOR_PRESETS_BY_KIND, |
| 6 | + descriptorFromPreset, |
4 | 7 | definitionFromDraft, |
5 | 8 | descriptorsFromCapabilities, |
6 | 9 | draftFromDefinition, |
@@ -69,42 +72,107 @@ describe("customModelEditor.logic", () => { |
69 | 72 | }); |
70 | 73 |
|
71 | 74 | it("preserves the current choice when it differs from the built-in default", () => { |
72 | | - const descriptors = descriptorsFromCapabilities({ |
73 | | - optionDescriptors: [ |
74 | | - { |
75 | | - id: "effort", |
76 | | - label: "Reasoning", |
77 | | - type: "select", |
78 | | - currentValue: "high", |
79 | | - options: [ |
80 | | - { id: "low", label: "Low", isDefault: true }, |
81 | | - { id: "high", label: "High" }, |
82 | | - ], |
83 | | - }, |
84 | | - ], |
85 | | - }); |
| 75 | + const descriptors = descriptorsFromCapabilities( |
| 76 | + { |
| 77 | + optionDescriptors: [ |
| 78 | + { |
| 79 | + id: "effort", |
| 80 | + label: "Reasoning", |
| 81 | + type: "select", |
| 82 | + currentValue: "high", |
| 83 | + options: [ |
| 84 | + { id: "low", label: "Low", isDefault: true }, |
| 85 | + { id: "high", label: "High" }, |
| 86 | + ], |
| 87 | + }, |
| 88 | + ], |
| 89 | + }, |
| 90 | + ProviderDriverKind.make("claudeAgent"), |
| 91 | + ); |
86 | 92 | expect(descriptors[0]!.choices.map((choice) => choice.isDefault)).toEqual([false, true]); |
87 | 93 | expect( |
88 | 94 | definitionFromDraft(draft({ descriptors })).capabilities?.optionDescriptors?.[0], |
89 | 95 | ).toMatchObject({ currentValue: "high" }); |
90 | 96 | }); |
91 | 97 |
|
92 | 98 | it("drops prompt-injected choices when copying a built-in's descriptors", () => { |
93 | | - const [copied] = descriptorsFromCapabilities({ |
| 99 | + const [copied] = descriptorsFromCapabilities( |
| 100 | + { |
| 101 | + optionDescriptors: [ |
| 102 | + { |
| 103 | + id: "effort", |
| 104 | + label: "Reasoning", |
| 105 | + type: "select", |
| 106 | + options: [ |
| 107 | + { id: "high", label: "High", isDefault: true }, |
| 108 | + { id: "ultrathink", label: "Ultrathink" }, |
| 109 | + ], |
| 110 | + promptInjectedValues: ["ultrathink"], |
| 111 | + }, |
| 112 | + ], |
| 113 | + }, |
| 114 | + ProviderDriverKind.make("claudeAgent"), |
| 115 | + ); |
| 116 | + expect(copied!.choices.map((choice) => choice.id)).toEqual(["high"]); |
| 117 | + }); |
| 118 | + |
| 119 | + it.each([true, false, undefined])( |
| 120 | + "preserves boolean values through copy and edit: %s", |
| 121 | + (currentValue) => { |
| 122 | + const capabilities: ModelCapabilities = { |
| 123 | + optionDescriptors: [ |
| 124 | + { |
| 125 | + id: "thinking", |
| 126 | + label: "Thinking", |
| 127 | + type: "boolean", |
| 128 | + ...(currentValue !== undefined ? { currentValue } : {}), |
| 129 | + }, |
| 130 | + ], |
| 131 | + }; |
| 132 | + const copied = definitionFromDraft( |
| 133 | + draft({ |
| 134 | + descriptors: descriptorsFromCapabilities(capabilities, ProviderDriverKind.make("cursor")), |
| 135 | + }), |
| 136 | + ); |
| 137 | + expect(copied.capabilities).toEqual(capabilities); |
| 138 | + const reopened = draftFromDefinition(copied); |
| 139 | + expect(definitionFromDraft({ ...reopened, name: "Renamed" }).capabilities).toEqual( |
| 140 | + capabilities, |
| 141 | + ); |
| 142 | + }, |
| 143 | + ); |
| 144 | + |
| 145 | + it("excludes Claude context choices from presets and copies without changing other providers or authored entries", () => { |
| 146 | + const capabilities: ModelCapabilities = { |
94 | 147 | optionDescriptors: [ |
95 | 148 | { |
96 | | - id: "effort", |
97 | | - label: "Reasoning", |
| 149 | + id: "contextWindow", |
| 150 | + label: "Context", |
98 | 151 | type: "select", |
99 | | - options: [ |
100 | | - { id: "high", label: "High", isDefault: true }, |
101 | | - { id: "ultrathink", label: "Ultrathink" }, |
102 | | - ], |
103 | | - promptInjectedValues: ["ultrathink"], |
| 152 | + options: [{ id: "1m", label: "1M", isDefault: true }], |
104 | 153 | }, |
| 154 | + { id: "thinking", label: "Thinking", type: "boolean", currentValue: true }, |
105 | 155 | ], |
106 | | - }); |
107 | | - expect(copied!.choices.map((choice) => choice.id)).toEqual(["high"]); |
| 156 | + }; |
| 157 | + const claude = ProviderDriverKind.make("claudeAgent"); |
| 158 | + const copied = definitionFromDraft( |
| 159 | + draft({ descriptors: descriptorsFromCapabilities(capabilities, claude) }), |
| 160 | + ); |
| 161 | + expect(copied.capabilities?.optionDescriptors).toEqual([capabilities.optionDescriptors![1]]); |
| 162 | + const presets = definitionFromDraft( |
| 163 | + draft({ |
| 164 | + descriptors: (DESCRIPTOR_PRESETS_BY_KIND[claude] ?? []).map(descriptorFromPreset), |
| 165 | + }), |
| 166 | + ); |
| 167 | + expect( |
| 168 | + presets.capabilities?.optionDescriptors?.some((option) => option.id === "contextWindow"), |
| 169 | + ).toBe(false); |
| 170 | + const cursorCopy = descriptorsFromCapabilities(capabilities, ProviderDriverKind.make("cursor")); |
| 171 | + expect(cursorCopy.map((option) => option.id)).toEqual(["contextWindow", "thinking"]); |
| 172 | + const authored = { slug: "custom", name: "Custom", capabilities }; |
| 173 | + expect( |
| 174 | + definitionFromDraft(draftFromDefinition(authored)).capabilities?.optionDescriptors?.[0], |
| 175 | + ).toMatchObject(capabilities.optionDescriptors![0]!); |
108 | 176 | }); |
109 | 177 |
|
110 | 178 | it("collapses a blank name and no options back to a bare definition", () => { |
|
0 commit comments