Artifact a82cea6ebb05a3c741d756130259c407ce36e9bea64127986d0a0ebffe61bc86:
- File
horizon_cost_test.go
— part of check-in
[834b28d9fe]
at
2026-10-23 03:02:17
on branch feat/horizon-cones
— feat(cli): report what each horizon rule would hold
Draft ยง3.4 asks a tool that suggests a horizon to show, before the choice, what each rule would hold in check-ins and bytes. repo cone cost <check-in> prints that for descendants and leaves from the local repository, and Repo.HorizonCost returns the figures. The --horizon help of repo clone and repo cone store points to it, noting that a clone has no repository yet. (user: [email protected], size: 1801) [annotate] [blame] [check-ins using] [more...]
package libfossil import ( "errors" "path/filepath" "testing" ) // costRepo is c1 -> c2 -> c3 on trunk and an unmerged childless fork feat off // c1. A horizon at c2 holds {c2, c3} under the descendants rule and all four // under the leaves rule, where feat's ancestry meets c2's at c1. func costRepo(t *testing.T) (r *Repo, c2 string) { t.Helper() r, err := Create(filepath.Join(t.TempDir(), "cost.fossil"), CreateOpts{User: "test"}) if err != nil { t.Fatal(err) } t.Cleanup(func() { r.Close() }) commit := func(parent int64, a string) (int64, string) { rid, uuid, err := r.Commit(CommitOpts{User: "test", ParentID: parent, Files: []FileToCommit{ {Name: "a", Content: []byte(a)}, {Name: "b", Content: []byte("shared b\n")}, }}) if err != nil { t.Fatal(err) } return rid, uuid } r1, _ := commit(0, "old a\n") r2, c2 := commit(r1, "new a\n") commit(r2, "newest a\n") commit(r1, "feat a\n") return r, c2 } func TestHorizonCost(t *testing.T) { r, c2 := costRepo(t) got, err := r.HorizonCost(c2) if err != nil { t.Fatal(err) } want := []HorizonRuleCost{ {Rule: HorizonDescendants, Checkins: 2, Blobs: 3, ExpandedBytes: 6 + 9 + 9}, {Rule: HorizonLeaves, Checkins: 4, Blobs: 5, ExpandedBytes: 6 + 6 + 9 + 7 + 9}, } if len(got) != len(want) { t.Fatalf("HorizonCost = %+v, want %d rules", got, len(want)) } for i, w := range want { g := got[i] if g.StoredBytes <= 0 { t.Errorf("%s: stored bytes %d, want positive", w.Rule, g.StoredBytes) } g.StoredBytes = 0 if g != w { t.Errorf("%s = %+v, want %+v", w.Rule, g, w) } } } func TestHorizonCostUnknownCheckin(t *testing.T) { r, _ := costRepo(t) if _, err := r.HorizonCost("no-such-name"); !errors.Is(err, ErrVersionNotFound) { t.Fatalf("error = %v, want ErrVersionNotFound", err) } }