Skip to content

Commit 6462579

Browse files
committed
test(anthropic): fabricate checkpoints via capture tracker
Keeps captureAnthropicCompaction module-local; knip flags exports whose only consumers are tests.
1 parent 466d1f0 commit 6462579

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

‎packages/ai/src/transports/anthropic-compaction-replay.test.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { AssistantMessage, Context, Model } from "@openclaw/llm-core";
22
import { describe, expect, it } from "vitest";
33
import {
44
buildAnthropicReplayPlan,
5-
captureAnthropicCompaction,
5+
createCompactionCapture,
66
isAnthropicReplayRejection,
77
suppressAnthropicCompaction,
88
} from "./anthropic-compaction-replay.js";
@@ -46,9 +46,20 @@ function assistant(texts: string[]): AssistantMessage {
4646
};
4747
}
4848

49+
function captureCheckpoint(
50+
message: AssistantMessage,
51+
summary: string,
52+
replayIndex: number,
53+
options = replayOptions,
54+
): void {
55+
const capture = createCompactionCapture(message, model, options);
56+
capture.begin(0, { type: "compaction", content: summary }, replayIndex);
57+
capture.complete(0);
58+
}
59+
4960
function contextWithCheckpoint(summary = "summary of the earlier conversation"): Context {
5061
const checkpoint = assistant(["before checkpoint", "after checkpoint"]);
51-
captureAnthropicCompaction(checkpoint, summary, 1, model, replayOptions);
62+
captureCheckpoint(checkpoint, summary, 1);
5263
return {
5364
messages: [
5465
{ role: "user", content: "old question", timestamp: 0 },
@@ -96,7 +107,7 @@ describe("Anthropic compaction replay", () => {
96107
it("uses the newest matching checkpoint", () => {
97108
const context = contextWithCheckpoint("older summary");
98109
const newest = assistant(["latest answer"]);
99-
captureAnthropicCompaction(newest, "newest summary", 0, model, replayOptions);
110+
captureCheckpoint(newest, "newest summary", 0);
100111
context.messages.push({ role: "user", content: "middle", timestamp: 3 }, newest, {
101112
role: "user",
102113
content: "latest question",

‎packages/ai/src/transports/anthropic-compaction-replay.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function replayContextMatches(
136136
);
137137
}
138138

139-
export function captureAnthropicCompaction(
139+
function captureAnthropicCompaction(
140140
output: ReplayOut,
141141
summary: string,
142142
replayIndex: number,

‎packages/ai/src/transports/anthropic-transport-stream.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
getAiTransportHost,
1212
type AiInlineContentBlock,
1313
} from "../host.js";
14-
import { captureAnthropicCompaction } from "./anthropic-compaction-replay.js";
14+
import { createCompactionCapture } from "./anthropic-compaction-replay.js";
1515

1616
const { buildGuardedModelFetchMock, guardedFetchMock } = vi.hoisted(() => ({
1717
buildGuardedModelFetchMock: vi.fn(),
@@ -656,7 +656,9 @@ describe("anthropic transport stream", () => {
656656
stopReason: "stop",
657657
timestamp: 1,
658658
};
659-
captureAnthropicCompaction(checkpoint, "summary checkpoint", 0, model, replayIdentity);
659+
const capture = createCompactionCapture(checkpoint, model, replayIdentity);
660+
capture.begin(0, { type: "compaction", content: "summary checkpoint" }, 0);
661+
capture.complete(0);
660662
guardedFetchMock.mockResolvedValueOnce(
661663
new Response(
662664
JSON.stringify({ error: { message: "context_management compaction block is invalid" } }),

0 commit comments

Comments
 (0)