feat: add persisted batch text testing

This commit is contained in:
Xin Wang
2026-08-10 13:49:24 +08:00
parent 5b8b9fd097
commit 19e8c8c108
27 changed files with 3855 additions and 1450 deletions
+100
View File
@@ -6,6 +6,15 @@
*/
import { loginPathWithReturnTo } from "@/lib/auth-redirect";
import type { BatchRunSnapshot } from "@/data/batch-run";
import type {
ContextTurn,
FixedInputTurn,
OverallCriterion,
TestCase,
TestCaseInputMode,
TestSuite,
} from "@/data/test-suites";
const LOOPBACK_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]"]);
@@ -769,3 +778,94 @@ export const webrtcApi = {
iceServers: () =>
request<{ iceServers: IceServerConfig[] }>("/api/webrtc/ice-servers"),
};
// ---------- 测试用例与批量运行 ----------
export type TestSuiteWrite = {
name: string;
description: string;
};
export type TestCaseWrite = {
name: string;
description: string;
inputMode: TestCaseInputMode;
contextTurns: ContextTurn[];
turns: FixedInputTurn[];
overallCriteria: OverallCriterion[];
};
export const testSuitesApi = {
list: () => request<TestSuite[]>("/api/test-suites"),
get: (id: string) => request<TestSuite>(`/api/test-suites/${id}`),
create: (body: TestSuiteWrite) =>
request<TestSuite>("/api/test-suites", {
method: "POST",
body: JSON.stringify(body),
}),
update: (id: string, body: TestSuiteWrite) =>
request<TestSuite>(`/api/test-suites/${id}`, {
method: "PUT",
body: JSON.stringify(body),
}),
duplicate: (id: string) =>
request<TestSuite>(`/api/test-suites/${id}/duplicate`, { method: "POST" }),
remove: (id: string) =>
request<{ ok: boolean }>(`/api/test-suites/${id}`, { method: "DELETE" }),
};
export const testCasesApi = {
list: (suiteId?: string) =>
request<TestCase[]>(
`/api/test-cases${suiteId ? `?suiteId=${encodeURIComponent(suiteId)}` : ""}`,
),
get: (id: string) => request<TestCase>(`/api/test-cases/${id}`),
create: (suiteId: string, body: TestCaseWrite) =>
request<TestCase>(`/api/test-suites/${suiteId}/cases`, {
method: "POST",
body: JSON.stringify(body),
}),
update: (id: string, body: TestCaseWrite) =>
request<TestCase>(`/api/test-cases/${id}`, {
method: "PUT",
body: JSON.stringify(body),
}),
duplicate: (id: string) =>
request<TestCase>(`/api/test-cases/${id}/duplicate`, { method: "POST" }),
remove: (id: string) =>
request<{ ok: boolean }>(`/api/test-cases/${id}`, { method: "DELETE" }),
bulkRemove: (caseIds: string[]) =>
request<{ ok: boolean; deleted: number }>("/api/test-cases/bulk-delete", {
method: "POST",
body: JSON.stringify({ caseIds }),
}),
reorder: (suiteId: string, caseIds: string[]) =>
request<{ ok: boolean }>(`/api/test-suites/${suiteId}/case-order`, {
method: "PUT",
body: JSON.stringify({ caseIds }),
}),
};
export const batchRunsApi = {
create: (body: {
assistantId: string;
evaluatorModelResourceId: string;
caseIds: string[];
title?: string;
config: {
concurrency: number;
timeoutSecs: number;
failureStrategy: "continue" | "stop_on_fail";
errorRetryCount: number;
errorStrategy: "continue" | "stop_on_error";
};
}) =>
request<BatchRunSnapshot>("/api/test-runs", {
method: "POST",
body: JSON.stringify(body),
}),
get: (id: string) => request<BatchRunSnapshot>(`/api/test-runs/${id}`),
cancel: (id: string) =>
request<BatchRunSnapshot>(`/api/test-runs/${id}/cancel`, {
method: "POST",
}),
};