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
+102
@@ -0,0 +1,102 @@
|
||||
package harness
|
||||
|
||||
import (
|
||||
"context"
|
||||
"iter"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Autumn-27/norma/llm"
|
||||
"github.com/Autumn-27/norma/permission"
|
||||
"github.com/Autumn-27/norma/tool"
|
||||
)
|
||||
|
||||
// On hitting MaxTurns with a Settlement configured, the loop injects the wrap-up
|
||||
// prompt, hides DisabledTools during wrap-up, and finishes with the ORIGINAL
|
||||
// budget reason (not ReasonCompleted).
|
||||
func TestSettlementOnBudgetHit(t *testing.T) {
|
||||
var toolsSeen [][]string
|
||||
turns := [][]llm.StreamEvent{
|
||||
toolTurn("a", "Bash", `{"command":"echo 1"}`), // turn 1 → hits MaxTurns=1
|
||||
textTurn("已写回事实并总结"), // settlement turn → natural stop
|
||||
}
|
||||
call := func(_ context.Context, req llm.CompletionRequest) iter.Seq2[llm.StreamEvent, error] {
|
||||
names := make([]string, 0, len(req.Tools))
|
||||
for _, ts := range req.Tools {
|
||||
names = append(names, ts.Name)
|
||||
}
|
||||
i := len(toolsSeen)
|
||||
toolsSeen = append(toolsSeen, names)
|
||||
evs := turns[i]
|
||||
return func(yield func(llm.StreamEvent, error) bool) {
|
||||
for _, ev := range evs {
|
||||
if !yield(ev, nil) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
in := QueryInput{
|
||||
Messages: []llm.Message{llm.UserText("go")},
|
||||
Tools: tool.NewRegistry(tool.NewBash()),
|
||||
PermissionMode: permission.ModeBypass,
|
||||
WorkingDir: t.TempDir(),
|
||||
MaxTurns: 1,
|
||||
Settlement: &Settlement{Prompt: "SETTLE_NOW 请写回事实", DisabledTools: []string{"Bash"}},
|
||||
}
|
||||
term := drain(t, in, QueryDeps{CallModel: call})
|
||||
|
||||
if term.Reason != ReasonMaxTurns {
|
||||
t.Fatalf("reason=%v, want ReasonMaxTurns(收尾后仍报原预算 reason)", term.Reason)
|
||||
}
|
||||
found := false
|
||||
for _, m := range term.Messages {
|
||||
for _, c := range m.Content {
|
||||
if strings.Contains(c.Text, "SETTLE_NOW") {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("收尾提示未被注入到对话")
|
||||
}
|
||||
if len(toolsSeen) < 2 {
|
||||
t.Fatalf("应至少 2 次模型调用(主+收尾),得 %d", len(toolsSeen))
|
||||
}
|
||||
if !contains(toolsSeen[0], "Bash") {
|
||||
t.Fatalf("主阶段应能看到 Bash: %v", toolsSeen[0])
|
||||
}
|
||||
if contains(toolsSeen[1], "Bash") {
|
||||
t.Fatalf("收尾阶段应屏蔽 Bash: %v", toolsSeen[1])
|
||||
}
|
||||
}
|
||||
|
||||
// With no Settlement, hitting the budget finishes immediately (unchanged behavior).
|
||||
func TestNoSettlementFinishesImmediately(t *testing.T) {
|
||||
m := &scriptedModel{turns: [][]llm.StreamEvent{
|
||||
toolTurn("a", "Bash", `{"command":"echo 1"}`),
|
||||
toolTurn("b", "Bash", `{"command":"echo 2"}`),
|
||||
}}
|
||||
in := QueryInput{
|
||||
Tools: tool.NewRegistry(tool.NewBash()),
|
||||
PermissionMode: permission.ModeBypass,
|
||||
WorkingDir: t.TempDir(),
|
||||
MaxTurns: 1,
|
||||
}
|
||||
term := drain(t, in, QueryDeps{CallModel: m.call})
|
||||
if term.Reason != ReasonMaxTurns {
|
||||
t.Fatalf("reason=%v", term.Reason)
|
||||
}
|
||||
if m.calls != 1 {
|
||||
t.Fatalf("无收尾应只调用 1 次模型,得 %d", m.calls)
|
||||
}
|
||||
}
|
||||
|
||||
func contains(xs []string, s string) bool {
|
||||
for _, x := range xs {
|
||||
if x == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in new issue
Block a user