test: normalize mocked package path suffixes#90
Conversation
|
Note
|
| Layer / File(s) | Summary |
|---|---|
Path suffix helper and verification src/__tests__/version-check.test.ts |
Introduces hasPathSuffix(path, suffix) which normalizes \ → / and checks suffixes; adds a test that Windows-style and POSIX-style paths match the same src/package.json suffix; updates production-path mock to use the helper. |
Apply helper to remaining test mocks src/__tests__/version-check.test.ts |
Updates fallback (“production fails, dev succeeds”), malformed-JSON, and non-string/missing-version readFileSync mock branches to use hasPathSuffix; ensures src/package.json is excluded when matching top-level package.json. |
Sequence Diagram(s)
No diagram necessary.
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~8 minutes
Possibly related PRs
- KDM-cli/kdm-cli#88: Related test updates and multi-path
getInstalledVersion()logic touchingsrc/package.jsonvs top-levelpackage.json.
Poem
🔧 Backslashes bow, slashes align,
A tiny helper makes paths combine.
Tests now agree on either side,
Windows and Unix walk in stride. ✨
🚥 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 clearly describes the main change: normalizing mocked package path suffixes to handle both Windows and POSIX separators in test mocks. |
| Linked Issues check | ✅ Passed | The PR directly addresses issue #89 by implementing path normalization in test mocks to handle both POSIX and Windows path separators, making suffix checks robust across platforms. |
| Out of Scope Changes check | ✅ Passed | All changes are scoped to test file path normalization logic in version-check.test.ts with no unrelated modifications or side effects. |
| 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.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@src/__tests__/version-check.test.ts`:
- Around line 115-118: Add a negative-path assertion to the existing test that
exercises hasPathSuffix to ensure non-matching suffixes are detected: inside the
test case 'should treat Windows and POSIX separators the same when matching
package paths' add at least one expect(...) that calls hasPathSuffix with a path
and a suffix that should not match (for example a different filename or extra
segment like 'src/other.json' or 'other/src/package.json') and assert
toBe(false) so the test covers a failing condition as well as the matching
cases.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 87fe6eac-f4c5-4ffb-a1ef-f35cb7ef2251
📒 Files selected for processing (1)
src/__tests__/version-check.test.ts
|
Addressed the CodeRabbit note by adding a negative-path assertion to the hasPathSuffix separator-parity test. Validation run: git diff --check. Full vitest run is still blocked on this runner's Node.js v12.22.9 versus the repo's newer Vitest/tooling requirements. |
utkarsh232005
left a comment
There was a problem hiding this comment.
LGTM @narutamaaurum Great work thankyou so much for contributing!!
Summary
version-check.test.tsbefore suffix checkspackage.jsonpath guard to work with both\and/Validation
git diff --checknpm test, but this runner only has Node.jsv12.22.9while the repo's Vitest stack requires a newer Node runtime; the change is test-only and scoped to path matching logicCloses #89
Summary by CodeRabbit