From ff3fca6a94a6b7dcad35c25b29178a307bfd9dfa Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 25 Nov 2026 06:07:32 -0500 Subject: [PATCH] test(7836): the client's link states are pinned to what a read returns Co-Authored-By: Claude Opus 5.5 --- src/grimoire/services/lesson_rules.py | 8 ++++++-- tests/test_lesson_rule_link_ui.py | 5 ++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/grimoire/services/lesson_rules.py b/src/grimoire/services/lesson_rules.py index 929dce89..8662a182 100644 --- a/src/grimoire/services/lesson_rules.py +++ b/src/grimoire/services/lesson_rules.py @@ -64,6 +64,10 @@ _REMOVED_NOTE = "removed from the lesson's rules by an update" # of that answer's reason. _NO_RULE_NOTE = "no rule fits: " +# The link states a read returns, in the order it lists them: a judgment, +# never a suggestion. +READ_STATES = (CONFIRMED, REJECTED) + # What `rule_judgment` reads on a lesson payload — the three answers. LINKED, NO_RULE, UNJUDGED = "linked", "no_rule", "unjudged" @@ -279,7 +283,7 @@ async def rules_for_lessons(user_id: int, lesson_ids) -> dict[int, list[dict]]: out: dict[int, list[dict]] = {i: [] for i in ids} if not ids: return out - order = {CONFIRMED: 0, REJECTED: 1} + order = {s: n for n, s in enumerate(READ_STATES)} async with async_session() as session: rows = (await session.execute( select(LessonRuleLink, Rule) @@ -306,7 +310,7 @@ async def lessons_for_rule(user_id: int, rule_id: int) -> list[dict]: """ from grimoire.services.access import readable_notes_clause - order = {CONFIRMED: 0, REJECTED: 1} + order = {s: n for n, s in enumerate(READ_STATES)} async with async_session() as session: rows = (await session.execute( select(LessonRuleLink, Note) diff --git a/tests/test_lesson_rule_link_ui.py b/tests/test_lesson_rule_link_ui.py index 522d7717..db394b3e 100644 --- a/tests/test_lesson_rule_link_ui.py +++ b/tests/test_lesson_rule_link_ui.py @@ -20,7 +20,6 @@ import inspect import re from pathlib import Path -from grimoire.models.lesson_rule_link import LINK_STATES from grimoire.services import lesson_rules as links_svc from grimoire.services.access import PERMISSION_RANK @@ -48,8 +47,8 @@ def test_the_client_judgment_union_is_the_services_three_answers(): } -def test_the_client_link_states_are_the_models(): - assert _union(_read("api/lessons.ts"), "LinkState") == set(LINK_STATES) +def test_the_client_link_states_are_the_ones_a_read_returns(): + assert _union(_read("api/lessons.ts"), "LinkState") == set(links_svc.READ_STATES) def test_the_lesson_page_answers_all_three_judgments():