Add ensure_state: idempotent read-compare-act-verify for control state#439
Merged
Conversation
Acting unconditionally double-toggles an already-checked box or re-enters an already-correct field and can't be safely re-run. ensure_state reads first and only acts (then re-reads to verify) when the state differs; ensure_toggle is the boolean flip specialization. A control already in the desired state is left untouched, so the call is idempotent. Distinct from idempotency (request-key cache) — this converges device state.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 24 |
| Duplication | 2 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Fourth feature of the ROUND-15 input-fidelity lane. Acting unconditionally double-toggles an already-checked box or re-enters an already-correct field and can't be safely re-run. The robust shape is read-compare-act-verify.
utils/ensure_state/:ensure_state(read via injectablereader; only if it doesn'tequalsdesiredapplysetterand re-read, up toattempts),ensure_toggle(boolean specialization delegating toensure_state— callstoggleonly while the state differs). A control already in the desired state is left untouched (changed=False), so the call is idempotent. Distinct fromidempotency(a request-key replay cache) — this converges device state.__all__;AC_ensure_field_valueexecutor command (idempotently sets a native control's value viacontrol_get_value/control_set_value); matchingac_ensure_field_valueMCP tool (side-effect); Script Builder under Flow.ensure_state/ensure_toggle(arbitrary callables) are the Python-API surface.v212_features_doc.rst+WHATS_NEW.md.Test
test/unit_test/headless/test_ensure_state_batch.py— no-op when already matching (setter never called), set-when-different, give-up when setter ineffective, customequals,ensure_toggleno-op / flip-once, plus facade + executor/MCP/builder wiring. All 8 green;ruff+bandit+radonclean; no float==; package stays Qt-free.