Private
Public Access
0
0

feat(audit): add FunctionRef dataclass (frozen, 4 fields)

fqname, file, line, role. Used in ProducerConsumerGraph edges
and per-aggregate producer/consumer lists. Per error_handling.md
Pattern 1 (immutability for cross-thread safety).
2 unit tests passing.
This commit is contained in:
2026-06-22 01:05:17 -04:00
parent be4ec0a459
commit 1680182953
2 changed files with 38 additions and 2 deletions
+9 -1
View File
@@ -9,6 +9,7 @@ postfix DSL + markdown + prefix tree text. See
conductor/tracks/code_path_audit_20260607/spec_v2.md.
"""
from __future__ import annotations
from dataclasses import dataclass
from typing import Literal
AggregateKind = Literal[
@@ -51,4 +52,11 @@ RecommendedDirection = Literal[
"unify",
"hold",
"insufficient_data",
]
]
@dataclass(frozen=True)
class FunctionRef:
fqname: str
file: str
line: int
role: str
+29 -1
View File
@@ -1,10 +1,13 @@
"""Tests for src.code_path_audit v2 - Phase 1 (data model)."""
from __future__ import annotations
import pytest
from src.code_path_audit import (
AggregateKind,
MemoryDim,
AccessPattern,
Frequency,
RecommendedDirection,
FunctionRef,
)
def test_aggregate_kind_4_values() -> None:
@@ -30,4 +33,29 @@ def test_frequency_7_values() -> None:
def test_recommended_direction_4_values() -> None:
"""RecommendedDirection is a Literal with 4 values: componentize, unify, hold, insufficient_data."""
expected = {"componentize", "unify", "hold", "insufficient_data"}
assert set(RecommendedDirection.__args__) == expected
assert set(RecommendedDirection.__args__) == expected
def test_function_ref_4_fields() -> None:
"""FunctionRef has fqname, file, line, role (per spec)."""
ref = FunctionRef(
fqname="src.ai_client.AIClient.send_result",
file="src/ai_client.py",
line=100,
role="producer",
)
assert ref.fqname == "src.ai_client.AIClient.send_result"
assert ref.file == "src/ai_client.py"
assert ref.line == 100
assert ref.role == "producer"
def test_function_ref_frozen() -> None:
"""FunctionRef is frozen (immutability per error_handling.md)."""
ref = FunctionRef(
fqname="src.x.y",
file="src/x.py",
line=1,
role="consumer",
)
with pytest.raises((AttributeError, Exception)) as exc_info:
ref.fqname = "src.z.w"
assert "frozen" in str(exc_info.value).lower() or "cannot assign" in str(exc_info.value).lower()