Skip to content

test(paths): cover lexical normalize and subtree grants - #80

Merged
kirillDevPro merged 1 commit into
masterfrom
test/paths-untested-logic
Sep 22, 2026
Merged

kirillDevPro merged 1 commit into
masterfrom
test/paths-untested-logic

Conversation

@kirillDevPro

Copy link
Copy Markdown
Collaborator

What & why

crates/moon-util/src/paths.rs had pure path helpers no existing test reached. This adds six unit tests for the branches a caller would notice: lexical .. / . normalization, a .. that climbs out of the path, subtree-grant pruning, and ASCII case-folding of a path component.

Production behaviour is unchanged. The only edit in paths.rs is #[cfg(test)] mod paths_tests;. The existing inline tests in that file were not modified.

Tests and the mutation that proved each one

Each test was run green, the production function was mutated, that test failed for the reason below, the production file was restored (git diff showed only the module declaration), and the test was run green again.

  • normalize_lexically_collapses_dot_and_parent_inside_the_pathParentDir did continue instead of lexical.pop(). Failed assert_eq with left foo\bar and right bar.
  • normalize_lexically_rejects_parent_that_escapes_the_root — the root-length check became if false && ..., so a .. that reaches the root was popped instead of rejected. Failed because foo/../../bar returned Ok("bar").
  • insert_subtree_prunes_descendants_and_keeps_prefix_siblingsretain kept every grant. Failed assert_eq: left still contained proj/src and proj/tests.
  • insert_subtree_ignores_a_path_an_existing_grant_covers — the already-covered early return was skipped (if false &&). Failed assert_eq: left gained proj/src.
  • path_within_subtree_matches_the_grant_and_not_a_prefix_siblingpath.starts_with(granted) was inverted. Failed the assertion that proj2 must stay outside a proj grant.
  • component_matches_ignore_ascii_case_folds_ascii_caseeq_ignore_ascii_case became eq. Failed the assertion that .ZED matches .zed.

A review with a clean context kept all six. Nothing was dropped. Nothing was left unverified.

Still untested in this file

  • PathExt::try_from_bytes
  • PathExt::local_to_wsl
  • PathExt::try_shell_safe
  • path_ends_with
  • SanitizedPath::from_arc, new_arc, cast_arc, cast_arc_ref
  • RemotePathBuf::from_str, to_proto
  • PathWithPosition::map_path
  • PathMatcher::is_match_std_path
  • compare_rel_paths

How to verify

cargo test -p moon-util --lib paths_tests

normalize_lexically, insert_subtree, path_within_subtree, and
component_matches_ignore_ascii_case had no test reaching them. A wrong
.. pop, an escaping parent, or a prefix-sibling treated as inside a
grant would ship without a failing test.
@kirillDevPro
kirillDevPro merged commit 7ff861d into master Sep 22, 2026
4 checks passed
@kirillDevPro
kirillDevPro deleted the test/paths-untested-logic branch September 22, 2026 09:16
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