Files
accounted/lib/agent/chat/__tests__/run-turn-tool-bounds.test.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

33 lines
1.5 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { boundToolResultText, MAX_TOOL_RESULT_CHARS } from '../run-turn'
// Tool results re-enter the model context on every later loop iteration and are
// persisted as a 'tool' message that loadConversationMessages replays on every
// future turn. An unbounded read (gnubok_get_document_content returns full
// OCR/PDF text) would therefore re-introduce the context rot we keep out of the
// system prompt. boundToolResultText caps the serialized payload.
describe('boundToolResultText: tool-return discipline', () => {
it('passes small results through unchanged', () => {
const small = JSON.stringify({ rows: [{ account: '1930', amount: 1000 }] })
expect(boundToolResultText(small)).toBe(small)
})
it('passes a result exactly at the ceiling through unchanged', () => {
const exact = 'x'.repeat(MAX_TOOL_RESULT_CHARS)
expect(boundToolResultText(exact)).toBe(exact)
})
it('truncates an oversized result to the ceiling and appends a steer', () => {
const huge = 'x'.repeat(MAX_TOOL_RESULT_CHARS + 50_000)
const out = boundToolResultText(huge)
// The body is capped at the ceiling…
expect(out.startsWith('x'.repeat(MAX_TOOL_RESULT_CHARS))).toBe(true)
expect(out.length).toBeLessThan(huge.length)
// …and the marker tells the model it was cut and how to narrow.
expect(out).toContain('avkortat')
expect(out).toContain(String(huge.length))
expect(out.toLowerCase()).toMatch(/smalare|limit|datumintervall/)
})
})