mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 22:34:32 +00:00
test(agents): share overflow retry compaction fixture
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user