feat: 全栈 Logger 依赖注入 — DB/Route/AI 层传参 + 前端 Logger + 测试更新 + 归档 add-frontend-logger
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, mock, test } from "bun:test";
|
||||
|
||||
import { createNoopLogger } from "../../../src/server/logger";
|
||||
import { createMigratedTestDatabase } from "../../helpers";
|
||||
|
||||
void mock.module("ai", () => ({
|
||||
@@ -36,12 +37,15 @@ describe("AI registry", () => {
|
||||
test("testProviderConnection reports unreachable Base URL", async () => {
|
||||
const { testProviderConnection } = await import("../../../src/server/ai/registry");
|
||||
|
||||
const result = await testProviderConnection({
|
||||
apiKey: "bad-key",
|
||||
baseUrl: "http://127.0.0.1:1",
|
||||
name: "Bad",
|
||||
type: "openai-compatible",
|
||||
});
|
||||
const result = await testProviderConnection(
|
||||
{
|
||||
apiKey: "bad-key",
|
||||
baseUrl: "http://127.0.0.1:1",
|
||||
name: "Bad",
|
||||
type: "openai-compatible",
|
||||
},
|
||||
createNoopLogger(),
|
||||
);
|
||||
|
||||
expect(result.ok).toBe(false);
|
||||
expect(result.message).toContain("Base URL 不可达");
|
||||
@@ -51,12 +55,15 @@ describe("AI registry", () => {
|
||||
await withProviderServer(new Response(null, { status: 401 }), async (baseUrl) => {
|
||||
const { testProviderConnection } = await import("../../../src/server/ai/registry");
|
||||
|
||||
const result = await testProviderConnection({
|
||||
apiKey: "bad-key",
|
||||
baseUrl,
|
||||
name: "Bad",
|
||||
type: "openai-compatible",
|
||||
});
|
||||
const result = await testProviderConnection(
|
||||
{
|
||||
apiKey: "bad-key",
|
||||
baseUrl,
|
||||
name: "Bad",
|
||||
type: "openai-compatible",
|
||||
},
|
||||
createNoopLogger(),
|
||||
);
|
||||
|
||||
expect(result.ok).toBe(false);
|
||||
expect(result.message).toContain("API Key 无效");
|
||||
@@ -68,12 +75,15 @@ describe("AI registry", () => {
|
||||
await withProviderServer(Response.json({ data: [{ id: "gpt-4o" }] }), async (baseUrl) => {
|
||||
const { testProviderConnection } = await import("../../../src/server/ai/registry");
|
||||
|
||||
const result = await testProviderConnection({
|
||||
apiKey: "sk-test",
|
||||
baseUrl,
|
||||
name: "Test",
|
||||
type: "openai",
|
||||
});
|
||||
const result = await testProviderConnection(
|
||||
{
|
||||
apiKey: "sk-test",
|
||||
baseUrl,
|
||||
name: "Test",
|
||||
type: "openai",
|
||||
},
|
||||
createNoopLogger(),
|
||||
);
|
||||
|
||||
expect(result.ok).toBe(true);
|
||||
expect(result.message).toContain("/models 返回 1 个模型");
|
||||
@@ -84,12 +94,15 @@ describe("AI registry", () => {
|
||||
await withProviderServer(new Response(null, { status: 404 }), async (baseUrl) => {
|
||||
const { testProviderConnection } = await import("../../../src/server/ai/registry");
|
||||
|
||||
const result = await testProviderConnection({
|
||||
apiKey: "sk-test",
|
||||
baseUrl,
|
||||
name: "Test",
|
||||
type: "openai",
|
||||
});
|
||||
const result = await testProviderConnection(
|
||||
{
|
||||
apiKey: "sk-test",
|
||||
baseUrl,
|
||||
name: "Test",
|
||||
type: "openai",
|
||||
},
|
||||
createNoopLogger(),
|
||||
);
|
||||
|
||||
expect(result.ok).toBe(true);
|
||||
expect(result.message).toContain("可能不支持 /models");
|
||||
@@ -134,13 +147,16 @@ describe("AI registry", () => {
|
||||
test("testModelConnection 成功返回 ok:true", async () => {
|
||||
const { testModelConnection } = await import("../../../src/server/ai/registry");
|
||||
|
||||
const result = await testModelConnection({
|
||||
apiKey: "sk-test",
|
||||
baseUrl: "https://api.openai.com/v1",
|
||||
modelId: "gpt-4o",
|
||||
name: "Test",
|
||||
type: "openai",
|
||||
});
|
||||
const result = await testModelConnection(
|
||||
{
|
||||
apiKey: "sk-test",
|
||||
baseUrl: "https://api.openai.com/v1",
|
||||
modelId: "gpt-4o",
|
||||
name: "Test",
|
||||
type: "openai",
|
||||
},
|
||||
createNoopLogger(),
|
||||
);
|
||||
|
||||
expect(result.ok).toBe(true);
|
||||
expect(result.message).toContain("模型连接成功");
|
||||
|
||||
Reference in New Issue
Block a user