Skip to content

test: add unit tests for branches.rs pure functions#586

Closed
matt2e wants to merge 1 commit intomainfrom
branches-unit-tests
Closed

test: add unit tests for branches.rs pure functions#586
matt2e wants to merge 1 commit intomainfrom
branches-unit-tests

Conversation

@matt2e
Copy link
Copy Markdown
Contributor

@matt2e matt2e commented Apr 8, 2026

Summary

Add a comprehensive #[cfg(test)] mod tests to branches.rs covering all 13 pure/utility functions with 65 unit tests.

Functions tested

Function Tests Coverage
infer_branch_name 8 Spaces, underscores, special chars, dots/slashes, dash collapsing, empty input, numbers, leading/trailing dashes
infer_workspace_name 5 Prefix, slashes, truncation at 32 chars, empty input, dash collapsing
repo_name_from_github_repo 7 Slug extraction, bare names, special chars, dots/underscores, empty after slash, empty string, dash collapsing
validate_workspace_subpath 6 Valid paths, slash/whitespace trimming, empty rejection, dot segments, empty segments, leading slash behavior
normalize_branch_ref 3 Strip origin/ prefix, no prefix, nested paths
resolve_workspace_repo_path 3 home: prefix resolution, nested paths, passthrough
workspace_home_dir 1 Always /home/bloxer
is_worktree_path_exists_error 3 Positive match, negative, empty
is_blox_onboarding_precondition_error 5 Both keywords, onboard only, wrong error type, precondition without onboard
map_blox_status_to_workspace_status 11 All status strings, case insensitivity, stopped/shutting_down while Starting, None/unknown defaults
bootstrap_command_type_name 1 All 4 known types + unknown
parse_git_progress_line 6 Counting/receiving/resolving, no percentage, empty, no colon
fallback_worktree_path_for 3 Non-existent path, suffix appending, skipping occupied suffixes

Changes

  • apps/staged/src-tauri/src/branches.rs — added #[cfg(test)] mod tests (+495 lines)
  • apps/staged/src-tauri/Cargo.toml — added tempfile = "3" dev-dependency
  • Cargo.lock — updated for tempfile

Cover 13 pure/utility functions with 65 tests:
- infer_branch_name: sanitization, special chars, empty input
- infer_workspace_name: prefix, truncation, dash collapsing
- repo_name_from_github_repo: slug extraction, sanitization
- validate_workspace_subpath: empty, dot segments, slash trimming
- normalize_branch_ref: origin/ prefix stripping
- resolve_workspace_repo_path: home: prefix resolution
- workspace_home_dir: always /home/bloxer
- is_worktree_path_exists_error: error message matching
- is_blox_onboarding_precondition_error: error classification
- map_blox_status_to_workspace_status: all status transitions
- bootstrap_command_type_name: command type mapping
- parse_git_progress_line: git progress parsing
- fallback_worktree_path_for: path fallback with tempdir
@matt2e matt2e requested review from baxen and wesbillman as code owners April 8, 2026 04:26
@matt2e matt2e marked this pull request as draft April 14, 2026 02:02
@matt2e matt2e closed this Apr 14, 2026
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