| 1 | package boot |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "reasonix/internal/extension" |
| 7 | ) |
| 8 | |
| 9 | func TestShouldReuseDiscoveryKinds(t *testing.T) { |
| 10 | cases := []struct { |
| 11 | kind extension.SubgraphKind |
| 12 | want bool |
| 13 | }{ |
| 14 | {extension.SubgraphNone, true}, |
| 15 | {extension.SubgraphInterceptorOnly, true}, |
| 16 | {extension.SubgraphUIOnly, true}, |
| 17 | {extension.SubgraphProviderOnly, true}, |
| 18 | {extension.SubgraphMCPOnly, true}, |
| 19 | {extension.SubgraphSidecar, false}, |
| 20 | {extension.SubgraphFull, false}, |
| 21 | } |
| 22 | for _, tc := range cases { |
| 23 | plan := &extension.RuntimePlan{Kind: tc.kind, Added: []extension.ComponentID{"x"}} |
| 24 | if tc.kind == extension.SubgraphNone { |
| 25 | plan.Added = nil |
| 26 | } |
| 27 | if got := shouldReuseDiscovery(plan); got != tc.want { |
| 28 | t.Fatalf("kind %v: got %v want %v", tc.kind, got, tc.want) |
| 29 | } |
| 30 | } |
| 31 | if shouldReuseDiscovery(nil) { |
| 32 | t.Fatal("nil plan must not reuse") |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | func TestShouldReuseSnapshot(t *testing.T) { |
| 37 | if !shouldReuseSnapshot(&extension.RuntimePlan{Kind: extension.SubgraphNone}) { |
| 38 | t.Fatal("no-op should reuse snapshot") |
| 39 | } |
| 40 | if !shouldReuseSnapshot(&extension.RuntimePlan{Kind: extension.SubgraphUIOnly, Reloaded: []extension.ComponentID{"a"}}) { |
| 41 | t.Fatal("UI-only should reuse snapshot body") |
| 42 | } |
| 43 | if shouldReuseSnapshot(&extension.RuntimePlan{Kind: extension.SubgraphProviderOnly, Reloaded: []extension.ComponentID{"a"}}) { |
| 44 | t.Fatal("provider-only must not claim snapshot cache reuse") |
| 45 | } |
| 46 | } |
| 47 |