fix(ai): use current form config for connection tests

This commit is contained in:
zipg authored and GitHub committed 2026-08-13 23:55:41 +08:00
1 parent 38bf4ec521
commit 4efd815329
4 files changed
+52 -6

No files matched your search

@@ -0,0 +1,26 @@
import { describe, expect, it } from "vitest";
import type { AiConfig } from "@/types/ai";
import { isAiConnectionTestConfigCurrent } from "../aiConnectionTest";
function config(overrides: Partial<AiConfig> = {}): AiConfig {
return {
provider: "openai-compatible",
apiKey: "key",
authMethod: "bearer",
endpoint: "https://example.com/v1",
model: "model-a",
apiStyle: "completions",
...overrides,
};
}
describe("AI connection test configuration", () => {
it("accepts a result only while the tested form values remain current", () => {
const tested = config();
expect(isAiConnectionTestConfigCurrent(tested, config())).toBe(true);
expect(isAiConnectionTestConfigCurrent(tested, config({ model: "model-b" }))).toBe(false);
expect(isAiConnectionTestConfigCurrent(tested, config({ endpoint: "https://other.example/v1" }))).toBe(false);
expect(isAiConnectionTestConfigCurrent(tested, config({ apiKey: "new-key" }))).toBe(false);
});
});
@@ -0,0 +1,5 @@
import type { AiConfig } from "@/types/ai";
export function isAiConnectionTestConfigCurrent(testedConfig: AiConfig, currentConfig: AiConfig): boolean {
return JSON.stringify(testedConfig) === JSON.stringify(currentConfig);
}