Files
weichenandCursor 2e99ee3661 feat(intentflow): route confirmed generate steps through a task adapter
Persist ComboNeedsConfirm plans at confirm tier without executing writes, then run task.run via OwnerMux and a stable idempotency key.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-16 02:24:23 +00:00

59 lines
1.9 KiB
Go

package intentflow_test
import (
"context"
"testing"
"chat-agent-system/internal/app/intentflow"
)
type routeProbe struct {
keys []string
}
func (p *routeProbe) Authorize(_ context.Context, exec intentflow.StepExec) error {
p.keys = append(p.keys, "auth:"+exec.ActionKey)
return nil
}
func (p *routeProbe) Execute(ctx context.Context, exec intentflow.StepExec) (intentflow.Receipt, error) {
p.keys = append(p.keys, "exec:"+exec.ActionKey)
return intentflow.Receipt{IdempotencyKey: exec.IdempotencyKey, ActionDigest: exec.ActionDigest, ResultRef: "probe:" + exec.ActionKey}, nil
}
func (p *routeProbe) LookupReceipt(context.Context, string) (intentflow.Receipt, bool, error) {
return intentflow.Receipt{}, false, nil
}
func TestOwnerMuxRoutesGenerateToTask(t *testing.T) {
query := &routeProbe{}
task := &routeProbe{}
mux := intentflow.OwnerMux{Query: query, Task: task}
ctx := context.Background()
if _, err := mux.Execute(ctx, intentflow.StepExec{ActionKey: "regulation.query", IdempotencyKey: "k-q", ActionDigest: "dq"}); err != nil {
t.Fatal(err)
}
if _, err := mux.Execute(ctx, intentflow.StepExec{ActionKey: "task.run", IdempotencyKey: "k-t", ActionDigest: "dt"}); err != nil {
t.Fatal(err)
}
if _, err := mux.Execute(ctx, intentflow.StepExec{ActionKey: "task.run.adhoc", IdempotencyKey: "k-a", ActionDigest: "da"}); err != nil {
t.Fatal(err)
}
if len(query.keys) == 0 || query.keys[len(query.keys)-1] != "exec:regulation.query" {
t.Fatalf("query probe = %v", query.keys)
}
if len(task.keys) < 2 {
t.Fatalf("task probe = %v", task.keys)
}
}
func TestOwnerMuxNilTaskFailClosed(t *testing.T) {
mux := intentflow.OwnerMux{Query: intentflow.NewFakeActionOwner(), Task: nil}
_, err := mux.Execute(context.Background(), intentflow.StepExec{
ActionKey: "task.run", Principal: principal(), IdempotencyKey: "k", ActionDigest: "d",
})
if err != intentflow.ErrPlanActionForbidden {
t.Fatalf("nil Task must fail closed, got %v", err)
}
}