aboutsummaryrefslogtreecommitdiff
path: root/internal/journal/read_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-15 00:00:05 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-15 00:00:05 +0200
commit5310c857d7531986c806404103f118b3c5e364f3 (patch)
tree4022cb838184c7e889793698a8a3cd3c4b6deebc /internal/journal/read_test.go
parent67ada0b5bc25cb6cff3ab780d82cb0bfe64e4968 (diff)
downloadkrino-5310c857d7531986c806404103f118b3c5e364f3.tar.gz
krino-5310c857d7531986c806404103f118b3c5e364f3.zip
krino log marks a run partly undone while reversible steps remain
Diffstat (limited to 'internal/journal/read_test.go')
-rw-r--r--internal/journal/read_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/internal/journal/read_test.go b/internal/journal/read_test.go
index 676b2bd..efb5a15 100644
--- a/internal/journal/read_test.go
+++ b/internal/journal/read_test.go
@@ -731,3 +731,51 @@ func TestEntriesRefusesALineCutInsideItsRunColumn(t *testing.T) {
t.Errorf("Entries = %+v, no error; a line cut inside its run column must refuse the run", got)
}
}
+
+// TestRunsMarksAPartlyUndoneRun: a run whose undo reversed some of its
+// reversible steps but not all is partly undone; once a later undo reverses
+// the rest, it is undone in full. A permanent delete counts toward neither
+// (triage 34l).
+func TestRunsMarksAPartlyUndoneRun(t *testing.T) {
+ path := filepath.Join(t.TempDir(), "krino.log")
+ w, _ := Open(path)
+ t0 := time.Date(2026, 9, 11, 9, 0, 0, 0, time.UTC)
+ for _, e := range []Entry{
+ {Time: t0, Run: "A", Action: "run-start", Status: "ok"},
+ {Time: t0, Run: "A", Dir: "dl", File: "x.pdf", Step: 1, Action: "move", Status: "ok", Src: "/a/x.pdf", Dst: "/b/x.pdf"},
+ {Time: t0, Run: "A", Dir: "dl", File: "y.pdf", Step: 1, Action: "rename", Status: "ok", Src: "/a/y.pdf", Dst: "/a/z.pdf"},
+ {Time: t0, Run: "A", Dir: "dl", File: "old.pdf", Step: 1, Action: "delete", Status: "ok", Src: "/a/old.pdf"},
+ {Time: t0, Run: "A", Action: "run-end", Status: "ok"},
+ {Time: t0.Add(time.Hour), Run: "B", Action: "run-start", Status: "ok", Detail: "undo of A"},
+ {Time: t0.Add(time.Hour), Run: "B", Dir: "dl", File: "x.pdf", Step: 1, Action: "undo-move", Status: "ok", Src: "/b/x.pdf", Dst: "/a/x.pdf"},
+ {Time: t0.Add(time.Hour), Run: "B", Dir: "dl", File: "y.pdf", Step: 1, Action: "undo-rename", Status: "declined", Src: "/a/z.pdf", Dst: "/a/y.pdf"},
+ {Time: t0.Add(time.Hour), Run: "B", Action: "run-end", Status: "ok"},
+ } {
+ w.Append(e)
+ }
+ runA := func() Run {
+ t.Helper()
+ runs, err := Runs(path, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, r := range runs {
+ if r.ID == "A" {
+ return r
+ }
+ }
+ t.Fatal("no run A")
+ return Run{}
+ }
+ if a := runA(); !a.Undone || !a.PartlyUndone {
+ t.Errorf("after one of two reversals: %+v, want undone, partly", a)
+ }
+ t2 := t0.Add(2 * time.Hour)
+ w.Append(Entry{Time: t2, Run: "C", Action: "run-start", Status: "ok", Detail: "undo of A"})
+ w.Append(Entry{Time: t2, Run: "C", Dir: "dl", File: "y.pdf", Step: 1, Action: "undo-rename", Status: "ok", Src: "/a/z.pdf", Dst: "/a/y.pdf"})
+ w.Append(Entry{Time: t2, Run: "C", Action: "run-end", Status: "ok"})
+ w.Close()
+ if a := runA(); !a.Undone || a.PartlyUndone {
+ t.Errorf("after both reversals: %+v, want undone in full", a)
+ }
+}