refactor: 简化模型管理,移除启用/禁用,优化测试和布局
- 移除供应商/模型启用禁用能力,清理DB schema/migration/API/前端 - 供应商测试改为Base URL连通性+/models探测 - 新增POST /api/models/test模型连接测试 - 新增GET /api/providers/options专用供应商选项接口 - 统一工具栏为ModelsToolbar,参考项目管理布局 - 模型弹窗优化:默认能力、响应式3列标签、并排数值 - 前后端正整数校验、供应商下拉loading/error/empty状态 - 表格列宽统一,操作列/名称列固定宽度
This commit is contained in:
@@ -3,10 +3,9 @@ import { describe, expect, test } from "bun:test";
|
||||
import {
|
||||
createModel,
|
||||
deleteModel,
|
||||
disableModel,
|
||||
enableModel,
|
||||
fetchModel,
|
||||
fetchModelList,
|
||||
testModelConnection,
|
||||
updateModel,
|
||||
} from "../../../src/web/hooks/use-models";
|
||||
import { installFetchMock, jsonResponse } from "../test-utils";
|
||||
@@ -15,7 +14,6 @@ const MODEL = {
|
||||
capabilities: ["text"] as Array<"text">,
|
||||
contextLength: null,
|
||||
createdAt: "2024-01-01T00:00:00.000Z",
|
||||
enabled: true,
|
||||
id: "m1",
|
||||
maxOutputTokens: null,
|
||||
modelId: "gpt-4o",
|
||||
@@ -50,7 +48,7 @@ describe("use-models request helpers", () => {
|
||||
expect(calls[0]?.url).toContain("keyword=GPT");
|
||||
});
|
||||
|
||||
test("模型 CRUD 与 enable/disable 使用正确 method、URL 与 body", async () => {
|
||||
test("模型 CRUD 使用正确 method、URL 与 body", async () => {
|
||||
const calls = installFetchMock((call) => {
|
||||
if (call.method === "DELETE") return new Response(null, { status: 204 });
|
||||
return jsonResponse(
|
||||
@@ -66,16 +64,12 @@ describe("use-models request helpers", () => {
|
||||
providerId: "pv1",
|
||||
});
|
||||
await updateModel("m1", { name: "GPT-4o Mini" });
|
||||
await enableModel("m1");
|
||||
await disableModel("m1");
|
||||
await deleteModel("m1");
|
||||
await fetchModel("m1");
|
||||
|
||||
expect(calls.map((call) => `${call.method} ${call.url}`)).toEqual([
|
||||
"POST /api/models",
|
||||
"PATCH /api/models/m1",
|
||||
"POST /api/models/m1/enable",
|
||||
"POST /api/models/m1/disable",
|
||||
"DELETE /api/models/m1",
|
||||
"GET /api/models/m1",
|
||||
]);
|
||||
@@ -102,4 +96,16 @@ describe("use-models request helpers", () => {
|
||||
|
||||
await expectRejectsWithMessage(() => fetchModel("m-missing"), "HTTP 500");
|
||||
});
|
||||
|
||||
test("testModelConnection 调用正确 URL 和 body", async () => {
|
||||
const calls = installFetchMock(() => jsonResponse({ modelTestResponse: { message: "模型连接成功", ok: true } }));
|
||||
|
||||
const result = await testModelConnection({ modelId: "gpt-4o", providerId: "pv1" });
|
||||
|
||||
expect(result.ok).toBe(true);
|
||||
expect(result.message).toBe("模型连接成功");
|
||||
expect(calls[0]?.method).toBe("POST");
|
||||
expect(calls[0]?.url).toBe("/api/models/test");
|
||||
expect(jsonBody(calls[0]?.body)).toEqual({ modelId: "gpt-4o", providerId: "pv1" });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,12 +3,10 @@ import { describe, expect, test } from "bun:test";
|
||||
import {
|
||||
createProvider,
|
||||
deleteProvider,
|
||||
disableProvider,
|
||||
enableProvider,
|
||||
fetchProvider,
|
||||
fetchProviderList,
|
||||
fetchProviderOptions,
|
||||
testProviderConfig,
|
||||
testProviderConnection,
|
||||
updateProvider,
|
||||
} from "../../../src/web/hooks/use-providers";
|
||||
import { installFetchMock, jsonResponse } from "../test-utils";
|
||||
@@ -17,7 +15,6 @@ const PROVIDER = {
|
||||
apiKey: "sk-test",
|
||||
baseUrl: "https://api.openai.com/v1",
|
||||
createdAt: "2024-01-01T00:00:00.000Z",
|
||||
enabled: true,
|
||||
id: "pv1",
|
||||
name: "OpenAI",
|
||||
type: "openai" as const,
|
||||
@@ -49,7 +46,7 @@ describe("use-providers request helpers", () => {
|
||||
expect(calls[0]?.url).toBe("/api/providers?page=1&pageSize=20&keyword=OpenAI");
|
||||
});
|
||||
|
||||
test("CRUD and enable/disable use correct method, URL and body", async () => {
|
||||
test("CRUD uses correct method, URL and body", async () => {
|
||||
const calls = installFetchMock((call) => {
|
||||
if (call.method === "DELETE") return new Response(null, { status: 204 });
|
||||
return jsonResponse(
|
||||
@@ -60,16 +57,12 @@ describe("use-providers request helpers", () => {
|
||||
|
||||
await createProvider({ apiKey: "sk-test", baseUrl: "https://api.openai.com/v1", name: "OpenAI", type: "openai" });
|
||||
await updateProvider("pv1", { name: "New OpenAI" });
|
||||
await enableProvider("pv1");
|
||||
await disableProvider("pv1");
|
||||
await deleteProvider("pv1");
|
||||
await fetchProvider("pv1");
|
||||
|
||||
expect(calls.map((c) => c.method + " " + c.url)).toEqual([
|
||||
"POST /api/providers",
|
||||
"PATCH /api/providers/pv1",
|
||||
"POST /api/providers/pv1/enable",
|
||||
"POST /api/providers/pv1/disable",
|
||||
"DELETE /api/providers/pv1",
|
||||
"GET /api/providers/pv1",
|
||||
]);
|
||||
@@ -82,12 +75,14 @@ describe("use-providers request helpers", () => {
|
||||
expect(jsonBody(calls[1]?.body)).toEqual({ name: "New OpenAI" });
|
||||
});
|
||||
|
||||
test("testProviderConnection uses correct URL and parses response", async () => {
|
||||
installFetchMock(() => jsonResponse({ providerTestResponse: { message: "ok", ok: true } }));
|
||||
test("fetchProviderOptions uses dedicated minimal endpoint", async () => {
|
||||
const calls = installFetchMock(() => jsonResponse({ items: [{ id: "pv1", name: "OpenAI", type: "openai" }] }));
|
||||
|
||||
const result = await testProviderConnection("pv1");
|
||||
const result = await fetchProviderOptions();
|
||||
|
||||
expect(result).toEqual({ message: "ok", ok: true });
|
||||
expect(result.items).toEqual([{ id: "pv1", name: "OpenAI", type: "openai" }]);
|
||||
expect(calls[0]?.method).toBe("GET");
|
||||
expect(calls[0]?.url).toBe("/api/providers/options");
|
||||
});
|
||||
|
||||
test("testProviderConfig posts form config and parses response", async () => {
|
||||
|
||||
Reference in New Issue
Block a user