mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-10-17 05:37:43 +00:00
fix(pricing): content-digest snapshot instead of a wall-clock date
The generated pricing_data_gen.go header used to stamp today's date on every `make pricing-sync` run, so a re-run against genuinely unchanged upstream data still touched the file and produced a spurious daily diff with nothing real to review. The header now records a short SHA-256 digest of the FETCHED bytes instead — identical upstream data always reproduces a byte-identical generated file. Folded review minor.
This commit is contained in:
@@ -168,13 +168,13 @@ func TestParseAndPrune_Golden(t *testing.T) {
|
||||
// TestRenderGoSource_ValidSortedGo asserts renderGoSource produces
|
||||
// syntactically valid, gofmt-canonical Go source (parseable by go/
|
||||
// parser) whose entries appear in sorted key order, and that its header
|
||||
// documents the pruning provenance (source URL, snapshot, counts).
|
||||
// documents the pruning provenance (source URL, content digest, counts).
|
||||
func TestRenderGoSource_ValidSortedGo(t *testing.T) {
|
||||
table := map[string]builtinEntry{
|
||||
"zzz-model": {ContextTokens: 1, InputCostPerMTokMicroUSD: 1, OutputCostPerMTokMicroUSD: 1},
|
||||
"aaa-model": {ContextTokens: 2, InputCostPerMTokMicroUSD: 2, OutputCostPerMTokMicroUSD: 2},
|
||||
}
|
||||
src, err := renderGoSource(table, sourceMeta{snapshot: "2026-08-22", totalUpstream: 3111, kept: 2})
|
||||
src, err := renderGoSource(table, sourceMeta{sourceDigest: "deadbeefcafe", totalUpstream: 3111, kept: 2})
|
||||
if err != nil {
|
||||
t.Fatalf("renderGoSource: %v", err)
|
||||
}
|
||||
@@ -188,8 +188,8 @@ func TestRenderGoSource_ValidSortedGo(t *testing.T) {
|
||||
if !strings.Contains(src, litellmSourceURL) {
|
||||
t.Error("generated source missing source URL provenance comment")
|
||||
}
|
||||
if !strings.Contains(src, "2026-08-22") || !strings.Contains(src, "3111") {
|
||||
t.Error("generated source missing snapshot date / upstream count provenance comment")
|
||||
if !strings.Contains(src, "deadbeefcafe") || !strings.Contains(src, "3111") {
|
||||
t.Error("generated source missing source-digest / upstream count provenance comment")
|
||||
}
|
||||
if got, want := strings.Index(src, `"aaa-model"`), strings.Index(src, `"zzz-model"`); got == -1 || want == -1 || got > want {
|
||||
t.Errorf(`entries not sorted: index("aaa-model")=%d, index("zzz-model")=%d, want aaa before zzz`, got, want)
|
||||
@@ -242,3 +242,25 @@ func TestApplyNamingBridges_DoesNotOverwriteExistingEntry(t *testing.T) {
|
||||
t.Errorf(`table["MiniMax-M2.1-highspeed"] = %+v, want %+v (its own direct LiteLLM entry, not the bridged duplicate)`, got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TestContentDigest covers the review-fix replacement for a wall-clock
|
||||
// snapshot date: identical bytes must always produce an identical
|
||||
// digest (the whole point — a `make pricing-sync` re-run against
|
||||
// unchanged upstream data must reproduce a byte-identical file, with no
|
||||
// spurious diff), different bytes must produce a different digest, and
|
||||
// the digest is always exactly contentDigestLen hex characters.
|
||||
func TestContentDigest(t *testing.T) {
|
||||
a := contentDigest([]byte(`{"gpt-5":{}}`))
|
||||
b := contentDigest([]byte(`{"gpt-5":{}}`))
|
||||
c := contentDigest([]byte(`{"gpt-5":{"changed":true}}`))
|
||||
|
||||
if a != b {
|
||||
t.Errorf("contentDigest is not deterministic: %q != %q for identical input", a, b)
|
||||
}
|
||||
if a == c {
|
||||
t.Errorf("contentDigest(%q) == contentDigest(%q) = %q, want different digests for different input", `{"gpt-5":{}}`, `{"gpt-5":{"changed":true}}`, a)
|
||||
}
|
||||
if len(a) != contentDigestLen {
|
||||
t.Errorf("len(contentDigest(...)) = %d, want %d", len(a), contentDigestLen)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user