| index 7a6deb7cf..518a6350d 100644 |
| --- a/internal/console/stateless_floor_test.go |
| +++ b/internal/console/stateless_floor_test.go |
| @@ -10,6 +10,7 @@ import ( |
| "time" |
| |
| "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/status" |
| ) |
| |
| const statelessFloorWant = "this box needs platform v0.34.0 or later to run a stateless release. update the box and try again" |
| @@ -47,6 +48,7 @@ func TestStatelessRuntimeFloorAPIMutations(t *testing.T) { |
| } { |
| t.Run(action+"/"+tc.name, func(t *testing.T) { |
| fx := newConsoleFixture(t) |
| + statelessFloorReports(t, fx, "stable") |
| if _, err := fx.st.CreateAppIn(OpsAccountID, "shop", "paul@keymail.dev", time.Now()); err != nil { |
| t.Fatal(err) |
| } |
| @@ -55,6 +57,7 @@ func TestStatelessRuntimeFloorAPIMutations(t *testing.T) { |
| t.Fatal(err) |
| } |
| const channel = "canary/shop" |
| + statelessFloorReports(t, fx, "canary") |
| statelessFloorPointer(t, fx, "canary", tc.platform) |
| // The app channel is independent of both platform channels. |
| statelessFloorPointer(t, fx, "stable", "v0.34.0") |
| @@ -106,7 +109,7 @@ type statelessPointerReads struct { |
| } |
| |
| func (s *statelessPointerReads) List(ctx context.Context, prefix string) ([]string, error) { |
| - if strings.HasPrefix(prefix, "control/system/") { |
| + if prefix == "status/boxes/" { |
| s.lists++ |
| if s.failList { |
| return nil, context.DeadlineExceeded |
| @@ -127,6 +130,7 @@ func (s *statelessPointerReads) Get(ctx context.Context, key string) ([]byte, st |
| |
| func TestStatelessRuntimeFloorSnapshotAndFleet(t *testing.T) { |
| fx := newConsoleFixture(t) |
| + statelessFloorReports(t, fx, "stable", "canary") |
| statelessFloorPointer(t, fx, "stable", "v0.34.0") |
| statelessFloorPointer(t, fx, "canary", "v0.34.0") |
| store := &statelessPointerReads{Store: fx.rel} |
| @@ -168,6 +172,7 @@ func TestStatelessRuntimeFloorPin(t *testing.T) { |
| for _, platform := range []string{"", "v0.33.9", "v0.34.0"} { |
| t.Run(platform, func(t *testing.T) { |
| fx := updatesFixture(t) |
| + statelessFloorReports(t, fx.consoleFixture, "stable") |
| fx.boxesEnforce(true) |
| m := release.Manifest{Schema: 1, Kind: "binary", App: "km", Version: "v3", Stateless: true, Artifacts: map[string]release.Artifact{"linux-amd64": {File: "app"}}} |
| if err := release.Ship(t.Context(), fx.rel, "bab", m, map[string][]byte{"linux-amd64": []byte("app")}); err != nil { |
| @@ -199,6 +204,7 @@ func TestStatelessRuntimeFloorBrowserAndPending(t *testing.T) { |
| for _, action := range []string{"promote", "rollback", "canary", "fasttrack", "pending-promote", "pending-fasttrack"} { |
| t.Run(action, func(t *testing.T) { |
| fx := newConsoleFixture(t) |
| + statelessFloorReports(t, fx, "stable") |
| if _, err := fx.st.CreateAppIn(OpsAccountID, "shop", "paul@keymail.dev", time.Now()); err != nil { |
| t.Fatal(err) |
| } |
| @@ -299,6 +305,7 @@ func (s *statelessChangedPointer) Get(ctx context.Context, key string) ([]byte, |
| |
| func TestStatelessRuntimeFloorChangedRollbackTarget(t *testing.T) { |
| fx := newConsoleFixture(t) |
| + statelessFloorReports(t, fx, "stable") |
| if _, err := fx.st.CreateAppIn(OpsAccountID, "shop", "paul@keymail.dev", time.Now()); err != nil { |
| t.Fatal(err) |
| } |
| @@ -347,6 +354,7 @@ func (s *statelessManifestReads) Get(ctx context.Context, key string) ([]byte, s |
| |
| func TestStatelessRuntimeFloorManifestReadFailureAdmits(t *testing.T) { |
| fx := newConsoleFixture(t) |
| + statelessFloorReports(t, fx, "stable") |
| store := &statelessManifestReads{Store: fx.rel, fail: true} |
| fx.srv.cfg.Releases = store |
| ctx := withWriteMemo(t.Context()) |
| @@ -359,3 +367,54 @@ func TestStatelessRuntimeFloorManifestReadFailureAdmits(t *testing.T) { |
| t.Fatalf("failed target read attempts = %d, want 1", store.reads) |
| } |
| } |
| + |
| +func statelessFloorReports(t *testing.T, fx *consoleFixture, channels ...string) { |
| + t.Helper() |
| + for _, channel := range channels { |
| + b := status.Box{Label: channel, GeneratedAt: time.Now(), Metrics: &status.BoxMetrics{SystemChannel: channel, UpdateSettings: status.UpdateSettingsProtocol}} |
| + raw, err := json.Marshal(b) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := fx.rel.Put(t.Context(), "status/boxes/"+strings.ReplaceAll(channel, "/", "-")+".json", raw, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| +} |
| + |
| +func TestStatelessRuntimeFloorFollowedChannels(t *testing.T) { |
| + for _, tc := range []struct { |
| + name string |
| + followed string |
| + failReports, failPointer, refuse bool |
| + }{ |
| + {name: "followed-below", followed: "v0.33.9", refuse: true}, |
| + {name: "abandoned-below-ignored", followed: "v0.34.0"}, |
| + {name: "all-followed-at-floor", followed: "v0.34.0"}, |
| + {name: "reports-unreadable", followed: "v0.34.0", failReports: true, refuse: true}, |
| + {name: "pointer-unreadable", followed: "v0.34.0", failPointer: true, refuse: true}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + statelessFloorReports(t, fx, "stable", "canary/live") |
| + statelessFloorPointer(t, fx, "stable", "v0.34.0") |
| + statelessFloorPointer(t, fx, "canary/live", tc.followed) |
| + statelessFloorPointer(t, fx, "canary/abandoned", "v0.1.0") |
| + store := &statelessPointerReads{Store: fx.rel, failList: tc.failReports, fail: tc.failPointer} |
| + fx.srv.cfg.Releases = store |
| + ctx := withWriteMemo(t.Context()) |
| + for range 2 { |
| + ref := fx.srv.statelessRuntimeRefusal(ctx, "app-channel", &release.Manifest{Stateless: true}, nil, "") |
| + if (ref != nil) != tc.refuse { |
| + t.Fatalf("refusal=%v", ref) |
| + } |
| + } |
| + if store.lists != 1 { |
| + t.Fatalf("report listings=%d", store.lists) |
| + } |
| + if !tc.refuse && store.reads != 2 { |
| + t.Fatalf("pointer reads=%d; want followed channels only, once each", store.reads) |
| + } |
| + }) |
| + } |
| +} |