feat(html): canonicalize compare variant keys
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

This commit is contained in:
Snider 2026-04-15 02:53:37 +01:00
parent e95c059412
commit dd68c6d0d7
2 changed files with 22 additions and 1 deletions

View file

@ -141,7 +141,12 @@ func CompareVariants(r *Responsive, ctx *Context) map[string]float64 {
scores := make(map[string]float64)
for i := range len(imprints) {
for j := i + 1; j < len(imprints); j++ {
key := imprints[i].name + ":" + imprints[j].name
left := imprints[i].name
right := imprints[j].name
if right < left {
left, right = right, left
}
key := left + ":" + right
scores[key] = imprints[i].imp.Similar(imprints[j].imp)
}
}

View file

@ -172,3 +172,19 @@ func TestCompareVariants_SameContent_Good(t *testing.T) {
t.Errorf("same content in different variants should score >= 0.8, got %f", sim)
}
}
func TestCompareVariants_KeyOrderDeterministic_Good(t *testing.T) {
svc, _ := i18n.New()
i18n.SetDefault(svc)
ctx := NewContext()
r := NewResponsive().
Variant("beta", NewLayout("C").C(El("p", Text("Building project")))).
Variant("alpha", NewLayout("C").C(El("p", Text("Building project"))))
scores := CompareVariants(r, ctx)
if _, ok := scores["alpha:beta"]; !ok {
t.Fatalf("CompareVariants should use deterministic key ordering, got keys: %v", scores)
}
}