Cookies took Secure from r.TLS, which is nil behind a proxy that terminates TLS, so sign-in cookies went out without it. Every dashboard cookie now goes through one builder that reads the scheme the way the origin check does. The worktree reset and the agent worker's chown walk use os.Root, so a symlink swapped in mid-walk can't point them outside the worktree. gosec runs in golangci-lint, tests included. G104, G115, G204 and G304 are excluded in config; each remaining finding is fixed or suppressed at the site with its reason.
72 lines
2.2 KiB
Go
72 lines
2.2 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-----" //nolint:gosec // G101: a fake key the redaction must catch.
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|