mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-12 14:19:00 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The server has about 1,100 test and helper files in `server/src/__tests__` > - `server/tsconfig.json` excludes that directory, Vitest does not check types, and no script runs the tsconfig in that directory > - So a test can call a function with the wrong arguments and still pass, and no tool reports it > - This gap hid 2,168 real type errors, and some of them hid tests that did not test what they claim > - This pull request fixes all of these errors and adds the directory to the server layers from paperclipai/paperclip#18737 > - The benefit is that a type error in a server test now fails the typecheck, with no baseline and no backlog ## Linked Issues or Issue Description Refs paperclipai/paperclip#18737, which is merged and added the server layers. Refs paperclipai/paperclip#18738, which is merged and checks the test projects outside `pnpm -r`, so it is not a duplicate. Refs paperclipai/paperclip#18137, which records that this directory has no check. **What happened?** No tool checked the types of 1,074 of the 1,101 files in `server/src/__tests__`. I searched `package.json`, the workflows, and all tsconfig files. 27 files are in the program of another tsconfig, and these 27 have 0 errors. 11 of the 27 are in `helpers/maintenance/tsconfig.json`. No script ran that project when I measured this. paperclipai/paperclip#18738 now runs it. **Expected behavior** The server typecheck checks these files, and a type error fails the check. **Steps to reproduce** 1. On the base commit, run `tsc -p server/src/__tests__/tsconfig.json --noEmit`. It reports 6,536 errors and needs 12.3 GiB. 2. Add a type error to any file in `server/src/__tests__`. 3. Run `pnpm --filter @paperclipai/server typecheck`. It passes. **Paperclip version or commit** I measured the error breakdown below on commit `8dfd632452`, with TypeScript 7.0.2. The branch now includes master up to paperclipai/paperclip#18865. **Deployment mode** Not applicable. This issue applies to development and CI. No production source file in the server changes. ### Error breakdown Each row adds one change to the row above. | Step | Total errors | Change | Cause | | --- | --- | --- | --- | | Config as committed | 6,536 | | | | Add `src/types/*.d.ts` | 4,447 | -2,089 | Config. The Express request types were missing. | | Set `rootDir` to the repository root | 2,436 | -2,011 | Config. | | Set `allowImportingTsExtensions` | 2,181 | -255 | Config. Vitest accepts `.ts` imports. | | Add `ES2024.Promise` to `lib` | 2,138 | -43 | Config. Node 24 has `Promise.withResolvers`. | | Set `allowJs` for `.mjs` imports | 2,148 | +10 | Config. It removes 8 `TS7016` errors and shows new real errors. | | Set `declaration` to false | 2,142 | -6 | Config. Tests emit nothing. | | Count only files in `server/src` | 2,058 | -84 | Other packages: 53 Daytona, 29 Runner test, 2 UI. | So 4,478 of the 6,536 errors (69%) came from config or scope, and 2,058 are real type errors in 314 files. The 29 Runner test errors are also real, which gives 2,087 errors. Tests that master added after this measurement had 81 more errors, so this pull request fixes 2,168 errors. This table classifies the first 2,058 errors. | Kind of real error | Errors | | --- | --- | | Wrong argument or assignment type | 1,023 | | Stale or partial fixture objects | 525 | | Property that the type does not have | 317 | | Missing narrowing of null or unknown | 101 | | Implicit any | 60 | | Missing name or module | 16 | | Other | 16 | ### What the type errors hid Most errors were stale fixtures and loose mocks. These errors hid real test problems, and this pull request fixes them: - **A test that never ran.** `instrumentation.test.ts` required `sdk-trace-base`, which is not installed. So 3 span tests were skipped. They now run and pass. - **Assertions that could not fail.** - `issue-thread-interactions-service` used a company ID as an issue ID. - `status-card-evaluation-work` compared `[]` with `[]` in a rollback check. - `slack-conversation-lifecycle` read `item.issueId`, which does not exist. - `email-channels` used a permission key that does not exist. - `heartbeat-project-env` imported `LOW_TRUST_REVIEW_PRESET`, which is not exported. The value was undefined. - **Postgres processes that did not stop.** 11 test files called `stop` on the test database helper. That method does not exist, and the helper method is `cleanup`. - **Arguments that the service ignored.** - `methodKey` is now `connectionMethodKey` in the Daytona, Unikraft, 1Password, and Railway tests. - 108 calls passed `"owner-user"` to a parameter that expects an options object. - 9 chat wizard fixtures passed `managementContext` as `source`, so they ran `existing_app` and not `manifest`. - 2 tests passed a `{ userId }` actor that the function ignores. - Inserts into `environments` passed a `companyId` column that the table does not have. - **Problems in tests that master added during this work.** - `sandbox-creation-operations` read `database.connectionString` when an external test database was set. In that mode `database` is undefined, so the fixture would stop with a TypeError. It now uses the external URL. - `idle-completed-history` set a Dot operation to `dispatched`. That is a Muse status, and the Dot type does not have it. The fixture now uses `admitted`, which is a real in-flight Dot status. ### Possible product problems, not changed These may be real problems in production code or types. I did not change them, because this pull request does not change production behavior: - `decisions-service` `service.create` does not validate the lenient `cancel_issue_tree` input. - `createConnection` ignores `input.connectionPurpose`. - The `createConnection` route schema default stores `{}` for `transportConfig`. - `prepareManagedAiRuntime` accepted the invalid value `mode: "connection"`. - `createBinding` accepts invalid `projectionClass` strings outside class 3. - `ensureManagedProjectWorkspace` forwards an untyped `repoRef` by spread. - `routineVariableSchema.label` is optional, but `RoutineVariable.label` is required. - `ToolRunContext.projectId` may be too strict. - `withdrawInteraction` reads `issue.status`, which its type omits. - `issueService.list` and `reconcileNativeFinalizations` omit fields that they return at runtime. - `createGitHubExternalObjectProvider` handles `tokenProvider: null`, but its type forbids this value. ## What Changed - Fixed the 2,168 type errors. The diff changes 322 test and helper files. - Corrected `server/src/__tests__/tsconfig.json`. Editors and the typecheck now read the same options and report the same errors. - Added three `test-tree` layers to `server/scripts/typecheck-layers.mjs`. They read the server layers as declarations, and any error fails them. A hash of the path selects the shard, so a new file does not move other files. - Added `server/scripts/typecheck-stubs/daytona-sdk.d.ts`. Server tests reach Daytona plugin source, and the root install does not have `@daytonaio/sdk`. - Changed two imports in `ui/src/lib/issue-execution-policy.ts` to use `.js` extensions, because server tests import this file. - Made `declarationsConfig` and `--declarations-only` skip the `test-tree` layers, because these layers emit nothing. Other projects read only the source layers. Added a test for this. - Updated `doc/DEVELOPING.md`. ## Verification Run these commands: ```sh pnpm --filter @paperclipai/server typecheck pnpm exec vitest run server/scripts/typecheck-layers.test.mjs ``` Results on macOS (arm64), Node 24, 16 cores. Each check ran after the merge of paperclipai/paperclip#18738 unless the row says otherwise: | Check | Commit | Result | | --- | --- | --- | | Server typecheck, `PAPERCLIP_TYPECHECK_LOW_MEMORY=1`, all 7 layers | `6e45a08573` | Exit 0, 0 errors, 62 seconds, peak 3.52 GiB | | `node scripts/typecheck-test-projects.mjs --low-memory` | `a3306bd13e` | Exit 0, 0 errors, 42 seconds, peak 3.25 GiB | | The same script with `--reuse-declarations` | `1b878aabc0` | Exit 0, 0 errors | | `typecheck-layers.test.mjs` and `live-recovery-work.test.ts` | `01db5634e4` | 90 passed. These include real compiler runs for a pass, a type error, and an invalid tsconfig. | | `tsconfig.declarations.json` after a full server typecheck | `0fb1e4fb0a` | It references only `below`, `cycle`, and `above`. No generated config names a `tsconfig.layers.json` file. | | Owned runtime test in `idle-completed-history` | `e8f2f448ac` | Passed, with the fix that master later replaced | | `idle-incoming-wake`, `plugin-idle-manager`, and the changed `chat-channels` test | `6e45a08573` | 30 passed | | Runner `native-execution.test.ts` | `eab4dcc1f4` | 114 passed | | The 19 server test files that changed since `eab4dcc1f4`, and `typecheck-layers.test.mjs` | `259737b700` | 4,275 of 4,277 passed. The 2 failures are in `chat-channels` and are in the list of 7 below. | The peak is the largest single process, from `/usr/bin/time -l`. Peaks for the server typecheck were between 3.42 GiB and 3.56 GiB across 8 runs. Peaks for the test projects were 3.25 GiB and 3.37 GiB across 2 runs. I did not measure a cgroup. **Runtime check of the fixes.** Types do not prove that a test still works. So I ran all 309 changed server test files, 11,929 tests, before the rebase onto paperclipai/paperclip#18737: | Result | Tests | Detail | | --- | --- | --- | | Passed | 11,913 | Includes the 2 tests and the 54 `dot-runner` tests that passed in a later run, as described below. | | Failed | 7 | The same 7 tests also fail on the commit before the fixes. | | Skipped | 9 | These tests have their own skip conditions: `sentry` 5, and 1 each in `bundled-plugin-registration`, `customer-success-cloud`, `onepassword-connection`, and `workspace-runtime-https-live-exercise`. | The 7 tests that fail with and without this change, on my machine: - 3 tests in `chat-channels` and `email-channels` stop with `ENOENT` on a `SKILL.md` file. The path is in the parent checkout, above the git worktree that I used, so I expect that the worktree is the cause. I did not prove this. - `workspace-instance-cleanup` compares `/private/var/...` with `/var/...`. This is a macOS symlink difference. - 2 tests in `git-reproducible-managed-checkouts` get `unknown_base_git_files` and expect `unpushed_managed_checkout`. I did not find the cause. - 1 more test in `chat-channels`, `materializes direct external-chat finals once`, gets `undefined`. I did not find the cause. CI is the check for these 7 tests. `ci / verify` passed on `eab4dcc1f4`. Failures during this work: - My fix to `agent-runtime-connector-access` changed an invalid permission key in the setup, but not in the assertion. The runtime check found this. I corrected the assertion, and the file passes. - `heartbeat-plugin-environment` failed one wait in the full run. It passed three times alone, so I think that load caused the failure. It can fail again under load. - `dot-runner` skipped all 54 tests in the full run because `cargo` was not on my `PATH`. It then passed 54 of 54 with the toolchain on the `PATH`. - My first `lib` value removed the default DOM types, and the error count went up by 375. I added the DOM libraries. - My Daytona stub with bare `any` left 48 errors, because generic helpers then inferred `unknown`. I added shapes that return promises. - One fix to `agent-secrets-routes` used `class_3_static_lease`, and the test failed. That class allows only specific paths. I reverted to `unclassified`. - `ci / General tests (server (8/12))` failed on `259737b700` because of the flaky port in `idle-completed-history`. paperclipai/paperclip#18853 fixed this test on master, so this pull request keeps that fix. **Audit of the diff.** I counted these patterns in added and removed lines, to find fixes that only hide an error: | Pattern | Added | Removed | | --- | --- | --- | | `@ts-ignore` | 0 | 0 | | `@ts-expect-error` | 0 | 1 | | `.skip` | 0 | 0 | | `as any` | 9 | 9 | | `: any` | 11 | 2 | | `as never` | 8 | 2 | | `as unknown as` | 35 | 4 | | `Promise<unknown>` | 16 | 5 | | `expect(` | 128 | 113 | No hunk removes more `expect(` calls than it adds. Three removals of test content were intentional, and I checked each one: - `muse-control` removed `signalToken`. Line 1012 already asserts that it is absent. - `merged-pr-confirmation-sweep` removed legacy aliases. Other tests cover them. - `heartbeat-workspace-branch-containment` removed a `finalize` branch that no test row can reach. Some partial fixtures stay unchecked through `as unknown as` and `Promise<unknown>`, mostly in `issue-agent-mutation-ownership-routes` and `issue-comment-reopen-routes`. **Accuracy of the check.** One program over the tree and the three shards reported the same errors at the same positions. Memory, as the peak of the largest process on one thread, was 3.93 GiB for one program and 2.43 GiB for the largest shard. I measured these two values before the fixes. Not run or not proven: - I did not run the full `pnpm test:run`, or a root `pnpm build`. I expect CI to run the full suites. - I did not run the 4 GiB container check, or the full `scripts/typecheck-low-memory.mjs`. The peaks above come from macOS, so they are not a Linux cgroup measurement. - I did not run the UI typecheck after the merges. - `workspace-runtime-https-live-exercise` is skipped, so its `cleanup` fix did not run. ## Risks - **A large diff in test files.** 328 files change. A pull request that edits the same tests can get merge conflicts. New tests on master can also add type errors before this merges. Any such error fails this check and needs a fix here. - **A higher cost for changes to source types.** A change to a type can add errors in test files that the author did not touch. The author must then fix them. This is the purpose of the check, but it is new work. - **Changed test behavior.** Some tests now run paths that they did not run before, such as the 9 chat wizard fixtures and the 3 span tests. They pass here, but they can be more sensitive to timing or to the environment. - **The Daytona stub can go stale.** The stub is written by hand. If the plugin uses a new SDK member, the typecheck reports an error until someone updates the stub. - **The release path.** `release-verify.yml` and `scripts/release.sh` run `pnpm -r typecheck`, so they now run this check. - **The tsconfig change.** The test transform reads `server/src/__tests__/tsconfig.json`. The options that I changed are for type checks, and the runs above passed. - **A gap that remains.** Tsconfigs in `packages/paperclip-runner` and in most sandbox provider plugins exclude `*.test.ts`. This check does not read most of those test files, so they can still drift. That work is separate from this pull request. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used Anthropic Claude Opus 5.5 (`claude-opus-5-5`) through Claude Code, with reasoning, tool use, code execution, and subagents. The runtime does not show the 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 - [ ] I have run tests locally and they pass (7 tests fail locally, with and without this change. See Verification.) - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
850 lines
34 KiB
TypeScript
850 lines
34 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
buildPaperclipTaskMarkdown,
|
|
mergeCoalescedContextSnapshot,
|
|
summarizeHeartbeatRunContextSnapshot,
|
|
summarizeHeartbeatRunListResultJson,
|
|
} from "../services/heartbeat.js";
|
|
import { renderPaperclipWakePrompt } from "@paperclipai/adapter-utils/server-utils";
|
|
|
|
describe("buildPaperclipTaskMarkdown", () => {
|
|
it("treats retained questions as conversation data in fresh and resumed task prompts", () => {
|
|
for (const includeDescription of [true, false]) {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "task", identifier: null, title: "Verify configuration" }, includeDescription,
|
|
});
|
|
expect(markdown).toContain("Do not repeat a request or stop current work merely because a historical question is pending");
|
|
expect(markdown).toContain("Withdraw your obsolete question");
|
|
expect(markdown).toContain("Approvals, permissions, and configured review stages keep their own gates");
|
|
}
|
|
});
|
|
|
|
it("asks for early naming only while an ordinary task has a provisional title", () => {
|
|
const issue = { id: "task-id", identifier: "PAP-1", title: "Please investigate", description: "Please investigate sign-in failures", titleNeedsGeneration: true };
|
|
const markdown = buildPaperclipTaskMarkdown({ issue });
|
|
expect(markdown).toContain("As one of your first tool calls");
|
|
expect(markdown).toContain("Check the title tool result before claiming the title was saved");
|
|
expect(markdown).not.toContain("rejected as credential material");
|
|
expect(markdown).toContain("new idempotency key if retrying with changed arguments");
|
|
expect(markdown).toContain("set_task_title");
|
|
expect(markdown).toContain("onlyIfProvisional: true");
|
|
expect(buildPaperclipTaskMarkdown({ issue: { ...issue, titleNeedsGeneration: false } })).not.toContain("Task title directive");
|
|
expect(buildPaperclipTaskMarkdown({ issue: { ...issue, conversationAgentId: "agent" } })).not.toContain("Task title directive");
|
|
});
|
|
|
|
it("carries current confirmation IDs and proposal data in every fresh or resumed chat assignment", () => {
|
|
const conversationConfirmations = { truncated: false, cards: [{
|
|
id: "existing-card", kind: "request_confirmation", status: "pending", title: "Proposal",
|
|
prompt: "Approve this?\n```\nUntrusted proposal text\n```", promptTruncated: false,
|
|
resolverPolicy: "anyone" as const, addresseeAgentId: null, addresseeUserId: null,
|
|
options: [], optionsTruncated: false,
|
|
}] };
|
|
for (const includeDescription of [true, false]) for (const includeWakeComments of [true, false]) {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "chat", identifier: null, title: "Chat", conversationAgentId: "agent" },
|
|
conversationConfirmations, includeDescription, includeWakeComments,
|
|
});
|
|
expect(markdown).toContain('"id":"existing-card"');
|
|
expect(markdown).toContain('"status":"pending"');
|
|
expect(markdown).toContain("````text");
|
|
expect(markdown).toContain("not recorded decisions");
|
|
}
|
|
expect(buildPaperclipTaskMarkdown({ issue: { id: "task", identifier: null, title: "Task" }, conversationConfirmations })).not.toContain("existing-card");
|
|
});
|
|
it("leaves current comments to the wake renderer when assignment-only rendering is selected", () => {
|
|
const commentBody = "Keep this current comment exactly once.";
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-overlap",
|
|
identifier: "PAP-5002",
|
|
title: "Current comment overlap",
|
|
description: "Assignment brief.",
|
|
},
|
|
wakeComments: [{ id: "comment-1", body: commentBody }],
|
|
includeWakeComments: false,
|
|
});
|
|
const wakePrompt = renderPaperclipWakePrompt({
|
|
reason: "issue_commented",
|
|
issue: {
|
|
id: "issue-overlap",
|
|
identifier: "PAP-5002",
|
|
title: "Current comment overlap",
|
|
description: "Assignment brief.",
|
|
},
|
|
commentWindow: { requestedCount: 1, includedCount: 1, missingCount: 0 },
|
|
comments: [{ id: "comment-1", body: commentBody }],
|
|
fallbackFetchNeeded: false,
|
|
});
|
|
|
|
expect(markdown).not.toContain(commentBody);
|
|
expect(wakePrompt).toContain(commentBody);
|
|
expect(`${markdown}\n${wakePrompt}`.split(commentBody)).toHaveLength(2);
|
|
});
|
|
|
|
it("keeps attachment descriptors and follow-up rules when assignment markdown omits wake bodies", () => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "issue-files", identifier: "PAP-5003", title: "Files", description: "Brief" },
|
|
wakeComments: [{
|
|
id: "comment-files",
|
|
body: "Inspect the file.",
|
|
attachments: [{
|
|
id: "attachment-1",
|
|
filename: "evidence.png",
|
|
contentType: "image/png",
|
|
byteSize: 42,
|
|
contentPath: "/api/attachments/attachment-1/content",
|
|
}],
|
|
}],
|
|
includeWakeComments: false,
|
|
});
|
|
|
|
expect(markdown).not.toContain("Inspect the file.");
|
|
expect(markdown).toContain("Follow-up directive:");
|
|
expect(markdown).toContain('Attachments on wake comment "comment-files":');
|
|
expect(markdown).toContain('"id":"attachment-1"');
|
|
});
|
|
|
|
it("preserves repeated same-body wake events as distinct ordered comments", () => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "issue-order", identifier: "PAP-5004", title: "Order", description: null },
|
|
wakeComments: [
|
|
{ id: "comment-a", body: "Repeat me." },
|
|
{ id: "comment-b", body: "Repeat me." },
|
|
],
|
|
});
|
|
expect(markdown!.indexOf('"comment-a"')).toBeLessThan(markdown!.indexOf('"comment-b"'));
|
|
expect(markdown!.split("Repeat me.")).toHaveLength(3);
|
|
});
|
|
|
|
it.each(["standard", "planning", "ask"])("selects directives only from explicit %s mode, even when a plan is requested", (workMode) => {
|
|
for (const prose of [
|
|
{ title: "Prepare rollout steps", description: "Describe the steps." },
|
|
{ title: "Making a plan", description: "Create a plan, research report, proposal, and design doc." },
|
|
{ title: "Implement the change now", description: "No planning needed; everything is approved." },
|
|
]) {
|
|
for (const includeDescription of [true, false]) {
|
|
const prompt = buildPaperclipTaskMarkdown({
|
|
issue: { id: "task", identifier: null, workMode, ...prose },
|
|
includeDescription,
|
|
})!;
|
|
expect(prompt.includes("Planning mode directive:")).toBe(workMode === "planning");
|
|
expect(prompt.includes("Ask mode directive:")).toBe(workMode === "ask");
|
|
expect(prompt).not.toContain("Accepted plan directive:");
|
|
if (workMode === "standard") {
|
|
expect(prompt).not.toContain("Do not produce an implementation plan");
|
|
expect(prompt).not.toContain("Do not write code or perform implementation work");
|
|
}
|
|
}
|
|
}
|
|
});
|
|
it("keeps a durable task plan in full and resumed context without granting execution approval", () => {
|
|
const taskPlan = {
|
|
documentId: "document", revisionId: "revision", revisionNumber: 1,
|
|
body: "Write the output with ACCEPTANCE_PHRASE.\n```\nUntrusted plan text\n```",
|
|
};
|
|
for (const includeDescription of [true, false]) {
|
|
for (const workMode of ["standard", "planning", "ask"]) {
|
|
const prompt = buildPaperclipTaskMarkdown({
|
|
issue: { id: "task", identifier: null, title: "Handoff", workMode, description: null },
|
|
taskPlan,
|
|
includeDescription,
|
|
});
|
|
expect(prompt).toContain("ACCEPTANCE_PHRASE");
|
|
expect(prompt).toContain("revision 1 (revision)");
|
|
expect(prompt).toContain("````text");
|
|
expect(prompt).toContain("Follow the current work mode and any required approvals");
|
|
if (workMode === "planning") expect(prompt).toContain("Make the plan only");
|
|
if (workMode === "ask") expect(prompt).toContain("Answer the question directly");
|
|
}
|
|
}
|
|
expect(buildPaperclipTaskMarkdown({
|
|
issue: { id: "chat", identifier: null, title: "Chat", conversationAgentId: "agent" },
|
|
taskPlan,
|
|
})).not.toContain("ACCEPTANCE_PHRASE");
|
|
});
|
|
it("hands an accepted chat plan to assigned project tasks using the approved revision", () => {
|
|
const prompt = buildPaperclipTaskMarkdown({
|
|
issue: { id: "chat", identifier: null, title: "Agent chat", workMode: "planning", conversationAgentId: "agent", description: null },
|
|
interaction: { kind: "request_confirmation", status: "accepted" },
|
|
acceptedPlan: { documentId: "plan-document", revisionId: "approved-revision", revisionNumber: 2 },
|
|
});
|
|
expect(prompt).toContain("Perform that handoff now");
|
|
expect(prompt).toContain("ordinary assigned execution tasks");
|
|
expect(prompt).toContain("initialPlan before execution starts");
|
|
expect(prompt).toContain("revision 2 approved-revision");
|
|
expect(prompt).not.toContain("Implement the accepted plan on this issue");
|
|
});
|
|
|
|
it.each(["ask", "new-comment", "unbound-confirmation"])("does not treat %s as plan handoff authorization", (kind) => {
|
|
const prompt = buildPaperclipTaskMarkdown({
|
|
issue: { id: "chat", identifier: null, title: "Agent chat", workMode: kind === "ask" ? "ask" : "planning", conversationAgentId: "agent", description: null },
|
|
interaction: { kind: "request_confirmation", status: "accepted" },
|
|
...(kind === "unbound-confirmation" ? {} : { acceptedPlan: { documentId: "plan-document", revisionId: "approved-revision", revisionNumber: 2 } }),
|
|
...(kind === "new-comment" ? { wakeComment: { id: "later-comment", body: "Please revise it again first." } } : {}),
|
|
});
|
|
expect(prompt).not.toContain("Perform that handoff now");
|
|
});
|
|
|
|
it("surfaces every coalesced wake comment in provider order", () => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-burst",
|
|
identifier: "PAP-5000",
|
|
title: "Handle a chat burst",
|
|
workMode: "standard",
|
|
description: "Original request",
|
|
},
|
|
wakeComment: {
|
|
id: "comment-3",
|
|
body: "burst-four",
|
|
},
|
|
wakeComments: [
|
|
{ id: "comment-1", body: "burst-two" },
|
|
{ id: "comment-2", body: "burst-three" },
|
|
{ id: "comment-3", body: "burst-four" },
|
|
],
|
|
});
|
|
|
|
expect(markdown).toContain(
|
|
"Address every comment without repeating completed work.",
|
|
);
|
|
expect(markdown).toContain("Pending wake comments (oldest to newest):");
|
|
expect(markdown).not.toContain("Latest wake comment:");
|
|
expect(markdown!.indexOf("burst-two")).toBeLessThan(
|
|
markdown!.indexOf("burst-three"),
|
|
);
|
|
expect(markdown!.indexOf("burst-three")).toBeLessThan(
|
|
markdown!.indexOf("burst-four"),
|
|
);
|
|
});
|
|
|
|
it("surfaces exact wake-comment attachment descriptors and inspection guidance", () => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-attachments",
|
|
identifier: "PAP-5001",
|
|
title: "Inspect provider files",
|
|
workMode: "standard",
|
|
description: null,
|
|
},
|
|
wakeComments: [
|
|
{
|
|
id: "comment-files",
|
|
body: "Identify the image and quote the text file.",
|
|
attachments: [
|
|
{
|
|
id: "attachment-image",
|
|
filename: "evidence.png",
|
|
contentType: "image/png",
|
|
byteSize: 2048,
|
|
contentPath: "/api/attachments/attachment-image/content",
|
|
},
|
|
{
|
|
id: "attachment-text",
|
|
filename: "phrase.txt",
|
|
contentType: "text/plain",
|
|
byteSize: 128,
|
|
contentPath: "/api/attachments/attachment-text/content",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(markdown).toContain(
|
|
'Attachments on wake comment "comment-files":',
|
|
);
|
|
expect(markdown).toContain('"id":"attachment-image"');
|
|
expect(markdown).toContain('"filename":"phrase.txt"');
|
|
expect(markdown).toContain(
|
|
'"contentPath":"/api/attachments/attachment-text/content"',
|
|
);
|
|
expect(markdown).toContain("PAPERCLIP_API_URL");
|
|
expect(markdown).toContain("PAPERCLIP_API_KEY");
|
|
expect(markdown).toContain("never invoke `npx`");
|
|
expect(markdown).toContain(
|
|
"Do not infer file contents from filenames or metadata",
|
|
);
|
|
});
|
|
|
|
it.each(["slack", "discord", "telegram", "microsoft-teams", "github"])(
|
|
"directs %s file replies through the bundled artifact handoff",
|
|
(externalChatProvider) => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-file-reply",
|
|
identifier: null,
|
|
title: "Send the requested image and file",
|
|
workMode: "standard",
|
|
description: null,
|
|
},
|
|
externalChatProvider,
|
|
});
|
|
expect(markdown).toContain("External chat file delivery:");
|
|
expect(markdown).toContain("paperclip-upload-artifact.sh --chat-comment");
|
|
expect(markdown).toContain("installed skill location, not the task workspace");
|
|
expect(markdown).toContain("Do not search for a separate provider tool connection");
|
|
expect(markdown).toContain("do not claim provider delivery merely because binding succeeded");
|
|
expect(markdown).toContain(
|
|
"one helper command per file into as few tool calls as practical",
|
|
);
|
|
expect(markdown).toContain("do not manually bind the same file again");
|
|
expect(markdown).toContain(
|
|
"Retry or investigate only a failed or ambiguous step",
|
|
);
|
|
},
|
|
);
|
|
|
|
it.each([true, false])("keeps rich Slack questions available on fresh and resumed turns (native=%s)", (nativeRunner) => {
|
|
for (const includeDescription of [true, false]) {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "slack-question", identifier: null, title: "Ask me a zoo question", workMode: "standard" },
|
|
externalChatProvider: "slack", nativeRunner, includeDescription,
|
|
});
|
|
expect(markdown).toContain("Interactive questions in Slack:");
|
|
expect(markdown).toContain("When you have results, update the user in the originating Slack");
|
|
expect(markdown).toContain("When the user needs to review a plan, approve an action, or review a result");
|
|
expect(markdown).toContain("create the required human-input or approval interaction before you yield");
|
|
expect(markdown).toContain("Saving a plan or setting a task to in_review alone does not ask the user to review it");
|
|
expect(markdown).toContain("do not continue gated work until the required approval is recorded");
|
|
expect(markdown).toContain("ask_user_questions");
|
|
expect(markdown).toContain("single_select");
|
|
expect(markdown).toContain("resumes this task after the answer");
|
|
expect(markdown).toContain("Do not post a second copy of your ordinary reply");
|
|
expect(markdown).toContain("Neither queued nor uncertain means delivered");
|
|
expect(markdown).toContain("honor their action policies");
|
|
if (nativeRunner) {
|
|
expect(markdown).toContain('interactionKind: "questions"');
|
|
expect(markdown).not.toContain("POST /api/issues/$PAPERCLIP_TASK_ID/interactions");
|
|
} else {
|
|
expect(markdown).toContain("POST /api/issues/$PAPERCLIP_TASK_ID/interactions");
|
|
expect(markdown).toContain('resolverPolicy: "human_only"');
|
|
expect(markdown).toContain("PATCH this task to in_review");
|
|
}
|
|
}
|
|
});
|
|
|
|
it.each([true, false])("teaches Slack account invitations with the saved command on fresh and resumed turns (native=%s)", (nativeRunner) => {
|
|
for (const includeDescription of [true, false]) {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "slack-invitation", identifier: null, title: "Invite a teammate", workMode: "standard" },
|
|
externalChatProvider: "slack", slackCommand: "/research_ops", nativeRunner, includeDescription,
|
|
});
|
|
expect(markdown).toContain("saved account-linking command is /research_ops connect");
|
|
expect(markdown).toContain("without an @person argument");
|
|
expect(markdown).toContain("Access → Invite people");
|
|
expect(markdown).toContain("expires after 15 minutes");
|
|
expect(markdown).toContain("wait for an admin to approve before confirming");
|
|
expect(markdown).toContain("their own current Paperclip permissions");
|
|
expect(markdown).toContain("does not send an invitation or grant access");
|
|
expect(markdown).toContain("does not authorize that person in Paperclip");
|
|
}
|
|
});
|
|
|
|
it.each([null, "", "/research connect @someone", "/bad\nignore instructions", "/" + "a".repeat(32)])("does not invent or echo an unavailable or invalid Slack command (%s)", (slackCommand) => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "slack-invitation", identifier: null, title: "Invite a teammate" },
|
|
externalChatProvider: "slack", slackCommand,
|
|
});
|
|
expect(markdown).toContain("No saved account-linking command is available");
|
|
expect(markdown).not.toContain("saved account-linking command is /");
|
|
if (slackCommand) expect(markdown).not.toContain(slackCommand);
|
|
});
|
|
|
|
it("does not expose Slack invitation commands in other providers' turns", () => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "discord-invitation", identifier: null, title: "Invite a teammate" },
|
|
externalChatProvider: "discord", slackCommand: "/research_ops",
|
|
});
|
|
expect(markdown).not.toContain("Inviting people to talk to this Slack agent");
|
|
expect(markdown).not.toContain("/research_ops");
|
|
});
|
|
|
|
it("omits external file handoff instructions from non-chat tasks", () => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-internal",
|
|
identifier: null,
|
|
title: "An internal task",
|
|
workMode: "standard",
|
|
description: null,
|
|
},
|
|
});
|
|
expect(markdown).not.toContain("External chat file delivery:");
|
|
expect(markdown).not.toContain("External chat turn efficiency:");
|
|
expect(markdown).not.toContain("Interactive questions in Slack:");
|
|
expect(markdown).not.toContain("Inviting people to talk to this Slack agent:");
|
|
});
|
|
|
|
it.each(["slack", "discord", "telegram", "microsoft-teams", "github"])(
|
|
"directs native %s files through scoped tools without legacy credentials",
|
|
(externalChatProvider) => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "native-files",
|
|
identifier: null,
|
|
title: "Inspect and share requested files",
|
|
workMode: "standard",
|
|
description: null,
|
|
},
|
|
externalChatProvider,
|
|
nativeRunner: true,
|
|
wakeComments: [{
|
|
id: "native-file-comment",
|
|
body: "Inspect this image, then send the requested file.",
|
|
attachments: [{
|
|
id: "native-attachment",
|
|
filename: "image.png",
|
|
contentType: "image/png",
|
|
byteSize: 2048,
|
|
contentPath: "/api/attachments/native-attachment/content",
|
|
}],
|
|
}],
|
|
});
|
|
expect(markdown).toContain("`register_deliverable`");
|
|
expect(markdown).toContain("workspace-relative `contentRef`");
|
|
expect(markdown).toContain("do not confirm provider delivery");
|
|
expect(markdown).toContain("Register or reuse only the requested files");
|
|
expect(markdown).toContain("`list_chat_attachments`");
|
|
expect(markdown).toContain("`reuse_chat_attachment`");
|
|
expect(markdown).toContain(
|
|
"never substitute an earlier file for unavailable current-turn input",
|
|
);
|
|
expect(markdown).toContain("workspace-relative staged attachment descriptors");
|
|
expect(markdown).toContain("clearly state that you could not inspect it");
|
|
expect(markdown).toContain("batch independent reads/inspection with the appropriate available tools");
|
|
expect(markdown).toContain("Compute exact sizes and SHA-256 hashes in the same preparation step");
|
|
expect(markdown).toContain("batch independent per-file registrations into as few tool calls as practical");
|
|
expect(markdown).toContain("one registration and a distinct stable idempotencyKey per file");
|
|
expect(markdown).toContain("wait for each receipt before the final-response protocol");
|
|
expect(markdown).toContain("retry only a failed or ambiguous step with its original key");
|
|
expect(markdown).toContain("current source/generation authorization, exact-byte reuse, or approval gates");
|
|
expect(markdown).toContain("skip a separate preamble and narration before each step");
|
|
expect(markdown).toContain("Keep useful wait, blocker, permission, and failure updates");
|
|
expect(markdown).toContain("do not suppress transport-managed progress");
|
|
expect(markdown).toContain('"id":"native-attachment"');
|
|
expect(markdown).not.toContain("paperclip-upload-artifact.sh");
|
|
expect(markdown).not.toContain("PAPERCLIP_API_KEY");
|
|
expect(markdown).not.toContain("/api/attachments/");
|
|
},
|
|
);
|
|
|
|
it.each([
|
|
{ nativeRunner: false, externalChatProvider: "slack" },
|
|
{ nativeRunner: true, externalChatProvider: null },
|
|
])("keeps native media batching out of unrelated instruction paths: %j", (mode) => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "other-workflow", identifier: null, title: "Other work" },
|
|
...mode,
|
|
});
|
|
expect(markdown).not.toContain("batch independent per-file registrations");
|
|
expect(markdown).not.toContain("skip a separate preamble and narration before each step");
|
|
});
|
|
|
|
it("does not imply that GitHub chat grants attachment or repository-tool access", () => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-github-chat",
|
|
identifier: "PAP-5002",
|
|
title: "Inspect a GitHub comment",
|
|
workMode: "standard",
|
|
description: null,
|
|
},
|
|
wakeComments: [
|
|
{
|
|
id: "comment-github",
|
|
body: "Inspect https://user-images.githubusercontent.com/example/file.png",
|
|
},
|
|
],
|
|
externalChatProvider: "github",
|
|
});
|
|
|
|
expect(markdown).toContain("GitHub chat attachment note:");
|
|
expect(markdown).toContain(
|
|
"does not grant repository-tool or attachment-download authority",
|
|
);
|
|
expect(markdown).toContain(
|
|
"do not ask for another chat connection",
|
|
);
|
|
expect(markdown).toContain(
|
|
"attach the file directly to this Paperclip task or paste the needed text",
|
|
);
|
|
expect(markdown).toContain(
|
|
"Never borrow browser cookies or forward credentials to an attachment URL",
|
|
);
|
|
});
|
|
|
|
it("adds planning directives for assignment and comment task context", () => {
|
|
const assignment = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-1",
|
|
identifier: "PAP-3404",
|
|
title: "Plan first",
|
|
workMode: "planning",
|
|
description: null,
|
|
},
|
|
});
|
|
|
|
expect(assignment).toContain("- Work mode: \"planning\"");
|
|
expect(assignment).toContain("Make the plan only. Do not write code or perform implementation work.");
|
|
|
|
const commentWake = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-1",
|
|
identifier: "PAP-3404",
|
|
title: "Plan first",
|
|
workMode: "planning",
|
|
description: null,
|
|
},
|
|
wakeComment: {
|
|
id: "comment-1",
|
|
body: "Please revise the plan.",
|
|
},
|
|
});
|
|
|
|
expect(commentWake).toContain("Update the plan only. Do not write code or perform implementation work.");
|
|
|
|
const acceptedConfirmation = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-1",
|
|
identifier: "PAP-3404",
|
|
title: "Plan first",
|
|
workMode: "planning",
|
|
description: null,
|
|
},
|
|
interaction: {
|
|
kind: "request_confirmation",
|
|
status: "accepted",
|
|
},
|
|
});
|
|
|
|
expect(acceptedConfirmation).toContain(
|
|
"Implement the accepted plan on this issue when the work is small and cohesive.",
|
|
);
|
|
expect(acceptedConfirmation).not.toContain("Make the plan only.");
|
|
});
|
|
|
|
it("adds accepted-plan continuation guidance for standard-work issues when the wake is flagged as a plan continuation", () => {
|
|
const acceptedConfirmation = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-2",
|
|
identifier: "PAP-415",
|
|
title: "Implement the fix",
|
|
workMode: "standard",
|
|
description: null,
|
|
},
|
|
acceptedPlanContinuation: true,
|
|
});
|
|
|
|
expect(acceptedConfirmation).toContain("Accepted plan directive:");
|
|
expect(acceptedConfirmation).toContain(
|
|
"Implement the accepted plan on this issue when the work is small and cohesive.",
|
|
);
|
|
expect(acceptedConfirmation).not.toContain("- Work mode: \"planning\"");
|
|
});
|
|
|
|
it("adds answer-only guidance for ask-mode issues", () => {
|
|
const assignment = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-ask",
|
|
identifier: "PAP-416",
|
|
title: "Explain the tradeoff",
|
|
workMode: "ask",
|
|
description: null,
|
|
},
|
|
});
|
|
|
|
expect(assignment).toContain("- Work mode: \"ask\"");
|
|
expect(assignment).toContain("Ask mode directive:");
|
|
expect(assignment).toContain("Answer the question directly in the issue thread.");
|
|
expect(assignment).toContain("Do not write implementation code");
|
|
expect(assignment).toContain("do not produce an implementation plan");
|
|
});
|
|
|
|
it("adds dry-run containment guidance for skill-test issues", () => {
|
|
const assignment = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-skill-test",
|
|
identifier: "PAP-417",
|
|
title: "Test skill draft",
|
|
workMode: "skill_test",
|
|
description: null,
|
|
},
|
|
});
|
|
|
|
expect(assignment).toContain("- Work mode: \"skill_test\"");
|
|
expect(assignment).toContain("Skill test mode directive:");
|
|
expect(assignment).toContain("Make no durable changes outside this issue.");
|
|
expect(assignment).toContain("Write your final output as issue document `output`");
|
|
});
|
|
|
|
it("strips the description for the compact resume variant but keeps directives and the wake comment", () => {
|
|
const input = {
|
|
issue: {
|
|
id: "issue-1",
|
|
identifier: "PAP-3404",
|
|
title: "Ship the fix",
|
|
workMode: "standard",
|
|
description: "Full multi-paragraph brief that the session already received.",
|
|
},
|
|
wakeComment: {
|
|
id: "comment-1",
|
|
body: "Please also update the changelog.",
|
|
},
|
|
};
|
|
|
|
const full = buildPaperclipTaskMarkdown(input);
|
|
expect(full).toContain("Issue description:");
|
|
expect(full).toContain("Full multi-paragraph brief that the session already received.");
|
|
|
|
const compact = buildPaperclipTaskMarkdown({ ...input, includeDescription: false });
|
|
expect(compact).not.toContain("Issue description:");
|
|
expect(compact).not.toContain("Full multi-paragraph brief");
|
|
expect(compact).toContain("- Issue: \"PAP-3404\"");
|
|
expect(compact).toContain("Please also update the changelog.");
|
|
});
|
|
|
|
it("makes the latest wake comment the immediate follow-up request", () => {
|
|
const commentWake = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-follow-up",
|
|
identifier: "PAP-418",
|
|
title: "Original task",
|
|
workMode: "standard",
|
|
description: "Reply with the original answer.",
|
|
},
|
|
wakeComment: {
|
|
id: "comment-follow-up",
|
|
body: "Reply with the new answer instead.",
|
|
},
|
|
});
|
|
|
|
expect(commentWake).toContain("Apply the latest wake comment to the current task.");
|
|
expect(commentWake).toContain("Later direction replaces conflicting scope");
|
|
expect(commentWake).toContain("preserve other requirements and approval gates");
|
|
expect(commentWake).not.toContain("unless the latest comment asks you to");
|
|
expect(commentWake).toContain("Reply with the new answer instead.");
|
|
});
|
|
|
|
it("prefers ordinary comment planning guidance over stale accepted confirmation state", () => {
|
|
const commentWake = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-1",
|
|
identifier: "PAP-3404",
|
|
title: "Plan first",
|
|
workMode: "planning",
|
|
description: null,
|
|
},
|
|
wakeComment: {
|
|
id: "comment-1",
|
|
body: "Please revise the plan.",
|
|
},
|
|
interaction: {
|
|
kind: "request_confirmation",
|
|
status: "accepted",
|
|
},
|
|
});
|
|
|
|
expect(commentWake).toContain("Update the plan only. Do not write code or perform implementation work.");
|
|
expect(commentWake).not.toContain("Create child issues from the approved plan only");
|
|
});
|
|
});
|
|
|
|
describe("mergeCoalescedContextSnapshot", () => {
|
|
it("clears stale accepted-plan interaction state when merging a later ordinary comment wake", () => {
|
|
const merged = mergeCoalescedContextSnapshot(
|
|
{
|
|
issueId: "issue-1",
|
|
interactionId: "interaction-1",
|
|
interactionKind: "request_confirmation",
|
|
interactionStatus: "accepted",
|
|
continuationPolicy: "wake_assignee_on_accept",
|
|
checkboxSelection: {
|
|
prompt: "Delete selected files?",
|
|
selectedOptionIds: ["file-b"],
|
|
selectedOptions: [{ id: "file-b", label: "b.txt", description: "Generated build output" }],
|
|
},
|
|
wakeReason: "issue_commented",
|
|
},
|
|
{
|
|
issueId: "issue-1",
|
|
commentId: "comment-1",
|
|
wakeCommentId: "comment-1",
|
|
wakeReason: "issue_commented",
|
|
},
|
|
);
|
|
|
|
expect(merged.interactionId).toBeUndefined();
|
|
expect(merged.interactionKind).toBeUndefined();
|
|
expect(merged.interactionStatus).toBeUndefined();
|
|
expect(merged.continuationPolicy).toBeUndefined();
|
|
expect(merged.checkboxSelection).toBeUndefined();
|
|
expect(merged.commentId).toBe("comment-1");
|
|
expect(merged.wakeCommentId).toBe("comment-1");
|
|
});
|
|
|
|
it("preserves resolved interaction state for the interaction wake itself", () => {
|
|
const merged = mergeCoalescedContextSnapshot(
|
|
{
|
|
issueId: "issue-1",
|
|
},
|
|
{
|
|
issueId: "issue-1",
|
|
interactionId: "interaction-1",
|
|
interactionKind: "request_confirmation",
|
|
interactionStatus: "accepted",
|
|
continuationPolicy: "wake_assignee_on_accept",
|
|
checkboxSelection: {
|
|
prompt: "Delete selected files?",
|
|
selectedOptionIds: ["file-b"],
|
|
selectedOptions: [{ id: "file-b", label: "b.txt", description: "Generated build output" }],
|
|
},
|
|
wakeReason: "issue_commented",
|
|
},
|
|
);
|
|
|
|
expect(merged.interactionId).toBe("interaction-1");
|
|
expect(merged.interactionKind).toBe("request_confirmation");
|
|
expect(merged.interactionStatus).toBe("accepted");
|
|
expect(merged.continuationPolicy).toBe("wake_assignee_on_accept");
|
|
expect(merged.checkboxSelection).toEqual({
|
|
prompt: "Delete selected files?",
|
|
selectedOptionIds: ["file-b"],
|
|
selectedOptions: [{ id: "file-b", label: "b.txt", description: "Generated build output" }],
|
|
});
|
|
});
|
|
|
|
it("preserves a deferred interaction when a later comment joins its successor wake", () => {
|
|
const merged = mergeCoalescedContextSnapshot(
|
|
{
|
|
issueId: "issue-1",
|
|
interactionId: "interaction-1",
|
|
interactionKind: "request_confirmation",
|
|
interactionStatus: "accepted",
|
|
continuationPolicy: "wake_assignee_on_accept",
|
|
wakeReason: "issue_commented",
|
|
},
|
|
{
|
|
issueId: "issue-1",
|
|
commentId: "comment-1",
|
|
wakeCommentId: "comment-1",
|
|
wakeReason: "issue_commented",
|
|
},
|
|
{ preserveExistingInteractionContinuation: true },
|
|
);
|
|
|
|
expect(merged.interactionId).toBe("interaction-1");
|
|
expect(merged.interactionKind).toBe("request_confirmation");
|
|
expect(merged.interactionStatus).toBe("accepted");
|
|
expect(merged.continuationPolicy).toBe("wake_assignee_on_accept");
|
|
expect(merged.commentId).toBe("comment-1");
|
|
expect(merged.wakeCommentId).toBe("comment-1");
|
|
});
|
|
|
|
it("keeps a queued comment when an interaction joins its successor wake", () => {
|
|
const merged = mergeCoalescedContextSnapshot(
|
|
{
|
|
issueId: "issue-1",
|
|
commentId: "comment-1",
|
|
wakeCommentId: "comment-1",
|
|
wakeCommentIds: ["comment-1"],
|
|
wakeReason: "issue_commented",
|
|
},
|
|
{
|
|
issueId: "issue-1",
|
|
interactionId: "interaction-1",
|
|
interactionKind: "ask_user_questions",
|
|
interactionStatus: "answered",
|
|
continuationPolicy: "wake_assignee_on_accept",
|
|
wakeReason: "issue_commented",
|
|
},
|
|
{ preserveExistingInteractionContinuation: true },
|
|
);
|
|
|
|
expect(merged.interactionId).toBe("interaction-1");
|
|
expect(merged.interactionKind).toBe("ask_user_questions");
|
|
expect(merged.interactionStatus).toBe("answered");
|
|
expect(merged.commentId).toBe("comment-1");
|
|
expect(merged.wakeCommentId).toBe("comment-1");
|
|
expect(merged.wakeCommentIds).toEqual(["comment-1"]);
|
|
});
|
|
});
|
|
|
|
describe("summarizeHeartbeatRunContextSnapshot", () => {
|
|
it("keeps only the small retry/linking fields needed by the client", () => {
|
|
const summarized = summarizeHeartbeatRunContextSnapshot({
|
|
issueId: "issue-1",
|
|
taskId: "task-1",
|
|
taskKey: "PAP-1",
|
|
commentId: "comment-1",
|
|
wakeCommentId: "comment-2",
|
|
wakeReason: "retry_failed_run",
|
|
wakeSource: "on_demand",
|
|
wakeTriggerDetail: "manual",
|
|
paperclipWake: {
|
|
comments: [
|
|
{
|
|
body: "x".repeat(50_000),
|
|
},
|
|
],
|
|
},
|
|
executionStage: {
|
|
summary: "large nested object that should not be sent back in run lists",
|
|
},
|
|
});
|
|
|
|
expect(summarized).toEqual({
|
|
issueId: "issue-1",
|
|
taskId: "task-1",
|
|
taskKey: "PAP-1",
|
|
commentId: "comment-1",
|
|
wakeCommentId: "comment-2",
|
|
wakeReason: "retry_failed_run",
|
|
wakeSource: "on_demand",
|
|
wakeTriggerDetail: "manual",
|
|
});
|
|
});
|
|
|
|
it("returns null when no allowed fields are present", () => {
|
|
expect(
|
|
summarizeHeartbeatRunContextSnapshot({
|
|
paperclipWake: { comments: [{ body: "hello" }] },
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("summarizeHeartbeatRunListResultJson", () => {
|
|
it("keeps only summary fields and parses numeric cost aliases", () => {
|
|
expect(
|
|
summarizeHeartbeatRunListResultJson({
|
|
summary: "Completed the task",
|
|
result: "Updated three files",
|
|
message: "",
|
|
error: null,
|
|
totalCostUsd: "1.25",
|
|
costUsd: "0.75",
|
|
costUsdCamel: "0.5",
|
|
}),
|
|
).toEqual({
|
|
summary: "Completed the task",
|
|
result: "Updated three files",
|
|
total_cost_usd: 1.25,
|
|
cost_usd: 0.75,
|
|
costUsd: 0.5,
|
|
});
|
|
});
|
|
|
|
it("returns null when projected fields are empty", () => {
|
|
expect(
|
|
summarizeHeartbeatRunListResultJson({
|
|
summary: "",
|
|
result: null,
|
|
message: undefined,
|
|
error: " ",
|
|
totalCostUsd: "abc",
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
});
|