Repository navigation
fix(trash): keep tests off the machine's real per-mount trash dirs - #3100
Merged
Merged
Conversation
setupHomeTrash redirects HOME and XDG_DATA_HOME, but allTrashDirs also walks readMountPoints() looking for <mount>/.Trash/<uid> and <mount>/.Trash-<uid>, and no environment variable affects that walk. So Count() and List() included whatever the developer had trashed on a second filesystem, and Empty() deleted it for real: with an orphaned file under a mount trash (no matching .trashinfo, so the count assert still saw 3), TestEmptyClearsAll passed and removed the file. Route the walk through a package-level mountPoints variable and have setupHomeTrash swap in an empty list, restoring it via t.Cleanup. Production behavior is unchanged.
There was a problem hiding this comment.
Pull request overview
This PR prevents core/internal/trash unit tests from interacting with (and potentially deleting from) the host machine’s real per-mount trash directories by adding a test seam for mount-point discovery, while keeping production behavior unchanged.
Changes:
- Introduce a package-level
mountPointsfunction variable initialized toreadMountPointsand used byallTrashDirs(). - In tests, stub
mountPointsto return no mount points and restore it viat.Cleanup, ensuringCount()/Empty()operate only on the test’s temporary trash directories.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| core/internal/trash/trash.go | Adds a mountPoints indirection and updates allTrashDirs() to use it. |
| core/internal/trash/trash_test.go | Stubs mountPoints during test setup to avoid touching real per-mount trash dirs. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
by-architect
pushed a commit
to by-architect/Phoenix
that referenced
this pull request
Aug 19, 2026
…uxlabs-dev#3100) setupHomeTrash redirects HOME and XDG_DATA_HOME, but allTrashDirs also walks readMountPoints() looking for <mount>/.Trash/<uid> and <mount>/.Trash-<uid>, and no environment variable affects that walk. So Count() and List() included whatever the developer had trashed on a second filesystem, and Empty() deleted it for real: with an orphaned file under a mount trash (no matching .trashinfo, so the count assert still saw 3), TestEmptyClearsAll passed and removed the file. Route the walk through a package-level mountPoints variable and have setupHomeTrash swap in an empty list, restoring it via t.Cleanup. Production behavior is unchanged.
marcusramberg
pushed a commit
to marcusramberg/DankMaterialShell
that referenced
this pull request
Sep 2, 2026
…uxlabs-dev#3100) setupHomeTrash redirects HOME and XDG_DATA_HOME, but allTrashDirs also walks readMountPoints() looking for <mount>/.Trash/<uid> and <mount>/.Trash-<uid>, and no environment variable affects that walk. So Count() and List() included whatever the developer had trashed on a second filesystem, and Empty() deleted it for real: with an orphaned file under a mount trash (no matching .trashinfo, so the count assert still saw 3), TestEmptyClearsAll passed and removed the file. Route the walk through a package-level mountPoints variable and have setupHomeTrash swap in an empty list, restoring it via t.Cleanup. Production behavior is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
internal/trashtests redirect the home trash witht.Setenv("HOME", ...)andt.Setenv("XDG_DATA_HOME", ...), butallTrashDirs()also walks every mount point looking for<mount>/.Trash/<uid>and<mount>/.Trash-<uid>, and no environment variable redirects that walk.Count()andEmpty()both iterate its result, so on any machine with a second mounted filesystem that has ever had a file trashed from it:TestListAndCountandTestEmptyClearsAllfail, becauseCount()returns the test's own three files plus whatever the real trash dirs hold..trashinfo), the count still matches, the test passes, andEmpty()deletes them.CI never hits either case because it runs on a single filesystem. The freedesktop spec requires a trashed file to stay on its own filesystem, so this affects anyone with a separate home and data partition.
This PR adds a
mountPointsfunction variable that the tests point away from the real filesystem and restore witht.Cleanup. Production behavior is unchanged:it is initialized to
readMountPoints. The seam sits intrash.gorather than inmounts_linux.goandmounts_freebsd.go, so one line covers both platforms.Type of change
Related issues
None
Screenshots / video
Validation
Measured on CachyOS with a second mount (
/run/user/1000, tmpfs) holding a fabricated.Trash-1000.Two orphaned files, no
.trashinfo, runningTestEmptyClearsAll:One file with a matching
.trashinfo, running both tests:make fmt,make test(2159 tests, 88 packages),go mod tidycleanGOOS=freebsd GOARCH=amd64 go build ./...(END)
Checklist
I18n.tr()with translator context, reusing existing terms where possiblemake fmt, added/updated tests,make testpasses, andgo mod tidyis cleanmake lint-qmlwith no new warnings