Skip to content

fix(integration): match Windows UNC paths in webhook path mapper#299

Merged
mescon merged 1 commit into
mainfrom
fix/windows-unc-path-matching
Jun 4, 2026
Merged

fix(integration): match Windows UNC paths in webhook path mapper#299
mescon merged 1 commit into
mainfrom
fix/windows-unc-path-matching

Conversation

@mescon
Copy link
Copy Markdown
Owner

@mescon mescon commented Jun 4, 2026

Closes #298.

Problem

The path matcher (`internal/integration/path_mapper.go`) required the post-prefix remainder to start with a forward slash, so Windows UNC paths reported by *arr never matched. Every Healarr-on-Docker-Desktop-Windows setup hit:

Webhook path mapping failed: *arr reported path
'\\\\alexpr4100\\media\\Movies\\High Strung (2016)\\film.mkv'
but no matching scan path found

even with a correctly configured scan path `\\alexpr4100\media\Movies`. Reported by @alex882001 in #298 after the v1.3.6 webhook-auth fix (#293) let his request reach the mapper layer in the first place.

Fix

Accept either `/` or `\\` as the directory-boundary separator in:

  • The post-HasPrefix remainder check (so `\\srv\share\Movies` matches `\\srv\share\Movies\film.mkv` but not `\\srv\share\MoviesArchive\film.mkv`)
  • The trailing-separator trim at load time

Helpers factored out (`pathSeparators`, `hasSepPrefix`, `trimTrailingSep`) so the rule is named once.

Test plan

  • `go build ./...` clean
  • `/usr/bin/golangci-lint run ./internal/integration/` — 0 issues
  • `go test ./internal/integration/ -run 'PathMapper'` — all existing 17 tests pass, plus 4 new UNC-specific tests:
    • `TestPathMapper_ToLocalPath_WindowsUNC` — exact, with file, deep-nested
    • `TestPathMapper_ToLocalPath_WindowsUNC_PrefixBoundary` — `MoviesArchive` must not false-match `Movies`
    • `TestPathMapper_ToLocalPath_TrimsTrailingBackslash` — trailing `\` is stripped at load
    • `TestPathMapper_ToArrPath_WindowsUNC` — reverse direction also covered

Caveats

This fix gets the path matching working. If the user is running Healarr in a Linux container (Docker Desktop default) and their UNC share isn't mounted into the container, scanning will still fail at file-access time — that's a deployment issue, not a code one. The error message in that case will be from the scanner ("file not accessible"), which is at least a useful signal pointing at the real problem rather than the misleading "no matching scan path".

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Windows UNC path handling to properly recognize and map network share paths with correct boundary detection.
    • Improved path separator handling to consistently process both forward slashes and backslashes, with proper normalization of trailing separators.
  • Tests

    • Added comprehensive Windows UNC path regression test coverage including prefix boundary validation and path mapping scenarios.

The path-matching logic between *arr-reported paths and configured
scan paths required the post-prefix remainder to begin with a forward
slash. On Windows, Sonarr/Radarr report paths verbatim with UNC roots
and backslash separators, e.g.:

  \\alexpr4100\\media\\Movies\\High Strung (2016)\\film.mkv

With a scan path configured as \\alexpr4100\\media\\Movies, the
HasPrefix match succeeded but the remainder validation (which only
accepted '/') rejected the match. Every Windows-hosted setup got:

  Webhook path mapping failed: *arr reported path '...' but no
  matching scan path found

even with a correctly configured scan path.

Fix: accept either / or \\ as the directory-boundary separator after
a prefix match, and strip either as a trailing separator at load time.
Helpers are factored out (pathSeparators, hasSepPrefix,
trimTrailingSep) so the rule is named once and applied consistently
across Reload / ToArrPath / ToLocalPath.

Reported by alex882001 in #298. The earlier per-instance webhook
secret fix (#293, v1.3.6) was a prerequisite for this report — without
it the request would have been rejected at the auth gate before ever
reaching path mapping.

Closes #298
@mescon mescon merged commit 8414614 into main Jun 4, 2026
4 of 7 checks passed
@mescon mescon deleted the fix/windows-unc-path-matching branch June 4, 2026 17:40
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b9f592ba-02be-41ec-b079-0d71dac8d6a0

📥 Commits

Reviewing files that changed from the base of the PR and between 20a29e7 and 11c5d5b.

📒 Files selected for processing (2)
  • internal/integration/path_mapper.go
  • internal/integration/path_mapper_test.go

📝 Walkthrough

Walkthrough

Path mapper logic is enhanced to recognize Windows UNC paths by supporting both forward and backslash separators in prefix matching and canonicalization. Helper functions normalize trailing separators while preserving UNC anchors, and conversion methods now validate directory boundaries using either separator type.

Changes

Windows UNC Path Mapping

Layer / File(s) Summary
Path separator utilities
internal/integration/path_mapper.go
pathSeparators constant, trimTrailingSep function to remove trailing separators while preserving UNC roots, and hasSepPrefix to validate directory-boundary prefixes on either / or \.
Reload and conversion boundary validation
internal/integration/path_mapper.go
Reload updates mapping normalization to use trimTrailingSep for both LocalPath and ArrPath; ToArrPath and ToLocalPath replace forward-slash-only checks with hasSepPrefix to support both separators while preserving longest-prefix selection.
Windows UNC regression tests
internal/integration/path_mapper_test.go
Four new test functions: TestPathMapper_ToLocalPath_WindowsUNC verifies UNC roots and nested paths, TestPathMapper_ToLocalPath_WindowsUNC_PrefixBoundary ensures sibling directories don't false-match, TestPathMapper_ToLocalPath_TrimsTrailingBackslash validates trailing backslash normalization, and TestPathMapper_ToArrPath_WindowsUNC verifies reverse-direction UNC mapping.

🎯 3 (Moderate) | ⏱️ ~20 minutes

In a garden where the paths once split
With slashes forward, backward bound,
Now both are one, a perfect fit—
No UNC path left unfound! 🐰✨

✨ 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 fix/windows-unc-path-matching

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/integration/path_mapper.go 80.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@mescon mescon mentioned this pull request Jun 4, 2026
5 tasks
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.

Webhook path mapping failed

1 participant