Skip to content

test(statusline): add buildSlotsLine coverage#146

Merged
jobordu merged 3 commits into
mainfrom
tests/build-slots-line
May 1, 2026
Merged

test(statusline): add buildSlotsLine coverage#146
jobordu merged 3 commits into
mainfrom
tests/build-slots-line

Conversation

@jobordu
Copy link
Copy Markdown

@jobordu jobordu commented May 1, 2026

Adds 9 tests covering the quorum-slots row introduced in #141. Closes the follow-up Copilot review thread that asked for buildSlotsLine test coverage and was acknowledged as a follow-up at the time.

What's covered

TC Scenario Expected
30 provider in providers.json but NOT in mcpServers dim · indicator
31 registered + recent OK probe green ●
32 registered + recent FAILED probe red ⊘
33 registered + no health cache hollow ○
34 registered + STALE (>5min) probe hollow ○ (stale OK does NOT render green)
35 providers.json absent no slots line emitted (fail-silent)
36 multiple providers declaration order preserved (not alphabetized)
37 malformed slot-health.json fail-open to ○ (no crash)
38 slots line position rendered ABOVE the tools line

A new setupSlotsHome helper lays down all three files (providers.json, ~/.claude.json mcpServers, slot-health.json) in a temp HOME so each scenario is hermetic and CI-portable.

Test plan

  • All 37 tests pass locally (28 existing + 9 new)
  • No changes to runtime hook behavior — pure test addition

Summary by CodeRabbit

  • Tests
    • Expanded test coverage with nine new test cases validating glyph rendering and provider status indicator behavior
    • Tests verify correct rendering across scenarios including registered/unregistered providers, health status detection, cache freshness, and error conditions
    • Added assertions for proper layout positioning, configuration order preservation, and graceful error handling

Adds 9 tests covering the quorum-slots row added in #141. Coverage:
  TC30: provider in providers.json but NOT mcpServers → · dim
  TC31: registered + recent OK probe → green ●
  TC32: registered + recent failed probe → red ⊘
  TC33: registered + no health cache → hollow ○
  TC34: registered + STALE (>5min) probe → ○ (stale OK doesn't render green)
  TC35: providers.json absent → no slots line emitted (fail-silent)
  TC36: multiple providers preserve declaration order (not alphabetized)
  TC37: malformed slot-health.json → fail-open to ○ (no crash)
  TC38: slots line renders ABOVE the tools line (coderlm/River/embed)

A `setupSlotsHome` helper lays down all three files (providers.json, .claude.json
mcpServers, slot-health.json) in the temp HOME so each scenario is hermetic.

Closes the follow-up Copilot flagged on #141 ("buildSlotsLine isn't covered by the
existing test suite").

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 1, 2026 18:00
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

Walkthrough

The pull request expands the test suite for hooks/nf-statusline.test.js by adding a "Quorum Slots Line Tests" section with a dedicated setup helper and nine new test cases (TC30–TC38) that validate glyph selection and rendering behavior for slot inventory scenarios across health cache states.

Changes

Cohort / File(s) Summary
Quorum Slots Line Tests
hooks/nf-statusline.test.js
Added setupSlotsHome helper for test fixture setup (slot inventory, MCP registration, optional cached probe results) and nine test cases validating glyph rendering (dim · for unregistered, hollow for registered with missing/stale cache, green for fresh successful probes, red for failed probes), along with assertions for providers.json handling, malformed cache resilience, and slots-line positional layout.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete. It is missing the required template sections: 'What', 'Why', 'Testing' checkboxes, 'Checklist' items, and 'Breaking Changes' declaration. Restructure the description to follow the template: add 'What' and 'Why' sections, include testing platform checkboxes, complete the checklist items, and explicitly state 'Breaking Changes: None'.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding test coverage for the buildSlotsLine function in the statusline hook.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 tests/build-slots-line

Review rate limit: 7/10 reviews remaining, refill in 16 minutes and 2 seconds.

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
hooks/nf-statusline.test.js (1)

744-763: ⚡ Quick win

Tighten the “no slots line” assertion to be line-structural, not regex-inferential.

This check can miss regressions if slot names or formatting change while still emitting a slots line. Prefer asserting exact non-empty line count and that the intermediate slots line is absent.

Proposed assertion hardening
-    const lines = stdout.split('\n').filter(l => l.length > 0);
-    // Last line should be the tools line. Everything else is the main line. No middle slots line.
-    const hasSlotsLine = lines.some(l => /[·●⊘○] [a-z]+-\d+/.test(l) && !l.includes('coderlm'));
-    assert.ok(!hasSlotsLine, 'no slots line should be emitted when providers.json is absent');
+    const lines = stdout.split('\n').filter(Boolean);
+    // main status line + tools line only (no middle slots line)
+    assert.ok(lines.length <= 2, `expected no slots line; got ${lines.length} non-empty lines`);
+    if (lines.length === 2) {
+      assert.ok(lines[1].includes('coderlm') || lines[1].includes('River') || lines[1].includes('embed'),
+        `second line should be tools line; got: ${JSON.stringify(lines[1])}`);
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@hooks/nf-statusline.test.js` around lines 744 - 763, The current regex-based
check for a missing slots line is brittle; instead assert the exact line
structure returned by runHook: after splitting stdout into non-empty lines (the
existing variable lines), assert there are exactly 2 lines (main statusline and
tools line) and then assert that the second line (lines[1]) contains the
expected tool indicators (e.g., 'coderlm'/'River'/'embed') while the first line
does not contain any slot glyphs (·, ●, ⊘, ○); update the test using the
existing tempHome, tempDir, runHook and lines variables to perform these
structural assertions rather than the regex-based hasSlotsLine check.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@hooks/nf-statusline.test.js`:
- Around line 744-763: The current regex-based check for a missing slots line is
brittle; instead assert the exact line structure returned by runHook: after
splitting stdout into non-empty lines (the existing variable lines), assert
there are exactly 2 lines (main statusline and tools line) and then assert that
the second line (lines[1]) contains the expected tool indicators (e.g.,
'coderlm'/'River'/'embed') while the first line does not contain any slot glyphs
(·, ●, ⊘, ○); update the test using the existing tempHome, tempDir, runHook and
lines variables to perform these structural assertions rather than the
regex-based hasSlotsLine check.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: bd04c016-b92d-4f54-a50b-3bbdb5cfe866

📥 Commits

Reviewing files that changed from the base of the PR and between 82ef4b8 and 89a8f23.

📒 Files selected for processing (1)
  • hooks/nf-statusline.test.js

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds missing unit test coverage for the quorum-slots status row (buildSlotsLine) introduced in PR #141, ensuring the statusline renders correct glyphs across provider registration and health-cache scenarios.

Changes:

  • Added 9 new test cases (TC30–TC38) to validate glyph selection, cache freshness behavior, ordering, and line placement.
  • Introduced a setupSlotsHome helper to create hermetic HOME fixtures for providers.json, ~/.claude.json (mcpServers), and slot-health.json.
  • Expanded coverage for fail-open / fail-silent behaviors (missing providers.json, malformed slot-health.json).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings May 1, 2026 19:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Expands the nf-statusline hook’s test suite to cover the quorum-slots status row introduced in PR #141, ensuring correct glyph rendering and layout behavior across a range of slot registration/health-cache scenarios.

Changes:

  • Added setupSlotsHome test helper to create hermetic HOME-based fixtures (providers.json, ~/.claude.json, slot-health.json).
  • Added 9 new test cases (TC30–TC38) covering slot registration, probe freshness, malformed cache handling, ordering, and row positioning.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jobordu jobordu merged commit 86b1449 into main May 1, 2026
19 checks passed
@jobordu jobordu deleted the tests/build-slots-line branch May 1, 2026 19:14
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.

2 participants