|
1 | | -import { parseRuntimeString } from "./chatCommands"; |
| 1 | +import type { SendMessageOptions } from "@/common/types/ipc"; |
| 2 | +import { parseRuntimeString, prepareCompactionMessage } from "./chatCommands"; |
2 | 3 |
|
3 | 4 | describe("parseRuntimeString", () => { |
4 | 5 | const workspaceName = "test-workspace"; |
@@ -84,3 +85,57 @@ describe("parseRuntimeString", () => { |
84 | 85 | ); |
85 | 86 | }); |
86 | 87 | }); |
| 88 | + |
| 89 | +describe("prepareCompactionMessage", () => { |
| 90 | + const createBaseOptions = (): SendMessageOptions => ({ |
| 91 | + model: "anthropic:claude-3-5-sonnet", |
| 92 | + thinkingLevel: "medium", |
| 93 | + toolPolicy: [], |
| 94 | + mode: "exec", |
| 95 | + }); |
| 96 | + |
| 97 | + const stubLocalStorage = () => { |
| 98 | + const store: Record<string, string> = {}; |
| 99 | + const storage: Storage = { |
| 100 | + getItem: (key) => (key in store ? store[key] : null), |
| 101 | + setItem: (key, value) => { |
| 102 | + store[key] = String(value); |
| 103 | + }, |
| 104 | + removeItem: (key) => { |
| 105 | + delete store[key]; |
| 106 | + }, |
| 107 | + clear: () => { |
| 108 | + for (const key of Object.keys(store)) { |
| 109 | + delete store[key]; |
| 110 | + } |
| 111 | + }, |
| 112 | + key: (index) => Object.keys(store)[index] ?? null, |
| 113 | + get length() { |
| 114 | + return Object.keys(store).length; |
| 115 | + }, |
| 116 | + }; |
| 117 | + globalThis.localStorage = storage; |
| 118 | + }; |
| 119 | + |
| 120 | + beforeEach(() => { |
| 121 | + stubLocalStorage(); |
| 122 | + }); |
| 123 | + |
| 124 | + test("embeds resumeModel from base send options", () => { |
| 125 | + const sendMessageOptions = createBaseOptions(); |
| 126 | + const { metadata } = prepareCompactionMessage({ |
| 127 | + workspaceId: "ws-1", |
| 128 | + maxOutputTokens: 4096, |
| 129 | + continueMessage: "Keep building", |
| 130 | + model: "anthropic:claude-3-5-haiku", |
| 131 | + sendMessageOptions, |
| 132 | + }); |
| 133 | + |
| 134 | + expect(metadata.type).toBe("compaction-request"); |
| 135 | + if (metadata.type !== "compaction-request") { |
| 136 | + throw new Error("Expected compaction metadata"); |
| 137 | + } |
| 138 | + |
| 139 | + expect(metadata.parsed.resumeModel).toBe(sendMessageOptions.model); |
| 140 | + }); |
| 141 | +}); |
0 commit comments