Files
wangdefa f782b612ec build: 内置 norma 模块,构建不再依赖上游仓库
把 github.com/Autumn-27/norma v0.4.3(commit 320ae32)的源码复制到
third_party/norma,并用 go.mod 的 replace 指向本地副本。上游删除仓库或
改写 tag 都不再影响本仓库构建。

- 已验证 GOPROXY=off 下可完整编译并打出发行包
- go.sum 中该模块的两条校验记录随之删除(本地 replace 不需要哈希)
- 升级方法与授权注意事项见 third_party/README.md
2026-10-20 21:10:41 -07:00

45 lines
1.5 KiB
Go

package harness
import (
"strings"
"testing"
"github.com/Autumn-27/norma/llm"
"github.com/Autumn-27/norma/tool"
)
// The global post-tool net caps an oversized text block regardless of the tool.
func TestCapOutputCapsOversizedTextBlock(t *testing.T) {
tc := &tool.ToolContext{MaxOutputChars: 100} // no OutputDir → head+tail truncation
long := strings.Repeat("z", 5000)
res := tool.Result{Content: []llm.ContentBlock{llm.TextBlock(long)}}
out := capOutput(tc, res)
got := out.Content[0].Text
if len(got) >= 5000 || !strings.Contains(got, "characters truncated]") {
t.Fatalf("capOutput did not cap oversized block: len=%d", len(got))
}
}
// Output already within budget is passed through untouched.
func TestCapOutputLeavesSmallOutputIntact(t *testing.T) {
tc := &tool.ToolContext{MaxOutputChars: 100}
res := tool.Result{Content: []llm.ContentBlock{llm.TextBlock("fine")}}
if out := capOutput(tc, res); out.Content[0].Text != "fine" {
t.Fatalf("small output changed: %q", out.Content[0].Text)
}
}
// Output a tool already captured (carries the spill marker) is not re-processed,
// so the net never double-truncates.
func TestCapOutputIdempotentOnAlreadyCaptured(t *testing.T) {
tc := &tool.ToolContext{MaxOutputChars: 100}
pre := strings.Repeat("a", 100) + "\n\n... <persisted-output>[Output too large: full 9999 bytes ... saved to x.txt </persisted-output>"
res := tool.Result{Content: []llm.ContentBlock{llm.TextBlock(pre)}}
if out := capOutput(tc, res); out.Content[0].Text != pre {
t.Fatalf("capOutput re-processed already-captured output")
}
}