mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 15:52:36 +01:00
test: retire redundant suites and consolidate owner coverage (#15978)
Retire duplicate ACPX and Codex proof after migrating unique assertions to their behavioral owners. Consolidate repeated fixtures and exact case matrices while preserving lifecycle, protocol, company, credential, approval, and ordering contracts. Remove the unused runtime-controls compatibility path and document test ownership and preservation evidence. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
94e4218310
commit
1e0cfcb4fc
43 files changed
+3460
-15030
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -10825,158 +10825,42 @@ describeEmbeddedPostgres("heartbeat orphaned process recovery", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it("requeues accepted interaction continuations stranded in_review without execution state", async () => {
|
||||
const companyId = randomUUID();
|
||||
const agentId = randomUUID();
|
||||
const issueId = randomUUID();
|
||||
const interactionId = randomUUID();
|
||||
|
||||
async function seedResolvedInteractionRecoveryFixture(input: {
|
||||
title: string;
|
||||
kind?: "request_confirmation" | "ask_user_questions";
|
||||
issueStatus?: "in_review" | "in_progress";
|
||||
agentName?: string;
|
||||
}) {
|
||||
const companyId = randomUUID(), agentId = randomUUID(), issueId = randomUUID(), interactionId = randomUUID();
|
||||
const resolvedAt = new Date("2026-03-19T00:05:00.000Z");
|
||||
const issuePrefix = `T${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`;
|
||||
|
||||
await db.insert(companies).values({
|
||||
id: companyId,
|
||||
name: "Paperclip",
|
||||
issuePrefix,
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
id: companyId, name: "Paperclip", issuePrefix, defaultResponsibleUserId: "responsible-user", requireBoardApprovalForNewAgents: false,
|
||||
});
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
name: "CodexCoder",
|
||||
role: "engineer",
|
||||
status: "idle",
|
||||
adapterType: "codex_local",
|
||||
adapterConfig: {},
|
||||
runtimeConfig: {
|
||||
heartbeat: { wakeOnDemand: true, maxConcurrentRuns: 1 },
|
||||
},
|
||||
permissions: {},
|
||||
id: agentId, companyId, name: input.agentName ?? "CodexCoder", role: "engineer", status: "idle", adapterType: "codex_local", adapterConfig: {},
|
||||
runtimeConfig: { heartbeat: { wakeOnDemand: true, maxConcurrentRuns: 1 } }, permissions: {},
|
||||
});
|
||||
await db.insert(issues).values({
|
||||
id: issueId,
|
||||
companyId,
|
||||
title: "Accepted plan never resumed",
|
||||
status: "in_review",
|
||||
priority: "medium",
|
||||
assigneeAgentId: agentId,
|
||||
responsibleUserId: "responsible-user",
|
||||
issueNumber: 1,
|
||||
identifier: `${issuePrefix}-1`,
|
||||
id: issueId, companyId, title: input.title, status: input.issueStatus ?? "in_review", priority: "medium", assigneeAgentId: agentId,
|
||||
responsibleUserId: "responsible-user", issueNumber: 1, identifier: `${issuePrefix}-1`,
|
||||
});
|
||||
const kind = input.kind ?? "request_confirmation";
|
||||
await db.insert(issueThreadInteractions).values({
|
||||
id: interactionId,
|
||||
companyId,
|
||||
issueId,
|
||||
kind: "request_confirmation",
|
||||
status: "accepted",
|
||||
continuationPolicy: "wake_assignee_on_accept",
|
||||
createdByAgentId: agentId,
|
||||
resolvedByUserId: "responsible-user",
|
||||
resolvedAt,
|
||||
updatedAt: resolvedAt,
|
||||
payload: { version: 1, prompt: "Approve the plan?" },
|
||||
result: { outcome: "accepted" },
|
||||
id: interactionId, companyId, issueId, kind, status: kind === "ask_user_questions" ? "answered" : "accepted",
|
||||
continuationPolicy: "wake_assignee_on_accept", createdByAgentId: agentId, resolvedByUserId: "responsible-user", resolvedAt, updatedAt: resolvedAt,
|
||||
payload: kind === "ask_user_questions" ? { version: 1, questions: [{
|
||||
id: "format", prompt: "Choose a format", selectionMode: "single", required: true, options: [{ id: "markdown", label: "Markdown" }],
|
||||
}] } : { version: 1, prompt: "Approve the plan?" },
|
||||
result: kind === "ask_user_questions" ? { version: 1, answers: [{ questionId: "format", optionIds: ["markdown"] }] } : { outcome: "accepted" },
|
||||
});
|
||||
|
||||
const heartbeat = heartbeatService(db);
|
||||
const result = await heartbeat.reconcileStrandedAssignedIssues();
|
||||
|
||||
expect(result.continuationRequeued).toBe(1);
|
||||
expect(result.issueIds).toEqual([issueId]);
|
||||
|
||||
const run = await db
|
||||
.select({
|
||||
agentId: heartbeatRuns.agentId,
|
||||
contextSnapshot: heartbeatRuns.contextSnapshot,
|
||||
retryOfRunId: heartbeatRuns.retryOfRunId,
|
||||
})
|
||||
.from(heartbeatRuns)
|
||||
.where(eq(heartbeatRuns.agentId, agentId))
|
||||
.then((rows) => rows[0] ?? null);
|
||||
expect(run?.agentId).toBe(agentId);
|
||||
expect(run?.retryOfRunId).toBeNull();
|
||||
expect(run?.contextSnapshot).toMatchObject({
|
||||
issueId,
|
||||
taskId: issueId,
|
||||
wakeReason: "issue_continuation_needed",
|
||||
retryReason: "issue_continuation_needed",
|
||||
source: "issue.interaction_continuation_recovery",
|
||||
interactionId,
|
||||
interactionKind: "request_confirmation",
|
||||
interactionStatus: "accepted",
|
||||
interactionContinuationPolicy: "wake_assignee_on_accept",
|
||||
interactionResolvedAt: resolvedAt.toISOString(),
|
||||
});
|
||||
});
|
||||
return { companyId, agentId, issueId, interactionId, resolvedAt };
|
||||
}
|
||||
|
||||
it("recovers an answered question with its interaction-specific continuation context", async () => {
|
||||
const companyId = randomUUID();
|
||||
const agentId = randomUUID();
|
||||
const issueId = randomUUID();
|
||||
const interactionId = randomUUID();
|
||||
const resolvedAt = new Date("2026-03-19T00:05:00.000Z");
|
||||
const issuePrefix = `T${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`;
|
||||
|
||||
await db.insert(companies).values({
|
||||
id: companyId,
|
||||
name: "Paperclip",
|
||||
issuePrefix,
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
});
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
name: "OpenCodeCoder",
|
||||
role: "engineer",
|
||||
status: "idle",
|
||||
adapterType: "codex_local",
|
||||
adapterConfig: {},
|
||||
runtimeConfig: {
|
||||
heartbeat: { wakeOnDemand: true, maxConcurrentRuns: 1 },
|
||||
},
|
||||
permissions: {},
|
||||
});
|
||||
await db.insert(issues).values({
|
||||
id: issueId,
|
||||
companyId,
|
||||
title: "Answered question never resumed",
|
||||
status: "in_progress",
|
||||
priority: "medium",
|
||||
assigneeAgentId: agentId,
|
||||
responsibleUserId: "responsible-user",
|
||||
issueNumber: 1,
|
||||
identifier: `${issuePrefix}-1`,
|
||||
});
|
||||
await db.insert(issueThreadInteractions).values({
|
||||
id: interactionId,
|
||||
companyId,
|
||||
issueId,
|
||||
kind: "ask_user_questions",
|
||||
status: "answered",
|
||||
continuationPolicy: "wake_assignee_on_accept",
|
||||
createdByAgentId: agentId,
|
||||
resolvedByUserId: "responsible-user",
|
||||
resolvedAt,
|
||||
updatedAt: resolvedAt,
|
||||
payload: {
|
||||
version: 1,
|
||||
questions: [
|
||||
{
|
||||
id: "format",
|
||||
prompt: "Choose a format",
|
||||
selectionMode: "single",
|
||||
required: true,
|
||||
options: [{ id: "markdown", label: "Markdown" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
result: {
|
||||
version: 1,
|
||||
answers: [{ questionId: "format", optionIds: ["markdown"] }],
|
||||
},
|
||||
});
|
||||
const { companyId, agentId, issueId, interactionId, resolvedAt } =
|
||||
await seedResolvedInteractionRecoveryFixture({ title: "Answered question never resumed", kind: "ask_user_questions", issueStatus: "in_progress", agentName: "OpenCodeCoder" });
|
||||
|
||||
const heartbeat = heartbeatService(db);
|
||||
const result = await heartbeat.reconcileStrandedAssignedIssues();
|
||||
@@ -11085,58 +10969,8 @@ describeEmbeddedPostgres("heartbeat orphaned process recovery", () => {
|
||||
});
|
||||
|
||||
it("counts five historical review-park cancellations against the upgraded disposition-repair ceiling", async () => {
|
||||
const companyId = randomUUID();
|
||||
const agentId = randomUUID();
|
||||
const issueId = randomUUID();
|
||||
const interactionId = randomUUID();
|
||||
const resolvedAt = new Date("2026-03-19T00:05:00.000Z");
|
||||
const issuePrefix = `T${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`;
|
||||
|
||||
await db.insert(companies).values({
|
||||
id: companyId,
|
||||
name: "Paperclip",
|
||||
issuePrefix,
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
});
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
name: "CodexCoder",
|
||||
role: "engineer",
|
||||
status: "idle",
|
||||
adapterType: "codex_local",
|
||||
adapterConfig: {},
|
||||
runtimeConfig: {
|
||||
heartbeat: { wakeOnDemand: true, maxConcurrentRuns: 1 },
|
||||
},
|
||||
permissions: {},
|
||||
});
|
||||
await db.insert(issues).values({
|
||||
id: issueId,
|
||||
companyId,
|
||||
title: "Accepted plan cancellation loop",
|
||||
status: "in_review",
|
||||
priority: "medium",
|
||||
assigneeAgentId: agentId,
|
||||
responsibleUserId: "responsible-user",
|
||||
issueNumber: 1,
|
||||
identifier: `${issuePrefix}-1`,
|
||||
});
|
||||
await db.insert(issueThreadInteractions).values({
|
||||
id: interactionId,
|
||||
companyId,
|
||||
issueId,
|
||||
kind: "request_confirmation",
|
||||
status: "accepted",
|
||||
continuationPolicy: "wake_assignee_on_accept",
|
||||
createdByAgentId: agentId,
|
||||
resolvedByUserId: "responsible-user",
|
||||
resolvedAt,
|
||||
updatedAt: resolvedAt,
|
||||
payload: { version: 1, prompt: "Approve the plan?" },
|
||||
result: { outcome: "accepted" },
|
||||
});
|
||||
const { companyId, agentId, issueId, interactionId, resolvedAt } =
|
||||
await seedResolvedInteractionRecoveryFixture({ title: "Accepted plan cancellation loop" });
|
||||
for (let attempt = 1; attempt <= 5; attempt += 1) {
|
||||
const finishedAt = new Date(resolvedAt.getTime() + attempt * 60_000);
|
||||
await db.insert(heartbeatRuns).values({
|
||||
@@ -11227,59 +11061,9 @@ describeEmbeddedPostgres("heartbeat orphaned process recovery", () => {
|
||||
});
|
||||
|
||||
it("skips accepted interaction recovery after its continuation succeeds", async () => {
|
||||
const companyId = randomUUID();
|
||||
const agentId = randomUUID();
|
||||
const issueId = randomUUID();
|
||||
const interactionId = randomUUID();
|
||||
const resolvedAt = new Date("2026-03-19T00:05:00.000Z");
|
||||
const { companyId, agentId, issueId, interactionId, resolvedAt } =
|
||||
await seedResolvedInteractionRecoveryFixture({ title: "Accepted plan already resumed" });
|
||||
const succeededAt = new Date("2026-03-19T00:06:00.000Z");
|
||||
const issuePrefix = `T${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`;
|
||||
|
||||
await db.insert(companies).values({
|
||||
id: companyId,
|
||||
name: "Paperclip",
|
||||
issuePrefix,
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
});
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
name: "CodexCoder",
|
||||
role: "engineer",
|
||||
status: "idle",
|
||||
adapterType: "codex_local",
|
||||
adapterConfig: {},
|
||||
runtimeConfig: {
|
||||
heartbeat: { wakeOnDemand: true, maxConcurrentRuns: 1 },
|
||||
},
|
||||
permissions: {},
|
||||
});
|
||||
await db.insert(issues).values({
|
||||
id: issueId,
|
||||
companyId,
|
||||
title: "Accepted plan already resumed",
|
||||
status: "in_review",
|
||||
priority: "medium",
|
||||
assigneeAgentId: agentId,
|
||||
responsibleUserId: "responsible-user",
|
||||
issueNumber: 1,
|
||||
identifier: `${issuePrefix}-1`,
|
||||
});
|
||||
await db.insert(issueThreadInteractions).values({
|
||||
id: interactionId,
|
||||
companyId,
|
||||
issueId,
|
||||
kind: "request_confirmation",
|
||||
status: "accepted",
|
||||
continuationPolicy: "wake_assignee_on_accept",
|
||||
createdByAgentId: agentId,
|
||||
resolvedByUserId: "responsible-user",
|
||||
resolvedAt,
|
||||
updatedAt: resolvedAt,
|
||||
payload: { version: 1, prompt: "Approve the plan?" },
|
||||
result: { outcome: "accepted" },
|
||||
});
|
||||
await db.insert(heartbeatRuns).values({
|
||||
id: randomUUID(),
|
||||
companyId,
|
||||
@@ -11316,59 +11100,9 @@ describeEmbeddedPostgres("heartbeat orphaned process recovery", () => {
|
||||
});
|
||||
|
||||
it("requeues accepted interaction continuations even when a later successful run is unrelated", async () => {
|
||||
const companyId = randomUUID();
|
||||
const agentId = randomUUID();
|
||||
const issueId = randomUUID();
|
||||
const interactionId = randomUUID();
|
||||
const resolvedAt = new Date("2026-03-19T00:05:00.000Z");
|
||||
const { companyId, agentId, issueId, interactionId, resolvedAt } =
|
||||
await seedResolvedInteractionRecoveryFixture({ title: "Accepted plan masked by unrelated run" });
|
||||
const unrelatedRunAt = new Date("2026-03-19T00:06:00.000Z");
|
||||
const issuePrefix = `T${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`;
|
||||
|
||||
await db.insert(companies).values({
|
||||
id: companyId,
|
||||
name: "Paperclip",
|
||||
issuePrefix,
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
});
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
name: "CodexCoder",
|
||||
role: "engineer",
|
||||
status: "idle",
|
||||
adapterType: "codex_local",
|
||||
adapterConfig: {},
|
||||
runtimeConfig: {
|
||||
heartbeat: { wakeOnDemand: true, maxConcurrentRuns: 1 },
|
||||
},
|
||||
permissions: {},
|
||||
});
|
||||
await db.insert(issues).values({
|
||||
id: issueId,
|
||||
companyId,
|
||||
title: "Accepted plan masked by unrelated run",
|
||||
status: "in_review",
|
||||
priority: "medium",
|
||||
assigneeAgentId: agentId,
|
||||
responsibleUserId: "responsible-user",
|
||||
issueNumber: 1,
|
||||
identifier: `${issuePrefix}-1`,
|
||||
});
|
||||
await db.insert(issueThreadInteractions).values({
|
||||
id: interactionId,
|
||||
companyId,
|
||||
issueId,
|
||||
kind: "request_confirmation",
|
||||
status: "accepted",
|
||||
continuationPolicy: "wake_assignee_on_accept",
|
||||
createdByAgentId: agentId,
|
||||
resolvedByUserId: "responsible-user",
|
||||
resolvedAt,
|
||||
updatedAt: resolvedAt,
|
||||
payload: { version: 1, prompt: "Approve the plan?" },
|
||||
result: { outcome: "accepted" },
|
||||
});
|
||||
await db.insert(heartbeatRuns).values({
|
||||
id: randomUUID(),
|
||||
companyId,
|
||||
@@ -11417,58 +11151,8 @@ describeEmbeddedPostgres("heartbeat orphaned process recovery", () => {
|
||||
// *no* wake request and *no* run at all. Pre-P1 the recovery sweep skipped in_review issues
|
||||
// lacking an execution policy, so this limbo persisted forever. The sweep now requeues it.
|
||||
it("recovers a plan approval whose accept-time continuation wake enqueue was silently dropped", async () => {
|
||||
const companyId = randomUUID();
|
||||
const agentId = randomUUID();
|
||||
const issueId = randomUUID();
|
||||
const interactionId = randomUUID();
|
||||
const resolvedAt = new Date("2026-03-19T00:05:00.000Z");
|
||||
const issuePrefix = `T${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`;
|
||||
|
||||
await db.insert(companies).values({
|
||||
id: companyId,
|
||||
name: "Paperclip",
|
||||
issuePrefix,
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
});
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
name: "CodexCoder",
|
||||
role: "engineer",
|
||||
status: "idle",
|
||||
adapterType: "codex_local",
|
||||
adapterConfig: {},
|
||||
runtimeConfig: {
|
||||
heartbeat: { wakeOnDemand: true, maxConcurrentRuns: 1 },
|
||||
},
|
||||
permissions: {},
|
||||
});
|
||||
await db.insert(issues).values({
|
||||
id: issueId,
|
||||
companyId,
|
||||
title: "Approved plan whose wake enqueue was dropped",
|
||||
status: "in_review",
|
||||
priority: "medium",
|
||||
assigneeAgentId: agentId,
|
||||
responsibleUserId: "responsible-user",
|
||||
issueNumber: 1,
|
||||
identifier: `${issuePrefix}-1`,
|
||||
});
|
||||
await db.insert(issueThreadInteractions).values({
|
||||
id: interactionId,
|
||||
companyId,
|
||||
issueId,
|
||||
kind: "request_confirmation",
|
||||
status: "accepted",
|
||||
continuationPolicy: "wake_assignee_on_accept",
|
||||
createdByAgentId: agentId,
|
||||
resolvedByUserId: "responsible-user",
|
||||
resolvedAt,
|
||||
updatedAt: resolvedAt,
|
||||
payload: { version: 1, prompt: "Approve the plan?" },
|
||||
result: { outcome: "accepted" },
|
||||
});
|
||||
const { companyId, agentId, issueId, interactionId, resolvedAt } =
|
||||
await seedResolvedInteractionRecoveryFixture({ title: "Approved plan whose wake enqueue was dropped" });
|
||||
|
||||
// Precondition of the silent-enqueue-drop bug: the accept produced no wake and no run.
|
||||
const priorWakeups = await db
|
||||
@@ -11492,15 +11176,23 @@ describeEmbeddedPostgres("heartbeat orphaned process recovery", () => {
|
||||
.select({
|
||||
agentId: heartbeatRuns.agentId,
|
||||
contextSnapshot: heartbeatRuns.contextSnapshot,
|
||||
retryOfRunId: heartbeatRuns.retryOfRunId,
|
||||
})
|
||||
.from(heartbeatRuns)
|
||||
.where(eq(heartbeatRuns.agentId, agentId))
|
||||
.then((rows) => rows[0] ?? null);
|
||||
expect(run?.agentId).toBe(agentId);
|
||||
expect(run?.retryOfRunId).toBeNull();
|
||||
expect(run?.contextSnapshot).toMatchObject({
|
||||
issueId,
|
||||
taskId: issueId,
|
||||
wakeReason: "issue_continuation_needed",
|
||||
retryReason: "issue_continuation_needed",
|
||||
interactionId,
|
||||
interactionKind: "request_confirmation",
|
||||
interactionStatus: "accepted",
|
||||
interactionContinuationPolicy: "wake_assignee_on_accept",
|
||||
interactionResolvedAt: resolvedAt.toISOString(),
|
||||
source: "issue.interaction_continuation_recovery",
|
||||
});
|
||||
|
||||
@@ -17032,5 +16724,4 @@ describeEmbeddedPostgres("heartbeat orphaned process recovery", () => {
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
@@ -1,79 +0,0 @@
|
||||
import fs from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
function assertReadOnlyInteractionsGet(source: string) {
|
||||
const start = source.search(
|
||||
/router\.get\(\s*["']\/issues\/:id\/interactions["']/,
|
||||
);
|
||||
expect(start).toBeGreaterThanOrEqual(0);
|
||||
const followingRoutes = source.slice(start);
|
||||
const end = followingRoutes.search(
|
||||
/router\.post\(\s*["']\/issues\/:id\/interactions["']/,
|
||||
);
|
||||
expect(end).toBeGreaterThan(0);
|
||||
const handler = followingRoutes.slice(0, end);
|
||||
|
||||
expect(handler).toContain("listForIssue");
|
||||
expect(handler).not.toContain("expireRequestConfirmations");
|
||||
expect(handler).not.toContain("expirePendingInteractions");
|
||||
expect(handler).not.toContain("logActivity");
|
||||
}
|
||||
|
||||
describe("issue interactions GET contract", () => {
|
||||
it("does not perform expiry sweeps or activity writes", () => {
|
||||
const source = fs.readFileSync(
|
||||
new URL("../routes/issues.ts", import.meta.url),
|
||||
"utf8",
|
||||
);
|
||||
assertReadOnlyInteractionsGet(source);
|
||||
});
|
||||
|
||||
it.each(["", "\n "])(
|
||||
"accepts a read-only GET with route whitespace %j",
|
||||
(whitespace) => {
|
||||
assertReadOnlyInteractionsGet(`
|
||||
router.get(${whitespace}"/issues/:id/interactions", async (req, res) => {
|
||||
res.json(await service.listForIssue(req.params.id));
|
||||
});
|
||||
router.post(${whitespace}"/issues/:id/interactions", async () => {
|
||||
await service.expirePendingInteractions();
|
||||
await logActivity();
|
||||
});
|
||||
`);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
"expireRequestConfirmations",
|
||||
"expirePendingInteractions",
|
||||
"logActivity",
|
||||
])("still rejects %s inside a formatted GET", (mutation) => {
|
||||
expect(() =>
|
||||
assertReadOnlyInteractionsGet(`
|
||||
router.get(
|
||||
"/issues/:id/interactions", async (req, res) => {
|
||||
await service.${mutation}();
|
||||
res.json(await service.listForIssue(req.params.id));
|
||||
},
|
||||
);
|
||||
router.post(
|
||||
"/issues/:id/interactions", async () => {},
|
||||
);
|
||||
`),
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it.each(["get", "post"])(
|
||||
"fails closed if the %s boundary is missing",
|
||||
(missingMethod) => {
|
||||
const routes = ["get", "post"]
|
||||
.filter((method) => method !== missingMethod)
|
||||
.map(
|
||||
(method) =>
|
||||
`router.${method}("/issues/:id/interactions", () => service.listForIssue());`,
|
||||
)
|
||||
.join("\n");
|
||||
expect(() => assertReadOnlyInteractionsGet(routes)).toThrow();
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -629,18 +629,21 @@ describe("issue thread interaction routes", () => {
|
||||
}), expect.anything());
|
||||
});
|
||||
|
||||
it("does not run historical-comment catch-up or queue recovery from the interaction read path", async () => {
|
||||
it.each(["in_review", "done"])("keeps interaction reads free of expiry, activity writes, and recovery while %s", async (status) => {
|
||||
mockIssueService.getById.mockResolvedValue(createIssue({
|
||||
status: "in_review",
|
||||
status,
|
||||
assigneeAgentId: ASSIGNEE_AGENT_ID,
|
||||
}));
|
||||
mockInteractionService.listForIssue.mockResolvedValue([]);
|
||||
|
||||
await request(await createApp())
|
||||
.get("/api/issues/aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa/interactions")
|
||||
.expect(200);
|
||||
.expect(200, []);
|
||||
|
||||
expect(mockInteractionService.listForIssue).toHaveBeenCalledExactlyOnceWith(ISSUE_ID);
|
||||
expect(mockInteractionService.expireRequestConfirmationsSupersededByHistoricalComments).not.toHaveBeenCalled();
|
||||
expect(mockInteractionService.expirePendingInteractionsForTerminalIssue).not.toHaveBeenCalled();
|
||||
expect(mockLogActivity).not.toHaveBeenCalled();
|
||||
expect(mockHeartbeatService.wakeup).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
@@ -5187,82 +5187,6 @@ describeEmbeddedPostgres("issueService.create workspace inheritance", () => {
|
||||
await tempDb?.cleanup();
|
||||
});
|
||||
|
||||
it("inherits the parent issue workspace linkage when child workspace fields are omitted", async () => {
|
||||
const companyId = randomUUID();
|
||||
const projectId = randomUUID();
|
||||
const parentIssueId = randomUUID();
|
||||
const projectWorkspaceId = randomUUID();
|
||||
const executionWorkspaceId = randomUUID();
|
||||
|
||||
await db.insert(companies).values({
|
||||
id: companyId,
|
||||
name: "Paperclip",
|
||||
issuePrefix: `T${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`,
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
});
|
||||
await instanceSettingsService(db).updateExperimental({ enableIsolatedWorkspaces: true });
|
||||
|
||||
await db.insert(projects).values({
|
||||
id: projectId,
|
||||
companyId,
|
||||
name: "Workspace project",
|
||||
status: "in_progress",
|
||||
});
|
||||
|
||||
await db.insert(projectWorkspaces).values({
|
||||
id: projectWorkspaceId,
|
||||
companyId,
|
||||
projectId,
|
||||
name: "Primary workspace",
|
||||
isPrimary: true,
|
||||
sharedWorkspaceKey: "workspace-key",
|
||||
});
|
||||
|
||||
await db.insert(executionWorkspaces).values({
|
||||
id: executionWorkspaceId,
|
||||
companyId,
|
||||
projectId,
|
||||
projectWorkspaceId,
|
||||
mode: "isolated_workspace",
|
||||
strategyType: "git_worktree",
|
||||
name: "Issue worktree",
|
||||
status: "active",
|
||||
providerType: "git_worktree",
|
||||
providerRef: `/tmp/${executionWorkspaceId}`,
|
||||
});
|
||||
|
||||
await db.insert(issues).values({
|
||||
id: parentIssueId,
|
||||
companyId,
|
||||
projectId,
|
||||
projectWorkspaceId,
|
||||
title: "Parent issue",
|
||||
status: "in_progress",
|
||||
priority: "medium",
|
||||
executionWorkspaceId,
|
||||
executionWorkspacePreference: "reuse_existing",
|
||||
executionWorkspaceSettings: {
|
||||
mode: "isolated_workspace",
|
||||
workspaceRuntime: { profile: "agent" },
|
||||
},
|
||||
});
|
||||
|
||||
const child = await svc.create(companyId, {
|
||||
parentId: parentIssueId,
|
||||
projectId,
|
||||
title: "Child issue",
|
||||
});
|
||||
|
||||
expect(child.parentId).toBe(parentIssueId);
|
||||
expect(child.projectWorkspaceId).toBe(projectWorkspaceId);
|
||||
expect(child.executionWorkspaceId).toBe(executionWorkspaceId);
|
||||
expect(child.executionWorkspacePreference).toBe("reuse_existing");
|
||||
expect(child.executionWorkspaceSettings).toEqual({
|
||||
mode: "isolated_workspace",
|
||||
workspaceRuntime: { profile: "agent" },
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves the parent project when a generic child create inherits workspace linkage", async () => {
|
||||
const companyId = randomUUID();
|
||||
const projectId = randomUUID();
|
||||
@@ -5463,105 +5387,6 @@ describeEmbeddedPostgres("issueService.create workspace inheritance", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps explicit workspace fields instead of inheriting the parent linkage", async () => {
|
||||
const companyId = randomUUID();
|
||||
const projectId = randomUUID();
|
||||
const parentIssueId = randomUUID();
|
||||
const parentProjectWorkspaceId = randomUUID();
|
||||
const parentExecutionWorkspaceId = randomUUID();
|
||||
const explicitProjectWorkspaceId = randomUUID();
|
||||
const explicitExecutionWorkspaceId = randomUUID();
|
||||
|
||||
await db.insert(companies).values({
|
||||
id: companyId,
|
||||
name: "Paperclip",
|
||||
issuePrefix: `T${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`,
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
});
|
||||
await instanceSettingsService(db).updateExperimental({ enableIsolatedWorkspaces: true });
|
||||
|
||||
await db.insert(projects).values({
|
||||
id: projectId,
|
||||
companyId,
|
||||
name: "Workspace project",
|
||||
status: "in_progress",
|
||||
});
|
||||
|
||||
await db.insert(projectWorkspaces).values([
|
||||
{
|
||||
id: parentProjectWorkspaceId,
|
||||
companyId,
|
||||
projectId,
|
||||
name: "Parent workspace",
|
||||
},
|
||||
{
|
||||
id: explicitProjectWorkspaceId,
|
||||
companyId,
|
||||
projectId,
|
||||
name: "Explicit workspace",
|
||||
},
|
||||
]);
|
||||
|
||||
await db.insert(executionWorkspaces).values([
|
||||
{
|
||||
id: parentExecutionWorkspaceId,
|
||||
companyId,
|
||||
projectId,
|
||||
projectWorkspaceId: parentProjectWorkspaceId,
|
||||
mode: "isolated_workspace",
|
||||
strategyType: "git_worktree",
|
||||
name: "Parent worktree",
|
||||
status: "active",
|
||||
providerType: "git_worktree",
|
||||
},
|
||||
{
|
||||
id: explicitExecutionWorkspaceId,
|
||||
companyId,
|
||||
projectId,
|
||||
projectWorkspaceId: explicitProjectWorkspaceId,
|
||||
mode: "shared_workspace",
|
||||
strategyType: "project_primary",
|
||||
name: "Explicit shared workspace",
|
||||
status: "active",
|
||||
providerType: "local_fs",
|
||||
},
|
||||
]);
|
||||
|
||||
await db.insert(issues).values({
|
||||
id: parentIssueId,
|
||||
companyId,
|
||||
projectId,
|
||||
projectWorkspaceId: parentProjectWorkspaceId,
|
||||
title: "Parent issue",
|
||||
status: "in_progress",
|
||||
priority: "medium",
|
||||
executionWorkspaceId: parentExecutionWorkspaceId,
|
||||
executionWorkspacePreference: "reuse_existing",
|
||||
executionWorkspaceSettings: {
|
||||
mode: "isolated_workspace",
|
||||
},
|
||||
});
|
||||
|
||||
const child = await svc.create(companyId, {
|
||||
parentId: parentIssueId,
|
||||
projectId,
|
||||
title: "Child issue",
|
||||
projectWorkspaceId: explicitProjectWorkspaceId,
|
||||
executionWorkspaceId: explicitExecutionWorkspaceId,
|
||||
executionWorkspacePreference: "reuse_existing",
|
||||
executionWorkspaceSettings: {
|
||||
mode: "shared_workspace",
|
||||
},
|
||||
});
|
||||
|
||||
expect(child.projectWorkspaceId).toBe(explicitProjectWorkspaceId);
|
||||
expect(child.executionWorkspaceId).toBe(explicitExecutionWorkspaceId);
|
||||
expect(child.executionWorkspacePreference).toBe("reuse_existing");
|
||||
expect(child.executionWorkspaceSettings).toEqual({
|
||||
mode: "shared_workspace",
|
||||
});
|
||||
});
|
||||
|
||||
it("inherits workspace linkage from an explicit source issue without creating a parent-child relationship", async () => {
|
||||
const companyId = randomUUID();
|
||||
const projectId = randomUUID();
|
||||
|
||||
@@ -3619,6 +3619,49 @@ describeEmbeddedPostgres("tool access service", () => {
|
||||
}),
|
||||
]),
|
||||
);
|
||||
|
||||
const gatewayAudit = await db
|
||||
.select()
|
||||
.from(activityLog)
|
||||
.where(
|
||||
and(
|
||||
eq(activityLog.companyId, company.id),
|
||||
eq(activityLog.action, "tool_gateway.approval_requested"),
|
||||
),
|
||||
);
|
||||
expect(gatewayAudit).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
actorType: "user",
|
||||
actorId: userId,
|
||||
agentId: agent.id,
|
||||
details: expect.objectContaining({
|
||||
source: "test",
|
||||
actionRequestId: res.body.actionRequestId,
|
||||
invocationId: res.body.invocationId,
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
|
||||
const dedicatedAudit = await db
|
||||
.select()
|
||||
.from(toolAccessAuditEvents)
|
||||
.where(eq(toolAccessAuditEvents.companyId, company.id));
|
||||
expect(dedicatedAudit).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
actorType: "user",
|
||||
actorId: userId,
|
||||
details: expect.objectContaining({
|
||||
source: "test",
|
||||
agentId: agent.id,
|
||||
actionRequestId: res.body.actionRequestId,
|
||||
runId: null,
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("cancels an ask-first test request when approval signing is unavailable", async () => {
|
||||
@@ -3672,77 +3715,6 @@ describeEmbeddedPostgres("tool access service", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("audits ask-first test calls with the real board actor and selected agent", async () => {
|
||||
const company = await createCompany(db);
|
||||
const userId = `tool-tester-${randomUUID()}`;
|
||||
await grantBoardUser(db, company.id, userId, ["tools:use"]);
|
||||
const agent = await createAgent(db, company.id);
|
||||
const { connection } = await createRemoteToolFixture(db, company.id);
|
||||
await db.insert(toolPolicies).values({
|
||||
companyId: company.id,
|
||||
name: `Ask first ${randomUUID()}`,
|
||||
policyType: "require_approval",
|
||||
priority: 100,
|
||||
selectors: { connectionId: connection.id },
|
||||
});
|
||||
const app = createRouteApp(
|
||||
db,
|
||||
boardSessionActor(company.id, "operator", userId),
|
||||
createToolGatewayService(db, { toolActionSigningSecret: "test-secret" }),
|
||||
);
|
||||
|
||||
const res = await request(app)
|
||||
.post(`/api/tool-connections/${connection.id}/test-calls`)
|
||||
.send({
|
||||
agentId: agent.id,
|
||||
toolName: "send_email",
|
||||
parameters: { to: "a@example.com" },
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const gatewayAudit = await db
|
||||
.select()
|
||||
.from(activityLog)
|
||||
.where(
|
||||
and(
|
||||
eq(activityLog.companyId, company.id),
|
||||
eq(activityLog.action, "tool_gateway.approval_requested"),
|
||||
),
|
||||
);
|
||||
expect(gatewayAudit).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
actorType: "user",
|
||||
actorId: userId,
|
||||
agentId: agent.id,
|
||||
details: expect.objectContaining({
|
||||
source: "test",
|
||||
actionRequestId: res.body.actionRequestId,
|
||||
invocationId: res.body.invocationId,
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
|
||||
const dedicatedAudit = await db
|
||||
.select()
|
||||
.from(toolAccessAuditEvents)
|
||||
.where(eq(toolAccessAuditEvents.companyId, company.id));
|
||||
expect(dedicatedAudit).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
actorType: "user",
|
||||
actorId: userId,
|
||||
details: expect.objectContaining({
|
||||
source: "test",
|
||||
agentId: agent.id,
|
||||
actionRequestId: res.body.actionRequestId,
|
||||
runId: null,
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("drives an ask-first test call through its live lifecycle (waiting → approved/done with the real result)", async () => {
|
||||
const company = await createCompany(db);
|
||||
@@ -3778,6 +3750,10 @@ describeEmbeddedPostgres("tool access service", () => {
|
||||
const actionRequestId = created.body.actionRequestId as string;
|
||||
expect(actionRequestId).toEqual(expect.any(String));
|
||||
|
||||
await request(app)
|
||||
.get(`/api/tool-connections/${connection.id}/test-calls/${randomUUID()}`)
|
||||
.expect(404);
|
||||
|
||||
// 2. Status starts as "waiting" and surfaces the redacted "Where" snapshot.
|
||||
const waiting = await request(app)
|
||||
.get(
|
||||
@@ -3949,24 +3925,6 @@ describeEmbeddedPostgres("tool access service", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("404s a single-id test-call status fetch for a non-test-origin action request", async () => {
|
||||
const company = await createCompany(db);
|
||||
const userId = `tool-tester-${randomUUID()}`;
|
||||
await grantBoardUser(db, company.id, userId, ["tools:use"]);
|
||||
const { connection } = await createRemoteToolFixture(db, company.id);
|
||||
const gateway = createToolGatewayService(db, {
|
||||
toolActionSigningSecret: "test-secret",
|
||||
});
|
||||
const app = createRouteApp(
|
||||
db,
|
||||
boardSessionActor(company.id, "operator", userId),
|
||||
gateway,
|
||||
);
|
||||
|
||||
await request(app)
|
||||
.get(`/api/tool-connections/${connection.id}/test-calls/${randomUUID()}`)
|
||||
.expect(404);
|
||||
});
|
||||
|
||||
it("returns off for blocked test calls without executing the remote tool", async () => {
|
||||
const company = await createCompany(db);
|
||||
@@ -4014,35 +3972,6 @@ describeEmbeddedPostgres("tool access service", () => {
|
||||
agentId: agent.id,
|
||||
runId: null,
|
||||
});
|
||||
});
|
||||
|
||||
it("audits blocked test calls with the real board actor and selected agent", async () => {
|
||||
const company = await createCompany(db);
|
||||
const userId = `tool-tester-${randomUUID()}`;
|
||||
await grantBoardUser(db, company.id, userId, ["tools:use"]);
|
||||
const agent = await createAgent(db, company.id);
|
||||
const { connection } = await createRemoteToolFixture(db, company.id);
|
||||
await db.insert(toolPolicies).values({
|
||||
companyId: company.id,
|
||||
name: `Block ${randomUUID()}`,
|
||||
policyType: "block",
|
||||
priority: 100,
|
||||
selectors: { connectionId: connection.id },
|
||||
});
|
||||
const app = createRouteApp(
|
||||
db,
|
||||
boardSessionActor(company.id, "operator", userId),
|
||||
createToolGatewayService(db, { toolActionSigningSecret: "test-secret" }),
|
||||
);
|
||||
|
||||
const res = await request(app)
|
||||
.post(`/api/tool-connections/${connection.id}/test-calls`)
|
||||
.send({
|
||||
agentId: agent.id,
|
||||
toolName: "send_email",
|
||||
parameters: { to: "a@example.com" },
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const gatewayAudit = await db
|
||||
.select()
|
||||
@@ -4089,6 +4018,7 @@ describeEmbeddedPostgres("tool access service", () => {
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
it("denies test calls through agents the board user cannot task", async () => {
|
||||
const company = await createCompany(db);
|
||||
const userId = `tool-tester-${randomUUID()}`;
|
||||
@@ -5536,7 +5466,6 @@ describeEmbeddedPostgres("tool access service", () => {
|
||||
|
||||
|
||||
|
||||
|
||||
it("retires saved Composio broker and child records without touching credentials until removal", async () => {
|
||||
const company = await createCompany(db);
|
||||
const { parent, child } = await createComposioParentAndChild(db, company.id);
|
||||
|
||||
@@ -3640,6 +3640,11 @@ rl.on("line", (line) => {
|
||||
.from(toolInvocations)
|
||||
.where(eq(toolInvocations.id, approvalRequest.invocationId));
|
||||
expect(approvalInvocation).toMatchObject({
|
||||
companyId: company.id,
|
||||
actorType: "agent",
|
||||
agentId: agent.id,
|
||||
runId: run.id,
|
||||
issueId: issue.id,
|
||||
status: "awaiting_approval",
|
||||
policyDecision: "require_approval",
|
||||
connectionId: approvalTool.connection.id,
|
||||
@@ -3648,6 +3653,14 @@ rl.on("line", (line) => {
|
||||
upstreamToolName: "kv_set",
|
||||
});
|
||||
|
||||
// Matching persisted company/connection rows must still be hidden from
|
||||
// the Test tab when a real agent run owns the approval.
|
||||
await expect(gateway.getTestCallStatus({
|
||||
companyId: company.id,
|
||||
connectionId: approvalTool.connection.id,
|
||||
actionRequestId: approvalRequest.id,
|
||||
})).rejects.toMatchObject({ status: 404, reasonCode: "action_request_not_found" });
|
||||
|
||||
await db
|
||||
.update(issueThreadInteractions)
|
||||
.set({
|
||||
|
||||
@@ -2588,110 +2588,7 @@ process.stderr.write(${JSON.stringify(stderr)}, () => { process.exitCode = ${cod
|
||||
}
|
||||
});
|
||||
|
||||
it(
|
||||
"provisions worktree-local pnpm node_modules instead of reusing base-repo links",
|
||||
async () => {
|
||||
const repoRoot = await createTempRepo();
|
||||
await writeRegisteredSourceConfig(repoRoot);
|
||||
await fs.mkdir(path.join(repoRoot, "scripts"), { recursive: true });
|
||||
await fs.mkdir(path.join(repoRoot, "packages", "shared"), { recursive: true });
|
||||
await fs.mkdir(path.join(repoRoot, "server"), { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.join(repoRoot, "package.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
name: "workspace-root",
|
||||
private: true,
|
||||
packageManager: "pnpm@9.15.4",
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
await fs.writeFile(
|
||||
path.join(repoRoot, "pnpm-workspace.yaml"),
|
||||
["packages:", " - packages/*", " - server", ""].join("\n"),
|
||||
"utf8",
|
||||
);
|
||||
await fs.writeFile(
|
||||
path.join(repoRoot, "packages", "shared", "package.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
name: "@repo/shared",
|
||||
version: "1.0.0",
|
||||
private: true,
|
||||
type: "module",
|
||||
exports: "./index.js",
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
await fs.writeFile(path.join(repoRoot, "packages", "shared", "index.js"), "export const value = 'shared';\n", "utf8");
|
||||
await fs.writeFile(
|
||||
path.join(repoRoot, "server", "package.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
name: "server",
|
||||
private: true,
|
||||
type: "module",
|
||||
dependencies: {
|
||||
"@repo/shared": "workspace:*",
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
await fs.writeFile(path.join(repoRoot, "server", "index.js"), "export {};\n", "utf8");
|
||||
await fs.copyFile(provisionWorktreeScriptPath, path.join(repoRoot, "scripts", "provision-worktree.sh"));
|
||||
await fs.chmod(path.join(repoRoot, "scripts", "provision-worktree.sh"), 0o755);
|
||||
await runPnpm(repoRoot, ["install"]);
|
||||
await runGit(repoRoot, ["add", "."]);
|
||||
await runGit(repoRoot, ["commit", "-m", "Add pnpm workspace fixture"]);
|
||||
|
||||
const workspace = await realizeExecutionWorkspace({
|
||||
base: {
|
||||
baseCwd: repoRoot,
|
||||
source: "project_primary",
|
||||
projectId: "project-1",
|
||||
workspaceId: "workspace-1",
|
||||
repoUrl: null,
|
||||
repoRef: "HEAD",
|
||||
},
|
||||
config: {
|
||||
workspaceStrategy: {
|
||||
type: "git_worktree",
|
||||
branchTemplate: "{{issue.identifier}}-{{slug}}",
|
||||
provisionCommand: "bash ./scripts/provision-worktree.sh",
|
||||
},
|
||||
},
|
||||
issue: {
|
||||
id: "issue-1",
|
||||
identifier: "PAP-551",
|
||||
title: "Provision local workspace dependencies",
|
||||
},
|
||||
agent: {
|
||||
id: "agent-1",
|
||||
name: "Codex Coder",
|
||||
companyId: "company-1",
|
||||
},
|
||||
});
|
||||
|
||||
expect((await fs.lstat(path.join(workspace.cwd, "node_modules"))).isSymbolicLink()).toBe(false);
|
||||
expect((await fs.lstat(path.join(workspace.cwd, "server", "node_modules"))).isSymbolicLink()).toBe(false);
|
||||
await expect(fs.realpath(path.join(workspace.cwd, "server", "node_modules", "@repo", "shared"))).resolves.toBe(
|
||||
await fs.realpath(path.join(workspace.cwd, "packages", "shared")),
|
||||
);
|
||||
await expect(fs.realpath(path.join(repoRoot, "server", "node_modules", "@repo", "shared"))).resolves.toBe(
|
||||
await fs.realpath(path.join(repoRoot, "packages", "shared")),
|
||||
);
|
||||
},
|
||||
15_000,
|
||||
);
|
||||
|
||||
it("records worktree setup and provision operations when a recorder is provided", async () => {
|
||||
const repoRoot = await createTempRepo();
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -79,211 +79,13 @@ const previousRunId = "40000000-0000-4000-8000-000000000004";
|
||||
const currentRunId = "50000000-0000-4000-8000-000000000005";
|
||||
const normalizedSessionId = "60000000-0000-4000-8000-000000000006";
|
||||
|
||||
const CONDITIONAL_READER_TOOL_CONTRACT_FINGERPRINT = `sha256:${createHash(
|
||||
"sha256",
|
||||
)
|
||||
.update(
|
||||
JSON.stringify({
|
||||
schema: "paperclip.native-tool-contract.v1",
|
||||
tools: [
|
||||
{ name: "register_deliverable", version: 1 },
|
||||
{
|
||||
name: "read_current_wake_comments",
|
||||
semanticContract: "paperclip.server-current-wake-comments.v1",
|
||||
version: 1,
|
||||
},
|
||||
],
|
||||
}),
|
||||
)
|
||||
.digest("hex")}`;
|
||||
|
||||
const PRE_CHAT_ATTACHMENT_REUSE_TOOL_CONTRACT_FINGERPRINT = `sha256:${createHash(
|
||||
"sha256",
|
||||
)
|
||||
.update(
|
||||
JSON.stringify({
|
||||
schema: "paperclip.native-tool-contract.v2",
|
||||
executionTargetKind: "local",
|
||||
advertisementPolicy: {
|
||||
readCurrentWakeComments: "always_advertised_binding_gated.v1",
|
||||
registerDeliverable: "local_workspace_only.v1",
|
||||
},
|
||||
tools: [
|
||||
{ name: "register_deliverable", version: 1 },
|
||||
{
|
||||
name: "read_current_wake_comments",
|
||||
semanticContract: "paperclip.server-current-wake-comments.v1",
|
||||
version: 1,
|
||||
},
|
||||
],
|
||||
}),
|
||||
)
|
||||
.digest("hex")}`;
|
||||
|
||||
const PRE_CHAT_ATTACHMENT_READ_TOOL_CONTRACT_FINGERPRINT = `sha256:${createHash(
|
||||
"sha256",
|
||||
)
|
||||
.update(
|
||||
JSON.stringify({
|
||||
schema: "paperclip.native-tool-contract.v3",
|
||||
executionTargetKind: "local",
|
||||
advertisementPolicy: {
|
||||
readCurrentWakeComments: "always_advertised_binding_gated.v1",
|
||||
historicalChatAttachments:
|
||||
"always_advertised_conversation_binding_gated.v1",
|
||||
registerDeliverable: "local_workspace_only.v1",
|
||||
},
|
||||
tools: [
|
||||
{ name: "register_deliverable", version: 1 },
|
||||
{
|
||||
name: "read_current_wake_comments",
|
||||
semanticContract: "paperclip.server-current-wake-comments.v1",
|
||||
version: 1,
|
||||
},
|
||||
{
|
||||
name: "list_chat_attachments",
|
||||
semanticContract: "paperclip.server-chat-attachment-reuse.v1",
|
||||
version: 1,
|
||||
},
|
||||
{
|
||||
name: "reuse_chat_attachment",
|
||||
semanticContract: "paperclip.server-chat-attachment-reuse.v1",
|
||||
version: 1,
|
||||
},
|
||||
],
|
||||
}),
|
||||
)
|
||||
.digest("hex")}`;
|
||||
|
||||
const PRE_STRUCTURED_HUMAN_INPUT_TOOL_CONTRACT_FINGERPRINT = `sha256:${createHash(
|
||||
"sha256",
|
||||
)
|
||||
.update(
|
||||
JSON.stringify({
|
||||
schema: "paperclip.native-tool-contract.v4",
|
||||
executionTargetKind: "local",
|
||||
advertisementPolicy: {
|
||||
readCurrentWakeComments: "always_advertised_binding_gated.v1",
|
||||
historicalChatAttachments:
|
||||
"always_advertised_conversation_binding_gated.v1",
|
||||
registerDeliverable: "local_workspace_only.v1",
|
||||
readChatAttachment: "always_advertised_run_scope_local_staging.v1",
|
||||
},
|
||||
tools: [
|
||||
{ name: "register_deliverable", version: 1 },
|
||||
{
|
||||
name: "read_current_wake_comments",
|
||||
semanticContract: "paperclip.server-current-wake-comments.v1",
|
||||
version: 1,
|
||||
},
|
||||
{
|
||||
name: "list_chat_attachments",
|
||||
semanticContract: "paperclip.server-chat-attachment-reuse.v1",
|
||||
version: 1,
|
||||
},
|
||||
{
|
||||
name: "reuse_chat_attachment",
|
||||
semanticContract: "paperclip.server-chat-attachment-reuse.v1",
|
||||
version: 1,
|
||||
},
|
||||
{
|
||||
name: "read_chat_attachment",
|
||||
semanticContract: "paperclip.server-chat-attachment-read.v1",
|
||||
version: 1,
|
||||
},
|
||||
],
|
||||
}),
|
||||
)
|
||||
.digest("hex")}`;
|
||||
|
||||
const PRE_RESPONSE_WAKE_YIELD_TOOL_CONTRACT_FINGERPRINT = `sha256:${createHash(
|
||||
"sha256",
|
||||
)
|
||||
.update(
|
||||
JSON.stringify({
|
||||
schema: "paperclip.native-tool-contract.v5",
|
||||
executionTargetKind: "local",
|
||||
advertisementPolicy: {
|
||||
readCurrentWakeComments: "always_advertised_binding_gated.v1",
|
||||
historicalChatAttachments:
|
||||
"always_advertised_conversation_binding_gated.v1",
|
||||
registerDeliverable: "local_workspace_only.v1",
|
||||
readChatAttachment: "always_advertised_run_scope_local_staging.v1",
|
||||
structuredHumanInput:
|
||||
"always_advertised_run_issue_agent_binding_gated.v1",
|
||||
},
|
||||
tools: [
|
||||
{ name: "register_deliverable", version: 1 },
|
||||
{
|
||||
name: "read_current_wake_comments",
|
||||
semanticContract: "paperclip.server-current-wake-comments.v1",
|
||||
version: 1,
|
||||
},
|
||||
{
|
||||
name: "list_chat_attachments",
|
||||
semanticContract: "paperclip.server-chat-attachment-reuse.v1",
|
||||
version: 1,
|
||||
},
|
||||
{
|
||||
name: "reuse_chat_attachment",
|
||||
semanticContract: "paperclip.server-chat-attachment-reuse.v1",
|
||||
version: 1,
|
||||
},
|
||||
{
|
||||
name: "read_chat_attachment",
|
||||
semanticContract: "paperclip.server-chat-attachment-read.v1",
|
||||
version: 1,
|
||||
},
|
||||
{ name: "request_human_input", version: 1 },
|
||||
],
|
||||
}),
|
||||
)
|
||||
.digest("hex")}`;
|
||||
|
||||
const PRE_EXPLICIT_CHAT_ATTACHMENT_GUIDANCE_TOOL_CONTRACT_FINGERPRINT = `sha256:${createHash(
|
||||
"sha256",
|
||||
)
|
||||
.update(
|
||||
JSON.stringify({
|
||||
schema: "paperclip.native-tool-contract.v7",
|
||||
executionTargetKind: "local",
|
||||
advertisementPolicy: {
|
||||
readCurrentWakeComments: "always_advertised_binding_gated.v1",
|
||||
historicalChatAttachments:
|
||||
"always_advertised_conversation_binding_gated.v1",
|
||||
registerDeliverable: "local_workspace_only.v1",
|
||||
readChatAttachment: "always_advertised_run_scope_local_staging.v1",
|
||||
structuredHumanInput:
|
||||
"always_advertised_run_issue_agent_binding_gated.v1",
|
||||
semanticCompletion: "finish_response_wake_concrete_object.v2",
|
||||
},
|
||||
tools: [
|
||||
{ name: "register_deliverable", version: 1 },
|
||||
{
|
||||
name: "read_current_wake_comments",
|
||||
semanticContract: "paperclip.server-current-wake-comments.v1",
|
||||
version: 1,
|
||||
},
|
||||
{
|
||||
name: "list_chat_attachments",
|
||||
semanticContract: "paperclip.server-chat-attachment-reuse.v1",
|
||||
version: 1,
|
||||
},
|
||||
{
|
||||
name: "reuse_chat_attachment",
|
||||
semanticContract: "paperclip.server-chat-attachment-reuse.v1",
|
||||
version: 1,
|
||||
},
|
||||
{
|
||||
name: "read_chat_attachment",
|
||||
semanticContract: "paperclip.server-chat-attachment-read.v1",
|
||||
version: 1,
|
||||
},
|
||||
{ name: "request_human_input", version: 1 },
|
||||
],
|
||||
}),
|
||||
)
|
||||
.digest("hex")}`;
|
||||
|
||||
|
||||
|
||||
function execution(
|
||||
runId: string,
|
||||
@@ -440,6 +242,8 @@ describe("capability-gated connection tool refresh", () => {
|
||||
current.runtimeContext.instructions.bundle.digest = "b".repeat(64);
|
||||
current.runtimeContext.aggregateDigest = canonicalNativeRuntimeContextDigest(current.runtimeContext);
|
||||
expect(rebindNativeSessionCheckpoint({ previousRun: previousRun(), currentExecution: current, toolRefreshOnResume: true, refreshTools: true })).toBeNull();
|
||||
current.runtimeContext = nativeRuntimeContextFixture();
|
||||
expect(rebindNativeSessionCheckpoint({ previousRun: previousRun(), currentExecution: current, toolRefreshOnResume: true, refreshTools: true })).not.toBeNull();
|
||||
current.binding.agentId = randomUUID();
|
||||
expect(rebindNativeSessionCheckpoint({ previousRun: previousRun(), currentExecution: current, toolRefreshOnResume: true, refreshTools: true })).toBeNull();
|
||||
});
|
||||
@@ -1918,6 +1722,12 @@ describe("rebindNativeSessionCheckpoint", () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ contract: "conditional current-wake reader", retainedFingerprint: "sha256:fe7a2e17ca825228ea2f51f23acdc82db65c91da5ec6add330fefa39b65e1c85" },
|
||||
{ contract: "same-conversation attachment reuse", retainedFingerprint: "sha256:2b84f2105c2cea10e0e5f37cf4a6ba9bf7fec90d8c8c19c655a0e21d3a8dab5f" },
|
||||
{ contract: "historical file inspection", retainedFingerprint: "sha256:9b558a575dfa4e3dfaf97b7139b47d1676ab3e0307953ec85f2af0b3f443567c" },
|
||||
{ contract: "structured human questions", retainedFingerprint: "sha256:1c3cd7e3223f6ed28e1c44a0ba3c961dd4c0c52e52c9c1100a4e41a83384259c" },
|
||||
{ contract: "response-wake completion yield", retainedFingerprint: "sha256:09887bbf1f6a3674fcf529d872fe2853cc1d6554376019dd1a9b8d607d7eb7fb" },
|
||||
{ contract: "explicit chat-attachment invocation guidance", retainedFingerprint: "sha256:d797c8bc1baef8407a8c80f2c4b28da63b2a4258a47cf52ee9b1fca45535f5e7" },
|
||||
{
|
||||
contract: "completion descriptions",
|
||||
// Deployed v8 / finish_response_wake_concrete_object.v2 local catalog.
|
||||
@@ -1950,7 +1760,13 @@ describe("rebindNativeSessionCheckpoint", () => {
|
||||
},
|
||||
])(
|
||||
"refreshes retained $contract without changing the Paperclip task or prior history",
|
||||
({ retainedFingerprint }) => {
|
||||
({ contract, retainedFingerprint }) => {
|
||||
if (contract === "explicit chat-attachment invocation guidance") {
|
||||
expect(LIST_CHAT_ATTACHMENTS_TOOL_DEFINITION.description).toContain("Call with {}");
|
||||
expect(LIST_CHAT_ATTACHMENTS_TOOL_DEFINITION.description).toContain("1 through 50");
|
||||
expect(REUSE_CHAT_ATTACHMENT_TOOL_DEFINITION.description).toContain("All four arguments are required");
|
||||
expect(REUSE_CHAT_ATTACHMENT_TOOL_DEFINITION.description).toContain("same key unchanged on every retry");
|
||||
}
|
||||
expect(NATIVE_TOOL_CONTRACT_FINGERPRINT).not.toBe(retainedFingerprint);
|
||||
const prior = previousRun({
|
||||
nativeToolContractFingerprint: retainedFingerprint,
|
||||
@@ -2001,35 +1817,7 @@ describe("rebindNativeSessionCheckpoint", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it("rotates a provider thread created while the current-wake reader was conditionally advertised", () => {
|
||||
expect(CONDITIONAL_READER_TOOL_CONTRACT_FINGERPRINT).not.toBe(
|
||||
NATIVE_TOOL_CONTRACT_FINGERPRINT,
|
||||
);
|
||||
expect(
|
||||
rebindNativeSessionCheckpoint({
|
||||
previousRun: previousRun({
|
||||
nativeToolContractFingerprint:
|
||||
CONDITIONAL_READER_TOOL_CONTRACT_FINGERPRINT,
|
||||
}),
|
||||
currentExecution: execution(currentRunId),
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("rotates a provider thread that predates same-conversation attachment reuse", () => {
|
||||
expect(PRE_CHAT_ATTACHMENT_REUSE_TOOL_CONTRACT_FINGERPRINT).not.toBe(
|
||||
NATIVE_TOOL_CONTRACT_FINGERPRINT,
|
||||
);
|
||||
expect(
|
||||
rebindNativeSessionCheckpoint({
|
||||
previousRun: previousRun({
|
||||
nativeToolContractFingerprint:
|
||||
PRE_CHAT_ATTACHMENT_REUSE_TOOL_CONTRACT_FINGERPRINT,
|
||||
}),
|
||||
currentExecution: execution(currentRunId),
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("binds the provider tool catalog to the local or remote execution target", () => {
|
||||
const remoteFingerprint = nativeToolContractFingerprintForTarget("remote");
|
||||
@@ -2052,77 +1840,10 @@ describe("rebindNativeSessionCheckpoint", () => {
|
||||
).not.toBeNull();
|
||||
});
|
||||
|
||||
it("rotates provider threads whose retained catalog cannot inspect historical files", () => {
|
||||
expect(PRE_CHAT_ATTACHMENT_READ_TOOL_CONTRACT_FINGERPRINT).not.toBe(
|
||||
NATIVE_TOOL_CONTRACT_FINGERPRINT,
|
||||
);
|
||||
expect(
|
||||
rebindNativeSessionCheckpoint({
|
||||
previousRun: previousRun({
|
||||
nativeToolContractFingerprint:
|
||||
PRE_CHAT_ATTACHMENT_READ_TOOL_CONTRACT_FINGERPRINT,
|
||||
}),
|
||||
currentExecution: execution(currentRunId),
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("rotates direct provider threads whose retained catalog cannot ask structured questions", () => {
|
||||
expect(PRE_STRUCTURED_HUMAN_INPUT_TOOL_CONTRACT_FINGERPRINT).not.toBe(
|
||||
NATIVE_TOOL_CONTRACT_FINGERPRINT,
|
||||
);
|
||||
expect(
|
||||
rebindNativeSessionCheckpoint({
|
||||
previousRun: previousRun({
|
||||
nativeToolContractFingerprint:
|
||||
PRE_STRUCTURED_HUMAN_INPUT_TOOL_CONTRACT_FINGERPRINT,
|
||||
}),
|
||||
currentExecution: execution(currentRunId),
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("rotates direct provider threads whose retained completion tool cannot yield for a response", () => {
|
||||
expect(PRE_RESPONSE_WAKE_YIELD_TOOL_CONTRACT_FINGERPRINT).not.toBe(
|
||||
NATIVE_TOOL_CONTRACT_FINGERPRINT,
|
||||
);
|
||||
expect(
|
||||
rebindNativeSessionCheckpoint({
|
||||
previousRun: previousRun({
|
||||
nativeToolContractFingerprint:
|
||||
PRE_RESPONSE_WAKE_YIELD_TOOL_CONTRACT_FINGERPRINT,
|
||||
}),
|
||||
currentExecution: execution(currentRunId),
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("rotates provider threads whose retained attachment tools lack explicit invocation guidance", () => {
|
||||
expect(LIST_CHAT_ATTACHMENTS_TOOL_DEFINITION.description).toContain(
|
||||
"Call with {}",
|
||||
);
|
||||
expect(LIST_CHAT_ATTACHMENTS_TOOL_DEFINITION.description).toContain(
|
||||
"1 through 50",
|
||||
);
|
||||
expect(REUSE_CHAT_ATTACHMENT_TOOL_DEFINITION.description).toContain(
|
||||
"All four arguments are required",
|
||||
);
|
||||
expect(REUSE_CHAT_ATTACHMENT_TOOL_DEFINITION.description).toContain(
|
||||
"same key unchanged on every retry",
|
||||
);
|
||||
expect(
|
||||
PRE_EXPLICIT_CHAT_ATTACHMENT_GUIDANCE_TOOL_CONTRACT_FINGERPRINT,
|
||||
).not.toBe(NATIVE_TOOL_CONTRACT_FINGERPRINT);
|
||||
expect(
|
||||
rebindNativeSessionCheckpoint({
|
||||
previousRun: previousRun({
|
||||
nativeToolContractFingerprint:
|
||||
PRE_EXPLICIT_CHAT_ATTACHMENT_GUIDANCE_TOOL_CONTRACT_FINGERPRINT,
|
||||
}),
|
||||
currentExecution: execution(currentRunId),
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
|
||||
it("permits legacy retry rebinding only before the replacement acquired authority", () => {
|
||||
const source = {
|
||||
|
||||
@@ -107,31 +107,7 @@ describe("runner API catalog", () => {
|
||||
expect(operation.responses).toBeDefined();
|
||||
expect(operation.authorization.actor).toBeTruthy();
|
||||
});
|
||||
it.each(
|
||||
runnerApiCatalog().filter((operation) => operation.transport === "rest"),
|
||||
)(
|
||||
"resolves the catalog route $operationId inside the bound origin",
|
||||
(operation) => {
|
||||
const pathParams = Object.fromEntries(
|
||||
operation.parameters
|
||||
.filter((parameter) => parameter.in === "path")
|
||||
.map((parameter) => [
|
||||
parameter.name,
|
||||
parameter.name === "companyId" ? context.companyId : "fixture-id",
|
||||
]),
|
||||
);
|
||||
const url = runnerApiUrl(
|
||||
operation,
|
||||
{ operationId: operation.operationId, pathParams },
|
||||
context,
|
||||
"https://paperclip.test",
|
||||
);
|
||||
expect(url.origin).toBe("https://paperclip.test");
|
||||
expect(url.pathname).not.toContain("{");
|
||||
expect(operation.responses).toBeDefined();
|
||||
expect(operation.authorization.actor).toBeTruthy();
|
||||
},
|
||||
);
|
||||
|
||||
it("ranks natural language, explains dedicated alternatives, and supports exact lookup", () => {
|
||||
expect(
|
||||
searchRunnerApi({ query: "create project" }).results.map(
|
||||
|
||||
Reference in new issue
Block a user