Skip to content

test(ai): add Vitest infrastructure and 56 unit tests for ai-provider#12

Closed
elicep01 wants to merge 2 commits intomainfrom
feat/add-test-coverage
Closed

test(ai): add Vitest infrastructure and 56 unit tests for ai-provider#12
elicep01 wants to merge 2 commits intomainfrom
feat/add-test-coverage

Conversation

@elicep01
Copy link
Collaborator

Closes #9

Summary

  • Installs Vitest and adds npm test / npm run test:watch scripts
  • Adds vitest.config.ts targeting the Node environment (no Electron needed to run tests)
  • Exports internal helpers from ai-provider.ts to make them unit-testable (resolveModel, resolveCompatibleChatUrl, parseSSE, parseNDJSON, resolveUploadMeta)
  • Extracts the base-URL normalisation logic into a named resolveCompatibleChatUrl helper (used by streamOpenAICompatible internally)

Test coverage — 56 tests across 6 suites

Suite What's tested
isAIAvailable All 4 providers, enabled: false short-circuit, missing credential edges (openai-compatible requires both URL and key)
resolveModel Known table keys, prefix stripping for all providers, openai-compatible- prefix must be checked before openai- (regression guard for the bug fixed in #5), defaultModel fallbacks, provider defaults
resolveCompatibleChatUrl Base URL with/without /v1, trailing slash, localhost with port, no double-insert of /v1
parseSSE Single chunk, [DONE] sentinel, multi-line, split-chunk reassembly, malformed JSON skip, trailing buffer
parseNDJSON Same breadth as parseSSE, Ollama NDJSON format
resolveUploadMeta All 6 MIME types + undefined/empty fallback

How to run

npm test          # run once
npm run test:watch  # watch mode during development

Tests complete in ~300ms with zero network calls.

…itical paths

Closes #9

- Install Vitest and add `test` / `test:watch` npm scripts
- Add vitest.config.ts targeting Node environment
- Export resolveModel, resolveCompatibleChatUrl (extracted helper),
  parseSSE, parseNDJSON, and resolveUploadMeta for testability
- 56 unit tests covering:
  - isAIAvailable: all 4 providers, enabled flag, missing credential edges
  - resolveModel: known table keys, prefix stripping, openai-compatible-
    prefix ordering regression, defaultModel fallbacks, provider defaults
  - resolveCompatibleChatUrl: with/without /v1, trailing slash, localhost,
    no double-insert guard
  - parseSSE: single chunk, [DONE] sentinel, multi-line, split-chunk
    reassembly, malformed JSON, trailing buffer
  - parseNDJSON: same coverage as parseSSE for Ollama NDJSON format
  - resolveUploadMeta: all 6 MIME types + undefined/empty fallback
@bircni
Copy link

bircni commented Feb 21, 2026

before merging please have a look at #68

@elicep01 elicep01 closed this Mar 2, 2026
@elicep01 elicep01 deleted the feat/add-test-coverage branch March 2, 2026 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: add test coverage for critical paths

2 participants