mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-30 05:16:50 +01:00
## Thinking Path > - Paperclip manages agents, tasks and their external chat responses. > - A completed chat turn can owe a response while an earlier review gate remains pending. > - Periodic recovery revisits that response history even when no work can advance. > - This change uses the existing delivery coordinator and saved retry deadlines. > - Approval, interaction and authority changes wake the affected issue or run after commit. > - The existing presentation owner verifies the durable result and current authority. > - Settled and dormant history becomes quiet without losing future eligible responses. ## Linked Issues or Issue Description Refs #17696 (merged) and #15625. This is slice 49, now based on master. It owns governed-review response presentation. Accepted responses and pending decision effects keep their existing owners. **What happened?** Native finalization recovery repeatedly inspects committed review responses. Removing the scan without covering approval, interaction, task-policy and authority changes would strand responses that become eligible later. **Expected behavior** Recover an owed response once from existing durable facts. Enforce authority at publication, wake after relevant outer transactions commit, retain real retry deadlines and restart/drain recovery, and stop recurring SQL when no response can advance. **Steps to reproduce** Complete an external chat turn while an earlier completion review remains pending. Block its response behind an approval or interaction, then resolve that blocker. The response must appear once without a periodic scan or resolving the original review gate. ## What Changed - Add a scoped governed-review worker using the existing coordinator, finalizations, decisions and comment receipts. No queue table or transaction wrapper is added. - Keep recovery and publication policy in the native finalizer. Preserve binding, source/session authority, ownership, deadline and deleted-comment fences; match coordinator-before-issue lock ordering. - Notify through actual approval, interaction, OAuth, task-policy and lifecycle producers before their owned writes. Serialize approval resolution with task linking so a concurrent link retains its wake. Nested transactions still settle at outer commit. - Scope ordinary milestones, finalization and coalesced input to their issue/run. Use the explicit company authority boundary for genuine global restoration, including membership changes. Both response workers share this boundary. - Register under maintenance and drain gates, disable the two periodic repair entrances, and retain fresh finalization and explicit recovery. Add the concurrent 0413 comment-receipt index and migration registration; retain five snapshots. - Preserve the producer inventory, source qualifications and earlier failures in the owner audit. Retain a real Photon regression proving routine ownership assertions stay quiet and concurrent authority restoration wakes each worker once. ## Verification - Scoped repair source `2341714720b5c273f0ce011b48345af0ef39227f` passes **2053 distinct cases**: 1703 in 15 complete producer/authority/recovery files, including all 273 governed-response cases and 95 wake-queue adapter cases, plus 350 selected chat cases. Another 1463 chat cases are outside that selection. Thirteen fresh PostgreSQL 17 fixtures migrate through unchanged 0413; the one temporary queue-fixture import restores exactly. All sixteen captured hashes match. - Two actual repeated coarse-hint SQL regressions fail before repair and pass afterward. Actual membership restoration passes before and after. The same assertions and time limits prove dormant work stays quiet and real authority restoration still publishes once. Real coalesced input covers both queues after commit. - Combined source `586f5674cd9798b33cd22437255e0480b5726d20`, including independent master #18129, passes **1297 distinct cases**: 1093 in five complete server files, 185 in five runner files, 14 Node protocol cases and five UI registry cases. This includes the complete 22-case Photon file for both response workers. The external Photon transport is mocked; Paperclip callbacks, transaction fences and observed SQL are real. The earlier and combined case counts are separate, with no cumulative double-counting. - A normal merge retains both complete owned and independent master binary patches. All twelve new-context hashes and sixteen earlier repair hashes match. Three dedicated fresh 0413 fixtures plus the live-event helper's own fresh database use PostgreSQL 17 without source adaptations. Database build, server types/build, boundaries, full-SHA migration order and generated TS/Rust profiles pass. The new inherited Runner vendor inputs rebuild successfully. - Database bytes remain identical to the previously qualified 0413 source. The recorded populated 0412-to0413 upgrade retains all 411 prior receipts and 38 companies, appends one receipt and none on replay; the index is valid and ready. The earlier 2828-case acceptance, CLI journey, setup failures and their repairs retain their recorded source scope in `doc/plans/2026-10-26-governed-review-response-sleep-audit.md`. - Parent #17696 merged with 58 clean checks, Greptile 5/5 and Ponytail 5/5. Its Photon warning was disproved by real callback/SQL evidence and the security check became successful. This PR still requires its own fresh exact-head CI and review gates. No deployed sleep, external alarm or fleet savings claim is made. ## Risks - Notifications use the existing process-local writer contract. Independent SQL writers and uncoordinated replicas are outside its coverage. - Genuine startup and company authority reconstruction remain proportional to the owed backlog. Queries page 100 rows, but discovery accumulates the candidates; this is not a constant-cost global operation. - Current publication authorization, durable binding, ownership and lock ordering remain mandatory. The worker does not resolve the original review gate. - The concurrent index uses existing migration replay handling. Other recovery duties and Cloud sleep eligibility remain separate. ## Model Used OpenAI Codex, GPT-6 family, with reasoning, repository tools, shell execution and PostgreSQL tests. The runtime does not expose a more specific serving snapshot or context-window size. ## 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> Co-authored-by: Codex <noreply@openai.com>
601 lines
18 KiB
TypeScript
601 lines
18 KiB
TypeScript
import { resolveExternalTestDatabaseUrl } from "./helpers/external-test-database.js";
|
|
import { randomUUID } from "node:crypto";
|
|
import { eq } from "drizzle-orm";
|
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
agents,
|
|
companies,
|
|
createDb,
|
|
documentRevisions,
|
|
documents,
|
|
goals,
|
|
heartbeatRuns,
|
|
issueComments,
|
|
issueDocuments,
|
|
issueThreadInteractions,
|
|
issues,
|
|
} from "@paperclipai/db";
|
|
import {
|
|
getEmbeddedPostgresTestSupport,
|
|
startEmbeddedPostgresTestDatabase,
|
|
} from "./helpers/embedded-postgres.js";
|
|
import { issueThreadInteractionService } from "../services/issue-thread-interactions.js";
|
|
|
|
const telemetryMocks = vi.hoisted(() => ({
|
|
track: vi.fn(),
|
|
getTelemetryClient: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("../telemetry.js", () => ({
|
|
getTelemetryClient: telemetryMocks.getTelemetryClient,
|
|
}));
|
|
|
|
const externalUrl = resolveExternalTestDatabaseUrl("PAPERCLIP_INTERACTION_TELEMETRY_TEST_DATABASE_URL");
|
|
const embeddedPostgresSupport = externalUrl ? { supported: true } : await getEmbeddedPostgresTestSupport();
|
|
const describeEmbeddedPostgres = embeddedPostgresSupport.supported ? describe : describe.skip;
|
|
|
|
describeEmbeddedPostgres("issueThreadInteractionService telemetry", () => {
|
|
let db!: ReturnType<typeof createDb>;
|
|
let interactionsSvc!: ReturnType<typeof issueThreadInteractionService>;
|
|
let tempDb: Awaited<ReturnType<typeof startEmbeddedPostgresTestDatabase>> | null = null;
|
|
|
|
beforeAll(async () => {
|
|
if (!externalUrl) tempDb = await startEmbeddedPostgresTestDatabase("paperclip-issue-interaction-telemetry-");
|
|
db = createDb(externalUrl ?? tempDb!.connectionString);
|
|
interactionsSvc = issueThreadInteractionService(db);
|
|
}, 20_000);
|
|
|
|
beforeEach(() => {
|
|
telemetryMocks.track.mockClear();
|
|
telemetryMocks.getTelemetryClient.mockReturnValue({
|
|
track: telemetryMocks.track,
|
|
hashPrivateRef: vi.fn((value: string) => `hashed:${value}`),
|
|
});
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await db.delete(issueThreadInteractions);
|
|
await db.delete(issueComments);
|
|
await db.delete(issueDocuments);
|
|
await db.delete(documentRevisions);
|
|
await db.delete(documents);
|
|
await db.delete(issues);
|
|
await db.delete(goals);
|
|
await db.delete(heartbeatRuns);
|
|
await db.delete(agents);
|
|
await db.delete(companies);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await db?.$client.end({ timeout: 1 });
|
|
await tempDb?.cleanup();
|
|
});
|
|
|
|
async function seedIssue(title = "Interaction telemetry") {
|
|
const companyId = randomUUID();
|
|
const goalId = randomUUID();
|
|
const issueId = randomUUID();
|
|
|
|
await db.insert(companies).values({
|
|
id: companyId,
|
|
name: "Paperclip",
|
|
issuePrefix: `T${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`,
|
|
requireBoardApprovalForNewAgents: false,
|
|
});
|
|
await db.insert(goals).values({
|
|
id: goalId,
|
|
companyId,
|
|
title,
|
|
level: "task",
|
|
status: "active",
|
|
});
|
|
await db.insert(issues).values({
|
|
id: issueId,
|
|
companyId,
|
|
goalId,
|
|
title,
|
|
status: "in_progress",
|
|
priority: "medium",
|
|
});
|
|
|
|
return { companyId, goalId, issueId };
|
|
}
|
|
|
|
async function seedAgent(companyId: string, role: string) {
|
|
const agentId = randomUUID();
|
|
await db.insert(agents).values({
|
|
id: agentId,
|
|
companyId,
|
|
name: role,
|
|
role,
|
|
status: "active",
|
|
adapterType: "codex_local",
|
|
adapterConfig: {},
|
|
runtimeConfig: {},
|
|
permissions: {},
|
|
});
|
|
return agentId;
|
|
}
|
|
|
|
function expectNoRawInteractionIds(dimensions: Record<string, unknown>) {
|
|
expect(dimensions).not.toHaveProperty("interaction_id");
|
|
expect(dimensions).not.toHaveProperty("created_by_agent_id");
|
|
expect(dimensions).not.toHaveProperty("source_run_id");
|
|
}
|
|
|
|
function lastInteractionResolvedDimensions() {
|
|
expect(telemetryMocks.track).toHaveBeenCalledWith("interaction.resolved", expect.any(Object));
|
|
const calls = telemetryMocks.track.mock.calls.filter((call) => call[0] === "interaction.resolved");
|
|
return calls.at(-1)?.[1] as Record<string, unknown>;
|
|
}
|
|
|
|
function lastInteractionCreatedDimensions() {
|
|
expect(telemetryMocks.track).toHaveBeenCalledWith("interaction.created", expect.any(Object));
|
|
const calls = telemetryMocks.track.mock.calls.filter((call) => call[0] === "interaction.created");
|
|
return calls.at(-1)?.[1] as Record<string, unknown>;
|
|
}
|
|
|
|
it("emits deprecated resolver alias use at creation without interaction content", async () => {
|
|
const { companyId, issueId } = await seedIssue("Deprecated alias telemetry issue title");
|
|
|
|
await interactionsSvc.create({
|
|
id: issueId,
|
|
companyId,
|
|
}, {
|
|
kind: "request_confirmation",
|
|
resolverPolicy: "board_only",
|
|
title: "Private confirmation title",
|
|
summary: "Private confirmation summary",
|
|
payload: {
|
|
version: 1,
|
|
prompt: "Private confirmation prompt",
|
|
detailsMarkdown: "Private confirmation details",
|
|
acceptLabel: "Private accept label",
|
|
rejectLabel: "Private reject label",
|
|
},
|
|
}, {
|
|
userId: "local-board",
|
|
});
|
|
|
|
expect(lastInteractionCreatedDimensions()).toEqual({
|
|
interaction_kind: "request_confirmation",
|
|
used_deprecated_resolver_policy_alias: true,
|
|
});
|
|
});
|
|
|
|
it("emits skipped resolution telemetry for composer Skip", async () => {
|
|
const { companyId, issueId } = await seedIssue("Skipped interaction telemetry");
|
|
const created = await interactionsSvc.create({
|
|
id: issueId,
|
|
companyId,
|
|
}, {
|
|
kind: "request_confirmation",
|
|
continuationPolicy: "none",
|
|
payload: {
|
|
version: 1,
|
|
prompt: "Continue with the proposed change?",
|
|
},
|
|
}, {
|
|
userId: "local-board",
|
|
});
|
|
|
|
await interactionsSvc.skipInteraction({
|
|
id: issueId,
|
|
companyId,
|
|
}, created.id, {}, {
|
|
userId: "local-board",
|
|
});
|
|
|
|
const dimensions = lastInteractionResolvedDimensions();
|
|
expect(dimensions).toMatchObject({
|
|
interaction_kind: "request_confirmation",
|
|
status: "cancelled",
|
|
resolved_by_kind: "user",
|
|
resolution_reason: "skipped",
|
|
created_by_kind: "user",
|
|
continuation_policy: "none",
|
|
target_type: "none",
|
|
});
|
|
expectNoRawInteractionIds(dimensions);
|
|
});
|
|
|
|
it("emits accepted suggested-task telemetry with created and skipped task counts", async () => {
|
|
const { companyId, goalId, issueId } = await seedIssue("Accept suggested tasks telemetry");
|
|
|
|
const created = await interactionsSvc.create({
|
|
id: issueId,
|
|
companyId,
|
|
}, {
|
|
kind: "suggest_tasks",
|
|
continuationPolicy: "wake_assignee",
|
|
payload: {
|
|
version: 1,
|
|
tasks: [
|
|
{
|
|
clientKey: "root",
|
|
title: "Create the root follow-up",
|
|
},
|
|
{
|
|
clientKey: "child",
|
|
parentClientKey: "root",
|
|
title: "Create the nested follow-up",
|
|
},
|
|
{
|
|
clientKey: "sibling",
|
|
title: "Create the sibling follow-up",
|
|
},
|
|
],
|
|
},
|
|
}, {
|
|
userId: "local-board",
|
|
});
|
|
|
|
await interactionsSvc.acceptInteraction({
|
|
id: issueId,
|
|
companyId,
|
|
goalId,
|
|
projectId: null,
|
|
}, created.id, {
|
|
selectedClientKeys: ["root"],
|
|
}, {
|
|
userId: "local-board",
|
|
});
|
|
|
|
const dimensions = lastInteractionResolvedDimensions();
|
|
expect(dimensions).toMatchObject({
|
|
interaction_kind: "suggest_tasks",
|
|
status: "accepted",
|
|
resolved_by_kind: "user",
|
|
resolution_reason: "accepted",
|
|
created_by_kind: "user",
|
|
continuation_policy: "wake_assignee",
|
|
target_type: "none",
|
|
created_task_count: 1,
|
|
skipped_task_count: 2,
|
|
});
|
|
expectNoRawInteractionIds(dimensions);
|
|
});
|
|
|
|
it("emits accepted checkbox telemetry with raw role, target, and counts", async () => {
|
|
const { companyId, goalId, issueId } = await seedIssue("Accept checkbox telemetry");
|
|
const creatorAgentId = await seedAgent(companyId, "Backend Engineer");
|
|
|
|
const created = await interactionsSvc.create({
|
|
id: issueId,
|
|
companyId,
|
|
}, {
|
|
kind: "request_checkbox_confirmation",
|
|
continuationPolicy: "wake_assignee",
|
|
payload: {
|
|
version: 1,
|
|
prompt: "Which files should be deleted?",
|
|
options: [
|
|
{ id: "file-a", label: "a.txt" },
|
|
{ id: "file-b", label: "b.txt" },
|
|
],
|
|
target: {
|
|
type: "custom",
|
|
key: "cleanup-plan",
|
|
},
|
|
},
|
|
}, {
|
|
agentId: creatorAgentId,
|
|
});
|
|
|
|
await interactionsSvc.acceptInteraction({
|
|
id: issueId,
|
|
companyId,
|
|
goalId,
|
|
projectId: null,
|
|
}, created.id, {
|
|
selectedOptionIds: ["file-b"],
|
|
}, {
|
|
userId: "local-board",
|
|
});
|
|
|
|
const dimensions = lastInteractionResolvedDimensions();
|
|
expect(dimensions).toMatchObject({
|
|
interaction_kind: "request_checkbox_confirmation",
|
|
status: "accepted",
|
|
resolved_by_kind: "user",
|
|
resolution_reason: "accepted",
|
|
created_by_kind: "agent",
|
|
creator_agent_role: "Backend Engineer",
|
|
continuation_policy: "wake_assignee",
|
|
target_type: "custom",
|
|
option_count: 2,
|
|
selected_option_count: 1,
|
|
});
|
|
expectNoRawInteractionIds(dimensions);
|
|
});
|
|
|
|
it("emits rejected confirmation telemetry and omits creator_agent_role for user-created interactions", async () => {
|
|
const { companyId, issueId } = await seedIssue("Reject confirmation telemetry");
|
|
const resolverAgentId = await seedAgent(companyId, "SecurityEngineer");
|
|
const resolverRunId = randomUUID();
|
|
await db.insert(heartbeatRuns).values({
|
|
id: resolverRunId,
|
|
companyId,
|
|
agentId: resolverAgentId,
|
|
status: "running",
|
|
});
|
|
|
|
const created = await interactionsSvc.create({
|
|
id: issueId,
|
|
companyId,
|
|
}, {
|
|
kind: "request_confirmation",
|
|
resolverPolicy: "board_or_agents",
|
|
payload: {
|
|
version: 1,
|
|
prompt: "Approve this?",
|
|
},
|
|
}, {
|
|
userId: "local-board",
|
|
});
|
|
|
|
await interactionsSvc.rejectInteraction({
|
|
id: issueId,
|
|
companyId,
|
|
}, created.id, {
|
|
reason: "Needs edits before approval.",
|
|
}, {
|
|
agentId: resolverAgentId,
|
|
runId: resolverRunId,
|
|
});
|
|
|
|
const dimensions = lastInteractionResolvedDimensions();
|
|
expect(dimensions).toMatchObject({
|
|
interaction_kind: "request_confirmation",
|
|
status: "rejected",
|
|
resolved_by_kind: "agent",
|
|
resolution_reason: "rejected",
|
|
created_by_kind: "user",
|
|
continuation_policy: "none",
|
|
target_type: "none",
|
|
});
|
|
expect(dimensions).not.toHaveProperty("creator_agent_role");
|
|
expect(dimensions).not.toHaveProperty("reason");
|
|
expectNoRawInteractionIds(dimensions);
|
|
});
|
|
|
|
it("emits answered question telemetry with system resolver and legacy restriction signal", async () => {
|
|
const { companyId, issueId } = await seedIssue("Answer question telemetry");
|
|
const creatorAgentId = await seedAgent(companyId, "Wizard");
|
|
|
|
const created = await interactionsSvc.create({
|
|
id: issueId,
|
|
companyId,
|
|
}, {
|
|
kind: "ask_user_questions",
|
|
continuationPolicy: "wake_assignee",
|
|
payload: {
|
|
version: 1,
|
|
questions: [
|
|
{
|
|
id: "scope",
|
|
prompt: "Choose the scope",
|
|
selectionMode: "single",
|
|
required: true,
|
|
options: [{ id: "phase-1", label: "Phase 1" }],
|
|
},
|
|
{
|
|
id: "extras",
|
|
prompt: "Optional extras",
|
|
selectionMode: "multi",
|
|
options: [{ id: "docs", label: "Docs" }],
|
|
},
|
|
],
|
|
},
|
|
}, {
|
|
agentId: creatorAgentId,
|
|
});
|
|
await db
|
|
.update(issueThreadInteractions)
|
|
.set({
|
|
continuationPolicy: "",
|
|
resolverPolicyProvenance: "legacy_inherited_restriction",
|
|
})
|
|
.where(eq(issueThreadInteractions.id, created.id));
|
|
|
|
await interactionsSvc.answerQuestions({
|
|
id: issueId,
|
|
companyId,
|
|
}, created.id, {
|
|
answers: [{ questionId: "scope", optionIds: ["phase-1"] }],
|
|
summaryMarkdown: "Do not emit this free text.",
|
|
}, {
|
|
systemId: "system:pr-merged",
|
|
});
|
|
|
|
const dimensions = lastInteractionResolvedDimensions();
|
|
expect(dimensions).toMatchObject({
|
|
interaction_kind: "ask_user_questions",
|
|
status: "answered",
|
|
resolved_by_kind: "system",
|
|
created_by_kind: "agent",
|
|
creator_agent_role: "Wizard",
|
|
target_type: "none",
|
|
question_count: 2,
|
|
answered_question_count: 1,
|
|
legacy_inherited_restriction: true,
|
|
});
|
|
expect(dimensions).not.toHaveProperty("continuation_policy");
|
|
expect(dimensions).not.toHaveProperty("summaryMarkdown");
|
|
expect(dimensions).not.toHaveProperty("answers");
|
|
expect(JSON.stringify(dimensions)).not.toContain("Choose the scope");
|
|
expect(JSON.stringify(dimensions)).not.toContain("Phase 1");
|
|
expect(JSON.stringify(dimensions)).not.toContain("Do not emit this free text.");
|
|
expectNoRawInteractionIds(dimensions);
|
|
});
|
|
|
|
it("emits expired question telemetry with zero answered question count", async () => {
|
|
const { companyId, issueId } = await seedIssue("Expired question telemetry");
|
|
const commentId = randomUUID();
|
|
|
|
const created = await interactionsSvc.create({
|
|
id: issueId,
|
|
companyId,
|
|
}, {
|
|
kind: "ask_user_questions",
|
|
continuationPolicy: "wake_assignee",
|
|
payload: {
|
|
version: 1,
|
|
supersedeOnUserComment: true,
|
|
questions: [
|
|
{
|
|
id: "scope",
|
|
prompt: "Choose the scope",
|
|
selectionMode: "single",
|
|
required: true,
|
|
options: [{ id: "phase-1", label: "Phase 1" }],
|
|
},
|
|
],
|
|
},
|
|
}, {
|
|
userId: "local-board",
|
|
});
|
|
|
|
const expired = await interactionsSvc.expireRequestConfirmationsSupersededByComment({
|
|
id: issueId,
|
|
companyId,
|
|
}, {
|
|
id: commentId,
|
|
createdAt: new Date(new Date(created.createdAt).getTime() + 1_000),
|
|
authorUserId: "local-board",
|
|
}, {
|
|
userId: "local-board",
|
|
});
|
|
|
|
expect(expired).toHaveLength(1);
|
|
const dimensions = lastInteractionResolvedDimensions();
|
|
expect(dimensions).toMatchObject({
|
|
interaction_kind: "ask_user_questions",
|
|
status: "expired",
|
|
resolved_by_kind: "user",
|
|
resolution_reason: "superseded_by_comment",
|
|
created_by_kind: "user",
|
|
continuation_policy: "wake_assignee",
|
|
target_type: "none",
|
|
question_count: 1,
|
|
answered_question_count: 0,
|
|
});
|
|
expectNoRawInteractionIds(dimensions);
|
|
});
|
|
|
|
it("emits expired stale-target telemetry without stale target identifiers", async () => {
|
|
const { companyId, issueId } = await seedIssue("Stale target telemetry");
|
|
const documentId = randomUUID();
|
|
const revisionId = randomUUID();
|
|
|
|
await db.insert(documents).values({
|
|
id: documentId,
|
|
companyId,
|
|
title: "Plan",
|
|
format: "markdown",
|
|
latestBody: "v1",
|
|
latestRevisionId: revisionId,
|
|
latestRevisionNumber: 1,
|
|
});
|
|
await db.insert(issueDocuments).values({
|
|
companyId,
|
|
issueId,
|
|
documentId,
|
|
key: "plan",
|
|
});
|
|
await db.insert(documentRevisions).values({
|
|
id: revisionId,
|
|
companyId,
|
|
documentId,
|
|
revisionNumber: 1,
|
|
title: "Plan",
|
|
format: "markdown",
|
|
body: "v1",
|
|
});
|
|
|
|
await interactionsSvc.create({
|
|
id: issueId,
|
|
companyId,
|
|
}, {
|
|
kind: "request_confirmation",
|
|
payload: {
|
|
version: 1,
|
|
prompt: "Approve the plan?",
|
|
target: {
|
|
type: "issue_document",
|
|
issueId,
|
|
documentId,
|
|
key: "plan",
|
|
revisionId,
|
|
revisionNumber: 1,
|
|
},
|
|
},
|
|
}, {
|
|
userId: "local-board",
|
|
});
|
|
|
|
const expired = await interactionsSvc.expireStaleRequestConfirmationsForIssueDocument({
|
|
id: issueId,
|
|
companyId,
|
|
}, null, {});
|
|
|
|
expect(expired).toHaveLength(1);
|
|
const dimensions = lastInteractionResolvedDimensions();
|
|
expect(dimensions).toMatchObject({
|
|
interaction_kind: "request_confirmation",
|
|
status: "expired",
|
|
resolved_by_kind: "system",
|
|
resolution_reason: "stale_target",
|
|
created_by_kind: "user",
|
|
continuation_policy: "none",
|
|
target_type: "issue_document",
|
|
});
|
|
expect(dimensions).not.toHaveProperty("staleTarget");
|
|
expect(dimensions).not.toHaveProperty("revisionId");
|
|
expectNoRawInteractionIds(dimensions);
|
|
});
|
|
|
|
it("emits superseded expiration telemetry without comment identifiers", async () => {
|
|
const { companyId, issueId } = await seedIssue("Superseded telemetry");
|
|
const commentId = randomUUID();
|
|
|
|
const created = await interactionsSvc.create({
|
|
id: issueId,
|
|
companyId,
|
|
}, {
|
|
kind: "request_confirmation",
|
|
payload: {
|
|
version: 1,
|
|
prompt: "Approve this plan?",
|
|
supersedeOnUserComment: true,
|
|
},
|
|
}, {
|
|
userId: "local-board",
|
|
});
|
|
|
|
const expired = await interactionsSvc.expireRequestConfirmationsSupersededByComment({
|
|
id: issueId,
|
|
companyId,
|
|
}, {
|
|
id: commentId,
|
|
createdAt: new Date(new Date(created.createdAt).getTime() + 1_000),
|
|
authorUserId: "local-board",
|
|
}, {
|
|
userId: "local-board",
|
|
});
|
|
|
|
expect(expired).toHaveLength(1);
|
|
const dimensions = lastInteractionResolvedDimensions();
|
|
expect(dimensions).toMatchObject({
|
|
interaction_kind: "request_confirmation",
|
|
status: "expired",
|
|
resolved_by_kind: "user",
|
|
resolution_reason: "superseded_by_comment",
|
|
created_by_kind: "user",
|
|
target_type: "none",
|
|
});
|
|
expect(dimensions).not.toHaveProperty("commentId");
|
|
expectNoRawInteractionIds(dimensions);
|
|
});
|
|
});
|