1680182953
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.
61 lines
2.4 KiB
Python
61 lines
2.4 KiB
Python
"""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:
|
|
"""AggregateKind is a Literal with 4 values: typealias, dataclass, candidate_dataclass, builtin."""
|
|
expected = {"typealias", "dataclass", "candidate_dataclass", "builtin"}
|
|
assert set(AggregateKind.__args__) == expected
|
|
|
|
def test_memory_dim_7_values() -> None:
|
|
"""MemoryDim is a Literal with 7 values: curation, discussion, rag, knowledge, config, control, unknown."""
|
|
expected = {"curation", "discussion", "rag", "knowledge", "config", "control", "unknown"}
|
|
assert set(MemoryDim.__args__) == expected
|
|
|
|
def test_access_pattern_5_values() -> None:
|
|
"""AccessPattern is a Literal with 5 values: whole_struct, field_by_field, hot_cold_split, bulk_batched, mixed."""
|
|
expected = {"whole_struct", "field_by_field", "hot_cold_split", "bulk_batched", "mixed"}
|
|
assert set(AccessPattern.__args__) == expected
|
|
|
|
def test_frequency_7_values() -> None:
|
|
"""Frequency is a Literal with 7 values: hot, per_turn, per_discussion, per_request, cold, init, unknown."""
|
|
expected = {"hot", "per_turn", "per_discussion", "per_request", "cold", "init", "unknown"}
|
|
assert set(Frequency.__args__) == expected
|
|
|
|
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
|
|
|
|
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() |