| 1 | package readcoord |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "time" |
| 6 | |
| 7 | "reasonix/internal/tool" |
| 8 | ) |
| 9 | |
| 10 | func TestAssociateExpandsOnlyMissingCoverageWithoutResettingBudget(t *testing.T) { |
| 11 | c := New() |
| 12 | end := 4 |
| 13 | env := tool.ReadResultEnvelope{ReadID: "first", Source: tool.ReadResultSource{CanonicalPath: "/w/a", Identity: "raw", Snapshot: "v"}, Intent: tool.ReadIntentRange, RequestedRange: &tool.ReadRange{Start: 0, End: 2}, DeliveredRanges: []tool.ReadRange{{Start: 0, End: 2}}, SourceEnd: &end} |
| 14 | c.Observe(env, 5) |
| 15 | env.ReadID, env.Intent, env.RequestedRange = "new-call", tool.ReadIntentFull, nil |
| 16 | env.ReadID = c.Associate(env) |
| 17 | if env.ReadID != "first" { |
| 18 | t.Fatal("lost previous coverage") |
| 19 | } |
| 20 | tr, _ := c.Observe(env, 7) |
| 21 | if tr.To != StateNeedsMore || !Covers(tr.Missing, []tool.ReadRange{{Start: 2, End: 4}}) { |
| 22 | t.Fatalf("missing ranges: %+v", tr) |
| 23 | } |
| 24 | ob, _ := c.Get("first") |
| 25 | if ob.Pages != 2 || ob.ActiveTime != 12*time.Millisecond { |
| 26 | t.Fatal("expanded requirement reset accounting") |
| 27 | } |
| 28 | env.DeliveredRanges, env.EOF = []tool.ReadRange{{Start: 2, End: 4}}, true |
| 29 | tr, _ = c.Observe(env, 3) |
| 30 | if tr.To != StateSatisfied { |
| 31 | t.Fatal("tail failed to finish expanded requirement") |
| 32 | } |
| 33 | } |
| 34 |