test(agents): cover undersized model dispatch guard (#55369)

This commit is contained in:
R. Desmond 2026-03-26 19:30:20 -05:00 committed by GitHub
parent 5a98a1dbe2
commit fa0835dd32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 48 additions and 10 deletions

View File

@ -138,6 +138,16 @@ export const mockedIsLikelyContextOverflowError = vi.fn((msg?: string) => {
export const mockedPickFallbackThinkingLevel = vi.fn<(params?: unknown) => ThinkLevel | null>(
() => null,
);
export const mockedEvaluateContextWindowGuard = vi.fn(() => ({
shouldWarn: false,
shouldBlock: false,
tokens: 200000,
source: "model",
}));
export const mockedResolveContextWindowInfo = vi.fn(() => ({
tokens: 200000,
source: "model",
}));
export const mockedGetApiKeyForModel = vi.fn(
async ({ profileId }: { profileId?: string } = {}) => ({
apiKey: "test-key",
@ -236,6 +246,18 @@ export function resetRunOverflowCompactionHarnessMocks(): void {
});
mockedPickFallbackThinkingLevel.mockReset();
mockedPickFallbackThinkingLevel.mockReturnValue(null);
mockedEvaluateContextWindowGuard.mockReset();
mockedEvaluateContextWindowGuard.mockReturnValue({
shouldWarn: false,
shouldBlock: false,
tokens: 200000,
source: "model",
});
mockedResolveContextWindowInfo.mockReset();
mockedResolveContextWindowInfo.mockReturnValue({
tokens: 200000,
source: "model",
});
mockedGetApiKeyForModel.mockReset();
mockedGetApiKeyForModel.mockImplementation(
async ({ profileId }: { profileId?: string } = {}) => ({
@ -363,16 +385,8 @@ export async function loadRunOverflowCompactionHarness(): Promise<{
vi.doMock("../context-window-guard.js", () => ({
CONTEXT_WINDOW_HARD_MIN_TOKENS: 1000,
CONTEXT_WINDOW_WARN_BELOW_TOKENS: 5000,
evaluateContextWindowGuard: vi.fn(() => ({
shouldWarn: false,
shouldBlock: false,
tokens: 200000,
source: "model",
})),
resolveContextWindowInfo: vi.fn(() => ({
tokens: 200000,
source: "model",
})),
evaluateContextWindowGuard: mockedEvaluateContextWindowGuard,
resolveContextWindowInfo: mockedResolveContextWindowInfo,
}));
vi.doMock("../../process/command-queue.js", () => ({

View File

@ -12,8 +12,10 @@ import {
mockedCompactDirect,
mockedContextEngine,
mockedDescribeFailoverError,
mockedEvaluateContextWindowGuard,
mockedGlobalHookRunner,
mockedPickFallbackThinkingLevel,
mockedResolveContextWindowInfo,
mockedResolveFailoverStatus,
mockedRunContextEngineMaintenance,
mockedRunEmbeddedAttempt,
@ -79,6 +81,28 @@ describe("runEmbeddedPiAgent overflow compaction trigger routing", () => {
);
});
it("blocks undersized models before dispatching a provider attempt", async () => {
mockedResolveContextWindowInfo.mockReturnValue({
tokens: 800,
source: "model",
});
mockedEvaluateContextWindowGuard.mockReturnValue({
shouldWarn: true,
shouldBlock: true,
tokens: 800,
source: "model",
});
await expect(
runEmbeddedPiAgent({
...overflowBaseRunParams,
runId: "run-small-context",
}),
).rejects.toThrow("Model context window too small (800 tokens). Minimum is 1000.");
expect(mockedRunEmbeddedAttempt).not.toHaveBeenCalled();
});
it("passes trigger=overflow when retrying compaction after context overflow", async () => {
mockOverflowRetrySuccess({
runEmbeddedAttempt: mockedRunEmbeddedAttempt,