import test from "node:test"; import assert from "node:assert/strict"; import { readFile } from "node:fs/promises"; async function readSource(path: string) { return readFile(new URL(path, import.meta.url), "utf8"); } test("events route supports message patch v1 while retaining snapshot fallback", async () => { const source = await readSource("../src/app/api/v1/events/route.ts"); assert.match( source, /x-boss-realtime-capabilities/, "expected realtime event route to inspect native app capability headers", ); assert.match( source, /projectMessagesPatch/, "expected realtime event route to emit a message patch for capable clients", ); assert.match( source, /projectMessagesPayload:\s*buildProjectMessagesRealtimePayload/, "expected realtime event route to retain full snapshot fallback for older clients", ); }); test("ProjectDetailActivity applies lightweight realtime chat payloads before scheduling reloads", async () => { const source = await readSource("../android/app/src/main/java/com/hyzq/boss/ProjectDetailActivity.java"); assert.match( source, /if \(tryApplyRealtimeMessagesPatch\(event\)\) \{\s*return;\s*\}/, "expected chat page to try a local realtime message patch before falling back to debounced reloads", ); assert.match( source, /JSONObject projectMessagesPayload = event\.payload\.optJSONObject\("projectMessagesPayload"\);/, "expected chat page to read the lightweight message payload from realtime events", ); assert.match( source, /JSONObject projectMessagesPatch = event\.payload\.optJSONObject\("projectMessagesPatch"\);/, "expected chat page to read message-patch-v1 realtime payloads first", ); assert.match( source, /scheduleRealtimeReload\(false\);/, "expected chat page to fall back to a debounced message reload when a patch has a gap", ); assert.match( source, /renderLoadedProjectSnapshot\(new ProjectSnapshot\(projectMessagesPayload,\s*null,\s*null\)\);/, "expected chat page to render the local realtime payload without forcing a network request", ); });