Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 draftRuntimeModeLimitsInstance,
5 draftSupportedRuntimeModes,
6 resolveCompatibleRuntimeMode,
7 resolveRuntimeModeOptions,
8 runtimeModeOptions,
9} from "./runtimeModeConfig";
10
11describe("draftSupportedRuntimeModes", () => {
12 const supervisedOnly = {
13 instanceId: "fx",
14 supportedRuntimeModes: ["approval-required"],
15 } as const;
16 const noAuto = {
17 instanceId: "muse",
18 supportedRuntimeModes: ["approval-required", "full-access"],
19 } as const;
20 const everyMode = { instanceId: "codex" };
21 const providers = [supervisedOnly, noAuto, everyMode];
22
23 it.each([
24 { label: "one provider that supports it", selections: [supervisedOnly, noAuto] },
25 { label: "a provider that reports no modes", selections: [supervisedOnly, everyMode] },
26 ])("shows Full access when a multi-model draft includes $label", ({ selections }) => {
27 const modes = draftSupportedRuntimeModes(
28 supervisedOnly.supportedRuntimeModes,
29 selections,
30 providers,
31 );
32 expect(resolveCompatibleRuntimeMode("full-access", modes).mode).toBe("full-access");
33 });
34
35 it("falls back only when no selected provider can run the mode", () => {
36 const modes = draftSupportedRuntimeModes(undefined, [supervisedOnly, noAuto], providers);
37 expect(resolveCompatibleRuntimeMode("auto", modes).mode).toBe("approval-required");
38 });
39});
40
41describe("draftRuntimeModeLimitsInstance", () => {
42 const claude = { instanceId: "claude" };
43 const codex = { instanceId: "codex" };
44
45 it.each([
46 { label: "no multi-model selection", selections: null, expected: "active" },
47 { label: "an empty multi-model selection", selections: [], expected: "active" },
48 { label: "one selected model", selections: [claude], expected: "claude" },
49 { label: "models that share one provider", selections: [claude, claude], expected: "claude" },
50 { label: "models on different providers", selections: [claude, codex], expected: undefined },
51 ])("checks the limits of the provider every thread uses: $label", ({ selections, expected }) => {
52 expect(draftRuntimeModeLimitsInstance("active", selections)).toBe(expected);
53 });
54});
55
56describe("resolveRuntimeModeOptions", () => {
57 it("keeps a mode the provider cannot run in this folder listed, disabled with the reason", () => {
58 const options = resolveRuntimeModeOptions(runtimeModeOptions, undefined, undefined, [
59 { mode: "auto", reason: "project-settings" },
60 ]);
61 expect(options.map((option) => [option.mode, option.disabledReason])).toEqual([
62 ["approval-required", undefined],
63 ["auto-accept-edits", undefined],
64 ["auto", "This project's Claude settings turn auto mode off."],
65 ["full-access", undefined],
66 ]);
67 });
68});