Move the contract tests to the end that now writes

Three integration cases pinned the old behaviour: the sync handshake stamping
the checkpoint, and the calendar read persisting the prediction. Both are the
faults this release removes, so the cases were asserting a bug.

Each file now asserts the read writes nothing AND that the other end does. The
second half is not decoration: without it, "nothing was written" would pass
just as well against a column nothing writes at all.

The cycle case seeds its own history and its own profile row rather than
reaching a route to get one, because reaching the route is exactly what the
prediction must no longer depend on.
This commit is contained in:
Marc-André Bombeck committed 2026-08-02 02:00:08 +02:00
1 parent c9ee84e5e4
commit 03d2a712d0
2 files changed
+81 -10

No files matched your search

+23 -3
View File
@@ -103,21 +103,41 @@ describe("GET /api/sync/state (real Postgres)", () => {
expect(json.data.intakes.liveCount).toBe(0);
expect(json.data.intakes.tombstonedCount).toBe(0);
// Server-side, lastSyncedAt now carries a value.
// The handshake asks where to resume. It does not deliver anything, so it
// must not move the resume point: advancing past a window the client has
// not drained is how rows go missing.
const after = await getPrismaClient().user.findUnique({
where: { id: TEST_USER_ID },
select: { lastSyncedAt: true },
});
expect(after?.lastSyncedAt).not.toBeNull();
expect(after?.lastSyncedAt).toBeNull();
});
it("returns the previous checkpoint on the second call", async () => {
it("still reports null on the second call, because asking twice is not syncing", async () => {
// The old contract stamped the checkpoint on the first call, so the second
// read found one. Nothing has arrived between these two calls, so the
// honest answer is still null.
const { GET } = await import("@/app/api/sync/state/route");
await GET(makeRequest());
const res = await GET(makeRequest());
const json = (await res.json()) as {
data: { lastSyncedAt: string | null };
};
expect(json.data.lastSyncedAt).toBeNull();
});
it("reports a checkpoint once data has actually arrived", async () => {
// The other half of the move: the mark now comes from an ingest boundary.
// Without this case the two above would pass just as well against a column
// nothing writes at all, which is the failure they exist to rule out.
const { markSyncCheckpoint } = await import("@/lib/sync/checkpoint");
await markSyncCheckpoint(TEST_USER_ID);
const { GET } = await import("@/app/api/sync/state/route");
const res = await GET(makeRequest());
const json = (await res.json()) as {
data: { lastSyncedAt: string | null };
};
expect(json.data.lastSyncedAt).not.toBeNull();
});