Skip to content

fix(trash): keep tests off the machine's real per-mount trash dirs - #3100

Merged
bbedward merged 1 commit into
duxlabs-dev:masterfrom
Conava:trash-test-mount-isolation
Aug 18, 2026
Merged

bbedward merged 1 commit into
duxlabs-dev:masterfrom
Conava:trash-test-mount-isolation

Conversation

@Conava

@Conava Conava commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

The internal/trash tests redirect the home trash with t.Setenv("HOME", ...) and t.Setenv("XDG_DATA_HOME", ...), but allTrashDirs() also walks every mount point looking for <mount>/.Trash/<uid> and <mount>/.Trash-<uid>, and no environment variable redirects that walk. Count() and Empty() both iterate its result, so on any machine with a second mounted filesystem that has ever had a file trashed from it:

  • TestListAndCount and TestEmptyClearsAll fail, because Count() returns the test's own three files plus whatever the real trash dirs hold.
  • If those dirs hold only orphaned files (no matching .trashinfo), the count still matches, the test passes, and Empty() 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 mountPoints function variable that the tests point away from the real filesystem and restore with t.Cleanup. Production behavior is unchanged:
it is initialized to readMountPoints. The seam sits in trash.go rather than in mounts_linux.go and mounts_freebsd.go, so one line covers both platforms.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that changes existing behavior)
  • Refactor / internal cleanup
  • Documentation
  • Other

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, running TestEmptyClearsAll:

test result the two files
before ok deleted
after ok intact

One file with a matching .trashinfo, running both tests:

before:
--- FAIL: TestListAndCount (0.00s)
    trash_test.go:120: initial count = 1, want 0
    trash_test.go:137: count = 4, want 3
--- FAIL: TestEmptyClearsAll (0.00s)
    trash_test.go:164: pre-empty count = 4

after:
ok (2 passed), and the trashed file is still there
  • make fmt, make test (2159 tests, 88 packages), go mod tidy clean
  • GOOS=freebsd GOARCH=amd64 go build ./...
    (END)

Checklist

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.
Copilot AI lite review requested due to automatic review settings August 17, 2026 21:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 mountPoints function variable initialized to readMountPoints and used by allTrashDirs().
  • In tests, stub mountPoints to return no mount points and restore it via t.Cleanup, ensuring Count() / 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.

@bbedward
bbedward merged commit f44b7b9 into duxlabs-dev:master Aug 18, 2026
3 checks passed
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.
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.

3 participants