| 1 | package planmode_test |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "reasonix/internal/planmode" |
| 7 | "reasonix/internal/tool" |
| 8 | |
| 9 | _ "reasonix/internal/tool/builtin" |
| 10 | ) |
| 11 | |
| 12 | func TestBuiltinPhaseClassifiersMatchPolicy(t *testing.T) { |
| 13 | builtins := tool.Builtins() |
| 14 | if len(builtins) == 0 { |
| 15 | t.Fatal("tool.Builtins() is empty") |
| 16 | } |
| 17 | for _, tl := range builtins { |
| 18 | safety := planmode.PlanSafetyUnknown |
| 19 | if classifier, ok := tl.(tool.PlanModeClassifier); ok { |
| 20 | if classifier.PlanModeSafe() { |
| 21 | safety = planmode.PlanSafetySafe |
| 22 | } else { |
| 23 | safety = planmode.PlanSafetyUnsafe |
| 24 | } |
| 25 | } |
| 26 | got := (planmode.Policy{}).Decide(planmode.Call{ |
| 27 | Name: tl.Name(), |
| 28 | ReadOnly: tl.ReadOnly(), |
| 29 | Safety: safety, |
| 30 | }) |
| 31 | if got.Blocked != (safety == planmode.PlanSafetyUnsafe) { |
| 32 | t.Errorf("builtin %q safety=%v decision=%+v", tl.Name(), safety, got) |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | func TestCompleteStepExplicitlyOptsOutOfPlanPhase(t *testing.T) { |
| 38 | for _, tl := range tool.Builtins() { |
| 39 | if tl.Name() != "complete_step" { |
| 40 | continue |
| 41 | } |
| 42 | classifier, ok := tl.(tool.PlanModeClassifier) |
| 43 | if !ok || classifier.PlanModeSafe() { |
| 44 | t.Fatal("complete_step must explicitly opt out of the planning phase") |
| 45 | } |
| 46 | return |
| 47 | } |
| 48 | t.Fatal("complete_step builtin not registered") |
| 49 | } |
| 50 |