From 2561e4ea9e30d9a3bf220d252bf106fe399c93ed Mon Sep 17 00:00:00 2001 From: Ed_ Date: Wed, 24 Jun 2026 10:00:08 -0400 Subject: [PATCH] refactor(audit): remove dead compute_result_coverage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit compute_result_coverage() was implemented during the 14-phase plan but is never called: synthesize_aggregate_profile() (now at ~line 1075) inlines its own ResultCoverage construction via the actual AST analysis at ~line 1135-1145. The function has a latent bug at line 754 (was): result_producers = total_producers which hardcodes result_producers to 100% of total_producers regardless of input — making the function return meaningless numbers. Tests deleted in lockstep: - tests/test_code_path_audit_phase78.py: test_compute_result_coverage_no_producers - tests/test_code_path_audit_phase78.py: test_compute_result_coverage_full The 'compute_result_coverage' import was also removed from the test file's import block. Verification: - grep -c 'compute_result_coverage' src/code_path_audit.py = 0 - grep -c 'compute_result_coverage' tests/ = 0 - 125 of 125 remaining tests pass (was 127; -2 tests deleted) --- src/code_path_audit.py | 30 --------------------------- tests/test_code_path_audit_phase78.py | 22 -------------------- 2 files changed, 52 deletions(-) diff --git a/src/code_path_audit.py b/src/code_path_audit.py index 9b69ed50..40475ced 100644 --- a/src/code_path_audit.py +++ b/src/code_path_audit.py @@ -735,36 +735,6 @@ def find_enclosing_function( return None return max(candidates, key=lambda r: r.line) -def compute_result_coverage( - producers: list[FunctionRef], - consumers: list[FunctionRef], - branches_on_errors: set[str], -) -> ResultCoverage: - """Compute the per-aggregate result coverage. - - result_producers: total number of producers (the caller is responsible - for filtering to Result[T] producers; this function reports the raw - count). - result_consumers: consumers whose fqname is in branches_on_errors - (the caller passes the set from AST analysis). - """ - total_producers = len(producers) - result_producers = total_producers - total_consumers = len(consumers) - result_consumers = len({c.fqname for c in consumers if c.fqname in branches_on_errors}) - if total_producers > 0 and result_producers == total_producers: - pct_p = 100 - else: - pct_p = (result_producers / total_producers * 100) if total_producers > 0 else 0 - pct_c = (result_consumers / total_consumers * 100) if total_consumers > 0 else 0 - summary = f"{result_producers}/{total_producers} producers return Result[T] ({pct_p:.0f}%); {result_consumers}/{total_consumers} consumers branch on .errors ({pct_c:.0f}%)" - return ResultCoverage( - total_producers=total_producers, - result_producers=result_producers, - total_consumers=total_consumers, - result_consumers=result_consumers, - summary=summary, - ) def compute_type_alias_coverage(total_sites: int, typed_sites: int) -> TypeAliasCoverage: """Compute the per-aggregate type alias coverage.""" diff --git a/tests/test_code_path_audit_phase78.py b/tests/test_code_path_audit_phase78.py index 7fdde391..daf93df0 100644 --- a/tests/test_code_path_audit_phase78.py +++ b/tests/test_code_path_audit_phase78.py @@ -63,7 +63,6 @@ from src.code_path_audit import ( read_input_json, INPUT_JSON_CONTRACTS, find_enclosing_function, - compute_result_coverage, compute_type_alias_coverage, aggregate_cross_audit_findings, run_all_cross_audit_reads, @@ -123,28 +122,7 @@ def test_find_enclosing_function_no_match() -> None: result = find_enclosing_function(file="src/y.py", line=15, function_refs=refs) assert result is None -def test_compute_result_coverage_no_producers() -> None: - """compute_result_coverage returns 0/0 when there are no producers.""" - cov = compute_result_coverage(producers=[], consumers=[], branches_on_errors=set()) - assert cov.total_producers == 0 - assert cov.result_producers == 0 - assert cov.total_consumers == 0 - assert cov.result_consumers == 0 -def test_compute_result_coverage_full() -> None: - """compute_result_coverage counts producers and consumers correctly.""" - f1 = FunctionRef(fqname="src.a", file="src/a.py", line=1, role="producer") - f2 = FunctionRef(fqname="src.b", file="src/b.py", line=1, role="consumer") - cov = compute_result_coverage( - producers=[f1, f1], - consumers=[f2, f2, f2], - branches_on_errors={f2.fqname}, - ) - assert cov.total_producers == 2 - assert cov.result_producers == 2 - assert cov.total_consumers == 3 - assert cov.result_consumers == 1 - assert "100%" in cov.summary def test_compute_type_alias_coverage_no_sites() -> None: """compute_type_alias_coverage returns 0/0/0 when there are no sites."""