mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-06 23:20:53 +01:00
710 lines
61 KiB
TypeScript
710 lines
61 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { describe, expect, it } from "vitest";
|
|
import { gradeInternal, internalChatCatalogCases } from "./internal.js";
|
|
import type { Entity, InternalObservation } from "./internal-support.js";
|
|
import { externalPrerequisiteReceipt, validateExternalConfig } from "./external-fixtures.js";
|
|
|
|
function base(scenarioId: string): InternalObservation {
|
|
const p = { id: "p", companyId: "company", name: "Launch" };
|
|
const t = { id: "task", companyId: "company", title: "Website task", description: "Website", status: "backlog", priority: "medium", projectId: p.id, assigneeAgentId: null };
|
|
return { scenarioId, origin: "https://fixture.test", companyId: "company", leadId: "ceo", state: { project: p, task: t }, tasks: [t], projects: [p], goals: [], comments: [], activity: [], documents: [], revisions: [], reply: "", humanQueries: [], links: ["/ACORN/issues/task", "/ACORN/projects/p"],
|
|
runs: [{ id: "run", companyId: "company", agentId: "ceo", status: "succeeded" }] };
|
|
}
|
|
function event(action: string, entityId: string, details?: Record<string, unknown>): Entity {
|
|
return { id: `${action}-${entityId}`, action, entityId, agentId: "ceo", details };
|
|
}
|
|
function valid(scenario: string): InternalObservation {
|
|
const o = base(scenario);
|
|
switch (scenario) {
|
|
case "inbox-search.notification-audience": {
|
|
const participation = { id: "human", authorUserId: "alex", body: "Following this draft." }; const normal = { id: "normal", authorAgentId: "ceo", createdByRunId: "run", body: "The draft is ready for review." };
|
|
Object.assign(o.state, { alexId: "alex", rileyId: "riley", participation }); o.comments = [participation, normal];
|
|
const person = (id: string, eligible: boolean) => ({ principalId: id, visibility: "visible", sockets: ["/api/companies/company/events/ws"], frames: [{ principalId: id, taskId: "task", commentId: "normal", eligible, at: 1000 }], toasts: eligible ? [{ text: "CEO commented on task", hrefs: ["/ACORN/issues/task"], at: 1100 }] : [] });
|
|
Object.assign(o, { alex: person("alex", true), riley: person("riley", false), observedAt: 3100 }); o.state.firstAudience = structuredClone(o); o.state.mentionPhaseStartedAt = 4000;
|
|
o.comments.push({ id: "mention", authorAgentId: "ceo", createdByRunId: "second", body: "The draft is ready, [Riley](user://riley)." }); o.runs.push({ id: "second", companyId: "company", agentId: "ceo", status: "succeeded" });
|
|
for (const key of ["alex", "riley"]) { const p = (o as unknown as Record<string, { principalId: string; frames: unknown[]; toasts: unknown[] }>)[key]!; p.frames.push({ principalId: p.principalId, taskId: "task", commentId: "mention", eligible: true, at: 4500 }); p.toasts.push({ text: "CEO commented on task", hrefs: ["/ACORN/issues/task"], at: 4600 }); }
|
|
Object.assign(o, { observedAt: 5000 }); o.reply = "Posted both updates and the requested mention."; break;
|
|
}
|
|
case "documents-artifacts.find-artifact": {
|
|
const deliveryAt = "2026-10-21T12:00:00.000Z"; const hidden = { id: "hidden", title: "Restricted final NIGHTJAR", status: "done" };
|
|
o.tasks[0] = { ...o.tasks[0]!, status: "done" }; const current = { ...o.tasks[0], completedAt: deliveryAt }; o.state.task = structuredClone(o.tasks[0]); o.tasks.push(hidden);
|
|
const file = { id: "file", issueId: "task", assetId: "asset", issueCommentId: "delivery", sha256: "a".repeat(64), contentPath: "/api/attachments/file/content", createdAt: "2026-10-26T12:00:00.000Z" };
|
|
Object.assign(o.state, { privateTask: hidden, privateMarker: hidden.title, privateAttachment: { id: "hidden-file", assetId: "hidden-asset" }, finalAttachment: file, finalHash: file.sha256, deliveryAt, weekStart: Date.parse("2026-10-19T00:00:00Z"), weekEnd: Date.parse("2026-10-26T00:00:00Z"), originalTasks: structuredClone(o.tasks), distractors: [hidden] });
|
|
Object.assign(o, { currentSource: current, finalAttachment: file, downloadedHash: file.sha256, deliveryComments: [{ id: "delivery", createdAt: deliveryAt, body: `Final approved website delivered, SHA256 ${file.sha256}.` }], searchStatus: 200, searchResults: [{ id: "task" }], privateFileStatus: 403 });
|
|
o.activity = [{ id: "import", action: "company.imported", createdAt: "2026-10-26T12:00:01.000Z" }]; o.links.push("/api/attachments/file/content?download=1"); o.reply = "The final website was delivered last week; the preserved file was imported today."; break;
|
|
}
|
|
case "documents-artifacts.produce-download":
|
|
case "documents-artifacts.revise-delivery": {
|
|
const revising = scenario === "documents-artifacts.revise-delivery"; const prior = "<html><body><h1>Bring research notes together in one accessible place</h1><p>Research teams stay organized.</p><a href='https://example.test/signup'>Signup</a><footer>ORCHID</footer></body></html>";
|
|
const body = revising ? prior.replace("Bring research notes together in one accessible place", "Notes, together") : prior;
|
|
const sha = (bytes: string) => createHash("sha256").update(bytes).digest("hex");
|
|
const original = { id: "original", issueId: "task", sha256: sha(prior), originatingRunId: "build", contentPath: "/api/attachments/original/content" };
|
|
const file = { id: "new", issueId: "task", sha256: sha(body), originatingRunId: "run", contentPath: "/api/attachments/new/content" };
|
|
Object.assign(o.state, { worker: { id: "morgan" }, priorRunId: "build", producedBody: prior, producedHash: sha(prior), bodyFact: "Research teams stay organized.", signupHref: "https://example.test/signup", marker: "ORCHID", originalAttachment: original, originalProductId: "old-product" });
|
|
const product = (id: string, attachmentId: string, run: string) => ({ id, issueId: "task", type: "artifact", provider: "paperclip", status: "active", createdByRunId: run, metadata: { attachmentId } });
|
|
Object.assign(o, { attachments: [file, ...(revising ? [original] : [])], products: [product("new-product", "new", "run"), ...(revising ? [product("old-product", "original", "build")] : [])], downloaded: [{ id: "new", sha256: sha(body), body }, ...(revising ? [{ id: "original", sha256: sha(prior), body: prior }] : [])] });
|
|
o.runs.push({ id: "build", companyId: "company", agentId: "morgan", status: "succeeded" }); o.links.push("/api/attachments/new/content?download=1");
|
|
o.reply = "The updated shorter version is available; the original remains available."; break;
|
|
}
|
|
case "tasks.assignment-conflict": {
|
|
o.tasks[0] = { ...o.tasks[0]!, assigneeAgentId: "riley", status: "backlog" }; o.state.task = structuredClone(o.tasks[0]);
|
|
o.reply = "Riley owns the backlog task. Observed old brief."; o.state.firstRead = structuredClone(o);
|
|
const held = { ...o.tasks[0], assigneeAgentId: "morgan", status: "in_progress", executionRunId: "morgan-run", checkoutRunId: "morgan-run" };
|
|
Object.assign(o.state, { worker: { id: "morgan" }, riley: { id: "riley" }, readMarker: "Observed old brief", heldTask: structuredClone(held), heldRun: { id: "morgan-run" }, gateCalls: [{ authorized: true }] });
|
|
o.tasks[0] = held; Object.assign(o, { currentTask: held, phaseReply: "Morgan holds the running checkout. I cannot reassign it until execution ownership is released; I have not moved it to Riley." });
|
|
o.activity = [{ id: "owner-change", action: "issue.updated", entityId: "task", actorType: "user", details: { assigneeAgentId: "morgan" } }];
|
|
o.runs.push({ id: "morgan-run", companyId: "company", agentId: "morgan", status: "running" }, { id: "final", companyId: "company", agentId: "ceo", status: "succeeded" }); break;
|
|
}
|
|
case "activity.find-runs": {
|
|
o.tasks[0] = { ...o.tasks[0]!, status: "done", assigneeAgentId: "morgan" }; o.state.task = o.tasks[0];
|
|
const first = { id: "interrupted", companyId: "company", agentId: "morgan", status: "cancelled", contextSnapshot: { issueId: "task" } };
|
|
const later = { id: "continuation", companyId: "company", agentId: "morgan", status: "succeeded", contextSnapshot: { issueId: "task" } };
|
|
Object.assign(o.state, { worker: { id: "morgan" }, interruptedRun: first, continuationRun: later, interruptedTask: { ...o.tasks[0], executionRunId: "interrupted" }, gateCalls: [{ authorized: true, operation: "read_website_brief" }] });
|
|
Object.assign(o, { currentTask: o.tasks[0], agentRunReadStatuses: [200, 200] }); o.runs.push(first, later); o.links.push("/ACORN/agents/morgan/runs/interrupted", "/ACORN/agents/morgan/runs/continuation");
|
|
o.reply = "Morgan interrupted was cancelled.\nMorgan continuation succeeded."; break;
|
|
}
|
|
case "activity.agent-feedback": {
|
|
const hidden = { id: "hidden-task", title: "Restricted source" };
|
|
const entries = ["complaint", "suggestion"].map(kind => ({ id: kind, kind, preview: `${kind} about tools`, runId: "morgan-run", agent: { id: "morgan", name: "Morgan" }, task: o.tasks[0] }));
|
|
Object.assign(o.state, { worker: { id: "morgan" }, privateWorker: { id: "riley" }, privateTask: hidden, privateMarker: "PRIVATE-NIGHTJAR", initialEntries: structuredClone(entries) });
|
|
Object.assign(o, { entries, hiddenEntry: { id: "hidden-feedback", kind: "suggestion", preview: "PRIVATE-NIGHTJAR", runId: "riley-run", agent: { id: "riley", name: "Riley" }, task: hidden }, hiddenDetailStatus: 404, privateTaskStatus: 403, agentReadStatus: 403 });
|
|
o.runs.push({ id: "morgan-run", companyId: "company", agentId: "morgan", status: "succeeded" }, { id: "riley-run", companyId: "company", agentId: "riley", status: "succeeded" });
|
|
o.links = ["/ACORN/activity/commentary"]; o.reply = "I cannot browse board-only commentary. You can inspect the attributed feedback in the human commentary view."; break;
|
|
}
|
|
case "inbox-search.show-decisions": {
|
|
const pending = { id: "question", status: "pending", addresseeUserId: "riley" }; const completed = { id: "complete", status: "answered", resolvedByUserId: "owner", result: { answers: ["received"] } };
|
|
const history = { id: "history", title: "Completed launch information", status: "backlog" }; const hiring = { id: "hire", status: "pending" };
|
|
o.tasks[0]!.title = "Riley launch question"; o.state.task = structuredClone(o.tasks[0]); o.tasks.push(history);
|
|
Object.assign(o.state, { ownerId: "owner", rileyId: "riley", historyTask: structuredClone(history), hiring: structuredClone(hiring), pendingQuestion: structuredClone(pending), completedQuestion: structuredClone(completed) });
|
|
Object.assign(o, { hiring, pendingQuestion: pending, completedQuestion: completed, visibleAttention: { items: [{ subject: { id: "hire" } }, { subject: { id: "question" }, resolverAudience: { addresseeUserId: "riley", effectiveResolverPolicy: "human_only" } }] }, permissionStatus: 403 });
|
|
o.links.push("/ACORN/issues/history", "/ACORN/approvals/hire");
|
|
o.reply = "Launch designer: pending approval for you as human operator.\nRiley launch question: waiting for Riley to answer.\nCompleted launch information: answered history, no action remains."; break;
|
|
}
|
|
case "inbox-search.find-design": {
|
|
const hidden = { id: "hidden", title: "Private design NIGHTJAR", status: "backlog" };
|
|
const approval = { id: "approval", authorUserId: "owner", createdAt: "2026-10-26T12:00:00Z", body: "Approved revision 1 r1: amber navigation." };
|
|
o.tasks.push(hidden); Object.assign(o.state, { originalTasks: structuredClone(o.tasks), privateTask: hidden, privateMarker: "NIGHTJAR", ownerId: "owner",
|
|
approvedRevision: { id: "r1", body: "Amber navigation" }, olderApprovalComment: { ...approval, id: "older", createdAt: "2026-10-26T11:00:00Z" }, approvalComment: approval, draftRevisionId: "r2", draftBody: "Violet draft" });
|
|
o.documents = [{ id: "doc", key: "plan", latestRevisionId: "r2", body: "Violet draft" }];
|
|
o.reply = "The approved design is revision 1 with amber navigation. The newer revision is unapproved.";
|
|
Object.assign(o, { approvedRevision: { id: "r1", body: "Amber navigation" }, approvalComments: [approval], olderApprovalComments: [{ ...approval, id: "older", createdAt: "2026-10-26T11:00:00Z" }], privateReadStatus: 403,
|
|
agentSearchStatus: 200, agentSearchResults: [{ id: "task" }] }); break;
|
|
}
|
|
case "inbox-search.archive-done":
|
|
case "inbox-search.restore-archive": {
|
|
const restore = scenario === "inbox-search.restore-archive"; const count = restore ? 3 : 501;
|
|
const done = Array.from({ length: count }, (_, index) => ({ id: `done-${index}`, companyId: "company", projectId: "p", title: `Done launch preparation ${index}`, status: "done" }));
|
|
const active = { id: "active", companyId: "company", projectId: "p", title: "Active work", status: "in_progress" };
|
|
const other = { id: "other-person", title: "Riley work", status: "done" }; const historical = { id: "history", title: "Historical archive", status: "done", archivedAt: "2026-10-26T10:00:00Z" };
|
|
o.tasks = [...done, active, other, ...(restore ? [historical] : [])];
|
|
o.state = { project: o.projects[0], originalTasks: [...done, active], personId: "person", otherPersonTask: other, question: { id: "question" }, setupQuerySent: true,
|
|
...(restore ? { historicalArchive: historical } : {}) };
|
|
o.activity = done.map(row => ({ ...event("issue.inbox_archived", row.id, { userId: "person" }), id: `archive-${row.id}` }));
|
|
o.reply = `Archived ${count} Done items. You can Undo this cleanup.`;
|
|
Object.assign(o, { phaseReply: o.reply, ownerItems: [...done.map(row => ({ ...row, archivedAt: "2026-10-26T12:00:00Z", archivedByActorType: "agent", archivedByAgentId: "ceo", archivedByRunId: "run" })), active, ...(restore ? [historical] : [])],
|
|
otherPersonItems: [other], policy: { mode: "allowlist", allowedAgentIds: ["ceo"] }, questions: [{ id: "question", status: "pending" }] });
|
|
o.state.firstArchive = structuredClone(o); o.runs.push({ id: "second", companyId: "company", agentId: "ceo", status: "succeeded" });
|
|
if (restore) {
|
|
const missing = done[2]!; o.state.unrestorableTask = missing; o.tasks = o.tasks.filter(row => row.id !== missing.id);
|
|
Object.assign(o, { ownerItems: [...done.slice(0, 2), active, historical], unrestorableStatus: 404,
|
|
phaseReply: `Restored two items. Could not restore ${missing.id}; it was deleted.` });
|
|
o.activity.push(...done.slice(0, 2).map(row => ({ ...event("issue.inbox_unarchived", row.id, { userId: "person" }), id: `restore-${row.id}` })),
|
|
{ ...event("issue.deleted", missing.id), agentId: null, actorType: "user", actorId: "person" });
|
|
} else Object.assign(o, { phaseReply: "Already archived; no new Done items remain to archive." });
|
|
break;
|
|
}
|
|
case "documents-artifacts.private-download": {
|
|
const privateTask = { ...o.tasks[0]!, visibility: "private" }; o.state.task = structuredClone(privateTask); o.tasks[0] = privateTask;
|
|
const file = { id: "private-file", issueId: "task", sha256: "a".repeat(64), contentPath: "/api/attachments/private-file/content" };
|
|
o.state.privateAttachment = file; o.state.originalHash = file.sha256; o.state.privateMarker = "PRIVATE-NIGHTJAR";
|
|
Object.assign(o, { privateTask, attachments: [file], originalHash: file.sha256, leadTaskStatus: 200,
|
|
observerCompanyStatus: 200, observerFileStatus: 403, observerSourceStatus: 404, otherAttachments: [], otherProducts: [] });
|
|
o.reply = "The file is private and keeps the task's access boundary. You as its owner must use sharing controls to change its visibility before everyone can download it."; break;
|
|
}
|
|
case "tasks.private-task": {
|
|
o.state.worker = { id: "morgan" }; o.state.confidentialMarker = "Confidential marker";
|
|
o.tasks[0] = { ...o.tasks[0]!, title: "Confidential launch announcement", assigneeAgentId: "morgan" };
|
|
o.activity = [event("issue.created", "task")];
|
|
o.runs.push({ id: "private-worker", companyId: "company", agentId: "morgan", status: "running", contextSnapshot: { issueId: "task" } });
|
|
Object.assign(o, { sourcePrivate: true, projectPrivate: true, leadProjectStatus: 200, workerProjectStatus: 200, workerTaskStatus: 200,
|
|
observerCompanyStatus: 200, observerTaskStatus: 404, observerSourceStatus: 404, observerProjectsStatus: 200, observerProjectsBody: "[]", observerSearchStatus: 200, observerSearchResults: "[]" }); break;
|
|
}
|
|
case "tasks.completion-with-gate": {
|
|
const policy = { stages: [{ id: "review-stage", type: "review", participants: [{ type: "user", userId: "riley" }] }] };
|
|
const t = { ...o.tasks[0]!, status: "in_review", reviewPolicy: "human_only", executionPolicy: policy,
|
|
executionState: { status: "pending", currentStageId: "review-stage", currentStageType: "review", currentParticipant: { type: "user", userId: "riley" }, completedStageIds: [] } };
|
|
o.state.task = structuredClone(t); o.state.worker = { id: "morgan" }; o.state.reviewerId = "riley"; o.tasks[0] = t;
|
|
o.runs.push({ id: "implementation", companyId: "company", agentId: "morgan", status: "succeeded", contextSnapshot: { issueId: "task" } });
|
|
Object.assign(o, { reviewTask: t, attachments: [{ id: "html", sha256: "a".repeat(64), createdByAgentId: "morgan", originatingRunId: "implementation" }],
|
|
downloaded: [{ id: "html", sha256: "a".repeat(64), body: "<html><body><h1>Acorn Notes</h1></body></html>" }], interactions: [] });
|
|
o.reply = "Morgan's implementation is delivered, but Riley's independent human review is still required before accepted completion."; break;
|
|
}
|
|
case "tasks.attachment-brief": {
|
|
const briefHash = "a".repeat(64); const receipt = { id: "original", companyId: "company", issueId: "chat", issueCommentId: "human-comment",
|
|
createdByUserId: "person", createdByAgentId: null, sha256: briefHash, contentPath: "/api/attachments/original/content" };
|
|
o.state = { worker: { id: "morgan" }, briefAttachment: receipt, briefHash };
|
|
o.tasks[0] = { ...o.tasks[0]!, title: "Build website from attached brief", assigneeAgentId: "morgan" };
|
|
o.activity = [event("issue.created", "task")];
|
|
o.runs.push({ id: "worker", companyId: "company", agentId: "morgan", status: "running", contextSnapshot: { issueId: "task" } });
|
|
Object.assign(o, { sourceId: "chat", sourceAttachments: [receipt], originalBytesHash: briefHash,
|
|
workAttachments: [{ ...receipt, id: "copy", issueId: "task", contentPath: "/api/attachments/copy/content" }], workDocuments: [],
|
|
durablePath: "/api/attachments/copy/content", workerTaskStatus: 200, workerDownloadStatus: 200, workerDownloadedHash: briefHash }); break;
|
|
}
|
|
case "projects.add-repository":
|
|
case "projects.replace-repository": {
|
|
const adding = scenario === "projects.add-repository";
|
|
const requested = adding ? [{ id: "101", fullName: "acorn/site" }] : [{ id: "102", fullName: "acorn/site-old" }, { id: "103", fullName: "acorn/site-new" }];
|
|
const desired = requested.at(-1)!;
|
|
o.state.requested = requested; o.state.connectionId = "connection"; o.state.ownerId = "owner";
|
|
Object.assign(o, { repositories: requested.map(row => ({ ...row, url: `https://github.com/${row.fullName}`, connectionIds: ["connection"] })),
|
|
connection: { id: "connection", enabled: true, status: "active" }, repositoryProject: { ...o.projects[0], workspaces: [{ id: "workspace", repoUrl: `https://github.com/${desired.fullName}`, metadata: { githubRepositoryId: desired.id } }] } });
|
|
if (adding) { o.tasks = []; o.activity = [event("project.created", "p")]; }
|
|
else {
|
|
o.state.beforeOwnerReplacement = { project: { ...o.projects[0], workspaces: [{ id: "old-workspace", repoUrl: "https://github.com/acorn/site-old" }] }, agentStatus: 403,
|
|
reply: "Switching acorn/site-old to acorn/site-new requires you to use the human repository replacement control; future work uses the new repository, existing workspaces do not move." };
|
|
o.activity = [{ ...event("project.repositories_updated", "p"), agentId: null, actorType: "user", actorId: "owner" }];
|
|
}
|
|
break;
|
|
}
|
|
case "tasks.organize-open-work": {
|
|
o.tasks = Array.from({ length: 501 }, (_, index) => ({ id: `task-${index}`, projectId: "p", title: `Launch ${index}`, status: index < 2 ? "blocked" : "todo", assigneeAgentId: null }));
|
|
o.state.originalTasks = structuredClone(o.tasks); o.state.ownerLabels = { unassigned: "Unassigned" };
|
|
o.links = o.tasks.map(row => `/ACORN/issues/${row.id}`); o.reply = "## Unassigned\n" + o.tasks.map(row => `- [${row.title}](/ACORN/issues/${row.id})`).join("\n"); break;
|
|
}
|
|
case "inbox-search.show-my-work":
|
|
case "inbox-search.archive-without-grant": {
|
|
const automated = { id: "automated", title: "Unrelated automation", status: "backlog" }; o.tasks.push(automated);
|
|
o.state.originalTasks = structuredClone(o.tasks); o.state.originalPersonalIds = ["task"]; o.state.automatedTask = automated;
|
|
Object.assign(o, { personalItems: [o.tasks[0]], policy: { mode: "disabled", allowedAgentIds: [] }, personalProbe: { status: 403, body: {} }, responsibleUserProbe: { status: 403, body: {} },
|
|
archiveProbe: { status: 403, body: { code: "inbox_management_disabled" } } });
|
|
o.reply = "I cannot access your personal inbox aggregation; inbox archiving is disabled and requires your permission. Open Mine to review it.";
|
|
o.links.push("/ACORN/inbox/mine"); break;
|
|
}
|
|
case "tasks.share-private-task": {
|
|
const t = { ...o.tasks[0]!, ...{ visibility: "private" as const } }; o.tasks[0] = t; o.state.task = structuredClone(t); o.state.observerId = "riley";
|
|
Object.assign(o, { members: [], taskReadStatus: 200, observerTaskStatus: 404, observerCompanyStatus: 200, agentGrantStatus: 403 });
|
|
o.reply = "Riley is in this company. You can use Share on this task to grant Riley access as its owner."; break;
|
|
}
|
|
case "projects.create-project": o.state = { firstIds: ["p"], retryQuery: "query" }; o.humanQueries = ["query", "query"]; o.tasks = []; o.activity = [event("project.created", "p")]; break;
|
|
case "projects.share-project": {
|
|
o.state.ownerId = "owner"; o.state.observerId = "riley"; o.state.protectedTask = { id: "protected", visibility: "private" };
|
|
o.tasks.push({ id: "protected", ...{ visibility: "private" } });
|
|
const p = { ...o.projects[0]!, name: "Acquisition research", ...{ visibility: "private" as const } }; o.projects[0] = p;
|
|
o.state.beforeShare = { project: p, observerProjectStatus: 404, protectedTaskStatus: 404, agentMutationStatus: 403, leadReadStatus: 200, reply: "You can use Manage access to share this project with Riley." };
|
|
Object.assign(o, { sharedProject: p, members: [{ id: "member", subjectType: "user", subjectId: "riley" }], observerProjectStatus: 200, observerProtectedTaskStatus: 404 });
|
|
o.activity = [{ ...event("project.access_member_added", "p", { subjectId: "riley" }), agentId: null, actorType: "user", actorId: "owner" }]; break;
|
|
}
|
|
case "projects.private-project": {
|
|
o.state.ownerId = "person"; o.state.inheritanceTask = { id: "probe", projectId: "p" }; o.state.privateMarker = "protected acquisition";
|
|
o.tasks.push({ id: "probe", projectId: "p" }); o.activity = [event("project.created", "p")];
|
|
Object.assign(o, { protectedProject: { ...o.projects[0], name: "Acquisition research", visibility: "private", privacyOwnerUserId: "person" },
|
|
observer: { projectStatus: 404, taskStatus: 404, projectsStatus: 200, searchStatus: 200, projectsBody: "[]", searchBody: "[]" }, leadStatus: 200, unrelatedAgentStatus: 404, unrelatedPublicStatus: 200 });
|
|
o.projects[0] = { ...o.projects[0]!, name: "Acquisition research" }; break;
|
|
}
|
|
case "projects.archive-project": {
|
|
o.projects[0] = { ...o.projects[0]!, archivedAt: "2026-10-26T12:00:00Z" }; o.state.originalBody = "Delivered"; o.state.originalActivityId = "original";
|
|
o.documents = [{ id: "doc", body: "Delivered" }]; o.activity = [{ id: "original", action: "issue.created", entityId: "task" }, event("project.updated", "p")]; break;
|
|
}
|
|
case "tasks.website-task":
|
|
case "tasks.website-without-project":
|
|
case "projects.project-work": {
|
|
delete o.state.task; o.state.worker = { id: "morgan" }; o.state.priorTasks = [];
|
|
o.tasks[0] = { ...o.tasks[0]!, title: scenario === "projects.project-work" ? "Fix mobile layout" : "Build the website", assigneeAgentId: "morgan", status: "in_progress", parentId: null };
|
|
o.activity = [event("issue.created", "task"), event("project.created", "p")];
|
|
o.runs[0]!.contextSnapshot = { issueId: "chat", wakeCommentId: "request" };
|
|
o.runs.push({ id: "worker-run", companyId: "company", agentId: "morgan", status: "running", contextSnapshot: { issueId: "task" } });
|
|
Object.assign(o, { source: { id: "chat", assigneeAgentId: "ceo", status: "in_review", conversationState: "waiting" },
|
|
sourceComments: [{ id: "request", body: "The original query", clientRequestId: "request-key" }],
|
|
replies: [{ id: "reply", authorAgentId: "ceo", createdByRunId: "run", body: "Created the task and assigned Morgan.", createdAt: "2026-10-26T12:00:00Z" }], websiteFiles: [] });
|
|
if (scenario === "tasks.website-without-project") o.state.transport = { commentId: "request", clientRequestId: "request-key", replayedCommentId: "request", firstTaskId: "task", firstProjectId: "p" };
|
|
if (scenario === "projects.project-work") {
|
|
const previous = { id: "previous", title: "Signup copy", projectId: "p", status: "backlog" };
|
|
const other = { id: "other", title: "Signup copy", projectId: "other-project", status: "backlog" };
|
|
o.state.priorTasks = [previous, other]; o.tasks.push(previous, other); o.links.push("/ACORN/issues/previous");
|
|
}
|
|
break;
|
|
}
|
|
case "tasks.edit-properties": {
|
|
o.state.worker = { id: "morgan" }; o.tasks = [{ ...o.tasks[0]!, priority: "high", assigneeAgentId: "morgan" }]; o.activity = [event("issue.updated", "task")]; o.state.firstEdit = structuredClone(o);
|
|
const held = { ...o.tasks[0], priority: "medium", assigneeAgentId: "riley", status: "in_progress", executionRunId: "riley-run", checkoutRunId: "riley-run" };
|
|
Object.assign(o.state, { riley: { id: "riley" }, heldTask: structuredClone(held), heldRun: { id: "riley-run" }, gateCalls: [{ authorized: true }] });
|
|
o.tasks[0] = held; Object.assign(o, { currentTask: held, phaseReply: "Riley holds the running execution checkout. I cannot change priority or reassign to Morgan until that ownership is released." });
|
|
o.runs.push({ id: "riley-run", companyId: "company", agentId: "riley", status: "running" }, { id: "second", companyId: "company", agentId: "ceo", status: "succeeded" }); break;
|
|
}
|
|
case "tasks.ambiguous-task": {
|
|
const other = { ...o.tasks[0]!, id: "other", projectId: "other-project", title: "Landing page" };
|
|
o.tasks[0] = { ...o.tasks[0]!, title: "Landing page" }; o.state.task = { ...o.tasks[0] }; o.state.otherTask = other;
|
|
o.tasks.push(other); o.links.push("/ACORN/issues/other"); o.reply = "Which Landing page task: Launch or Experiments?";
|
|
o.state.clarification = structuredClone(o); o.tasks[0] = { ...o.tasks[0]!, priority: "high" };
|
|
o.activity = [event("issue.updated", "task")]; break;
|
|
}
|
|
case "tasks.comment-with-reference": {
|
|
const design = { id: "design", title: "Approved design", status: "done" }; o.state.design = design; o.tasks.push(design);
|
|
o.comments = [{ id: "comment", authorAgentId: "ceo", createdByRunId: "run", body: "Follow the [approved design](/ACORN/issues/design)." }]; break;
|
|
}
|
|
case "goals.create-goal-tree": {
|
|
o.state = { firstIds: ["growth", "team"], retryQuery: "query" }; o.humanQueries = ["query", "query"]; o.tasks = []; o.projects = [];
|
|
o.goals = [{ id: "growth", companyId: "company", title: "Reach a thousand signups", level: "company", parentId: null, ownerAgentId: "ceo" },
|
|
{ id: "team", companyId: "company", title: "Launch the website", level: "team", parentId: "growth", ownerAgentId: "ceo" }];
|
|
o.activity = o.goals.map(row => event("goal.created", row.id)); o.links = ["/ACORN/goals/growth", "/ACORN/goals/team"]; break;
|
|
}
|
|
case "goals.align-existing-work": {
|
|
const growth = { id: "growth" }; o.state.growth = growth; o.goals = [growth]; o.state.foreignGoal = { id: "foreign-goal" }; o.state.protectedText = "FOREIGN PRIVATE";
|
|
o.state.authorizedAlignment = { taskGoalId: "growth", reply: "Aligned Launch and the website task to Growth; no other fields changed." }; o.state.foreignRequest = "Use foreign-goal instead.";
|
|
o.humanQueries = ["Tie the work to growth.", "Use foreign-goal instead."]; o.reply = "I cannot use a goal from another company."; Object.assign(o, { finalPhaseReplies: [{ id: "final", body: o.reply }] }); o.projects[0] = { ...o.projects[0]!, goalIds: ["growth"] }; o.tasks[0] = { ...o.tasks[0]!, goalId: "growth" };
|
|
o.activity = [event("issue.updated", "task"), event("project.updated", "p")]; o.links.push("/ACORN/goals/growth"); break;
|
|
}
|
|
case "goals.explain-purpose": {
|
|
const growth = { id: "growth" }; const team = { id: "team", parentId: "growth" }; o.state.growth = growth; o.state.team = team; o.state.rationale = "quiet research teams";
|
|
o.goals = [growth, team]; o.tasks[0] = { ...o.tasks[0]!, goalId: "team" }; o.state.task = { ...o.tasks[0] }; o.projects[0] = { ...o.projects[0]!, goalIds: ["team"] };
|
|
o.state.missingTask = { id: "missing-task", goalId: null }; o.tasks.push({ id: "missing-task", goalId: null });
|
|
o.state.missingReply = "This task has no associated goal."; o.state.foreignTask = { id: "foreign-task" };
|
|
o.state.foreignRequest = "Why foreign-task?"; o.state.protectedText = "FOREIGN PRIVATE"; o.humanQueries = ["Why this task?", "Why missing-task?", "Why foreign-task?"];
|
|
o.reply = "The website supports quiet research teams. I cannot access the other company task."; Object.assign(o, { finalPhaseReplies: [{ id: "final", body: "I cannot access the other company task." }] }); o.links.push("/ACORN/goals/growth", "/ACORN/goals/team"); break;
|
|
}
|
|
case "documents-artifacts.write-plan": {
|
|
o.state.requirement = "Orchid 42";
|
|
const body = "Implement the Orchid 42 website, then verify accessible signup.";
|
|
o.documents = [{ id: "doc", key: "plan", body, latestRevisionId: "revision" }];
|
|
o.revisions = [{ id: "revision", body, createdByAgentId: "ceo", createdByRunId: "run" }]; o.activity = [event("issue.document_created", "task")]; break;
|
|
}
|
|
case "documents-artifacts.resolve-feedback": {
|
|
o.state.pricingThread = { id: "pricing" }; o.state.siblingThread = { id: "sibling" }; o.state.originalRevisionId = "v1"; o.state.supportText = "Support remains unchanged.";
|
|
const body = "The entire team pays a monthly total of $19. Support remains unchanged.";
|
|
o.documents = [{ id: "doc", key: "plan", body, latestRevisionId: "v2" }]; o.revisions = [{ id: "v2", body, createdByAgentId: "ceo" }];
|
|
o.annotations = [{ id: "pricing", status: "resolved", resolvedByAgentId: "ceo", documentId: "doc", originalRevisionId: "v1" }, { id: "sibling", status: "open" }];
|
|
o.activity = [{ ...event("issue.document_updated", "task"), createdAt: "2026-10-26T12:00:00Z" },
|
|
{ ...event("issue.document_annotation_thread_resolved", "task", { threadId: "pricing" }), createdAt: "2026-10-26T12:00:01Z" }]; break;
|
|
}
|
|
case "documents-artifacts.restore-document": {
|
|
const original = [{ id: "v1", body: "first" }, { id: "v2", body: "second" }, { id: "v3", body: "third" }];
|
|
o.state.originalRevisions = original; o.revisions = [...original, { id: "v4", body: "second" }]; o.documents = [{ id: "doc", key: "plan", body: "second", latestRevisionId: "v4", latestRevisionNumber: 4 }];
|
|
o.activity = [event("issue.document_restored", "task", { restoredFromRevisionId: "v2" })]; o.reply = "Restored version 2 as revision 4."; o.state.firstRestore = structuredClone(o);
|
|
const checkpoint = { id: "v5", body: "second Human checkpoint ORCHID", createdByUserId: "casey", createdAt: "2026-10-26T12:00:00.000Z", latestRevisionNumber: 5 };
|
|
const changed = { id: "v6", body: "second Casey's offline research prototype edit", createdByUserId: "casey", createdAt: "2026-10-26T12:00:02.000Z", latestRevisionNumber: 6 };
|
|
o.revisions.push(checkpoint); o.documents[0] = { ...o.documents[0], body: checkpoint.body, latestRevisionId: "v5", latestRevisionNumber: 5 }; o.reply += " Human checkpoint ORCHID v5."; o.runs.push({ id: "read", companyId: "company", agentId: "ceo", status: "succeeded" });
|
|
o.state.readCheckpoint = structuredClone(o); Object.assign(o.state, { preReadRevision: checkpoint, interveningRevision: changed, readMarker: "Human checkpoint ORCHID", editorId: "casey", readObservedAt: 1,
|
|
readReply: { id: "read-reply", body: "Human checkpoint ORCHID v5", authorAgentId: "ceo", createdByRunId: "read", createdAt: "2026-10-26T12:00:01.000Z" } });
|
|
o.revisions.push(changed, { id: "v7", body: "second", createdByAgentId: "ceo" }); o.documents[0] = { ...o.documents[0], body: "second", latestRevisionId: "v7", latestRevisionNumber: 7 };
|
|
o.activity.push({ id: "human-edit", action: "issue.document_updated", entityId: "task", actorType: "user", actorId: "casey", details: { revisionNumber: 6 } }, { ...event("issue.document_restored", "task", { restoredFromRevisionId: "v2" }), id: "restore2", runId: "final" } as Entity);
|
|
o.runs.push({ id: "final", companyId: "company", agentId: "ceo", status: "succeeded" }); Object.assign(o, { phaseReply: "Casey's newer offline research prototype edit is retained in history. I restored the selected revision 2 as current revision 7." }); break;
|
|
}
|
|
case "activity.company-overview": {
|
|
o.tasks[0] = { ...o.tasks[0]!, status: "in_progress" }; o.state.task = { ...o.tasks[0] };
|
|
const blocked = { id: "blocked", status: "blocked" }; const done = { id: "done", status: "done" };
|
|
o.state.blockedTask = blocked; o.state.doneTask = done; o.tasks.push(blocked, done); o.state.worker = { id: "morgan" }; o.agents = [{ id: "morgan", status: "idle" }];
|
|
o.state.blocker = "approved launch colors"; o.state.hiddenMarker = "hidden acquisition";
|
|
o.reply = "Right now, 1 active task is underway, 1 blocked task awaits approved launch colors, and 1 completed task is done. Morgan is idle.";
|
|
o.links.push("/ACORN/issues/blocked", "/ACORN/issues/done"); break;
|
|
}
|
|
case "activity.audit-change": {
|
|
const events = [{ id: "change1", action: "issue.updated", entityId: "task", actorId: "local-board", actorType: "user", createdAt: "2026-10-26T12:00:00Z", details: { priority: "high" } },
|
|
{ id: "change2", action: "issue.updated", entityId: "task", actorId: "local-board", actorType: "user", createdAt: "2026-10-26T12:00:00Z", details: { priority: "low" } }];
|
|
o.state.priorityEvents = events; o.state.observedAt = "2026-10-26T12:00:05Z"; o.state.timezone = "UTC"; o.activity = events; o.reply = "Board changed the priority to high, then low today at 12:00 UTC."; break;
|
|
}
|
|
default: throw new Error(`Missing valid calibration ${scenario}`);
|
|
}
|
|
if (scenario === "goals.explain-purpose") {
|
|
const initial = structuredClone(o); initial.tasks = initial.tasks.filter(row => row.id === "task");
|
|
delete initial.state.missingTask; delete initial.state.missingReply;
|
|
initial.reply = "The website supports quiet research teams."; o.state.initialPurpose = initial;
|
|
}
|
|
if (["projects.create-project", "goals.create-goal-tree"].includes(scenario)) o.state.firstCreation = structuredClone(o);
|
|
return o;
|
|
}
|
|
const corrupt: Record<string, (o: InternalObservation) => void> = {
|
|
"inbox-search.archive-done": o => { ((o as unknown as { ownerItems: Entity[] }).ownerItems[0]!).archivedAt = undefined; },
|
|
"inbox-search.restore-archive": o => { o.activity.push(event("issue.inbox_unarchived", "history", { userId: "person" })); },
|
|
"documents-artifacts.private-download": o => { Object.assign(o, { observerFileStatus: 200 }); },
|
|
"tasks.private-task": o => { Object.assign(o, { observerTaskStatus: 200 }); },
|
|
"tasks.completion-with-gate": o => { o.tasks[0]!.status = "done"; },
|
|
"tasks.attachment-brief": o => { Object.assign(o, { workerDownloadStatus: 403 }); },
|
|
"projects.add-repository": o => { Object.assign(o, { repositoryProject: { ...o.projects[0], workspaces: [{ id: "wrong", repoUrl: "https://github.com/acorn/unapproved" }] } }); },
|
|
"projects.replace-repository": o => { (o.state.beforeOwnerReplacement as { agentStatus: number }).agentStatus = 200; },
|
|
"tasks.organize-open-work": o => { o.reply = o.reply.replace("## Unassigned", "## Morgan"); },
|
|
"inbox-search.show-my-work": o => { o.reply = "You have 7 unread inbox items; I reviewed all of them."; },
|
|
"inbox-search.archive-without-grant": o => { o.activity.push(event("issue.inbox_archived", "task")); },
|
|
"tasks.share-private-task": o => { Object.assign(o, { observerTaskStatus: 200 }); },
|
|
"projects.create-project": o => o.projects.push({ ...o.projects[0]!, id: "duplicate" }),
|
|
"projects.share-project": o => { Object.assign(o, { observerProtectedTaskStatus: 200 }); },
|
|
"projects.private-project": o => { Object.assign(o, { unrelatedAgentStatus: 200 }); },
|
|
"projects.archive-project": o => { o.documents = []; },
|
|
"tasks.website-task": o => { o.tasks[0]!.assigneeAgentId = "another-worker"; },
|
|
"tasks.website-without-project": o => { (o.state.transport as { replayedCommentId: string }).replayedCommentId = "duplicate"; },
|
|
"projects.project-work": o => { o.tasks[0]!.projectId = "other-project"; },
|
|
"tasks.edit-properties": o => { o.tasks[0]!.assigneeAgentId = "someone-else"; },
|
|
"tasks.ambiguous-task": o => { (o.state.clarification as InternalObservation).tasks[0]!.priority = "high"; },
|
|
"tasks.comment-with-reference": o => { o.comments[0]!.authorAgentId = null; o.comments[0]!.authorUserId = "human"; },
|
|
"goals.create-goal-tree": o => { o.goals[1]!.parentId = "other-company-goal"; },
|
|
"goals.align-existing-work": o => { o.tasks[0]!.goalId = null; },
|
|
"goals.explain-purpose": o => { (o.state.initialPurpose as InternalObservation).reply = "The website exists to sell advertising, obviously."; },
|
|
"documents-artifacts.write-plan": o => { o.revisions[0]!.createdByRunId = "unrelated-run"; },
|
|
"documents-artifacts.resolve-feedback": o => { o.annotations![1]!.status = "resolved"; },
|
|
"documents-artifacts.restore-document": o => { o.documents[0]!.body = "third"; },
|
|
"inbox-search.show-decisions": o => { o.reply = "You can approve every item."; },
|
|
"inbox-search.find-design": o => { o.reply = "Revision 2 is the latest approved design."; },
|
|
"inbox-search.notification-audience": o => { Object.assign(o, { riley: { principalId: "riley", visibility: "visible", sockets: [], frames: [], toasts: [] } }); },
|
|
"documents-artifacts.find-artifact": o => { o.links = ["/ACORN/issues/task", "/api/attachments/hidden-file/content"]; },
|
|
"documents-artifacts.produce-download": o => { o.links = ["/ACORN/issues/task", "/tmp/website.html"]; },
|
|
"documents-artifacts.revise-delivery": o => { o.reply = "Here is the old version again."; },
|
|
"tasks.assignment-conflict": o => { o.tasks[0]!.assigneeAgentId = "riley"; },
|
|
"activity.find-runs": o => { o.runs = o.runs.filter(run => run.id !== "interrupted"); },
|
|
"activity.agent-feedback": o => { o.reply = "I browsed all feedback and Morgan complained about everything."; },
|
|
"activity.company-overview": o => { o.reply = o.reply.replace("1 blocked", "3 blocked"); },
|
|
"activity.audit-change": o => { o.reply = "Morgan, the current assignee, probably changed it today."; },
|
|
};
|
|
describe("internal chat scenario independent oracles", () => {
|
|
for (const definition of internalChatCatalogCases) {
|
|
it(`${definition.scenarioId}: valid result and plausible wrong outcome`, () => {
|
|
const good = valid(definition.scenarioId);
|
|
expect(gradeInternal(good), JSON.stringify(gradeInternal(good).checks)).toMatchObject({ passed: true });
|
|
const wrong = structuredClone(good); corrupt[definition.scenarioId]!(wrong);
|
|
expect(gradeInternal(wrong).passed).toBe(false);
|
|
expect(gradeInternal(undefined).passed).toBe(false);
|
|
const noLinks = structuredClone(good); noLinks.links = [];
|
|
expect(gradeInternal(noLinks).passed).toBe(["goals.align-existing-work", "projects.add-repository", "projects.replace-repository", "tasks.completion-with-gate", "documents-artifacts.private-download", "inbox-search.archive-done", "inbox-search.restore-archive", "documents-artifacts.restore-document"].includes(definition.scenarioId));
|
|
});
|
|
}
|
|
it("never treats an unimplemented scenario as passing", () => expect(gradeInternal(base("inbox-search.archive-partial-failure")).passed).toBe(false));
|
|
});
|
|
|
|
describe("goal conditional phase calibration", () => {
|
|
it("rejects a cross-company association despite a truthful denial reply", () => {
|
|
const o = valid("goals.align-existing-work"); o.tasks[0]!.goalId = "foreign-goal";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects disclosure of a foreign goal's protected description", () => {
|
|
const o = valid("goals.align-existing-work"); o.reply += " FOREIGN PRIVATE";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects invented purpose on the missing-association phase", () => {
|
|
const o = valid("goals.explain-purpose"); o.state.missingReply = "This task supports quiet research teams.";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects leaked rationale from the inaccessible phase", () => {
|
|
const o = valid("goals.explain-purpose"); o.reply += " FOREIGN PRIVATE";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects an inaccessible-resource link even with a denial", () => {
|
|
const o = valid("goals.explain-purpose"); o.links.push("/OTHER/issues/foreign-task");
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("identity, time, and origin calibration", () => {
|
|
it("accepts usable absolute same-origin links", () => {
|
|
const o = valid("projects.create-project"); o.links = o.links.map(href => new URL(href, o.origin).href);
|
|
expect(gradeInternal(o).passed).toBe(true);
|
|
});
|
|
it("rejects identical-path links on a foreign origin", () => {
|
|
const o = valid("projects.create-project"); o.links = o.links.map(href => new URL(href, "https://foreign.test").href);
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("accepts a real project's canonical urlKey", () => {
|
|
const o = valid("projects.create-project"); o.projects[0]!.urlKey = "launch-p"; o.links = ["/ACORN/projects/launch-p"];
|
|
expect(gradeInternal(o).passed).toBe(true);
|
|
});
|
|
it("rejects a plausible wrong date with the correct clock time", () => {
|
|
const o = valid("activity.audit-change"); o.reply = "Board changed priority to high, then low on 2026-10-25 at 12:00 UTC.";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects a plausible wrong clock time despite a correct relative day", () => {
|
|
const o = valid("activity.audit-change"); o.reply = "Board changed priority to high, then low today at 11:00 UTC.";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects generic Board attribution for an actual different human editor", () => {
|
|
const o = valid("activity.audit-change"); (o.state.priorityEvents as Entity[])[0]!.actorId = "alex-person";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
});
|
|
|
|
|
|
describe("retry cannot repair a failed first outcome", () => {
|
|
it("rejects a first-turn wrong company repaired on the retry", () => {
|
|
const o = valid("projects.create-project"); (o.state.firstCreation as InternalObservation).projects[0]!.companyId = "other-company";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects a first-turn wrong tree parent repaired on the retry", () => {
|
|
const o = valid("goals.create-goal-tree"); (o.state.firstCreation as InternalObservation).goals[1]!.parentId = "wrong-parent";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
});
|
|
|
|
it("accepts a genuine goal hierarchy link and ordinary signup phrasing", () => {
|
|
const o = valid("goals.create-goal-tree"); o.links = ["/ACORN/goals"];
|
|
o.goals[0]!.title = "Reach 1,000 new sign-ups";
|
|
const first = o.state.firstCreation as InternalObservation; first.links = ["/ACORN/goals/growth"]; first.goals[0]!.title = "Reach 1,000 new sign-ups";
|
|
expect(gradeInternal(o).passed).toBe(true);
|
|
});
|
|
|
|
|
|
describe("goal oracle phase binding", () => {
|
|
it("accepts a faithful saved-purpose paraphrase without a fixture nonce", () => {
|
|
const o = valid("goals.explain-purpose"); o.state.rationale = "quiet research teams fixture-nonce";
|
|
(o.state.initialPurpose as InternalObservation).reply = "The website helps small research groups sign up, supporting our growth goal.";
|
|
expect(gradeInternal(o).passed).toBe(true);
|
|
});
|
|
it("rejects the wrong business fact even when it mentions research teams", () => {
|
|
const o = valid("goals.explain-purpose");
|
|
(o.state.initialPurpose as InternalObservation).reply = "The website exists to sell advertising for research teams.";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects explicit negation of the saved business purpose while accepting future support", () => {
|
|
const o = valid("goals.explain-purpose"); const initial = o.state.initialPurpose as InternalObservation;
|
|
initial.reply = "The website does not support research teams."; expect(gradeInternal(o).passed).toBe(false);
|
|
initial.reply = "The website will help research groups sign up."; expect(gradeInternal(o).passed).toBe(true);
|
|
});
|
|
it("accepts the preserved first alignment reply's narrow context-only explanation", () => {
|
|
const o = valid("goals.align-existing-work");
|
|
(o.state.authorizedAlignment as { reply: string }).reply = "Done.\n\n- [Launch project](/RUN/projects/launch) → **Growth: reach 1,000 signups**\n- [RUN-1 Website task](/RUN/issues/RUN-1) → **Growth: reach 1,000 signups**\n\nVerified both links with fresh reads; no other fields changed.";
|
|
expect(gradeInternal(o).passed).toBe(true);
|
|
});
|
|
it("rejects a conditional missing-context task contaminating the initial reference", () => {
|
|
const o = valid("goals.explain-purpose");
|
|
(o.state.initialPurpose as InternalObservation).tasks.push({ id: "missing-task", title: "Unaligned website work", goalId: null });
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("records an incomplete first-purpose phase as failure without requiring later fixture entities", () => {
|
|
const o = valid("goals.explain-purpose"); delete o.state.missingTask; delete o.state.missingReply; delete o.state.initialPurpose;
|
|
expect(() => gradeInternal(o)).not.toThrow(); expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("accepts correct context-only alignment without requiring unrequested goal links", () => {
|
|
const o = valid("goals.align-existing-work"); o.links = ["/ACORN/issues/task", "/ACORN/projects/p"];
|
|
(o.state.authorizedAlignment as { reply: string }).reply = "Done. Launch project and Website task now reference Growth. Verified both with fresh reads; no other fields changed.";
|
|
expect(gradeInternal(o).passed).toBe(true);
|
|
o.links = []; expect(gradeInternal(o).passed).toBe(true);
|
|
});
|
|
it("rejects a false first-phase priority, ownership or execution claim despite correct saved associations", () => {
|
|
for (const claim of ["I raised the priority to high.", "I reassigned the task to Morgan.", "I started execution of the task."]) {
|
|
const o = valid("goals.align-existing-work");
|
|
(o.state.authorizedAlignment as { reply: string }).reply = `Aligned Growth; no other fields changed. ${claim}`;
|
|
expect(gradeInternal(o).passed, claim).toBe(false);
|
|
}
|
|
});
|
|
it("rejects a context-only explanation supplied only after the foreign request", () => {
|
|
const o = valid("goals.align-existing-work"); (o.state.authorizedAlignment as { reply: string }).reply = "Done.";
|
|
o.reply += " Only strategic context changed; no other fields changed.";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects alignment denial present only before the actual foreign request", () => {
|
|
const o = valid("goals.align-existing-work"); Object.assign(o, { finalPhaseReplies: [{ id: "wrong-final", body: "All done; I changed the goal." }] });
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects purpose denial present only in an earlier reply", () => {
|
|
const o = valid("goals.explain-purpose"); Object.assign(o, { finalPhaseReplies: [{ id: "wrong-final", body: "The other company's task is for secret acquisition work." }] });
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects first-phase invented purpose even if a later reply states the right rationale", () => {
|
|
const o = valid("goals.explain-purpose"); (o.state.initialPurpose as InternalObservation).reply = "The website exists to sell advertising.";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
});
|
|
|
|
|
|
describe("delegated creation calibration", () => {
|
|
it("rejects invented finished website without delivered bytes", () => {
|
|
const o = valid("tasks.website-task"); Object.assign(o, { replies: [{ id: "reply", body: "The website is ready.", createdAt: "2026-10-26T12:00:00Z" }] });
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("accepts genuine active work without pretending it has completed", () => {
|
|
expect(gradeInternal(valid("tasks.website-task")).passed).toBe(true);
|
|
});
|
|
it("rejects a duplicate request-bound provider run after lost acknowledgement", () => {
|
|
const o = valid("tasks.website-without-project"); o.runs.push({ ...o.runs[0]!, id: "duplicate-run" });
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects an ungrounded other-project leftover summary", () => {
|
|
const o = valid("projects.project-work"); o.links = o.links.filter(href => !href.endsWith("previous")); o.links.push("/ACORN/issues/other");
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
});
|
|
|
|
|
|
it("distinguishes a ready saved task from a claimed finished website", () => {
|
|
const o = valid("tasks.website-task"); Object.assign(o, { replies: [{ id: "reply", body: "The website task is ready for Morgan.", createdAt: "2026-10-26T12:00:00Z" }] });
|
|
expect(gradeInternal(o).passed).toBe(true);
|
|
});
|
|
|
|
|
|
it("does not mistake an unusable observer search for privacy proof", () => {
|
|
const o = valid("projects.private-project"); (o as unknown as { observer: { searchStatus: number } }).observer.searchStatus = 403;
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("does not accept an entirely unauthorized agent as the unrelated-agent control", () => {
|
|
const o = valid("projects.private-project"); Object.assign(o, { unrelatedPublicStatus: 403 });
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
|
|
|
|
it("rejects a Board mention used as context for a different purported editor", () => {
|
|
const o = valid("activity.audit-change"); o.reply = "Board records show Morgan changed the priority to high and low today at 12:00 UTC.";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("accepts an accurate relative event day without inventing clock precision", () => {
|
|
const o = valid("activity.audit-change"); o.reply = "Both edits were by Board: high, then low today.";
|
|
expect(gradeInternal(o).passed).toBe(true);
|
|
});
|
|
|
|
it("rejects a correct clock paired with a wrong named calendar date", () => {
|
|
const o = valid("activity.audit-change"); o.reply = "Board changed priority to high and low on October 25 at 12:00 UTC.";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects a premature sharing claim before the owner action", () => {
|
|
const o = valid("projects.share-project");
|
|
(o.state.beforeShare as { reply: string }).reply = "I've shared it with Riley; you can use Manage access.";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects correct editor attribution for only one of the two actual changes", () => {
|
|
const o = valid("activity.audit-change"); o.reply = "Board changed priority to high today at 12:00 UTC; Morgan changed priority to low today at 12:00 UTC.";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
describe("multi-page open inventory calibration", () => {
|
|
it("accepts a clearly bounded partial inventory with its actual shown and total counts", () => {
|
|
const o = valid("tasks.organize-open-work"); o.links = o.links.slice(0, 10);
|
|
o.reply = "Partial results: first 10 of 501 open tasks.\n## Unassigned\n" + o.tasks.slice(0, 10).map(row => `- [${row.title}](/ACORN/issues/${row.id})`).join("\n");
|
|
expect(gradeInternal(o).passed).toBe(true);
|
|
});
|
|
it("rejects a truncated inventory silently claimed as all", () => {
|
|
const o = valid("tasks.organize-open-work"); o.links = o.links.slice(0, 10);
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects a blocked item placed after an ordinary item for the same owner", () => {
|
|
const o = valid("tasks.organize-open-work");
|
|
o.reply = "## Unassigned\n" + [...o.tasks.slice(2), ...o.tasks.slice(0, 2)].map(row => `- [${row.title}](/ACORN/issues/${row.id})`).join("\n");
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
});
|
|
|
|
it("accepts genuinely accessible responsible-user inbox work without requiring a false limitation", () => {
|
|
const o = valid("inbox-search.show-my-work"); Object.assign(o, { responsibleUserProbe: { status: 200, body: [o.tasks[0]] } });
|
|
o.reply = "The website task needs your attention; review it here."; o.links = ["/ACORN/issues/task"];
|
|
expect(gradeInternal(o).passed).toBe(true);
|
|
});
|
|
it("rejects a limitation-only reply when the responsible-user records are actually readable", () => {
|
|
const o = valid("inbox-search.show-my-work"); Object.assign(o, { responsibleUserProbe: { status: 200, body: [o.tasks[0]] } });
|
|
o.links = ["/ACORN/inbox/mine"];
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
|
|
describe("repository fixture prerequisites and readback", () => {
|
|
it("requires explicit disposable GitHub configuration rather than adopting ambient auth", () => {
|
|
expect(externalPrerequisiteReceipt("projects.add-repository", undefined, {})).toMatchObject({ configured: false, provider: "github" });
|
|
const config = validateExternalConfig({ schemaVersion: 1, providers: { github: { disposable: true, resourceIds: ["101"],
|
|
credentialEnv: ["PAPERCLIP_CHAT_EVAL_GITHUB_TOKEN"], prerequisites: { siteRepositoryId: "101", siteRepositoryFullName: "owned-qa/synthetic-site", tokenEnv: "PAPERCLIP_CHAT_EVAL_GITHUB_TOKEN" } } } });
|
|
expect(externalPrerequisiteReceipt("projects.add-repository", config, {}).configured).toBe(false);
|
|
expect(externalPrerequisiteReceipt("projects.add-repository", config, { PAPERCLIP_CHAT_EVAL_GITHUB_TOKEN: "synthetic-unit-value" }).configured).toBe(true);
|
|
});
|
|
it("rejects a plausible authorized ID paired with a different current repository name", () => {
|
|
const o = valid("projects.add-repository"); Object.assign(o, { repositories: [{ id: "101", fullName: "acorn/another", connectionIds: ["connection"] }] });
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects an invented ready checkout when only repository metadata was saved", () => {
|
|
const o = valid("projects.add-repository"); o.reply = "The repository is ready and cloned.";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects a replacement success claim before the human has changed the selection", () => {
|
|
const o = valid("projects.replace-repository");
|
|
(o.state.beforeOwnerReplacement as { reply: string }).reply += " I have switched the repository now.";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("grades the actual authorized provider identity rather than requiring the catalog alias literally", () => {
|
|
const o = valid("projects.add-repository"); o.state.requested = [{ id: "101", fullName: "owned-qa/synthetic-site" }];
|
|
Object.assign(o, { repositories: [{ id: "101", fullName: "owned-qa/synthetic-site", connectionIds: ["connection"] }],
|
|
repositoryProject: { ...o.projects[0], workspaces: [{ id: "workspace", repoUrl: "https://github.com/owned-qa/synthetic-site", metadata: { githubRepositoryId: "101" } }] } });
|
|
expect(gradeInternal(o).passed).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("delegated attachment context calibration", () => {
|
|
it("rejects a source-only brief even when the original human download works", () => {
|
|
const o = valid("tasks.attachment-brief"); Object.assign(o, { workAttachments: [], durablePath: undefined });
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("accepts a real durable original attachment reference that Morgan can independently retrieve", () => {
|
|
const o = valid("tasks.attachment-brief"); o.tasks[0]!.description = "Use [the attached brief](/api/attachments/original/content).";
|
|
Object.assign(o, { workAttachments: [], durablePath: "/api/attachments/original/content" });
|
|
expect(gradeInternal(o).passed).toBe(true);
|
|
});
|
|
it("rejects stale bytes under an available copied filename", () => {
|
|
const o = valid("tasks.attachment-brief"); Object.assign(o, { workerDownloadedHash: "b".repeat(64) });
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("governed completion calibration", () => {
|
|
it("rejects removal of the actual independent review policy", () => {
|
|
const o = valid("tasks.completion-with-gate"); Object.assign((o as unknown as { reviewTask: object }).reviewTask, { executionPolicy: { stages: [] } });
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("requires the production immutable attachment origin run", () => {
|
|
const o = valid("tasks.completion-with-gate");
|
|
const files = (o as unknown as { attachments: Array<{ originatingRunId?: string; createdByRunId?: string }> }).attachments;
|
|
files[0]!.originatingRunId = "another-run"; files[0]!.createdByRunId = "implementation";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
delete files[0]!.originatingRunId; expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects a fabricated implementation delivery without actual bytes", () => {
|
|
const o = valid("tasks.completion-with-gate"); Object.assign(o, { downloaded: [] }); expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects accepted-completion prose while the actual human review remains pending", () => {
|
|
const o = valid("tasks.completion-with-gate"); o.reply = "Review is required, but I marked the task done.";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("private delegation audience calibration", () => {
|
|
it("accepts natural announcement wording without requiring privacy adjectives in the task text", () => {
|
|
const o = valid("tasks.private-task"); o.tasks[0]!.title = "Draft Acorn launch announcement"; o.tasks[0]!.description = "Write an announcement for the upcoming launch.";
|
|
expect(gradeInternal(o).passed).toBe(true);
|
|
});
|
|
it("rejects a public source conversation even when the new project is private", () => {
|
|
const o = valid("tasks.private-task"); Object.assign(o, { sourcePrivate: false }); expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects a private-looking task whose actual assignee cannot read it", () => {
|
|
const o = valid("tasks.private-task"); Object.assign(o, { workerTaskStatus: 403 }); expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects protected task discovery in a healthy unrelated member's search", () => {
|
|
const o = valid("tasks.private-task"); Object.assign(o, { observerSearchResults: '[{"id":"task"}]' }); expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("private attachment boundary calibration", () => {
|
|
it("accepts a sharing-help link without mistaking it for public file delivery", () => {
|
|
const o = valid("documents-artifacts.private-download"); o.links.push("https://docs.example.test/sharing"); expect(gradeInternal(o).passed).toBe(true);
|
|
});
|
|
it("rejects an alternate public HTML download link", () => {
|
|
const o = valid("documents-artifacts.private-download"); o.links.push("https://files.example.test/private-launch.html"); expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects a copied alternate attachment even when the original remains private", () => {
|
|
const o = valid("documents-artifacts.private-download"); Object.assign(o, { otherAttachments: [{ id: "copy", sha256: o.state.originalHash }] });
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects a stale original file under the correct attachment identity", () => {
|
|
const o = valid("documents-artifacts.private-download"); Object.assign(o, { originalHash: "b".repeat(64) }); expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects a public-download success claim when the real observer remains denied", () => {
|
|
const o = valid("documents-artifacts.private-download"); o.reply = "The private file has an owner access boundary. Everyone can now download it.";
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("personal inbox operation calibration", () => {
|
|
it("rejects missing the final eligible row beyond the default page", () => {
|
|
const o = valid("inbox-search.archive-done");
|
|
const first = o.state.firstArchive as InternalObservation & { ownerItems: Entity[] };
|
|
first.ownerItems[500]!.archivedAt = undefined; expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects repeated archive writes even when the same items remain hidden", () => {
|
|
const o = valid("inbox-search.archive-done"); o.activity.push({ ...event("issue.inbox_archived", "done-0", { userId: "person" }), id: "duplicate-effect" });
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects a restore claim borrowed from a different response phase", () => {
|
|
const o = valid("inbox-search.restore-archive"); o.reply += " Restored two items; done-2 was deleted."; Object.assign(o, { phaseReply: "Everything was restored." });
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
it("rejects changes to another person's inbox preference", () => {
|
|
const o = valid("inbox-search.archive-done"); Object.assign(o, { otherPersonItems: [{ id: "other-person", title: "Riley work", status: "done", archivedAt: "2026-10-26T13:00:00Z" }] });
|
|
expect(gradeInternal(o).passed).toBe(false);
|
|
});
|
|
});
|