Artifact f7acc875f864b09c37b7491995cd1011da3de8901a41888db2090588ea19650c:
- File
internal/horizon/graph_test.go
— part of check-in
[b1933e5f82]
at
2026-10-22 22:12:00
on branch feat/horizon-cones
— feat(horizon): a check-in graph a held set extends over
An origin computes K for every horizon request by reading every plink edge and held check-in from the store. draft-fossil-horizon-00 §6.2 asks it to read those references once into a graph keyed to the store prefix and extend that graph by the artifacts appended since. Graph is that graph: loaded once, extended copy-on-write by the rids that changed, and HeldSet over it equals HeldSet over the store. (user: [email protected], size: 2339) [annotate] [blame] [check-ins using] [more...]
package horizon_test import ( "context" "slices" "testing" "github.com/danmestas/go-libfossil/internal/cone" libfossil "github.com/danmestas/go-libfossil/internal/fsltype" "github.com/danmestas/go-libfossil/internal/horizon" ) // draft-fossil-horizon-00 §6.2: a graph loaded once and extended by the // check-ins appended since yields, for every C and both rules, the held set // a fresh read of plink does. The appended check-ins include a fork from // below every C, which under the leaves rule brings old check-ins into K. func TestGraphExtendMatchesHeldSet(t *testing.T) { ctx := context.Background() d := newDAG(t) c := d.chain("c1", "c2", "c3", "c4") g, err := horizon.LoadGraph(ctx, d.r.DB()) if err != nil { t.Fatal(err) } f1 := d.commit("f1", p(c[0]), branchTags("feat")...) f2 := d.commit("f2", p(f1)) m := d.commit("m", p(c[3], f2)) g1 := d.commit("g1", p(c[1]), branchTags("gone")...) g, err = g.Extend(ctx, d.r.DB(), []libfossil.FslID{f1, f2}) if err != nil { t.Fatal(err) } g, err = g.Extend(ctx, d.r.DB(), []libfossil.FslID{m, g1}) if err != nil { t.Fatal(err) } all := append(slices.Clone(c), f1, f2, m, g1) for _, at := range all { for _, rule := range []cone.HorizonRule{cone.RuleDescendants, cone.RuleLeaves} { want, err := horizon.HeldSet(ctx, d.r.DB(), at, rule) if err != nil { t.Fatal(err) } got, err := g.HeldSet(ctx, at, rule) if err != nil { t.Fatal(err) } if !slices.Equal(got, want) { t.Errorf("C=%d %v: extended graph %v, fresh %v", at, rule, got, want) } } } if _, err := g.HeldSet(ctx, 1<<30, cone.RuleLeaves); err == nil { t.Fatal("a C the graph does not hold placed") } } // Extending leaves the graph it extends as it was: an origin's request that // rolls back must not change the classification another request shares. func TestGraphExtendCopies(t *testing.T) { ctx := context.Background() d := newDAG(t) c := d.chain("c1", "c2") g, err := horizon.LoadGraph(ctx, d.r.DB()) if err != nil { t.Fatal(err) } c3 := d.commit("c3", p(c[1])) if _, err := g.Extend(ctx, d.r.DB(), []libfossil.FslID{c3}); err != nil { t.Fatal(err) } got, err := g.HeldSet(ctx, c[0], cone.RuleDescendants) if err != nil { t.Fatal(err) } if !slices.Equal(got, c) { t.Fatalf("extension changed the graph it extended: %v", got) } }