From a1f75a40c9af1929d5d2cd3aca32fc0208b6e6bc Mon Sep 17 00:00:00 2001 From: nesquena-hermes Date: Fri, 3 Jul 2026 19:46:56 +0000 Subject: [PATCH] fix(test): assert branch-guard on the extracted helper, not stale inline text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test_branch_endpoint_consults_foreign_session_guard_on_missing_sidecar grepped the inline handler block for _claim_or_synthesize_cli_session + not_claimable + 403 — but #5449 extracted that logic into the _load_branch_source_or_refuse helper, leaving only a dead comment carrying the old text to satisfy the grep. Point the test at the helper so it asserts real post-refactor structure instead of a comment. --- tests/test_465_session_branching.py | 32 ++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tests/test_465_session_branching.py b/tests/test_465_session_branching.py index 2513ed65..7d986d81 100644 --- a/tests/test_465_session_branching.py +++ b/tests/test_465_session_branching.py @@ -169,7 +169,13 @@ def test_branch_endpoint_validates_session_id(): def test_branch_endpoint_consults_foreign_session_guard_on_missing_sidecar(): - """Missing sidecars should classify foreign read-only sessions before 404ing.""" + """Missing sidecars should classify foreign read-only sessions before 404ing. + + The classification logic was extracted from the inline handler into the + ``_load_branch_source_or_refuse`` helper (#5449). Assert the handler + delegates to it, and that the helper carries the real not_claimable→403 + provenance logic — not a stale inline copy. + """ src = _read('api/routes.py') branch_match = re.search( r'parsed\.path == "/api/session/branch"(.*?)(?=\n if parsed\.path|$)', @@ -177,12 +183,24 @@ def test_branch_endpoint_consults_foreign_session_guard_on_missing_sidecar(): ) assert branch_match, "Could not find /api/session/branch handler block" block = branch_match.group(1) - assert '_claim_or_synthesize_cli_session(body["session_id"])' in block, \ - "Branch handler should classify missing-sidecar foreign sessions before returning" - assert 'if _reason == "not_claimable":' in block, \ - "Branch handler should branch on not_claimable foreign ownership" - assert 'return bad(handler, "Read-only sessions cannot be branched from WebUI", 403)' in block, \ - "Branch handler should return a provenance-correct 403 for read-only foreign sessions" + assert '_load_branch_source_or_refuse(handler, body["session_id"])' in block, \ + "Branch handler should delegate source-load/refusal to the shared helper" + + # The helper itself must carry the foreign-session classification + 403. + helper_match = re.search( + r'def _load_branch_source_or_refuse\(.*?\)(.*?)(?=\ndef )', + src, re.DOTALL + ) + assert helper_match, "Could not find _load_branch_source_or_refuse helper" + helper = helper_match.group(1) + assert '_claim_or_synthesize_cli_session(sid)' in helper, \ + "Helper should classify missing-sidecar foreign sessions before returning" + assert 'if _reason == "not_claimable":' in helper, \ + "Helper should branch on not_claimable foreign ownership" + assert 'return bad(handler, "Read-only sessions cannot be branched from WebUI", 403)' in helper \ + or ('bad(handler, "Read-only sessions cannot be branched from WebUI", 403)' in helper + and 'return None' in helper), \ + "Helper should return a provenance-correct 403 for read-only foreign sessions" def test_branch_endpoint_returns_new_session_id():