Repository navigation
refactor(fleet): move the fleet-case join persistence out of the cron route (Closes #61) - #98
Conversation
… 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]>
|
Pushed a164899 (signed off). Files: |
SoFrexs
left a comment
There was a problem hiding this comment.
Reviewed a164899. A clean move; approving.
joinOneTenantandupsertGroupare byte-identical tomainonce the new doc comments andexportare removed. Queries and their order, the per-tenant transaction and advisory lock (JOIN_LOCK_KEY, stillrunPerTenantin the route), the idempotence guard onupdatedAt, severity never going down, and the result shape are unchanged.import type { Prisma }is right; the module followslib/case-grouping-store.ts;docs/architecture.md,fleet/README.mdandlib/fleet-case.tspoint 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
Closes #61 (SV-030).
What changes
joinOneTenant(the per-tenant join pass), its privateupsertGroup,TenantJoinResultand the two read limits (JOIN_LOOKBACK_MS,JOIN_BATCH_SIZE) move fromapp/api/cron/join-fleet-cases/route.tsto the newlib/fleet-case-store.ts, the waygroupOneTenantlives inlib/case-grouping-store.ts.JOIN_LOCK_KEY,JOIN_LABELand therunPerTenantcall: 170 lines down to 46.docs/architecture.md,fleet/README.md, and the pointer inlib/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.tsalready pins create, grow, merge into the older case, idempotence (the whole row,updatedAtincluded), 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 --noEmitclean;npm run lint0 errors, 113 warnings (same as main);vitest run tests/unit1479 passed, 1 skipped.join-fleet-cases-cronandfleet-cases-consoleintegration tests: 27 passed.🤖 Generated with Claude Code