fix(tests): harden agent worker test environment#831
Merged
zbigniewsobiecki merged 1 commit intodevfrom Mar 14, 2026
Merged
Conversation
Three changes to prevent agent confusion when running tests inside worker containers: 1. **CLAUDE.md**: Document correct test commands (npm test, test:unit, test:integration, test:all) and add a warning against `npm test -- --project integration`, which adds rather than replaces the unit project flags. 2. **beforeAll(truncateAll)**: Add file-level truncation to all 6 top-level integration test files so each file starts from a known-clean state regardless of what previous test files left in the DB. 3. **withTestTransaction helper**: Implement a correct transaction-rollback pattern for integration tests. Adds `_setTestDb` hook to getDb() so the active transaction can be injected, and exports `withTestTransaction` from tests/integration/helpers/db.ts for future use without re-inventing it. New unit tests cover _setTestDb/getDb override and withTestTransaction lifecycle (rollback-on-success, error propagation, _setTestDb cleanup in finally). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
Three hardening changes to prevent agent confusion and fragile test isolation when running tests inside worker containers, identified from analysis of agent run
87523cb1.npm test,test:unit,test:integration,test:all,test:coverage,test:watch) and add an explicit warning againstnpm test -- --project integration, which adds the integration project on top of the 4 hardcoded unit flags rather than filtering to it. Documents how integration tests locate their database.beforeAll(truncateAll): Add file-level DB truncation to all 6 top-level integration test files (github-personas,integration-validation,multi-provider-credentials,pm-provider-switching,trigger-registry,webhook-logging). Ensures each file starts from a clean slate regardless of what previous test files left in the DB — purely additive, existingbeforeEach(truncateAll)unchanged.withTestTransactionhelper +_setTestDbhook: Implement the correct transaction-rollback pattern for integration tests. Adds_setTestDb(db | null)tosrc/db/client.tssogetDb()can be overridden with an active transaction object, and exportswithTestTransactionfrom the integration test helpers. Prevents future agents from re-inventing a broken global-singleton approach.Tests
tests/unit/db/client.test.ts— 3 new tests covering_setTestDb/getDb()override mechanismtests/unit/integration-helpers/withTestTransaction.test.ts— 5 new tests covering rollback-on-success, error propagation, and_setTestDblifecycle (called with tx before fn, null in finally)Test plan
npm test— all 4797 unit tests passnpm run test:integration— all 306 integration tests passnpm run typecheck— cleannpm run lint— clean🤖 Generated with Claude Code