Skip to content

Commit 31d23c9

Browse files
committed
fix: enforce deterministic path ordering
1 parent 79823da commit 31d23c9

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

_includes/catalog-grid.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
{% assign ordered_paths = site.data.resources.catalog.paths | sort: "order" %}
12
<nav class="path-grid" aria-label="{% if page.lang == 'zh-CN' %}学习路径{% else %}Learning paths{% endif %}">
2-
{% for path in site.data.resources.catalog.paths %}
3+
{% for path in ordered_paths %}
34
{% assign path_resources = include.resources | where: "path", path.id %}
45
<a class="path-card" href="#{{ path.id }}">
56
<span class="path-number">0{{ path.order }}</span>
@@ -16,7 +17,7 @@
1617
{% endfor %}
1718
</nav>
1819

19-
{% for path in site.data.resources.catalog.paths %}
20+
{% for path in ordered_paths %}
2021
{% assign path_resources = include.resources | where: "path", path.id %}
2122
<section class="path-section" id="{{ path.id }}" aria-labelledby="{{ path.id }}-title">
2223
<header class="section-heading">

tests/test_catalog.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ def test_resource_ids_and_urls_reject_unsafe_forms(valid_catalog: dict) -> None:
6262
assert {"invalid-id", "url-credentials"} <= codes
6363

6464

65+
def test_path_orders_must_be_consecutive(valid_catalog: dict) -> None:
66+
data = deepcopy(valid_catalog)
67+
data["catalog"]["paths"][-1]["order"] = 5
68+
69+
codes = {
70+
issue.code for issue in validate_catalog(data, today=date(2026, 8, 31))
71+
}
72+
73+
assert "order-parity" in codes
74+
75+
6576
@pytest.mark.parametrize(
6677
("url", "expected"),
6778
[

tools/catalog.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,19 @@ def validate_catalog(
263263
)
264264
)
265265

266+
expected_path_orders = set(range(1, len(EXPECTED_PATH_IDS) + 1))
267+
if path_orders != expected_path_orders:
268+
missing = sorted(expected_path_orders - path_orders)
269+
extra = sorted(path_orders - expected_path_orders)
270+
issues.append(
271+
ValidationIssue(
272+
"order-parity",
273+
"$.catalog.paths",
274+
f"expected consecutive path orders 1-{len(EXPECTED_PATH_IDS)}; "
275+
f"missing={missing}, extra={extra}",
276+
)
277+
)
278+
266279
resources = data.get("resources")
267280
if not isinstance(resources, list):
268281
issues.append(

0 commit comments

Comments
 (0)