Skip to content

Commit 18279e4

Browse files
committed
test(knowledge): cover the capped step budget
1 parent ff29701 commit 18279e4

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎apps/sim/lib/knowledge/search/budget.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ describe('search SQL deadline', () => {
4444
}
4545
})
4646

47+
it('caps a step without letting it shorten or outlive the leg it came from', () => {
48+
vi.spyOn(performance, 'now').mockReturnValue(0)
49+
const controller = new AbortController()
50+
const leg = new SearchBudget('vector', 1000, controller.signal)
51+
const step = leg.capped(600)
52+
expect(step.deadline).toBe(600)
53+
expect(step.leg).toBe('vector')
54+
expect(step.signal).toBe(controller.signal)
55+
/** Spending the step is the step's own business; the leg keeps its deadline and its verdict. */
56+
step.isTimeout(new SearchDeadlineError())
57+
expect(step.timedOut).toBe(true)
58+
expect(leg.timedOut).toBe(false)
59+
expect(leg.remaining()).toBe(1000)
60+
/** A step longer than what the leg has left cannot extend it. */
61+
expect(new SearchBudget('vector', 200).capped(600).deadline).toBe(200)
62+
})
63+
4764
it('preserves cancellation and unexpected errors instead of labeling them incomplete evidence', async () => {
4865
const controller = new AbortController()
4966
const budget = new SearchBudget('keyword', performance.now() - 1, controller.signal)

0 commit comments

Comments
 (0)