Files
PaperClipAI/server
Dotta ca21075837 test(server): fold tiny purge suites into the agent lifecycle owner suite (#23719)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - The agent lifecycle module owns agent purge and company deletion.
> - The repository test budget rule asks to add a narrow database case
to the owning suite, not to a small standalone file.
> - Two small test files each start their own embedded Postgres for a
few purge cases only.
> - This pull request moves those cases into the agent lifecycle owner
suite and deletes the two small files.
> - The benefit is two fewer test workers and two fewer database setups
in CI, with the same assertions kept.

## Linked Issues or Issue Description

No public GitHub issue exists for this change. The problem is described
here, using the enhancement template labels.

**What existing behavior does this improve?**

The layout of the agent lifecycle test suites and their CI setup cost.

**Subsystem affected**

server/ — REST API & orchestration services (agent lifecycle and company
deletion tests).

**Current behavior**

Two test files each boot an own embedded Postgres for a few purge cases:

- `server/src/services/agent-cost-history-deletion.test.ts` (61 lines)
covers the `agent_cost_history_retained` purge guard.
- `server/src/services/case-deletion.test.ts` (69 lines) covers company
deletion with retained case handoffs and the
`agent_case_history_retained` purge guard.

Each file pays a separate Vitest worker import and a separate embedded
database start. The `rules/test-budget.mdc` rule says: do not keep a
standalone embedded-Postgres file for one narrow regression case; add
the case to the owning service suite. The owner suite
`server/src/modules/agent-lifecycle/__tests__/lifecycle.test.ts` already
imports the same production modules (`createAgentLifecycle`,
`deleteCompany`) and uses the same database fixture.

**Proposed behavior**

The owner suite holds these cases inside two nested describe blocks. The
two small files no longer exist. No assertion changed.

**Reason and benefit**

CI runs two fewer standalone database files in the general server lane.
The moved cases reuse the database the owner suite already started. The
historical duration manifest recorded about 6 s and 8 s per file at its
recorded revision; these weights are scheduling estimates, not measured
savings for this change.

**Breaking changes**

None. Test code only.

## What Changed

- Moved 4 purge cost-history cases (cost event by run, cost event by
agent, finance event by run, and the positive purge case) into the owner
suite under `describe("agent purge with retained cost history")`.
- Moved 3 company-deletion-with-case-handoff cases (an `it.each` over
three handoff states, an `it.each` over source and target roles, and the
unrelated-agent purge case; 6 test registrations in total) into the
owner suite under `describe("deletion with retained case handoffs")`.
- Deleted `server/src/services/agent-cost-history-deletion.test.ts` and
`server/src/services/case-deletion.test.ts`.
- Added the `cases`, `caseAccessSources`, `caseHandoffs`, `costEvents`,
and `financeEvents` table imports to the owner suite.
- Net change: 131 deleted and 102 added test lines. No production line
changed.

The owner suite is a test file and was already longer than 1,000 lines
before this change. Extending the designated owner suite is the remedy
the test budget rule names for these files.

## Verification

Commands run on this branch (head `01bc9384`), local sandbox, Node
v25.9.0:

- `cd server && ../../node_modules/.bin/vitest run
src/modules/agent-lifecycle/__tests__/lifecycle.test.ts` — 1 file
passed, 86 tests passed, all 10 moved registrations included.
- Intended-failure control 1: the `agent_cost_history_retained` guard in
`server/src/services/agent-deletion.ts` was disabled for a moment. The 3
moved cost-history cases failed on their expected 409 conflict. The
positive purge case still passed. The file was then restored with `git
checkout` and the diff was checked clean.
- Intended-failure control 2: the `agent_case_history_retained` guard
was disabled the same way. The 2 moved handoff purge cases failed on
their expected 409 conflict. The other matched cases still passed. The
file was restored the same way.
- `node scripts/check-test-budget.mjs --files
server/src/modules/agent-lifecycle/__tests__/lifecycle.test.ts` — PASS.
- The full owner suite was run again after the restorations: 86 tests
passed.

Not run locally: the repository typecheck and the full test suite. The
runner build dependency for the typecheck did not fit the free disk of
this sandbox. The required CI checks passed on the PR head `01bc9384`:
68 checks succeeded (typecheck, build, all 20 general server test
shards, chat and workspaces-b shards, runner support, Greptile). Six
conditional lanes were skipped as not applicable. Three independent bot
reviews scored the change 5/5 with no findings.

## Risks

- Low risk. Test files only; no production code changed.
- The moved cases now share the database instance the owner suite
starts. Each moved case still creates its own rows with fresh
identifiers, and the controls above show each case still fails at its
own guard.
- The general server shard durations manifest still lists the two
deleted files. The manifest is regenerated from CI runs by
`scripts/ci/refresh-test-durations.mjs`; stale entries do not route
work.

## Model Used

GLM 5.3 (z-ai/glm-5.3; exact model ID `openrouter/z-ai/glm-5.3`), run by
the Paperclip Test Gardener agent, with tool use and code execution. No
extended thinking mode.

## 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
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-12-04 02:12:34 -06:00
..