Add inspect-stage1 debug command
This commit is contained in:
@@ -1,21 +1,107 @@
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from tgvideo_check.cli import app
|
||||
from tgvideo_check.ffmpeg_runner import FfmpegExecutionResult
|
||||
from tgvideo_check.ffprobe_runner import ProbeExecutionResult
|
||||
from tgvideo_check.models import FileCandidate
|
||||
from tgvideo_check.store import ScanStore
|
||||
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
|
||||
def _make_candidate(path: Path, *, order: int, size: int = 10, mtime_ns: int = 100) -> FileCandidate:
|
||||
path.write_bytes(b"x" * size)
|
||||
return FileCandidate(
|
||||
path=path,
|
||||
size=size,
|
||||
mtime_ns=mtime_ns,
|
||||
extension=path.suffix.lower().lstrip("."),
|
||||
discovery_order=order,
|
||||
)
|
||||
|
||||
|
||||
def test_help_shows_scan_command() -> None:
|
||||
result = runner.invoke(app, ["--help"])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "scan" in result.stdout
|
||||
assert "verify-stage2" in result.stdout
|
||||
assert "inspect-stage1" in result.stdout
|
||||
|
||||
|
||||
def test_inspect_stage1_command_reports_pending_stage1_probe_rows(tmp_path: Path) -> None:
|
||||
store = ScanStore(tmp_path / "scan_state.db")
|
||||
store.initialize()
|
||||
run_id = store.create_run(profile="tg-hdd", root_paths=(tmp_path,))
|
||||
|
||||
candidate = _make_candidate(tmp_path / "broken.mp4", order=0)
|
||||
[stored] = store.upsert_files(run_id, [candidate])
|
||||
store.record_stage1_result(
|
||||
stored.file_id,
|
||||
exit_code=1,
|
||||
stdout_text='{\n',
|
||||
stderr_text="moov atom not found",
|
||||
elapsed_ms=12,
|
||||
)
|
||||
|
||||
result = runner.invoke(
|
||||
app,
|
||||
[
|
||||
"inspect-stage1",
|
||||
"--db",
|
||||
str(store.db_path),
|
||||
],
|
||||
)
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert f"Stage1 inspect: run_id={run_id} mode=pending_only matched=1" in result.stdout
|
||||
assert "path=" in result.stdout
|
||||
assert "broken.mp4" in result.stdout
|
||||
assert "stdout_len=2" in result.stdout
|
||||
assert r"stdout_head={\n" in result.stdout
|
||||
assert "stderr_head=moov atom not found" in result.stdout
|
||||
|
||||
|
||||
def test_inspect_stage1_command_can_show_recent_rows_with_all_flag(tmp_path: Path) -> None:
|
||||
store = ScanStore(tmp_path / "scan_state.db")
|
||||
store.initialize()
|
||||
run_id = store.create_run(profile="tg-hdd", root_paths=(tmp_path,))
|
||||
|
||||
candidate = _make_candidate(tmp_path / "passed.avi", order=0)
|
||||
[stored] = store.upsert_files(run_id, [candidate])
|
||||
store.record_stage1_result(
|
||||
stored.file_id,
|
||||
exit_code=0,
|
||||
stdout_text='{"format":{"format_name":"avi"}}',
|
||||
stderr_text="soft warning",
|
||||
elapsed_ms=8,
|
||||
)
|
||||
store.record_stage1_status(
|
||||
stored.file_id,
|
||||
stage1_status="passed_stage1",
|
||||
final_status="passed_stage1",
|
||||
reason_code="passed_stage1",
|
||||
)
|
||||
|
||||
result = runner.invoke(
|
||||
app,
|
||||
[
|
||||
"inspect-stage1",
|
||||
"--db",
|
||||
str(store.db_path),
|
||||
"--all",
|
||||
],
|
||||
)
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert f"Stage1 inspect: run_id={run_id} mode=all matched=1" in result.stdout
|
||||
assert "stage1_status=passed_stage1" in result.stdout
|
||||
assert "reason_code=passed_stage1" in result.stdout
|
||||
assert "stderr_head=soft warning" in result.stdout
|
||||
|
||||
|
||||
def test_scan_command_processes_stage1_results_and_exports_reports(
|
||||
|
||||
Reference in New Issue
Block a user