|
| 1 | +// Covers the poll-comment folder: a native poll's caption is an inline reply to |
| 2 | +// the poll balloon (its reply_to_guid == the poll's guid) that lands WITH the |
| 3 | +// poll, and must be folded (dropped) rather than delivered as a standalone |
| 4 | +// message the agent answers in prose. A deliberate later reply, or a different |
| 5 | +// sender's reply, must NOT be folded. |
| 6 | +import { describe, expect, it } from "vitest"; |
| 7 | +import { createPollCommentFolder } from "./poll-comment.js"; |
| 8 | + |
| 9 | +const POLL_GUID = "75A8F623-947D-4611-A23D-4DDD6D17BC0F"; |
| 10 | +const T0 = 1_000_000; // arbitrary base timestamp (ms) |
| 11 | + |
| 12 | +describe("createPollCommentFolder", () => { |
| 13 | + it("folds a caption whose reply_to_guid targets a poll that lands with it", () => { |
| 14 | + const folder = createPollCommentFolder(); |
| 15 | + folder.rememberPoll(POLL_GUID, T0, "+15551110000"); |
| 16 | + // Caption ships with the poll — same instant, same sender. |
| 17 | + expect(folder.isPollComment(POLL_GUID, T0 + 500, "+15551110000")).toBe(true); |
| 18 | + }); |
| 19 | + |
| 20 | + it("does NOT fold a deliberate later inline reply to the poll", () => { |
| 21 | + const folder = createPollCommentFolder({ windowMs: 15_000 }); |
| 22 | + folder.rememberPoll(POLL_GUID, T0, "+15551110000"); |
| 23 | + // A real "I can't make it" reply a minute later must be delivered. |
| 24 | + expect(folder.isPollComment(POLL_GUID, T0 + 60_000, "+15551110000")).toBe(false); |
| 25 | + }); |
| 26 | + |
| 27 | + it("does NOT fold an in-window reply from a different sender (group member)", () => { |
| 28 | + const folder = createPollCommentFolder(); |
| 29 | + folder.rememberPoll(POLL_GUID, T0, "+15551110000"); |
| 30 | + expect(folder.isPollComment(POLL_GUID, T0 + 500, "+15559998888")).toBe(false); |
| 31 | + }); |
| 32 | + |
| 33 | + it("does NOT fold when the reply sender is known but the poll sender is unknown", () => { |
| 34 | + // Fail closed: an unknown-sender poll row must not turn a real in-window |
| 35 | + // reply from an identified participant into a dropped message. This fold |
| 36 | + // runs before the normal missing-sender/allowlist gate. |
| 37 | + const folder = createPollCommentFolder(); |
| 38 | + folder.rememberPoll(POLL_GUID, T0, undefined); |
| 39 | + expect(folder.isPollComment(POLL_GUID, T0 + 500, "+15551110000")).toBe(false); |
| 40 | + }); |
| 41 | + |
| 42 | + it("does NOT fold when the reply sender is unknown", () => { |
| 43 | + const folder = createPollCommentFolder(); |
| 44 | + folder.rememberPoll(POLL_GUID, T0, "+15551110000"); |
| 45 | + expect(folder.isPollComment(POLL_GUID, T0 + 500, undefined)).toBe(false); |
| 46 | + }); |
| 47 | + |
| 48 | + it("does not fold a reply to an unrelated message", () => { |
| 49 | + const folder = createPollCommentFolder(); |
| 50 | + folder.rememberPoll(POLL_GUID, T0, "+15551110000"); |
| 51 | + expect(folder.isPollComment("SOME-OTHER-GUID", T0, "+15551110000")).toBe(false); |
| 52 | + }); |
| 53 | + |
| 54 | + it("does not fold a non-reply or a reply with no usable timestamp", () => { |
| 55 | + const folder = createPollCommentFolder(); |
| 56 | + folder.rememberPoll(POLL_GUID, T0, "+15551110000"); |
| 57 | + expect(folder.isPollComment(null, T0)).toBe(false); |
| 58 | + expect(folder.isPollComment("", T0)).toBe(false); |
| 59 | + expect(folder.isPollComment(POLL_GUID, Number.NaN)).toBe(false); |
| 60 | + }); |
| 61 | + |
| 62 | + it("does not track a poll without a usable timestamp or guid", () => { |
| 63 | + const folder = createPollCommentFolder(); |
| 64 | + folder.rememberPoll(POLL_GUID, Number.NaN, "+15551110000"); |
| 65 | + expect(folder.isPollComment(POLL_GUID, T0)).toBe(false); |
| 66 | + folder.rememberPoll(null, T0, "+15551110000"); |
| 67 | + expect(folder.isPollComment("", T0)).toBe(false); |
| 68 | + }); |
| 69 | + |
| 70 | + it("does not fold before the poll has been seen (ordering safety)", () => { |
| 71 | + const folder = createPollCommentFolder(); |
| 72 | + expect(folder.isPollComment(POLL_GUID, T0, "+15551110000")).toBe(false); |
| 73 | + folder.rememberPoll(POLL_GUID, T0, "+15551110000"); |
| 74 | + expect(folder.isPollComment(POLL_GUID, T0, "+15551110000")).toBe(true); |
| 75 | + }); |
| 76 | +}); |
0 commit comments