From 145623530a7f710a6aa2166cdb3251234173f77d Mon Sep 17 00:00:00 2001 From: Ed_ Date: Wed, 24 Jun 2026 10:03:48 -0400 Subject: [PATCH] test(audit): behavioral SSDL test locks down effective_codepaths math Adds a small synthetic fixture (tests/fixtures/synthetic_ssdl/) with 5 consumer functions, each containing 3 explicit if-statements. The fixture is self-contained and does not depend on the live src/ tree. The new test tests/test_code_path_audit_ssdl_behavioral.py has 2 tests: - test_effective_codepaths_synthetic: builds an AggregateProfile with 5 consumers pointing at the fixture's 5 functions, calls compute_effective_codepaths, asserts the result is 40 (= 5 consumers x 2^3 branches per function). - test_effective_codepaths_candidate_returns_zero: asserts that an AggregateProfile with is_candidate=True returns 0 (the SSDL early-exit guard for candidate aggregates). This locks down the SSDL effective-codepaths math so future refactors of compute_effective_codepaths() or count_branches_in_function() cannot silently change the formula without a failing test. Verification: - uv run pytest tests/test_code_path_audit_ssdl_behavioral.py -v -> 2 passed --- tests/fixtures/synthetic_ssdl/__init__.py | 0 .../fixtures/synthetic_ssdl/sample_module.py | 48 +++++++++ tests/test_code_path_audit_ssdl_behavioral.py | 98 +++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 tests/fixtures/synthetic_ssdl/__init__.py create mode 100644 tests/fixtures/synthetic_ssdl/sample_module.py create mode 100644 tests/test_code_path_audit_ssdl_behavioral.py diff --git a/tests/fixtures/synthetic_ssdl/__init__.py b/tests/fixtures/synthetic_ssdl/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/fixtures/synthetic_ssdl/sample_module.py b/tests/fixtures/synthetic_ssdl/sample_module.py new file mode 100644 index 00000000..2d5b8e33 --- /dev/null +++ b/tests/fixtures/synthetic_ssdl/sample_module.py @@ -0,0 +1,48 @@ +def func_one(x: int) -> int: + if x > 0: + x += 1 + if x > 1: + x += 1 + if x > 2: + x += 1 + return x + + +def func_two(x: int) -> int: + if x > 0: + x += 1 + if x > 1: + x += 1 + if x > 2: + x += 1 + return x + + +def func_three(x: int) -> int: + if x > 0: + x += 1 + if x > 1: + x += 1 + if x > 2: + x += 1 + return x + + +def func_four(x: int) -> int: + if x > 0: + x += 1 + if x > 1: + x += 1 + if x > 2: + x += 1 + return x + + +def func_five(x: int) -> int: + if x > 0: + x += 1 + if x > 1: + x += 1 + if x > 2: + x += 1 + return x \ No newline at end of file diff --git a/tests/test_code_path_audit_ssdl_behavioral.py b/tests/test_code_path_audit_ssdl_behavioral.py new file mode 100644 index 00000000..1558d9ba --- /dev/null +++ b/tests/test_code_path_audit_ssdl_behavioral.py @@ -0,0 +1,98 @@ +"""Behavioral SSDL tests for src.code_path_audit_ssdl.compute_effective_codepaths. + +Locks down the headline 4.01e22 effective codepaths math against a small +synthetic fixture so future refactors cannot silently change the formula. + +CONVENTION: 1-space indentation. NO COMMENTS. +""" +from __future__ import annotations + +from src.code_path_audit import ( + AggregateProfile, + CrossAuditFindings, + DecompositionCost, + FunctionRef, + Frequency, + FrequencyEvidence, + ResultCoverage, + TypeAliasCoverage, +) +from src.code_path_audit_ssdl import compute_effective_codepaths + + +FIXTURE_FILE = "sample_module.py" +FIXTURE_SRC_DIR = "tests/fixtures/synthetic_ssdl" +FIXTURE_FUNC_NAMES = ( + "func_one", + "func_two", + "func_three", + "func_four", + "func_five", +) + + +def _make_synthetic_profile() -> AggregateProfile: + consumers = tuple( + FunctionRef( + fqname=f"tests.fixtures.synthetic_ssdl.sample_module.{name}", + file=FIXTURE_FILE, + line=1, + role="consumer", + ) + for name in FIXTURE_FUNC_NAMES + ) + return AggregateProfile( + name="synthetic", + aggregate_kind="typealias", + memory_dim="control", + producers=(), + consumers=consumers, + access_pattern="whole_struct", + access_pattern_evidence=(), + frequency="per_turn", + frequency_evidence=(), + result_coverage=ResultCoverage(0, 0, 0, 0, ""), + type_alias_coverage=TypeAliasCoverage(0, 0, 0, ""), + cross_audit_findings=CrossAuditFindings((), (), (), (), ()), + decomposition_cost=DecompositionCost(0, 0, 0, "hold", "no data", None, 0, False), + optimization_candidates=(), + is_candidate=False, + ) + + +def _make_candidate_profile() -> AggregateProfile: + f = FunctionRef( + fqname="tests.fixtures.synthetic_ssdl.sample_module.func_one", + file=FIXTURE_FILE, + line=1, + role="consumer", + ) + return AggregateProfile( + name="synthetic_candidate", + aggregate_kind="typealias", + memory_dim="control", + producers=(), + consumers=(f,), + access_pattern="whole_struct", + access_pattern_evidence=(), + frequency="per_turn", + frequency_evidence=(), + result_coverage=ResultCoverage(0, 0, 0, 0, ""), + type_alias_coverage=TypeAliasCoverage(0, 0, 0, ""), + cross_audit_findings=CrossAuditFindings((), (), (), (), ()), + decomposition_cost=DecompositionCost(0, 0, 0, "hold", "no data", None, 0, False), + optimization_candidates=(), + is_candidate=True, + ) + + +def test_effective_codepaths_synthetic() -> None: + profile = _make_synthetic_profile() + result = compute_effective_codepaths(profile, src_dir=FIXTURE_SRC_DIR) + assert result == 40 + + +def test_effective_codepaths_candidate_returns_zero() -> None: + profile = _make_candidate_profile() + result = compute_effective_codepaths(profile, src_dir=FIXTURE_SRC_DIR) + assert result == 0 \ No newline at end of file