feat: auto-resolve missing managed sample files

parent 19729cfe
...@@ -144,6 +144,32 @@ def test_ensure_sample_file_returns_existing_path_without_download(tmp_path, mon ...@@ -144,6 +144,32 @@ def test_ensure_sample_file_returns_existing_path_without_download(tmp_path, mon
assert calls == [] assert calls == []
def test_ensure_sample_file_downloads_missing_managed_default(tmp_path, monkeypatch):
managed_path = tmp_path / "samples" / "question-audio.wav"
downloaded = []
def fake_download(path):
downloaded.append(path)
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(b"audio")
return path
monkeypatch.setattr(
"tools.manual_multimodal_test_client.SAMPLE_URLS",
{managed_path.as_posix(): "https://example.invalid/question-audio.wav"},
)
monkeypatch.setattr(
"tools.manual_multimodal_test_client.download_default_sample",
fake_download,
)
result = ensure_sample_file(str(managed_path), "--audio-file")
assert result == managed_path
assert downloaded == [managed_path]
assert managed_path.read_bytes() == b"audio"
def test_build_request_spec_for_llm_uses_chat_completions_payload(tmp_path): def test_build_request_spec_for_llm_uses_chat_completions_payload(tmp_path):
config = { config = {
"mode": "llm", "mode": "llm",
......
...@@ -106,8 +106,19 @@ def download_default_sample(path: Path) -> Path: ...@@ -106,8 +106,19 @@ def download_default_sample(path: Path) -> Path:
return path return path
def _managed_sample_key(path: Path) -> str:
return path.as_posix()
def ensure_sample_file(path_value: str | None, flag_name: str) -> Path: def ensure_sample_file(path_value: str | None, flag_name: str) -> Path:
return _require_file(path_value, flag_name) if not path_value:
raise FileNotFoundError(f"Missing required file. Supply {flag_name}.")
path = Path(path_value)
if path.exists():
return path
if _managed_sample_key(path) in SAMPLE_URLS:
return download_default_sample(path)
raise FileNotFoundError(f"File not found: {path}. Supply {flag_name}.")
def build_request_spec(config: dict) -> dict: def build_request_spec(config: dict) -> dict:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment