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
This commit is contained in:
1 parent
a819fa3230
commit
f782b612ec
213 files changed
+37401
-2
No files matched your search
+68
@@ -0,0 +1,68 @@
|
||||
package compaction
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/Autumn-27/norma/llm"
|
||||
)
|
||||
|
||||
func TestIsOverflowStrings(t *testing.T) {
|
||||
cases := []struct {
|
||||
msg string
|
||||
want bool
|
||||
}{
|
||||
{"", false}, // nil handled separately below
|
||||
{"anthropic: status 400: prompt is too long", true},
|
||||
{"context length exceeded", true},
|
||||
{"maximum context window reached", true},
|
||||
{"error: context_length_exceeded", true},
|
||||
{"anthropic: status 413", true},
|
||||
{"network timeout", false},
|
||||
{"rate limited", false},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
if got := IsOverflow(errors.New(tc.msg)); got != tc.want {
|
||||
t.Errorf("IsOverflow(%q)=%v, want %v", tc.msg, got, tc.want)
|
||||
}
|
||||
}
|
||||
if IsOverflow(nil) {
|
||||
t.Fatal("IsOverflow(nil) must be false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsOverflowMethodForm(t *testing.T) {
|
||||
c := New(Config{ContextWindow: 200000}, nil)
|
||||
if !c.IsOverflow(errors.New("prompt is too long")) {
|
||||
t.Fatal("method form should detect overflow")
|
||||
}
|
||||
if c.IsOverflow(errors.New("boom")) {
|
||||
t.Fatal("method form false positive")
|
||||
}
|
||||
}
|
||||
|
||||
// New applies all defaults for a zero Config: 200000 window, 8000 output,
|
||||
// 8 recent messages — verified through the derived thresholds and geometry.
|
||||
func TestDefaultsApplied(t *testing.T) {
|
||||
c := New(Config{}, func(context.Context, []llm.Message) (string, error) { return "D", nil })
|
||||
if c.effectiveWindow() != 192000 { // 200000 - 8000
|
||||
t.Fatalf("effectiveWindow=%d, want 192000 (defaulted window/output)", c.effectiveWindow())
|
||||
}
|
||||
if c.autoThreshold() != 179000 {
|
||||
t.Fatalf("autoThreshold=%d, want 179000", c.autoThreshold())
|
||||
}
|
||||
// KeepRecent defaulted to 8: summarizing 10 messages preserves the last 8.
|
||||
var msgs []llm.Message
|
||||
for range 10 {
|
||||
msgs = append(msgs, bigMsg(llm.RoleUser, 10))
|
||||
}
|
||||
out, ok := c.autoCompact(context.Background(), msgs, 100, "auto")
|
||||
if !ok {
|
||||
t.Fatal("autoCompact should run")
|
||||
}
|
||||
meta, _ := llm.ParseBoundaryMeta(out[llm.LastBoundaryIndex(out)])
|
||||
if meta.MessagesSummarized != 2 { // 10 - 8 kept
|
||||
t.Fatalf("messagesSummarized=%d, want 2 (KeepRecent defaulted to 8)", meta.MessagesSummarized)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user