Skip to content

Commit 1bde4b7

Browse files
committed
test(agent-core-v2): strengthen recovery tests per review findings
Assert exact token_budget trigger values in the mixed-delta continuation test, and cover the current-step abort guard separately from the loop-signal abort case.
1 parent a4d1ec1 commit 1bde4b7

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

packages/agent-core-v2/test/agent/turnBudget/turnBudget.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ describe('turnBudget plugin', () => {
130130

131131
expect(result).toMatchObject({ type: 'completed' });
132132
expect(calls).toBe(5);
133-
expect(retryOriginTriggers()).toHaveLength(4);
133+
expect(retryOriginTriggers()).toEqual([
134+
'token_budget',
135+
'token_budget',
136+
'token_budget',
137+
'token_budget',
138+
]);
134139
});
135140

136141
it('does not continue when the flag is off even with a budget configured', async () => {

packages/agent-core-v2/test/agent/turnRecovery/modelFallback.test.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ describe('modelFallback plugin', () => {
172172
expect(ctx.get(IAgentProfileService).getModel()).toBe('mock-model');
173173
});
174174

175-
it('refuses to switch when the step is already aborted', async () => {
175+
it('refuses to switch when the turn signal is already aborted', async () => {
176176
ctx = createTestAgent(
177177
fallbackFlags(),
178178
llmGenerateServices(async () => ({
@@ -214,4 +214,49 @@ describe('modelFallback plugin', () => {
214214
expect(switched).toBe(false);
215215
expect(ctx.get(IAgentProfileService).getModel()).toBe('mock-model');
216216
});
217+
218+
it('refuses to switch when only the current step is aborted', async () => {
219+
ctx = createTestAgent(
220+
fallbackFlags(),
221+
llmGenerateServices(async () => ({
222+
id: 'step-aborted',
223+
message: {
224+
role: 'assistant' as const,
225+
content: [{ type: 'text' as const, text: 'ok' }],
226+
toolCalls: [],
227+
},
228+
usage: emptyUsage(),
229+
finishReason: 'completed' as const,
230+
rawFinishReason: 'stop',
231+
})),
232+
{ initialConfig: fallbackTestConfig() },
233+
);
234+
235+
const stepController = new AbortController();
236+
stepController.abort();
237+
const stepStub: Step = {
238+
id: 'step-1',
239+
turnId: 1,
240+
state: 'running',
241+
signal: stepController.signal,
242+
result: Promise.resolve({ type: 'cancelled', reason: new Error('cancelled') }),
243+
cancel: () => false,
244+
};
245+
const context: LoopErrorContext = {
246+
turnId: 1,
247+
step: 1,
248+
signal: new AbortController().signal,
249+
currentStep: stepStub,
250+
error: new APIConnectionError('terminated'),
251+
failedDriver: new ContinuationStepRequest(),
252+
retry: () => stepStub,
253+
};
254+
255+
const switched = await ctx
256+
.get(IAgentModelFallbackService)
257+
.tryFallbackSwitch(context);
258+
259+
expect(switched).toBe(false);
260+
expect(ctx.get(IAgentProfileService).getModel()).toBe('mock-model');
261+
});
217262
});

0 commit comments

Comments
 (0)