diff --git a/internal/testutil/sshtest/home.go b/internal/testutil/sshtest/home.go index 2ea2e8f..84d6ce7 100644 --- a/internal/testutil/sshtest/home.go +++ b/internal/testutil/sshtest/home.go @@ -21,6 +21,7 @@ func IsolatedHome(t testing.TB) string { t.Setenv("HOME", home) t.Setenv("SSH_AUTH_SOCK", "") t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) + t.Setenv("XDG_DATA_HOME", filepath.Join(home, ".local", "share")) if err := os.MkdirAll(filepath.Join(home, ".ssh"), 0o700); err != nil { t.Fatal(err) } diff --git a/internal/ui/model.go b/internal/ui/model.go index e828664..aeef409 100644 --- a/internal/ui/model.go +++ b/internal/ui/model.go @@ -133,6 +133,10 @@ type archiveDoneMsg struct { sourcePaths []string targetPath string err error + // trashFailed lists the items a trash job could not move to the trash + // (the failing one and the rest); the user is offered to delete them + // permanently (QA-1). + trashFailed []string } type copyDoneMsg struct { @@ -628,6 +632,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if m.modal.kind == modalArchiveProgress { m.modal = modalState{} } + if len(msg.trashFailed) > 0 && msg.err != context.Canceled { + m.offerPermanentDelete(msg.trashFailed, msg.err) + } return m, m.loadPreviewCmd() } @@ -3217,6 +3224,25 @@ func (m *Model) openRenameModal() { } } +// offerPermanentDelete asks, after the trash refused some items (another +// filesystem without a usable trash, broken trash), whether to delete them +// permanently instead. Nothing is deleted without this explicit +// confirmation (QA-1). +func (m *Model) offerPermanentDelete(paths []string, cause error) { + m.deleteKind = "permanent" + n := len(paths) + m.openConfirmModal( + "Cannot move to trash. Delete permanently?", + fmt.Sprintf("%s\nNot in trash: %d entr%s (first: %s)\nPermanently deleted files cannot be restored.", + strings.Join(strings.Fields(cause.Error()), " "), n, pluralSuffix(n, "y", "ies"), filepath.Base(paths[0])), + "Enter / y to delete permanently, Esc / n to keep the files", + pendingOperation{ + kind: opPermanentDelete, + sourcePaths: append([]string(nil), paths...), + }, + ) +} + func (m *Model) openConfirmModal(title, body, note string, pending pendingOperation) { m.modal = modalState{ kind: modalConfirm, @@ -5246,11 +5272,15 @@ func (m *Model) startDeleteJob(kind fileOpKind, sources []string) tea.Cmd { err = vfs.MoveToTrash(sourcePath) } if err != nil { - m.archiveProgress <- archiveDoneMsg{ + done := archiveDoneMsg{ jobID: jobID, sourcePaths: append([]string(nil), sources...), err: fmt.Errorf("%s %s: %w", verb, sourcePath, err), } + if kind != opPermanentDelete { + done.trashFailed = append([]string(nil), sources[i:]...) + } + m.archiveProgress <- done return } diff --git a/internal/ui/qa_fixes_test.go b/internal/ui/qa_fixes_test.go new file mode 100644 index 0000000..f91b539 --- /dev/null +++ b/internal/ui/qa_fixes_test.go @@ -0,0 +1,63 @@ +package ui + +// Developer C (v0.2.8 QA fixes): tests for fixes that need more than the QA +// tests in qa_*_test.go. + +import ( + "os" + "path/filepath" + "testing" + "time" + + "vcom/internal/testutil/teadriver" +) + +// QA-1: when the trash refuses an item (another filesystem without a +// usable trash, a broken trash), the same flow offers permanent deletion; +// nothing is deleted without the explicit confirmation. +func TestQA1TrashFailureOffersPermanentDelete(t *testing.T) { + for _, tc := range []struct { + name string + answer string + deleted bool + }{ + {"confirm", "enter", true}, + {"y", "y", true}, + {"cancel", "esc", false}, + {"n", "n", false}, + } { + t.Run(tc.name, func(t *testing.T) { + dir := t.TempDir() + writeFile(t, filepath.Join(dir, "a.txt"), "x") + writeFile(t, filepath.Join(dir, "b.txt"), "y") + d := newDriver(t, dir, t.TempDir()) + // A file where the trash directory should be: MoveToTrash fails. + writeFile(t, filepath.Join(os.Getenv("HOME"), ".local", "share", "Trash"), "not a dir") + m := cur(t, d) + for _, e := range m.activePane().Entries { + if !e.IsParent { + m.activePane().EnsureMarked(e.Path) + } + } + d = teadriver.New(t, m, 160, 40, teadriver.WithoutInit(), teadriver.WithLongCmd(300*time.Millisecond)) + d.Press("f8", "enter") + d.Settle(settle) + if !exists(filepath.Join(dir, "a.txt")) || !exists(filepath.Join(dir, "b.txt")) { + t.Fatal("files deleted before confirmation") + } + if !d.ScreenContains("Delete permanently?") || !d.ScreenContains("Not in trash: 2") { + t.Fatalf("permanent delete not offered:\n%s", d.Screen()) + } + d.Press(tc.answer) + d.Settle(settle) + for _, n := range []string{"a.txt", "b.txt"} { + if got := exists(filepath.Join(dir, n)); got == tc.deleted { + t.Fatalf("%s exists=%v after %q (status %q)", n, got, tc.answer, cur(t, d).status) + } + } + if cur(t, d).modal.kind != modalNone { + t.Fatalf("dialog still open:\n%s", d.Screen()) + } + }) + } +}