




















@@ -5,13 +5,15 @@ import { estimateToolResultReductionPotential } from "../tool-result-truncation.
5566let PREEMPTIVE_OVERFLOW_ERROR_TEXT: typeof import("./preemptive-compaction.js").PREEMPTIVE_OVERFLOW_ERROR_TEXT;
77let estimatePrePromptTokens: typeof import("./preemptive-compaction.js").estimatePrePromptTokens;
8+let formatPrePromptPrecheckLog: typeof import("./preemptive-compaction.js").formatPrePromptPrecheckLog;
89let shouldPreemptivelyCompactBeforePrompt: typeof import("./preemptive-compaction.js").shouldPreemptivelyCompactBeforePrompt;
9101011beforeAll(async () => {
1112vi.resetModules();
1213({
1314PREEMPTIVE_OVERFLOW_ERROR_TEXT,
1415 estimatePrePromptTokens,
16+ formatPrePromptPrecheckLog,
1517 shouldPreemptivelyCompactBeforePrompt,
1618} = await import("./preemptive-compaction.js"));
1719});
@@ -93,6 +95,42 @@ describe("preemptive-compaction", () => {
9395expect(result.estimatedPromptTokens).toBeLessThan(result.promptBudgetBeforeReserve);
9496});
959798+it("formats all-route pre-prompt diagnostics for a fits decision", () => {
99+const result = shouldPreemptivelyCompactBeforePrompt({
100+messages: [makeAssistantHistory("short history")],
101+systemPrompt: "sys",
102+prompt: "hello",
103+contextTokenBudget: 10_000,
104+reserveTokens: 1_000,
105+});
106+const line = formatPrePromptPrecheckLog({
107+ result,
108+sessionKey: "discord:channel:thread",
109+sessionId: "session-1",
110+provider: "anthropic",
111+modelId: "claude-opus-4-6",
112+messageCount: 1,
113+unwindowedMessageCount: 3,
114+contextTokenBudget: 10_000,
115+reserveTokens: 1_000,
116+sessionFile: "sessions/session-1.json",
117+});
118+119+expect(line).toContain("[context-overflow-precheck] pre-prompt check");
120+expect(line).toContain("sessionKey=discord:channel:thread");
121+expect(line).toContain("provider=anthropic/claude-opus-4-6");
122+expect(line).toContain("route=fits");
123+expect(line).toContain(`estimatedPromptTokens=${result.estimatedPromptTokens}`);
124+expect(line).toContain(`promptBudgetBeforeReserve=${result.promptBudgetBeforeReserve}`);
125+expect(line).toContain("overflowTokens=0");
126+expect(line).toContain(`toolResultReducibleChars=${result.toolResultReducibleChars}`);
127+expect(line).toContain("reserveTokens=1000");
128+expect(line).toContain(`effectiveReserveTokens=${result.effectiveReserveTokens}`);
129+expect(line).toContain("contextTokenBudget=10000");
130+expect(line).toContain("messages=1");
131+expect(line).toContain("unwindowedMessages=3");
132+});
133+96134it("uses the larger unwindowed message estimate when explicitly provided", () => {
97135const result = shouldPreemptivelyCompactBeforePrompt({
98136messages: [makeAssistantHistory("small assembled window")],
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。