Skip to content

test: cover the tui lifecycle and theme switching - #23

Merged
clappingmonkey merged 1 commit into
mainfrom
test/tui-lifecycle
Sep 26, 2026
Merged

clappingmonkey merged 1 commit into
mainfrom
test/tui-lifecycle

Conversation

@clappingmonkey

Copy link
Copy Markdown
Owner

What & why

Adds test/tui.test.ts, which tests the tui function itself: timers, lifecycle and theme switching. Until now only the pure helpers had tests. The tests call the real tui export with a fake host API and node:test mock timers (Date, setInterval, setTimeout). No source changes.

16 tests covering the rules the plugin relies on:

  • startup at night and during the day; toast: false
  • a manual theme change survives until the next day/night boundary
  • theme not ready yet: retried every 250 ms, with only one retry pending at a time, including while interval ticks keep firing
  • theme.set() fails: retried on the next interval, the period isn't marked as handled
  • theme not installed: warns once per period
  • solar mode switches at sunrise; solar mode without coordinates warns and falls back to fixed hours
  • signal already aborted before startup; abort, dispose, and abort followed by dispose all clear the timers
  • errors thrown by the host API are caught, and the next tick retries

Closes #

Behavior impact

  • Theme-switching logic (periodFor, boundaries, gentle override)
  • Plugin options (dayTheme, nightTheme, dayStartHour, nightStartHour,
    checkIntervalMs, toast) — README options table updated
  • Lifecycle / timer / toast behavior
  • Packaging (package.json exports, files, published contents)
  • No user-facing behavior change

Testing

  • npm run typecheck passes (TypeScript 7.0.2)
  • npm test passes (38 tests)
  • Manually verified in opencode (if behavior changed): not needed, tests only

Also:

  • passes with TZ set to UTC, Pacific/Kiritimati, America/St_Johns and Australia/Lord_Howe
  • mutation check: removing any one guard in tui makes at least one test fail. The guards are the abort listener, onDispose, the aborted-at-start check, the boundary-only check, not-ready/failed not marking the period handled, the ready retry and its single-pending guard, and the try/catch.
  • npm pack --dry-run is unchanged (tests aren't published)

Checklist

  • PR title follows Conventional Commits
    (enforced by the PR Title check; drives the release-please version bump)
  • Defaults still work with zero config
  • Docs updated if behavior/config changed (no behavior change)
  • No secrets or credentials introduced

Drive the real tui export with a fake host API and node:test mock timers to lock down startup, gentle override, not-ready/failed retries, missing-theme warning, solar mode, and abort/dispose cleanup.
@clappingmonkey
clappingmonkey merged commit 212bafc into main Sep 26, 2026
3 checks passed
@clappingmonkey
clappingmonkey deleted the test/tui-lifecycle branch September 26, 2026 15:00
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