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。
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
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)
|
||
}
|
||
}
|
||
}
|
||
}
|