Download this file
| 1 | package memoria |
| 2 | |
| 3 | import ( |
| 4 | "math" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/google/uuid" |
| 8 | ) |
| 9 | |
| 10 | func TestAgentNoteUpdateRevisionExhaustion(t *testing.T) { |
| 11 | for _, body := range []string{"original body", "changed body"} { |
| 12 | t.Run(body, func(t *testing.T) { |
| 13 | f, p := linkedAgentFixture(t) |
| 14 | active := true |
| 15 | h := mountAgentFixture(t, f, &p, &active) |
| 16 | id, err := f.app.store.Ingest(t.Context(), IngestSpec{Source: "paste", Key: "limit", Title: "original", Body: "original body"}) |
| 17 | if err != nil { |
| 18 | t.Fatal(err) |
| 19 | } |
| 20 | if err := f.app.db.G.Model(&Document{}).Where("id=?", id).Update("revision", math.MaxInt).Error; err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | if w := agentCall(h, "notes_update", noteUpdateJSON(id, math.MaxInt, uuid.NewString(), "changed", body)); w.Code != 503 { |
| 24 | t.Fatal(w.Code, w.Body.String()) |
| 25 | } |
| 26 | var d Document |
| 27 | if err := f.app.db.G.First(&d, id).Error; err != nil || d.Revision != math.MaxInt { |
| 28 | t.Fatal("revision corrupted", d.Revision, err) |
| 29 | } |
| 30 | }) |
| 31 | } |
| 32 | } |
| 33 | |