Skip to content

Add unit tests for daemonState.ts (pidAlive / readDaemonState / httpReachable) #26

Description

@vincentvella

Problem. src/daemonState.ts has no isolated unit tests, yet it backs the shared-mode auto-connect story (--shared, daemon --status, daemon --stop). Untested edge-case logic:

  • pidAlive — the EPERM branch (process exists but not signalable) should count as alive.
  • readDaemonState — JSON parse + schema validation (malformed/partial state file → null).
  • httpReachable — timeout and connection-error paths.

A regression here silently breaks all of shared mode, and the cockpit selftest doesn't cover it.

Proposed. Add test/daemonState.test.ts (bun test) exercising those branches with injected fs/probe seams (mirroring the style of the existing pure-logic tests).

Affected: src/daemonState.ts, new test/daemonState.test.ts.

Filed from the weekly repo audit.

Metadata

Metadata

Assignees

Labels

testTest coverage

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions