Skip to content

Add unit tests for doctor.ts #16

@isaacsight

Description

@isaacsight

What

Add a test file packages/kbot/src/doctor.test.ts with unit tests for the diagnostic checks in doctor.ts.

Why

doctor.ts is a critical user-facing command (the first thing people run when something is wrong), but it has zero test coverage. The individual check functions (checkNodeVersion, checkApiKey, checkGit, etc.) are pure enough to test in isolation, and regressions here would confuse new users.

Suggested approach

  1. Create packages/kbot/src/doctor.test.ts.
  2. Test the exported functions: runDoctor() and formatDoctorReport().
  3. Mock external dependencies:
    • Mock child_process.execSync for checkNpmVersion, checkGit, etc.
    • Mock ./auth.js (loadConfig, isByokEnabled, getByokProvider) for checkApiKey.
    • Mock fetch for checkProviderReachable and checkLocalRuntimes.
    • Mock ./machine.js for hardware checks.
  4. Test cases to cover:
    • All checks pass (happy path)
    • Missing API key returns fail status
    • Old Node.js version returns fail status
    • Unreachable provider returns warn status
    • formatDoctorReport renders pass/warn/fail correctly
    • Overall status is fail if any check fails, warn if any warns

Follow the patterns in existing test files like auth.test.ts and sessions.test.ts.

Files to look at

  • packages/kbot/src/doctor.ts — The module to test (all check functions + runDoctor + formatDoctorReport)
  • packages/kbot/src/auth.test.ts — Example of how tests are structured in this project
  • packages/kbot/src/sessions.test.ts — Another test file to reference for mocking patterns

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions