Files
boss/tests/project-scoped-realtime-refresh.test.ts
2026-04-07 17:29:42 +08:00

65 lines
2.5 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import path from "node:path";
import { readFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
const testsDir = path.dirname(fileURLToPath(import.meta.url));
async function readWorkspaceFile(relativePath: string) {
return readFile(path.join(testsDir, "..", relativePath), "utf8");
}
test("RealtimeRefresh supports project-scoped refresh filtering", async () => {
const source = await readWorkspaceFile("src/components/app-runtime.tsx");
assert.match(source, /projectId\?: string/, "expected RealtimeRefresh to accept an optional projectId");
assert.match(
source,
/conversationUpdatedNotes\?: string\[]/,
"expected RealtimeRefresh to accept optional conversationUpdatedNotes",
);
assert.match(
source,
/payload\.projectId !== projectId[\s\S]*return false/,
"expected RealtimeRefresh to filter by matching projectId",
);
assert.match(
source,
/payload\.note\)\s*&&\s*!conversationUpdatedNotes\.includes\(payload\.note\)/,
"expected RealtimeRefresh to ignore unmatched conversation.updated notes",
);
});
test("project conversation pages wire project-scoped realtime refresh", async () => {
const [projectPage, goalsPage, versionsPage, threadStatusPage] = await Promise.all([
readWorkspaceFile("src/app/conversations/[projectId]/page.tsx"),
readWorkspaceFile("src/app/conversations/[projectId]/goals/page.tsx"),
readWorkspaceFile("src/app/conversations/[projectId]/versions/page.tsx"),
readWorkspaceFile("src/app/conversations/[projectId]/thread-status/page.tsx"),
]);
assert.match(projectPage, /projectId=\{detail\.project\.id\}/, "expected project chat page to pass projectId into RealtimeRefresh");
for (const [label, source] of [
["goals", goalsPage],
["versions", versionsPage],
["thread-status", threadStatusPage],
] as const) {
assert.match(source, /<RealtimeRefresh/, `expected ${label} page to render RealtimeRefresh`);
assert.match(source, /projectId=\{projectId\}/, `expected ${label} page to scope refreshes to the current project`);
assert.match(source, /"conversation\.updated"/, `expected ${label} page to listen to conversation updates`);
}
assert.match(
goalsPage,
/conversationUpdatedNotes=\{\["project_goals\.updated"\]\}/,
"expected goals page to refresh only on project goal markers",
);
assert.match(
versionsPage,
/conversationUpdatedNotes=\{\["project_goals\.updated"\]\}/,
"expected versions page to refresh only on project goal markers",
);
});