Skip to content

Commit 57333ff

Browse files
committed
fix: SonarCloud quality gate — float equality, dict fromkeys, PRNG hotspot
1 parent 57cfe1f commit 57333ff

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

benchmarks/contextbench_diffctx.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,15 @@ def evaluate_instance(inst: dict, budget: int = 8000) -> dict | None:
268268
if frag_count == 0:
269269
diagnostics.append("WARN: diffctx returned 0 fragments")
270270

271-
if lo_all["line_recall"] == 0.0 and frag_count > 0:
271+
if lo_all["line_recall"] < 1e-9 and frag_count > 0:
272272
diagnostics.append("DIAG: line_recall=0 with fragments>0 — possible line parse bug or no file overlap")
273273

274-
if file_recall == 0.0 and frag_count > 0:
274+
if file_recall < 1e-9 and frag_count > 0:
275275
diagnostics.append("DIAG: file_recall=0 with fragments>0 — selected files don't overlap gold at all")
276276
diagnostics.append(f" gold_files: {sorted(gf)[:5]}")
277277
diagnostics.append(f" selected: {sorted(sel_files)[:5]}")
278278

279-
if nontrivial_recall == 0.0 and frag_count > 5:
279+
if nontrivial_recall < 1e-9 and frag_count > 5:
280280
diagnostics.append("DIAG: nontrivial_recall=0 — diffctx may only be selecting patch-adjacent files")
281281

282282
unparsed = sum(1 for f in output.get("fragments", []) if parse_lines_field(f.get("lines", "")) is None)
@@ -335,7 +335,7 @@ def aggregate(results: list[dict]) -> None:
335335
print(f" {repo:30s} (n={len(rr):3d}): nontrivial_recall={avg_ntr:.3f}")
336336

337337
zero_frag = sum(1 for r in ok if r["fragments"] == 0)
338-
zero_line = sum(1 for r in ok if r["line_recall"] == 0.0 and r["fragments"] > 0)
338+
zero_line = sum(1 for r in ok if r["line_recall"] < 1e-9 and r["fragments"] > 0)
339339

340340
print("\nDiagnostic summary:")
341341
print(f" Instances with 0 fragments: {zero_frag}/{len(ok)}")
@@ -380,8 +380,8 @@ def main():
380380
print(f"Nontrivial instances: {len(instances)}")
381381

382382
if not args.no_shuffle:
383-
random.seed(args.seed)
384-
random.shuffle(instances)
383+
rng = random.Random(args.seed) # NOSONAR — deterministic shuffle for benchmark reproducibility, not crypto
384+
rng.shuffle(instances)
385385
print(f"Shuffled with seed={args.seed}")
386386

387387
instances = instances[: args.limit]

tests/test_diffctx_integrity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ def test_hub_node_edges_are_dampened(self) -> None:
586586
edges[(src, hub)] = raw_weight
587587
edges[(sources[0], non_hub)] = raw_weight
588588

589-
categories: dict[tuple[FragmentId, FragmentId], str] = {k: "generic" for k in edges}
589+
categories: dict[tuple[FragmentId, FragmentId], str] = dict.fromkeys(edges, "generic")
590590

591591
suppressed = _apply_hub_suppression(edges, categories)
592592

0 commit comments

Comments
 (0)