evOo-local/packages/core/src/message-visibility.test.ts
cynarAI 6c7eed7580 Initial clean evOo-local from f00577b
Fresh history cut from cynarAI/evoo antigravity-handoff/project-timeline
(Voice First + project timeline). Brand docs/titles as evOo; keep @rakazo/*
packages as tech debt. Excludes node_modules, caches, secrets, voice blobs.
2026-09-20 17:15:16 +02:00

84 lines
2.8 KiB
TypeScript

import type { ThreadMessage } from "@rakazo/contracts";
import { describe, expect, it } from "vitest";
import { userVisibleMessages } from "./message-visibility.js";
function message(id: string, runId: string, blocks: ThreadMessage["blocks"]): ThreadMessage {
return {
id,
threadId: "thread-1",
seq: 1,
role: "bot",
blocks,
runId,
createdAt: "2026-08-30T22:00:00.000Z",
};
}
const peerExchange = [
message("user", "run-user", [{ kind: "text", text: "Please ask Coder." }]),
message("sent", "run-user", [
{ kind: "bot_message_sent", toBotId: "coder", toBotName: "Coder", text: "Check this." },
]),
message("received", "run-peer", [
{
kind: "bot_message_received",
fromBotId: "coder",
fromBotName: "Coder",
text: "Done.",
},
]),
message("activity", "run-peer", [{ kind: "steps", steps: [{ label: "Message bot", count: 1 }] }]),
message("reply", "run-peer", [{ kind: "text", text: "Sent Coder the endpoints." }]),
message("answer", "run-user", [{ kind: "text", text: "Coder is checking it." }]),
];
describe("user-visible messages", () => {
it("hides peer activity but keeps the bot's text reply to the user", () => {
expect(userVisibleMessages(peerExchange).map((item) => item.id)).toEqual([
"user",
"reply",
"answer",
]);
});
it("keeps compact peer receipts when includePeerReceipts is set", () => {
expect(
userVisibleMessages(peerExchange, { includePeerReceipts: true }).map((item) => item.id),
).toEqual(["user", "sent", "received", "reply", "answer"]);
});
it("uses authoritative peer run ids when the receipt is outside the loaded page", () => {
const messages = [
message("activity", "run-peer", [
{ kind: "steps", steps: [{ label: "Echoed peer reply", count: 1 }] },
]),
message("reply", "run-peer", [{ kind: "text", text: "Echoed peer reply" }]),
message("answer", "run-user", [{ kind: "text", text: "Visible answer" }]),
];
expect(
userVisibleMessages(messages, { knownPeerRunIds: ["run-peer"] }).map((item) => item.id),
).toEqual(["reply", "answer"]);
});
it("keeps a peer-run ask card and text reply while hiding other peer activity", () => {
const messages = [
message("ask", "run-peer", [
{
kind: "ask",
text: "Pick one",
status: "pending",
actions: [{ id: "a", label: "A" }],
},
]),
message("activity", "run-peer", [{ kind: "steps", steps: [{ label: "Work", count: 1 }] }]),
message("reply", "run-peer", [{ kind: "text", text: "Peer body" }]),
message("answer", "run-user", [{ kind: "text", text: "Visible answer" }]),
];
expect(
userVisibleMessages(messages, { knownPeerRunIds: ["run-peer"] }).map((item) => item.id),
).toEqual(["ask", "reply", "answer"]);
});
});