commit remaining modified project files
This commit is contained in:
+65
-1
@@ -1,5 +1,6 @@
|
||||
"""Unit tests for plan generator."""
|
||||
|
||||
import json
|
||||
import pytest
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
@@ -12,7 +13,7 @@ from vlm.models import (
|
||||
SeriesIdentity,
|
||||
VideoFile,
|
||||
)
|
||||
from vlm.planner import generate_plan
|
||||
from vlm.planner import generate_plan, load_plan
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -1255,3 +1256,66 @@ def test_series_rejected_by_review_generates_noop(config):
|
||||
plan = generate_plan([(video_file, identity)], config)
|
||||
assert plan.operations[0].operation_type == "no-op"
|
||||
assert "rejected" in plan.operations[0].reason.lower()
|
||||
|
||||
|
||||
def test_save_and_load_plan_validates_schema(tmp_path):
|
||||
"""Saved plan artifacts should round-trip through schema validation."""
|
||||
plan = ExecutionPlan(
|
||||
plan_id="plan-123",
|
||||
created_at=datetime(2026, 4, 2, 12, 0, tzinfo=timezone.utc),
|
||||
operations=[
|
||||
FileOperation(
|
||||
operation_type="move",
|
||||
source_path=Path("/mnt/nas/videos/movie/source.mkv"),
|
||||
destination_path=Path("/mnt/nas/videos/movie/target.mkv"),
|
||||
reason="move movie",
|
||||
has_conflict=False,
|
||||
)
|
||||
],
|
||||
summary={"move": 1, "rename": 0, "noop": 0, "delete": 0},
|
||||
summary_by_reason={"move movie": 1},
|
||||
human_summary="计划已生成",
|
||||
metadata={"analysis_source": "analysis.json"},
|
||||
)
|
||||
|
||||
output_path = tmp_path / "plan.json"
|
||||
from vlm.planner import save_plan
|
||||
|
||||
save_plan(plan, output_path)
|
||||
loaded = load_plan(output_path)
|
||||
|
||||
assert loaded.plan_id == plan.plan_id
|
||||
assert loaded.operations[0].source_path == plan.operations[0].source_path
|
||||
assert loaded.operations[0].destination_path == plan.operations[0].destination_path
|
||||
assert loaded.summary == plan.summary
|
||||
assert loaded.summary_by_reason == plan.summary_by_reason
|
||||
assert loaded.human_summary == plan.human_summary
|
||||
assert loaded.metadata == plan.metadata
|
||||
|
||||
|
||||
def test_load_plan_rejects_invalid_schema(tmp_path):
|
||||
"""Invalid plan artifacts should fail validation before deserialization."""
|
||||
invalid_path = tmp_path / "invalid-plan.json"
|
||||
invalid_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"vlm_schema_version": "1.0",
|
||||
"plan_id": "plan-123",
|
||||
"created_at": "2026-04-02T12:00:00+00:00",
|
||||
"operations": [
|
||||
{
|
||||
"operation_type": "move",
|
||||
"source_path": "/mnt/nas/videos/movie/source.mkv",
|
||||
"destination_path": "/mnt/nas/videos/movie/target.mkv",
|
||||
"has_conflict": False,
|
||||
}
|
||||
],
|
||||
"summary": {"move": 1},
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="plan JSON.operations\\[0\\]\\.reason"):
|
||||
load_plan(invalid_path)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user