From 991db29e273c72e6be5a91527f4b5f6603736d48 Mon Sep 17 00:00:00 2001 From: gilesb Date: Mon, 12 Jan 2026 12:27:05 +0000 Subject: [PATCH] Fix input preview hash -> cid key mismatch Template uses inp.cid and input.cid but router created previews with 'hash' key. Fixed both input_previews and run_inputs to use 'cid'. Co-Authored-By: Claude Opus 4.5 --- app/routers/runs.py | 4 ++-- tests/test_run_artifacts.py | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/routers/runs.py b/app/routers/runs.py index 0ca5f81..198fdd6 100644 --- a/app/routers/runs.py +++ b/app/routers/runs.py @@ -278,7 +278,7 @@ async def get_run( except Exception: pass run_inputs.append({ - "hash": input_hash, + "cid": input_hash, "name": f"Input {i + 1}", "media_type": media_type, }) @@ -407,7 +407,7 @@ async def list_runs( inputs = run.get("inputs", []) if isinstance(inputs, list): for input_hash in inputs[:3]: - preview = {"hash": input_hash, "media_type": None} + preview = {"cid": input_hash, "media_type": None} try: cache_path = cache_manager.get_by_cid(input_hash) if cache_path and cache_path.exists(): diff --git a/tests/test_run_artifacts.py b/tests/test_run_artifacts.py index 4591d95..e6042c4 100644 --- a/tests/test_run_artifacts.py +++ b/tests/test_run_artifacts.py @@ -36,6 +36,33 @@ class TestCacheNotFoundTemplate: "Route should pass cid=cid to not_found.html template" +class TestInputPreviewsDataStructure: + """Tests for input_previews dict keys matching template expectations.""" + + def test_run_card_template_expects_inp_cid(self) -> None: + """Run card template uses inp.cid for input previews.""" + path = Path('/home/giles/art/art-celery/app/templates/runs/_run_card.html') + content = path.read_text() + + assert 'inp.cid' in content, \ + "Run card template should use inp.cid for input previews" + + def test_input_previews_use_cid_key(self) -> None: + """ + Regression test: input_previews must use 'cid' key not 'hash'. + + Bug: Router created input_previews with 'hash' key but template expected 'cid'. + """ + path = Path('/home/giles/art/art-celery/app/routers/runs.py') + content = path.read_text() + + # Should have: "cid": input_hash, not "hash": input_hash + assert '"cid": input_hash' in content, \ + "input_previews should use 'cid' key" + assert '"hash": input_hash' not in content, \ + "input_previews should not use 'hash' key (template expects 'cid')" + + class TestArtifactDataStructure: """Tests for artifact dict keys matching template expectations."""