Skip to content

test(policy): add unit tests for extractPresetEntries and parseCurrentPolicy#636

Open
pjt222 wants to merge 1 commit intoNVIDIA:mainfrom
pjt222:test/policy-merge-logic
Open

test(policy): add unit tests for extractPresetEntries and parseCurrentPolicy#636
pjt222 wants to merge 1 commit intoNVIDIA:mainfrom
pjt222:test/policy-merge-logic

Conversation

@pjt222
Copy link

@pjt222 pjt222 commented Mar 22, 2026

Summary

  • Add 8 unit tests for extractPresetEntries and parseCurrentPolicy in test/policies.test.js
  • These exported functions had zero test coverage despite being used in the merge path of applyPreset()

Test plan

  • node --test test/policies.test.js — 23 tests pass (15 existing + 8 new)
  • No functional changes — pure test addition

Note: The inline merge logic inside applyPreset() (lines 125-170) is not directly testable without mocking runCapture/run/registry. Extracting it into a mergePresetEntries() helper would enable full coverage — happy to follow up if maintainers are interested.

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

Summary by CodeRabbit

  • Tests
    • Enhanced test coverage for policy utility functions to validate behavior when processing configuration presets and parsing policy content across multiple input scenarios, including edge cases with metadata handling and content formatting.

…tPolicy

These two exported functions in bin/lib/policies.js had zero test
coverage despite being used in the merge path of applyPreset().

Adds 8 tests in 2 new describe blocks:

extractPresetEntries (4 tests):
- Extracts entries from a real preset (telegram)
- Returns null when no network_policies key
- Trims trailing whitespace
- Returns empty string for empty network_policies section

parseCurrentPolicy (4 tests):
- Returns empty string for falsy input
- Returns raw content when no --- separator
- Strips metadata header before --- separator
- Splits on first --- only

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ec715ab4-10a1-4e3f-843a-3637a7249d91

📥 Commits

Reviewing files that changed from the base of the PR and between 04012f7 and 0370f32.

📒 Files selected for processing (1)
  • test/policies.test.js

📝 Walkthrough

Walkthrough

Added test coverage for two policy-related functions: extractPresetEntries returns null for missing YAML keys, empty string for empty entries, trims whitespace, and excludes metadata; parseCurrentPolicy handles falsy inputs, missing separators, and metadata removal.

Changes

Cohort / File(s) Summary
Policy Test Coverage
test/policies.test.js
Added 57 lines of test cases for extractPresetEntries and parseCurrentPolicy functions, covering YAML parsing behavior, null/empty handling, whitespace trimming, metadata stripping, and separator-based content splitting.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 With whiskers twitched and paws so keen,
New tests ensure our code's pristine,
YAML entries parsed with care,
Metadata stripped with flair,
Coverage grows, our rabbit's been seen! 🔬✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding unit tests for two specific policy functions (extractPresetEntries and parseCurrentPolicy).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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