test(ai): add Vitest infrastructure and 56 unit tests for ai-provider#12
Closed
test(ai): add Vitest infrastructure and 56 unit tests for ai-provider#12
Conversation
…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
|
before merging please have a look at #68 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9
Summary
npm test/npm run test:watchscriptsvitest.config.tstargeting the Node environment (no Electron needed to run tests)ai-provider.tsto make them unit-testable (resolveModel,resolveCompatibleChatUrl,parseSSE,parseNDJSON,resolveUploadMeta)resolveCompatibleChatUrlhelper (used bystreamOpenAICompatibleinternally)Test coverage — 56 tests across 6 suites
isAIAvailableenabled: falseshort-circuit, missing credential edges (openai-compatible requires both URL and key)resolveModelresolveCompatibleChatUrl/v1, trailing slash, localhost with port, no double-insert of/v1parseSSE[DONE]sentinel, multi-line, split-chunk reassembly, malformed JSON skip, trailing bufferparseNDJSONresolveUploadMetaundefined/empty fallbackHow to run
Tests complete in ~300ms with zero network calls.