From dd68c6d0d7c5df7609aaa79f9cae4eb3f6aecc8b Mon Sep 17 00:00:00 2001 From: Snider Date: Wed, 15 Apr 2026 02:53:37 +0100 Subject: [PATCH] feat(html): canonicalize compare variant keys --- pipeline.go | 7 ++++++- pipeline_test.go | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pipeline.go b/pipeline.go index d359637..683b21f 100644 --- a/pipeline.go +++ b/pipeline.go @@ -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) } } diff --git a/pipeline_test.go b/pipeline_test.go index 2f865ba..0e3bd2f 100644 --- a/pipeline_test.go +++ b/pipeline_test.go @@ -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) + } +}