Skip to content

feat(tests): add integration test suites for all DB repositories#549

Merged
zbigniewsobiecki merged 2 commits intodevfrom
feature/integration-test-suites-db-repositories
Feb 25, 2026
Merged

feat(tests): add integration test suites for all DB repositories#549
zbigniewsobiecki merged 2 commits intodevfrom
feature/integration-test-suites-db-repositories

Conversation

@aaight
Copy link
Copy Markdown
Collaborator

@aaight aaight commented Feb 25, 2026

Summary

  • Adds 7 new integration test suites for DB repositories that were previously only unit-tested with mocks: configRepository, runsRepository, settingsRepository, webhookLogsRepository, prWorkItemsRepository, partialsRepository, usersRepository
  • Adds 1 cross-cutting credential resolution test (credentialResolution.test.ts) that tests getAllProjectCredentials() end-to-end with real DB, integration credential overrides, and encryption round-trips
  • Extends the seed helper (tests/integration/helpers/seed.ts) with 7 new functions: seedDefaults, seedAgentConfig, seedRun, seedUser, seedWebhookLog, seedPromptPartial, seedPrWorkItem, seedSession, seedRunLogs
  • Adds 0000_base_schema.sql migration to enable running the full migration chain from a fresh database (required for runMigrations() in integration test setup)

Total: 155 integration tests (8 previously from credentialsRepository.test.ts, plus 147 new)

Key decisions

  • Used vi.stubEnv() for environment variable manipulation in tests (vitest's unstubEnvs: true cleans up automatically), avoiding the biome noDelete lint rule while ensuring proper cleanup
  • Added 0000_base_schema.sql as the initial schema since the existing migrations (starting at 0001) assume a pre-existing projects table from when the DB was originally created with drizzle-kit push
  • Added the base schema to the journal with timestamp 1735000000000 (before 0001's 1736000000000) so existing databases (which have already had migrations applied) won't re-run it

Test plan

  • All 155 integration tests pass
  • All 3198 unit tests pass
  • Lint passes (biome check, zero errors)
  • TypeScript typecheck passes (zero errors)
  • Integration tests run from a fresh database using runMigrations()

Card

https://trello.com/c/3KLGEu9q/118-add-key-missing-integration-test-suites-for-db-repositories

🤖 Generated with Claude Code

@nhopeatall
Copy link
Copy Markdown
Collaborator

nhopeatall commented Feb 25, 2026

✨ On it — checking the PR for feature/integration-test-suites-db-repositories


Progress: [███░░░░░░░] 34% (iteration 24/70)

🔍 Code Review Update (1 min)

I've completed a thorough review of the database migrations, confirming that the 0000_base_schema.sql migration correctly sets up the tables expected by 0001_three_tier_normalization.sql. I've also investigated the seeding functions, noting that seedPrWorkItem and seedRunLogs are defined but unused, and seedRun is an unused import in runsRepository.test.ts. I'm now ready to provide a comprehensive review of the changes.

Last updated: iteration 24 · review

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — Well-structured integration test suite that follows the established patterns from credentialsRepository.test.ts.

Notes

Migration approach is sound: The 0000_base_schema.sql correctly uses CREATE TABLE IF NOT EXISTS / CREATE ... INDEX IF NOT EXISTS, making it idempotent — safe both for fresh databases (integration tests) and existing databases where these tables already exist. The timestamp ordering (1735000000000 before 1736000000000) ensures the bootstrap-journal script skips it on already-migrated databases.

Test quality: Tests cover CRUD, edge cases (null/missing data, wrong project isolation), upsert semantics, pagination, and cross-cutting concerns like encryption round-trips and credential resolution priority. The beforeEach(truncateAll → seed) pattern matches the existing credentialsRepository.test.ts convention.

Minor observations (not blocking):

  • seedRun is imported but never used in runsRepository.test.ts (tests use createRun directly) — unused import
  • seedPrWorkItem and seedRunLogs are defined in seed.ts but not used by any test file yet — dead code for now, but reasonable to include as helpers for future tests

@zbigniewsobiecki
Copy link
Copy Markdown
Member

@aaight address code review concerns

@aaight
Copy link
Copy Markdown
Collaborator Author

aaight commented Feb 25, 2026

Request Addressed

What was asked

Address code review concerns raised by @nhopeatall.

Changes Made

  • Removed unused seedRun import from runsRepository.test.ts (tests use createRun directly)
  • Removed unused seedPrWorkItem and seedRunLogs helper functions from seed.ts
  • Cleaned up unused prWorkItems and agentRunLogs schema imports from seed.ts

Verification

  • All 3198 unit tests passing
  • Lint passes (biome check, zero errors)
  • TypeScript typecheck passes (zero errors)
  • Pre-commit and pre-push hooks all green

Remove unused `seedRun` import from runsRepository.test.ts, and remove
unused `seedPrWorkItem` and `seedRunLogs` helpers from seed.ts along
with their now-unnecessary schema imports.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aaight
Copy link
Copy Markdown
Collaborator Author

aaight commented Feb 25, 2026

Addressed the code review concerns from @nhopeatall:

  1. Removed unused seedRun import from runsRepository.test.ts — the tests use createRun directly from the repository, so the seed helper was never called.

  2. Removed unused seedPrWorkItem and seedRunLogs helpers from seed.ts — these were dead code with no consumers. Also cleaned up the now-unnecessary prWorkItems and agentRunLogs schema imports.

All checks pass (3198 unit tests, lint, typecheck).

@nhopeatall
Copy link
Copy Markdown
Collaborator

nhopeatall commented Feb 25, 2026

🤖 Just a sec, looking into PR #549 now


Progress: [████░░░░░░] 37% (iteration 26/70)

🔍 Code Review Update (1 min)

I've completed reviewing the migration files and confirmed that the 0001 migration correctly assumes the projects table exists, as it's created by the base schema. I've also clarified that the PR description's mention of seedPrWorkItem and seedRunLogs was an inaccuracy, as the tests directly use repository functions. I'm currently examining how Drizzle's migrate method uses created_at timestamps and hashes to determine which migrations to skip.

Last updated: iteration 26 · review

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

LGTM — Well-structured integration test suite that follows existing patterns precisely, with a sound approach to the base schema migration.

Migration Safety Verified

The 0000_base_schema.sql insertion into the journal is safe for existing databases. I traced through drizzle-orm's migrator (pg-core/dialect.cjs:64): it applies migrations by checking Number(lastDbMigration.created_at) < migration.folderMillis. For production databases with migrations up to 0015 (timestamp 1750000000000), the base schema's 1735000000000 is below the watermark and will be skipped. For fresh databases, CREATE TABLE IF NOT EXISTS provides additional idempotency. The re-indexing of idx values is cosmetic from drizzle's perspective — the migrator uses when/created_at for ordering, not idx.

Test Quality

  • Consistent structure: All 8 new test files follow the established pattern from credentialsRepository.test.ts (truncateAll + seedOrg/seedProject in beforeEach, section headers with =====, testing both happy paths and edge cases).
  • Good coverage of domain invariants: Tests verify cross-project isolation (prWorkItemsRepository), config inheritance hierarchy (configRepository), credential override precedence (credentialResolution), and session expiry behavior (usersRepository).
  • Seed helpers are well-factored: Each new seed function follows the overrides pattern established by the existing helpers, with sensible defaults.
  • vi.stubEnv usage is correct: Vitest's unstubEnvs: true handles cleanup, and the credential encryption round-trip tests properly validate the encrypt/decrypt path.

Minor note (not blocking)

The PR description lists seedPrWorkItem and seedRunLogs as new seed functions, but these don't exist in the code — the tests use the repository functions directly for those operations, which is fine.

@zbigniewsobiecki zbigniewsobiecki merged commit 3ea14a4 into dev Feb 25, 2026
6 checks passed
@zbigniewsobiecki zbigniewsobiecki mentioned this pull request Feb 25, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants