Files
ARTEX/third_party/norma/tool/captureonce_test.go
T
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

55 lines
1.7 KiB
Go

package tool
import (
"os"
"strings"
"testing"
)
// First pass spills oversized output; a second pass over that result must not
// spill again or change it — the marker makes CaptureOnce idempotent, which is
// what lets a global post-tool net coexist with tools that Capture themselves.
func TestCaptureOnceSpillIsIdempotent(t *testing.T) {
dir := t.TempDir()
tc := &ToolContext{WorkingDir: dir, OutputDir: dir, MaxOutputChars: 100}
long := strings.Repeat("x", 5000)
first := CaptureOnce(tc, long)
if !strings.Contains(first, "<persisted-output>") {
t.Fatalf("first CaptureOnce should spill oversized output: %q", first)
}
if files, _ := os.ReadDir(dir); len(files) != 1 {
t.Fatalf("expected exactly 1 spill file, got %d", len(files))
}
second := CaptureOnce(tc, first)
if second != first {
t.Fatalf("CaptureOnce not idempotent on spilled output:\n first=%q\n second=%q", first, second)
}
if files, _ := os.ReadDir(dir); len(files) != 1 {
t.Fatalf("second CaptureOnce spilled again: %d files", len(files))
}
}
// Without an OutputDir, Capture falls back to head+tail truncation (a different
// marker). CaptureOnce must recognise that too and not re-truncate.
func TestCaptureOnceTruncationIsIdempotent(t *testing.T) {
tc := &ToolContext{MaxOutputChars: 100}
long := strings.Repeat("y", 5000)
first := CaptureOnce(tc, long)
if !strings.Contains(first, "characters truncated]") {
t.Fatalf("expected truncation marker: %q", first)
}
if second := CaptureOnce(tc, first); second != first {
t.Fatalf("CaptureOnce re-truncated already-truncated output")
}
}
func TestCaptureOncePassesShortOutput(t *testing.T) {
tc := &ToolContext{MaxOutputChars: 100}
if got := CaptureOnce(tc, "ok"); got != "ok" {
t.Fatalf("short output changed: %q", got)
}
}