Skip to content

test: add node:test coverage for WS URL, arrangement, and prefs logic#19

Merged
OmikronApex merged 2 commits into
mainfrom
chore/add-basic-tests
Jul 8, 2026
Merged

test: add node:test coverage for WS URL, arrangement, and prefs logic#19
OmikronApex merged 2 commits into
mainfrom
chore/add-basic-tests

Conversation

@OmikronApex

@OmikronApex OmikronApex commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Eighth repo from the org test-coverage audit. screen.js interleaves top-level DOM/window access with function declarations throughout (not a clean declarations-then-init split like earlier plugins), so the module.exports hook sits at the very end of the IIFE instead of before init — after every let/const binding the exported functions close over has run its initializer, and after the FOLLOWER-mode bootstrap check (which no-ops under Node since location.search is empty).

15 tests:

  • getWsUrl: percent-decoding (%2F/, matching core highway.js), arrangement param, ws/wss protocol selection
  • resolveArrIndex: case-insensitive name lookup, special-mode sentinels excluded
  • getDefaultArrangements: lead/rhythm/bass prioritization, fill + wrap-around, fallback to natural order when no names match
  • _ctlRange: default/clamped bounds, non-finite → defaults
  • panelToPrefs: plain-arrangement / lyrics-mode / viz-mode encoding
  • migratePanelPrefs: non-array passthrough, one-time lyrics reset (v<2), legacy __3d_highway__ sentinel migration, no reset once already migrated

A test-only _setArrangementsForTest setter is exported alongside the real functions since arrangements is a closured let the tested functions read.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added a Node.js-based automated test suite for screen behavior, covering URL building (including percent-decoding), arrangement/index resolution, default control range handling, panel-to-preferences encoding across modes, and preference migration logic (including legacy conversions).
  • Chores
    • Enhanced testability of screen utilities by exposing selected helpers in a Node/CommonJS environment.

Node-only module.exports hook placed at the very end of the IIFE
(after every let/const initializer has run and FOLLOWER-mode is
correctly skipped in Node), exporting getWsUrl, resolveArrIndex,
getDefaultArrangements, panelToPrefs, migratePanelPrefs, _ctlRange
plus a test-only arrangements setter. Tests stub window/document/
localStorage minimally; no deps needed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7fa7f687-b025-4cd9-96a1-285d6febc16f

📥 Commits

Reviewing files that changed from the base of the PR and between 90374e0 and 785d815.

📒 Files selected for processing (1)
  • tests/screen.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/screen.test.js

📝 Walkthrough

Walkthrough

This PR adds a guarded Node/test-only export block in screen.js and a new tests/screen.test.js suite that reloads the module per test and verifies helper behavior for URL building, arrangement selection, panel preference encoding, and migration handling.

Changes

Test exports and coverage

Layer / File(s) Summary
Export internal helpers
screen.js
Guarded CommonJS export block exposes getWsUrl, resolveArrIndex, getDefaultArrangements, panelToPrefs, migratePanelPrefs, _ctlRange, and a test setter for arrangements.
Test harness setup
tests/screen.test.js
Adds stubs for window, document, location, and localStorage, plus a fresh-require helper for isolated per-test state.
URL and arrangement resolution tests
tests/screen.test.js
Covers getWsUrl, resolveArrIndex, getDefaultArrangements, _ctlRange, and panelToPrefs across arrangement, lyrics, and viz modes.
Panel preference migration tests
tests/screen.test.js
Covers migratePanelPrefs pass-through and legacy migration cases, including lyrics reset rules and sentinel prefix conversion.

Estimated code review effort: 2 (Simple) | ~12 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding node:test coverage for WS URL, arrangement, and preference logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/add-basic-tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
tests/screen.test.js (2)

18-36: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

freshPlugin() hardcodes protocol: 'http:', ignoring any caller-provided protocol.

This forces the wss:// test (Line 50-55) to work around it by mutating global.location.protocol after freshPlugin() runs, relying on the fact that getWsUrl reads the shared location object reference dynamically at call time rather than at require time. It works, but it's fragile and the location object assigned at Line 51 is effectively dead code since freshPlugin() immediately replaces it.

Consider parameterizing protocol alongside search for clarity:

♻️ Proposed refactor
-function freshPlugin({ search = '' } = {}) {
-    const location = { search, host: 'localhost:8420', protocol: 'http:' };
+function freshPlugin({ search = '', protocol = 'http:' } = {}) {
+    const location = { search, host: 'localhost:8420', protocol };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/screen.test.js` around lines 18 - 36, freshPlugin() currently hardcodes
window.location.protocol to http:, which makes protocol-sensitive tests depend
on later mutation and hides the intended setup. Update freshPlugin to accept a
protocol option alongside search, and use that value when building the shared
location object assigned to global.window and global.location. Then adjust the
wss:// test to pass the protocol through freshPlugin instead of mutating
global.location.protocol afterward, so the setup stays explicit and stable.

50-55: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Simplify by using the protocol param instead of post-hoc mutation.

Once freshPlugin() accepts protocol, this test can pass it directly instead of pre-setting global.location (which gets discarded) and patching it after the fact.

♻️ Proposed fix
 test('getWsUrl uses wss:// under https', () => {
-    global.location = { search: '', host: 'x', protocol: 'https:' };
-    const { getWsUrl } = freshPlugin();
-    global.location.protocol = 'https:'; // freshPlugin rebuilds location; keep consistent
+    const { getWsUrl } = freshPlugin({ protocol: 'https:' });
     assert.match(getWsUrl('a.sloppak', 1), /^wss:\/\//);
 });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/screen.test.js` around lines 50 - 55, The test setup for getWsUrl is
mutating global.location after freshPlugin() rebuilds it, which is unnecessary
once protocol can be passed directly. Update the test to supply the https
protocol through freshPlugin() itself and remove the pre-setting and post-hoc
mutation of global.location, keeping the assertion against getWsUrl unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/screen.test.js`:
- Around line 18-36: freshPlugin() currently hardcodes window.location.protocol
to http:, which makes protocol-sensitive tests depend on later mutation and
hides the intended setup. Update freshPlugin to accept a protocol option
alongside search, and use that value when building the shared location object
assigned to global.window and global.location. Then adjust the wss:// test to
pass the protocol through freshPlugin instead of mutating
global.location.protocol afterward, so the setup stays explicit and stable.
- Around line 50-55: The test setup for getWsUrl is mutating global.location
after freshPlugin() rebuilds it, which is unnecessary once protocol can be
passed directly. Update the test to supply the https protocol through
freshPlugin() itself and remove the pre-setting and post-hoc mutation of
global.location, keeping the assertion against getWsUrl unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 86f4662c-8a58-4030-a253-f37f9656668d

📥 Commits

Reviewing files that changed from the base of the PR and between 49948fd and 90374e0.

📒 Files selected for processing (2)
  • screen.js
  • tests/screen.test.js

Coderabbit nit: the wss:// test mutated global.location after
freshPlugin() already rebuilt it, relying on getWsUrl reading the
shared reference at call time. Pass protocol through directly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@OmikronApex
OmikronApex merged commit 7a2e508 into main Jul 8, 2026
3 checks passed
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