aboutsummaryrefslogtreecommitdiff
path: root/internal/engine/undo_identity_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 22:24:38 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 22:24:38 +0200
commitd50f3670bf2ccb843e9001321d072a2d5680cb2a (patch)
tree8259f29f9d4f1236c071a2c3dbfd414d097a2f46 /internal/engine/undo_identity_test.go
parent394d117b90ffb64c87adfc8c2436b57007840c2b (diff)
downloadkrino-d50f3670bf2ccb843e9001321d072a2d5680cb2a.tar.gz
krino-d50f3670bf2ccb843e9001321d072a2d5680cb2a.zip
plan 10: a step that ran but could not be logged is named in the error
Diffstat (limited to 'internal/engine/undo_identity_test.go')
-rw-r--r--internal/engine/undo_identity_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/internal/engine/undo_identity_test.go b/internal/engine/undo_identity_test.go
index d4169be..23e0bf9 100644
--- a/internal/engine/undo_identity_test.go
+++ b/internal/engine/undo_identity_test.go
@@ -274,3 +274,46 @@ func TestUndoCanBeFinishedAfterAFailure(t *testing.T) {
t.Errorf("dl/a.pdf = %q, %v; want the original back", b, err)
}
}
+
+// TestApplyReportsAStepThatCouldNotBeLogged: when the log stops accepting
+// writes mid-chain, the step that already ran is named in the error - file,
+// action and where the file is now - so the user can find what undo cannot
+// see (re-review N1).
+func TestApplyReportsAStepThatCouldNotBeLogged(t *testing.T) {
+ h := sandbox(t)
+ p := filepath.Join(h, "dl", "a.pdf")
+ os.MkdirAll(filepath.Dir(p), 0o755)
+ os.WriteFile(p, []byte("one"), 0o644)
+ old := time.Now().Add(-2 * time.Hour)
+ os.Chtimes(p, old, old)
+ main := writeConfig(t, h, `(include "dl")`, map[string]string{"dl": "(path \"~/dl\")\n(rule \"r\" (rename \"r-{name}\") (move \"Out\"))\n"})
+ e, errs := Load(main)
+ if len(errs) > 0 {
+ t.Fatal(errs)
+ }
+ dp, err := e.Plan(context.Background(), e.Dirs[0], plan.NewClaims())
+ if err != nil {
+ t.Fatal(err)
+ }
+ j, err := journal.Open(filepath.Join(h, "state", "krino.log"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ calls := 0
+ e.Now = func() time.Time {
+ calls++
+ if calls == 3 { // run-start and the rename are logged; the move is not
+ j.Close()
+ }
+ return time.Now()
+ }
+ _, err = e.Apply(context.Background(), dp, map[string]bool{"a.pdf": true}, j, "R")
+ if err == nil {
+ t.Fatal("apply succeeded with a closed log")
+ }
+ for _, want := range []string{"a.pdf", "move", "could not be logged", "Out/r-a.pdf"} {
+ if !strings.Contains(err.Error(), want) {
+ t.Errorf("error %q does not mention %q", err, want)
+ }
+ }
+}