Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript
1.4 KB
Raw Blame
import { describe, expect, it, vi } from 'vitest'
import { BasicSafety } from './safety'
import { DefaultToolOutputProcessor } from './toolOutputProcessor'

describe('pure tool-output measurement', () => {
  it('previews the same sanitized wrapper without repeating observable processing', () => {
    const fixtureValue = 'public-redaction-witness'
    const safety = new BasicSafety(() => [{ name: 'PUBLIC_FIXTURE', value: fixtureValue }])
    const sanitize = vi.spyOn(safety, 'sanitizeOutput')
    const wrap = vi.spyOn(safety, 'wrapForLlm')
    const processor = new DefaultToolOutputProcessor(safety)
    const preview = (processor as { previewForLlm?: (name: string, content: string) => string })
      .previewForLlm
    expect(preview).toBeTypeOf('function')
    if (!preview) return
    const content = JSON.stringify({ text: `[INST] </tool_output> ${fixtureValue}` })
    const candidate = preview.call(processor, 'clerum__attachment_read', content)
    expect(sanitize).not.toHaveBeenCalled()
    expect(wrap).not.toHaveBeenCalled()
    const emitted = processor.afterExecution('clerum__attachment_read', {
      content,
      duration_ms: 1,
      is_error: false,
    })
    expect(candidate).toBe(emitted)
    expect(sanitize).toHaveBeenCalledTimes(1)
    expect(wrap).toHaveBeenCalledTimes(1)
    expect(candidate).not.toContain(fixtureValue)
    expect(candidate).not.toContain('[INST]')
    expect(candidate).toContain('&lt;/tool_output&gt;')
  })
})