oficina / memoria Public

Reproduce stale corpus after successful empty sibling replacement

Paul Campbell pushed by paul@keymail.dev 762a8b7a1eb2648004b94b81a879074297c32485 parent a012c8f
1 file changed, +52 −0
  • internal/memoria/siblingsync_empty_test.go +52 −0
diff --git a/internal/memoria/siblingsync_empty_test.go b/internal/memoria/siblingsync_empty_test.go
new file mode 100644
index 0000000..b81777f
--- /dev/null
+++ b/internal/memoria/siblingsync_empty_test.go
@@ -0,0 +1,52 @@
+package memoria
+
+import (
+ "context"
+ "testing"
+
+ "amadan.net/oficina/suite"
+)
+
+// Regression: a successful empty replacement used to leave the prior
+// revision in storage and the index after Poll advanced its cursor.
+func TestEmptySiblingReplacementRetiresPriorPassages(t *testing.T) {
+ for _, body := range []string{"", " \n\t "} {
+ t.Run(body, func(t *testing.T) {
+ ctx := context.Background()
+ s := storeForTest(t)
+ f := &feedServer{t: t, pages: map[string]suite.Feed{
+ "": {Cursor: "c1", Rows: []suite.FeedRow{row("item", 7, false)}},
+ "c1": {Cursor: "c1", Rows: []suite.FeedRow{}},
+ }, bodies: map[string]string{"item": "Synthetic retained passage from an earlier revision."}}
+ sib, client := f.start(t)
+ if _, err := s.Poll(ctx, client, sib); err != nil {
+ t.Fatal(err)
+ }
+ assertHeld(t, s, "Docs", "item", 7)
+ n, err := s.Count()
+ if err != nil || n == 0 {
+ t.Fatalf("initial index count=%d error=%v", n, err)
+ }
+ f.pages["c1"] = suite.Feed{Cursor: "c2", Rows: []suite.FeedRow{row("item", 8, false)}}
+ f.pages["c2"] = suite.Feed{Cursor: "c2", Rows: []suite.FeedRow{}}
+ f.bodies["item"] = body
+ res, err := s.Poll(ctx, client, sib)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if res.Empty != 1 {
+ t.Fatalf("empty=%d", res.Empty)
+ }
+ if heldCount(t, s, "Docs") != 0 {
+ t.Fatal("successful empty replacement retained the old document")
+ }
+ n, err = s.Count()
+ if err != nil || n != 0 {
+ t.Fatalf("stale index count=%d error=%v", n, err)
+ }
+ if cursorOf(t, s, "Docs") != "c2" {
+ t.Fatal("replacement cursor not applied")
+ }
+ })
+ }
+}