Luck ce0fa4c114
feat(batch): add browser review for persisted results (#7006)
* feat(batch): add browser review for persisted results

* fix(batch): address browser review feedback

* test(batch): cover persisted result review regressions

Exercise running-to-terminal detail refresh, scoped citation dialogs, omitted evidence, translated page labels, and legacy evidence bounds. Fix component lint and formatting and synchronize the review contract documentation.

* docs(frontend): keep batch review guidance within budget

* fix(batch): refresh retried reviews and account for omitted evidence

* fix(ci): keep batch review guidance within size budget

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-10-25 23:27:35 +08:00

78 lines
2.5 KiB
TypeScript

import { beforeEach, describe, expect, it, rs } from "@rstest/core";
rs.mock("@/core/api/fetcher", () => ({ fetch: rs.fn() }));
rs.mock("@/core/config", () => ({ getBackendBaseURL: () => "" }));
import { fetch } from "@/core/api/fetcher";
import {
controlSubagentBatch,
fetchSubagentBatchItemDetail,
fetchSubagentBatchItems,
fetchSubagentBatches,
retrySubagentBatchItem,
subagentBatchResultsUrl,
} from "@/core/subagent-batches/api";
const mockedFetch = rs.mocked(fetch);
function jsonResponse(body: unknown, status = 200): Response {
return new Response(JSON.stringify(body), {
status,
headers: { "Content-Type": "application/json" },
});
}
beforeEach(() => {
mockedFetch.mockReset();
});
describe("subagent batch API", () => {
it("loads thread batches and items through encoded local ids", async () => {
mockedFetch.mockResolvedValueOnce(jsonResponse([]));
await fetchSubagentBatches("thread / 1");
expect(mockedFetch).toHaveBeenLastCalledWith(
"/api/threads/thread%20%2F%201/subagent-batches?limit=20",
);
mockedFetch.mockResolvedValueOnce(jsonResponse([]));
await fetchSubagentBatchItems("thread / 1", "batch / 1", {
offset: 100,
limit: 50,
status: "failed",
});
expect(mockedFetch).toHaveBeenLastCalledWith(
"/api/threads/thread%20%2F%201/subagent-batches/batch%20%2F%201/items?offset=100&limit=50&status=failed",
);
mockedFetch.mockResolvedValueOnce(jsonResponse({}));
await fetchSubagentBatchItemDetail("thread / 1", "batch / 1", 3);
expect(mockedFetch).toHaveBeenLastCalledWith(
"/api/threads/thread%20%2F%201/subagent-batches/batch%20%2F%201/items/3",
);
});
it("posts control and failed-item retry actions", async () => {
mockedFetch
.mockResolvedValueOnce(jsonResponse({}))
.mockResolvedValueOnce(jsonResponse({}));
await controlSubagentBatch("thread-1", "batch-1", "pause");
expect(mockedFetch).toHaveBeenLastCalledWith(
"/api/threads/thread-1/subagent-batches/batch-1/pause",
{ method: "POST" },
);
await retrySubagentBatchItem("thread-1", "batch-1", "item / 1");
expect(mockedFetch).toHaveBeenLastCalledWith(
"/api/threads/thread-1/subagent-batches/batch-1/items/item%20%2F%201/retry",
{ method: "POST" },
);
});
it("builds a JSONL export URL without putting results in chat context", () => {
expect(subagentBatchResultsUrl("thread-1", "batch-1")).toBe(
"/api/threads/thread-1/subagent-batches/batch-1/results.jsonl",
);
});
});