carlos / platform Public

test: publish box snapshots on witness boxes like production

Wait for fresh snapshots from both agents before the first witness case.
Use the production status writer and cadence; reject missing, stale or
partial snapshot evidence. Product alias behavior is unchanged.
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev f273661c3e064bd92e2626b7bf4283b44d63be45 parent 9864a42
2 files changed, +72 −0
  • internal/host/region_ha_g2_peer_test.go +34 −0
  • internal/host/region_ha_g2_pool_root_linux_test.go +38 −0

Intent

Human

<task-notification> <task-id>bjk9n604d</task-id> <tool-use-id>toolu_01SdG9q8REFYNvyALzdrmbCW</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/5555438b-7fa2-408d-b2c4-9fa87ea89332/tasks/bjk9n604d.output</output-file> <status>completed</status> <summary>Background command "Run F-B witness live, run 9" completed (exit code 0)</summary> </task-notification>

diff --git a/internal/host/region_ha_g2_peer_test.go b/internal/host/region_ha_g2_peer_test.go
index a3c3140b2..36898dbe0 100644
--- a/internal/host/region_ha_g2_peer_test.go
+++ b/internal/host/region_ha_g2_peer_test.go
@@ -11,8 +11,42 @@ import (
"time"
"github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/status"
)
+func TestG2PoolBoxSnapshotsReady(t *testing.T) {
+ now := time.Now().UTC()
+ for _, tc := range []struct {
+ name string
+ boxes []status.Box
+ corrupt bool
+ wantReady bool
+ }{
+ {name: "missing both"},
+ {name: "missing A", boxes: []status.Box{{Label: "box-b", GeneratedAt: now}}},
+ {name: "missing B", boxes: []status.Box{{Label: "box-a", GeneratedAt: now}}},
+ {name: "wrong label", boxes: []status.Box{{Label: "other", GeneratedAt: now}, {Label: "box-b", GeneratedAt: now}}},
+ {name: "stale A", boxes: []status.Box{{Label: "box-a", GeneratedAt: now.Add(-16 * time.Minute)}, {Label: "box-b", GeneratedAt: now}}},
+ {name: "fresh both", boxes: []status.Box{{Label: "box-a", GeneratedAt: now}, {Label: "box-b", GeneratedAt: now}}, wantReady: true},
+ {name: "partial listing", boxes: []status.Box{{Label: "box-a", GeneratedAt: now}, {Label: "box-b", GeneratedAt: now}}, corrupt: true},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ s := release.NewDirStore(t.TempDir())
+ for _, box := range tc.boxes {
+ g2Must(t, status.WriteBox(t.Context(), s, box))
+ }
+ if tc.corrupt {
+ _, err := s.Put(t.Context(), "status/boxes/broken.json", []byte("not JSON"), "")
+ g2Must(t, err)
+ }
+ err := g2BoxSnapshotsReady(t.Context(), s, []string{"box-a", "box-b"}, now)
+ if (err == nil) != tc.wantReady {
+ t.Fatalf("ready=%t, want %t: %v", err == nil, tc.wantReady, err)
+ }
+ })
+ }
+}
+
func TestG2PoolJournalBoundary(t *testing.T) {
now := time.Unix(100, 123456000)
for _, tc := range []struct{ output, previous, want string }{
diff --git a/internal/host/region_ha_g2_pool_root_linux_test.go b/internal/host/region_ha_g2_pool_root_linux_test.go
index ec969d97c..84f8dc091 100644
--- a/internal/host/region_ha_g2_pool_root_linux_test.go
+++ b/internal/host/region_ha_g2_pool_root_linux_test.go
@@ -31,6 +31,7 @@ import (
"github.com/carlosframework/platform/internal/hafresh"
"github.com/carlosframework/platform/internal/provision"
"github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/status"
)
type g2Response struct {
@@ -338,6 +339,42 @@ func g2Seed(t *testing.T, storage *g2Storage) (g2Config, []byte) {
return config, mesh
}
+func g2BoxSnapshotsReady(ctx context.Context, s release.Store, refs []string, now time.Time) error {
+ boxes, complete, err := status.LoadBoxesComplete(ctx, s)
+ if err != nil {
+ return err
+ }
+ if !complete {
+ return errors.New("box snapshot listing is incomplete")
+ }
+ for _, ref := range refs {
+ found := false
+ for _, box := range boxes {
+ if box.Label == ref && !status.BoxStale(box, now, status.SnapshotPeriod) {
+ found = true
+ break
+ }
+ }
+ if !found {
+ return fmt.Errorf("no fresh agent snapshot at status/boxes/%s.json", ref)
+ }
+ }
+ return nil
+}
+
+func g2WaitBoxSnapshots(t *testing.T, s release.Store, refs ...string) {
+ t.Helper()
+ ctx, cancel := context.WithTimeout(t.Context(), 90*time.Second)
+ defer cancel()
+ evidence, err := g2WaitIsolation(ctx, time.Second, func(ctx context.Context) error {
+ probeCtx, probeCancel := context.WithTimeout(ctx, 5*time.Second)
+ defer probeCancel()
+ return g2BoxSnapshotsReady(probeCtx, s, refs, time.Now())
+ })
+ t.Logf("BOX_SNAPSHOT_READINESS refs=%v %s", refs, g2JSON(t, evidence))
+ g2Must(t, err)
+}
+
func TestRootG2PoolIngress(t *testing.T) {
g2Prereqs(t, "A")
// Local helpers never call this test: it requires the two driver-owned IIDs.
@@ -373,6 +410,7 @@ func TestRootG2PoolIngress(t *testing.T) {
client := g2Client(t, config.CA)
b = g2Peer(t, g2RPC{Action: "start"})
g2Must(t, a.start())
+ g2WaitBoxSnapshots(t, storage.deploy, a.state().Ref, b.Ref)
g2Serial(t, storage.deploy)
g2WaitPeer(t, storage.deploy, b.Ref, []string{"ha"})
// Any changed guard is observed at the first ineligible local service,