From ec78a865bdc5e94ae7e77b162c7f32eb7a2b031e Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 07:41:03 +0000 Subject: [PATCH 1/3] test(stack): name the stalled phase in the Realtime catalog test The Realtime, pg-meta and Studio catalog test hit the 120s test timeout on Podman with only the generator frame to go on. It now runs under a 110s guard that fails with CatalogStallError naming the service and phase in progress, plus that service's launch output. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01MBEk1PCdaXDCUPR16M9Ria --- .../src/services/Realtime.integration.test.ts | 281 +++++++++++------- 1 file changed, 176 insertions(+), 105 deletions(-) diff --git a/packages/stack/src/services/Realtime.integration.test.ts b/packages/stack/src/services/Realtime.integration.test.ts index 03c0b72c80..6c07faf970 100644 --- a/packages/stack/src/services/Realtime.integration.test.ts +++ b/packages/stack/src/services/Realtime.integration.test.ts @@ -1,9 +1,10 @@ import { NodeHttpClient, NodeServices } from "@effect/platform-node"; import { describe, expect, it } from "@effect/vitest"; -import { Effect, Layer, Redacted } from "effect"; +import { Data, Effect, Layer, Redacted, Ref, Stream } from "effect"; import { HttpClient, HttpClientRequest } from "effect/http"; import { makeStandaloneService } from "../../tests/standalone-service.ts"; import { makeServiceRecipe } from "./Catalog.ts"; +import type { CatalogLogs } from "./Recipe.ts"; import { makeDockerHttpRelay, makeDockerTcpRelay } from "../../tests/docker-relay.ts"; import { makeDockerDatabaseRoot } from "../../tests/docker-fixture.ts"; import { engineTarget, testEngine } from "../../tests/engine-target.ts"; @@ -25,120 +26,190 @@ const dockerOptions = (root: string) => ({ engineTarget, }); +class CatalogStallError extends Data.TaggedError("CatalogStallError")<{ + readonly message: string; +}> {} + +/** Tracks the current launch phase and each service's output so a stall names both. */ +const makeLaunchTrace = Effect.gen(function* () { + const phase = yield* Ref.make({ service: "database", step: "recipe" }); + const outputs = yield* Ref.make>(new Map()); + const capture = Effect.fnUntraced(function* (service: string, logs: CatalogLogs) { + yield* Stream.fromSubscription(yield* logs).pipe( + Stream.runForEach(({ bytes }) => + Ref.update(outputs, (current) => + new Map(current).set( + service, + ((current.get(service) ?? "") + new TextDecoder().decode(bytes)).slice(-4_000), + ), + ), + ), + Effect.forkScoped({ startImmediately: true }), + ); + }); + const enter = (service: string, step: string) => Ref.set(phase, { service, step }); + const guard = + (duration: `${number} seconds`) => + (effect: Effect.Effect) => + effect.pipe( + Effect.timeoutOrElse({ + duration, + orElse: () => + Effect.all([Ref.get(phase), Ref.get(outputs)]).pipe( + Effect.flatMap(([{ service, step }, output]) => + Effect.fail( + new CatalogStallError({ + message: `${service} ${step} did not finish within ${duration}; ${service} output:\n${output.get(service) || "(none)"}`, + }), + ), + ), + ), + }), + ); + return { capture, enter, guard }; +}); + describe("service catalog", () => { it.live( "serves Realtime, pg-meta, and Studio against the owned database", () => - Effect.scoped( - Effect.gen(function* () { - const client = yield* HttpClient.HttpClient; - const root = yield* makeDockerDatabaseRoot("catalog-optional-api-"); - const secret = "catalog-optional-api-secret-with-at-least-32-chars"; - const databaseRecipe = yield* makeServiceRecipe( - { - service: "database", - pin: selection.database, - config: { - databasePassword: Redacted.make("postgres"), - jwtSecret: Redacted.make(secret), - jwtExpiry: 3600, + Effect.gen(function* () { + const trace = yield* makeLaunchTrace; + yield* Effect.scoped( + Effect.gen(function* () { + const client = yield* HttpClient.HttpClient; + const root = yield* makeDockerDatabaseRoot("catalog-optional-api-"); + const secret = "catalog-optional-api-secret-with-at-least-32-chars"; + const databaseRecipe = yield* makeServiceRecipe( + { + service: "database", + pin: selection.database, + config: { + databasePassword: Redacted.make("postgres"), + jwtSecret: Redacted.make(secret), + jwtExpiry: 3600, + }, }, - }, - dockerOptions(root), - ); - const database = yield* makeStandaloneService(databaseRecipe.definition, { - id: "database", - config: databaseRecipe.creation, - }); - yield* database.start; - yield* database.ready; - const databaseRelay = yield* makeDockerTcpRelay(databaseRecipe.endpoint("sql")); - const databaseUrl = `postgresql://supabase_admin:postgres@${databaseRelay.host}:${databaseRelay.port}/postgres`; + dockerOptions(root), + ); + yield* trace.capture("database", databaseRecipe.logs); + const database = yield* makeStandaloneService(databaseRecipe.definition, { + id: "database", + config: databaseRecipe.creation, + }); + yield* trace.enter("database", "start"); + yield* database.start; + yield* trace.enter("database", "readiness"); + yield* database.ready; + yield* trace.enter("database", "relay"); + const databaseRelay = yield* makeDockerTcpRelay(databaseRecipe.endpoint("sql")); + const databaseUrl = `postgresql://supabase_admin:postgres@${databaseRelay.host}:${databaseRelay.port}/postgres`; - const realtimeRecipe = yield* makeServiceRecipe( - { - service: "realtime", - pin: selection.realtime, - config: { databaseUrl, jwtSecret: secret }, - }, - dockerOptions(root), - ); - const realtime = yield* makeStandaloneService(realtimeRecipe.definition, { - id: "realtime", - config: realtimeRecipe.creation, - }); - yield* realtime.start; - yield* realtime.ready; - const realtimeEndpoint = yield* realtimeRecipe.endpoint("http"); - const realtimeResponse = yield* client.execute( - HttpClientRequest.get( - `http://${httpHost(realtimeEndpoint)}:${realtimeEndpoint.port}/healthcheck`, - ), - ); - expect(realtimeResponse.status).toBe(200); + yield* trace.enter("realtime", "recipe"); + const realtimeRecipe = yield* makeServiceRecipe( + { + service: "realtime", + pin: selection.realtime, + config: { databaseUrl, jwtSecret: secret }, + }, + dockerOptions(root), + ); + yield* trace.capture("realtime", realtimeRecipe.logs); + const realtime = yield* makeStandaloneService(realtimeRecipe.definition, { + id: "realtime", + config: realtimeRecipe.creation, + }); + yield* trace.enter("realtime", "start"); + yield* realtime.start; + yield* trace.enter("realtime", "readiness"); + yield* realtime.ready; + yield* trace.enter("realtime", "/healthcheck request"); + const realtimeEndpoint = yield* realtimeRecipe.endpoint("http"); + const realtimeResponse = yield* client.execute( + HttpClientRequest.get( + `http://${httpHost(realtimeEndpoint)}:${realtimeEndpoint.port}/healthcheck`, + ), + ); + expect(realtimeResponse.status).toBe(200); + yield* trace.enter("pgmeta", "recipe"); - const pgmetaRecipe = yield* makeServiceRecipe( - { service: "pgmeta", pin: selection.pgmeta, config: { databaseUrl } }, - dockerOptions(root), - ); - const pgmeta = yield* makeStandaloneService(pgmetaRecipe.definition, { - id: "pgmeta", - config: pgmetaRecipe.creation, - }); - yield* pgmeta.start; - yield* pgmeta.ready; - const pgmetaEndpoint = yield* pgmetaRecipe.endpoint("http"); - const pgmetaRelay = yield* makeDockerHttpRelay(pgmetaRecipe.endpoint("http")); - const schemasResponse = yield* client.execute( - HttpClientRequest.get( - `http://${httpHost(pgmetaEndpoint)}:${pgmetaEndpoint.port}/schemas`, - ), - ); - expect(schemasResponse.status).toBe(200); - expect(yield* schemasResponse.text).toContain("public"); + const pgmetaRecipe = yield* makeServiceRecipe( + { service: "pgmeta", pin: selection.pgmeta, config: { databaseUrl } }, + dockerOptions(root), + ); + yield* trace.capture("pgmeta", pgmetaRecipe.logs); + const pgmeta = yield* makeStandaloneService(pgmetaRecipe.definition, { + id: "pgmeta", + config: pgmetaRecipe.creation, + }); + yield* trace.enter("pgmeta", "start"); + yield* pgmeta.start; + yield* trace.enter("pgmeta", "readiness"); + yield* pgmeta.ready; + yield* trace.enter("pgmeta", "/schemas request"); + const pgmetaEndpoint = yield* pgmetaRecipe.endpoint("http"); + const pgmetaRelay = yield* makeDockerHttpRelay(pgmetaRecipe.endpoint("http")); + const schemasResponse = yield* client.execute( + HttpClientRequest.get( + `http://${httpHost(pgmetaEndpoint)}:${pgmetaEndpoint.port}/schemas`, + ), + ); + expect(schemasResponse.status).toBe(200); + expect(yield* schemasResponse.text).toContain("public"); + yield* trace.enter("studio", "recipe"); - const studioRecipe = yield* makeServiceRecipe( - { - service: "studio", - pin: selection.studio, - config: { - databaseUrl, - pgmetaUrl: `http://${pgmetaRelay.host}:${pgmetaRelay.port}`, - analyticsApiKey: "catalog-analytics-key", - apiUrl: "http://localhost:8000", - publicApiUrl: "http://localhost:8000", - jwtSecret: secret, + const studioRecipe = yield* makeServiceRecipe( + { + service: "studio", + pin: selection.studio, + config: { + databaseUrl, + pgmetaUrl: `http://${pgmetaRelay.host}:${pgmetaRelay.port}`, + analyticsApiKey: "catalog-analytics-key", + apiUrl: "http://localhost:8000", + publicApiUrl: "http://localhost:8000", + jwtSecret: secret, + }, }, - }, - dockerOptions(root), - ); - const studio = yield* makeStandaloneService(studioRecipe.definition, { - id: "studio", - config: studioRecipe.creation, - }); - yield* studio.start; - yield* studio.ready; - const studioEndpoint = yield* studioRecipe.endpoint("http"); - const profileResponse = yield* client.execute( - HttpClientRequest.get( - `http://${httpHost(studioEndpoint)}:${studioEndpoint.port}/api/platform/profile`, - ), - ); - expect(profileResponse.status).toBe(200); - const queryResponse = yield* client.execute( - HttpClientRequest.post( - `http://${httpHost(studioEndpoint)}:${studioEndpoint.port}/api/platform/pg-meta/default/query`, - ).pipe(HttpClientRequest.bodyJsonUnsafe({ query: "select current_user" })), - ); - expect(queryResponse.status).toBe(200); - expect(yield* queryResponse.text).toContain('"current_user":"postgres"'); + dockerOptions(root), + ); + yield* trace.capture("studio", studioRecipe.logs); + const studio = yield* makeStandaloneService(studioRecipe.definition, { + id: "studio", + config: studioRecipe.creation, + }); + yield* trace.enter("studio", "start"); + yield* studio.start; + yield* trace.enter("studio", "readiness"); + yield* studio.ready; + yield* trace.enter("studio", "API requests"); + const studioEndpoint = yield* studioRecipe.endpoint("http"); + const profileResponse = yield* client.execute( + HttpClientRequest.get( + `http://${httpHost(studioEndpoint)}:${studioEndpoint.port}/api/platform/profile`, + ), + ); + expect(profileResponse.status).toBe(200); + const queryResponse = yield* client.execute( + HttpClientRequest.post( + `http://${httpHost(studioEndpoint)}:${studioEndpoint.port}/api/platform/pg-meta/default/query`, + ).pipe(HttpClientRequest.bodyJsonUnsafe({ query: "select current_user" })), + ); + expect(queryResponse.status).toBe(200); + expect(yield* queryResponse.text).toContain('"current_user":"postgres"'); - yield* studio.stop; - yield* pgmeta.stop; - yield* realtime.stop; - yield* database.stop; - }), - ).pipe(Effect.provide(Layer.merge(NodeServices.layer, NodeHttpClient.layerNodeHttp))), + yield* trace.enter("studio", "stop"); + yield* studio.stop; + yield* trace.enter("pgmeta", "stop"); + yield* pgmeta.stop; + yield* trace.enter("realtime", "stop"); + yield* realtime.stop; + yield* trace.enter("database", "stop"); + yield* database.stop; + yield* trace.enter("database", "root cleanup"); + }), + ).pipe(trace.guard("110 seconds")); + }).pipe(Effect.provide(Layer.merge(NodeServices.layer, NodeHttpClient.layerNodeHttp))), { timeout: 120_000 }, ); }); From 8a1f2e41895ff78097dbfa2cae971d4d19fb86d6 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 07:46:52 +0000 Subject: [PATCH 2/3] test(stack): report a Realtime catalog stall without waiting on teardown The guard now joins a detached body under its deadline, so a teardown that hangs during interruption cannot delay the stall report. Phase labels cover root setup, the pg-meta relay and scope teardown, and launch output is decoded as a stream per channel. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01MBEk1PCdaXDCUPR16M9Ria --- .../src/services/Realtime.integration.test.ts | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/packages/stack/src/services/Realtime.integration.test.ts b/packages/stack/src/services/Realtime.integration.test.ts index 6c07faf970..550f17efb1 100644 --- a/packages/stack/src/services/Realtime.integration.test.ts +++ b/packages/stack/src/services/Realtime.integration.test.ts @@ -1,6 +1,6 @@ import { NodeHttpClient, NodeServices } from "@effect/platform-node"; import { describe, expect, it } from "@effect/vitest"; -import { Data, Effect, Layer, Redacted, Ref, Stream } from "effect"; +import { Data, Effect, Fiber, Layer, Redacted, Ref, Stream } from "effect"; import { HttpClient, HttpClientRequest } from "effect/http"; import { makeStandaloneService } from "../../tests/standalone-service.ts"; import { makeServiceRecipe } from "./Catalog.ts"; @@ -32,15 +32,18 @@ class CatalogStallError extends Data.TaggedError("CatalogStallError")<{ /** Tracks the current launch phase and each service's output so a stall names both. */ const makeLaunchTrace = Effect.gen(function* () { - const phase = yield* Ref.make({ service: "database", step: "recipe" }); + const phase = yield* Ref.make({ service: "database", step: "setup" }); const outputs = yield* Ref.make>(new Map()); const capture = Effect.fnUntraced(function* (service: string, logs: CatalogLogs) { + const decoders = { stdout: new TextDecoder(), stderr: new TextDecoder() }; yield* Stream.fromSubscription(yield* logs).pipe( - Stream.runForEach(({ bytes }) => + Stream.runForEach(({ stream, bytes }) => Ref.update(outputs, (current) => new Map(current).set( service, - ((current.get(service) ?? "") + new TextDecoder().decode(bytes)).slice(-4_000), + ((current.get(service) ?? "") + decoders[stream].decode(bytes, { stream: true })).slice( + -4_000, + ), ), ), ), @@ -48,23 +51,27 @@ const makeLaunchTrace = Effect.gen(function* () { ); }); const enter = (service: string, step: string) => Ref.set(phase, { service, step }); + /** Reports a stall without waiting for the stalled scope's finalizers, which may hang too. */ const guard = (duration: `${number} seconds`) => (effect: Effect.Effect) => - effect.pipe( - Effect.timeoutOrElse({ - duration, - orElse: () => - Effect.all([Ref.get(phase), Ref.get(outputs)]).pipe( - Effect.flatMap(([{ service, step }, output]) => - Effect.fail( - new CatalogStallError({ - message: `${service} ${step} did not finish within ${duration}; ${service} output:\n${output.get(service) || "(none)"}`, - }), + Effect.flatMap(Effect.forkDetach(effect), (fiber) => + Fiber.join(fiber).pipe( + Effect.onInterrupt(() => Effect.forkDetach(Fiber.interrupt(fiber))), + Effect.timeoutOrElse({ + duration, + orElse: () => + Effect.all([Ref.get(phase), Ref.get(outputs)]).pipe( + Effect.flatMap(([{ service, step }, output]) => + Effect.fail( + new CatalogStallError({ + message: `${service} ${step} did not finish within ${duration}; ${service} output:\n${output.get(service) || "(none)"}`, + }), + ), ), ), - ), - }), + }), + ), ); return { capture, enter, guard }; }); @@ -146,9 +153,10 @@ describe("service catalog", () => { yield* pgmeta.start; yield* trace.enter("pgmeta", "readiness"); yield* pgmeta.ready; - yield* trace.enter("pgmeta", "/schemas request"); + yield* trace.enter("pgmeta", "relay"); const pgmetaEndpoint = yield* pgmetaRecipe.endpoint("http"); const pgmetaRelay = yield* makeDockerHttpRelay(pgmetaRecipe.endpoint("http")); + yield* trace.enter("pgmeta", "/schemas request"); const schemasResponse = yield* client.execute( HttpClientRequest.get( `http://${httpHost(pgmetaEndpoint)}:${pgmetaEndpoint.port}/schemas`, @@ -206,7 +214,7 @@ describe("service catalog", () => { yield* realtime.stop; yield* trace.enter("database", "stop"); yield* database.stop; - yield* trace.enter("database", "root cleanup"); + yield* trace.enter("database", "scope teardown"); }), ).pipe(trace.guard("110 seconds")); }).pipe(Effect.provide(Layer.merge(NodeServices.layer, NodeHttpClient.layerNodeHttp))), From c15f5ba6a00e8dc236270a17efc57986bb7e45e3 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 16:06:52 +0000 Subject: [PATCH 3/3] test(stack): include database output in a Realtime catalog stall Realtime, pg-meta and Studio all depend on the owned database, so a stall in one of them now also reports the database's launch output. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01MBEk1PCdaXDCUPR16M9Ria --- packages/stack/src/services/Realtime.integration.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/stack/src/services/Realtime.integration.test.ts b/packages/stack/src/services/Realtime.integration.test.ts index 550f17efb1..b23901c30b 100644 --- a/packages/stack/src/services/Realtime.integration.test.ts +++ b/packages/stack/src/services/Realtime.integration.test.ts @@ -65,7 +65,12 @@ const makeLaunchTrace = Effect.gen(function* () { Effect.flatMap(([{ service, step }, output]) => Effect.fail( new CatalogStallError({ - message: `${service} ${step} did not finish within ${duration}; ${service} output:\n${output.get(service) || "(none)"}`, + message: [ + `${service} ${step} did not finish within ${duration}`, + ...(service === "database" ? [service] : [service, "database"]).map( + (name) => `${name} output:\n${output.get(name) || "(none)"}`, + ), + ].join("\n"), }), ), ),