Files
archie/internal/agentexec/modelloop/transcript_test.go
T
sam 6f10ecc04f feat(agentexec): record each agent run's transcript and show it per step (#1718)
The loop runner hooks every model call and tool call and reports ordered,
redacted, clipped entries. Each is persisted as an agent_transcript task
event through InsertEvent, left out of the timeline read, and served per
attempt at /api/tasks/{id}/transcript. The step run view shows it with Trace.
2026-11-01 22:09:53 +11:00

72 lines
2.1 KiB
Go

package modelloop
import (
"strings"
"testing"
"github.com/samcharles93/ai-sdk/core"
"github.com/samcharles93/archie-core/internal/domain/agentrun"
)
func TestTranscriptToolEntryRedactsAndClips(t *testing.T) {
const jwt = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcmNoaWUifQ.c2lnbmF0dXJlc2lnbmF0dXJl"
const pem = "-----BEGIN RSA PRIVATE KEY-----\nMIIEow\n-----END RSA PRIVATE KEY-----"
long := strings.Repeat("x", transcriptFieldLimit+10)
tests := []struct {
name string
input string
output string
wantArgs string
wantOutput string
wantBytes int
}{
{
name: "secret key in arguments, token inside output",
input: `{"path":"a.txt","api_key":"plain-value"}`,
output: "curl -H 'Authorization: Bearer " + jwt + "' done",
wantArgs: `{"api_key":"[redacted]","path":"a.txt"}`,
wantOutput: "curl -H 'Authorization: Bearer [redacted]' done",
},
{
name: "private key block inside output",
input: `{}`,
output: "before\n" + pem + "\nafter",
wantArgs: `{}`,
wantOutput: "before\n[redacted]\nafter",
},
{
name: "oversized output keeps its full size",
input: `{}`,
output: long,
wantArgs: `{}`,
wantOutput: long[:transcriptFieldLimit],
wantBytes: len(long),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var got []agentrun.TranscriptEntry
recorder := newTranscript(func(entry agentrun.TranscriptEntry) { got = append(got, entry) })
call := core.ToolCall{ToolCallID: "c1", ToolName: "shell", Input: tt.input}
if _, err := recorder.BeforeToolExecute(t.Context(), &call); err != nil {
t.Fatal(err)
}
recorder.AfterToolExecute(t.Context(), call, &core.ToolResult{Output: tt.output})
if len(got) != 1 {
t.Fatalf("entries = %d, want 1", len(got))
}
entry := got[0]
if entry.Args != tt.wantArgs {
t.Errorf("args = %q, want %q", entry.Args, tt.wantArgs)
}
if entry.Output != tt.wantOutput {
t.Errorf("output = %q, want %q", entry.Output, tt.wantOutput)
}
if entry.OutputBytes != tt.wantBytes {
t.Errorf("output bytes = %d, want %d", entry.OutputBytes, tt.wantBytes)
}
})
}
}