Files
Agent-Native/runtime/subagent/subagent_hooks_test.go
T
weichen 6ddd3da8df Enable canonical versioned Go module consumption
Why: Allow consumers to download an immutable module revision without nested source checkouts or local path replacements.

Evidence: SELF package tests and the prior canonical-path rejection are recorded in the Dev dependency-workspace task card; remote consumption is replayed against the committed candidate.

Impact: Change the module identity and its Go imports while preserving API behavior. Existing historical submodule revisions remain buildable.

Refs: Versioned dependencies U1/U3; feature/dependency-workspace
2026-10-13 15:36:10 +00:00

61 lines
1.8 KiB
Go

package subagent
import (
"context"
"encoding/json"
"testing"
"git-ssh.u1680832.nyat.app/weichen/Agent-Native.git/runtime/hooks"
"git-ssh.u1680832.nyat.app/weichen/Agent-Native.git/runtime/tools"
)
func TestDelegateEmitsStartAndStop(t *testing.T) {
var seen []hooks.Event
bus := hooks.New()
bus.On(func(c hooks.Call) hooks.Outcome {
seen = append(seen, c.Event)
return hooks.Outcome{}
})
reg := tools.NewRegistry(t.TempDir())
RegisterWithHooks(reg, func(ctx context.Context, req Request) (Result, error) {
return Result{Success: true, Text: "done"}, nil
}, bus)
res := reg.Execute(context.Background(), "delegate_task", json.RawMessage(`{"goal":"核对第三章来源","done_criteria":"逐条标注"}`))
if res.IsError {
t.Fatalf("delegate result: %s", res.Content)
}
if len(seen) != 2 || seen[0] != hooks.SubagentStart || seen[1] != hooks.SubagentStop {
t.Fatalf("events = %v", seen)
}
}
func TestDelegateStopMarksFailure(t *testing.T) {
failed := false
bus := hooks.New()
bus.On(func(c hooks.Call) hooks.Outcome {
if c.Event == hooks.SubagentStop {
failed = c.IsError
}
return hooks.Outcome{}
})
reg := tools.NewRegistry(t.TempDir())
RegisterWithHooks(reg, func(ctx context.Context, req Request) (Result, error) {
return Result{Success: false, Text: "nope"}, nil
}, bus)
reg.Execute(context.Background(), "delegate_task", json.RawMessage(`{"goal":"x","done_criteria":"y"}`))
if !failed {
t.Fatal("stop event did not mark the failure")
}
}
func TestRegisterWithoutBusKeepsSilent(t *testing.T) {
reg := tools.NewRegistry(t.TempDir())
Register(reg, func(ctx context.Context, req Request) (Result, error) {
return Result{Success: true, Text: "ok"}, nil
})
res := reg.Execute(context.Background(), "delegate_task", json.RawMessage(`{"goal":"x","done_criteria":"y"}`))
if res.IsError {
t.Fatalf("result: %s", res.Content)
}
}