Mirrored from GitHub github.com/roostorg/coop

test: migrate DB-backed tests to transactional harness (#821) master

* fix: close express-session store on api shutdown connect-pg-simple keeps a recurring pruneSessions timer that calls pool.query on its pool. makeApiServer created the store with the shared KyselyPgPool but never closed it, so the timer kept running after shutdown. In tests this leaked a setInterval per makeMockedServer() call that fired pool.query on the harness's already-closed pinned connection after each test, logging "Failed to prune sessions: Client was closed and is not queryable" indefinitely and hanging the test worker — the loop that forced the manual cancellation of CI run 27951870325. Hold a reference to the store instance and call its close() in the shutdown path. ownsPg is false (we pass in our own pool), so close() only stops the prune timer and won't end the shared pool. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * test: migrate DB-backed tests to transactional harness Move the remaining DB-backed server tests onto the transaction-rollback harness from #732 so they get per-test isolation with no hand-written cleanup. - Convert the makeMockedServer/getBottle-based tests to makeTransactionalTestWithFixture, dropping manual org/user/queue/action deletes and KyselyPg.destroy() teardown: userKyselyPersistenceFindByEmailAndOrg, resolveSamlUser, and the MRT module tests (CommentOperations, JobRouting, QueueOperations, ReporterInvalidation). - Rewrite moderationConfigService and manualReviewToolService so every test is self-contained: each creates its own fresh org (rolled back automatically) rather than sharing a suite-scoped org. This removes the cross-test ordering/accumulator dependency in moderationConfigService and the hardcoded staging-seed-data dependency in manualReviewToolService. Scylla-touching tests (itemInvestigationService) keep uid-based isolation, since the Postgres-only harness can't roll those back. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test: migrate UserReportSweep and userStrikeService to transactional harness Two DB-backed test suites were missed by the initial migration commit: - manualReviewToolService/modules/UserReportSweep.test.ts: a sibling of the four MRT module tests already migrated (CommentOperations, JobRouting, QueueOperations, ReporterInvalidation). It used makeTestWithFixture + getBottle with hand-written cleanup (createOrg/createUser/createMrtQueue teardown + KyselyPg/KyselyPgReadReplica.destroy()). Converted to makeTransactionalTestWithFixture; cleanup is now automatic rollback. - userStrikeService/userStrikeService.test.ts: used beforeAll/afterAll with a shared getBottle container and uid-based isolation. Converted to makeTransactionalTestWithFixture for true per-test rollback isolation. Also fixes a copy-paste describe block name ('Item Investigation Service' -> 'User Strike Service'). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix: resolve typecheck errors in migrated test files Two files migrated by the prior commit had TypeScript errors that broke `tsc` (and therefore `check_api_server` and the e2e server start): - manualReviewToolService.test.ts: the 'records an AUTOMATIC_CLOSE decision with no human reviewer' test was left as a bare `it(...)` referencing an out-of-scope `mrtService` and hardcoded staging `orgId`/'queueId' ('e7c89ce7729'/'1') — the very seed-data dependency the migration was meant to remove. Convert it to `testWithQueue()` like its siblings, using the fixture's `mrtService`/`org.id`/`queue.id`. - moderationConfigService.test.ts: the 'should return actions for a rule scoped to the caller org' snapshot read `it.id` from `getActionsForRuleId`, which returns `{ action, parameters }[]` — should be `it.action.id` (as on main). Also add the now-present `email` field role to the #createUserType inline snapshot. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix: create real user in migrated JobRouting fixture The transactional JobRouting fixture accidentally replaced the pre-migration createUser() call with a bare uid(). createManualReviewQueue validates queue users, so setup failed after creating org/item-type rows but before the fixture returned. Because makeTestWithFixture cannot run cleanup when setup throws, the outer transaction stayed idle-in-transaction and later tests blocked on the item_type_versions materialized-view refresh, timing out check_api_server. Keep the transactional harness, but create a real user and pass user.id to the queue setup. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix: restore QueueOperations org-scoping tests The rebase conflict resolution for QueueOperations.test.ts accidentally kept the pre-#872 branch side and dropped the two-org org-scoping regression tests that now exist on main. Restore testWithTwoOrgs and its cross-org access tests, using the transactional harness. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test: configure decision-reason settings through service API Replace the decision-reason test helpers' direct writes to manual_review_tool_settings with a behavior-shaped helper that uses the ManualReviewToolService update API. The tests still exercise persisted org settings through submitDecision, but no longer couple setup to table and column names. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * style: remove api shutdown explanatory comments Remove the comments added around the express-session store shutdown while keeping the shutdown behavior unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>