Files
ARTEX/third_party/norma/harness/task_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

71 lines
1.9 KiB
Go

package harness
import (
"strings"
"testing"
"time"
"github.com/Autumn-27/norma/llm"
"github.com/Autumn-27/norma/permission"
"github.com/Autumn-27/norma/tool"
)
// A pending background-task completion is drained into the conversation and the
// loop takes one extra turn so the model can react to it.
func TestTaskNotificationInjected(t *testing.T) {
mgr, err := tool.NewManager("harness-notify-test")
if err != nil {
t.Fatalf("NewManager: %v", err)
}
defer mgr.Cleanup()
task, err := mgr.Spawn(tool.SpawnSpec{Command: "echo hi"})
if err != nil {
t.Fatalf("Spawn: %v", err)
}
mgr.Background(task.ID)
// Wait until the task finishes and its notification is queued.
deadline := time.Now().Add(5 * time.Second)
for {
if info, ok := mgr.Get(task.ID); ok && info.Status.Terminal() {
break
}
if time.Now().After(deadline) {
t.Fatal("task did not finish")
}
time.Sleep(10 * time.Millisecond)
}
// Model: first turn produces no tools (loop should inject the notification and
// continue); second turn completes.
m := &scriptedModel{turns: [][]llm.StreamEvent{
textTurn("first"),
textTurn("done"),
}}
in := QueryInput{
Messages: []llm.Message{llm.UserText("go")},
Tools: tool.NewRegistry(tool.NewBash()),
PermissionMode: permission.ModeBypass,
WorkingDir: t.TempDir(),
Tasks: mgr,
}
term := drain(t, in, QueryDeps{CallModel: m.call})
if term.Reason != ReasonCompleted || term.Text != "done" {
t.Fatalf("terminal=%+v", term)
}
if m.calls != 2 {
t.Fatalf("expected the loop to take an extra turn for the notification, calls=%d", m.calls)
}
var found bool
for _, msg := range term.Messages {
if strings.Contains(msg.Text(), "<task-notification>") && strings.Contains(msg.Text(), task.OutputPath) {
found = true
}
}
if !found {
t.Fatal("no task-notification injected into the conversation")
}
}