Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/app/api/agents/[agentName]/tasks/report/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,20 @@ describe("POST /api/agents/[agentName]/tasks/report — already_done close (#114
});
}

it.each([
{ taskType: "followup-pr", prFixItem: undefined },
{ taskType: "followup-pr", prFixItem: { id: "item-1", generation: 1 } },
{ taskType: "implement", prFixItem: { id: "item-1", generation: 1 } },
])("rejects already_done for $taskType with invalid task/token combination before side effects", async ({ taskType, prFixItem }) => {
const res = await postRequest({ ...validBody, taskType, ...(prFixItem ? { prFixItem } : {}) });
expect(res.status).toBe(400);
expect((await res.json()).error).toMatch(/only valid for implement reports without prFixItem/);
expect(mockAgentRun.create).not.toHaveBeenCalled();
expect(mockDedupe.create).not.toHaveBeenCalled();
expect(prFixResolveMock).not.toHaveBeenCalled();
expect(closeResolveMock).not.toHaveBeenCalled();
});

it("returns 400 when already_done has no idempotencyKey", async () => {
const { idempotencyKey: _omit, ...body } = validBody;
const res = await postRequest(body);
Expand Down Expand Up @@ -1895,6 +1909,22 @@ describe("POST /api/agents/[agentName]/tasks/report — already_done close (#114
expect(closeResolveMock).toHaveBeenCalledTimes(1);
});

it("settles followup-pr already_addressed with its generation token", async () => {
const res = await postRequest({
taskType: "followup-pr",
outcome: "already_addressed",
repoFullName: "o/r",
pullRequestNumber: 5,
evidence: "done",
prFixItem: { id: "item-1", generation: 2 },
});
expect(res.status).toBe(200);
expect(prFixResolveMock).toHaveBeenCalledWith(expect.objectContaining({
outcome: "already_addressed",
attempt: { itemId: "item-1", generation: 2 },
}));
});

it("does not route already_addressed through the close resolver", async () => {
const res = await postRequest({
taskType: "followup-pr",
Expand Down
3 changes: 3 additions & 0 deletions src/app/api/agents/[agentName]/tasks/report/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ export async function POST(
// stringFields validation.
const isAlreadyAddressed = (outcome as ValidOutcome) === "already_addressed";
const isAlreadyDone = (outcome as ValidOutcome) === "already_done";
if (isAlreadyDone && (taskType !== "implement" || (raw.prFixItem !== undefined && raw.prFixItem !== null))) {
return errorResponse("already_done is only valid for implement reports without prFixItem", 400);
}
const evidence =
(isAlreadyAddressed || isAlreadyDone) && typeof raw.evidence === "string"
? raw.evidence.trim()
Expand Down
Loading