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

thread-settings-options.test.ts

100 lines3.4 KB

1import {
2 getPromptControlledTraits,
3 getTraitSelectChange,
4} from "@t3tools/client-runtime/model-traits";
5import type {
6 ManagedPolicySummary,
7 ProviderOptionDescriptor,
8 RuntimeMode,
9} from "@t3tools/contracts";
10import { describe, expect, it } from "vite-plus/test";
11​
12import {
13 RUNTIME_MODE_CHOICES,
14 resolveNewThreadRuntimeMode,
15 selectableChoices,
16 withManagedRuntimeModeLimits,
17} from "./thread-settings-options";
18​
19const policy = (organization: string, maxRuntimeMode?: RuntimeMode): ManagedPolicySummary => ({
20 organization,
21 lockedSettings: [],
22 ...(maxRuntimeMode === undefined ? {} : { limits: { maxRuntimeMode } }),
23});
24​
25describe("managed runtime mode limits", () => {
26 it("disables modes above the strictest target's ceiling with that target's reason", () => {
27 const choices = withManagedRuntimeModeLimits(RUNTIME_MODE_CHOICES, [
28 policy("Wide Corp", "auto"),
29 undefined,
30 policy("Narrow Corp", "auto-accept-edits"),
31 ]);
32​
33 expect(choices.map((choice) => [choice.mode, choice.disabledReason])).toEqual([
34 ["approval-required", undefined],
35 ["auto-accept-edits", undefined],
36 ["auto", "Narrow Corp limits threads to Auto-accept edits."],
37 ["full-access", "Wide Corp limits threads to Auto."],
38 ]);
39 });
40​
41 it("drops a new thread's draft mode above the ceiling for the default", () => {
42 const capped = policy("Corp", "auto");
43 expect(resolveNewThreadRuntimeMode("full-access", "auto", capped)).toBe("auto");
44 expect(resolveNewThreadRuntimeMode("approval-required", "auto", capped)).toBe(
45 "approval-required",
46 );
47 expect(resolveNewThreadRuntimeMode(undefined, "auto", capped)).toBe("auto");
48 expect(resolveNewThreadRuntimeMode("full-access", "auto", undefined)).toBe("full-access");
49 });
50});
51​
52const effortDescriptor: Extract<ProviderOptionDescriptor, { type: "select" }> = {
53 id: "effort",
54 label: "Reasoning",
55 type: "select",
56 options: [
57 { id: "low", label: "Low" },
58 { id: "medium", label: "Medium", isDefault: true },
59 { id: "high", label: "High" },
60 { id: "ultrathink", label: "Ultrathink" },
61 { id: "ultracode", label: "Ultracode" },
62 ],
63 currentValue: "high",
64 promptInjectedValues: ["ultrathink"],
65};
66​
67describe("selectableChoices", () => {
68 // regression: #21406 bring model controls in line with web
69 it("leaves out prompt-injected choices and keeps workflow choices in declared order", () => {
70 expect(selectableChoices(effortDescriptor).map((choice) => choice.id)).toEqual([
71 "low",
72 "medium",
73 "high",
74 "ultracode",
75 ]);
76 });
77});
78​
79describe("prompt-controlled reasoning", () => {
80 it("removes the prefix when choosing a regular effort and saves Ultracode as an option", () => {
81 const descriptors = [effortDescriptor];
82 const prompt = "Ultrathink:\nsolve it";
83 expect(
84 getTraitSelectChange(
85 { ...getPromptControlledTraits(descriptors, prompt), descriptors },
86 effortDescriptor,
87 prompt,
88 "ultracode",
89 ),
90 ).toEqual({ prompt: "solve it", modelOptions: [{ id: "effort", value: "ultracode" }] });
91 });
92​
93 it("keeps body-controlled Ultrathink locked", () => {
94 const descriptors = [effortDescriptor];
95 const prompt = "please ultrathink about this";
96 const selected = { ...getPromptControlledTraits(descriptors, prompt), descriptors };
97 expect(selected.ultrathinkInBodyText).toBe(true);
98 expect(getTraitSelectChange(selected, effortDescriptor, prompt, "low")).toBeNull();
99 });
100});