// @vitest-environment jsdom import { afterEach, expect, it, vi } from "vitest"; vi.mock("@playwright/test", () => ({ expect: vi.fn() })); vi.mock("./api.js", () => ({ pollUntil: vi.fn() })); vi.mock("./run-observations.js", () => ({ collectRunEvents: vi.fn() })); vi.mock("./chat-catalog-domains/external-secret-scan.js", () => ({ scanReachableSecretOutputs: vi.fn(), privateScanJson: vi.fn(), bytesContainSecret: vi.fn(), sameSecretIdentity: vi.fn() })); // Isolate the CSS/DOM regression from unrelated Node-only runtime setup. vi.mock("./chat-flow.js", () => ({ sendChatMessage: vi.fn() })); vi.mock("./chat-catalog-domains/identity-support.js", () => ({ identityWorker: vi.fn(), openStandingChat: vi.fn(), probeAgentPermission: vi.fn() })); vi.mock("./chat-catalog-domains/external-support.js", () => ({ definition: () => ({}), observeExternal: vi.fn(), externalObservation: vi.fn(), checks: vi.fn(), root: vi.fn(), verifyRenderedReply: vi.fn() })); import { secretProposalCardSelector } from "./chat-catalog-domains/external-secret-proposal.js"; afterEach(() => { document.body.innerHTML = ""; }); it("selects the actual expanded proposal card when the pending trigger has the same production interaction ID", () => { // The timeline trigger owns the page anchor id; the docked card carries only the interaction data attribute. document.body.innerHTML = `

Deployment publishing key

Morgan

env.PUBLISHING_API_KEY

Other request

`; expect(document.querySelectorAll('[data-interaction-id="owned"]')).toHaveLength(2); const selected = document.querySelectorAll(secretProposalCardSelector("owned")); expect(selected).toHaveLength(1); expect(selected[0]?.tagName).toBe("DIV"); for (const fact of ["Deployment publishing key", "Morgan", "env.PUBLISHING_API_KEY"]) expect(selected[0]?.textContent).toContain(fact); expect(document.querySelectorAll(secretProposalCardSelector("missing"))).toHaveLength(0); }); it("a trigger, unrelated card or completed receipt cannot stand in for the bound proposal card", () => { document.body.innerHTML = `
Deployment publishing key Morgan env.PUBLISHING_API_KEY
Approved
`; expect(document.querySelectorAll(secretProposalCardSelector("owned"))).toHaveLength(0); });