package dobotaiops import ( "context" "testing" ) func TestMirrorSourceManifestDetectsUpdatesWithoutVolatileTimes(t *testing.T) { p := fixturePool(t) c := buildReadOnlyClient(t, qaRecordsFixture(t, p)) ctx := context.Background() a, e := c.ReadMirrorManifest(ctx, "default") if e != nil || len(a.Keys) != 4 || a.AsOf.IsZero() { t.Fatal("full fixed-channel manifest is missing", e, len(a.Keys)) } b, e := c.ReadMirrorManifest(ctx, "default") if e != nil || len(b.Keys) != len(a.Keys) { t.Fatal(e) } old := map[string]string{} for i, k := range a.Keys { old[k.ID] = k.Fingerprint if k != b.Keys[i] { t.Fatal("source clock alone changed the content fingerprint") } } rows, e := c.ReadMirrorRecords(ctx, "default", []string{"turn-3"}) if e != nil || len(rows) != 1 || rows[0].Key.Fingerprint != old["turn-3"] { t.Fatal("bounded safe payload fetch failed", e) } before, e := DecodeMirrorPayload(string(rows[0].Payload)) if e != nil || before.Feedback.Up != 1 || before.Identity.StaffID == "" { t.Fatal("safe payload lost required fields", e) } execFixture(t, p, `UPDATE answer_feedback SET value='down' WHERE id='fb1'`) after, e := c.ReadMirrorRecords(ctx, "default", []string{"turn-3"}) if e != nil || after[0].Key.Fingerprint == old["turn-3"] { t.Fatal("feedback update on old question was missed", e) } rec, _ := DecodeMirrorPayload(string(after[0].Payload)) if rec.QualityInputHash != before.QualityInputHash { t.Fatal("feedback invalidated unrelated human quality input") } execFixture(t, p, `UPDATE turns SET answer='changed answer' WHERE id='turn-3'`) after, e = c.ReadMirrorRecords(ctx, "default", []string{"turn-3"}) rec, _ = DecodeMirrorPayload(string(after[0].Payload)) if e != nil || rec.QualityInputHash == before.QualityInputHash { t.Fatal("answer change was missed") } if _, e = c.ReadMirrorRecords(ctx, "default", make([]string, 101)); e == nil { t.Fatal("unbounded payload fetch allowed") } }