The Sync bullet now says that POST /api/sync creates no occurrence (a
completed `task create` still adds its own row), and that the wait of a
second simultaneous request is read, not tested: PGlite has one
connection. The header of the task route test says that the WebSocket
notice is recorded.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Their afterEach wrote `UTC` back, so they could stand in for the first
statement of the file: with that statement removed, the parity cases that
ran after them still passed (found by mutation, one red test instead of
five). The hook now restores the zone read when the file is collected.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
One bullet in the Sync zone, after the `task create` bullet: the app for
its own completions, completeTask for the site and the MCP tools, never
POST /api/sync; the UTC computation of the server against the local time
of the app; the contract of taskWrites.ts.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Completing a recurring task on the site only set completedAt: the next
occurrence was created by the app alone. PUT /api/tasks/[id] now creates
it, through a function the MCP tools will call too.
- lib/recurrence.ts: RECURRENCES, isRecurrence and nextOccurrence, computed
in UTC without date-fns (a day, seven days, a month or a year later at the
same UTC time, ends of months as date-fns).
- lib/taskWrites.ts: completeTask and reopenTask. They take the transaction
of their caller first, then userId; they open no transaction, send no
notification and do not import the database client. completeTask moves
the task from open to done with one UPDATE ... WHERE completed = false
... RETURNING, and creates the next occurrence only when that statement
returns the row.
- PUT /api/tasks/[id]: one transaction for the whole body; `completed` goes
through completeTask or reopenTask, the other fields are written first.
Two wanted changes: `completed: true` on a task already done no longer
rewrites completedAt, and a body that carries `completed` answers 404 for
a deleted task. The notification leaves once, after the commit.
- POST /api/sync is untouched: the app creates and pushes the next
occurrence of its own completions; a test locks it.
- Tests: recurrence table (replayed under four time zones), parity with the
app's getNextOccurrence under TZ=UTC in the folder of the sync harness,
route tests of the completion, of its refusals and of the module contract.
Resolves#201
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>