Skip to content

Increase test coverage to prevent regressions #25

@jkeresman01

Description

@jkeresman01

Title: Increase test coverage to prevent regressions

Summary

Recent refactors (e.g., dependency picker ↔ UI adapter) exposed gaps in test coverage that allowed breaking changes to be delivered. Expand automated tests to cover core modules and integration paths to prevent similar regressions.

Scope

  • Add/extend unit tests across modules
  • Add light integration “smoke” tests for UI wiring
  • Keep the Arrange–Act–Assert convention
  • Reuse the existing Plenary/Busted runner and tests/minimal_init.lua

Target Areas

  1. algo/hashset.lua

    • Already covered; add edge cases (nil inputs, boolean keys, large inserts, union with empty set).
  2. telescope/telescope.lua (dependency picker)

    • Flattens groups correctly (empty groups, missing values).
    • Entry formatting ([Group] Name) and ordering.
    • Selection handler calls record_selection once per confirm.
    • No duplicates when the same item is confirmed multiple times.
  3. ui/deps.lua (adapter used by layout)

    • create_button maps <CR> to open picker and then calls update_display.
    • create_display initializes buffer and first render.
    • update_display renders “no items” vs list state.
    • (Stub/mocking) Verify it reads from telescope.selected_dependencies.
  4. ui/layout.lua

    • “Builds” end-to-end without throwing (smoke test).
    • Left/right panels both mount; focus maps exist.
  5. metadata/metadata.lua

    • Successful decode: calls callbacks with table and sets loaded.
    • Failed decode: sets error, calls callbacks with error.
    • Subsequent fetch_metadata returns cached data without issuing a job.
  6. utils/

    • url: urlencode and encode_query (reserved chars, spaces, unicode).
    • http: download_file success vs non-zero exit (mock Job).
    • file: unzip triggers on_done and removes file (mock Job, stub os.remove).
    • window: get_winid for {winid} vs {popup.winid}; safe_close no-op on invalid.

Proposed Plan

  • Create new specs in tests/ mirroring module paths:
    tests/
    ├── algo/hashset_spec.lua
    ├── telescope/telescope_spec.lua
    ├── ui/deps_spec.lua
    ├── ui/layout_smoke_spec.lua
    ├── metadata/metadata_spec.lua
    └── utils/
        ├── url_spec.lua
        ├── http_spec.lua
        ├── file_spec.lua
        └── window_spec.lua
    
  • Use Plenary stubs/mocks:
    • Stub require("plenary.job").new to inject fake on_exit, result, stderr_result.
    • For UI smoke tests, construct minimal instances and assert no exceptions and expected side-effects (buffer lines, keymaps exist).
  • Keep tests headless; avoid real network/file system effects.

CI Integration

  • Reuse/extend existing test workflow:
    • Ensure plenary is installed (vendor path) in CI.
    • Run: nvim --headless -u tests/minimal_init.lua -c "PlenaryBustedDirectory tests" +q

Acceptance Criteria

  • Specs exist for all modules listed in Target Areas.
  • Tests follow Arrange–Act–Assert and run headlessly via Plenary/Busted.
  • ui/layout.lua smoke test mounts the layout without runtime errors.
  • ui/deps.lua adapter tests verify create_button, create_display, update_display behavior and interaction with the picker state.
  • metadata.lua tests cover success, parse failure, and cache hit paths.
  • utils tests cover happy paths and error branches.
  • CI test job passes on push and pull_request to main.

Notes

  • Where direct mocking is awkward, wrap external calls (e.g., Job/new) behind tiny local helpers to make stubbing easier in tests.
  • Keep tests deterministic and avoid timing flakiness by calling scheduled callbacks synchronously where practical.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestmediumDifficulty level of this issue is: MEDIUM

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions