Repository navigation
ci: run the suite and an upgrade check against real Postgres - #464
Merged
Merged
Conversation
Adds a postgres workflow, run on PRs that touch migrations, models or the services that send their own SQL, nightly, and on dispatch. - suite: with TEST_DB=postgres the run migrates a real database and adds a postgres vitest project (tests/postgres) that exercises the audit hash chain triggers, retention and the raw SQL services without mocks. The old global setup synced no models and so tested nothing; it is removed. - upgrade: migrates to the newest v* tag not on HEAD, seeds users, credentials, sessions, chained auth events, system_config and the rest, runs the current migrations, then compares every seeded row and checks the chain verifies, the schema guard is satisfied and every model can read. Closes #436
5 of 35 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #436
Adds
.github/workflows/postgres.yml, which runs on pull requests touchingsrc/migrations,src/models, the database config, or the services and controllers that send their own SQL (plus its own files), nightly, and onworkflow_dispatch.Jobs
Suite on Postgres.
TEST_DB=postgres npm run test:runagainst apostgres:18-alpineservice. In that modevitest.config.tsadds apostgresproject next to the existingunitone. Its global setup drops and recreates thepublicschema (refusing any database whose name lackstest) and runs the real migration chain with sequelize-cli, then the specs undertests/postgres/run with none of the shared mocks:auditChain.spec.ts: concurrent inserts form one unbroken chain; UPDATE, DELETE and TRUNCATE are refused by the triggers; a tampered row is reported ashash_mismatchand verifies again once restored; retention archives a prefix and what remains still verifies from the archive's last hash.rawSqlServices.spec.ts: seeds users, a credential, an organization and auth events in an isolated time window and checks exact figures from sign-in metrics, funnel metrics, the coverage report, enrollment, review account usage, the audit export, the schema guard andgetDatabaseSize.The old
tests/setup/globalSetup.tsransequelize.sync({ force: true })before any model was registered, so withTEST_DB=postgresit connected and tested nothing. It is removed. The default mock run is unchanged (138 files, same coverage).Upgrade from the previous release. Resolves the newest
v*tag not on HEAD (or theprevious-refdispatch input), checks it out in a worktree, runs its migrations on an empty database, thenscripts/upgrade-check/seed.mjswrites realistic rows (users, credentials, TOTP, organizations and memberships, rotated and active sessions, a magic link, OAuth and external ids, an auth failure, admin-managedsystem_config, and twelve auth events chained by the previous release's trigger) and snapshots every table. After the current migrations,scripts/upgrade-check/verify.mjsfails on any seeded row, column or value that changed or disappeared, unless listed in itsEXPECTED_CHANGES, and also checks that the schema guard sees no pending migrations, the audit chain verifies with every seeded event,bootstrapSystemConfigplusgetSystemConfigsucceed, every model can read its table, and a new event extends the chain.No changeset: CI and test-only change.
Local verification
Against Postgres 18.6 in throwaway databases (all dropped afterwards):
npm run typecheck,npm run lint,npm run format:check: clean.npm run test:run: 138 files, 1879 passed, 1 todo.npm run coverage: 98.93 / 95.41 / 99.28 / 99.16, thresholds met.TEST_DB=postgres npm run test:run: 140 files, 1893 passed, 1 todo (the 14 new postgres specs pass; run twice).totp_credentials.issuerfailed withcredentials.counter ...: 7 became 0,sessions ...: row is gone,totp_credentials.issuer: column is goneandTotpCredential: column "issuer" does not exist.No test failed on real Postgres and no product bug was found; the only harness fix was the global setup above.