mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
test(agents): share overflow retry compaction fixture
This commit is contained in:
@@ -50,7 +50,7 @@ vi.mock("../pi-embedded-helpers.js", async () => {
|
||||
import { compactEmbeddedPiSessionDirect } from "./compact.js";
|
||||
import { log } from "./logger.js";
|
||||
import { runEmbeddedPiAgent } from "./run.js";
|
||||
import { makeAttemptResult } from "./run.overflow-compaction.fixture.js";
|
||||
import { makeAttemptResult, mockOverflowRetrySuccess } from "./run.overflow-compaction.fixture.js";
|
||||
import { runEmbeddedAttempt } from "./run/attempt.js";
|
||||
import type { EmbeddedRunAttemptResult } from "./run/types.js";
|
||||
import {
|
||||
@@ -87,20 +87,9 @@ describe("overflow compaction in run loop", () => {
|
||||
});
|
||||
|
||||
it("retries after successful compaction on context overflow promptError", async () => {
|
||||
const overflowError = new Error("request_too_large: Request size exceeds model context window");
|
||||
|
||||
mockedRunEmbeddedAttempt
|
||||
.mockResolvedValueOnce(makeAttemptResult({ promptError: overflowError }))
|
||||
.mockResolvedValueOnce(makeAttemptResult({ promptError: null }));
|
||||
|
||||
mockedCompactDirect.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
compacted: true,
|
||||
result: {
|
||||
summary: "Compacted session",
|
||||
firstKeptEntryId: "entry-5",
|
||||
tokensBefore: 150000,
|
||||
},
|
||||
mockOverflowRetrySuccess({
|
||||
runEmbeddedAttempt: mockedRunEmbeddedAttempt,
|
||||
compactDirect: mockedCompactDirect,
|
||||
});
|
||||
|
||||
const result = await runEmbeddedPiAgent(baseParams);
|
||||
|
||||
@@ -21,3 +21,46 @@ export function makeAttemptResult(
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
type MockRunEmbeddedAttempt = {
|
||||
mockResolvedValueOnce: (value: EmbeddedRunAttemptResult) => unknown;
|
||||
};
|
||||
|
||||
type MockCompactDirect = {
|
||||
mockResolvedValueOnce: (value: {
|
||||
ok: true;
|
||||
compacted: true;
|
||||
result: {
|
||||
summary: string;
|
||||
firstKeptEntryId: string;
|
||||
tokensBefore: number;
|
||||
};
|
||||
}) => unknown;
|
||||
};
|
||||
|
||||
export function mockOverflowRetrySuccess(params: {
|
||||
runEmbeddedAttempt: MockRunEmbeddedAttempt;
|
||||
compactDirect: MockCompactDirect;
|
||||
overflowMessage?: string;
|
||||
}) {
|
||||
const overflowError = new Error(
|
||||
params.overflowMessage ?? "request_too_large: Request size exceeds model context window",
|
||||
);
|
||||
|
||||
params.runEmbeddedAttempt.mockResolvedValueOnce(
|
||||
makeAttemptResult({ promptError: overflowError }),
|
||||
);
|
||||
params.runEmbeddedAttempt.mockResolvedValueOnce(makeAttemptResult({ promptError: null }));
|
||||
|
||||
params.compactDirect.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
compacted: true,
|
||||
result: {
|
||||
summary: "Compacted session",
|
||||
firstKeptEntryId: "entry-5",
|
||||
tokensBefore: 150000,
|
||||
},
|
||||
});
|
||||
|
||||
return overflowError;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import "./run.overflow-compaction.mocks.shared.js";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { compactEmbeddedPiSessionDirect } from "./compact.js";
|
||||
import { runEmbeddedPiAgent } from "./run.js";
|
||||
import { makeAttemptResult } from "./run.overflow-compaction.fixture.js";
|
||||
import { mockOverflowRetrySuccess } from "./run.overflow-compaction.fixture.js";
|
||||
import { runEmbeddedAttempt } from "./run/attempt.js";
|
||||
|
||||
const mockedRunEmbeddedAttempt = vi.mocked(runEmbeddedAttempt);
|
||||
@@ -14,20 +14,9 @@ describe("runEmbeddedPiAgent overflow compaction trigger routing", () => {
|
||||
});
|
||||
|
||||
it("passes trigger=overflow when retrying compaction after context overflow", async () => {
|
||||
const overflowError = new Error("request_too_large: Request size exceeds model context window");
|
||||
|
||||
mockedRunEmbeddedAttempt
|
||||
.mockResolvedValueOnce(makeAttemptResult({ promptError: overflowError }))
|
||||
.mockResolvedValueOnce(makeAttemptResult({ promptError: null }));
|
||||
|
||||
mockedCompactDirect.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
compacted: true,
|
||||
result: {
|
||||
summary: "Compacted session",
|
||||
firstKeptEntryId: "entry-5",
|
||||
tokensBefore: 150000,
|
||||
},
|
||||
mockOverflowRetrySuccess({
|
||||
runEmbeddedAttempt: mockedRunEmbeddedAttempt,
|
||||
compactDirect: mockedCompactDirect,
|
||||
});
|
||||
|
||||
await runEmbeddedPiAgent({
|
||||
|
||||
Reference in New Issue
Block a user