Skip to content

[nightshift] test-gap: test coverage gap analysis #52

@nightshift-micr

Description

@nightshift-micr

Test Coverage Gap Analysis — Microck/kagi-cli

Summary

Module Lines (approx) Test Count Coverage Assessment
src/api.rs ~5165 54 Good — extensive unit tests for parsing, normalization, stream handling
src/auth.rs ~880 19 Good — credential management, normalization, save/load
src/auth_wizard.rs ~655 9 Moderate — helper functions tested, interactive wizard untested
src/cli.rs ~1324 6 Adequate — validation and parsing tested
src/error.rs ~25 0 No tests — thin wrapper, low risk
src/http.rs ~169 2 Minimal — URL building tested, error mapping untested
src/main.rs ~1595 15 Moderate — output formatting tested, routing/command wiring untested
src/parser.rs ~917 12 Good — all major parsers tested
src/quick.rs ~756 10 Good — stream parsing and formatting tested
src/search.rs ~653 11 Good — validation, query building, error handling tested
src/types.rs ~902 0 No tests — data types only
tests/integration-cli.rs ~422 7 Sparse — only search, batch, auth check, summarize, news tested

Total: ~145 tests across 10 source modules + 1 integration test file.


P0 Critical — Core Business Logic Without ANY Tests

1. Integration tests missing for 8+ CLI commands

Commands with zero integration test coverage:

  • kagi assistant (all subcommands: thread list/get/delete/export, custom assistant CRUD, prompt)
  • kagi ask-page
  • kagi quick
  • kagi translate
  • kagi fastgpt
  • kagi enrich (web/news)
  • kagi smallweb
  • kagi lens (all subcommands)
  • kagi bang (all subcommands)
  • kagi redirect (all subcommands)

Only 5 of 13+ commands have integration tests.

2. execute_translate() orchestration untested

  • File: src/api.rs lines ~1800–2800
  • Individual parsing functions are unit-tested, but the full orchestration flow is not.
  • Suggested test: Integration test using httpmock to mock translate endpoints.

3. Full CLI command routing untested

  • File: src/main.rs lines 90–658
  • The run() function dispatches to 13+ command variants with mostly untested paths.

P1 High — Error Handling Paths Untested

4. map_transport_error() — no unit tests

  • File: src/http.rs line 33
  • Suggested test: Verify timeout, connect, and generic error mappings.

5. HTTP status error branches in decode_kagi_*() functions untested

  • File: src/api.rs lines 3508–3629
  • None of the error branches (401, 403, 5xx, unexpected status) are tested.
  • Suggested test: ~10 tests using mock reqwest::Response objects.

6. Search fallback logic (API → session token) untested

  • File: src/main.rs lines 713–742
  • Suggested test: Integration test where first API search returns 403, fallback succeeds.

7. run() error paths untested

  • File: src/main.rs
  • Including: bare auth non-interactive, conflicting flags, missing command, summarize flag combinations.

8. HTTP error status branches in search.rs and quick.rs

  • Only #[ignore] live tests exist for error paths.

P2 Medium — Edge Cases Not Covered

9. Serde roundtrip tests missing

  • File: src/types.rs (902 lines, 0 tests)
  • Suggested test: Roundtrip tests for SearchResponse, AssistantPromptResponse, TranslateTextResponse, NewsStoriesResponse.

10. Parser error path tests with malformed HTML

  • File: src/parser.rs
  • All tests use valid HTML. No tests for missing title, missing href, missing attributes.

11. Batch search output formats untested

  • File: src/main.rs lines 1129–1241
  • Only JSON format integration-tested. Pretty, markdown, CSV formats untested.

12. Assistant stream error parsing

  • Files: src/api.rs stream parsers
  • Not tested with empty streams, unknown tags, or invalid JSON payloads.

P3 Low — Nice-to-Have

13. Display/format trait tests for CLI enums

14. format_status() with empty credential inventory

15. format_pretty_response() with published dates

16. format_client_error_suffix() with JSON/HTML/empty bodies


Recommended Actions

Priority Action Est. Tests
P0 Integration tests for 8+ CLI commands ~15-20 tests
P0 Unit tests for execute_translate() with mocks ~5 tests
P1 Tests for map_transport_error() ~3 tests
P1 HTTP status error branch tests ~10 tests
P1 Search fallback integration test ~1 test
P1 run() error path tests ~5 tests
P2 Serde roundtrip tests ~8 tests
P2 Parser error path tests ~6 tests
P2 Batch search format tests ~3 tests

Automated by Nightshift v3 (GLM 5.1) — merge if useful, close if not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions