Private
Public Access
0
0
Files
manual_slop/tests/test_tool_definition.py
T
ed bacddc8549 feat(type_aliases): add per-aggregate dataclasses for metadata_promotion_20260624
TIER-2 READ AGENTS.md conductor/workflow.md conductor/edit_workflow.md conductor/tier2/githooks/forbidden-files.txt conductor/tracks/tier2_leak_prevention_20260620/spec.md conductor/code_styleguides/data_oriented_design.md conductor/code_styleguides/error_handling.md conductor/code_styleguides/type_aliases.md before Phase 0 Tasks 0.1, 0.2, 0.4.

Phase 0 of metadata_promotion_20260624. 11 NEW per-aggregate dataclasses added to src/type_aliases.py (CommsLogEntry, HistoryMessage, FileItem, ToolDefinition, SessionInsights, DiscussionSettings, CustomSlice, MMAUsageStats, ProviderPayload, UIPanelConfig, PathInfo) + RAGChunk added to src/rag_engine.py. Metadata: TypeAlias = dict[str, Any] preserved unchanged as the catch-all for collapsed codepaths. Each dataclass has paired to_dict()/from_dict() methods.

11 regression-guard test files created with 5-7 tests each (~70 tests total). All tests PASS.

The existing tests/test_type_aliases.py was updated to reflect the NEW design (CommsLogEntry etc. are now classes, not aliases to Metadata).

Conventions: 1-space indentation, CRLF preserved, no comments.
2026-06-25 14:47:18 -04:00

56 lines
1.5 KiB
Python

"""Tests for ToolDefinition in src/type_aliases.py
Per-aggregate dataclass regression-guard for the metadata_promotion_20260624 track.
CONVENTION: 1-space indentation. NO COMMENTS.
"""
from __future__ import annotations
from dataclasses import FrozenInstanceError
import pytest
from src.type_aliases import ToolDefinition
def test_constructor_with_kwargs() -> None:
td = ToolDefinition(name="read_file", description="read a file", auto_start=True)
assert td.name == "read_file"
assert td.description == "read a file"
assert td.auto_start is True
def test_field_access() -> None:
td = ToolDefinition(name="x", parameters={"type": "object"})
assert td.parameters == {"type": "object"}
def test_frozen_raises_on_mutation() -> None:
td = ToolDefinition()
with pytest.raises(FrozenInstanceError):
td.name = "x"
def test_to_dict_from_dict_roundtrip() -> None:
td = ToolDefinition(name="f", description="d", auto_start=True, parameters={"k": "v"})
restored = ToolDefinition.from_dict(td.to_dict())
assert restored == td
def test_from_dict_filters_unknown_keys() -> None:
raw = {"name": "x", "extra_unknown_key": "ignored"}
td = ToolDefinition.from_dict(raw)
assert td.name == "x"
def test_default_values() -> None:
td = ToolDefinition()
assert td.name == ""
assert td.description == ""
assert td.parameters == {}
assert td.auto_start is False
def test_hashability_skipped_unhashable_dict_field() -> None:
td = ToolDefinition()
assert td.parameters == {}