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.
95 lines
2.6 KiB
Python
95 lines
2.6 KiB
Python
import pytest
|
|
import tempfile
|
|
import os
|
|
from pathlib import Path
|
|
from src import project_manager
|
|
from src.mma import ThinkingSegment
|
|
|
|
|
|
def test_save_and_load_history_with_thinking_segments():
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
project_path = Path(tmpdir) / "test_project"
|
|
project_path.mkdir()
|
|
|
|
project_file = project_path / "test_project.toml"
|
|
project_file.write_text("[project]\nname = 'test'\n")
|
|
|
|
history_data = {
|
|
"entries": [
|
|
{
|
|
"role": "AI",
|
|
"content": "Here's the response",
|
|
"thinking_segments": [
|
|
{"content": "Let me think about this...", "marker": "thinking"}
|
|
],
|
|
"ts": "2026-03-13T10:00:00",
|
|
"collapsed": False,
|
|
},
|
|
{
|
|
"role": "User",
|
|
"content": "Hello",
|
|
"ts": "2026-03-13T09:00:00",
|
|
"collapsed": False,
|
|
},
|
|
]
|
|
}
|
|
|
|
project_manager.save_project(
|
|
{"project": {"name": "test"}}, project_file, disc_data=history_data
|
|
)
|
|
|
|
loaded = project_manager.load_history(project_file)
|
|
|
|
assert "entries" in loaded
|
|
assert len(loaded["entries"]) == 2
|
|
|
|
ai_entry = loaded["entries"][0]
|
|
assert ai_entry["role"] == "AI"
|
|
assert ai_entry["content"] == "Here's the response"
|
|
assert "thinking_segments" in ai_entry
|
|
assert len(ai_entry["thinking_segments"]) == 1
|
|
assert (
|
|
ai_entry["thinking_segments"][0]["content"] == "Let me think about this..."
|
|
)
|
|
|
|
user_entry = loaded["entries"][1]
|
|
assert user_entry["role"] == "User"
|
|
assert "thinking_segments" not in user_entry
|
|
|
|
|
|
def test_entry_to_str_with_thinking():
|
|
entry = {
|
|
"role": "AI",
|
|
"content": "Response text",
|
|
"thinking_segments": [{"content": "Thinking...", "marker": "thinking"}],
|
|
"ts": "2026-03-13T10:00:00",
|
|
}
|
|
result = project_manager.entry_to_str(entry)
|
|
assert "@2026-03-13T10:00:00" in result
|
|
assert "AI:" in result
|
|
assert "Response text" in result
|
|
|
|
|
|
def test_str_to_entry_with_thinking():
|
|
raw = "@2026-03-13T10:00:00\nAI:\nResponse text"
|
|
roles = ["User", "AI", "Vendor API", "System", "Reasoning"]
|
|
result = project_manager.str_to_entry(raw, roles)
|
|
assert result["role"] == "AI"
|
|
assert result["content"] == "Response text"
|
|
assert "ts" in result
|
|
|
|
|
|
def test_clean_nones_removes_thinking():
|
|
entry = {"role": "AI", "content": "Test", "thinking_segments": None, "ts": None}
|
|
cleaned = project_manager.clean_nones(entry)
|
|
assert "thinking_segments" not in cleaned
|
|
assert "ts" not in cleaned
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_save_and_load_history_with_thinking_segments()
|
|
test_entry_to_str_with_thinking()
|
|
test_str_to_entry_with_thinking()
|
|
test_clean_nones_removes_thinking()
|
|
print("All project_manager thinking tests passed!")
|