mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-06 10:48:12 +02:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Agents request human input through durable issue interactions. > - A question form has a canonical presentation and a compatibility storage format. > - The creation API required agents to write both formats. > - Tool guidance told agents to split text and choice questions across those formats. > - This pull request accepts one complete canonical form and derives storage fields on the server. > - The benefit is a complete question card with stable answer and retry behavior. ## Linked Issues or Issue Description Related work: Refs #13630 and #14430. PR #13630 addresses the display of historical partial forms. This change fixes creation and keeps the check that rejects conflicting new forms. **What happened?** A question save supplied three compatibility questions and one canonical text question. The API correctly rejected the incomplete canonical form. The Runner's tool description encouraged this split. Sending only a complete canonical form also failed because the API required compatibility questions. **Expected behavior** An agent sends one complete `payload.questionSet` with every text and choice question. Paperclip derives `payload.questions` for storage and answer compatibility. Existing legacy requests remain valid. Explicitly conflicting dual forms remain invalid. **Steps to reproduce** 1. Call `paperclip_request_human_input` with `interactionKind: "questions"`. 2. Send `payload: { version: 1, questionSet: ... }` with a required text question and a required choice question. 3. The old API rejects the missing compatibility questions. With this change, it stores both questions and preserves the canonical form. 4. Retry with the same idempotency key. Confirm that only one interaction exists. 5. Submit both answers. Confirm that the normal resolver and continuation rules apply. **Paperclip version or commit** The branch is based on `cf8ad63c8`. The problem affects the native Runner and the interaction creation API. **Deployment mode** Server deployment with the native Paperclip Runner. Integration tests use the real interaction service and an embedded test database. ## What Changed - Add one shared canonical-to-storage projection. Reuse it for native harness question requests. - Accept canonical-only question creation at the shared validator and server boundary. - Export the input type and update the plugin SDK and its RPC contract. - Advertise a typed, complete question form in the live and scenario tool schemas. - Enforce canonical text and custom-answer constraints before ordinary or native resolution. Preserve harmless display whitespace. - Run regex matching in isolated workers with a deadline and resource limits. Both answer paths await the result before persistence. Saved native delivery uses the validated answer without taking another worker slot. - Update agent guidance and generated Runner contracts. - Test mixed forms, option-ID collisions, retries, answers, legacy requests, and conflicting forms. ## Verification - Interaction service, HTTP route, native bridge, and Runner authority suites: 221 tests passed after correcting an obsolete tool-description assertion. - Shared validator, plugin SDK, CLI, and UI compatibility suites: 67 tests passed. - Runner core tool-contract suite: 20 tests passed. AJV validates live and scenario schemas. - Final review regressions: 172 shared, service, native bridge, and authority tests passed. These cover text length, pattern, numeric limits, whitespace, custom option IDs, and historical pending cards. - Runner session suites: 67 tests passed. Published example tests: 4 tests passed. - Server typecheck and the shared/server builds passed after the compatibility fixes. - Final delivery verification: 35 response-delivery tests passed. The native delivery regression proves saved answers do not enter pattern workers; server typecheck and build passed. - Pattern security and answer-flow verification: 205 tests passed after repairing the child fixture loader. These cover pathological matching, event-loop responsiveness, worker concurrency, slot cleanup, HTTP routes, native delivery, and the full helper in a child process. - `pnpm -r typecheck` passed on the bounded-worker revision. - `pnpm build` passed on the bounded-worker revision. - All 55 GitHub checks passed on `fe457af`; four optional jobs were skipped. An unchanged Cursor adapter test timed out once in CI, passed locally, and passed on one failed-job rerun. - Reviewers can send the canonical-only mixed form above and verify that the saved interaction contains both canonical and compatibility questions. ## Risks - The creation API accepts a new input shape. Stored rows and answer contracts keep the existing shape. - The shared projection must preserve synthetic free-text option IDs. Collision and native round-trip tests cover this behavior. - Historical partial rows remain readable. New conflicting dual forms, including written-answer mismatches, remain rejected. - Existing pending cards retain the written-answer paths offered by their stored options. Canonical text constraints still apply. - Ordinary answers now enforce declared canonical constraints before persistence. Invalid answers leave the card pending. - Regex validation has a one-second deadline and a four-worker capacity limit. A complex pattern or capacity error leaves the card pending with a validation error. - No database migration or change to company authorization is required. ## Model Used - OpenAI GPT-6 through Codex. The session exposes the GPT-6 model family; its exact runtime model identifier and context window size are not exposed. Used reasoning, 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 - [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>
167 lines
5.5 KiB
TypeScript
167 lines
5.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { createTestHarness } from "../src/testing.js";
|
|
import type { PaperclipPluginManifestV1 } from "../src/types.js";
|
|
|
|
const manifest = {
|
|
id: "paperclip.test-actions",
|
|
apiVersion: 1,
|
|
version: "1.0.0",
|
|
displayName: "Test Actions",
|
|
description: "Test plugin",
|
|
author: "Paperclip",
|
|
categories: ["automation"],
|
|
capabilities: [],
|
|
entrypoints: {},
|
|
} satisfies PaperclipPluginManifestV1;
|
|
|
|
describe("createTestHarness action context", () => {
|
|
it("passes immutable authenticated actor context and overrides caller company scope", async () => {
|
|
const harness = createTestHarness({ manifest });
|
|
|
|
harness.ctx.actions.register("inspect", async (params, context) => ({
|
|
paramsCompanyId: params.companyId,
|
|
actor: context.actor,
|
|
companyId: context.companyId,
|
|
contextFrozen: Object.isFrozen(context),
|
|
actorFrozen: Object.isFrozen(context.actor),
|
|
}));
|
|
|
|
const result = await harness.performAction<{
|
|
paramsCompanyId: unknown;
|
|
actor: {
|
|
type: string;
|
|
userId: string | null;
|
|
agentId: string | null;
|
|
runId: string | null;
|
|
companyId: string | null;
|
|
};
|
|
companyId: string | null;
|
|
contextFrozen: boolean;
|
|
actorFrozen: boolean;
|
|
}>(
|
|
"inspect",
|
|
{ companyId: "spoofed-company", value: true },
|
|
{
|
|
companyId: "host-company",
|
|
actor: {
|
|
type: "user",
|
|
userId: "board-user-1",
|
|
runId: "run-1",
|
|
},
|
|
},
|
|
);
|
|
|
|
expect(result.paramsCompanyId).toBe("host-company");
|
|
expect(result.companyId).toBe("host-company");
|
|
expect(result.actor).toEqual({
|
|
type: "user",
|
|
userId: "board-user-1",
|
|
agentId: null,
|
|
runId: "run-1",
|
|
companyId: "host-company",
|
|
});
|
|
expect(result.contextFrozen).toBe(true);
|
|
expect(result.actorFrozen).toBe(true);
|
|
});
|
|
|
|
it("keeps existing one-argument action handlers compatible", async () => {
|
|
const harness = createTestHarness({ manifest });
|
|
harness.ctx.actions.register("legacy", async (params) => ({ ok: params.ok }));
|
|
|
|
await expect(harness.performAction("legacy", { ok: true })).resolves.toEqual({ ok: true });
|
|
});
|
|
});
|
|
|
|
describe("createTestHarness managed routines", () => {
|
|
it("preserves declared activity gate settings", async () => {
|
|
const harness = createTestHarness({
|
|
manifest: {
|
|
...manifest,
|
|
capabilities: ["routines.managed"],
|
|
routines: [{
|
|
routineKey: "quiet-watcher",
|
|
title: "Quiet watcher",
|
|
activityGatePolicy: "require_external_activity",
|
|
activityGateScope: "project",
|
|
}],
|
|
},
|
|
});
|
|
|
|
const resolved = await harness.ctx.routines.managed.reconcile("quiet-watcher", "company-1");
|
|
|
|
expect(resolved.routine).toMatchObject({
|
|
activityGatePolicy: "require_external_activity",
|
|
activityGateScope: "project",
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("createTestHarness issue interactions", () => {
|
|
it("normalizes a canonical question form through the typed host helper", async () => {
|
|
const harness = createTestHarness({ manifest, capabilities: ["issues.create", "issue.interactions.create"] });
|
|
const issue = await harness.ctx.issues.create({ companyId: "company-1", title: "Ask for a repository" });
|
|
const input = {
|
|
idempotencyKey: "canonical:repo",
|
|
payload: { version: 1 as const, questionSet: { schema: "paperclip.question_set.v1" as const, questions: [{ id: "repo", prompt: "Repository URL?", required: true, answerMode: "text" as const }] } },
|
|
};
|
|
const created = await harness.ctx.issues.askUserQuestions(issue.id, input, "company-1");
|
|
expect(created.payload.questionSet).toEqual(input.payload.questionSet);
|
|
expect(created.payload.questions).toMatchObject([{ id: "repo", options: [{ id: "paperclip_text_answer", freeText: true }] }]);
|
|
expect(await harness.ctx.issues.askUserQuestions(issue.id, input, "company-1")).toEqual(created);
|
|
});
|
|
it("creates request_checkbox_confirmation interactions through the typed host helper", async () => {
|
|
const harness = createTestHarness({
|
|
manifest,
|
|
capabilities: ["issues.create", "issue.interactions.create"],
|
|
});
|
|
const issue = await harness.ctx.issues.create({
|
|
companyId: "company-1",
|
|
title: "Pick files",
|
|
});
|
|
|
|
const interaction = await harness.ctx.issues.requestCheckboxConfirmation(
|
|
issue.id,
|
|
{
|
|
idempotencyKey: "checkbox:files",
|
|
title: "Choose files",
|
|
payload: {
|
|
version: 1,
|
|
prompt: "Which files should be included?",
|
|
options: [
|
|
{ id: "file-a", label: "File A" },
|
|
{ id: "file-b", label: "File B", description: "Secondary draft" },
|
|
],
|
|
defaultSelectedOptionIds: ["file-a"],
|
|
minSelected: 1,
|
|
maxSelected: 2,
|
|
},
|
|
},
|
|
"company-1",
|
|
{ authorAgentId: "agent-1" },
|
|
);
|
|
|
|
expect(interaction).toMatchObject({
|
|
issueId: issue.id,
|
|
companyId: "company-1",
|
|
kind: "request_checkbox_confirmation",
|
|
status: "pending",
|
|
continuationPolicy: "wake_assignee",
|
|
idempotencyKey: "checkbox:files",
|
|
title: "Choose files",
|
|
createdByAgentId: "agent-1",
|
|
payload: {
|
|
version: 1,
|
|
prompt: "Which files should be included?",
|
|
options: [
|
|
{ id: "file-a", label: "File A" },
|
|
{ id: "file-b", label: "File B", description: "Secondary draft" },
|
|
],
|
|
defaultSelectedOptionIds: ["file-a"],
|
|
minSelected: 1,
|
|
maxSelected: 2,
|
|
},
|
|
});
|
|
});
|
|
});
|