8f11340b38
Per post_module_taxonomy_de_cruft_20260627 Phase 2 (FR7). Each
'from src.models import X' for a moved class is rewritten to
'from src.<destination> import X':
Ticket, Track, WorkerContext, TrackState, TrackMetadata,
ThinkingSegment, EMPTY_TRACK_STATE -> src.mma
ProjectContext, ProjectMeta, ProjectOutput, ProjectFiles,
ProjectScreenshots, ProjectDiscussion, EMPTY_PROJECT_CONTEXT -> src.project
FileItem, Preset, ContextPreset, ContextFileEntry,
NamedViewPreset -> src.project_files
Tool, ToolPreset -> src.tool_presets
BiasProfile -> src.tool_bias
TextEditorConfig, ExternalEditorConfig,
EMPTY_TEXT_EDITOR_CONFIG -> src.external_editor
Persona -> src.personas
WorkspaceProfile -> src.workspace_manager
MCPServerConfig, MCPConfiguration, VectorStoreConfig,
RAGConfig, load_mcp_config -> src.mcp_client
NOT touched (kept on src.models; Phase 3 or Phase 4 will move them):
GenerateRequest, ConfirmRequest, DEFAULT_TOOL_CATEGORIES, Metadata, PROVIDERS
Migration was performed by the one-time script
scripts/tier2/artifacts/post_module_taxonomy_de_cruft_20260627/migrate_imports.py
which uses a class-to-module map and re.sub() to rewrite each
'from src.models import X' line.
Total: 85 import lines rewritten across 71 files.
Note: this commit depends on the v2 SHIPPED work
(origin/tier2/module_taxonomy_refactor_20260627) being merged into
this branch NEXT. On master (without the v2 SHIPPED commits), the
destination modules do not exist and these imports would fail.
57 lines
2.2 KiB
Python
57 lines
2.2 KiB
Python
import pytest
|
|
from src.project_files import FileItem
|
|
|
|
def test_file_item_custom_slices_serialization_with_annotations():
|
|
# Test that FileItem correctly serializes custom_slices with tag and comment.
|
|
slices = [
|
|
{'start_line': 1, 'end_line': 10, 'tag': 'init', 'comment': 'Constructor logic'},
|
|
{'start_line': 20, 'end_line': 30, 'tag': 'process', 'comment': 'Main processing loop'}
|
|
]
|
|
item = FileItem(path='src/app.py', custom_slices=slices)
|
|
|
|
serialized = item.to_dict()
|
|
assert 'custom_slices' in serialized
|
|
assert len(serialized['custom_slices']) == 2
|
|
assert serialized['custom_slices'][0]['tag'] == 'init'
|
|
assert serialized['custom_slices'][0]['comment'] == 'Constructor logic'
|
|
assert serialized['custom_slices'][1]['tag'] == 'process'
|
|
assert serialized['custom_slices'][1]['comment'] == 'Main processing loop'
|
|
|
|
def test_file_item_custom_slices_deserialization_with_annotations():
|
|
# Test that FileItem correctly deserializes custom_slices with tag and comment.
|
|
data = {
|
|
'path': 'src/app.py',
|
|
'custom_slices': [
|
|
{'start_line': 5, 'end_line': 15, 'tag': 'helper', 'comment': 'Utility function'},
|
|
{'start_line': 40, 'end_line': 50} # Missing optional fields
|
|
]
|
|
}
|
|
|
|
item = FileItem.from_dict(data)
|
|
assert len(item.custom_slices) == 2
|
|
|
|
# First slice has annotations
|
|
assert item.custom_slices[0]['tag'] == 'helper'
|
|
assert item.custom_slices[0]['comment'] == 'Utility function'
|
|
|
|
# Second slice should have default None or empty string for optional fields
|
|
# This is where it will likely FAIL if we haven't updated from_dict to inject defaults
|
|
assert 'tag' in item.custom_slices[1]
|
|
assert 'comment' in item.custom_slices[1]
|
|
assert item.custom_slices[1]['tag'] is None
|
|
assert item.custom_slices[1]['comment'] is None
|
|
|
|
def test_file_item_custom_slices_round_trip_annotations():
|
|
# Test a full round trip of FileItem with slice annotations.
|
|
item = FileItem(path='src/test.py', custom_slices=[
|
|
{'start_line': 1, 'end_line': 5, 'tag': 'test', 'comment': 'Unit test case'}
|
|
])
|
|
|
|
serialized = item.to_dict()
|
|
deserialized = FileItem.from_dict(serialized)
|
|
|
|
assert deserialized.custom_slices == item.custom_slices
|
|
assert deserialized.custom_slices[0]['tag'] == 'test'
|
|
assert deserialized.custom_slices[0]['comment'] == 'Unit test case'
|
|
|