Skip to content

test: add unit tests for lowest-coverage packages#91

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
feat/add-unit-tests-low-coverage
Open

test: add unit tests for lowest-coverage packages#91
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
feat/add-unit-tests-low-coverage

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

go test -cover ./... surfaced four packages with 0% coverage (no test files at all). This PR adds table-driven unit tests for the three lowest-coverage/untested logic packages plus the pure modelref parser, without touching any production code.

Package Before After
internal/modelref 0.0% 100.0%
internal/service/server/trace 0.0% 100.0%
internal/service/server/usage 0.0% 100.0%
internal/service/server/session 0.0% 94.9%

What the new tests cover:

  • modelref.Parse — both provider/model and model(provider) forms, whitespace trimming, precedence of the paren form, and fallbacks (empty provider/model inside parens, (x) at index 0, missing ), multi-slash, empty string).
  • session.InMemoryManagerGetOrCreate create-vs-reuse, TTL pruning (both explicit Prune and prune-on-lookup), LRU eviction under MaxSessions including recency update on reuse, List snapshot, NewEphemeral not being tracked, and the plugin-registry ExtensionData init/backfill branches. Remaining uncovered lines are the hourly startPruning ticker.
  • trace.FileWriterWriteTrace category dispatch (Chat / Response / Anthropic, individually and combined) verified by inspecting files written to a temp dir, no-category / disabled-tracer / nil-tracer no-ops, and the WriteCategory error-reporting branch (forced via an unwritable root).
  • usage.StatsTrackerRecordBilling accounting + cost, CostForRequest computation (no side effects), unknown-model and nil-stats guards.

Tests use dependency injection via small fakes (fakeConfig implementing ConfigAccessor) and real collaborators (plugin.NewRegistry(nil), stats.NewSessionStats, mbtrace.New(...) with t.TempDir()), mirroring the existing test style in the repo.

go test ./... and go vet pass; gofmt clean.

Link to Devin session: https://app.devin.ai/sessions/2db8a2c166aa495e984b9fbcb97fe9bf
Requested by: @ZhiYi-R

Add unit tests for four packages that previously had 0% coverage:
- internal/modelref (Parse) -> 100%
- internal/service/server/session (InMemoryManager) -> ~95%
- internal/service/server/trace (FileWriter) -> 100%
- internal/service/server/usage (StatsTracker) -> 100%

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@ZhiYi-R ZhiYi-R self-assigned this Jul 11, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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.

2 participants