diff --git a/tests/runner-e2e/product-journeys/clarification-evidence.test.ts b/tests/runner-e2e/product-journeys/clarification-evidence.test.ts index 2a0287cc8d3..7dd12248a3a 100644 --- a/tests/runner-e2e/product-journeys/clarification-evidence.test.ts +++ b/tests/runner-e2e/product-journeys/clarification-evidence.test.ts @@ -112,6 +112,17 @@ describe("attached clarification evidence", () => { expect(failures(f).length).toBeGreaterThan(0); } }); + it.each([ + ["Welcome to the club meetup this afternoon; reference: AMBERnonce.", true], + ["Welcome to the afternoon meetup. Use AMBERnonce.", true], + ["Welcome to the afternoon meetup, AMBERnonc.", false], + ["Welcome to the afternoon meetup, AMBERnonce2.", false], + ])("grades the saved reference by the complete submitted token: %s", (body, passes) => { + const f = recording(["semantic", "semantic"]), final = f.checkpoints.at(-1); + final.documents[0].body = body; + f.readback = { ...f.readback, body, visibleBody: body }; + expect(failures(f).map(c => c.id)).toEqual(passes ? [] : ["question-resume.complete-evidence", "question-document-reloaded"]); + }); it("requires reload evidence even for a correct API document", () => { const f = recording(["provider", "provider"]); expect(gradeClarificationEvidence(context, "task", "AMBERnonce", f.checkpoints).some(c => c.id === "question-document-reloaded" && !c.passed)).toBe(true); diff --git a/tests/runner-e2e/product-journeys/clarification-evidence.ts b/tests/runner-e2e/product-journeys/clarification-evidence.ts index 4d3ab02e70a..d2b218bef08 100644 --- a/tests/runner-e2e/product-journeys/clarification-evidence.ts +++ b/tests/runner-e2e/product-journeys/clarification-evidence.ts @@ -1,5 +1,6 @@ import { gradeQuestionResume, questionPath, validResumeQuestionForm, validResumeReferenceForm } from "../question-resume-scoring.js"; import type { ContinuationCheckpoint } from "../continuation-scoring.js"; +import { includesSubmittedReference } from "../submitted-reference.js"; import { validateAgentTaskState } from "./agent-flows.js"; import type { JourneyContext } from "./types.js"; @@ -49,7 +50,7 @@ export function gradeClarificationEvidence(context: JourneyContext, issueId: str detail: "The owned native agent created and last wrote the document on this exact task and company." }, { id: "question-document-reloaded", passed: !!document && !!readback && readback.issueId === issueId && readback.key === document.key && readback.revisionId === document.latestRevisionId && readback.body === document.body - && readback.visibleBody.includes(`Use ${marker}.`) && /\bafternoon\b/i.test(readback.visibleBody), + && includesSubmittedReference(readback.visibleBody, marker) && /\bafternoon\b/i.test(readback.visibleBody), detail: "The reloaded document must show both saved answers at the independently read revision." }, { id: "configured-model-and-environment", passed: bound && checkpoints.length === 3 && !!final && final.runs.length >= 1 && final.runs.length <= 3 && final.runs.every(run => run.status === "succeeded"), diff --git a/tests/runner-e2e/product-journeys/clarification-flow.ts b/tests/runner-e2e/product-journeys/clarification-flow.ts index baaa071a452..ec410c98de4 100644 --- a/tests/runner-e2e/product-journeys/clarification-flow.ts +++ b/tests/runner-e2e/product-journeys/clarification-flow.ts @@ -4,6 +4,7 @@ import { expect, type Locator } from "@playwright/test"; import { continuationScenario } from "../continuation-cases.js"; import { continuationAnswerCommitted, continuationCheckpointReady } from "../continuation-readiness.js"; import type { ContinuationCheckpoint } from "../continuation-scoring.js"; +import { submittedReferencePattern } from "../submitted-reference.js"; import { answerResumeQuestionThroughUi } from "../question-resume-ui.js"; import { createTaskThroughUi } from "../user-actions.js"; import { validateAgentTaskState } from "./agent-flows.js"; @@ -15,7 +16,7 @@ type Row = Record; export const DOCUMENT_READBACK_MS = 120_000; interface Options { deadlineAt: number; directory: string; capture(id: string, label: string, file: string): Promise } -export async function waitForClarificationDocument(visible: Locator, answer: string, deadlineAt: number) { +export async function waitForClarificationDocument(visible: Locator, marker: string, deadlineAt: number) { const remaining = () => { const timeout = deadlineAt - Date.now(); if (!Number.isFinite(timeout) || timeout <= 0) throw new JourneyError("failed", "clarification_document_not_ready"); @@ -23,7 +24,7 @@ export async function waitForClarificationDocument(visible: Locator, answer: str }; await expect(visible).toHaveCount(1, { timeout: remaining() }); await expect(visible).toBeVisible({ timeout: remaining() }); - await expect(visible).toContainText(answer, { timeout: remaining() }); + await expect(visible).toContainText(submittedReferencePattern(marker), { timeout: remaining() }); await expect(visible).toContainText(/afternoon/i, { timeout: remaining() }); remaining(); } @@ -116,7 +117,7 @@ export async function runClarificationJourney(context: JourneyContext, session: const visible = context.page.locator(`[id=${JSON.stringify(`document-${document.key}`)}]:visible, [id=${JSON.stringify(`side-panel-content-document:${document.key}`)}]:visible`); // The API already returned the saved document, so this is a bounded UI readback, // not agent work time: a missing view must not hold the worker until the case deadline. - await waitForClarificationDocument(visible, scenario.answer, Math.min(options.deadlineAt, Date.now() + DOCUMENT_READBACK_MS)); + await waitForClarificationDocument(visible, scenario.marker, Math.min(options.deadlineAt, Date.now() + DOCUMENT_READBACK_MS)); const persisted = await context.api.get(`/api/issues/${issue.id}/documents/${encodeURIComponent(document.key)}`); readback = { issueId: persisted.issueId, key: persisted.key, revisionId: persisted.latestRevisionId, body: persisted.body, visibleBody: await visible.innerText() }; await options.capture("reloaded", "Saved answers after reload", "clarification-reloaded.png"); diff --git a/tests/runner-e2e/product-journeys/clarification-readback.test.ts b/tests/runner-e2e/product-journeys/clarification-readback.test.ts index 5ec51654630..826d70ee6c6 100644 --- a/tests/runner-e2e/product-journeys/clarification-readback.test.ts +++ b/tests/runner-e2e/product-journeys/clarification-readback.test.ts @@ -2,12 +2,12 @@ import { afterEach, expect, it, vi } from "vitest"; import type { Locator } from "@playwright/test"; const clock = vi.hoisted(() => ({ now: 0, locator: {} })); -const answer = "Use AMBERreadback."; -const body = `Welcome to the afternoon meetup. ${answer}`; +const marker = "AMBERreadback", answer = `Use ${marker}.`; +let body = `Welcome to the afternoon meetup. ${answer}`, partial = answer; function stateAt(now: number) { return { count: now >= 100 ? 1 : 0, visible: now >= 100, - text: now >= 1_300 ? body : now >= 600 ? answer : "Loading" }; + text: now >= 1_300 ? body : now >= 600 ? partial : "Loading" }; } vi.mock("@playwright/test", async importOriginal => { @@ -39,7 +39,7 @@ afterEach(() => vi.restoreAllMocks()); it("shares one document deadline and retains rejection evidence through a later scheduler stall", async () => { clock.now = 0; vi.spyOn(Date, "now").mockImplementation(() => clock.now); - const observed = await waitForClarificationDocument(clock.locator as Locator, answer, 1_000).then( + const observed = await waitForClarificationDocument(clock.locator as Locator, marker, 1_000).then( () => ({ outcome: "resolved", at: clock.now, text: stateAt(clock.now).text }), (error: Error) => ({ outcome: "rejected", error: error.message, at: clock.now, text: stateAt(clock.now).text }), ); @@ -47,3 +47,16 @@ it("shares one document deadline and retains rejection evidence through a later expect(stateAt(clock.now).text).toBe(body); expect(observed).toEqual({ outcome: "rejected", error: "Document not ready within wait budget", at: 1_000, text: answer }); }); + +it.each([ + ["Welcome to the club meetup this afternoon; reference: AMBERreadback.", "resolved"], + ["Welcome to the afternoon meetup. Use AMBERreadback.", "resolved"], + ["Welcome to the afternoon meetup. Use AMBERreadbac.", "rejected"], +])("waits for the complete submitted reference, not the answer's instruction wording: %s", async (saved, outcome) => { + clock.now = 0; + vi.spyOn(Date, "now").mockImplementation(() => clock.now); + body = saved; partial = "Saving"; + const observed = await waitForClarificationDocument(clock.locator as Locator, marker, 5_000).then(() => "resolved", () => "rejected"); + body = `Welcome to the afternoon meetup. ${answer}`; partial = answer; + expect(observed).toBe(outcome); +}); diff --git a/tests/runner-e2e/product-journeys/hire-delegate-evidence.test.ts b/tests/runner-e2e/product-journeys/hire-delegate-evidence.test.ts index a9ad5c57fbf..e8a074443a4 100644 --- a/tests/runner-e2e/product-journeys/hire-delegate-evidence.test.ts +++ b/tests/runner-e2e/product-journeys/hire-delegate-evidence.test.ts @@ -252,6 +252,9 @@ describe("deployment hiring qualification", () => { } expect(() => grade({ ...document, issueId: "other" })).toThrow(); expect(() => grade({ ...document, key: "plan" })).toThrow(); + for (const changed of ["Reference: independent-marker-old", "Reference: xindependent-marker"]) { + expect(() => grade({ ...document, body: changed }, [{ ...revision, body: changed }])).toThrow(); + } expect(() => grade(document, [])).toThrow(); expect(() => grade(document, [revision], [])).toThrow(); }); diff --git a/tests/runner-e2e/product-journeys/hire-delegate-evidence.ts b/tests/runner-e2e/product-journeys/hire-delegate-evidence.ts index 242bcd5c65e..6ec5efc99a0 100644 --- a/tests/runner-e2e/product-journeys/hire-delegate-evidence.ts +++ b/tests/runner-e2e/product-journeys/hire-delegate-evidence.ts @@ -2,6 +2,7 @@ import { isDeepStrictEqual } from "node:util"; import { createRequire } from "node:module"; import { applyCompanyPrefix } from "../../../ui/src/lib/company-routes.js"; import { parseIssueReferenceFromHref, remarkLinkIssueReferences } from "../../../ui/src/lib/issue-reference.js"; +import { includesSubmittedReference } from "../submitted-reference.js"; import { JourneyError } from "./types.js"; import { isPendingNativeRecovery } from "./workspace-deferral.js"; @@ -206,7 +207,7 @@ export function assertHireDocument(scope: HireScope, task: Row, document: Row, r const revision = revisions.find(row => row.id === document.latestRevisionId); if (task.companyId !== scope.companyId || task.assigneeAgentId !== hiredId || task.status !== "done" || task.projectId !== scope.projectId || work.length !== 1 || work[0]?.status !== "succeeded" || document.issueId !== task.id || document.companyId !== scope.companyId - || document.key === "plan" || !document.body?.includes(marker) || !revision || revision.body !== document.body + || document.key === "plan" || !includesSubmittedReference(document.body, marker) || !revision || revision.body !== document.body || revision.createdByAgentId !== hiredId || revision.createdByRunId !== work[0]?.id) { throw new JourneyError("failed", "hired_document_provenance_mismatch"); } diff --git a/tests/runner-e2e/question-documentation-scoring.ts b/tests/runner-e2e/question-documentation-scoring.ts index a10ddc9390d..1574672d127 100644 --- a/tests/runner-e2e/question-documentation-scoring.ts +++ b/tests/runner-e2e/question-documentation-scoring.ts @@ -1,4 +1,5 @@ import type { ContinuationCheckpoint } from "./continuation-scoring.js"; +import { includesSubmittedReference } from "./submitted-reference.js"; type Row = Record; const questions = (checkpoint?: ContinuationCheckpoint): Row[] => @@ -61,7 +62,7 @@ export function gradeQuestionDocumentation(checkpoints: ContinuationCheckpoint[] }, { id: "both-answers-in-output", - passed: Boolean(final?.documents.some(d => d.key !== "plan" && d.body.includes(marker) && /\bafternoon\b/i.test(d.body))), + passed: Boolean(final?.documents.some(d => d.key !== "plan" && includesSubmittedReference(d.body, marker) && /\bafternoon\b/i.test(d.body))), detail: "The saved note must use both the selected time and the literal reference supplied in the text answer.", }, ]; diff --git a/tests/runner-e2e/question-documentation.test.ts b/tests/runner-e2e/question-documentation.test.ts index 516f2026f46..d913be2111e 100644 --- a/tests/runner-e2e/question-documentation.test.ts +++ b/tests/runner-e2e/question-documentation.test.ts @@ -72,4 +72,10 @@ describe("question tool documentation regression", () => { r[2].documents[0].body = "Welcome AMBER123."; expect(failed(r)).toContain("both-answers-in-output"); }); + it.each(["Welcome to the afternoon meetup, AMBER1234.", "Welcome to the afternoon meetup, AMBER123_old."])( + "rejects a changed reference token in the saved result: %s", body => { + const r = recording(); + r[2].documents[0].body = body; + expect(failed(r)).toContain("both-answers-in-output"); + }); }); diff --git a/tests/runner-e2e/question-resume-scoring.ts b/tests/runner-e2e/question-resume-scoring.ts index 30f1e46c350..1ee10cc0742 100644 --- a/tests/runner-e2e/question-resume-scoring.ts +++ b/tests/runner-e2e/question-resume-scoring.ts @@ -1,6 +1,7 @@ import { isDeepStrictEqual } from "node:util"; import type { ContinuationCheckpoint } from "./continuation-scoring.js"; import { isSingleClaudeQuestion } from "./runtime-question-readiness.js"; +import { includesSubmittedReference } from "./submitted-reference.js"; type Row = Record; export type QuestionPath = "provider" | "semantic" | "api"; @@ -156,7 +157,7 @@ export function gradeQuestionResume(checkpoints: ContinuationCheckpoint[], marke r.issueId === final.issue.id && r.agentId === final.issue.assigneeAgentId && typeof r.runnerProfileJson?.nativeExecutionInput?.task?.prompt === "string") && final.documents.length === 1 && !!final.documents[0].latestRevisionId && - final.documents[0].body.includes(`Use ${marker}.`) && /\bafternoon\b/i.test(final.documents[0].body), + includesSubmittedReference(final.documents[0].body, marker) && /\bafternoon\b/i.test(final.documents[0].body), detail: "Retain all three checkpoints, every native input and exactly one saved document containing the choice and the complete submitted reference.", }); return checks.map(c => ({ ...c, passed: Boolean(c.passed) })); diff --git a/tests/runner-e2e/question-resume.test.ts b/tests/runner-e2e/question-resume.test.ts index c312d4af580..af965210e39 100644 --- a/tests/runner-e2e/question-resume.test.ts +++ b/tests/runner-e2e/question-resume.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from "vitest"; import { readFileSync } from "node:fs"; import { gradeQuestionResume, questionPath, validResumeQuestionForm, type QuestionPath } from "./question-resume-scoring.js"; +import { includesSubmittedReference, submittedReferencePattern } from "./submitted-reference.js"; import { gradeContinuation } from "./continuation-scoring.js"; import { gradeLifecycleBaseline } from "./lifecycle-baseline.js"; import { continuationScenario } from "./continuation-cases.js"; @@ -181,13 +182,34 @@ describe("native question/resume path qualification", () => { expect(gradeLifecycleBaseline(r).filter(c => !c.passed)).toEqual([]); }); it.each([ - "Welcome to the afternoon meetup, AMBERnonce.", + "Welcome to the club meetup this afternoon; reference: AMBERnonce.", "Welcome to the afternoon meetup. Use AMBERnonce", + "Welcome to the afternoon meetup. Reference: _AMBERnonce_.", + "Welcome to the afternoon meetup. Reference: __AMBERnonce__.", + "Welcome to the afternoon meetup. Reference: **AMBERnonce**.", + ])("accepts the complete supplied reference without the answer's instruction wording: %s", body => { + const r = recording(); + r[2].documents[0].body = body; + expect(failed(r)).toEqual([]); + }); + it.each([ + "Welcome to the afternoon meetup, AMBERnonc.", + "Welcome to the afternoon meetup, AMBERnonce2.", + "Welcome to the afternoon meetup, xAMBERnonce.", + "Welcome to the afternoon meetup, AMBERnonce_extra.", + "Welcome to the afternoon meetup, AMBERnonce-extra.", + "Welcome to the afternoon meetup, old-AMBERnonce.", + "Welcome to the afternoon meetup, old_AMBERnonce.", + "Welcome to the afternoon meetup, _AMBERnonce_extra_.", ])("rejects a shortened supplied reference in the saved document: %s", body => { const r = recording(); r[2].documents[0].body = body; expect(failed(r)).toContain("question-resume.complete-evidence"); }); + it("never matches an empty reference marker", () => { + expect(includesSubmittedReference("Welcome to the afternoon meetup ! here", "")).toBe(false); + expect(() => submittedReferencePattern("")).toThrow(); + }); it("does not admit an optional Other field on the semantic path", () => { const r = recording(["semantic", "semantic"]); const i = question(r); diff --git a/tests/runner-e2e/submitted-reference.ts b/tests/runner-e2e/submitted-reference.ts new file mode 100644 index 00000000000..6d03c1773f7 --- /dev/null +++ b/tests/runner-e2e/submitted-reference.ts @@ -0,0 +1,10 @@ +// The board answers "Use ."; agents may save the instruction or only the +// reference, so a document passes when it holds the complete marker token. +export const submittedReferencePattern = (marker: string) => { + if (!marker) throw new Error("A submitted reference marker is required"); + // "_" may be Markdown emphasis (_X_ or __X__) but not a joined word (old_X, X_extra). + const escaped = marker.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + return new RegExp(`(? + !!marker && typeof body === "string" && submittedReferencePattern(marker).test(body);