//go:build integration package replays import ( "context" "fmt" "strings" "testing" "time" ) // **R-studio — a check that asks an address the program does not bind fails the bed, not a machine** // (novox/hq ADR 0240 Phase D, done when). The hosted database suite's studio binds the address the runtime // puts in HOSTNAME, so it answered only on its network address while its image's own check asked localhost: // unhealthy for ever while working, until the module set HOSTNAME=0.0.0.0. Adopted by name without proof, it // would have put back a good build. // // The replay is that image in miniature: a web server that binds $HOSTNAME's address, and an image check that // asks localhost. Adopted as the module declared it before the fix, the bed fails it; with the fix, it proves // it. The image is built here and removed after, with everything the bed made. func TestBedFailsTheStudiosFalseUnhealthy(t *testing.T) { docker, ok := DockerFromEnv() if !ok { t.Skip("no container runtime: the studio is a container") } ctx, cancel := context.WithTimeout(t.Context(), 5*time.Minute) defer cancel() if err := docker.Pull(ctx, "busybox:1.36"); err != nil { t.Fatal(err) } tag := fmt.Sprintf("mesh-replay-studio:%d", time.Now().UnixNano()) if err := docker.Build(ctx, tag, StudioDockerfile); err != nil { t.Fatal(err) } defer docker.RemoveImage(context.Background(), tag) was := BedFloor BedFloor = 15 * time.Second defer func() { BedFloor = was }() studio := func(env map[string]any) BedResource { r := map[string]any{"id": "studio", "type": "container", "name": "supabase-studio", "image": tag, "health": map[string]any{"kind": "runtime", "grace": "10s"}} if env != nil { r["env"] = env } return BedResource{Module: "supabase", ID: "studio", Resource: r, Listens: map[string]int{}} } before := docker.Prove(ctx, studio(nil), nil) if !before.Failed || !strings.Contains(before.Said, "does not see it") { t.Fatalf("the studio's false unhealthy was not failed on the bed: %+v", before) } t.Logf("before the fix: %s", before.Said) after := docker.Prove(ctx, studio(map[string]any{"HOSTNAME": "0.0.0.0"}), nil) if !after.Proved { t.Fatalf("the studio with HOSTNAME=0.0.0.0 was not proved: %+v", after) } t.Logf("with the fix: %s", after.Said) } // StudioDockerfile is the studio in miniature: it serves on the address HOSTNAME names, and its own check // asks localhost, as the studio's image does. const StudioDockerfile = `FROM busybox:1.36 RUN mkdir -p /www && echo studio > /www/index.html HEALTHCHECK --interval=5s --timeout=2s --retries=2 CMD wget -q -O /dev/null http://localhost:3000/ || exit 1 CMD addr=$(grep -w "$HOSTNAME" /etc/hosts | head -n 1 | cut -f 1); exec httpd -f -p "${addr:-$HOSTNAME}:3000" -h /www `