refactor(src): Phase 10.2 batch 3 - project_manager + orchestrator_pm Result migration

project_manager.py (3 sites):
- get_all_tracks returns list[dict[str, Any]] where each dict now
  has an 'errors' field (list[ErrorInfo]) capturing per-track
  metadata recovery. The 3 SILENT_SWALLOW sites (state.from_dict,
  metadata.json, plan.md) now append to this list instead of
  silently passing.

orchestrator_pm.py (2 sites):
- get_track_history_summary returns Result[str]. The 2 SILENT_SWALLOW
  sites (metadata.json + spec.md reads) append to a scan_errors list
  that's threaded through the Result.

Tests updated to check result.ok and use result.data.
This commit is contained in:
ed
2026-06-17 22:33:57 -04:00
parent a7d8e2adfd
commit 89ce7ad770
3 changed files with 38 additions and 25 deletions
+16 -9
View File
@@ -332,16 +332,22 @@ def get_all_tracks(base_dir: Union[str, Path] = ".") -> list[dict[str, Any]]:
and 'progress' (0.0 to 1.0).
Handles missing or malformed metadata.json or state.toml by falling back
to available info or defaults.
Each returned dict includes an 'errors' list (list[ErrorInfo]) for any
per-track metadata recovery that occurred. Callers can ignore the errors
field for display purposes; the metadata is best-effort.
[C: tests/test_project_manager_tracks.py:test_get_all_tracks_empty, tests/test_project_manager_tracks.py:test_get_all_tracks_malformed, tests/test_project_manager_tracks.py:test_get_all_tracks_with_metadata_json, tests/test_project_manager_tracks.py:test_get_all_tracks_with_state, tests/test_project_paths.py:test_get_all_tracks_project_specific]
"""
tracks_dir = paths.get_tracks_dir(project_path=str(base_dir))
if not tracks_dir.exists(): return []
from src.result_types import ErrorInfo, ErrorKind
results: list[dict[str, Any]] = []
for entry in tracks_dir.iterdir():
if not entry.is_dir(): continue
track_id = entry.name
track_errors: list[dict[str, Any]] = []
track_info: dict[str, Any] = {
"id": track_id,
"title": track_id,
@@ -351,7 +357,7 @@ def get_all_tracks(base_dir: Union[str, Path] = ".") -> list[dict[str, Any]]:
"progress": 0.0
}
state_found = False
try:
state = load_track_state(track_id, base_dir)
if state:
@@ -363,8 +369,8 @@ def get_all_tracks(base_dir: Union[str, Path] = ".") -> list[dict[str, Any]]:
track_info["total"] = progress["total"]
track_info["progress"] = progress["percentage"] / 100.0
state_found = True
except (OSError, AttributeError, KeyError, TypeError):
pass
except (OSError, AttributeError, KeyError, TypeError) as e:
track_errors.append(ErrorInfo(kind=ErrorKind.INTERNAL, message=str(e), source=f"project_manager.get_all_tracks[{track_id}].state", original=e))
if not state_found:
metadata_file = entry / "metadata.json"
@@ -375,8 +381,8 @@ def get_all_tracks(base_dir: Union[str, Path] = ".") -> list[dict[str, Any]]:
track_info["id"] = data.get("id", data.get("track_id", track_id))
track_info["title"] = data.get("title", data.get("name", data.get("description", track_id)))
track_info["status"] = data.get("status", "unknown")
except (OSError, json.JSONDecodeError, UnicodeDecodeError):
pass
except (OSError, json.JSONDecodeError, UnicodeDecodeError) as e:
track_errors.append(ErrorInfo(kind=ErrorKind.INTERNAL, message=str(e), source=f"project_manager.get_all_tracks[{track_id}].metadata", original=e))
if track_info["total"] == 0:
plan_file = entry / "plan.md"
@@ -390,9 +396,10 @@ def get_all_tracks(base_dir: Union[str, Path] = ".") -> list[dict[str, Any]]:
track_info["complete"] = len(completed_tasks)
if track_info["total"] > 0:
track_info["progress"] = float(track_info["complete"]) / track_info["total"]
except (OSError, UnicodeDecodeError, re.error):
pass
except (OSError, UnicodeDecodeError, re.error) as e:
track_errors.append(ErrorInfo(kind=ErrorKind.INTERNAL, message=str(e), source=f"project_manager.get_all_tracks[{track_id}].plan", original=e))
track_info["errors"] = track_errors
results.append(track_info)
return results