


























@@ -1,3 +1,4 @@
1+// Behavior coverage for replay-history sanitization across provider policies.
12import type { AgentMessage } from "openclaw/plugin-sdk/agent-core";
23import type {
34AssistantMessage,
@@ -42,6 +43,8 @@ vi.mock("../plugins/provider-hook-runtime.js", async () => {
4243resolveProviderHookPlugin: vi.fn(() => undefined),
4344resolveProviderPluginsForHooks: vi.fn(() => []),
4445resolveProviderRuntimePlugin: vi.fn(({ provider }: { provider?: string }) =>
46+// Provider-specific replay policies are injected through the hook runtime
47+// so core tests assert the contract without importing plugin internals.
4548provider === "openrouter" || provider === "github-copilot"
4649 ? {
4750buildReplayPolicy: (context?: { modelId?: string | null }) => {
@@ -94,6 +97,8 @@ vi.mock("../plugins/provider-runtime.js", async () => {
9497};
9598};
9699}) => {
100+// Google-style providers may need a synthetic user turn before replaying
101+// assistant-first history; the session marker prevents duplicate repair.
97102if (
98103provider &&
99104provider.startsWith("google") &&
@@ -120,8 +125,8 @@ let mockedHelpers: SanitizeSessionHistoryHarness["mockedHelpers"];
120125let testTimestamp = 1;
121126const nextTimestamp = () => testTimestamp++;
122127123-// We don't mock session-transcript-repair.js as it is a pure function and complicates mocking.
124-// We rely on the real implementation which should pass through our simple messages.
128+// Keep session-transcript-repair real: it is a pure repair boundary, and these
129+// tests should fail if the shared sanitizer stops passing simple messages.
125130126131describe("sanitizeSessionHistory", () => {
127132let mockSessionManager: ReturnType<typeof makeMockSessionManager>;
@@ -135,6 +140,8 @@ describe("sanitizeSessionHistory", () => {
135140modelApi?: string;
136141modelId?: string;
137142}) =>
143+// Copilot routes through OpenAI-shaped APIs but can apply provider-owned
144+// replay policy such as dropping Claude thinking blocks.
138145sanitizeSessionHistory({
139146messages: params.messages,
140147modelApi: params.modelApi ?? "openai-completions",
@@ -480,6 +487,8 @@ describe("sanitizeSessionHistory", () => {
480487it("drops stale assistant usage snapshots kept before latest compaction summary", async () => {
481488vi.mocked(mockedHelpers.isGoogleModelApi).mockReturnValue(false);
482489490+// Historical usage before a compaction summary would double-count prompt
491+// budget if replayed as fresh model metadata.
483492const messages = castAgentMessages([
484493{ role: "user", content: "old context" },
485494makeAssistantUsageMessage({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。