| 1 | package boot |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "testing" |
| 6 | "time" |
| 7 | |
| 8 | "reasonix/internal/config" |
| 9 | "reasonix/internal/extension/protocol" |
| 10 | ) |
| 11 | |
| 12 | func TestModelCandidateDiscardPreservesLiveExtensionManager(t *testing.T) { |
| 13 | isolateConfigHome(t) |
| 14 | root := robustTempDir(t) |
| 15 | t.Chdir(root) |
| 16 | writeRuntimeFixture(t, root) |
| 17 | installBootFakePlugin(t, config.ReasonixHomeDir(), "preserved", map[string]any{}) |
| 18 | old, err := BuildRuntime(t.Context(), Options{}) |
| 19 | if err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | t.Cleanup(old.Controller.Close) |
| 23 | client := old.Extensions.Client("preserved") |
| 24 | options := Options{RuntimeReload: RuntimeReload{Extensions: old.Extensions, Graph: old.Plan.Graph}} |
| 25 | options.Model = "missing/model" |
| 26 | if _, err := Rebuild(t.Context(), old.Controller, options); err == nil { |
| 27 | t.Fatal("expected model resolution failure") |
| 28 | } |
| 29 | options.Model = "" |
| 30 | candidate, err := Rebuild(t.Context(), old.Controller, options) |
| 31 | if err != nil { |
| 32 | t.Fatal(err) |
| 33 | } |
| 34 | if candidate.Extensions.Client("preserved") == client { |
| 35 | t.Fatal("candidate stole outgoing sidecar before publication") |
| 36 | } |
| 37 | candidate.Controller.ReleaseResources() |
| 38 | if old.Extensions.Client("preserved") != client || client.Exited() { |
| 39 | t.Fatal("discard retired live extension manager") |
| 40 | } |
| 41 | result, err := client.Intercept(t.Context(), protocol.EventSessionStart, json.RawMessage(`{}`), 5*time.Second) |
| 42 | if err != nil || result.Decision != protocol.DecisionContinue { |
| 43 | t.Fatalf("outgoing extension lost after discard: %v, %v", result, err) |
| 44 | } |
| 45 | } |
| 46 |