From 95f8192fdc7c70c0b7a8eaa3672ff7ec9a6e0970 Mon Sep 17 00:00:00 2001 From: Juan Date: Wed, 26 Aug 2026 14:34:50 +0200 Subject: [PATCH] Treat a missing partial index as empty when merging Quarto indexes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit merge_file read the partial index unconditionally, but Quarto only writes listings.json when a rendered page declares a listing. A targeted preview render of pages carrying no card listing therefore produces no partial index, and the merge died with FileNotFoundError before the preview was uploaded — so the check went red on exactly the kind of change the targeted path exists for. No listings changed means nothing to merge: fall back to an empty list and write the staging base out unchanged. The new test reproduces the production traceback and fails without this change. Co-Authored-By: Claude Opus 5 (1M context) --- .github/scripts/merge_quarto_indexes.py | 5 ++++- .github/scripts/test_merge_quarto_indexes.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/scripts/merge_quarto_indexes.py b/.github/scripts/merge_quarto_indexes.py index cc574a7fff..fc1a504b40 100644 --- a/.github/scripts/merge_quarto_indexes.py +++ b/.github/scripts/merge_quarto_indexes.py @@ -27,7 +27,10 @@ def merge_items( def merge_file(base_path: Path, partial_path: Path, key: str) -> None: base = json.loads(base_path.read_text()) - partial = json.loads(partial_path.read_text()) + # Quarto only writes listings.json when a rendered page declares a listing, + # so a targeted render of pages that carry none produces no partial index. + # That is a normal outcome, not a failure: nothing changed, nothing to merge. + partial = json.loads(partial_path.read_text()) if partial_path.exists() else [] if not isinstance(base, list) or not isinstance(partial, list): raise ValueError("Quarto indexes must contain JSON arrays") partial_path.write_text( diff --git a/.github/scripts/test_merge_quarto_indexes.py b/.github/scripts/test_merge_quarto_indexes.py index f2b450ecfd..661d793cdb 100644 --- a/.github/scripts/test_merge_quarto_indexes.py +++ b/.github/scripts/test_merge_quarto_indexes.py @@ -40,6 +40,20 @@ def test_merge_file_updates_partial_path(self): ], ) + def test_absent_partial_leaves_base_as_the_merged_index(self): + """A targeted render of pages with no listing writes no partial index.""" + with tempfile.TemporaryDirectory() as directory: + base_path = Path(directory) / "base.json" + partial_path = Path(directory) / "partial.json" + base_path.write_text(json.dumps([{"listing": "/old", "items": ["a"]}])) + + merge_file(base_path, partial_path, "listing") + + self.assertEqual( + json.loads(partial_path.read_text()), + [{"listing": "/old", "items": ["a"]}], + ) + def test_missing_key_is_rejected(self): with self.assertRaises(ValueError): merge_items([], [{"text": "missing object id"}], "objectID")