mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-13 04:59:51 +08:00
- tests/e2e/lib: openApp(page, { path, config }), MODEL_CONFIGS_KEY,
savedModelConfigs, settingsDialog, chunkedReplies, sse() and
toolCallEvents() replace about 70 copies of goto + wait for iframe,
three local openApp functions, 14 window.fetch overrides and the
Node-side SSE serialisers; unused fixtures removed
- delete theme, save, history, model-config, upload and copy-paste
specs (the copy-button test moves to chat.spec.ts); trim
iframe-interaction, history-restore, keyboard and smoke to tests that
can fail; file-upload asserts on the preview image
- settings-review-fixes.spec.ts split by topic into settings-bedrock,
settings-tabs-sync and settings-providers
- unit tests use vi.stubEnv with unstubEnvs: true instead of
hand-written process.env save and restore loops
86 lines
3.0 KiB
TypeScript
86 lines
3.0 KiB
TypeScript
// @vitest-environment node
|
|
import { generateText } from "ai"
|
|
import { afterEach, describe, expect, it, vi } from "vitest"
|
|
import { getAIModel } from "@/lib/ai-providers"
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals()
|
|
})
|
|
|
|
/** Send one request through the real Google provider and return its body */
|
|
async function googleRequestBody(modelId = "gemini-2.5-flash") {
|
|
let body: any
|
|
vi.stubGlobal(
|
|
"fetch",
|
|
vi.fn(async (_url: string, init: RequestInit) => {
|
|
body = JSON.parse(init.body as string)
|
|
return new Response(
|
|
JSON.stringify({
|
|
candidates: [
|
|
{
|
|
content: { role: "model", parts: [{ text: "ok" }] },
|
|
finishReason: "STOP",
|
|
},
|
|
],
|
|
}),
|
|
{ headers: { "content-type": "application/json" } },
|
|
)
|
|
}),
|
|
)
|
|
// providerOptions carry the thinking settings, as the chat route passes them
|
|
const { model, providerOptions } = getAIModel({
|
|
provider: "google",
|
|
modelId,
|
|
})
|
|
await generateText({
|
|
model,
|
|
prompt: "hi",
|
|
maxRetries: 0,
|
|
...(providerOptions && { providerOptions }),
|
|
})
|
|
return body
|
|
}
|
|
|
|
describe("Google sampling settings", () => {
|
|
it("sends GOOGLE_TOP_K and GOOGLE_TOP_P in the generation config", async () => {
|
|
vi.stubEnv("GOOGLE_GENERATIVE_AI_API_KEY", "test-key")
|
|
vi.stubEnv("GOOGLE_TOP_K", "40")
|
|
vi.stubEnv("GOOGLE_TOP_P", "0.9")
|
|
const body = await googleRequestBody()
|
|
expect(body.generationConfig).toMatchObject({ topK: 40, topP: 0.9 })
|
|
})
|
|
|
|
it("sends neither when they are not set", async () => {
|
|
vi.stubEnv("GOOGLE_GENERATIVE_AI_API_KEY", "test-key")
|
|
vi.stubEnv("GOOGLE_TOP_K", undefined)
|
|
vi.stubEnv("GOOGLE_TOP_P", undefined)
|
|
const body = await googleRequestBody()
|
|
expect(body.generationConfig?.topK).toBeUndefined()
|
|
expect(body.generationConfig?.topP).toBeUndefined()
|
|
})
|
|
})
|
|
|
|
describe("Gemini thinking settings", () => {
|
|
it("sends GOOGLE_THINKING_BUDGET as the Gemini 2.5 thinking budget", async () => {
|
|
vi.stubEnv("GOOGLE_GENERATIVE_AI_API_KEY", "test-key")
|
|
vi.stubEnv("GOOGLE_THINKING_BUDGET", "8192")
|
|
vi.stubEnv("GOOGLE_THINKING_LEVEL", undefined)
|
|
const body = await googleRequestBody("gemini-2.5-flash")
|
|
expect(body.generationConfig.thinkingConfig).toEqual({
|
|
includeThoughts: true,
|
|
thinkingBudget: 8192,
|
|
})
|
|
})
|
|
|
|
it("sends GOOGLE_THINKING_LEVEL as the Gemini 3 thinking level", async () => {
|
|
vi.stubEnv("GOOGLE_GENERATIVE_AI_API_KEY", "test-key")
|
|
vi.stubEnv("GOOGLE_THINKING_LEVEL", "high")
|
|
vi.stubEnv("GOOGLE_THINKING_BUDGET", undefined)
|
|
const body = await googleRequestBody("gemini-3-pro-preview")
|
|
expect(body.generationConfig.thinkingConfig).toEqual({
|
|
includeThoughts: true,
|
|
thinkingLevel: "high",
|
|
})
|
|
})
|
|
})
|