mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 01:39:51 +01:00
test(e2e): grade the question journey's saved reference by its complete token (#22949)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - The daily QA staging smoke runs the `question-answer-resume` product
journey against a real agent
> - The board answers the agent's reference question with the text `Use
<marker>.`
> - The grader required the literal text `Use <marker>.` in the saved
note
> - Agents read `Use X.` as an instruction. Some save `Use X.`, others
save only `X`. Both notes are correct
> - This pull request grades the saved note by the complete marker
token, not by the answer's instruction wording
> - The benefit is that the smoke case no longer fails at random on a
correct note
## Linked Issues or Issue Description
**Describe the bug**
The QA staging smoke case `question-answer-resume` failed with
`journey_operation_failed`. The failed checks were
`question-resume.complete-evidence` and `question-document-reloaded`.
**Steps to reproduce**
1. Run the QA staging smoke journeys (full run on 2026-11-25).
2. The agent asks for a reference. The board answers `Use
AMBERjourney179560441987913f9fa70.`
3. The agent saves `Welcome to the club meetup this afternoon — we're
glad you're here; reference: AMBERjourney179560441987913f9fa70.`
4. The grader fails the note because it does not contain the word `Use`.
**Expected behavior**
A note that contains the complete submitted reference and the selected
time passes. A second campaign on the same day passed only because that
agent kept `Use` in the note.
**Additional context**
The private record also showed 4 `Invalid JSON body` responses. They
come from one failed `POST /api/issues/{id}/interactions` call that the
agent made itself, before it retried with a valid body and got 201. That
call is not the cause of the failure. The journey and the server route
are correct.
## What Changed
- Add `includesSubmittedReference` in
`tests/runner-e2e/question-resume-scoring.ts`. It matches the complete
marker token with no extra letters or digits on either side.
- Use it in `question-resume.complete-evidence` and in
`question-document-reloaded`.
- `waitForClarificationDocument` waits for the complete marker
(`submittedReferencePattern`), not for `Use <marker>.`. Before, a
correct note without `Use` timed out in the browser readback.
- Change the old unit test that rejected a note with only the marker. It
now accepts that note. New cases reject a shortened marker, an extended
marker, and a prefixed marker.
## Verification
- Red: the new cases failed on the old grader (3 failed, 144 passed).
The new readback case timed out on the old wait (1 failed, 3 passed).
- Green: `pnpm exec vitest run --config
tests/runner-e2e/vitest.config.ts` on the question-resume,
clarification, and question-documentation tests: 6 files, 170 tests
pass.
- `pnpm test:e2e:runner:typecheck` passes.
- After merge: a single-case `qa-staging-smoke.yml` run for
`question-answer-resume` on the new harness pin.
## Risks
Low risk. Test code only. The grader still requires the full marker. The
marker is a unique nonce, so a truncated or changed reference still
fails.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use and
code execution.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0609da79fb
commit
a0d5f275af
11 files changed
+82
-12
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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<string, any>;
|
||||
export const DOCUMENT_READBACK_MS = 120_000;
|
||||
interface Options { deadlineAt: number; directory: string; capture(id: string, label: string, file: string): Promise<void> }
|
||||
|
||||
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<Row>(`/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");
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { ContinuationCheckpoint } from "./continuation-scoring.js";
|
||||
import { includesSubmittedReference } from "./submitted-reference.js";
|
||||
|
||||
type Row = Record<string, any>;
|
||||
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.",
|
||||
},
|
||||
];
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
@@ -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<string, any>;
|
||||
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) }));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// The board answers "Use <marker>."; 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(`(?<![A-Za-z0-9-])(?<![A-Za-z0-9-]_+)${escaped}(?![A-Za-z0-9-])(?!_+[A-Za-z0-9-])`);
|
||||
};
|
||||
export const includesSubmittedReference = (body: unknown, marker: string) =>
|
||||
!!marker && typeof body === "string" && submittedReferencePattern(marker).test(body);
|
||||
Reference in new issue
Block a user