Files
PaperClipAI/server
b0d2500a63 test(server): split the Cloud SSH workspace heartbeat runs into per-harness files (#22629)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Each pull request runs CI, and the slowest check sets the time until
a reviewer sees a result
> - The server tests run in 12 shards, and the slowest shard sets that
time
> - In PR run
[45186146272](https://github.com/paperclipai/paperclip/actions/runs/45186146272),
the slowest check was **General tests (server (3/12))** at **872s**
> - One file in that shard,
`server/src/services/ssh-remote-workspace.integration.test.ts`, took
**317s** on one worker, because its 11 heartbeat runs against a real SSH
server ran one after another
> - This pull request moves the shared setup into a fixture and divides
the heartbeat runs into four files that can run in parallel
> - The benefit is a shorter slowest server shard and more even shards

## Linked Issues or Issue Description

No public issue exists. This is the problem:

**Problem / motivation**
The file `ssh-remote-workspace.integration.test.ts` took 317s in CI
(`PAPERCLIP_TEST_TIMING`). The next slowest file in the same shard took
206s. The slowest files in the other shards took about 110s or less. The
file was also over the 180s limit for oversized test files. Most of the
time came from the 11 `it.each` heartbeat runs. Each run does a full
heartbeat and a follow-up against a real SSH server.

**Proposed solution**
Move the shared embedded-Postgres and SSH setup and the heartbeat-run
body into a fixture. Divide the heartbeat runs into one file for each
large harness family, and one catch-all file for the other harnesses.

**Alternatives considered**
Increase the shard count. That makes every server shard pay the setup
cost again and does not make the 317s file shorter. Run the `it.each`
cases concurrently in one file. That puts many heartbeat runs on one
shared SSH server and one database, which can cause flaky tests.

## What Changed

- `__tests__/ssh-remote-workspace-fixture.ts` now holds the shared
embedded-Postgres/SSH setup (`useSshWorkspaceFixture`), the harness
table, and the heartbeat-run body (`describeSshHeartbeatRuns`). The body
was moved without changes.
- `ssh-remote-workspace.integration.test.ts` keeps its two
durable-workspace tests and uses the shared fixture.
- The heartbeat runs are now in four files:
  - `ssh-remote-workspace-heartbeat-claude` (2 runs)
  - `ssh-remote-workspace-heartbeat-codex` (2 runs)
  - `ssh-remote-workspace-heartbeat-gemini` (2 runs)
- `ssh-remote-workspace-heartbeat-cli` (5 runs). This file uses
`exclude`, so it runs every harness that does not have its own file. A
new harness gets coverage automatically.
- Each file gets its own Postgres, temporary root and sshd. Company
`issuePrefix` values still come from the global run index, so they stay
unique.

**Expected savings:** The largest single file goes from about 317s to
about 60–120s. After the timing-weighted balancer has data for the new
files, shard 3/12 should go from about 872s to the level of the other
server shards (about 790–855s). That is about **20–80s off the slowest
server shard**. The PR critical path gets the same saving when this
shard is the last to finish.

## Verification

- Run `pnpm --filter @paperclipai/server exec vitest run
src/services/ssh-remote-workspace` on a machine with sshd. Locally with
sshd and embedded Postgres: **5 files passed, 13 tests passed** (2 + 11,
the same count as before), 210s wall time with the files in parallel.
- CI on this PR: all server shards, the serialized suites and typecheck
passed.
- Compare the timing of the new files in the CI timing output of a later
run.

## Risks

- Low risk. The change only affects test files. Product code does not
change.
- Each new file starts its own embedded Postgres and sshd. This adds a
small setup cost per file, but the files run on different workers.
- If a harness is added to the `claude`, `codex` or `gemini` include
lists but is not added to the `exclude` list of the catch-all file, it
runs twice. It is not skipped.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), by Anthropic, in Claude Code with
tool use and code execution.

## 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)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: devinfoley <139239+devinfoley@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 13:32:48 -08:00
..