From 6ef83d6bdfb6120f9e1fbd145e0bc463196103d1 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Wed, 16 Sep 2026 09:39:59 +0200 Subject: gui: History and undo tab; each plan and undo is its own run --- internal/engine/apply_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'internal/engine/apply_test.go') diff --git a/internal/engine/apply_test.go b/internal/engine/apply_test.go index 104fb73..142e4d2 100644 --- a/internal/engine/apply_test.go +++ b/internal/engine/apply_test.go @@ -5,6 +5,7 @@ package engine import ( "context" "os" + "path" "path/filepath" "strings" "testing" @@ -461,6 +462,48 @@ func TestApplyUndoRestoresMovedFile(t *testing.T) { } } +// TestApplyUndoNamesItsFiles: every file in an undo result says which file +// it is, reversed or declined, so a front end showing a row per file can +// put each outcome on the right row (GUI design ยง4). The log is the only +// source of that name, so Rel and Name are all an undo result can carry. +func TestApplyUndoNamesItsFiles(t *testing.T) { + h, e, dp, j, run := applyFixture(t) + if _, err := e.Apply(context.Background(), dp, map[string]bool{"a.pdf": true}, j, run); err != nil { + t.Fatal(err) + } + j.Close() + + j2, err := journal.Open(filepath.Join(h, ".local", "state", "krino", "krino.log")) + if err != nil { + t.Fatal(err) + } + defer j2.Close() + + // Declined first - nothing is reversed, so the run is still undoable - + // then reversed for real. Both paths must name the file. + for _, declined := range []bool{true, false} { + up, err := e.PlanUndo(run) + if err != nil { + t.Fatal(err) + } + if len(up.Files) != 1 || up.Files[0].Refused != "" { + t.Fatalf("undo plan = %+v", up.Files) + } + up.Files[0].Declined = declined + res, err := e.ApplyUndo(context.Background(), up, j2, journal.NewRunID(time.Now())) + if err != nil { + t.Fatal(err) + } + if len(res.Files) != 1 { + t.Fatalf("declined=%v: result files = %+v, want one", declined, res.Files) + } + fr := res.Files[0] + if fr.File.Rel != "a.pdf" || fr.File.Name != path.Base("a.pdf") { + t.Errorf("declined=%v: file = %+v, want a.pdf", declined, fr.File) + } + } +} + // TestApplyUndoSkipsRefusedFiles: rule 4 enforced at execution time too - a // refused file must come back from ApplyUndo untouched. func TestApplyUndoSkipsRefusedFiles(t *testing.T) { -- cgit v1.3