Skip to content

Commit 9e342da

Browse files
authored
Fix cron jobs using dev env instead of test env in CI workflows (#1319)
The custom-base-port and db-migration-backwards-compatibility workflows were running cron jobs with `with-env:dev` instead of `with-env:test`, causing ClickHouse sync mismatches in verify-data-integrity. <!-- Make sure you've read the CONTRIBUTING.md guidelines: https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Streamlined CI test workflows to standardize background cron job startup for more consistent test runs. * **Tests** * Improved end-to-end test reliability by aligning background process behavior across suites. * **Bug Fixes** * Enhanced data verification reliability by ensuring external database sync before integrity checks and tightening comparison ordering for certain records, reducing false mismatch detections. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 0301961 commit 9e342da

4 files changed

Lines changed: 9 additions & 4 deletions

File tree

.github/workflows/db-migration-backwards-compatibility.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ jobs:
200200
uses: JarvusInnovations/background-action@v1.0.7
201201
if: ${{ hashFiles('apps/backend/scripts/run-cron-jobs.ts') != '' }}
202202
with:
203-
run: pnpm -C apps/backend run with-env:dev tsx scripts/run-cron-jobs.ts --log-order=stream &
203+
run: pnpm -C apps/backend run run-cron-jobs:test --log-order=stream &
204204
wait-on: |
205205
http://localhost:8102
206206
tail: true
@@ -394,7 +394,7 @@ jobs:
394394
uses: JarvusInnovations/background-action@v1.0.7
395395
if: ${{ hashFiles('apps/backend/scripts/run-cron-jobs.ts') != '' }}
396396
with:
397-
run: pnpm -C apps/backend run with-env:dev tsx scripts/run-cron-jobs.ts --log-order=stream &
397+
run: pnpm -C apps/backend run run-cron-jobs:test --log-order=stream &
398398
wait-on: |
399399
http://localhost:8102
400400
tail: true

.github/workflows/e2e-custom-base-port-api-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ jobs:
145145
- name: Start run-cron-jobs in background
146146
uses: JarvusInnovations/background-action@v1.0.7
147147
with:
148-
run: pnpm -C apps/backend run run-cron-jobs --log-order=stream &
148+
run: pnpm -C apps/backend run run-cron-jobs:test --log-order=stream &
149149
wait-on: |
150150
http://localhost:6702
151151
tail: true

apps/backend/scripts/verify-data-integrity/clickhouse-sync-verifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const SORT_KEYS = {
1818
team_invitations: ["id"],
1919
email_outboxes: ["id"],
2020
project_permissions: ["user_id", "permission_id"],
21-
notification_preferences: ["id"],
21+
notification_preferences: ["user_id", "notification_category_id"],
2222
refresh_tokens: ["id"],
2323
connected_accounts: ["user_id", "provider", "provider_account_id"],
2424
} satisfies Record<keyof typeof DEFAULT_DB_SYNC_MAPPINGS, string[]>;

apps/backend/scripts/verify-data-integrity/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { syncExternalDatabases } from "@/lib/external-db-sync";
12
import { DEFAULT_BRANCH_ID, getSoleTenancyFromProjectBranch } from "@/lib/tenancies";
23
import { getPrismaClientForTenancy, globalPrismaClient } from "@/prisma-client";
34
import type { OrganizationRenderedConfig } from "@stackframe/stack-shared/dist/config/schema";
@@ -228,6 +229,10 @@ async function main() {
228229

229230
if (!shouldSkipClickhouse && clickhouseAvailable && tenancy) {
230231
await recurse("[clickhouse sync]", async (recurse) => {
232+
// Flush any pending ClickHouse syncs by running a direct sync before verifying.
233+
// This avoids race conditions where QStash hasn't delivered all sync callbacks yet.
234+
await syncExternalDatabases(tenancy);
235+
231236
await verifyClickhouseSync({
232237
tenancy,
233238
projectId,

0 commit comments

Comments
 (0)