Skip to content

test: add unit test suite and CI - #1

Merged
RakshithBhat03 merged 1 commit into
mainfrom
test/add-test-suite
Oct 5, 2026
Merged

RakshithBhat03 merged 1 commit into
mainfrom
test/add-test-suite

Conversation

@RakshithBhat03

Copy link
Copy Markdown
Owner

The project had four small parsing tests. This adds a suite covering every module, two bug fixes the tests turned up, and CI to run it.

Tests (70, about 1.5s)

None of them use the network, a real browser, or ~/.portmap. Probes and the HTTP API run against real sockets on ephemeral loopback ports. Thumbnail capture uses a stub "browser" shell script, and persistence uses throwaway directories. Shared fixtures are in src/testutil.rs.

  • scan: parsing of lsof/ps output, runtime/system/desktop-app classification, project detection on a temp directory tree, and HTTP probing (titles, redirects, non-HTTP listeners, address fallback, closed ports).
  • store: entry classification and state, persistence round-trip (transient fields not saved), orphan thumbnail sweep, expiry rules, view versioning and name fallback.
  • scanner: port filtering, probe caching (re-probes on restart, return, and force), stale→removed transitions, thumbnail scheduling (preference, hidden, failure backoff), batching of refresh requests.
  • server: Host and Origin/CSRF guards, every action, the end-to-end API (static assets, 304 polling, scanner wake-up, /api/refresh waiting for a scan, thumbnail serving).
  • thumbs: capture through a stub browser including the real sips JPEG conversion on macOS, failure backoff, skipped work.
  • launchd: plist rendering and escaping. main: --port parsing.

Refactors

These pull pure logic out of subprocess and socket code so it can be tested: parse_listeners/parse_ps_args/parse_cwds, scanner relevant/update/run_with, server serve/host_allowed/mutation_allowed, plist(), and parse_args(). Behavior is unchanged, except that a malformed lsof line starting with a multi-byte character is now skipped instead of panicking.

Bug fixes found by the tests

  • probe() reported a server with 3 or more chained redirects as non-HTTP, so it showed up under "other" instead of as a card. The last hop's response is now reported as-is.
  • The thumbnail worker ignored hidden. A service hidden while queued, or during a capture, got a screenshot anyway, which brought back the thumbnail that hiding had just deleted.

Verification

  • cargo test passed 10 times in a row locally. Clippy (-D warnings) and cargo fmt --check are clean.
  • I checked that the redirect test, the hidden-thumbnail tests, and the refresh-wait test each fail when their fix or behavior is reverted.
  • GPT-6.1-Sol (Codex, medium) ran two independent review rounds. Its round-1 findings are addressed here, and round 2 recommended merging.

Known follow-up (not in this PR)

A scan saves state.json only when the visible view changes, so last_seen for a long-running, unchanged service isn't persisted. If portmap restarts abruptly and the service is gone by then, its bookmark is cleared immediately instead of after the stale TTL. Fixing this needs periodic state writes, which is a separate design decision.

Cover every module with focused unit tests (70 total, ~1.5s, no network,
real browser, or ~/.portmap access):

- scan: lsof/ps output parsing, runtime/system/desktop classification,
  project detection, and HTTP probing against scripted loopback servers
- store: entry lifecycle, persistence round-trip, orphan thumbnail sweep,
  expiry rules, and view versioning
- scanner: probe caching, stale/expiry transitions, thumbnail scheduling,
  and batching of refresh requests
- server: Host/Origin guards, every action, and the HTTP API end to end
- thumbs: capture via a stub browser, sips conversion, failure backoff
- launchd plist rendering and CLI argument parsing

Small refactors separate pure logic from subprocess and socket calls so
it can be tested; behavior is unchanged.

Fixes found by the new tests:
- probe() reported servers with 3+ chained redirects as non-HTTP
- the thumbnail worker captured hidden services and restored thumbnails
  the user had just removed by hiding them

CI runs fmt, clippy, and tests on macOS for every push and pull request.
@RakshithBhat03
RakshithBhat03 merged commit 7d12541 into main Oct 5, 2026
1 check passed
@RakshithBhat03
RakshithBhat03 deleted the test/add-test-suite branch October 5, 2026 00:37
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.

1 participant