refactor(test): dedupe agent and discord test fixtures

This commit is contained in:
Peter Steinberger
2026-02-22 20:01:43 +00:00
parent 5547a2275c
commit 3c75bc0e41
26 changed files with 632 additions and 737 deletions

View File

@@ -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;
}