From 690f0b95c022039a0100cd85923f7d471352a458 Mon Sep 17 00:00:00 2001 From: Lucas Berger Date: Tue, 9 Jun 2026 13:40:11 -0400 Subject: [PATCH] refactor(04): move rank.test.ts into tests/ mirror dir (convention + dist hygiene) src/lib/rank.test.ts was the last co-located API test. The API tsconfig excludes tests/ from the build, so all test files belong there; a test in src/ gets compiled into dist/ and vitest then runs the stale compiled copy (the source of phantom '22 todo' and dist sourcemap warnings). Moving it to tests/lib/ matches convention and leaves zero test files in src/, so the production build no longer emits test artifacts. Updated rank.test.ts path refs in phase-04 plan docs. --- .../phases/04-shared-lists-live-sync/04-04-PLAN.md | 8 ++++---- .../phases/04-shared-lists-live-sync/04-04-SUMMARY.md | 10 +++++----- .../phases/04-shared-lists-live-sync/04-05-PLAN.md | 10 +++++----- .../phases/04-shared-lists-live-sync/04-05-SUMMARY.md | 8 ++++---- apps/api/{src => tests}/lib/rank.test.ts | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) rename apps/api/{src => tests}/lib/rank.test.ts (96%) diff --git a/.planning/phases/04-shared-lists-live-sync/04-04-PLAN.md b/.planning/phases/04-shared-lists-live-sync/04-04-PLAN.md index 07521f4..70d9d7b 100644 --- a/.planning/phases/04-shared-lists-live-sync/04-04-PLAN.md +++ b/.planning/phases/04-shared-lists-live-sync/04-04-PLAN.md @@ -8,7 +8,7 @@ files_modified: - apps/api/src/routes/lists.ts - apps/api/tests/routes/lists.test.ts - apps/api/src/lib/rank.ts - - apps/api/src/lib/rank.test.ts + - apps/api/tests/lib/rank.test.ts - apps/pwa/src/api/listsClient.ts - apps/pwa/src/routes/ListDetail.tsx - apps/pwa/src/routes/ListDetail.test.tsx @@ -77,7 +77,7 @@ Output: item endpoints on listsRouter (POST items, per-field PATCH, DELETE); ran Task 1: Item endpoints + fractional-rank assignment (LIST-02, D-05/D-08/D-09) - apps/api/src/routes/lists.ts, apps/api/tests/routes/lists.test.ts, apps/api/src/lib/rank.ts, apps/api/src/lib/rank.test.ts + apps/api/src/routes/lists.ts, apps/api/tests/routes/lists.test.ts, apps/api/src/lib/rank.ts, apps/api/tests/lib/rank.test.ts - apps/api/src/routes/lists.ts (listsRouter from Plan 03 — extend; access-check pattern) - apps/api/tests/routes/lists.test.ts (item stubs) @@ -105,7 +105,7 @@ Output: item endpoints on listsRouter (POST items, per-field PATCH, DELETE); ran Note the route paths: items-by-list use /:id/items (nested under lists); single-item mutations use /list-items/:itemId at the listsRouter root (matches RESEARCH architecture diagram). Mount accordingly so both resolve under /api. Do NOT add publishListEvent here — Plan 06 inserts fan-out triggers (leave a clearly commented seam after each successful write). - pnpm --filter @familysync/api exec vitest run tests/routes/lists.test.ts src/lib/rank.test.ts && pnpm --filter @familysync/api typecheck + pnpm --filter @familysync/api exec vitest run tests/routes/lists.test.ts tests/lib/rank.test.ts && pnpm --filter @familysync/api typecheck - rank.ts tests green; ordering stable. @@ -172,7 +172,7 @@ Output: item endpoints on listsRouter (POST items, per-field PATCH, DELETE); ran -pnpm --filter @familysync/api exec vitest run tests/routes/lists.test.ts src/lib/rank.test.ts && pnpm --filter @familysync/pwa exec vitest run src/routes/ListDetail.test.tsx +pnpm --filter @familysync/api exec vitest run tests/routes/lists.test.ts tests/lib/rank.test.ts && pnpm --filter @familysync/pwa exec vitest run src/routes/ListDetail.test.tsx - `playwright-cli`: add / check / delete items in a real browser. diff --git a/.planning/phases/04-shared-lists-live-sync/04-04-SUMMARY.md b/.planning/phases/04-shared-lists-live-sync/04-04-SUMMARY.md index 22c910d..2009985 100644 --- a/.planning/phases/04-shared-lists-live-sync/04-04-SUMMARY.md +++ b/.planning/phases/04-shared-lists-live-sync/04-04-SUMMARY.md @@ -21,7 +21,7 @@ dependency_graph: - apps/api/src/routes/lists.ts (item routes added, listItemsRouter exported) - apps/api/src/index.ts (listItemsRouter mounted at /api/list-items) - apps/api/src/lib/rank.ts (new) - - apps/api/src/lib/rank.test.ts (new) + - apps/api/tests/lib/rank.test.ts (new) - apps/api/tests/routes/lists.test.ts (item route tests added) - apps/pwa/src/api/listsClient.ts (item functions added) - apps/pwa/src/routes/ListDetail.tsx (placeholder replaced with real implementation) @@ -41,7 +41,7 @@ tech_stack: key_files: created: - apps/api/src/lib/rank.ts - - apps/api/src/lib/rank.test.ts + - apps/api/tests/lib/rank.test.ts - apps/pwa/src/components/ItemRow.tsx - apps/pwa/src/components/AddItemInput.tsx modified: @@ -80,7 +80,7 @@ metrics: | Task | Name | Commit | Files | |------|------|--------|-------| -| RED | Failing tests for item routes + rank helpers | b1dc9b8 | tests/routes/lists.test.ts, src/lib/rank.test.ts | +| RED | Failing tests for item routes + rank helpers | b1dc9b8 | tests/routes/lists.test.ts, tests/lib/rank.test.ts | | GREEN | rank.ts + item endpoints + listItemsRouter + index.ts mount | 5e31514 | rank.ts, lists.ts, index.ts | | 2 | ListDetail + ItemRow + AddItemInput + listsClient item fns | 6da9c2a | 5 files (2 new, 3 modified) | @@ -107,7 +107,7 @@ Ran against `http://localhost:5173/lists/284` (list id 284, Test Groceries) with ## Verification Results ### API Tests -- `tests/routes/lists.test.ts + src/lib/rank.test.ts`: 48 passed (0 failed) +- `tests/routes/lists.test.ts + tests/lib/rank.test.ts`: 48 passed (0 failed) - rank.ts pure unit tests: 8 passed (rankForAppend/rankBetween ordering/stability) - Item POST assigns rank "a0" for first item; subsequent items rank > prior — PASS - Per-field PATCH zod refine (exactly one field) — two-field body → 400 — PASS @@ -152,7 +152,7 @@ No new threat surface beyond the plan's trust boundaries. ## Self-Check: PASSED - `apps/api/src/lib/rank.ts` — FOUND -- `apps/api/src/lib/rank.test.ts` — FOUND +- `apps/api/tests/lib/rank.test.ts` — FOUND - `apps/api/src/routes/lists.ts` (POST /:id/items route) — FOUND - `apps/api/src/index.ts` (listItemsRouter mounted at /api/list-items) — FOUND - `apps/pwa/src/components/ItemRow.tsx` — FOUND diff --git a/.planning/phases/04-shared-lists-live-sync/04-05-PLAN.md b/.planning/phases/04-shared-lists-live-sync/04-05-PLAN.md index adc98e2..17236c6 100644 --- a/.planning/phases/04-shared-lists-live-sync/04-05-PLAN.md +++ b/.planning/phases/04-shared-lists-live-sync/04-05-PLAN.md @@ -8,7 +8,7 @@ files_modified: - apps/pwa/src/routes/ListDetail.tsx - apps/pwa/src/components/ItemRow.tsx - apps/pwa/src/api/listsClient.ts - - apps/api/src/lib/rank.test.ts + - apps/api/tests/lib/rank.test.ts - apps/api/tests/routes/lists.test.ts autonomous: true requirements: [LIST-03] @@ -97,9 +97,9 @@ Output: dnd-kit DndContext/SortableContext in ListDetail; sortable ItemRow with Task 2: Strengthen server-side reorder ordering tests (LIST-03, D-13) - apps/api/src/lib/rank.test.ts, apps/api/tests/routes/lists.test.ts + apps/api/tests/lib/rank.test.ts, apps/api/tests/routes/lists.test.ts - - apps/api/src/lib/rank.test.ts (from Plan 04) + - apps/api/tests/lib/rank.test.ts (from Plan 04) - apps/api/tests/routes/lists.test.ts (PATCH position coverage) - .planning/phases/04-shared-lists-live-sync/04-VALIDATION.md (LIST-03 row: "PATCH new rank produces correct fractional order") - .planning/phases/04-shared-lists-live-sync/04-RESEARCH.md §"Common Pitfalls" Pitfall 2 (precision) @@ -108,7 +108,7 @@ Output: dnd-kit DndContext/SortableContext in ListDetail; sortable ItemRow with Add server-side tests proving reorder correctness: (a) repeated mid-point inserts via rankBetween produce strictly increasing distinct strings over many iterations (precision does not collapse — Pitfall 2); (b) PATCH /api/list-items/:id { position } updates only rank and a subsequent GET returns items in the new ASC order; (c) moving an item between two neighbors yields a rank strictly between theirs. These align the LIST-03 row in 04-VALIDATION.md to a green automated check. No production behavior change — Plan 04 already implements the PATCH position path. - pnpm --filter @familysync/api exec vitest run src/lib/rank.test.ts tests/routes/lists.test.ts + pnpm --filter @familysync/api exec vitest run tests/lib/rank.test.ts tests/routes/lists.test.ts - LIST-03 ordering test ("PATCH new rank produces correct fractional order") is present and green. @@ -136,7 +136,7 @@ Output: dnd-kit DndContext/SortableContext in ListDetail; sortable ItemRow with -pnpm --filter @familysync/api exec vitest run src/lib/rank.test.ts tests/routes/lists.test.ts && pnpm --filter @familysync/pwa exec tsc --noEmit +pnpm --filter @familysync/api exec vitest run tests/lib/rank.test.ts tests/routes/lists.test.ts && pnpm --filter @familysync/pwa exec tsc --noEmit - `playwright-cli`: drag-reorder persists across reload. diff --git a/.planning/phases/04-shared-lists-live-sync/04-05-SUMMARY.md b/.planning/phases/04-shared-lists-live-sync/04-05-SUMMARY.md index 9f8b1c0..6c74733 100644 --- a/.planning/phases/04-shared-lists-live-sync/04-05-SUMMARY.md +++ b/.planning/phases/04-shared-lists-live-sync/04-05-SUMMARY.md @@ -16,7 +16,7 @@ dependency_graph: affects: - apps/pwa/src/components/ItemRow.tsx (useSortable + handle listeners) - apps/pwa/src/routes/ListDetail.tsx (DndContext/SortableContext/useSensors/onDragEnd) - - apps/api/src/lib/rank.test.ts (precision + between-neighbors tests) + - apps/api/tests/lib/rank.test.ts (precision + between-neighbors tests) - apps/api/tests/routes/lists.test.ts (5 LIST-03 ordering tests) tech_stack: added: [] @@ -32,7 +32,7 @@ key_files: modified: - apps/pwa/src/components/ItemRow.tsx (useSortable + handle listeners + D-14 transition) - apps/pwa/src/routes/ListDetail.tsx (DndContext + SortableContext + useSensors + onDragEnd) - - apps/api/src/lib/rank.test.ts (2 new tests: precision + between-neighbors) + - apps/api/tests/lib/rank.test.ts (2 new tests: precision + between-neighbors) - apps/api/tests/routes/lists.test.ts (5 new LIST-03 ordering tests) decisions: - "@dnd-kit/utilities not installed as direct dependency; transformToString inlined (5-line function identical to CSS.Transform.toString) to avoid adding a redundant dep" @@ -85,7 +85,7 @@ Tested against `http://localhost:5173/lists/358` (list id 358, "Test Drag List", ## Verification Results ### API Tests -- `src/lib/rank.test.ts`: 10 passed (0 failed) — includes new precision test (100-iteration zipper inserts) and between-neighbors contract +- `tests/lib/rank.test.ts`: 10 passed (0 failed) — includes new precision test (100-iteration zipper inserts) and between-neighbors contract - `tests/routes/lists.test.ts`: 45 passed (0 failed) — includes 5 new LIST-03 ordering tests - Combined: 55 passed (0 failed) @@ -118,7 +118,7 @@ No new threat surface introduced. - `apps/pwa/src/components/ItemRow.tsx` — FOUND (useSortable imported and used) - `apps/pwa/src/routes/ListDetail.tsx` — FOUND (DndContext, SortableContext, generateKeyBetween imported and used) -- `apps/api/src/lib/rank.test.ts` — FOUND (precision + between-neighbors tests present) +- `apps/api/tests/lib/rank.test.ts` — FOUND (precision + between-neighbors tests present) - `apps/api/tests/routes/lists.test.ts` — FOUND (5 LIST-03 reorder tests added) - Commit d49c5f1 (Task 1) — FOUND - Commit ef4b115 (Task 2) — FOUND diff --git a/apps/api/src/lib/rank.test.ts b/apps/api/tests/lib/rank.test.ts similarity index 96% rename from apps/api/src/lib/rank.test.ts rename to apps/api/tests/lib/rank.test.ts index b367493..3c4e09e 100644 --- a/apps/api/src/lib/rank.test.ts +++ b/apps/api/tests/lib/rank.test.ts @@ -2,11 +2,11 @@ * Unit tests for rank.ts — fractional-indexing helpers (D-13). * * Pure function tests, no DB needed. - * Run: pnpm --filter @familysync/api exec vitest run src/lib/rank.test.ts + * Run: pnpm --filter @familysync/api exec vitest run tests/lib/rank.test.ts */ import { describe, it, expect } from 'vitest' -import { rankForAppend, rankBetween } from './rank.js' +import { rankForAppend, rankBetween } from '../../src/lib/rank.js' describe('rankForAppend', () => { it('returns "a0" when list is empty (no existing rank)', () => {