mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 16:14:58 +00:00
refactor(test): dedupe agent and discord test fixtures
This commit is contained in:
@@ -1,5 +1,28 @@
|
||||
import type { EmbeddedRunAttemptResult } from "./run/types.js";
|
||||
|
||||
export const DEFAULT_OVERFLOW_ERROR_MESSAGE =
|
||||
"request_too_large: Request size exceeds model context window";
|
||||
|
||||
export function makeOverflowError(message: string = DEFAULT_OVERFLOW_ERROR_MESSAGE): Error {
|
||||
return new Error(message);
|
||||
}
|
||||
|
||||
export function makeCompactionSuccess(params: {
|
||||
summary: string;
|
||||
firstKeptEntryId: string;
|
||||
tokensBefore: number;
|
||||
}) {
|
||||
return {
|
||||
ok: true as const,
|
||||
compacted: true as const,
|
||||
result: {
|
||||
summary: params.summary,
|
||||
firstKeptEntryId: params.firstKeptEntryId,
|
||||
tokensBefore: params.tokensBefore,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function makeAttemptResult(
|
||||
overrides: Partial<EmbeddedRunAttemptResult> = {},
|
||||
): EmbeddedRunAttemptResult {
|
||||
@@ -43,24 +66,38 @@ export function mockOverflowRetrySuccess(params: {
|
||||
compactDirect: MockCompactDirect;
|
||||
overflowMessage?: string;
|
||||
}) {
|
||||
const overflowError = new Error(
|
||||
params.overflowMessage ?? "request_too_large: Request size exceeds model context window",
|
||||
);
|
||||
const overflowError = makeOverflowError(params.overflowMessage);
|
||||
|
||||
params.runEmbeddedAttempt.mockResolvedValueOnce(
|
||||
makeAttemptResult({ promptError: overflowError }),
|
||||
);
|
||||
params.runEmbeddedAttempt.mockResolvedValueOnce(makeAttemptResult({ promptError: null }));
|
||||
|
||||
params.compactDirect.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
compacted: true,
|
||||
result: {
|
||||
params.compactDirect.mockResolvedValueOnce(
|
||||
makeCompactionSuccess({
|
||||
summary: "Compacted session",
|
||||
firstKeptEntryId: "entry-5",
|
||||
tokensBefore: 150000,
|
||||
},
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
return overflowError;
|
||||
}
|
||||
|
||||
export function queueOverflowAttemptWithOversizedToolOutput(
|
||||
runEmbeddedAttempt: MockRunEmbeddedAttempt,
|
||||
overflowError: Error = makeOverflowError(),
|
||||
): Error {
|
||||
runEmbeddedAttempt.mockResolvedValueOnce(
|
||||
makeAttemptResult({
|
||||
promptError: overflowError,
|
||||
messagesSnapshot: [
|
||||
{
|
||||
role: "assistant",
|
||||
content: "big tool output",
|
||||
} as unknown as EmbeddedRunAttemptResult["messagesSnapshot"][number],
|
||||
],
|
||||
}),
|
||||
);
|
||||
return overflowError;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user