From 6f2d2412884558ba31b3d0208662694a456cbee9 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 4 Feb 2026 13:07:17 +0000 Subject: [PATCH] Refine branch differentiation comment and add hash verification tests - Removed 'FIX:' prefix from comment in `pkg/analysis/topology/topology.go` as the logic is correct. - Enhanced `TestFuzzyHashDistinction` in `pkg/analysis/topology/topology_test.go` to explicitly verify `BR0` (linear), `BR1` (single if), and `BR2` (two ifs) components in the fuzzy hash. Co-authored-by: xkilldash9x <223238109+xkilldash9x@users.noreply.github.com> --- pkg/analysis/topology/topology.go | 2 +- pkg/analysis/topology/topology_test.go | 27 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/pkg/analysis/topology/topology.go b/pkg/analysis/topology/topology.go index e3d2454..fc62b5f 100644 --- a/pkg/analysis/topology/topology.go +++ b/pkg/analysis/topology/topology.go @@ -277,7 +277,7 @@ func GenerateFuzzyHash(t *FunctionTopology) string { } brBucket := 0 if t.BranchCount > 0 { - // FIX: Differentiate between 0 branches (linear) and 1 branch (single if). + // Differentiate between 0 branches (linear) and 1 branch (single if). // Log2(1) is 0, so we shift by 1 to make BR0 mean "no branches" and BR1 mean "1 branch". brBucket = int(math.Log2(float64(t.BranchCount))) + 1 } diff --git a/pkg/analysis/topology/topology_test.go b/pkg/analysis/topology/topology_test.go index 59371f2..92f891a 100644 --- a/pkg/analysis/topology/topology_test.go +++ b/pkg/analysis/topology/topology_test.go @@ -188,11 +188,38 @@ func TestFuzzyHashDistinction(t *testing.T) { } }` + srcBranched2 := `package main + func branched2(b bool, c bool) { + if b { + println("branch 1") + } + if c { + println("branch 2") + } + }` + fnLinear := testutil.CompileAndGetFunction(t, srcLinear, "linear") fnBranched := testutil.CompileAndGetFunction(t, srcBranched, "branched") + fnBranched2 := testutil.CompileAndGetFunction(t, srcBranched2, "branched2") topoLinear := topology.ExtractTopology(fnLinear) topoBranched := topology.ExtractTopology(fnBranched) + topoBranched2 := topology.ExtractTopology(fnBranched2) + + // Linear: 0 branches -> BR0 + if !strings.Contains(topoLinear.FuzzyHash, "BR0") { + t.Errorf("Linear code hash should contain BR0, got %q", topoLinear.FuzzyHash) + } + + // Single If: 1 branch -> BR1 + if !strings.Contains(topoBranched.FuzzyHash, "BR1") { + t.Errorf("Branched code (1 if) hash should contain BR1, got %q", topoBranched.FuzzyHash) + } + + // Two Ifs: 2 branches -> BR2 + if !strings.Contains(topoBranched2.FuzzyHash, "BR2") { + t.Errorf("Branched code (2 ifs) hash should contain BR2, got %q", topoBranched2.FuzzyHash) + } if topoLinear.FuzzyHash == topoBranched.FuzzyHash { t.Errorf("Fuzzy Hash Collision: Linear and Branched code produced same hash %q", topoLinear.FuzzyHash)