Skip to content
This repository was archived by the owner on May 26, 2026. It is now read-only.

fix(KR-P2-CLEANUP ST5): realign test_web_server_operational_state with PR #35 flip#64

Merged
rafe-walker merged 1 commit into
mainfrom
feat/kora-KR-P2-CLEANUP-st5-ops-tests-fix
May 21, 2026
Merged

fix(KR-P2-CLEANUP ST5): realign test_web_server_operational_state with PR #35 flip#64
rafe-walker merged 1 commit into
mainfrom
feat/kora-KR-P2-CLEANUP-st5-ops-tests-fix

Conversation

@rafe-walker

Copy link
Copy Markdown
Owner

Summary

KR-P2-CLEANUP ST5 of 5. KR-P2-I-integration ST5 (PR #35) flipped /api/operational-state from the hardcoded stub to a live OperationalStateHolder read without updating these tests. 4 of the 8 tests were failing on main — they asserted stub semantics that no longer apply, and the file lacked a holder-reset fixture so state leaked across tests.

Full rewrite around the two-branch endpoint shape

Uninitialized branch (autouse fixture clears holder; get_holder() returns None)

  • test_uninitialized_branch_returns_stub_with_error — asserts stub: True + error field + "not yet initialized" in the message
  • test_uninitialized_branch_top_level_shape — asserts the 8-key shape (incl. stub + error) + cold defaults (primary_state="booting", claim_permission="none", empty transition_history, empty valid_next_states)
  • test_uninitialized_branch_uses_only_valid_enum_values

Live branch (init_holder + transition)

  • test_live_branch_returns_real_state_without_stub_or_error — confirms neither field appears on the live path
  • test_live_branch_transition_history_populated_after_transition — after one transition the history ring has the entry with the documented shape + correct from_state / to_state / trigger
  • test_live_branch_valid_next_states_derived_from_transition_table — READY advertises ACTIVE / PAUSED / STOPPED arrows
  • test_live_branch_degradation_reasons_render_sorted — stable alphabetical ordering + is_degraded=True with multiple reasons

Plus

  • Existing 200 sanity check
  • Cron-regression sanity

New autouse fixture — _reset_holder

Clears the OperationalStateHolder singleton via _reset_holder_for_tests before AND after every test. Without this, prior test runs in the same file (or run-order) leak holder state, which is why the original 4 tests intermittently passed/failed depending on ordering.

Mock-fixture pattern documented

The module docstring spells out the two-branch coverage requirement so future endpoint changes update both branches in lockstep. The "PR #35 flipped without updating tests" gap is the load-bearing reason this ST exists; documenting the pattern is half the fix.

Honest scope

Sub-task chain — final ST of this bucket

ST PR Status
ST1 #55 open
ST2 #57 open
ST3 #60 open
ST4 #62 open
ST5 this PR open (independent test fix; no production code changes)

Test plan

  • CI green on pytest tests/kora_cli/test_web_server_operational_state.py
  • All 4 previously-failing tests now pass

🤖 Generated with Claude Code

…h PR #35 flip

KR-P2-I-integration ST5 (PR #35) flipped /api/operational-state
from the hardcoded stub to a live OperationalStateHolder read
without updating these tests. 4 of the 8 tests were failing on
main (they asserted stub semantics that no longer apply, and
didn't reset the holder singleton between tests so state leaked
across the file).

Full rewrite around the two-branch endpoint shape:

Uninitialized branch (autouse fixture clears holder; get_holder()
returns None):
  - test_uninitialized_branch_returns_stub_with_error: asserts
    stub:True + error field + "not yet initialized" in message
  - test_uninitialized_branch_top_level_shape: asserts the 8-key
    shape (incl. stub + error) + cold defaults (primary_state
    "booting", claim_permission "none", empty history + next-states)
  - test_uninitialized_branch_uses_only_valid_enum_values

Live branch (init_holder + transition):
  - test_live_branch_returns_real_state_without_stub_or_error:
    confirms neither field appears on live path
  - test_live_branch_transition_history_populated_after_transition:
    after one transition the history ring has the entry with the
    documented shape + correct from/to/trigger values
  - test_live_branch_valid_next_states_derived_from_transition_table:
    READY advertises ACTIVE/PAUSED/STOPPED arrows
  - test_live_branch_degradation_reasons_render_sorted: stable
    alphabetical ordering + is_degraded=True with multiple reasons

Plus the existing 200 sanity check + cron-regression test.

New autouse _reset_holder fixture: clears the OperationalStateHolder
singleton via _reset_holder_for_tests before AND after every test.
Without this, prior test runs in the same file (or run-order) leak
holder state and the uninit-branch assertions intermittently fail.

The module docstring documents the mock-fixture pattern so future
endpoint changes update both branches in lockstep — the "PR #35
flipped without updating tests" gap is the load-bearing reason
this ST exists.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rafe-walker rafe-walker merged commit 977a472 into main May 21, 2026
@rafe-walker rafe-walker deleted the feat/kora-KR-P2-CLEANUP-st5-ops-tests-fix branch May 21, 2026 23:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant