mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-17 10:06:42 +02:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Task questions remain saved so a person can answer them later. > - The composer moves an old question into history after a newer human message. > - Native completion still treated every pending question as a required response. > - This caused agents to demand an old answer after the person moved work forward. > - This pull request shares the historical-question rule across context and task execution. > - Agents can finish verified work while the original question remains answerable. ## Linked Issues or Issue Description Refs #15229, Refs #14613, Refs #13130. **What happened?** An agent repeatedly asked a person to answer a question that had moved into feed history. Completion feedback explicitly told the agent to request a response. The saved pending row also blocked task completion. **Expected behavior** A question before newer human direction remains answerable in the feed. Its pending state alone must not require another reminder or stop completed work. A new input blocker, an approval, or a configured review stage must keep its gate. **Steps to reproduce** 1. Let a task agent create an ordinary question. 2. Dismiss the question and send a newer task message. 3. Let the agent finish the requested work and submit its completion report. 4. Observe a demand to answer the old question and a retained completion gate. ## What Changed - Add one company-scoped predicate for historical questions. Only later human comments count. Exclude agent attribution, run attribution, system notices, and untrusted source data. - Apply the predicate to completion feedback, native waits, finalization, commit validation, retry validation, blocked routing, and successful-run handoff. - Include question classification and guidance in heartbeat context and both native task-context tools. Add the guidance to fresh and resumed task prompts. - Replace automatic reminders for current ordinary questions with instructions to assess the real blocker, continue independent work, and withdraw obsolete questions through the existing API. - Preserve historical question rows during completion while cancelling their live native source runs through the existing post-commit and recovery paths. Let an authorized human answer them after completion without reopening work or creating a response wake. Preserve cancellation, current-input, approval, permission, credential, connection, and review gates. Add no dismissal storage or migration. - Document the rule in the execution contract and agent skill. Refresh generated capability source anchors. Add database-backed status, context, attribution, and governance regression tests. ## Verification - `pnpm build` passed. The server rebuild also passed after the lifecycle fix. Generated capability contract and inventory checks passed after the agent documentation update. - `pnpm -r typecheck` passed. Final `pnpm --filter @paperclipai/server exec tsc --noEmit` also passed after the last test additions. - Lifecycle and interaction regressions passed: 224 tests in 3 suites. Context and prompt tests also passed. Final historical-question cases passed (33 tests), native cancellation/recovery cases passed (6 tests), and the existing interaction/confirmation suites passed (72 tests). The full local `pnpm test:run` was attempted and stopped after more than two hours with unrelated fixture/hook timeout failures; it did not pass. All 52 successful GitHub checks are green on the latest commit, including the complete test matrix; no checks are pending or failing. Greptile is 5/5 and both review threads are resolved. - Regression cases cover the old-question/new-human-message sequence, final task status, answering after completion with no wake, live-run cancellation and crash recovery, current input blockers, both task-context tools, API context, timestamp precision, attribution boundaries, and protected gates. ## Risks - A later human task message makes an earlier ordinary question historical even if its input is still missing. The agent must identify the current blocker and ask only for information that still prevents work. - Browser dismissal remains a local preference. Dismissal without a later human message is not recorded by this change. - No schema change or data migration. Completion retains ordinary historical questions; cancellation still expires them. A completed task accepts historical answers only from an authorized human and creates no response-delivery outbox row. Governed requests retain their gates. ## Model Used OpenAI Codex, GPT-6, with repository editing, code execution, and browser diagnostics. The exact deployment model ID and context-window size are not exposed in this session. ## 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 - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
268 lines
22 KiB
TypeScript
268 lines
22 KiB
TypeScript
import { randomUUID } from "node:crypto";
|
|
import { eq, sql } from "drizzle-orm";
|
|
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
|
import { activityLog, agents, authUsers, companies, companyMemberships, createDb, documents, documentRevisions, heartbeatRuns,
|
|
issueComments, issueDocuments, issues, issueThreadInteractions } from "@paperclipai/db";
|
|
import { getEmbeddedPostgresTestSupport, startEmbeddedPostgresTestDatabase } from "./helpers/embedded-postgres.js";
|
|
import { resolveConfirmationFromComment } from "../services/confirmation-comment-resolution.js";
|
|
import { issueThreadInteractionService } from "../services/issue-thread-interactions.js";
|
|
import { pendingNativeGovernance } from "../services/native-runtime/native-run-finalizer.js";
|
|
import { getConversationConfirmationContext } from "../services/conversation-confirmation-context.js";
|
|
|
|
const { resolvedTelemetry } = vi.hoisted(() => ({ resolvedTelemetry: vi.fn() }));
|
|
vi.mock("@paperclipai/shared/telemetry", async importOriginal => ({
|
|
...await importOriginal<Record<string, unknown>>(), trackInteractionResolved: resolvedTelemetry, trackInteractionCreated: vi.fn(),
|
|
}));
|
|
vi.mock("../telemetry.js", async importOriginal => ({
|
|
...await importOriginal<Record<string, unknown>>(), getTelemetryClient: () => ({}),
|
|
}));
|
|
|
|
const support = await getEmbeddedPostgresTestSupport();
|
|
(support.supported ? describe : describe.skip)("conversational confirmation resolution", () => {
|
|
let temporary: Awaited<ReturnType<typeof startEmbeddedPostgresTestDatabase>>;
|
|
let db: ReturnType<typeof createDb>;
|
|
beforeAll(async () => { temporary = await startEmbeddedPostgresTestDatabase("confirmation-replies-"); db = createDb(temporary.connectionString); }, 30_000);
|
|
afterAll(async () => { await temporary?.cleanup(); });
|
|
async function seed(checkbox = false, conversation = false) {
|
|
const companyId = randomUUID(), agentId = randomUUID(), issueId = randomUUID(), runId = randomUUID();
|
|
await db.insert(companies).values({ id: companyId, name: "Replies", issuePrefix: companyId.slice(0, 8) });
|
|
if (conversation) {
|
|
await db.insert(authUsers).values({ id: "operator", name: "Operator", email: "operator@example.test", createdAt: new Date(), updatedAt: new Date() }).onConflictDoNothing();
|
|
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "operator", status: "active", membershipRole: "member" });
|
|
}
|
|
await db.insert(agents).values({ id: agentId, companyId, name: "Planner", adapterType: "paperclip_runner" });
|
|
const [issue] = await db.insert(issues).values({ id: issueId, companyId, title: "Proposal", status: "in_progress", assigneeAgentId: agentId,
|
|
...(conversation ? { conversationAgentId: agentId, conversationUserId: "operator", conversationState: "active", conversationSessionGeneration: 1 } : {}) }).returning();
|
|
await db.insert(heartbeatRuns).values({ id: runId, companyId, agentId, nativeIssueId: issueId, status: "running", runtimeMode: "native", contextSnapshot: { issueId, conversationSessionGeneration: 1 } });
|
|
await db.update(issues).set({ executionRunId: runId }).where(eq(issues.id, issueId));
|
|
const svc = issueThreadInteractionService(db);
|
|
const card = await svc.create(issue, checkbox ? {
|
|
kind: "request_checkbox_confirmation", payload: { version: 1, prompt: "Approve selected work?", options: [{ id: "note", label: "Welcome note" }, { id: "poster", label: "Poster" }], minSelected: 1, defaultSelectedOptionIds: ["poster"] },
|
|
} : { kind: "request_confirmation", payload: { version: 1, prompt: "Approve the welcome note?" } }, { agentId });
|
|
const [comment] = await db.insert(issueComments).values({ companyId, issueId, authorUserId: "operator", authorType: "user", body: "Yes, write the welcome note." }).returning();
|
|
const args = { companyId, issueId, interactionId: card.id, actor: { agentId, runId }, input: { commentId: comment.id, decision: "accept" as const, ...(checkbox ? { selectedOptionIds: ["note"] } : {}) } };
|
|
return { args, card, issue, comment, svc, companyId, issueId, agentId, runId };
|
|
}
|
|
const readCard = (id: string) => db.select().from(issueThreadInteractions).where(eq(issueThreadInteractions.id, id)).then(rows => rows[0]!);
|
|
const audit = (id: string) => db.select().from(activityLog).where(eq(activityLog.entityId, id)).then(rows => rows.filter(row => row.details?.source === "conversation_reply"));
|
|
|
|
it.each(["ask_user_questions", "request_confirmation", "request_checkbox_confirmation"])("an older chat %s stays pending without gating a later reply", async kind => {
|
|
const f = await seed(false, true);
|
|
await db.update(issueThreadInteractions).set({ kind, sourceRunId: null }).where(eq(issueThreadInteractions.id, f.card.id));
|
|
expect(await pendingNativeGovernance({ db, ...f, executionState: null })).toBeNull();
|
|
expect((await readCard(f.card.id)).status).toBe("pending");
|
|
await db.update(issueThreadInteractions).set({ sourceRunId: f.runId }).where(eq(issueThreadInteractions.id, f.card.id));
|
|
// A later human message makes ordinary questions historical even when
|
|
// they came from the current run; confirmations still require a decision.
|
|
expect(await pendingNativeGovernance({ db, ...f, executionState: null }))
|
|
.toEqual(kind === "ask_user_questions" ? null : { kind: "interaction", id: f.card.id });
|
|
});
|
|
|
|
it.each(["ordinary-task", "human_only", "toolAction", "secretProposal", "connectionAuthorization"])("preserves the existing %s completion gate", async kind => {
|
|
const f = await seed(false, kind !== "ordinary-task");
|
|
if (kind === "human_only") await db.update(issueThreadInteractions).set({ effectiveResolverPolicy: "human_only" }).where(eq(issueThreadInteractions.id, f.card.id));
|
|
else if (kind !== "ordinary-task") await db.update(issueThreadInteractions).set({ payload: { ...f.card.payload, [kind]: {} } }).where(eq(issueThreadInteractions.id, f.card.id));
|
|
expect(await pendingNativeGovernance({ db, ...f, executionState: null })).toEqual({ kind: "interaction", id: f.card.id });
|
|
expect(await pendingNativeGovernance({ db, ...f, executionState: { status: "pending" } })).toEqual({ kind: "execution_stage", id: f.runId });
|
|
expect(await pendingNativeGovernance({ db, ...f, companyId: randomUUID(), executionState: null })).toBeNull();
|
|
});
|
|
|
|
it.each([true, false])("preserves historical questions only in agent chat (conversation=%s)", async conversation => {
|
|
const f = await seed(false, conversation);
|
|
const question = (prompt: string) => ({ kind: "ask_user_questions" as const, payload: { version: 1 as const,
|
|
supersedeOnUserComment: true, questions: [{ id: "color", prompt, selectionMode: "single" as const, required: true,
|
|
options: [{ id: "blue", label: "Blue" }, { id: "green", label: "Green" }] }] } });
|
|
const first = await f.svc.create(f.issue, question("Which color?"), { agentId: f.agentId });
|
|
await f.svc.expireRequestConfirmationsSupersededByComment(f.issue,
|
|
{ id: f.comment.id, authorUserId: "operator", createdAt: new Date(Date.now() + 1000) }, { userId: "operator" });
|
|
expect((await readCard(first.id)).status).toBe(conversation ? "pending" : "expired");
|
|
const second = await f.svc.create(f.issue, question("Which shade?"), { agentId: f.agentId });
|
|
await f.svc.create(f.issue, question("Which finish?"), { agentId: f.agentId });
|
|
expect((await readCard(second.id)).status).toBe(conversation ? "pending" : "expired");
|
|
if (conversation) {
|
|
const answered = await f.svc.answerQuestions(f.issue, first.id, { answers: [{ questionId: "color", optionIds: ["blue"] }] }, { userId: "operator" });
|
|
expect(answered).toMatchObject({ status: "answered", result: { answers: [{ questionId: "color", optionIds: ["blue"] }] } });
|
|
expect((await readCard(second.id)).status).toBe("pending");
|
|
await expect(f.svc.answerQuestions(f.issue, first.id, { answers: [{ questionId: "color", optionIds: ["green"] }] }, { userId: "operator" })).rejects.toThrow();
|
|
}
|
|
});
|
|
|
|
it("supplies actual pending card identities and explicit choices, then refreshes after resolution", async () => {
|
|
const f = await seed(true, true);
|
|
const snapshot = await getConversationConfirmationContext({ db, ...f });
|
|
expect(snapshot).toMatchObject({ truncated: false, cards: [{ id: f.card.id, status: "pending", resolverPolicy: "anyone",
|
|
options: [{ id: "note", label: "Welcome note" }, { id: "poster", label: "Poster" }] }] });
|
|
expect(JSON.stringify(snapshot)).not.toContain("defaultSelectedOptionIds");
|
|
await resolveConfirmationFromComment(db, f.args);
|
|
expect(await getConversationConfirmationContext({ db, ...f })).toEqual({ truncated: false, cards: [] });
|
|
});
|
|
it.each(["ordinary-task", "other-company", "other-agent"])("does not supply confirmation context for %s", async kind => {
|
|
const f = await seed(false, kind !== "ordinary-task");
|
|
expect(await getConversationConfirmationContext({ db, ...f,
|
|
...(kind === "other-company" ? { companyId: randomUUID() } : {}),
|
|
...(kind === "other-agent" ? { agentId: randomUUID() } : {}),
|
|
})).toBeNull();
|
|
});
|
|
it.each(["toolAction", "secretProposal", "connectionAuthorization", "questions", "expired"])("excludes %s from ordinary confirmation context", async kind => {
|
|
const f = await seed(false, true);
|
|
await db.update(issueThreadInteractions).set(kind === "questions" ? { kind: "ask_user_questions" }
|
|
: kind === "expired" ? { status: "expired" }
|
|
: { payload: { ...f.card.payload, [kind]: { value: "must-not-leak" } } }).where(eq(issueThreadInteractions.id, f.card.id));
|
|
expect(await getConversationConfirmationContext({ db, ...f })).toEqual({ truncated: false, cards: [] });
|
|
});
|
|
it("excludes prior-session cards and preserves the current card's human-only policy", async () => {
|
|
const f = await seed(false, true);
|
|
const boundaryAt = new Date(Date.now() + 1000);
|
|
const [boundary] = await db.insert(issueComments).values({ companyId: f.companyId, issueId: f.issueId,
|
|
authorType: "user", authorUserId: "operator", body: "/new", createdAt: boundaryAt }).returning();
|
|
await db.update(issues).set({ conversationBoundaryCommentId: boundary.id }).where(eq(issues.id, f.issueId));
|
|
const [current] = await db.insert(issueThreadInteractions).values({ companyId: f.companyId, issueId: f.issueId,
|
|
kind: "request_confirmation", effectiveResolverPolicy: "human_only", payload: { version: 1, prompt: "Current proposal" },
|
|
createdAt: new Date(boundaryAt.getTime() + 1000) }).returning();
|
|
expect(await getConversationConfirmationContext({ db, ...f })).toMatchObject({ cards: [{ id: current.id, resolverPolicy: "human_only" }] });
|
|
});
|
|
it("bounds card and proposal data and declares truncation instead of hiding it", async () => {
|
|
const f = await seed(false, true);
|
|
await db.update(issueThreadInteractions).set({ payload: { version: 1, prompt: "x".repeat(2500) } }).where(eq(issueThreadInteractions.id, f.card.id));
|
|
await db.insert(issueThreadInteractions).values(Array.from({ length: 13 }, () => ({ companyId: f.companyId, issueId: f.issueId,
|
|
kind: "request_confirmation", payload: { version: 1 as const, prompt: "Another proposal" }, createdAt: new Date(Date.now() + 1000) })));
|
|
const snapshot = await getConversationConfirmationContext({ db, ...f });
|
|
expect(snapshot?.truncated).toBe(true);
|
|
expect(snapshot?.cards).toHaveLength(12);
|
|
expect(snapshot?.cards[0]?.prompt).toHaveLength(2000);
|
|
expect(snapshot?.cards[0]?.promptTruncated).toBe(true);
|
|
});
|
|
|
|
it.each([false, true])("persists acceptance, explicit selection and source-message audit (checkbox=%s)", async checkbox => {
|
|
const f = await seed(checkbox, true);
|
|
const answer = await resolveConfirmationFromComment(db, f.args);
|
|
expect(answer).toMatchObject({ deduplicated: false, interaction: { status: "accepted", resolvedByAgentId: f.agentId, resolvedByRunId: f.runId, resolvedByUserId: null, result: { outcome: "accepted", commentId: f.comment.id, ...(checkbox ? { selectedOptionIds: ["note"] } : {}) } } });
|
|
expect(await audit(f.issueId)).toMatchObject([{ action: "issue.thread_interaction_accepted", details: { responseCommentId: f.comment.id, responseUserId: "operator" } }]);
|
|
});
|
|
it.each(["accept", "reject"] as const)("does not emit a %s resolution when the provenance audit rolls back", async decision => {
|
|
const f = await seed();
|
|
await db.execute(sql.raw(`CREATE FUNCTION fail_confirmation_audit() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN IF NEW.entity_id = '${f.issueId}' THEN RAISE EXCEPTION 'audit write failed'; END IF; RETURN NEW; END $$`));
|
|
await db.execute(sql.raw("CREATE TRIGGER fail_confirmation_audit BEFORE INSERT ON activity_log FOR EACH ROW EXECUTE FUNCTION fail_confirmation_audit()"));
|
|
resolvedTelemetry.mockClear();
|
|
try {
|
|
await expect(resolveConfirmationFromComment(db, { ...f.args, input: { commentId: f.comment.id, decision } })).rejects.toThrow();
|
|
expect((await readCard(f.card.id)).status).toBe("pending");
|
|
expect(await audit(f.issueId)).toHaveLength(0);
|
|
expect(resolvedTelemetry).not.toHaveBeenCalled();
|
|
} finally {
|
|
await db.execute(sql.raw("DROP TRIGGER fail_confirmation_audit ON activity_log"));
|
|
await db.execute(sql.raw("DROP FUNCTION fail_confirmation_audit()"));
|
|
}
|
|
await resolveConfirmationFromComment(db, { ...f.args, input: { commentId: f.comment.id, decision } });
|
|
expect(resolvedTelemetry).toHaveBeenCalledExactlyOnceWith(expect.anything(), expect.objectContaining({ status: decision === "accept" ? "accepted" : "rejected" }));
|
|
await resolveConfirmationFromComment(db, { ...f.args, input: { commentId: f.comment.id, decision } });
|
|
expect(resolvedTelemetry).toHaveBeenCalledTimes(1);
|
|
});
|
|
it("records refusal and its reason on the card", async () => {
|
|
const f = await seed();
|
|
const answer = await resolveConfirmationFromComment(db, { ...f.args, input: { commentId: f.comment.id, decision: "reject", reason: "Not needed" } });
|
|
expect(answer.interaction).toMatchObject({ status: "rejected", result: { outcome: "rejected", reason: "Not needed", commentId: f.comment.id } });
|
|
});
|
|
it("serializes simultaneous retries into one decision and one audit record", async () => {
|
|
const f = await seed(true);
|
|
const answers = await Promise.all([resolveConfirmationFromComment(db, f.args), resolveConfirmationFromComment(db, f.args)]);
|
|
expect(answers.map(x => x.deduplicated).sort()).toEqual([false, true]);
|
|
expect(await audit(f.issueId)).toHaveLength(1);
|
|
const before = await readCard(f.card.id);
|
|
await resolveConfirmationFromComment(db, f.args);
|
|
expect(await readCard(f.card.id)).toEqual(before);
|
|
});
|
|
it("does not rewrite an opposite decision or a different checkbox selection", async () => {
|
|
const f = await seed(true);
|
|
await resolveConfirmationFromComment(db, f.args);
|
|
await expect(resolveConfirmationFromComment(db, { ...f.args, input: { commentId: f.comment.id, decision: "reject" } })).rejects.toThrow("different decision");
|
|
await expect(resolveConfirmationFromComment(db, { ...f.args, input: { ...f.args.input, selectedOptionIds: ["poster"] } })).rejects.toThrow("different decision");
|
|
expect((await readCard(f.card.id)).result).toMatchObject({ selectedOptionIds: ["note"] });
|
|
});
|
|
it.each(["deleted", "agent", "system", "agent-attributed", "quarantined", "before-card", "other-task", "other-company", "newer-message", "wrong-user", "reset-command"])("rejects %s answer evidence without effects", async kind => {
|
|
const f = await seed(false, true);
|
|
const change: Record<string, unknown> = kind === "deleted" ? { deletedAt: new Date() }
|
|
: kind === "agent" ? { authorType: "agent", authorAgentId: f.agentId }
|
|
: kind === "system" ? { authorType: "system" }
|
|
: kind === "agent-attributed" ? { createdByRunId: f.runId }
|
|
: kind === "quarantined" ? { sourceTrust: { preset: "low_trust", disposition: "quarantined" } }
|
|
: kind === "before-card" ? { createdAt: new Date(0) }
|
|
: kind === "wrong-user" ? { authorUserId: "somebody-else" }
|
|
: kind === "reset-command" ? { body: "/new" } : {};
|
|
if (kind === "other-task") {
|
|
const [otherIssue] = await db.insert(issues).values({ companyId: f.companyId, title: "Other proposal", status: "in_progress" }).returning();
|
|
const [otherComment] = await db.insert(issueComments).values({ companyId: f.companyId, issueId: otherIssue.id, authorUserId: "operator", authorType: "user", body: "Yes, go ahead." }).returning();
|
|
f.args.input.commentId = otherComment.id;
|
|
} else if (kind === "other-company") {
|
|
const other = await seed();
|
|
f.args.input.commentId = other.comment.id;
|
|
} else if (kind === "newer-message") {
|
|
await db.insert(issueComments).values({ companyId: f.companyId, issueId: f.issueId, authorUserId: "operator", authorType: "user", body: "Wait, do not proceed.", createdAt: new Date(Date.now() + 1000) });
|
|
} else await db.update(issueComments).set(change).where(eq(issueComments.id, f.comment.id));
|
|
await expect(resolveConfirmationFromComment(db, f.args)).rejects.toThrow();
|
|
expect((await readCard(f.card.id)).status).toBe("pending");
|
|
expect(await audit(f.issueId)).toHaveLength(0);
|
|
});
|
|
it.each(["cancelled", "finished", "lost-owner", "wrong-run-task", "reset-generation", "old-card"])("fences %s execution", async kind => {
|
|
const f = await seed(false, true);
|
|
if (kind === "cancelled" || kind === "finished") await db.update(heartbeatRuns).set({ status: kind === "cancelled" ? "cancelled" : "succeeded" }).where(eq(heartbeatRuns.id, f.runId));
|
|
if (kind === "lost-owner") await db.update(issues).set({ executionRunId: null }).where(eq(issues.id, f.issueId));
|
|
if (kind === "wrong-run-task") await db.update(heartbeatRuns).set({ nativeIssueId: null, contextSnapshot: {} }).where(eq(heartbeatRuns.id, f.runId));
|
|
if (kind === "reset-generation") await db.update(issues).set({ conversationSessionGeneration: 2 }).where(eq(issues.id, f.issueId));
|
|
if (kind === "old-card") {
|
|
const [boundary] = await db.insert(issueComments).values({ companyId: f.companyId, issueId: f.issueId, authorType: "user", authorUserId: "operator", body: "/new" }).returning();
|
|
await db.update(issues).set({ conversationBoundaryCommentId: boundary.id }).where(eq(issues.id, f.issueId));
|
|
}
|
|
await expect(resolveConfirmationFromComment(db, f.args)).rejects.toThrow();
|
|
expect((await readCard(f.card.id)).status).toBe("pending");
|
|
});
|
|
it.each(["human_only", "not_creator", "addressee", "toolAction", "secretProposal", "connectionAuthorization", "questions", "closed"])("preserves %s restrictions", async kind => {
|
|
const f = await seed();
|
|
if (kind === "closed") await db.update(issues).set({ status: "done" }).where(eq(issues.id, f.issueId));
|
|
else if (kind === "human_only" || kind === "not_creator") await db.update(issueThreadInteractions).set({ effectiveResolverPolicy: kind }).where(eq(issueThreadInteractions.id, f.card.id));
|
|
else if (kind === "addressee") await db.update(issueThreadInteractions).set({ addresseeUserId: "another-user" }).where(eq(issueThreadInteractions.id, f.card.id));
|
|
else if (kind === "questions") await db.update(issueThreadInteractions).set({ kind: "ask_user_questions" }).where(eq(issueThreadInteractions.id, f.card.id));
|
|
else await db.update(issueThreadInteractions).set({ payload: { ...f.card.payload, [kind]: {} } }).where(eq(issueThreadInteractions.id, f.card.id));
|
|
await expect(resolveConfirmationFromComment(db, f.args)).rejects.toThrow();
|
|
expect((await readCard(f.card.id)).status).toBe("pending");
|
|
});
|
|
it.each(["human_only", "not_creator"] as const)("does not promote a user's yes through an additional %s review restriction", async policy => {
|
|
const f = await seed();
|
|
await expect(resolveConfirmationFromComment(db, { ...f.args, actor: { ...f.args.actor, resolverPolicyRestriction: policy } })).rejects.toThrow();
|
|
expect((await readCard(f.card.id)).status).toBe("pending");
|
|
expect(await audit(f.issueId)).toHaveLength(0);
|
|
});
|
|
it("rechecks narrowed permissions on an otherwise matching retry", async () => {
|
|
const f = await seed();
|
|
await resolveConfirmationFromComment(db, f.args);
|
|
await db.update(issueThreadInteractions).set({ effectiveResolverPolicy: "human_only" }).where(eq(issueThreadInteractions.id, f.card.id));
|
|
await expect(resolveConfirmationFromComment(db, f.args)).rejects.toThrow();
|
|
expect((await readCard(f.card.id)).resolvedByUserId).toBeNull();
|
|
expect(await audit(f.issueId)).toHaveLength(1);
|
|
});
|
|
it("does not borrow checkbox defaults, unknown choices, or insufficient selections", async () => {
|
|
const f = await seed(true);
|
|
for (const selectedOptionIds of [undefined, [], ["unknown"], ["note", "note"]]) {
|
|
await expect(resolveConfirmationFromComment(db, { ...f.args, input: { ...f.args.input, selectedOptionIds } })).rejects.toThrow();
|
|
}
|
|
expect((await readCard(f.card.id)).status).toBe("pending");
|
|
});
|
|
it("does not bless a card already accepted through a different channel", async () => {
|
|
const f = await seed();
|
|
await f.svc.acceptInteraction(f.issue, f.card.id, {}, { userId: "operator" });
|
|
await expect(resolveConfirmationFromComment(db, f.args)).rejects.toThrow("different decision");
|
|
expect((await readCard(f.card.id)).resolvedByUserId).toBe("operator");
|
|
});
|
|
it("rejects an obsolete plan revision", async () => {
|
|
const f = await seed();
|
|
const documentId = randomUUID(), revisionId = randomUUID(), nextRevisionId = randomUUID();
|
|
await db.insert(documents).values({ id: documentId, companyId: f.companyId, latestBody: "New plan", latestRevisionId: nextRevisionId });
|
|
await db.insert(documentRevisions).values([{ id: revisionId, documentId, companyId: f.companyId, revisionNumber: 1, body: "Old plan" }, { id: nextRevisionId, documentId, companyId: f.companyId, revisionNumber: 2, body: "New plan" }]);
|
|
await db.insert(issueDocuments).values({ companyId: f.companyId, issueId: f.issueId, documentId, key: "plan" });
|
|
await db.update(issueThreadInteractions).set({ payload: { ...f.card.payload, target: { type: "issue_document", key: "plan", revisionId } } }).where(eq(issueThreadInteractions.id, f.card.id));
|
|
await expect(resolveConfirmationFromComment(db, f.args)).rejects.toThrow();
|
|
expect((await readCard(f.card.id)).status).not.toBe("accepted");
|
|
expect(await audit(f.issueId)).toHaveLength(0);
|
|
});
|
|
});
|