Skip to content

Refactor: extract Trash interface, move orphan logic, and DRY up XDG storage#119

Merged
babarot merged 3 commits intomainfrom
babarot/refactor-phase2-structural-improvements
Apr 4, 2026
Merged

Refactor: extract Trash interface, move orphan logic, and DRY up XDG storage#119
babarot merged 3 commits intomainfrom
babarot/refactor-phase2-structural-improvements

Conversation

@babarot
Copy link
Copy Markdown
Owner

@babarot babarot commented Apr 4, 2026

WHAT

Structural improvements across the trash management codebase: extract a Trash interface for mockability, relocate XDG-specific domain logic from CLI to its proper package, and eliminate code duplication in XDG storage operations.

WHY

A comprehensive code review identified three structural issues:

  1. CLI and UI depended on the concrete *trash.Manager type, making mock-based testing impossible
  2. Orphan detection logic (findOrphanedTrashInfoFiles, parseTrashInfoFile, OrphanedFile) was XDG-specific domain logic incorrectly placed in the CLI package
  3. Restore() and Remove() in XDG storage had identical .trashinfo path reconstruction code

This PR also includes Phase 1 safety fixes (SelectionManager global removal + legacy Storage mutex) since those aren't merged yet.

babarot added 3 commits April 4, 2026 11:47
Define a Trash interface (Put, List, Restore, Remove) in the trash
package. CLI and UI now depend on the interface instead of the
concrete *Manager type, enabling mock-based testing.
OrphanedFile type, FindOrphanedTrashInfoFiles(), and
ParseTrashInfoFile() are XDG trash domain logic that was incorrectly
placed in the CLI package. Move them to trash/xdg/orphan.go with
their tests in orphan_test.go. CLI now delegates to xdg package.
Restore() and Remove() had identical logic to compute the .trashinfo
path from a trash file path. Extract into infoPathForFile() helper.
Also replace fmt.Fprintf(os.Stderr) with slog.Warn for consistency.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

Code Metrics Report

main (5f8a73d) #119 (016fee9) +/-
Coverage 50.6% 44.5% -6.2%
Code to Test Ratio 1:1.5 1:1.5 -0.1
Test Execution Time 4s 3s -1s
Details
  |                     | main (5f8a73d) | #119 (016fee9) |  +/-  |
  |---------------------|----------------|----------------|-------|
- | Coverage            |          50.6% |          44.5% | -6.2% |
  |   Files             |             23 |             24 |    +1 |
  |   Lines             |           1565 |           1810 |  +245 |
+ |   Covered           |            793 |            806 |   +13 |
- | Code to Test Ratio  |          1:1.5 |          1:1.5 |  -0.1 |
  |   Code              |           2701 |           2775 |   +74 |
+ |   Test              |           4203 |           4248 |   +45 |
+ | Test Execution Time |             4s |             3s |   -1s |

Code coverage of files in pull request scope (69.1% → 36.9%)

Files Coverage +/- Status
internal/trash/manager.go 42.7% -48.8% modified
internal/trash/xdg/orphan.go 43.2% +43.2% added
internal/trash/xdg/storage.go 31.1% -23.7% modified

Reported by octocov

@babarot babarot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, issues, etc. label Apr 4, 2026
@babarot babarot marked this pull request as ready for review April 4, 2026 02:58
@babarot babarot merged commit 7d45896 into main Apr 4, 2026
6 checks passed
@babarot babarot deleted the babarot/refactor-phase2-structural-improvements branch April 4, 2026 02:58
@github-actions github-actions bot mentioned this pull request Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Categorizes issue or PR as related to cleaning up code, issues, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant