carlos / platform Public

test: end-to-end path flip and rollback

Walks claim -> reconcile -> fingerprint -> reload -> traffic, then walks it
back. With ti.to not moving behind the edge, this is the only thing that
proves the four layers compose rather than each working against a
hand-written input.

Asserts the fingerprint actually moves: a flip that reconciles correctly and
never reaches the live map is the failure this feature is most exposed to.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 043bc05cd5eac9be124c16585dcc375decb785b6 parent 6b93daa
1 file changed, +117 −0
  • internal/edge/path_e2e_test.go +117 −0
diff --git a/internal/edge/path_e2e_test.go b/internal/edge/path_e2e_test.go
new file mode 100644
index 000000000..67ed8bc26
--- /dev/null
+++ b/internal/edge/path_e2e_test.go
@@ -0,0 +1,117 @@
+package edge
+
+import (
+ "context"
+ "net/http/httptest"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/domains"
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// TestPathFlipEndToEnd walks the whole chain a real flip takes — claim
+// published, reconcile pass, fingerprint moves, edge reloads, traffic changes
+// — and then walks it backwards. Each earlier task proved one layer against a
+// hand-written input; this is the only test that proves they compose.
+//
+// The registry write and the edge reload are driven directly rather than
+// waited on: the 2s tick is a latency bound, not a correctness property, and
+// polling it would make this test slow and flaky. What must be true is that
+// the fingerprint MOVES, which is asserted rather than assumed.
+func TestPathFlipEndToEnd(t *testing.T) {
+ ctx := context.Background()
+ classic, _ := hostEchoBackend(t, "classic")
+ golive, _ := hostEchoBackend(t, "go")
+
+ reg := openReg(t)
+ if err := reg.Upsert(registry.Route{
+ Host: "ti.to", Kind: "service", Account: "tito", App: "classic",
+ Addr: classic.Listener.Addr().String(), Status: "ready",
+ }); err != nil {
+ t.Fatal(err)
+ }
+ if err := reg.Upsert(registry.Route{
+ Host: "go.tito.io", Kind: "service", Account: "tito", App: "go",
+ Addr: golive.Listener.Addr().String(), Status: "ready",
+ }); err != nil {
+ t.Fatal(err)
+ }
+
+ store := release.NewDirStore(t.TempDir())
+ if _, _, err := domains.AttachClaim(ctx, store, domains.Claim{
+ Schema: 1, Host: "ti.to", Account: "tito", App: "classic",
+ Route: "ti.to", CreatedAt: "2026-09-03T00:00:00Z",
+ }); err != nil {
+ t.Fatal(err)
+ }
+
+ e, err := New(reg, nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ srv := httptest.NewServer(e)
+ defer srv.Close()
+
+ // Before the flip: everything is classic.
+ if _, body := getHostPath(t, srv.URL, "ti.to", "/paulca/awesomeconf"); body != "classic" {
+ t.Fatalf("before the flip: body = %q, want classic", body)
+ }
+
+ fpBefore, err := reg.Fingerprint()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ // The flip: Tito publishes its map, the pass folds it, the edge reloads.
+ if _, err := domains.SetClaimPaths(ctx, store, "ti.to", "tito", "classic",
+ map[string]string{"paulca": "go.tito.io"}); err != nil {
+ t.Fatal(err)
+ }
+ if err := domains.ReconcileAliases(ctx, store, reg, time.Now, nil, nil); err != nil {
+ t.Fatal(err)
+ }
+ fpAfter, err := reg.Fingerprint()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if fpBefore == fpAfter {
+ t.Fatal("fingerprint did not move across a flip — the edge's watcher would never reload")
+ }
+ if err := e.Reload(); err != nil {
+ t.Fatal(err)
+ }
+
+ // After the flip: that account is on Go, its neighbours are not.
+ if _, body := getHostPath(t, srv.URL, "ti.to", "/paulca/awesomeconf"); body != "go" {
+ t.Fatalf("after the flip: body = %q, want go", body)
+ }
+ if _, body := getHostPath(t, srv.URL, "ti.to", "/someoneelse/event"); body != "classic" {
+ t.Fatalf("after the flip: a neighbouring account moved too, body = %q", body)
+ }
+ if _, body := getHostPath(t, srv.URL, "ti.to", "/paulcarson"); body != "classic" {
+ t.Fatalf("after the flip: a longer account name was dragged along, body = %q", body)
+ }
+
+ // The rollback: republish without that account.
+ if _, err := domains.SetClaimPaths(ctx, store, "ti.to", "tito", "classic", nil); err != nil {
+ t.Fatal(err)
+ }
+ if err := domains.ReconcileAliases(ctx, store, reg, time.Now, nil, nil); err != nil {
+ t.Fatal(err)
+ }
+ if err := e.Reload(); err != nil {
+ t.Fatal(err)
+ }
+ if _, body := getHostPath(t, srv.URL, "ti.to", "/paulca/awesomeconf"); body != "classic" {
+ t.Fatalf("after the rollback: body = %q, want classic", body)
+ }
+ rows, err := reg.ListPaths()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(rows) != 0 {
+ t.Fatalf("after the rollback: %d path rows remain, want 0", len(rows))
+ }
+}