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")