Repository navigation
test: integration tier against real Postgres + Redis (Testcontainers): infra + auth/payments/isolation suites (#135) - #165
Merged
Levi-Ojukwu merged 3 commits intoOct 17, 2026
Conversation
…Redis prefix) (OracleDesk#135) - ensureContainers(): TEST_DATABASE_URL/TEST_REDIS_URL or Testcontainers postgres:16-alpine + redis:7-alpine; skips cleanly without Docker - global setup migrates od_template once; each file clones it - truncateAll, typed factories, per-file Redis key prefix - test:integration / test:all scripts; setupTestEnv defaults REDIS_URL
|
@choniszn1 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Summary
Adds the integration test tier: real Postgres 16 and Redis 7, one migrated database per test file, and per-test truncation. It ports the auth and payments suites to it and adds an isolation check.
npm testis unchanged and still runs only the unit tier, with no Docker needed.What's included
Infrastructure (
tests/helpers/,tests/integration/)containers.ts›ensureContainers(): usesTEST_DATABASE_URL+TEST_REDIS_URLwhen set (CI). Otherwise it startspostgres:16-alpineandredis:7-alpinewith Testcontainers, reusing them only whenTESTCONTAINERS_REUSE_ENABLE=true. Without Docker and without theTEST_*URLs it returnsnull, and every integration test is skipped with one clear message instead of failing.integration/global-setup.ts: loaded with--test-global-setup(Node ≥ 22.10, matching.nvmrc). It runs once, migrates anod_templatedatabase, and passes URLs to test files through env vars. Teardown stops the containers.db.ts:createTestDatabase(label)clones the template (CREATE DATABASE … TEMPLATE od_template) with?connection_limit=5so parallel files don't exhaust Postgres connections.migrate(url)runsprisma migrate deploy.truncateAll(prisma)truncates everypublictable except_prisma_migrationswithRESTART IDENTITY CASCADE.integration/setup.ts›integrationEnv(label): setsDATABASE_URL/REDIS_URLbefore anysrcimport, from an asyncbefore()hook.configandprismaread env when first imported, and the compiled output is CommonJS, so there's no top-level await.redis.ts›withRedisPrefix(): a per-file key prefix, with a challenge store that issues the same realSET EX/GETDELcommands asredisChallengeStore.flushPrefix()deletes the file's keys withSCAN+UNLINK.factories.ts:makeUser,makeMarketwith counter-based values.env.ts:setupTestEnv()now defaultsREDIS_URLwith||, as it already did forDATABASE_URL.Suites (
tests/integration/*.int.test.ts)auth.int.test.tsusersrow via the real upsert) · replay →CHALLENGE_NOT_FOUND· 20 concurrentverifyChallengeof one signed challenge → exactly 1 success, 19CHALLENGE_NOT_FOUND(realGETDELatomicity)payments.int.test.tsPAYMENT_ALREADY_USEDfor another user · concurrent double claim → one subscription and one payment event, via the realpayment_events.txHashunique index. The loser's P2002 is marked// BUG:per the issue's non-goals · rollback on mid-transaction failure istest.todo, since it needs a fault-injection hookisolation.int.test.tsScripts, CI, docs
test:integration:node --test --test-concurrency=4 --test-global-setup=… dist-tests/tests/integration/*.int.test.js.test:allruns unit then integration.npm teststill only globsdist-tests/tests/*.test.js, which excludesintegration/.ci.yml: afternpm test, runsnpm run test:integrationwithTEST_DATABASE_URL=…/postgres(the admin DB, forCREATE DATABASE) andTEST_REDIS_URLagainst the existing service containers.CONTRIBUTING.mdgets a Tests section (two tiers, local Docker, how to write an integration test). TheREADME.mdscripts table is updated.New dev dependencies:
testcontainers,@testcontainers/postgresql,@testcontainers/redis,pg,@types/pg.indexer.int.test.ts:backfillEventsend to end, the atomicMarketResolvedtransaction, and trace linking by hash.generation-status.int.test.ts: the JSON-pathagentLoglookup.The payments rollback test (currently
test.todo).A
makeTrace/makePositionfactory, which the indexer suite will need.Verification, and what wasn't checked
npm run build:testreports no errors in any new file.ci.ymlstill parses as valid YAML.develop:npm run build:testreports 16 TypeScript errors in existing files (e.g.src/services/trace-audit.service.ts,tests/resilience.test.ts,tests/copy-trade-verify.test.ts).tsconfig.test.jsonsetsnoEmitOnError, so these blocknpm testand this new tier alike until fixed.Closes #132
Closes #133
Closes #134
Closes #135