test: keep departure schedule deliveries alive after fixture ticks
Bind asynchronous fixture deliveries to the agent test lifetime and use the loopback deployment store inside the installed unit sandbox. Preserve both recovery assertions and include timer state on failure.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+83
−4
internal/host/hadepartures_harness_test.go+74 −0internal/host/hadepartures_root_linux_test.go+5 −3internal/host/haplacement_root_linux_test.go+4 −1
Intent
Human
<task-notification> <task-id>bq905n1f1</task-id> <tool-use-id>toolu_01LrmsyyJshUYtDEuMWpQ7va</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22c9817b-87ae-432b-b6d2-3ebbc209af38/tasks/bq905n1f1.output</output-file> <status>completed</status> <summary>Background command "Wait for Astra B5" completed (exit code 0)</summary> </task-notification>
Human
Check Astra B5 (task-B5-astra-a.md/.log) for P1b-3b slice T; ledger progress.md in /home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b3b-duties/.superpowers/sdd/2026-11-03-region-ha-p1b3b-duties/; Bash sandbox off; continue SDD (root runner, whole-branch review, census, merge).
diff --git a/internal/host/hadepartures_harness_test.go b/internal/host/hadepartures_harness_test.go| new file mode 100644 |
| index 000000000..af752d988 |
| --- /dev/null |
| +++ b/internal/host/hadepartures_harness_test.go |
| @@ -0,0 +1,74 @@ |
| +package host |
| + |
| +import ( |
| + "context" |
| + "net/http" |
| + "net/http/httptest" |
| + "path/filepath" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/schedule" |
| +) |
| + |
| +func departureTickHandler(lifetime context.Context, runner *schedule.Runner) http.HandlerFunc { |
| + return func(_ http.ResponseWriter, _ *http.Request) { |
| + runner.Tick(lifetime) |
| + } |
| +} |
| + |
| +type departureTickDelivery struct { |
| + entered chan context.Context |
| + resume chan struct{} |
| +} |
| + |
| +func (d departureTickDelivery) Deliver(ctx context.Context, _ registry.Route, _ *http.Request) (int, error) { |
| + d.entered <- ctx |
| + <-d.resume |
| + return http.StatusOK, ctx.Err() |
| +} |
| + |
| +func TestHADepartureHarnessTickLifetime(t *testing.T) { |
| + reg, err := registry.Open(filepath.Join(t.TempDir(), "registry.db")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer reg.Close() |
| + const host = "shop.example.com" |
| + if err := reg.Upsert(registry.Route{Host: host, Kind: "instance", App: "shop", Account: "bab", Status: "ready"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + now := time.Now() |
| + if err := reg.UpsertTimer(registry.Timer{Host: host, Name: "reminder", Kind: "once", Spec: "at 1", Path: "/remind", NextAt: 1, DueAt: 1}); err != nil { |
| + t.Fatal(err) |
| + } |
| + delivery := departureTickDelivery{entered: make(chan context.Context, 1), resume: make(chan struct{})} |
| + finished := make(chan struct{}) |
| + runner := &schedule.Runner{Reg: reg, Deliver: delivery, Now: func() time.Time { return now }, Token: func(string) (string, error) { return "fixture", nil }, Report: func(registry.Route, schedule.Status) { close(finished) }} |
| + lifetime, stop := context.WithCancel(t.Context()) |
| + defer stop() |
| + request, cancel := context.WithCancel(t.Context()) |
| + defer cancel() |
| + departureTickHandler(lifetime, runner).ServeHTTP(httptest.NewRecorder(), httptest.NewRequest("POST", "/tick", nil).WithContext(request)) |
| + var call context.Context |
| + select { |
| + case call = <-delivery.entered: |
| + case <-time.After(5 * time.Second): |
| + t.Fatal("delivery did not enter") |
| + } |
| + cancel() |
| + if call.Err() != nil { |
| + t.Error("admin request completion cancelled scheduled delivery:", call.Err()) |
| + } |
| + close(delivery.resume) |
| + select { |
| + case <-finished: |
| + case <-time.After(5 * time.Second): |
| + t.Fatal("delivery did not finish") |
| + } |
| + timer, err := reg.GetTimer(host, "reminder") |
| + if err != nil || timer == nil || timer.NextAt != 0 || timer.LastStatus != "200" { |
| + t.Fatalf("delivery not durably completed: %+v, %v", timer, err) |
| + } |
| +} |
diff --git a/internal/host/hadepartures_root_linux_test.go b/internal/host/hadepartures_root_linux_test.go| index 1b9d5ba04..e56c76608 100644 |
| --- a/internal/host/hadepartures_root_linux_test.go |
| +++ b/internal/host/hadepartures_root_linux_test.go |
| @@ -129,6 +129,7 @@ func departureRootWire(t *testing.T, ref string, svc *activator.Service, eb *act |
| } |
| sd := newScheduleDeps(reg, store, svc, nil, eb.DataDir) |
| sd.runner.Now = clock |
| + tick := departureTickHandler(t.Context(), sd.runner) |
| var imported int |
| actualAdopt := c.cfg.Adopt |
| c.cfg.Adopt = func(ctx context.Context, h provision.DepartureHost, d registry.HADeparture, v hafresh.View) (activator.AdoptResult, error) { |
| @@ -167,7 +168,7 @@ func departureRootWire(t *testing.T, ref string, svc *activator.Service, eb *act |
| now = time.Unix(n, 0).UTC() |
| mu.Unlock() |
| } |
| - sd.runner.Tick(r.Context()) |
| + tick(w, r) |
| case "shutdown": |
| ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second) |
| defer cancel() |
| @@ -258,8 +259,9 @@ func departureRootCall(t *testing.T, data, command string) departureRootState { |
| func departureRootWait(t *testing.T, data, name string) { |
| t.Helper() |
| deadline := time.Now().Add(2 * time.Minute) |
| + var state departureRootState |
| for time.Now().Before(deadline) { |
| - state := departureRootCall(t, data, "state") |
| + state = departureRootCall(t, data, "state") |
| delivered := 0 |
| for _, timers := range state.Timers { |
| for _, timer := range timers { |
| @@ -273,7 +275,7 @@ func departureRootWait(t *testing.T, data, name string) { |
| } |
| time.Sleep(100 * time.Millisecond) |
| } |
| - t.Fatal("schedule did not deliver both durable registrations without visitors") |
| + t.Fatalf("schedule did not deliver both durable registrations without visitors: %+v", state) |
| } |
| func departureRootSecrets(t *testing.T) [32]byte { |
| var all strings.Builder |
diff --git a/internal/host/haplacement_root_linux_test.go b/internal/host/haplacement_root_linux_test.go| index f8a45762e..87929d138 100644 |
| --- a/internal/host/haplacement_root_linux_test.go |
| +++ b/internal/host/haplacement_root_linux_test.go |
| @@ -132,7 +132,10 @@ func TestColdPlacementRootAgent(t *testing.T) { |
| t.Setenv("CARLOS_S3_ENDPOINT", os.Getenv("COLD_ROOT_DATA_ENDPOINT")) |
| t.Setenv("CARLOS_DEPLOYMENT_BUCKET", "") |
| data := os.Getenv("CARLOS_DATA_DIR") |
| - store := release.NewDirStore(os.Getenv("CARLOS_DEPLOYMENT_DIR")) |
| + var store release.Store = release.NewDirStore(os.Getenv("CARLOS_DEPLOYMENT_DIR")) |
| + if strings.HasPrefix(os.Getenv("COLD_ROOT_MODE"), "departure-") { |
| + store = publisher |
| + } |
| reg, err := registry.Open(filepath.Join(data, "registry.db")) |
| lifecycleCheck(t, "edge registry", err) |
| defer reg.Close() |