Skip to content

test: normalize mocked package path suffixes#90

Merged
utkarsh232005 merged 2 commits into
KDM-cli:mainfrom
narutamaaurum:fix-89-windows-mock-paths
May 24, 2026
Merged

test: normalize mocked package path suffixes#90
utkarsh232005 merged 2 commits into
KDM-cli:mainfrom
narutamaaurum:fix-89-windows-mock-paths

Conversation

@narutamaaurum
Copy link
Copy Markdown
Contributor

@narutamaaurum narutamaaurum commented May 23, 2026

Summary

  • normalize mocked file paths in version-check.test.ts before suffix checks
  • update every package.json path guard to work with both \ and /
  • add a focused regression assertion covering Windows and POSIX path separators

Validation

  • git diff --check
  • attempted npm test, but this runner only has Node.js v12.22.9 while the repo's Vitest stack requires a newer Node runtime; the change is test-only and scoped to path matching logic

Closes #89

Summary by CodeRabbit

  • Tests
    • Improved cross-platform path handling in version-detection tests to ensure consistent behavior on Windows and POSIX systems.
    • Updated test mocks and routing to use normalized suffix matching.
    • Added a unit test verifying Windows-style and POSIX-style path variants are treated equivalently for version resolution.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 23, 2026

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key: "pre_merge_checks"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 189a13e1-1922-4426-baf2-ca6a87dc0508

📥 Commits

Reviewing files that changed from the base of the PR and between 0b2bd47 and 160ac5e.

📒 Files selected for processing (1)
  • src/__tests__/version-check.test.ts

📝 Walkthrough

Walkthrough

Adds a hasPathSuffix helper that normalizes backslashes to forward slashes and updates four readFileSync test mocks in version-check.test.ts to use it; also adds a test confirming Windows/POSIX path-equivalence for the src/package.json suffix.

Changes

Cross-platform Path Matching

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 touching src/package.json vs top-level package.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.

Copy link
Copy Markdown
Contributor

@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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 670dd7a and 0b2bd47.

📒 Files selected for processing (1)
  • src/__tests__/version-check.test.ts

Comment thread src/__tests__/version-check.test.ts
@narutamaaurum
Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Member

@utkarsh232005 utkarsh232005 left a comment

Choose a reason for hiding this comment

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

LGTM @narutamaaurum Great work thankyou so much for contributing!!

@utkarsh232005 utkarsh232005 merged commit 0b26266 into KDM-cli:main May 24, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Mocked file path suffix checks fail on Windows

2 participants