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
84 lines
3.3 KiB
Go
84 lines
3.3 KiB
Go
package route
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git-ssh.u1680832.nyat.app/weichen/Agent-System-Backend.git/internal/intentgate"
|
|
core "git-ssh.u1680832.nyat.app/weichen/Agent-System-Core.git"
|
|
)
|
|
|
|
func startCmd(action intentgate.ActionRef) intentgate.Command {
|
|
return intentgate.Command{Kind: intentgate.CommandStart, Action: action}
|
|
}
|
|
|
|
func TestDecideAutoPrefersCommandThenWorkflow(t *testing.T) {
|
|
in := intentgate.MatchResult{Branch: "matched", ID: "demo.x",
|
|
Commands: []intentgate.Command{startCmd(intentgate.ActionRef{Kind: intentgate.ActionAuto, ID: "demo.x"})}}
|
|
d := Decide(in, Env{HasCommand: func(string) bool { return true }})
|
|
if d.Kind != KindCommand || d.CommandID != "demo.x" {
|
|
t.Fatalf("auto command = %+v", d)
|
|
}
|
|
d = Decide(in, Env{
|
|
HasCommand: func(string) bool { return false },
|
|
WorkflowFor: func(string) (core.WorkflowDef, bool) { return core.WorkflowDef{ID: "wf"}, true },
|
|
})
|
|
if d.Kind != KindWorkflow || d.Workflow.ID != "wf" {
|
|
t.Fatalf("auto workflow = %+v", d)
|
|
}
|
|
d = Decide(in, Env{})
|
|
if d.Kind != KindTurn || !d.StartFound {
|
|
t.Fatalf("auto turn = %+v", d)
|
|
}
|
|
}
|
|
|
|
func TestDecideExplicitKinds(t *testing.T) {
|
|
mk := func(kind, id string) intentgate.MatchResult {
|
|
return intentgate.MatchResult{Branch: "matched", ID: "demo.x",
|
|
Commands: []intentgate.Command{startCmd(intentgate.ActionRef{Kind: kind, ID: id})}}
|
|
}
|
|
if d := Decide(mk(intentgate.ActionCommand, "cmd-1"), Env{HasCommand: func(id string) bool { return id == "cmd-1" }}); d.Kind != KindCommand || d.CommandID != "cmd-1" {
|
|
t.Fatalf("explicit command = %+v", d)
|
|
}
|
|
d := Decide(mk(intentgate.ActionCommand, "nope"), Env{
|
|
WorkflowFor: func(string) (core.WorkflowDef, bool) { return core.WorkflowDef{ID: "wf"}, true },
|
|
})
|
|
if d.Kind != KindTurn || d.Reason == "" {
|
|
t.Fatalf("unresolvable command = %+v", d)
|
|
}
|
|
if d := Decide(mk(intentgate.ActionWorkflow, "wf-1"), Env{
|
|
WorkflowFor: func(id string) (core.WorkflowDef, bool) { return core.WorkflowDef{ID: id}, true },
|
|
}); d.Kind != KindWorkflow || d.Workflow.ID != "wf-1" {
|
|
t.Fatalf("explicit workflow = %+v", d)
|
|
}
|
|
if d := Decide(mk(intentgate.ActionBlueprint, "bp-1"), Env{SquadReady: true}); d.Kind != KindSquad || d.Blueprint != "bp-1" {
|
|
t.Fatalf("blueprint = %+v", d)
|
|
}
|
|
if d := Decide(mk(intentgate.ActionBlueprint, "bp-1"), Env{}); d.Kind != KindTurn || d.Reason == "" {
|
|
t.Fatalf("blueprint without squad = %+v", d)
|
|
}
|
|
}
|
|
|
|
func TestDecideNonMatchedAndLegacyFallback(t *testing.T) {
|
|
if d := Decide(intentgate.MatchResult{Branch: "fallback"}, Env{}); d.Kind != KindTurn {
|
|
t.Fatalf("fallback = %+v", d)
|
|
}
|
|
// matched 但命令列表为空(旧消费方):按 TopID 走 auto,与现网一致。
|
|
d := Decide(intentgate.MatchResult{Branch: "matched", ID: "demo.x"}, Env{HasCommand: func(string) bool { return true }})
|
|
if d.Kind != KindCommand || d.StartFound {
|
|
t.Fatalf("legacy auto = %+v", d)
|
|
}
|
|
}
|
|
|
|
func TestSlotsFromStartCommand(t *testing.T) {
|
|
in := intentgate.MatchResult{Branch: "matched", ID: "demo.x",
|
|
Commands: []intentgate.Command{{
|
|
Kind: intentgate.CommandStart,
|
|
Action: intentgate.ActionRef{Kind: intentgate.ActionAuto, ID: "demo.x"},
|
|
Slots: map[string]string{"topic": "电机"},
|
|
}}}
|
|
d := Decide(in, Env{HasCommand: func(string) bool { return true }})
|
|
if d.Slots["topic"] != "电机" {
|
|
t.Fatalf("slots = %v", d.Slots)
|
|
}
|
|
}
|