Private
Public Access
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:
@@ -9,6 +9,7 @@ postfix DSL + markdown + prefix tree text. See
|
|||||||
conductor/tracks/code_path_audit_20260607/spec_v2.md.
|
conductor/tracks/code_path_audit_20260607/spec_v2.md.
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
from dataclasses import dataclass
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
|
|
||||||
AggregateKind = Literal[
|
AggregateKind = Literal[
|
||||||
@@ -52,3 +53,10 @@ RecommendedDirection = Literal[
|
|||||||
"hold",
|
"hold",
|
||||||
"insufficient_data",
|
"insufficient_data",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class FunctionRef:
|
||||||
|
fqname: str
|
||||||
|
file: str
|
||||||
|
line: int
|
||||||
|
role: str
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
"""Tests for src.code_path_audit v2 - Phase 1 (data model)."""
|
"""Tests for src.code_path_audit v2 - Phase 1 (data model)."""
|
||||||
|
from __future__ import annotations
|
||||||
|
import pytest
|
||||||
from src.code_path_audit import (
|
from src.code_path_audit import (
|
||||||
AggregateKind,
|
AggregateKind,
|
||||||
MemoryDim,
|
MemoryDim,
|
||||||
AccessPattern,
|
AccessPattern,
|
||||||
Frequency,
|
Frequency,
|
||||||
RecommendedDirection,
|
RecommendedDirection,
|
||||||
|
FunctionRef,
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_aggregate_kind_4_values() -> None:
|
def test_aggregate_kind_4_values() -> None:
|
||||||
@@ -31,3 +34,28 @@ def test_recommended_direction_4_values() -> None:
|
|||||||
"""RecommendedDirection is a Literal with 4 values: componentize, unify, hold, insufficient_data."""
|
"""RecommendedDirection is a Literal with 4 values: componentize, unify, hold, insufficient_data."""
|
||||||
expected = {"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()
|
||||||
Reference in New Issue
Block a user