Files
PaperClipAI/server/vitest.config.ts
T
Dotta 629281b1e8 fix(test): eliminate Cloud Readiness timeouts in route imports and multi-page arbiter drain tests (#23160)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Post-merge `Cloud readiness` runs the full server test suite with
`--retry=0` before publishing new Core Docker images.
> - Five consecutive `Cloud readiness` runs on `master` failed over 22
hours because two test timeout patterns surfaced under multi-worker CI
shards.
> - First, `issue-activity-events-routes.test.ts` and
`issue-comment-attribution-audit-routes.test.ts` dynamically import
`server/src/routes/issues.ts` inside the first `it()` block, crossing
the 15s `testTimeout` when 5 fork workers simultaneously hit Vite's
transform server.
> - Second, `native-status-arbiter-corpus.test.ts` seeds 103 rows
sequentially in its multi-page drain tests, crossing 60s under 7-worker
shared-Postgres load and causing `afterEach` to time out before
restoring real timers.
> - This pull request moves those module imports into `beforeAll`,
aligns `server/vitest.config.ts` `testTimeout` with `hookTimeout` (30s),
batches the 103-row fixture seeding with bounded concurrency, and guards
timer restoration in `try/finally`.
> - The benefit is green, deterministic post-merge `Cloud readiness`
builds without weakening any test assertion or retry policy.

## Linked Issues or Issue Description

**What happened?**
Five consecutive `Cloud readiness` workflow runs on `master` failed and
cancelled over a 22-hour window, blocking new Core image publication:
- Three runs failed with `Test timed out in 15000ms` on the first test
of `server/src/__tests__/issue-activity-events-routes.test.ts` (twice)
and
`server/src/__tests__/issue-comment-attribution-audit-routes.test.ts`
(once) while dynamically importing `server/src/routes/issues.ts` under
5-worker parallel serialized shards.
- Two runs failed in
`server/src/__tests__/native-status-arbiter-corpus.test.ts` when `drains
more than one reconstruction page without replaying settled reviews`
timed out at `60000ms` during 103 sequential `seedReview()` calls, which
also timed out `afterEach` (`30000ms`) before restoring
`vi.useRealTimers()`.

**Expected behavior**
All server route and native status arbiter tests pass reliably on
post-merge `Cloud readiness` (`--retry=0`) without cold-transform
timeouts or leaked fake timers.

**Steps to reproduce**
1. Run `Cloud readiness` (`release-verify.yml`) on `master` with
`--retry=0` on 8-core runners (`maxWorkers=5` serialized shards,
`maxWorkers=7` general-server shards).
2. Observe cold dynamic imports of `routes/issues.ts` inside `it()`
crossing `15000ms` and the 103-row sequential seed test in
`native-status-arbiter-corpus.test.ts` crossing `60000ms`.

**Paperclip version or commit**
`c57471459f` (`master`)

## What Changed

- **`server/src/__tests__/issue-activity-events-routes.test.ts`**:
Register module mocks and import `routes/issues.js` and
`middleware/index.js` once in `beforeAll` (30s timeout) instead of
calling `vi.resetModules()` and re-importing on every test; keep full
`vi.clearAllMocks()` and mock defaults reset in `beforeEach`.
-
**`server/src/__tests__/issue-comment-attribution-audit-routes.test.ts`**:
Pre-import `routes/activity.js` and `routes/issues.js` in `beforeAll`
alongside embedded Postgres startup (30s timeout) instead of lazily
importing inside `createApp()` on the first test.
- **`server/vitest.config.ts`**: Increase `testTimeout` from `15000` to
`30000` (matching `hookTimeout` and `teardownTimeout`) so parallel cold
Vite transforms on 5-worker CI shards do not flake the first test in
sibling route suites.
- **`server/src/__tests__/native-status-arbiter-corpus.test.ts`**: Seed
the 103 fixtures in both multi-page drain tests in bounded concurrent
batches of 8, parallelize the final status assertions, allow `30_000ms`
for multi-page `flush()`, and wrap `coordinator?.stop()` in
`try/finally` in both `afterEach` hooks so `vi.useRealTimers()` and
`vi.restoreAllMocks()` always run.

## Verification

- `pnpm --filter @paperclipai/server typecheck` — passed
- `pnpm exec vitest run --project @paperclipai/server
server/src/__tests__/issue-activity-events-routes.test.ts
server/src/__tests__/issue-comment-attribution-audit-routes.test.ts
server/src/__tests__/native-status-arbiter-corpus.test.ts` — passed
(`3/3` files, `189/189` tests; `issue-activity-events-routes.test.ts`
ran in `3.95s` total and test 1 of
`issue-comment-attribution-audit-routes.test.ts` ran in `445ms`)

## Risks

- Low risk: test-only and Vitest timeout configuration changes. No
production server behavior, schema, or API contracts are changed, and no
test assertions or retry policies are weakened.

## Model Used

- Google DeepMind Antigravity (Gemini 3.1 Pro, agentic tool use with
shell verification)

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
2026-11-28 14:06:21 +00:00

58 lines
2.3 KiB
TypeScript

import { fileURLToPath } from "node:url";
import { defineConfig } from "vitest/config";
export default defineConfig({
resolve: {
alias: [
{
find: /^@paperclipai\/paperclip-runner\/live$/,
replacement: fileURLToPath(
new URL("../packages/paperclip-runner/src/live/index.ts", import.meta.url),
),
},
{
find: /^@paperclipai\/paperclip-runner$/,
replacement: fileURLToPath(
new URL("../packages/paperclip-runner/src/index.ts", import.meta.url),
),
},
],
},
test: {
environment: "node",
include: ["src/**/*.test.ts", "scripts/**/*.test.mjs"],
// Each server suite boots + tears down its own embedded Postgres in
// beforeAll/afterAll. Under the loaded serial shard (maxWorkers=1) the
// graceful shutdown can occasionally cross vitest's default 10s hookTimeout,
// producing flaky "Hook timed out in 10000ms" afterAll failures on CI. Give
// the boot/teardown hooks generous headroom; 30s is far above the observed
// worst-case teardown yet still catches a genuinely hung hook. teardownTimeout
// mirrors it for the same reason.
hookTimeout: 30000,
teardownTimeout: 30000,
// The route/authz suites import very large modules (for example
// src/routes/issues.ts and its dependency graph). The first test in each
// file can pay the one-time Vite transform cost inside its own timeout
// budget. Under file-parallel CI shards (up to 5 workers sharing Vite's
// transform server on 8-core runners, with --retry=0 on Cloud Readiness),
// simultaneous cold transforms regularly cross 15s and fail the first test,
// which also lets fire-and-forget wakes leak into the next test. Match
// hookTimeout/teardownTimeout at 30s so cold module loading never flakes
// while genuinely hung tests still fail well inside the 20 minute job limit.
testTimeout: 30000,
isolate: true,
maxConcurrency: 1,
maxWorkers: 1,
pool: "forks",
// Server suites share process state and one embedded Postgres instance,
// so tests inside a file must run one at a time. Do not set
// sequence.concurrent to true.
sequence: {
concurrent: false,
hooks: "list",
},
setupFiles: ["./src/__tests__/setup-supertest.ts"],
},
});