aboutsummaryrefslogtreecommitdiff
path: root/internal/engine/undo_identity_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 22:26:23 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 22:26:23 +0200
commit21339a73f5cd592ebd92937a1440aa9f13e75bbb (patch)
tree9b3e71e1f05e3c8cf49a34630615cb1f8c4a317c /internal/engine/undo_identity_test.go
parentd50f3670bf2ccb843e9001321d072a2d5680cb2a (diff)
downloadkrino-21339a73f5cd592ebd92937a1440aa9f13e75bbb.tar.gz
krino-21339a73f5cd592ebd92937a1440aa9f13e75bbb.zip
plan 10: a damaged log line refuses only its file, not the run
Diffstat (limited to 'internal/engine/undo_identity_test.go')
-rw-r--r--internal/engine/undo_identity_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/engine/undo_identity_test.go b/internal/engine/undo_identity_test.go
index 23e0bf9..5040ece 100644
--- a/internal/engine/undo_identity_test.go
+++ b/internal/engine/undo_identity_test.go
@@ -317,3 +317,45 @@ func TestApplyReportsAStepThatCouldNotBeLogged(t *testing.T) {
}
}
}
+
+// TestUndoRefusesOnlyTheFileWithADamagedLine: a crash that cuts one file's
+// log line refuses that file; the other files of the run are still undone
+// (re-review N1).
+func TestUndoRefusesOnlyTheFileWithADamagedLine(t *testing.T) {
+ e, run, h, logPath := appliedRun(t, map[string]map[string]string{"dl": {"a.pdf": "one", "b.pdf": "two"}},
+ map[string]string{"dl": "(path \"~/dl\")\n(rule \"r\" (move \"Out\"))\n"})
+ raw, err := os.ReadFile(logPath)
+ if err != nil {
+ t.Fatal(err)
+ }
+ lines := strings.Split(strings.TrimRight(string(raw), "\n"), "\n")
+ for i, l := range lines {
+ if strings.Contains(l, "\tb.pdf\t") && strings.Contains(l, "\tmove\t") {
+ lines[i] = l[:len(l)/2] // cut mid-write
+ }
+ }
+ if err := os.WriteFile(logPath, []byte(strings.Join(lines, "\n")+"\n"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ up, err := e.PlanUndo(run)
+ if err != nil {
+ t.Fatalf("PlanUndo refused the whole run: %v", err)
+ }
+ if f := undoFileNamed(t, up, "dl", "b.pdf"); !strings.Contains(f.Refused, "damaged") {
+ t.Errorf("b.pdf: Refused %q; want its damaged log named", f.Refused)
+ }
+ if f := undoFileNamed(t, up, "dl", "a.pdf"); f.Refused != "" {
+ t.Errorf("a.pdf refused: %q", f.Refused)
+ }
+ j, err := journal.Open(logPath)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer j.Close()
+ if _, err := e.ApplyUndo(context.Background(), up, j, journal.NewRunID(time.Now())); err != nil {
+ t.Fatal(err)
+ }
+ if b, err := os.ReadFile(filepath.Join(h, "dl", "a.pdf")); err != nil || string(b) != "one" {
+ t.Errorf("a.pdf not restored: %q %v", b, err)
+ }
+}