Skip to content

Commit 35751a0

Browse files
e2e: 'released' means no LIVE claim, not an absent state file
just e2e on db0eefe: 9 failed / 586 passed / 20 skipped of 615. All nine polled or asserted 'not state.study_session_id' after a web ending. Since 10a38eb (plan 5, larger #1) a web release keeps the saved mode=ended state file so the dashboard's summary view can render from it -- exactly the assertion lane R predicted would be 'wrong by design' in its log. Every consumer already reads an ended id as no session: _render.py:29, session_state.has_active_session / _claim_exists, components.js:1090,3568, session-timer.js:279. The nine sites now use the same predicate (a shared _live() helper in the two Python files; the JS predicates inline), and the abandon-mid-flight test pins the kept record truthfully (mode=ended, purpose=planning) while the page-level assertion keeps guarding that no LIVE planning label survives. The nine pass against the real server (9 passed in 47 s); the predicate still rejects an id whose mode is not ended, so a session that genuinely failed to release still fails them.
1 parent db0eefe commit 35751a0

4 files changed

Lines changed: 42 additions & 11 deletions

File tree

‎packages/studyloop/tests/e2e/test_ghostty_live_session_journey.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,10 +710,13 @@ def test_refresh_recovers_the_engine_and_allows_a_fresh_session(
710710
after = live_page.evaluate(
711711
"async () => (await fetch('/api/session/state', { cache: 'no-store' })).json()"
712712
)
713-
if not after.get("study_session_id"):
713+
# Released = no LIVE claim: since plan 5 (larger #1) a web end keeps
714+
# the saved ``mode=ended`` state file so the summary view can
715+
# render from it; every client reads that as inactive.
716+
if not after.get("study_session_id") or after.get("mode") == "ended":
714717
break
715718
time.sleep(0.3)
716-
assert not after.get("study_session_id"), (
719+
assert not after.get("study_session_id") or after.get("mode") == "ended", (
717720
f"explicit end did not release the session: {after!r}"
718721
)
719722

‎packages/studyloop/tests/e2e/test_session_recovery_journey.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ def test_end_from_the_picker_releases_the_slot(self, clean_session: str, page: P
291291
"""async () => {
292292
const res = await fetch('/api/session/state');
293293
const s = await res.json();
294-
return !s.study_session_id;
294+
// released = no LIVE claim (plan 5 keeps the ended state file)
295+
return !s.study_session_id || s.mode === 'ended';
295296
}""",
296297
timeout=10.0,
297298
what="the session to be released server-side",
@@ -452,7 +453,8 @@ def test_body_double_picker_can_end_a_foreign_session(
452453
"""async () => {
453454
const res = await fetch('/api/session/state');
454455
const state = await res.json();
455-
return !state.study_session_id;
456+
// released = no LIVE claim (plan 5 keeps the ended state file)
457+
return !state.study_session_id || state.mode === 'ended';
456458
}""",
457459
timeout=10.0,
458460
what="the conflicting session to be ended server-side",

‎packages/studyloop/tests/e2e/test_ws_grace_real_server.py‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ def _free_port() -> int:
7373
return int(s.getsockname()[1])
7474

7575

76+
def _live(state: dict) -> bool:
77+
"""A LIVE claim: an id whose state is not ``mode=ended``.
78+
79+
Since plan 5 (larger #1) a web ending keeps the saved ``mode=ended`` state
80+
file so the dashboard's summary view can render from it; the server render,
81+
``session_state.has_active_session`` and both JS components all read that as
82+
"no session". "Released" therefore means no live claim, not an absent id.
83+
"""
84+
return bool(state.get("study_session_id")) and state.get("mode") != "ended"
85+
86+
7687
def _agent_pids() -> set[int]:
7788
"""PIDs of every live fake-agent process.
7889
@@ -267,7 +278,7 @@ def test_window_expiry_releases_the_session_and_reaps_the_agent(self, server: Se
267278
agent_pid = next(iter(_agent_pids() - before))
268279

269280
_await(
270-
lambda: not server.state().get("study_session_id"),
281+
lambda: not _live(server.state()),
271282
"the grace window to expire and release the session",
272283
timeout=GRACE_S + 10,
273284
)
@@ -294,7 +305,7 @@ def test_agent_exit_while_detached_releases_without_waiting(self, server: Server
294305
os.kill(agent_pid, signal.SIGKILL)
295306
killed_at = time.monotonic()
296307
_await(
297-
lambda: not server.state().get("study_session_id"),
308+
lambda: not _live(server.state()),
298309
"the dead session to be released",
299310
timeout=GRACE_S + 10,
300311
)
@@ -356,7 +367,7 @@ def test_end_during_the_window_releases_at_once(self, server: Server) -> None:
356367

357368
status, _ = server.post("/api/session/end")
358369
assert status == 200
359-
assert not server.state().get("study_session_id")
370+
assert not _live(server.state())
360371
_await(lambda: agent_pid not in _agent_pids(), "the agent child to be reaped on end")
361372

362373
def test_end_then_start_gets_a_working_socket(self, server: Server) -> None:

‎packages/studyloop/tests/test_web_plan_architect_journey.py‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,17 @@ def _wait_for_planning_label(page: Page) -> list[str]:
276276
return _visible_purpose_labels(page)
277277

278278

279+
def _live(state: dict) -> bool:
280+
"""A LIVE claim: an id whose state is not ``mode=ended``.
281+
282+
Since plan 5 (larger #1) a web ending keeps the saved ``mode=ended`` state
283+
file so the dashboard's summary view can render from it; the server render,
284+
``session_state.has_active_session`` and both JS components all read that as
285+
"no session". "Released" therefore means no live claim, not an absent id.
286+
"""
287+
return bool(state.get("study_session_id")) and state.get("mode") != "ended"
288+
289+
279290
def _session_state(page: Page) -> dict:
280291
return page.evaluate(
281292
"async () => (await fetch('/api/session/state', {cache: 'no-store'})).json()"
@@ -436,7 +447,7 @@ def test_manual_new_plan_form_still_works(page: Page) -> None:
436447
)
437448
assert _plans(page)["count"] == before + 1
438449
# No session was started by the manual path.
439-
assert not _session_state(page).get("study_session_id")
450+
assert not _live(_session_state(page))
440451

441452

442453
def test_one_console_one_websocket(page: Page) -> None:
@@ -602,8 +613,12 @@ def test_abandoning_a_launch_mid_flight_leaves_no_session_and_no_plan(
602613
)
603614

604615
state = _session_state(page)
605-
assert not state.get("study_session_id"), state
606-
assert state.get("purpose") in (None, "focus"), "no planning label survives the abandon"
616+
assert not _live(state), state
617+
# The saved ``mode=ended`` record says what the session WAS (plan 5 keeps it
618+
# for the summary view); the label that must not survive is the LIVE one,
619+
# asserted on the page below (``_visible_purpose_labels(page) == []``).
620+
assert state.get("mode") == "ended", state
621+
assert state.get("purpose") == "planning", "the ended record keeps its truthful purpose"
607622
assert _plans(page) == plans_before, "the abandoned interview created no plan"
608623
assert sorted(p.name for p in world["plans"].glob("*.md")) == files_before
609624
probe = _probe(page)
@@ -721,7 +736,7 @@ def test_leaving_before_the_launch_lands_leaves_a_session_like_any_other(
721736
# The learner leaves before the server has answered.
722737
page.evaluate("() => window.Alpine.store('nav').go('study-plans')")
723738
page.locator('[data-testid="plan-new"]').wait_for(state="visible", timeout=8000)
724-
assert not _session_state(page).get("study_session_id"), "nothing exists yet: the POST is held"
739+
assert not _live(_session_state(page)), "nothing exists yet: the POST is held"
725740

726741
def _is_start(response) -> bool: # type: ignore[no-untyped-def]
727742
return response.request.method == "POST" and response.url.endswith("/api/session/start")

0 commit comments

Comments
 (0)