test: run infra and module tests against real postgres/redis#18
Draft
zaxovaiko wants to merge 2 commits into
Draft
test: run infra and module tests against real postgres/redis#18zaxovaiko wants to merge 2 commits into
zaxovaiko wants to merge 2 commits into
Conversation
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
Rewrites the infra-layer and module test suites to run against real Postgres and Redis instead of in-process fakes and vi-mocked Drizzle chains. Mock-choreography assertions (call counts on query builders) are replaced with outcome assertions on real rows, which lets the suite prove behaviors mocks structurally cannot: unique-index dedupe,
FOR UPDATElocking under concurrency, atomic conditional updates, and real read-through cache invalidation. Whole-suite cost: 528 -> 535 tests, ~7.7s -> ~9-11s.Changes
packages/core/src/testing/real-infra.ts(new, exported from@openora/core/testing):createTestDb(migrations)- ephemeral per-file database + per-module migrations, droppedWITH (FORCE);createTestRedis()- per-vitest-worker logical Redis DB (VITEST_POOL_ID % 16) so parallel workers never share keys. Fails fast with an actionable message when infra is down.server/kernel/__tests__- all Redis drivers (RedisCache,RedisRateLimiter,RedisStreamsBroker,BullMqJobQueue),EventBus, and thecached/assertRateLimitprod helpers now run on live Redis. New multi-instance broker test: two brokers with the same service name -> exactly one handles an event (competing consumers); different names -> both.iam.service.test.ts(41 -> 44): dropsvi.mock('drizzle-orm')entirely; real concurrency proofs forLastSuperAdminError(FOR UPDATE),acceptInvitationreplay-safety,assignRoleunique-index dedupe; grant-cache read-through +invalidateUser/invalidateRolepurge on live Redis.chat.service.test.ts- message persistence, display-name resolution, and per-viewer block filtering on real SQL; realtime-push seam keeps its designated test double.cms.reads.test.ts,lobby.cache.test.ts- true read-through cache tests (TTL asserted via PTTL, staleness-after-direct-DB-write actually observed).identity.rate-limit.test.ts,wallet.rate-limit.test.ts-RedisRateLimiteron live Redis; DB stays mocked (only limiter behavior is asserted).docker-compose.yml-redisservice ungated (starts by default)..github/workflows/ci.yml-verifyjob gets health-checked postgres + redis service containers.Checklist
pnpm verifyis green (typecheck + lint + boundaries + module-shape + tests)pnpm verify:driftis green (catalog / OpenAPI not stale) - test-only change, no contract/schema edits/schemasubpath (no direct module imports)tenantIdand are RLS-covered - n/a, no new tablesNotes
@openora/core/testingfakes relocation andRedisStreamsBroker; retarget todevafter refactor: distributed-only production - remove in-process seams from the prod path #15 merges.pnpm test:unitnow requiresdocker compose up -dlocally (postgres + redis). CI provides both as service containers.testing/fakesthemselves (used bybootTestApp), and pure-logic tests that never touch a backend.