Files
AutoZero/llm/trace_test.go
T
Sakurasan d5dac5a6fc feat: AutoZero 通用 Agent 框架(从 AutoGo 五阶段拆分完成)
llm(三协议 Provider)/ session(JSONL 持久化)/ tools(Registry、围栏、
builtin、computer)/ cdp(browser)/ skills / mcp / agent(循环、两级压缩、
编排、审批门控)+ 底座 jsonl/textx/execx/diag/scratch/spill/imagecache。

产品装配代码(config 桥接、schedule 工具、memory/plan/retro/prompt)
留在 AutoGo,宿主接入方式见 MIGRATION.md。
2026-10-26 00:54:46 +08:00

48 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package llm
import (
"encoding/json"
"strings"
"testing"
)
// TestTraceFieldsNeverSentToAPI 锁死一条边界:Message 上的本地 trace 字段
// (started_at / duration_ms / step)绝不能出现在任何 provider 的请求体里。
// 三家 provider 都靠手工白名单拼 body,一旦有人改成 json.Marshal(Message)
// 或顺手把字段透传,这个测试会立刻失败。
func TestTraceFieldsNeverSentToAPI(t *testing.T) {
msgs := []Message{{
Role: RoleAssistant,
Content: "hi",
ToolCalls: []ToolCall{{ID: "t1", Name: "read", Input: "{}"}},
StartedAt: 1700000000000,
DurationMs: 42,
Step: 3,
}, {
Role: RoleTool,
Content: "result",
ToolCallID: "t1",
StartedAt: 1700000000001,
DurationMs: 7,
Step: 3,
}}
builders := map[string]any{
"openai": oaBuildMessages("sys", msgs),
"responses": rsBuildInput("sys", msgs),
"anthropic": anBuildMessages(msgs, true),
}
for name, body := range builders {
raw, err := json.Marshal(body)
if err != nil {
t.Fatalf("%s: marshal: %v", name, err)
}
s := string(raw)
for _, key := range []string{`"started_at"`, `"duration_ms"`, `"step"`} {
if strings.Contains(s, key) {
t.Errorf("%s request body leaked trace field %s: %s", name, key, s)
}
}
}
}