Artifact 860deb1e76c06a61c7cfc1fb3e64d0b9ab1f4c452cc6b8930f41754b90e406d9:
- File
internal/sync/horizon_history_test.go
— part of check-in
[fe06d02a12]
at
2026-10-23 02:20:22
on branch feat/horizon-cones
— feat(sync): name a history URL in horizon-served
draft-fossil-horizon-00 §6.2.5 lets an origin append to pragma horizon-served the URL of an interface outside the protocol at which history below a horizon can be queried, and §5.5 has a client direct the user there. go-libfossil emitted the level alone and dropped any URL a reply carried.
An origin now appends its horizon-history-url setting when set. The value rides the pragma as one raw card token, so SetConfig refuses anything but a single http or https URL with a host and no white space or credentials, and the handler emits nothing for a value stored past that check. The client records a valid URL from any origin in its clone and sync results, exported additively on the public results, and the CLI's clone and cone store/deepen print it. (user: [email protected], size: 2543) [annotate] [blame] [check-ins using] [more...]
package sync import ( "context" "strings" "testing" "github.com/danmestas/go-libfossil/internal/cone" "github.com/danmestas/go-libfossil/internal/repo" "github.com/danmestas/go-libfossil/internal/xfer" ) func servedValues(t *testing.T, r *repo.Repo) [][]string { t.Helper() cards := append([]xfer.Card{&xfer.PullCard{ServerCode: "x", ProjectCode: testPC}}, conePragmas(testHorizonCone(t, cone.DepthContent), noSeed)...) resp, err := HandleSync(context.Background(), r, &xfer.Message{Cards: cards}) if err != nil { t.Fatal(err) } var out [][]string for _, card := range resp.Cards { if p, ok := card.(*xfer.PragmaCard); ok && p.Name == horizonServedPragma { out = append(out, p.Values) } } return out } // draft-fossil-horizon-00 §6.2.5: an origin whose horizon-history-url is // set appends it to horizon-served; unset, or stored invalid by a path // that bypassed the setting's check, it emits the level alone. func TestHorizonServedHistoryURL(t *testing.T) { r := setupSyncTestRepo(t) if got := servedValues(t, r); len(got) != 1 || strings.Join(got[0], " ") != "content" { t.Fatalf("unset: horizon-served %q, want [content]", got) } const url = "https://example.org/history" if err := r.SetConfig(repo.SettingHorizonHistoryURL, url); err != nil { t.Fatal(err) } if got := servedValues(t, r); len(got) != 1 || strings.Join(got[0], " ") != "content "+url { t.Fatalf("set: horizon-served %q, want [content %s]", got, url) } if _, err := r.DB().Exec("UPDATE config SET value=? WHERE name=?", "https://example.org/a b", repo.SettingHorizonHistoryURL); err != nil { t.Fatal(err) } if got := servedValues(t, r); len(got) != 1 || strings.Join(got[0], " ") != "content" { t.Fatalf("stored invalid: horizon-served %q, want [content]", got) } } // A client records the URL a horizon-served pragma carries when it is a // valid one, and ignores an invalid one while still taking the level. func TestServedHistoryURL(t *testing.T) { for _, tc := range []struct { values []string want string }{ {[]string{"content"}, ""}, {[]string{"content", "https://example.org/h"}, "https://example.org/h"}, {[]string{"structural", "http://example.org/h"}, "http://example.org/h"}, {[]string{"content", "ftp://example.org/h"}, ""}, {[]string{"content", "https://example.org/h", "extra"}, ""}, } { got := servedHistoryURL(&xfer.PragmaCard{Name: horizonServedPragma, Values: tc.values}) if got != tc.want { t.Errorf("servedHistoryURL(%q) = %q, want %q", tc.values, got, tc.want) } } }