Skip to content

refactor(fleet): move the fleet-case join persistence out of the cron route (Closes #61) - #98

Merged
SherlockOmss merged 1 commit into
mainfrom
refactor/61-fleet-case-store
Nov 26, 2026
Merged

SherlockOmss merged 1 commit into
mainfrom
refactor/61-fleet-case-store

Conversation

@SherlockOmss

@SherlockOmss SherlockOmss commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Closes #61 (SV-030).

What changes

  • joinOneTenant (the per-tenant join pass), its private upsertGroup, TenantJoinResult and the two read limits (JOIN_LOOKBACK_MS, JOIN_BATCH_SIZE) move from app/api/cron/join-fleet-cases/route.ts to the new lib/fleet-case-store.ts, the way groupOneTenant lives in lib/case-grouping-store.ts.
  • The route keeps JOIN_LOCK_KEY, JOIN_LABEL and the runPerTenant call: 170 lines down to 46.
  • Docs that point at the code are updated: docs/architecture.md, fleet/README.md, and the pointer in lib/fleet-case.ts.

Behavior

Unchanged: the function bodies moved as they were (queries, order, lock, result shape).

Tests

No new test: tests/integration/join-fleet-cases-cron.test.ts already pins create, grow, merge into the older case, idempotence (the whole row, updatedAt included), severity never lowered, tenant isolation and a failing tenant. Run before and after the move on a PostgreSQL 15: 18 of 18 both times.

Checks

  • tsc --noEmit clean; npm run lint 0 errors, 113 warnings (same as main); vitest run tests/unit 1479 passed, 1 skipped.
  • join-fleet-cases-cron and fleet-cases-console integration tests: 27 passed.

🤖 Generated with Claude Code

… route (#61)

`joinOneTenant` and `upsertGroup` move from `app/api/cron/join-fleet-cases/route.ts`
to `lib/fleet-case-store.ts`, as `groupOneTenant` lives in `lib/case-grouping-store.ts`.
The route keeps the lock key, the label and the runner call. No logic change; the
18 integration tests of the cron pass unchanged.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: SherlockOmss <[email protected]>
@SherlockOmss

Copy link
Copy Markdown
Contributor Author

Pushed a164899 (signed off). Files: app/api/cron/join-fleet-cases/route.ts, lib/fleet-case-store.ts (new), lib/fleet-case.ts (comment), docs/architecture.md, fleet/README.md. Checks run locally: tsc, lint 0 errors, 1479 unit tests, 27 integration tests on a PostgreSQL 15 container. CI not yet seen.

@SoFrexs SoFrexs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed a164899. A clean move; approving.

  • joinOneTenant and upsertGroup are byte-identical to main once the new doc comments and export are removed. Queries and their order, the per-tenant transaction and advisory lock (JOIN_LOCK_KEY, still runPerTenant in the route), the idempotence guard on updatedAt, severity never going down, and the result shape are unchanged.
  • import type { Prisma } is right; the module follows lib/case-grouping-store.ts; docs/architecture.md, fleet/README.md and lib/fleet-case.ts point at the new place.
  • The existing integration test imports only the route's GET, so it still exercises the moved code end to end.

[should-fix, follow-up is fine] lib/fleet-case-store.ts:61: upsertGroup is 72 lines and trips max-lines-per-function (one of the 113 counted warnings, and SV-030 names it). Keeping a move verbatim is right, but the debt it touches should be tracked: an issue to split it into find-or-create target / merge others / link detections / recompute summary, with an explicit return type.

[nit] fleet/README.md:17 is now 111 characters; rewrap it to the file's width.

Verified: verbatim diff of the moved code against origin/main; tsc --noEmit clean; lint 0 errors, 113 warnings; vitest run tests/unit 1467 passed, 5 skipped (Windows); no conflict with #97 (git merge-tree). Not run: integration tests (no Docker here); I rely on the 18/18 on PG15 reported in the PR.

🤖 Generated with Claude Code

@SherlockOmss
SherlockOmss merged commit 1b9369d into main Nov 26, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SV-030: Domain persistence logic in a route file

2 participants