Skip to content

refactor(tests): add integration test infrastructure and review fixes#548

Merged
zbigniewsobiecki merged 2 commits intodevfrom
test-infra-review-fixes
Feb 25, 2026
Merged

refactor(tests): add integration test infrastructure and review fixes#548
zbigniewsobiecki merged 2 commits intodevfrom
test-infra-review-fixes

Conversation

@zbigniewsobiecki
Copy link
Copy Markdown
Member

Summary

  • Integration test infrastructure: Vitest workspace with separate unit/integration projects, docker-compose.test.yml for isolated Postgres, shared helpers (factories, mock DB, mock personas), and a full credential repository integration test suite including encryption round-trip coverage
  • Unit test cleanup: Remove redundant mock boilerplate (vi.mock, beforeEach resets) across 100+ test files by centralizing into workspace setup files and shared helpers (~800 lines removed)
  • Review fixes: OS-aware psql in ensure-services.sh (macOS compat), explicit DATABASE_URL in setup.sh migrations, build step in CI integration job, container_name in docker-compose, documentation comments in test setup files
  • Lint fix: Extract buildProgressMonitorConfig() from executeWithBackend() to resolve pre-existing cognitive complexity warning (21 → under 15)

Changes

New files

File Purpose
vitest.workspace.ts Workspace config separating unit and integration test projects
docker-compose.test.yml Ephemeral Postgres 16 container for integration tests (port 5433, tmpfs)
tests/integration/setup.ts Integration test global setup (migrations, DB lifecycle)
tests/integration/helpers/db.ts DB helpers (runMigrations, truncateAll, closeTestDb)
tests/integration/helpers/seed.ts Seed factories for org, project, credential, integration
tests/integration/db/credentialsRepository.test.ts Full CRUD + resolution + encryption integration tests
tests/helpers/factories.ts Shared mock factories for unit tests
tests/helpers/mockDb.ts Centralized DB mock setup
tests/helpers/mockPersonas.ts Centralized personas mock setup

Modified files

Area Files Change
.cascade/ ensure-services.sh, setup.sh, env OS-aware psql, explicit migration URLs, TEST_DATABASE_URL
.github/workflows/ci.yml CI config Integration test job + build step
src/backends/adapter.ts Backend adapter Extract progress monitor config to reduce complexity
vitest.config.ts Test config Add unstubEnvs, adjust for workspace
package.json Scripts Add test:integration script
tests/unit/** 100+ test files Remove redundant mock boilerplate
web/src/components/projects/pm-wizard.tsx PM wizard Remove unused imports

Test plan

  • npm test — 187 test files, 3198 tests pass
  • npm run typecheck — clean
  • npm run lint — clean (pre-existing warning resolved)
  • CI: lint-and-test job passes
  • CI: integration-tests job passes (requires Postgres service container)
  • CI: docker-build-check passes

🤖 Generated with Claude Code

Introduce vitest workspace with separate unit/integration projects,
shared test helpers (factories, mock DB, mock personas), and a full
integration test suite for credentialsRepository including encryption
round-trip coverage.

Review fixes:
- OS-aware psql in ensure-services.sh for macOS compatibility
- Explicit DATABASE_URL in setup.sh migrations (removes env race)
- Build step added to CI integration-tests job
- container_name in docker-compose.test.yml for easier debugging
- Extract buildProgressMonitorConfig() to fix cognitive complexity lint

Unit test cleanup: remove redundant mock boilerplate across 100+ test
files by leveraging vitest workspace setup files and shared helpers.

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

nhopeatall commented Feb 25, 2026

🤖 Looking into the integration test infrastructure now


Progress: [████░░░░░░] 39% (iteration 27/70)

🔍 Code Review Update (1 min)

I've been reviewing the provided PR, focusing on understanding the changes and ensuring best practices. I've confirmed that pm-wizard.tsx was mentioned in the PR description but not actually changed, and I've verified that the trigger tests are correctly utilizing helper factories. I've also confirmed that vi.stubEnv is being handled correctly in the integration tests due to unstubEnvs: true in the Vitest config, and that the DATABASE_URL is properly handled for lazy-initialized DB clients.

Last updated: iteration 27 · 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 addition of integration test infrastructure with clean test boilerplate reduction. The changes are consistent and correct.

What's good

The clearMocks: true and unstubEnvs: true in vitest.config.ts make the removal of ~100 vi.clearAllMocks() / vi.unstubAllEnvs() calls safe — Vitest handles this automatically in beforeEach/afterEach. The configCache import change in tests/setup.ts avoids a real module-loading side-effect (pulling in DB client during unit tests). The integration test infrastructure (workspace separation, Docker Compose, seed helpers, truncation strategy) follows solid patterns.

Minor observations (non-blocking)

  1. PR description lists pm-wizard.tsx as modified (removing unused imports) but it's not in the diff. No code issue — just a stale description entry.

  2. Integration tests only run on push (if: github.event_name == 'push'). This is a reasonable choice to avoid service containers on every PR, but means this PR's integration tests won't be validated until merge to dev. Worth noting for the merge checklist.

  3. buildProgressMonitorConfig extraction (adapter.ts) — clean refactoring to reduce cognitive complexity. The function signature and spread behavior are preserved exactly.

No blocking issues, no security concerns, no correctness bugs found.

@zbigniewsobiecki
Copy link
Copy Markdown
Member Author

@aaight make the integration tests run on PRs

@aaight
Copy link
Copy Markdown
Collaborator

aaight commented Feb 25, 2026

Request Addressed

What was asked

Make the integration tests run on PRs.

Changes Made

  • Removed if: github.event_name == 'push' from the integration-tests job in .github/workflows/ci.yml
  • The job now runs on both push (to main/dev) and pull_request events

Verification

  • All 3198 unit tests passing
  • TypeScript typecheck clean
  • Lint clean

Remove the `if: github.event_name == 'push'` guard from the
integration-tests job so it also runs on pull_request events.

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

aaight commented Feb 25, 2026

Done — removed the if: github.event_name == 'push' guard from the integration-tests job so it now runs on both pushes and PRs. The Postgres service container will spin up for PR checks too.

Commit: f8cce4e

@zbigniewsobiecki zbigniewsobiecki merged commit edbcd3c into dev Feb 25, 2026
5 of 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