Files
PaperClipAI/tests/runner-e2e/chat-catalog-domains/runtime-email-private.test.ts
T

13 lines
3.6 KiB
TypeScript

import { expect, it } from "vitest";
import { randomUUID } from "node:crypto";
import { validateEmailPrivateReceipt } from "./runtime-email-private.js";
const expected = { operation: "setup" as const, companyId: randomUUID(), agentId: randomUUID() };
const valid = () => ({ ...expected, processIsolation: true, testRunnerAttached: false, apiStepRecorder: false, actualSingleDedicatedInbox: true, personId: "actual-fixture-person", connectionId: randomUUID(), endpointId: randomUUID(), actualActiveEndpoint: true, publicSetupOperationCount: 2, directProviderProbeCount: 3 });
it("accepts the finite actual setup receipt without credential/account contents", () => expect(validateEmailPrivateReceipt(valid(), expected).actualActiveEndpoint).toBe(true));
it("rejects another company, Test recorder, missing dedicated proof and secret fields", () => { for (const change of [{ companyId: randomUUID() }, { apiStepRecorder: true }, { actualSingleDedicatedInbox: false }, { token: "synthetic-private-value" }, { publicSetupOperationCount: -1 }]) expect(() => validateEmailPrivateReceipt({ ...valid(), ...change }, expected)).toThrow("closed receipt boundary"); });
it("retains only independently verified matched sent-message identities and rejects fabricated free-form payloads", () => { const receipt = { ...valid(), operation: "inspect" as const, matchedSent: [{ messageId: "actual-message", threadId: "actual-thread", publicationId: randomUUID(), contentMatches: true, accepted: true, recipientCopyObserved: false }], originalMessageMatched: true }; expect(validateEmailPrivateReceipt(receipt, { ...expected, operation: "inspect" }).matchedSent).toHaveLength(1); expect(() => validateEmailPrivateReceipt({ ...receipt, matchedSent: [{ ...receipt.matchedSent[0], text: "unapproved raw contents" }] }, { ...expected, operation: "inspect" })).toThrow(); });
it("accepts only the same closed independent receipt for an actually saved normal publication", () => { const r = { ...valid(), operation: "inspect-publication" as const, matchedSent: [{ messageId: "provider-message", threadId: "provider-thread", publicationId: randomUUID(), contentMatches: true, accepted: true, recipientCopyObserved: false }], originalMessageMatched: true }; expect(validateEmailPrivateReceipt(r, { ...expected, operation: "inspect-publication" }).originalMessageMatched).toBe(true); expect(() => validateEmailPrivateReceipt({ ...r, providerBody: "forbidden private response" }, { ...expected, operation: "inspect-publication" })).toThrow(); });
it("retains actual second-sender two-inbound qualification without exposing contents or accepting forged order", () => { const r = { ...valid(), operation: "seed-review" as const, actualFixtureSendCount: 2, inbound: { earlierMessageId: "actual-earlier", latestMessageId: "actual-latest", threadId: "actual-thread", earlierTimestamp: "2026-10-26T12:00:00Z", latestTimestamp: "2026-10-26T12:00:02Z", actualSenderQualified: true, actualRecipientQualified: true, earlierTextSha256: "a".repeat(64), latestTextSha256: "b".repeat(64) } }; expect(validateEmailPrivateReceipt(r, { ...expected, operation: "seed-review" }).inbound?.actualSenderQualified).toBe(true); for (const change of [{ actualSenderQualified: false }, { latestMessageId: "actual-earlier" }, { latestTimestamp: r.inbound.earlierTimestamp }, { text: "private message contents" }]) expect(() => validateEmailPrivateReceipt({ ...r, inbound: { ...r.inbound, ...change } }, { ...expected, operation: "seed-review" })).toThrow(); expect(() => validateEmailPrivateReceipt({ ...r, actualFixtureSendCount: 0 }, { ...expected, operation: "seed-review" })).toThrow(); });