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
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
KR-P2-CLEANUP ST5 of 5. KR-P2-I-integration ST5 (PR #35) flipped
/api/operational-statefrom the hardcoded stub to a liveOperationalStateHolderread 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()returnsNone)test_uninitialized_branch_returns_stub_with_error— assertsstub: True+errorfield +"not yet initialized"in the messagetest_uninitialized_branch_top_level_shape— asserts the 8-key shape (incl.stub+error) + cold defaults (primary_state="booting",claim_permission="none", emptytransition_history, emptyvalid_next_states)test_uninitialized_branch_uses_only_valid_enum_valuesLive branch (
init_holder+ transition)test_live_branch_returns_real_state_without_stub_or_error— confirms neither field appears on the live pathtest_live_branch_transition_history_populated_after_transition— after one transition the history ring has the entry with the documented shape + correctfrom_state/to_state/triggertest_live_branch_valid_next_states_derived_from_transition_table— READY advertises ACTIVE / PAUSED / STOPPED arrowstest_live_branch_degradation_reasons_render_sorted— stable alphabetical ordering +is_degraded=Truewith multiple reasonsPlus
New autouse fixture —
_reset_holderClears the
OperationalStateHoldersingleton via_reset_holder_for_testsbefore 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
_VALID_*enum-value sets retained from the original test file.Sub-task chain — final ST of this bucket
Test plan
pytest tests/kora_cli/test_web_server_operational_state.py🤖 Generated with Claude Code