145623530a
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
98 lines
2.6 KiB
Python
98 lines
2.6 KiB
Python
"""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 |