diff --git a/tests/runner-e2e/SECURITY.md b/tests/runner-e2e/SECURITY.md index 0ffe1996445..2eb2b121014 100644 --- a/tests/runner-e2e/SECURITY.md +++ b/tests/runner-e2e/SECURITY.md @@ -829,3 +829,11 @@ unknown outside heartbeat accounting, never zero. This candidate includes only the focused local native-probe prerequisite from core PR18103; all candidate outcomes are separate from frozen39e qualification. Source acceptance is not permission to run the unused initial. + + +The hiring journey retains `hire-user-message-checks.json` before grading each +submitted message. Its private receipt contains comment IDs, exact byte counts, +SHA-256 body hashes and comparison results. It contains no raw message bodies or +provider session state. Mention insertion uses ordinary keyboard editing to +remove the editor-added space before typing the next exact source slice. The +exact saved-body check and single-message count remain required. diff --git a/tests/runner-e2e/hire-delegate-composer.spec.ts b/tests/runner-e2e/hire-delegate-composer.spec.ts index 1fd0aa3140d..d5a599edf65 100644 --- a/tests/runner-e2e/hire-delegate-composer.spec.ts +++ b/tests/runner-e2e/hire-delegate-composer.spec.ts @@ -11,7 +11,7 @@ test.afterAll(async () => { await fixture?.close(); }); const references = hireHandoffMentions({ companyId: r.companyId, leadId: r.leadId, projectId: r.projectId, campaignId: r.campaignId }, r.agentId, { id: r.agentId, companyId: r.companyId, reportsTo: r.leadId, name: `Morgan Reviewer ${r.campaignId}`, icon: "code" }, { id: r.projectId, companyId: r.companyId, name: `Journey QA hire-delegate-reuse ${r.campaignId}`, color: "#336699" }); -const message = (review = false) => `Have the existing ${references.teammate} ${review ? "review the checklist on QA-1 and write a separate saved review" : "write a concise launch checklist as a saved Paperclip document"}. Create exactly one task in ${references.project}, already assigned to that teammate when it is created. Link the result here.`; +const message = (review = false) => `Have the existing ${references.teammate} ${review ? "review the checklist on QA-1 and write a separate saved review" : 'write a concise launch checklist as a saved Paperclip document with the line "Reference: HIREjourney1deadbeef"'}. Create exactly one task in ${references.project}, already assigned to that teammate when it is created. Link the result here.`; async function open(page: Page, key: string, variant = "valid", mode = "production") { const url = new URL("/__hire.html", fixture.url); url.searchParams.set("case", key); url.searchParams.set("variant", variant); url.searchParams.set("mode", mode); await page.goto(url.href); diff --git a/tests/runner-e2e/product-journeys/hire-delegate-composer.ts b/tests/runner-e2e/product-journeys/hire-delegate-composer.ts index d94986723a6..97607109665 100644 --- a/tests/runner-e2e/product-journeys/hire-delegate-composer.ts +++ b/tests/runner-e2e/product-journeys/hire-delegate-composer.ts @@ -36,6 +36,18 @@ export async function sendHireHandoffMessage(page: Page, text: string, reference await expect(chip).toBeVisible({ timeout: timeout() }); if (await chip.getAttribute("href") !== token.href) throw new JourneyError("failed", "hire_handoff_mention_mismatch"); await page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(() => resolve())))); + // Mention insertion leaves the caret after one editor-added space. Remove + // that space through the normal keyboard path; the next source slice owns + // its exact whitespace (including punctuation directly after a mention). + const hasInsertedSpace = await editable.evaluate(element => { + const selection = element.ownerDocument.getSelection(); + const node = selection?.anchorNode; + return Boolean(selection?.isCollapsed && node?.nodeType === Node.TEXT_NODE + && element.contains(node) && selection.anchorOffset > 0 + && node.textContent?.slice(selection.anchorOffset - 1, selection.anchorOffset) === " "); + }); + if (!hasInsertedSpace) throw new JourneyError("failed", "hire_handoff_caret_mismatch"); + await editable.press("Backspace"); offset = token.at + token.markdown.length; } const suffix = text.slice(offset); diff --git a/tests/runner-e2e/product-journeys/hire-delegate-flow.test.ts b/tests/runner-e2e/product-journeys/hire-delegate-flow.test.ts index c954a0083dd..8bfbc140fb2 100644 --- a/tests/runner-e2e/product-journeys/hire-delegate-flow.test.ts +++ b/tests/runner-e2e/product-journeys/hire-delegate-flow.test.ts @@ -16,7 +16,7 @@ type Row = Record; const directories: string[] = []; afterEach(async () => { vi.mocked(sendChatMessage).mockReset(); await Promise.all(directories.splice(0).map(directory => rm(directory, { recursive: true, force: true }))); }); -async function fixture(options: { readError?: Error; mutate?(agents: Row[], tasks: Row[]): void; ownError?: Error; firstSendError?: Error; connectionList?: Row; connectionReadError?: Error } = {}) { +async function fixture(options: { storedBody?: string; readError?: Error; mutate?(agents: Row[], tasks: Row[]): void; ownError?: Error; firstSendError?: Error; connectionList?: Row; connectionReadError?: Error } = {}) { const campaignId = "journey-1-deadbeef", names = hireDelegateNames(campaignId), owned: Row[] = [], comments: Row[] = []; const binding = { connectionId: "approved" }, lead = { id: "lead", companyId: "company", name: `Lead ${campaignId}`, permissions: { canCreateAgents: true }, runtimeConfig: { aiConnection: binding } }; const hire = { id: "hired", companyId: "company", name: names.hire, reportsTo: lead.id, adapterType: "paperclip_runner", @@ -35,7 +35,7 @@ async function fixture(options: { readError?: Error; mutate?(agents: Row[], task const stop = new JourneyError("failed", "test_stop_before_delegation"); vi.mocked(sendChatMessage).mockImplementation(async (_page, text) => { if (sent) throw stop; - sent = true; if (options.firstSendError) throw options.firstSendError; comments.push({ id: "user-comment", authorUserId: "user", body: text }); + sent = true; if (options.firstSendError) throw options.firstSendError; comments.push({ id: "user-comment", authorUserId: "user", body: options.storedBody ?? text }); }); const api = { origin: "https://qa.example.test", async get(route: string) { if (route === "/api/instance/settings/experimental") return { enableAgentChat: true }; @@ -355,3 +355,19 @@ it.each(["earlier-handoff", "foreign-company", "foreign-chat", "wrong-run", "for { companyId: "company", chatId: "chat", runId: "callback" })).toBe(false); expect(clicked).toBe(false); }); + + +it("retains an exact failed message comparison before grading, without retaining raw bodies", async () => { + const f = await fixture({ storedBody: "A changed private fixture message" }); + await expect(f.run()).rejects.toMatchObject({ code: "hire_user_messages_stored_once" }); + const raw = await readFile(path.join(f.directory, "hire-user-message-checks.json"), "utf8"); + const receipt = JSON.parse(raw); + expect(receipt).toMatchObject({ schema: "paperclip.product-journey.hire-user-messages/v1", checks: [ + { turn: 1, matches: false, added: [{ id: "user-comment", matches: false }] }, + ] }); + expect(receipt.checks[0].expected.sha256).toMatch(/^[a-f0-9]{64}$/); + expect(receipt.checks[0].added[0].body.sha256).not.toBe(receipt.checks[0].expected.sha256); + expect(raw).not.toContain("private fixture message"); + expect(raw).not.toContain("Hire exactly one"); + expect(sendChatMessage).toHaveBeenCalledTimes(1); +}); diff --git a/tests/runner-e2e/product-journeys/hire-delegate-flow.ts b/tests/runner-e2e/product-journeys/hire-delegate-flow.ts index e6f61f494e0..af231adb320 100644 --- a/tests/runner-e2e/product-journeys/hire-delegate-flow.ts +++ b/tests/runner-e2e/product-journeys/hire-delegate-flow.ts @@ -1,3 +1,4 @@ +import { createHash } from "node:crypto"; import { mkdir, writeFile } from "node:fs/promises"; import { isDeepStrictEqual } from "node:util"; import path from "node:path"; @@ -172,6 +173,10 @@ export async function hireDelegateReuse(context: JourneyContext, session: Target } throw new JourneyError("failed", awaitingReply ? "hire_completion_reply_missing" : "hire_chat_not_completed"); }; + const messageChecks: Row[] = []; + const bodyReceipt = (body: unknown) => typeof body === "string" ? { + byteSize: Buffer.byteLength(body), sha256: createHash("sha256").update(body).digest("hex"), + } : null; const turn = async (text: string, count: number, handoff?: ReturnType) => { await page.goto(chatUrl, { waitUntil: "domcontentloaded" }); const before = await api.get(chatPath); @@ -181,7 +186,13 @@ export async function hireDelegateReuse(context: JourneyContext, session: Target const state = await waitForIdle(count); const comments = await api.get(`/api/issues/${state.chat.id}/comments?order=asc`); const added = comments.filter(row => row.authorUserId === context.user.id && !prior.some(old => old.id === row.id)); - check("hire-user-messages-stored-once", added.length === 1 && added[0].body === text); + const matches = added.length === 1 && added[0].body === text; + messageChecks.push({ turn: messageChecks.length + 1, expected: bodyReceipt(text), matches, + added: added.map(row => ({ id: row.id, body: bodyReceipt(row.body), matches: row.body === text })) }); + // Keep the actual comparison inputs before a failed grade, without copying + // message bodies, private session state or credentials into this receipt. + await retain("hire-user-message-checks.json", { schema: "paperclip.product-journey.hire-user-messages/v1", checks: messageChecks }); + check("hire-user-messages-stored-once", matches); return state; }; await session.own({ kind: "agent", name: names.hire, journeyId: "hire-delegate-reuse" });