mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-22 11:54:35 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The task page shows the instruction and the recent exchange first, and shows a **More messages** button for older history > - The button is visible on almost every task. A click often shows no new message, and the button then goes away > - The compact chat shows only the latest run, so the page treats any task with two or more runs as a task with hidden history > - The recent comments read also reports more comments when the omitted comment is already pinned into the window > - This pull request shows the button only when a message is really hidden > - The benefit is a clean task page and a button that always reveals something ## Linked Issues or Issue Description Refs #17751 **What happened?** The task page shows **More messages** on almost every task. A click often adds no message, and the button then goes away. **Expected behavior** The page shows **More messages** only when it hides an older comment or an older run that has no visible answer. **Steps to reproduce** 1. Create a task and let an agent answer it in two runs. 2. Open the task with a fresh application cache. 3. See **More messages** above the conversation. Click it. No new message appears. ## What Changed - The recent run window keeps the newest omitted run (`earlierRun`), and it keeps that run as later turns arrive. - The task page ignores the omitted run when the run succeeded and its agent answer is already visible. A failed run, or a run with no visible answer, still shows the button. The answer check is the same one the chat thread uses (moved to `ui/src/lib/run-answer-visibility.ts`), so a legacy withheld-run placeholder or a progress comment does not count as an answer. - `GET /issues/:id/recent-comments` reads seven rows instead of five. It sets `hasMore` only when the window leaves out a comment. Older comments that are pinned into the window (the latest human message and the first instruction) do not count. - Added regression tests for the page (including the placeholder case), the run window cache and the server route. ## Verification - `pnpm exec vitest run src/pages/IssueDetail.test.tsx src/components/TaskChatThread.test.tsx src/lib` in `ui`: 3,637 passed, 1 skipped. The new page test fails without the fix. - After the review fixes: `pnpm exec vitest run src/pages/IssueDetail.test.tsx src/components/TaskChatThread.test.tsx src/lib/issueChatBootstrapCache.test.ts src/lib/issueDetailCache.test.ts` in `ui`: 738 passed, 1 skipped. - `pnpm exec vitest run src/__tests__/task-cold-open.test.ts src/__tests__/issue-chat-bootstrap-routes.test.ts` in `server`: 33 passed. - `tsc --noEmit` in `ui` and `server`: no errors in the changed files. - I did not do a check in the browser. ## Risks Low risk. No schema change. The API response shape does not change. The run window cache gets one optional field, and older saved caches without the field keep the old behavior. Limitation: the recent runs read returns only the two latest runs, so the page sees one omitted run. If that run has a visible answer but an older run failed, the page does not show the button. **More task actions → Show task activity** still shows that run. ## Model Used Claude Opus 5.5 (`claude-opus-5-5`) through Claude Code, with tool use and code execution. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: devinfoley <139239+devinfoley@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
279 lines
20 KiB
TypeScript
279 lines
20 KiB
TypeScript
import nativePlanWrites from "./fixtures/native-plan-write-events.json" with { type: "json" };
|
|
import { randomUUID } from "node:crypto";
|
|
import express from "express";
|
|
import request from "supertest";
|
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
import { activityLog, agents, applyPendingMigrations, closeRegisteredClients, companies, createDb, heartbeatRunEvents, heartbeatRuns, issueComments, issues, issueWorkProducts } from "@paperclipai/db";
|
|
import { getEmbeddedPostgresTestSupport, startEmbeddedPostgresTestDatabase } from "./helpers/embedded-postgres.js";
|
|
import { issueRoutes } from "../routes/issues.js";
|
|
import { errorHandler } from "../middleware/index.js";
|
|
import { createHeartbeatRunState } from "../services/heartbeat/run-state.js";
|
|
import { activityService } from "../services/activity.js";
|
|
import { documentService } from "../services/documents.js";
|
|
|
|
const externalDatabase = process.env.PAPERCLIP_TASK_COLD_OPEN_DATABASE_URL;
|
|
if (externalDatabase) {
|
|
const target = new URL(externalDatabase);
|
|
if (!["localhost", "127.0.0.1", "[::1]"].includes(target.hostname) || !target.pathname.endsWith("_test"))
|
|
throw new Error("PAPERCLIP_TASK_COLD_OPEN_DATABASE_URL must name a disposable loopback database ending in _test");
|
|
}
|
|
const support = externalDatabase ? { supported: true } : await getEmbeddedPostgresTestSupport();
|
|
(support.supported ? describe : describe.skip)("task cold-open reads", () => {
|
|
let fixture: Pick<Awaited<ReturnType<typeof startEmbeddedPostgresTestDatabase>>, "connectionString" | "cleanup">;
|
|
let db: ReturnType<typeof createDb>;
|
|
const companyId = randomUUID();
|
|
const issueId = randomUUID();
|
|
const agentId = randomUUID();
|
|
const runId = randomUUID();
|
|
beforeAll(async () => {
|
|
if (externalDatabase) {
|
|
await applyPendingMigrations(externalDatabase);
|
|
fixture = { connectionString: externalDatabase, cleanup: () => closeRegisteredClients(externalDatabase) };
|
|
} else fixture = await startEmbeddedPostgresTestDatabase("task-cold-open-");
|
|
db = createDb(fixture.connectionString);
|
|
await db.insert(companies).values({ id: companyId, name: "Cold open", issuePrefix: `T${companyId.slice(0, 6)}` });
|
|
await db.insert(agents).values({ id: agentId, companyId, name: "Writer", role: "engineer", adapterType: "codex_local" });
|
|
await db.insert(issues).values({ id: issueId, companyId, title: "Original instruction", description: "Read this first", identifier: `T${companyId.slice(0, 6)}-1`, issueNumber: 1 });
|
|
await db.insert(heartbeatRuns).values({ id: runId, companyId, agentId, issueId, runtimeMode: "native", status: "succeeded" });
|
|
}, 30_000);
|
|
afterAll(async () => { await fixture?.cleanup(); });
|
|
function app(allowedCompany = companyId) {
|
|
const app = express();
|
|
app.use((req, _res, next) => {
|
|
(req as any).actor = { type: "board", userId: "local-board", source: allowedCompany === companyId ? "local_implicit" : "cloud_tenant", companyIds: [allowedCompany], isInstanceAdmin: allowedCompany === companyId };
|
|
next();
|
|
});
|
|
app.use("/api", issueRoutes(db, {} as any));
|
|
app.use(errorHandler);
|
|
return app;
|
|
}
|
|
it("returns the instruction and saved card projection without related detail and keeps company checks", async () => {
|
|
const response = await request(app()).get(`/api/issues/${issueId}?view=core`);
|
|
expect(response.status, JSON.stringify(response.body)).toBe(200);
|
|
expect(response.body).toMatchObject({ id: issueId, description: "Read this first" });
|
|
expect(response.body).not.toHaveProperty("ancestors");
|
|
expect(response.body).toMatchObject({ documentSummaries: [], planDocument: null, workProducts: [] });
|
|
const denied = await request(app(randomUUID())).get(`/api/issues/${issueId}?view=core`);
|
|
expect([403, 404]).toContain(denied.status);
|
|
});
|
|
it("includes saved plan content, document metadata and work products in the core read", async () => {
|
|
const documents = documentService(db);
|
|
await documents.upsertIssueDocument({ issueId, key: "plan", title: "Saved plan", format: "markdown", body: "# Stable plan" });
|
|
await documents.upsertIssueDocument({ issueId, key: "evidence", title: "Saved evidence", format: "markdown", body: "Long saved evidence".repeat(1000) });
|
|
const savedProduct = {
|
|
id: randomUUID(), companyId, issueId, type: "pull_request", provider: "github",
|
|
title: "Saved investigation fix", status: "merged",
|
|
url: "https://github.com/example/reproduction/pull/42",
|
|
metadata: { repository: "example/reproduction", number: 42, additions: 78, deletions: 2 },
|
|
};
|
|
await db.insert(issueWorkProducts).values(savedProduct);
|
|
const response = await request(app()).get(`/api/issues/${issueId}?view=core`);
|
|
expect(response.status).toBe(200);
|
|
expect(response.body.planDocument).toMatchObject({ key: "plan", body: "# Stable plan" });
|
|
expect(response.body.workProducts).toEqual([expect.objectContaining(savedProduct)]);
|
|
expect(response.body.documentSummaries).toEqual(expect.arrayContaining([expect.objectContaining({ key: "evidence", title: "Saved evidence" })]));
|
|
expect(response.body.documentSummaries.every((document: Record<string, unknown>) => !("body" in document))).toBe(true);
|
|
expect(response.body).not.toHaveProperty("ancestors");
|
|
});
|
|
it("returns a bounded recent exchange plus the latest human instruction", async () => {
|
|
const humanId = randomUUID();
|
|
await db.insert(issueComments).values([
|
|
{ id: humanId, companyId, issueId, body: "Human direction", authorType: "user", authorUserId: "local-board", createdAt: new Date(0) },
|
|
...Array.from({ length: 20 }, (_, i) => ({ companyId, issueId, authorType: "agent" as const, authorAgentId: agentId, body: `Reply ${i}`, createdAt: new Date(1000 + i) })),
|
|
]);
|
|
const response = await request(app()).get(`/api/issues/${issueId}/recent-comments`);
|
|
expect(response.status, JSON.stringify(response.body)).toBe(200);
|
|
expect(response.body.hasMore).toBe(true);
|
|
expect(response.body.comments.map((c: { body: string }) => c.body)).toEqual(["Human direction", "Reply 19", "Reply 18", "Reply 17", "Reply 16"]);
|
|
expect(response.body.latestCommentId).toBe(response.body.comments[1].id);
|
|
expect([403, 404]).toContain((await request(app(randomUUID())).get(`/api/issues/${issueId}/recent-comments`)).status);
|
|
});
|
|
it("opens long chats with a contiguous recent window and pages every older message", async () => {
|
|
const chatId = randomUUID();
|
|
await db.insert(issues).values({ id: chatId, companyId, title: "Persistent chat", conversationAgentId: agentId, conversationUserId: "local-board", assigneeAgentId: agentId, conversationState: "waiting" });
|
|
const rows = Array.from({ length: 123 }, (_, i) => ({ id: randomUUID(), companyId, issueId: chatId,
|
|
authorType: "user" as const, authorUserId: "local-board", body: `Chat ${i}`, createdAt: new Date(1000 + Math.floor(i / 3)) }));
|
|
await db.insert(issueComments).values(rows);
|
|
const ordered = [...rows].sort((a, b) => +b.createdAt - +a.createdAt || b.id.localeCompare(a.id));
|
|
const response = await request(app()).get(`/api/issues/${chatId}/recent-comments`);
|
|
expect(response.status).toBe(200);
|
|
expect(response.body.comments.map((row: { id: string }) => row.id)).toEqual(ordered.slice(0, 20).map(row => row.id));
|
|
expect(response.body.oldestCommentId).toBe(ordered[19].id);
|
|
expect(response.body.hasMore).toBe(true);
|
|
const seen = response.body.comments.map((row: { id: string }) => row.id);
|
|
let cursor = response.body.oldestCommentId;
|
|
while (cursor) {
|
|
const page = await request(app()).get(`/api/issues/${chatId}/comments`).query({ order: "desc", limit: 50, after: cursor });
|
|
expect(page.status).toBe(200);
|
|
seen.push(...page.body.map((row: { id: string }) => row.id));
|
|
cursor = page.body.at(-1)?.id;
|
|
}
|
|
expect(seen).toEqual(ordered.map(row => row.id));
|
|
expect(new Set(seen).size).toBe(123);
|
|
expect([403, 404]).toContain((await request(app(randomUUID())).get(`/api/issues/${chatId}/recent-comments`)).status);
|
|
});
|
|
it("hydrates only requested runs linked to the company and issue", async () => {
|
|
const otherIssue = randomUUID(), otherRun = randomUUID();
|
|
await db.insert(issues).values({ id: otherIssue, companyId, title: "Other task" });
|
|
await db.insert(heartbeatRuns).values({ id: otherRun, companyId, agentId, issueId: otherIssue, status: "succeeded" });
|
|
const activity = activityService(db);
|
|
expect((await activity.runsForIssue(companyId, issueId, null, undefined, [runId, otherRun])).map(run => run.runId)).toEqual([runId]);
|
|
expect(await activity.runsForIssue(randomUUID(), issueId, null, undefined, [runId])).toEqual([]);
|
|
expect(await activity.runsForIssue(companyId, issueId, null, undefined, [])).toEqual([]);
|
|
});
|
|
it.each(["user", null] as const)("preserves initial and latest human instructions without a description (authorType=%s)", async (authorType) => {
|
|
const bareIssueId = randomUUID();
|
|
await db.insert(issues).values({ id: bareIssueId, companyId, title: "No description" });
|
|
await db.insert(issueComments).values([
|
|
{ companyId, issueId: bareIssueId, body: "Human direction", authorType, authorUserId: "local-board", createdAt: new Date(0) },
|
|
{ companyId, issueId: bareIssueId, body: "Newest direction", authorType, authorUserId: "local-board", createdAt: new Date(50_000) },
|
|
...Array.from({ length: 6 }, (_, i) => ({ companyId, issueId: bareIssueId, body: `New reply ${i}`, authorType: "agent" as const, authorAgentId: agentId, createdAt: new Date(60_000 + i) })),
|
|
]);
|
|
const response = await request(app()).get(`/api/issues/${bareIssueId}/recent-comments`);
|
|
expect(response.status).toBe(200);
|
|
expect(response.body.comments.map((c: { body: string }) => c.body)).toEqual([
|
|
"Human direction", "Newest direction", "New reply 5", "New reply 4", "New reply 3", "New reply 2",
|
|
]);
|
|
expect(response.body.hasMore).toBe(true);
|
|
});
|
|
it.each([
|
|
{ replies: 4, pinned: 2, hasMore: false },
|
|
{ replies: 4, pinned: 3, hasMore: true },
|
|
{ replies: 4, pinned: 6, hasMore: true },
|
|
])("reports more comments only when one stays hidden ($replies replies after $pinned older)", async ({ replies, pinned, hasMore }) => {
|
|
const bareIssueId = randomUUID();
|
|
await db.insert(issues).values({ id: bareIssueId, companyId, title: "No description" });
|
|
await db.insert(issueComments).values([
|
|
...Array.from({ length: pinned }, (_, i) => ({
|
|
companyId, issueId: bareIssueId, body: `Older ${i}`, createdAt: new Date(i),
|
|
...(i === 0 || i === pinned - 1 ? { authorType: "user" as const, authorUserId: "local-board" } : { authorType: "agent" as const, authorAgentId: agentId }),
|
|
})),
|
|
...Array.from({ length: replies }, (_, i) => ({ companyId, issueId: bareIssueId, body: `Reply ${i}`, authorType: "agent" as const, authorAgentId: agentId, createdAt: new Date(1000 + i) })),
|
|
]);
|
|
const response = await request(app()).get(`/api/issues/${bareIssueId}/recent-comments`);
|
|
expect(response.status).toBe(200);
|
|
expect(response.body.comments).toHaveLength(replies + 2);
|
|
expect(response.body.hasMore).toBe(hasMore);
|
|
});
|
|
it("loads the original input receipts outside the recent activity window and ignores replay receipts", async () => {
|
|
const commentId = randomUUID();
|
|
const receiptIssueId = randomUUID();
|
|
await db.insert(issues).values({ id: receiptIssueId, companyId, title: "Steering receipts" });
|
|
await db.insert(activityLog).values([
|
|
{ companyId, actorId: "test", entityType: "issue", entityId: receiptIssueId, action: "issue.queued_comment_steered", createdAt: new Date(1), details: { commentId, targetRunId: runId } },
|
|
{ companyId, actorId: "test", entityType: "issue", entityId: receiptIssueId, action: "issue.queued_comment_steered", createdAt: new Date(2), details: { commentId, targetRunId: runId, duplicate: true } },
|
|
...Array.from({ length: 51 }, () => ({ companyId, actorId: "test", entityType: "issue", entityId: receiptIssueId, action: "issue.updated" })),
|
|
]);
|
|
const activity = activityService(db);
|
|
expect((await activity.forIssue(receiptIssueId, 50)).some(row => row.action === "issue.queued_comment_steered")).toBe(false);
|
|
const facts = await activity.inputFactsForIssue(companyId, receiptIssueId, [commentId]);
|
|
expect(facts).toHaveLength(1);
|
|
expect(facts[0].createdAt).toEqual(new Date(1));
|
|
expect(await activity.inputFactsForIssue(companyId, receiptIssueId, [randomUUID()])).toEqual([]);
|
|
expect(await activity.inputFactsForIssue(randomUUID(), receiptIssueId, [commentId])).toEqual([]);
|
|
expect(await activity.inputFactsForIssue(companyId, randomUUID(), [commentId])).toEqual([]);
|
|
});
|
|
|
|
it("pages conversation events without ordinary tools, including identity-less deltas and requests", async () => {
|
|
const event = (seq: number, eventType: string, payload: Record<string, unknown>, itemId?: string) => ({
|
|
companyId, runId, agentId, seq, eventType, payload: { prpEvent: { schema: "paperclip.prp.event.v1", eventType, itemId, payload } },
|
|
});
|
|
await db.insert(heartbeatRunEvents).values([
|
|
event(1, "item.started", { kind: "toolCall", arguments: "large tool arguments" }, "tool"),
|
|
event(2, "item.completed", { kind: "toolCall", output: "x".repeat(100_000) }, "tool"),
|
|
event(3, "item.started", { kind: "agentMessage" }, "message"),
|
|
event(4, "item.delta", { text: "Current progress" }, "message"),
|
|
event(5, "runtime_request.opened", { requestId: "request", prompt: "Which option?" }),
|
|
event(6, "runtime_request.resolved", { requestId: "request" }),
|
|
event(7, "item.completed", { kind: "assistant_message", text: "Final answer" }),
|
|
event(8, "turn.completed", {}),
|
|
event(9, "provider.notice.recorded", { schema: "paperclip.provider.notice.v1", category: "mcp_server_startup_failed",
|
|
summary: "github MCP server failed to start: No such file or directory (os error 2)" }),
|
|
event(10, "provider.notice.recorded", { schema: "paperclip.provider.notice.v1", category: "configWarning", summary: "diagnostic" }),
|
|
]);
|
|
const service = createHeartbeatRunState(db);
|
|
const first = await service.listEvents(runId, 0, 2, true);
|
|
expect(first.map(e => e.seq)).toEqual([3, 4]);
|
|
const rest = await service.listEvents(runId, 4, 1000, true);
|
|
// A settled run keeps the MCP startup failure that explains missing tools.
|
|
expect(rest.map(e => e.seq)).toEqual([5, 6, 7, 8, 9]);
|
|
expect(JSON.stringify([...first, ...rest])).not.toContain("large tool arguments");
|
|
expect(await service.listEvents(runId)).toHaveLength(10);
|
|
await db.insert(heartbeatRuns).values({ companyId, agentId, issueId, status: "succeeded", createdAt: new Date(Date.now() + 1000) });
|
|
const activity = activityService(db);
|
|
await db.insert(activityLog).values(Array.from({ length: 55 }, () => ({
|
|
companyId, actorId: "test", action: "issue.updated", entityType: "issue", entityId: issueId,
|
|
})));
|
|
expect(await activity.forIssue(issueId, 50)).toHaveLength(50);
|
|
expect(await activity.forIssue(issueId)).toHaveLength(55);
|
|
expect(await activity.runsForIssue(companyId, issueId, null, 1)).toHaveLength(1);
|
|
expect(await activity.runsForIssue(companyId, issueId)).toHaveLength(2);
|
|
});
|
|
it("retains only successful Plan writes, with bodies removed in the database", async () => {
|
|
const planRunId = randomUUID();
|
|
await db.insert(heartbeatRuns).values({ id: planRunId, companyId, agentId, issueId, runtimeMode: "native", status: "succeeded" });
|
|
const event = (seq: number, eventType: string, item: Record<string, unknown>, turnId = "turn-1", sourceKind = "runner") => ({
|
|
companyId, runId: planRunId, agentId, seq, eventType, message: "private tool message",
|
|
payload: { extra: "private outer payload", prpEvent: { schema: "paperclip.prp.event.v1", runId: planRunId,
|
|
sourceKind, turnId, eventType, sourceSeq: seq, itemId: item.id, payload: { kind: item.type, item } } },
|
|
});
|
|
const call = (id: string, key = "plan") => ({ id, type: "tool_use", name: "write_document", input: { key, body: "private plan input" } });
|
|
const result = (id: string, key = "plan") => ({ id, tool_use_id: id, type: "tool_result",
|
|
result: { disposition: "applied", document: { key, body: "private plan output".repeat(10_000) } }, arbitrary: "private extension" });
|
|
await db.insert(heartbeatRunEvents).values([
|
|
event(1, "item.started", call("write-plan")),
|
|
event(2, "item.completed", result("write-plan")),
|
|
event(3, "item.completed", { type: "assistant_message", text: "Plan saved.\u0000" }),
|
|
event(4, "item.started", call("write-plan-revised")),
|
|
event(5, "item.completed", result("write-plan-revised")),
|
|
event(6, "item.started", call("write-notes", "notes")),
|
|
event(7, "item.completed", result("write-notes", "notes")),
|
|
event(8, "item.completed", { ...result("write-plan"), isError: true }),
|
|
event(9, "item.completed", { ...result("write-plan"), result: { disposition: "failed", document: { key: "plan" } } }),
|
|
event(10, "item.completed", result("write-plan"), "turn-1", "control_plane"),
|
|
event(11, "item.completed", result("write-plan"), "unrelated-turn"),
|
|
event(12, "item.completed", result("")),
|
|
event(13, "item.started", call("x".repeat(513))),
|
|
event(14, "item.completed", result("x".repeat(513))),
|
|
event(15, "item.started", { ...call("read-plan"), name: "read_document" }),
|
|
event(16, "item.completed", result("read-plan")),
|
|
{ ...event(17, "item.completed", result("write-plan")), payload: { prpEvent: {
|
|
schema: "unknown", sourceKind: "runner", turnId: "turn-1", payload: { item: result("write-plan") } } } },
|
|
event(18, "item.started", { id: "shared", type: "assistant_message", text: "ordinary conversation" }),
|
|
event(19, "item.completed", result("shared", "notes")),
|
|
]);
|
|
const service = createHeartbeatRunState(db);
|
|
const first = await service.listEvents(planRunId, 0, 1, true);
|
|
expect(first.map(event => event.seq)).toEqual([2]);
|
|
expect(first[0]).toMatchObject({ message: null, payload: { prpEvent: { sourceKind: "runner", sourceSeq: 2,
|
|
payload: { item: { type: "tool_result", id: "write-plan", name: "write_document", input: { key: "plan" },
|
|
result: { disposition: "applied", document: { key: "plan" } } } } } } });
|
|
const rest = await service.listEvents(planRunId, 2, 1000, true);
|
|
expect(rest.map(event => event.seq)).toEqual([3, 5, 18, 19]);
|
|
expect(rest[3]).toMatchObject({ message: "private tool message", payload: { prpEvent: { payload: { item: { result: { document: { key: "notes" } } } } } } });
|
|
expect(rest[0].payload).toMatchObject({ prpEvent: { payload: { item: { text: "Plan saved.\u0000" } } } });
|
|
const writes = [first[0], rest[1]];
|
|
expect(JSON.stringify(writes)).not.toContain("private");
|
|
expect(Buffer.byteLength(JSON.stringify(writes))).toBeLessThan(4_000);
|
|
const full = await service.listEvents(planRunId);
|
|
expect(full).toHaveLength(19);
|
|
expect(full[1].payload).toMatchObject({ extra: "private outer payload", prpEvent: { payload: { item: result("write-plan") } } });
|
|
});
|
|
|
|
it.each(nativePlanWrites.captures)("keeps the retained $provider Plan receipt alongside provider activity", async ({ events }) => {
|
|
const captureRunId = randomUUID();
|
|
await db.insert(heartbeatRuns).values({ id: captureRunId, companyId, agentId, issueId, runtimeMode: "native", status: "succeeded" });
|
|
await db.insert(heartbeatRunEvents).values(events.map(event => ({ ...event, companyId, agentId, runId: captureRunId,
|
|
payload: { prpEvent: { ...event.payload.prpEvent, runId: captureRunId } } })));
|
|
const service = createHeartbeatRunState(db);
|
|
const compact = await service.listEvents(captureRunId, 0, 1000, true);
|
|
expect(compact.map(event => event.seq)).toEqual([events.find(event => event.eventType === "item.completed")!.seq]);
|
|
expect(compact[0].payload).toMatchObject({ prpEvent: { payload: { item: {
|
|
type: "tool_result", name: "write_document", result: { document: { key: "plan" } },
|
|
} } } });
|
|
expect(JSON.stringify(compact)).not.toContain("private fixture body");
|
|
expect(await service.listEvents(captureRunId)).toHaveLength(events.length);
|
|
});
|
|
|
|
});
|