PAP-10829 preserve intake case fields

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-06-10 20:15:25 +00:00
1 parent f89262df82
commit 33a0b110b5
3 files changed
+59 -5

No files matched your search

@@ -5,13 +5,13 @@ describe("pipeline stage variable schema", () => {
it("validates select variables require options", () => {
expect(
pipelineStageConfigSchema.safeParse({
variables: [{ key: "status", type: "select", options: ["open", "done"] }],
variables: [{ key: "status", label: "Status", type: "select", options: ["open", "done"] }],
}).success,
).toBe(true);
expect(
pipelineStageConfigSchema.safeParse({
variables: [{ key: "status", type: "select", options: [] }],
variables: [{ key: "status", label: "Status", type: "select", options: [] }],
}).success,
).toBe(false);
});
@@ -20,8 +20,8 @@ describe("pipeline stage variable schema", () => {
expect(
pipelineStageConfigSchema.safeParse({
variables: [
{ key: "repo", type: "text" },
{ key: "repo", type: "text" },
{ key: "repo", label: "Repo", type: "text" },
{ key: "repo", label: "Repo", type: "text" },
],
}).success,
).toBe(false);
+50 -1
View File
@@ -473,6 +473,10 @@ describe("routine routes", () => {
userName: "Ada",
priority: "high",
},
caseFields: {
userName: "Ada",
priority: "high",
},
}, {
agentId: null,
userId: "board-user",
@@ -480,10 +484,55 @@ describe("routine routes", () => {
expect(mockLogActivity).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
action: "routine.run_triggered",
entityId: "run-1",
details: { source: "api", status: "issue_created" },
details: expect.objectContaining({ source: "api", status: "issue_created" }),
}));
});
it("runs a routine from an intake form with explicit case fields", async () => {
mockAccessService.canUser.mockResolvedValue(true);
const app = await createApp({
type: "board",
userId: "board-user",
source: "session",
isInstanceAdmin: false,
companyIds: [companyId],
});
mockRoutineService.runRoutine.mockResolvedValueOnce({
id: "run-2",
source: "api",
status: "issue_created",
});
const res = await request(app)
.post(`/api/routines/${routineId}/intake-form`)
.send({
projectId,
caseFields: {
repo: "paperclip",
},
userName: "Ada",
});
expect(res.status).toBe(202);
expect(mockRoutineService.runRoutine).toHaveBeenCalledWith(routineId, {
source: "api",
projectId,
payload: {
userName: "Ada",
},
variables: {
userName: "Ada",
},
caseFields: {
repo: "paperclip",
},
}, {
agentId: null,
userId: "board-user",
});
});
it("passes the board actor through when manually running a routine", async () => {
mockAccessService.canUser.mockResolvedValue(true);
const app = await createApp({
+5
View File
@@ -36,6 +36,7 @@ export function routineRoutes(
"executionWorkspaceId",
"executionWorkspacePreference",
"executionWorkspaceSettings",
"caseFields",
"source",
]);
@@ -366,11 +367,15 @@ export function routineRoutes(
const runPayload = "payload" in control
? control.payload as Record<string, unknown> | null
: payload;
const caseFields = Object.hasOwn(control, "caseFields")
? (control.caseFields as Record<string, unknown> | null)
: payload;
const run = await svc.runRoutine(routine.id, {
...control,
source: "api",
payload: runPayload,
variables: payload,
caseFields,
}, {
agentId: req.actor.type === "agent" ? req.actor.agentId : null,
userId: req.actor.type === "board" ? req.actor.userId ?? null : null,