2026-02-26 13:55:21 +01:00
|
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
|
2026-01-13 22:14:45 +09:00
|
|
|
import {
|
2026-02-26 13:55:21 +01:00
|
|
|
getAIModel,
|
2026-01-13 22:14:45 +09:00
|
|
|
resolveBaseURL,
|
|
|
|
|
supportsImageInput,
|
|
|
|
|
supportsPromptCaching,
|
|
|
|
|
} from "@/lib/ai-providers"
|
|
|
|
|
|
|
|
|
|
describe("resolveBaseURL", () => {
|
|
|
|
|
const SERVER_BASE_URL = "https://server-proxy.example.com"
|
|
|
|
|
const USER_BASE_URL = "https://user-proxy.example.com"
|
|
|
|
|
const DEFAULT_BASE_URL = "https://api.provider.com/v1"
|
|
|
|
|
const USER_API_KEY = "user-api-key-123"
|
|
|
|
|
|
|
|
|
|
describe("when user provides their own API key", () => {
|
|
|
|
|
it("uses user's baseUrl when provided", () => {
|
|
|
|
|
const result = resolveBaseURL(
|
|
|
|
|
USER_API_KEY,
|
|
|
|
|
USER_BASE_URL,
|
|
|
|
|
SERVER_BASE_URL,
|
|
|
|
|
DEFAULT_BASE_URL,
|
|
|
|
|
)
|
|
|
|
|
expect(result).toBe(USER_BASE_URL)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("uses default baseUrl when user provides no baseUrl", () => {
|
|
|
|
|
const result = resolveBaseURL(
|
|
|
|
|
USER_API_KEY,
|
|
|
|
|
null,
|
|
|
|
|
SERVER_BASE_URL,
|
|
|
|
|
DEFAULT_BASE_URL,
|
|
|
|
|
)
|
|
|
|
|
expect(result).toBe(DEFAULT_BASE_URL)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("returns undefined when user provides no baseUrl and no default exists", () => {
|
|
|
|
|
const result = resolveBaseURL(
|
|
|
|
|
USER_API_KEY,
|
|
|
|
|
null,
|
|
|
|
|
SERVER_BASE_URL,
|
|
|
|
|
undefined,
|
|
|
|
|
)
|
|
|
|
|
expect(result).toBeUndefined()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("does NOT use server's baseUrl even when available", () => {
|
|
|
|
|
const result = resolveBaseURL(
|
|
|
|
|
USER_API_KEY,
|
|
|
|
|
undefined,
|
|
|
|
|
SERVER_BASE_URL,
|
|
|
|
|
undefined,
|
|
|
|
|
)
|
|
|
|
|
// Should NOT return SERVER_BASE_URL
|
|
|
|
|
expect(result).not.toBe(SERVER_BASE_URL)
|
|
|
|
|
expect(result).toBeUndefined()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("prefers user's baseUrl over default", () => {
|
|
|
|
|
const result = resolveBaseURL(
|
|
|
|
|
USER_API_KEY,
|
|
|
|
|
USER_BASE_URL,
|
|
|
|
|
SERVER_BASE_URL,
|
|
|
|
|
DEFAULT_BASE_URL,
|
|
|
|
|
)
|
|
|
|
|
expect(result).toBe(USER_BASE_URL)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe("when using server credentials (no user API key)", () => {
|
|
|
|
|
it("uses user's baseUrl when provided (overrides server)", () => {
|
|
|
|
|
const result = resolveBaseURL(
|
|
|
|
|
null,
|
|
|
|
|
USER_BASE_URL,
|
|
|
|
|
SERVER_BASE_URL,
|
|
|
|
|
DEFAULT_BASE_URL,
|
|
|
|
|
)
|
|
|
|
|
expect(result).toBe(USER_BASE_URL)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("falls back to server's baseUrl when no user baseUrl", () => {
|
|
|
|
|
const result = resolveBaseURL(
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
SERVER_BASE_URL,
|
|
|
|
|
DEFAULT_BASE_URL,
|
|
|
|
|
)
|
|
|
|
|
expect(result).toBe(SERVER_BASE_URL)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("falls back to default when no user or server baseUrl", () => {
|
|
|
|
|
const result = resolveBaseURL(
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
undefined,
|
|
|
|
|
DEFAULT_BASE_URL,
|
|
|
|
|
)
|
|
|
|
|
expect(result).toBe(DEFAULT_BASE_URL)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("returns undefined when no baseUrl available anywhere", () => {
|
|
|
|
|
const result = resolveBaseURL(null, null, undefined, undefined)
|
|
|
|
|
expect(result).toBeUndefined()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("handles undefined apiKey same as null", () => {
|
|
|
|
|
const result = resolveBaseURL(
|
|
|
|
|
undefined,
|
|
|
|
|
null,
|
|
|
|
|
SERVER_BASE_URL,
|
|
|
|
|
DEFAULT_BASE_URL,
|
|
|
|
|
)
|
|
|
|
|
expect(result).toBe(SERVER_BASE_URL)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe("edge cases", () => {
|
|
|
|
|
it("handles empty string apiKey as falsy (uses server config)", () => {
|
|
|
|
|
const result = resolveBaseURL(
|
|
|
|
|
"",
|
|
|
|
|
null,
|
|
|
|
|
SERVER_BASE_URL,
|
|
|
|
|
DEFAULT_BASE_URL,
|
|
|
|
|
)
|
|
|
|
|
// Empty string is falsy, so should use server config
|
|
|
|
|
expect(result).toBe(SERVER_BASE_URL)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("handles empty string baseUrl as falsy", () => {
|
|
|
|
|
const result = resolveBaseURL(
|
|
|
|
|
USER_API_KEY,
|
|
|
|
|
"",
|
|
|
|
|
SERVER_BASE_URL,
|
|
|
|
|
DEFAULT_BASE_URL,
|
|
|
|
|
)
|
|
|
|
|
// Empty string baseUrl is falsy, should fall back to default
|
|
|
|
|
expect(result).toBe(DEFAULT_BASE_URL)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
test: add Vitest and Playwright testing infrastructure (#512)
* test: add Vitest and Playwright testing infrastructure
- Add Vitest for unit tests (39 tests)
- cached-responses.test.ts
- ai-providers.test.ts
- chat-helpers.test.ts
- utils.test.ts
- Add Playwright for E2E tests (3 smoke tests)
- Homepage load
- Japanese locale
- Settings dialog
- Add CI workflow (.github/workflows/test.yml)
- Add vitest.config.mts and playwright.config.ts
- Update .gitignore for test artifacts
* test: add more E2E tests for UI components
- Chat panel tests (interactive elements, iframe)
- Settings tests (dark mode, language, draw.io theme)
- Save dialog tests (buttons exist)
- History dialog tests
- Model config tests
- Keyboard interaction tests
- Upload area tests
Total: 15 E2E tests, all passing
* test: fix E2E test issues from review
Fixes based on Gemini and Codex review:
- Remove brittle nth(1) selector in keyboard tests
- Remove waitForTimeout(500) race condition
- Remove if(isVisible) silent skip patterns
- Add proper assertions instead of no-op checks
- Remove expect(count >= 0) that always passes
- Remove unused hasProviderUI variable
All 14 E2E tests and 39 unit tests pass.
* style: auto-format with Biome
* fix: resolve lint errors for CI
* test(e2e): add diagram generation tests with mocked AI responses
- Add tests for generate, edit, and append diagram operations
- Use SSE mocked responses matching AI SDK UI message stream format
- Generate mxCell XML directly in tests for deterministic assertions
- Tests verify tool card rendering and 'Complete' badge state
* test: add comprehensive E2E tests for all major features
- Error handling tests (API errors, rate limits, network timeout, truncated XML)
- Multi-turn conversation tests (sequential requests, history preservation)
- File upload tests (upload button, file preview, sending with message)
- Theme switching tests (dark mode toggle, persistence, system preference)
- Language switching tests (EN/JA/ZH, persistence, locale URLs)
- Iframe interaction tests (draw.io loading, toolbar, diagram rendering)
- Copy/paste tests (chat input, XML input, special characters)
- History restore tests (new chat, persistence, browser navigation)
* refactor: extract shared test helpers and improve error assertions
- Create tests/e2e/lib/helpers.ts with shared SSE mock functions
- Add proper error UI assertions to error-handling.spec.ts
- Remove waitForTimeout calls in favor of real assertions
- Update 6 test files to use shared helpers
* docs: add testing section to CONTRIBUTING.md
* fix: improve test infrastructure based on PR review
- Fix double build in CI: remove redundant build from playwright webServer
- Export chat helpers from shared module for proper unit testing
- Replace waitForTimeout with explicit waits in E2E tests
- Add data-testid attributes to settings and new chat buttons
- Add list reporter for CI to show failures in logs
- Add Playwright browser caching to speed up CI
- Add vitest coverage configuration
- Fix conditional test assertions to use test.skip() instead of silent pass
- Remove unused variables flagged by linter
* fix: improve E2E test assertions and remove silent skips
- Replace silent test.skip() with explicit conditional skips
- Add actual persistence assertion after page reload
- Use data-testid selector for new chat button test
* refactor: add shared fixtures and test.step() patterns
- Add tests/e2e/lib/fixtures.ts with shared test helpers
- Add tests/e2e/fixtures/diagrams.ts with XML test data
- Add expectBeforeAndAfterReload() helper for persistence tests
- Add test.step() for better test reporting in complex tests
- Consolidate mock helpers into fixtures module
- Reduce code duplication across 17 test files
* fix: make persistence tests more reliable
- Remove expectBeforeAndAfterReload from mocked API tests
- Add explicit test.step() for before/after reload checks
- Add retry config for flaky clipboard tests
- Add sleep after reload for language persistence test
* test: remove flaky XML paste test
* docs: run both unit and e2e tests before PR
* chore: add type check and unit test git hooks
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-05 01:37:32 +09:00
|
|
|
|
|
|
|
|
describe("supportsPromptCaching", () => {
|
|
|
|
|
it("returns true for Claude models", () => {
|
|
|
|
|
expect(supportsPromptCaching("claude-sonnet-4-5")).toBe(true)
|
|
|
|
|
expect(supportsPromptCaching("anthropic.claude-3-5-sonnet")).toBe(true)
|
|
|
|
|
expect(supportsPromptCaching("us.anthropic.claude-3-5-sonnet")).toBe(
|
|
|
|
|
true,
|
|
|
|
|
)
|
|
|
|
|
expect(supportsPromptCaching("eu.anthropic.claude-3-5-sonnet")).toBe(
|
|
|
|
|
true,
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("returns false for non-Claude models", () => {
|
|
|
|
|
expect(supportsPromptCaching("gpt-4o")).toBe(false)
|
|
|
|
|
expect(supportsPromptCaching("gemini-pro")).toBe(false)
|
|
|
|
|
expect(supportsPromptCaching("deepseek-chat")).toBe(false)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe("supportsImageInput", () => {
|
|
|
|
|
it("returns true for models with vision capability", () => {
|
|
|
|
|
expect(supportsImageInput("gpt-4-vision")).toBe(true)
|
|
|
|
|
expect(supportsImageInput("qwen-vl")).toBe(true)
|
|
|
|
|
expect(supportsImageInput("deepseek-vl")).toBe(true)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("returns false for Kimi K2 models without vision", () => {
|
|
|
|
|
expect(supportsImageInput("kimi-k2")).toBe(false)
|
|
|
|
|
expect(supportsImageInput("moonshot/kimi-k2")).toBe(false)
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-02 00:14:27 +09:00
|
|
|
it("returns true for Kimi K2.5 models (supports vision)", () => {
|
|
|
|
|
expect(supportsImageInput("kimi-k2.5")).toBe(true)
|
|
|
|
|
expect(supportsImageInput("moonshotai/kimi-k2.5")).toBe(true)
|
|
|
|
|
})
|
|
|
|
|
|
2026-03-21 00:22:44 +08:00
|
|
|
it("returns false for Moonshot v1 text models", () => {
|
|
|
|
|
expect(supportsImageInput("moonshot-v1-8k")).toBe(false)
|
|
|
|
|
expect(supportsImageInput("moonshot-v1-32k")).toBe(false)
|
|
|
|
|
expect(supportsImageInput("moonshot-v1-128k")).toBe(false)
|
|
|
|
|
})
|
|
|
|
|
|
2026-06-02 18:38:49 +08:00
|
|
|
it("returns false for MiniMax M2 text models", () => {
|
2026-03-21 00:22:44 +08:00
|
|
|
expect(supportsImageInput("MiniMax-M2.7")).toBe(false)
|
2026-06-02 18:38:49 +08:00
|
|
|
expect(supportsImageInput("MiniMax-M2.7-highspeed")).toBe(false)
|
2026-03-21 00:22:44 +08:00
|
|
|
expect(supportsImageInput("MiniMax-M2")).toBe(false)
|
2026-06-02 18:38:49 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("returns true for MiniMax M3 (supports image input)", () => {
|
|
|
|
|
expect(supportsImageInput("MiniMax-M3")).toBe(true)
|
2026-03-21 00:22:44 +08:00
|
|
|
})
|
|
|
|
|
|
test: add Vitest and Playwright testing infrastructure (#512)
* test: add Vitest and Playwright testing infrastructure
- Add Vitest for unit tests (39 tests)
- cached-responses.test.ts
- ai-providers.test.ts
- chat-helpers.test.ts
- utils.test.ts
- Add Playwright for E2E tests (3 smoke tests)
- Homepage load
- Japanese locale
- Settings dialog
- Add CI workflow (.github/workflows/test.yml)
- Add vitest.config.mts and playwright.config.ts
- Update .gitignore for test artifacts
* test: add more E2E tests for UI components
- Chat panel tests (interactive elements, iframe)
- Settings tests (dark mode, language, draw.io theme)
- Save dialog tests (buttons exist)
- History dialog tests
- Model config tests
- Keyboard interaction tests
- Upload area tests
Total: 15 E2E tests, all passing
* test: fix E2E test issues from review
Fixes based on Gemini and Codex review:
- Remove brittle nth(1) selector in keyboard tests
- Remove waitForTimeout(500) race condition
- Remove if(isVisible) silent skip patterns
- Add proper assertions instead of no-op checks
- Remove expect(count >= 0) that always passes
- Remove unused hasProviderUI variable
All 14 E2E tests and 39 unit tests pass.
* style: auto-format with Biome
* fix: resolve lint errors for CI
* test(e2e): add diagram generation tests with mocked AI responses
- Add tests for generate, edit, and append diagram operations
- Use SSE mocked responses matching AI SDK UI message stream format
- Generate mxCell XML directly in tests for deterministic assertions
- Tests verify tool card rendering and 'Complete' badge state
* test: add comprehensive E2E tests for all major features
- Error handling tests (API errors, rate limits, network timeout, truncated XML)
- Multi-turn conversation tests (sequential requests, history preservation)
- File upload tests (upload button, file preview, sending with message)
- Theme switching tests (dark mode toggle, persistence, system preference)
- Language switching tests (EN/JA/ZH, persistence, locale URLs)
- Iframe interaction tests (draw.io loading, toolbar, diagram rendering)
- Copy/paste tests (chat input, XML input, special characters)
- History restore tests (new chat, persistence, browser navigation)
* refactor: extract shared test helpers and improve error assertions
- Create tests/e2e/lib/helpers.ts with shared SSE mock functions
- Add proper error UI assertions to error-handling.spec.ts
- Remove waitForTimeout calls in favor of real assertions
- Update 6 test files to use shared helpers
* docs: add testing section to CONTRIBUTING.md
* fix: improve test infrastructure based on PR review
- Fix double build in CI: remove redundant build from playwright webServer
- Export chat helpers from shared module for proper unit testing
- Replace waitForTimeout with explicit waits in E2E tests
- Add data-testid attributes to settings and new chat buttons
- Add list reporter for CI to show failures in logs
- Add Playwright browser caching to speed up CI
- Add vitest coverage configuration
- Fix conditional test assertions to use test.skip() instead of silent pass
- Remove unused variables flagged by linter
* fix: improve E2E test assertions and remove silent skips
- Replace silent test.skip() with explicit conditional skips
- Add actual persistence assertion after page reload
- Use data-testid selector for new chat button test
* refactor: add shared fixtures and test.step() patterns
- Add tests/e2e/lib/fixtures.ts with shared test helpers
- Add tests/e2e/fixtures/diagrams.ts with XML test data
- Add expectBeforeAndAfterReload() helper for persistence tests
- Add test.step() for better test reporting in complex tests
- Consolidate mock helpers into fixtures module
- Reduce code duplication across 17 test files
* fix: make persistence tests more reliable
- Remove expectBeforeAndAfterReload from mocked API tests
- Add explicit test.step() for before/after reload checks
- Add retry config for flaky clipboard tests
- Add sleep after reload for language persistence test
* test: remove flaky XML paste test
* docs: run both unit and e2e tests before PR
* chore: add type check and unit test git hooks
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-05 01:37:32 +09:00
|
|
|
it("returns false for DeepSeek text models", () => {
|
|
|
|
|
expect(supportsImageInput("deepseek-chat")).toBe(false)
|
|
|
|
|
expect(supportsImageInput("deepseek-coder")).toBe(false)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("returns false for Qwen text models", () => {
|
|
|
|
|
expect(supportsImageInput("qwen-turbo")).toBe(false)
|
|
|
|
|
expect(supportsImageInput("qwen-plus")).toBe(false)
|
2026-03-21 00:22:44 +08:00
|
|
|
expect(supportsImageInput("qwen3-max")).toBe(false)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("returns true for Qwen vision models", () => {
|
|
|
|
|
expect(supportsImageInput("qwen-vl")).toBe(true)
|
2026-04-10 09:23:39 +08:00
|
|
|
expect(supportsImageInput("Qwen3.5")).toBe(true)
|
|
|
|
|
expect(supportsImageInput("qwen3.5")).toBe(true)
|
2026-03-21 00:22:44 +08:00
|
|
|
expect(supportsImageInput("qwen3.5-plus")).toBe(true)
|
|
|
|
|
expect(supportsImageInput("qwen3.5-flash")).toBe(true)
|
|
|
|
|
expect(supportsImageInput("qwen3-vl-plus")).toBe(true)
|
|
|
|
|
expect(supportsImageInput("qwen3-vl-flash")).toBe(true)
|
|
|
|
|
})
|
|
|
|
|
|
2026-04-13 19:05:57 +08:00
|
|
|
it("returns true for QvQ (Qwen Visual QA) models including OpenRouter-prefixed names", () => {
|
|
|
|
|
expect(supportsImageInput("qvq-72b-preview")).toBe(true)
|
|
|
|
|
expect(supportsImageInput("qvq-max")).toBe(true)
|
|
|
|
|
expect(supportsImageInput("qwen/qvq-72b-preview")).toBe(true)
|
|
|
|
|
expect(supportsImageInput("qwen/qvq-max")).toBe(true)
|
|
|
|
|
})
|
|
|
|
|
|
2026-03-21 00:22:44 +08:00
|
|
|
it("returns false for GLM text models", () => {
|
|
|
|
|
expect(supportsImageInput("glm-4")).toBe(false)
|
|
|
|
|
expect(supportsImageInput("glm-4-plus")).toBe(false)
|
|
|
|
|
expect(supportsImageInput("glm-4-flash")).toBe(false)
|
|
|
|
|
expect(supportsImageInput("glm-4-long")).toBe(false)
|
|
|
|
|
expect(supportsImageInput("glm-4.7")).toBe(false)
|
|
|
|
|
expect(supportsImageInput("glm-5")).toBe(false)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("returns true for GLM vision models", () => {
|
|
|
|
|
expect(supportsImageInput("glm-4v")).toBe(true)
|
|
|
|
|
expect(supportsImageInput("glm-4v-9b")).toBe(true)
|
|
|
|
|
expect(supportsImageInput("glm-4.1v-9b-thinking")).toBe(true)
|
test: add Vitest and Playwright testing infrastructure (#512)
* test: add Vitest and Playwright testing infrastructure
- Add Vitest for unit tests (39 tests)
- cached-responses.test.ts
- ai-providers.test.ts
- chat-helpers.test.ts
- utils.test.ts
- Add Playwright for E2E tests (3 smoke tests)
- Homepage load
- Japanese locale
- Settings dialog
- Add CI workflow (.github/workflows/test.yml)
- Add vitest.config.mts and playwright.config.ts
- Update .gitignore for test artifacts
* test: add more E2E tests for UI components
- Chat panel tests (interactive elements, iframe)
- Settings tests (dark mode, language, draw.io theme)
- Save dialog tests (buttons exist)
- History dialog tests
- Model config tests
- Keyboard interaction tests
- Upload area tests
Total: 15 E2E tests, all passing
* test: fix E2E test issues from review
Fixes based on Gemini and Codex review:
- Remove brittle nth(1) selector in keyboard tests
- Remove waitForTimeout(500) race condition
- Remove if(isVisible) silent skip patterns
- Add proper assertions instead of no-op checks
- Remove expect(count >= 0) that always passes
- Remove unused hasProviderUI variable
All 14 E2E tests and 39 unit tests pass.
* style: auto-format with Biome
* fix: resolve lint errors for CI
* test(e2e): add diagram generation tests with mocked AI responses
- Add tests for generate, edit, and append diagram operations
- Use SSE mocked responses matching AI SDK UI message stream format
- Generate mxCell XML directly in tests for deterministic assertions
- Tests verify tool card rendering and 'Complete' badge state
* test: add comprehensive E2E tests for all major features
- Error handling tests (API errors, rate limits, network timeout, truncated XML)
- Multi-turn conversation tests (sequential requests, history preservation)
- File upload tests (upload button, file preview, sending with message)
- Theme switching tests (dark mode toggle, persistence, system preference)
- Language switching tests (EN/JA/ZH, persistence, locale URLs)
- Iframe interaction tests (draw.io loading, toolbar, diagram rendering)
- Copy/paste tests (chat input, XML input, special characters)
- History restore tests (new chat, persistence, browser navigation)
* refactor: extract shared test helpers and improve error assertions
- Create tests/e2e/lib/helpers.ts with shared SSE mock functions
- Add proper error UI assertions to error-handling.spec.ts
- Remove waitForTimeout calls in favor of real assertions
- Update 6 test files to use shared helpers
* docs: add testing section to CONTRIBUTING.md
* fix: improve test infrastructure based on PR review
- Fix double build in CI: remove redundant build from playwright webServer
- Export chat helpers from shared module for proper unit testing
- Replace waitForTimeout with explicit waits in E2E tests
- Add data-testid attributes to settings and new chat buttons
- Add list reporter for CI to show failures in logs
- Add Playwright browser caching to speed up CI
- Add vitest coverage configuration
- Fix conditional test assertions to use test.skip() instead of silent pass
- Remove unused variables flagged by linter
* fix: improve E2E test assertions and remove silent skips
- Replace silent test.skip() with explicit conditional skips
- Add actual persistence assertion after page reload
- Use data-testid selector for new chat button test
* refactor: add shared fixtures and test.step() patterns
- Add tests/e2e/lib/fixtures.ts with shared test helpers
- Add tests/e2e/fixtures/diagrams.ts with XML test data
- Add expectBeforeAndAfterReload() helper for persistence tests
- Add test.step() for better test reporting in complex tests
- Consolidate mock helpers into fixtures module
- Reduce code duplication across 17 test files
* fix: make persistence tests more reliable
- Remove expectBeforeAndAfterReload from mocked API tests
- Add explicit test.step() for before/after reload checks
- Add retry config for flaky clipboard tests
- Add sleep after reload for language persistence test
* test: remove flaky XML paste test
* docs: run both unit and e2e tests before PR
* chore: add type check and unit test git hooks
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-05 01:37:32 +09:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("returns true for Claude and GPT models by default", () => {
|
|
|
|
|
expect(supportsImageInput("claude-sonnet-4-5")).toBe(true)
|
|
|
|
|
expect(supportsImageInput("gpt-4o")).toBe(true)
|
|
|
|
|
expect(supportsImageInput("gemini-pro")).toBe(true)
|
|
|
|
|
})
|
|
|
|
|
})
|
2026-02-26 13:55:21 +01:00
|
|
|
|
|
|
|
|
vi.mock("ollama-ai-provider-v2", () => {
|
|
|
|
|
const mockModel = { modelId: "test-model" }
|
|
|
|
|
const mockProviderFn = vi.fn(() => mockModel)
|
|
|
|
|
const mockCreateOllama = vi.fn(() => mockProviderFn)
|
|
|
|
|
const mockOllama = vi.fn(() => mockModel)
|
|
|
|
|
return { createOllama: mockCreateOllama, ollama: mockOllama }
|
|
|
|
|
})
|
|
|
|
|
|
2026-05-15 13:02:26 +08:00
|
|
|
vi.mock("@ai-sdk/deepseek", () => {
|
|
|
|
|
const mockModel = { modelId: "test-model" }
|
|
|
|
|
const mockProviderFn = vi.fn(() => mockModel)
|
|
|
|
|
const mockCreateDeepSeek = vi.fn(() => mockProviderFn)
|
|
|
|
|
const mockDeepseek = vi.fn(() => mockModel)
|
|
|
|
|
return { createDeepSeek: mockCreateDeepSeek, deepseek: mockDeepseek }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe("Kimi provider uses createDeepSeek for reasoning_content support", () => {
|
|
|
|
|
let createDeepSeekMock: ReturnType<typeof vi.fn>
|
|
|
|
|
const savedEnv: Record<string, string | undefined> = {}
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
savedEnv.KIMI_API_KEY = process.env.KIMI_API_KEY
|
|
|
|
|
savedEnv.KIMI_BASE_URL = process.env.KIMI_BASE_URL
|
|
|
|
|
delete process.env.KIMI_BASE_URL
|
|
|
|
|
|
|
|
|
|
const mod = await import("@ai-sdk/deepseek")
|
|
|
|
|
createDeepSeekMock = mod.createDeepSeek as ReturnType<typeof vi.fn>
|
|
|
|
|
createDeepSeekMock.mockClear()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
process.env.KIMI_API_KEY = savedEnv.KIMI_API_KEY
|
|
|
|
|
process.env.KIMI_BASE_URL = savedEnv.KIMI_BASE_URL
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("uses createDeepSeek with Kimi default base URL for reasoning_content support", () => {
|
|
|
|
|
process.env.KIMI_API_KEY = "test-kimi-key"
|
|
|
|
|
|
|
|
|
|
getAIModel({
|
|
|
|
|
provider: "kimi",
|
|
|
|
|
apiKey: "test-kimi-key",
|
|
|
|
|
modelId: "moonshot-v1-8k",
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(createDeepSeekMock).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
baseURL: "https://api.moonshot.cn/v1",
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("uses custom base URL when provided for kimi provider", () => {
|
|
|
|
|
process.env.KIMI_API_KEY = "test-kimi-key"
|
|
|
|
|
|
|
|
|
|
getAIModel({
|
|
|
|
|
provider: "kimi",
|
|
|
|
|
apiKey: "test-kimi-key",
|
|
|
|
|
baseUrl: "https://custom-kimi-endpoint.com/v1",
|
|
|
|
|
modelId: "kimi-k2.6",
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(createDeepSeekMock).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
baseURL: "https://custom-kimi-endpoint.com/v1",
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-26 13:55:21 +01:00
|
|
|
describe("Ollama API key security", () => {
|
|
|
|
|
let createOllamaMock: ReturnType<typeof vi.fn>
|
|
|
|
|
const savedEnv: Record<string, string | undefined> = {}
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
savedEnv.OLLAMA_API_KEY = process.env.OLLAMA_API_KEY
|
|
|
|
|
savedEnv.OLLAMA_BASE_URL = process.env.OLLAMA_BASE_URL
|
|
|
|
|
delete process.env.OLLAMA_BASE_URL
|
|
|
|
|
|
|
|
|
|
const mod = await import("ollama-ai-provider-v2")
|
|
|
|
|
createOllamaMock = mod.createOllama as ReturnType<typeof vi.fn>
|
|
|
|
|
createOllamaMock.mockClear()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
process.env.OLLAMA_API_KEY = savedEnv.OLLAMA_API_KEY
|
|
|
|
|
process.env.OLLAMA_BASE_URL = savedEnv.OLLAMA_BASE_URL
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("applies server OLLAMA_API_KEY when no client baseUrl is provided", () => {
|
|
|
|
|
process.env.OLLAMA_API_KEY = "server-secret-key"
|
|
|
|
|
|
|
|
|
|
getAIModel({ provider: "ollama", modelId: "llama2" })
|
|
|
|
|
|
|
|
|
|
expect(createOllamaMock).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
headers: { Authorization: "Bearer server-secret-key" },
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("does NOT leak server OLLAMA_API_KEY when client provides a custom baseUrl", () => {
|
|
|
|
|
process.env.OLLAMA_API_KEY = "server-secret-key"
|
|
|
|
|
|
|
|
|
|
// When server has OLLAMA_API_KEY, the SSRF guard rejects
|
|
|
|
|
// client-provided baseUrl without an apiKey outright
|
|
|
|
|
expect(() =>
|
|
|
|
|
getAIModel({
|
|
|
|
|
provider: "ollama",
|
|
|
|
|
baseUrl: "https://evil-server.com",
|
|
|
|
|
modelId: "llama2",
|
|
|
|
|
}),
|
|
|
|
|
).toThrow("API key is required")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("uses client API key when client provides both baseUrl and apiKey", () => {
|
|
|
|
|
process.env.OLLAMA_API_KEY = "server-secret-key"
|
|
|
|
|
|
|
|
|
|
getAIModel({
|
|
|
|
|
provider: "ollama",
|
|
|
|
|
baseUrl: "https://my-ollama.com",
|
|
|
|
|
apiKey: "client-key",
|
|
|
|
|
modelId: "llama2",
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(createOllamaMock).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
baseURL: "https://my-ollama.com",
|
|
|
|
|
headers: { Authorization: "Bearer client-key" },
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("applies both server OLLAMA_BASE_URL and OLLAMA_API_KEY when no client overrides", () => {
|
|
|
|
|
process.env.OLLAMA_BASE_URL = "https://cloud.ollama.com"
|
|
|
|
|
process.env.OLLAMA_API_KEY = "server-key"
|
|
|
|
|
|
|
|
|
|
getAIModel({ provider: "ollama", modelId: "llama2" })
|
|
|
|
|
|
|
|
|
|
expect(createOllamaMock).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
baseURL: "https://cloud.ollama.com",
|
|
|
|
|
headers: { Authorization: "Bearer server-key" },
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("works when OLLAMA_API_KEY is set but OLLAMA_BASE_URL is not", () => {
|
|
|
|
|
process.env.OLLAMA_API_KEY = "server-key"
|
|
|
|
|
delete process.env.OLLAMA_BASE_URL
|
|
|
|
|
|
|
|
|
|
getAIModel({ provider: "ollama", modelId: "llama2" })
|
|
|
|
|
|
|
|
|
|
expect(createOllamaMock).toHaveBeenCalledTimes(1)
|
|
|
|
|
const callArgs = createOllamaMock.mock.calls[0][0]
|
|
|
|
|
expect(callArgs).not.toHaveProperty("baseURL")
|
|
|
|
|
expect(callArgs).toEqual(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
headers: { Authorization: "Bearer server-key" },
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("allows client custom baseUrl without apiKey when no server OLLAMA_API_KEY", () => {
|
|
|
|
|
delete process.env.OLLAMA_API_KEY
|
|
|
|
|
|
|
|
|
|
getAIModel({
|
|
|
|
|
provider: "ollama",
|
|
|
|
|
baseUrl: "https://my-ollama.com",
|
|
|
|
|
modelId: "llama2",
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(createOllamaMock).toHaveBeenCalledTimes(1)
|
|
|
|
|
const callArgs = createOllamaMock.mock.calls[0][0]
|
|
|
|
|
expect(callArgs.baseURL).toBe("https://my-ollama.com")
|
|
|
|
|
expect(callArgs).not.toHaveProperty("headers")
|
|
|
|
|
})
|
|
|
|
|
})
|