From ce5a1bbcbdbc94c0adbf94281eae457505c37ab5 Mon Sep 17 00:00:00 2001 From: Bilal Godil Date: Fri, 30 Jan 2026 15:44:29 -0800 Subject: [PATCH] fix tests --- .github/workflows/e2e-api-tests.yaml | 7 +++- .../e2e-custom-base-port-api-tests.yaml | 7 +++- .../e2e-source-of-truth-api-tests.yaml | 7 +++- ...rt-dev-and-test-with-custom-base-port.yaml | 7 +++- .github/workflows/restart-dev-and-test.yaml | 7 +++- .../setup-tests-with-custom-base-port.yaml | 5 ++- .github/workflows/setup-tests.yaml | 5 ++- .../internal/external-db-sync/poller/route.ts | 34 ++++++++++++++++--- 8 files changed, 67 insertions(+), 12 deletions(-) diff --git a/.github/workflows/e2e-api-tests.yaml b/.github/workflows/e2e-api-tests.yaml index e819fe89e..aeb35c80c 100644 --- a/.github/workflows/e2e-api-tests.yaml +++ b/.github/workflows/e2e-api-tests.yaml @@ -20,7 +20,9 @@ jobs: STACK_ENABLE_HARDCODED_PASSKEY_CHALLENGE_FOR_TESTING: yes STACK_DATABASE_CONNECTION_STRING: "postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@localhost:8128/stackframe" STACK_FORCE_EXTERNAL_DB_SYNC: "true" - STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000" + STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "20000" + STACK_EXTERNAL_DB_SYNC_DIRECT: "true" + NEXT_PUBLIC_STACK_API_URL: "http://host.docker.internal:8102" strategy: matrix: @@ -50,6 +52,9 @@ jobs: wait-for: 3s log-output-if: true + - name: Wait for QStash + run: pnpx wait-on tcp:localhost:8125 -t 60000 + - name: Install dependencies run: pnpm install --frozen-lockfile diff --git a/.github/workflows/e2e-custom-base-port-api-tests.yaml b/.github/workflows/e2e-custom-base-port-api-tests.yaml index dc12883f2..c2438f976 100644 --- a/.github/workflows/e2e-custom-base-port-api-tests.yaml +++ b/.github/workflows/e2e-custom-base-port-api-tests.yaml @@ -20,7 +20,9 @@ jobs: STACK_DATABASE_CONNECTION_STRING: "postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@localhost:6728/stackframe" NEXT_PUBLIC_STACK_PORT_PREFIX: "67" STACK_FORCE_EXTERNAL_DB_SYNC: "true" - STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000" + STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "20000" + STACK_EXTERNAL_DB_SYNC_DIRECT: "true" + NEXT_PUBLIC_STACK_API_URL: "http://host.docker.internal:6702" strategy: matrix: @@ -49,6 +51,9 @@ jobs: wait-for: 3s log-output-if: true + - name: Wait for QStash + run: pnpx wait-on tcp:localhost:6725 -t 60000 + - name: Install dependencies run: pnpm install --frozen-lockfile diff --git a/.github/workflows/e2e-source-of-truth-api-tests.yaml b/.github/workflows/e2e-source-of-truth-api-tests.yaml index aa3463192..af309516d 100644 --- a/.github/workflows/e2e-source-of-truth-api-tests.yaml +++ b/.github/workflows/e2e-source-of-truth-api-tests.yaml @@ -22,7 +22,9 @@ jobs: STACK_TEST_SOURCE_OF_TRUTH: true STACK_DATABASE_CONNECTION_STRING: "postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@localhost:8128/stackframe" STACK_FORCE_EXTERNAL_DB_SYNC: "true" - STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000" + STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "20000" + STACK_EXTERNAL_DB_SYNC_DIRECT: "true" + NEXT_PUBLIC_STACK_API_URL: "http://host.docker.internal:8102" strategy: matrix: @@ -51,6 +53,9 @@ jobs: wait-for: 3s log-output-if: true + - name: Wait for QStash + run: pnpx wait-on tcp:localhost:8125 -t 60000 + - name: Install dependencies run: pnpm install --frozen-lockfile diff --git a/.github/workflows/restart-dev-and-test-with-custom-base-port.yaml b/.github/workflows/restart-dev-and-test-with-custom-base-port.yaml index 4a1436db6..43390c185 100644 --- a/.github/workflows/restart-dev-and-test-with-custom-base-port.yaml +++ b/.github/workflows/restart-dev-and-test-with-custom-base-port.yaml @@ -20,7 +20,9 @@ jobs: env: NEXT_PUBLIC_STACK_PORT_PREFIX: "69" STACK_FORCE_EXTERNAL_DB_SYNC: "true" - STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000" + STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "20000" + STACK_EXTERNAL_DB_SYNC_DIRECT: "true" + NEXT_PUBLIC_STACK_API_URL: "http://host.docker.internal:6902" steps: - uses: actions/checkout@v6 @@ -39,6 +41,9 @@ jobs: - name: Start dev environment run: pnpm run restart-dev-environment + - name: Wait for QStash + run: pnpx wait-on tcp:localhost:6925 -t 60000 + - name: Run tests run: pnpm run test run --reporter=verbose diff --git a/.github/workflows/restart-dev-and-test.yaml b/.github/workflows/restart-dev-and-test.yaml index d2769dde9..c76a2f2ae 100644 --- a/.github/workflows/restart-dev-and-test.yaml +++ b/.github/workflows/restart-dev-and-test.yaml @@ -19,7 +19,9 @@ jobs: runs-on: ubicloud-standard-16 env: STACK_FORCE_EXTERNAL_DB_SYNC: "true" - STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000" + STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "20000" + STACK_EXTERNAL_DB_SYNC_DIRECT: "true" + NEXT_PUBLIC_STACK_API_URL: "http://host.docker.internal:8102" steps: - uses: actions/checkout@v6 @@ -38,6 +40,9 @@ jobs: - name: Start dev environment run: pnpm run restart-dev-environment + - name: Wait for QStash + run: pnpx wait-on tcp:localhost:8125 -t 60000 + - name: Run tests run: pnpm run test run --reporter=verbose diff --git a/.github/workflows/setup-tests-with-custom-base-port.yaml b/.github/workflows/setup-tests-with-custom-base-port.yaml index aef1097bc..90ec63515 100644 --- a/.github/workflows/setup-tests-with-custom-base-port.yaml +++ b/.github/workflows/setup-tests-with-custom-base-port.yaml @@ -20,7 +20,9 @@ jobs: env: NEXT_PUBLIC_STACK_PORT_PREFIX: "69" STACK_FORCE_EXTERNAL_DB_SYNC: "true" - STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000" + STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "20000" + STACK_EXTERNAL_DB_SYNC_DIRECT: "true" + NEXT_PUBLIC_STACK_API_URL: "http://host.docker.internal:6902" steps: - uses: actions/checkout@v6 @@ -48,4 +50,5 @@ jobs: tail: true wait-for: 120s log-output-if: true + - run: pnpx wait-on tcp:localhost:6925 -t 60000 - run: pnpm run test run --reporter=verbose diff --git a/.github/workflows/setup-tests.yaml b/.github/workflows/setup-tests.yaml index bfce50fd8..d2e9011e9 100644 --- a/.github/workflows/setup-tests.yaml +++ b/.github/workflows/setup-tests.yaml @@ -19,7 +19,9 @@ jobs: runs-on: ubicloud-standard-16 env: STACK_FORCE_EXTERNAL_DB_SYNC: "true" - STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000" + STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "20000" + STACK_EXTERNAL_DB_SYNC_DIRECT: "true" + NEXT_PUBLIC_STACK_API_URL: "http://host.docker.internal:8102" steps: - uses: actions/checkout@v6 @@ -46,4 +48,5 @@ jobs: tail: true wait-for: 120s log-output-if: true + - run: pnpx wait-on tcp:localhost:8125 -t 60000 - run: pnpm run test run --reporter=verbose diff --git a/apps/backend/src/app/api/latest/internal/external-db-sync/poller/route.ts b/apps/backend/src/app/api/latest/internal/external-db-sync/poller/route.ts index 8e559536d..00515654e 100644 --- a/apps/backend/src/app/api/latest/internal/external-db-sync/poller/route.ts +++ b/apps/backend/src/app/api/latest/internal/external-db-sync/poller/route.ts @@ -14,6 +14,7 @@ import { captureError, StatusError } from "@stackframe/stack-shared/dist/utils/e import { wait } from "@stackframe/stack-shared/dist/utils/promises"; const DEFAULT_MAX_DURATION_MS = 3 * 60 * 1000; +const DIRECT_SYNC_ENV = "STACK_EXTERNAL_DB_SYNC_DIRECT"; function parseMaxDurationMs(value: string | undefined): number { if (!value) return DEFAULT_MAX_DURATION_MS; @@ -24,6 +25,15 @@ function parseMaxDurationMs(value: string | undefined): number { return parsed; } +function directSyncEnabled(): boolean { + return getEnvVariable(DIRECT_SYNC_ENV, "") === "true"; +} + +function getLocalApiBaseUrl(): string { + const prefix = getEnvVariable("NEXT_PUBLIC_STACK_PORT_PREFIX", "81"); + return `http://localhost:${prefix}02`; +} + export const GET = createSmartRouteHandler({ metadata: { summary: "Poll outgoing requests and push to QStash", @@ -113,11 +123,25 @@ export const GET = createSmartRouteHandler({ } } - - await upstash.publishJSON({ - url: fullUrl, - body: options.body, - }); + if (directSyncEnabled()) { + const directUrl = new URL(options.url, getLocalApiBaseUrl()).toString(); + const res = await fetch(directUrl, { + method: "POST", + headers: { + "content-type": "application/json", + "upstash-signature": "test-bypass", + }, + body: JSON.stringify(options.body), + }); + if (!res.ok) { + throw new StatusError(res.status, `Direct sync failed: ${res.status} ${res.statusText}`); + } + } else { + await upstash.publishJSON({ + url: fullUrl, + body: options.body, + }); + } await deleteOutgoingRequest(request.id); }),