Skip to content

Add ensure_state: idempotent read-compare-act-verify for control state#439

Merged
JE-Chen merged 1 commit into
devfrom
feat/ensure-state-batch
Jun 25, 2026
Merged

Add ensure_state: idempotent read-compare-act-verify for control state#439
JE-Chen merged 1 commit into
devfrom
feat/ensure-state-batch

Conversation

@JE-Chen

@JE-Chen JE-Chen commented Jun 25, 2026

Copy link
Copy Markdown
Member

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.

  • Headless core utils/ensure_state/: ensure_state (read via injectable reader; only if it doesn't equals desired apply setter and re-read, up to attempts), ensure_toggle (boolean specialization delegating to ensure_state — calls toggle only while the state differs). A control already in the desired state is left untouched (changed=False), so the call is idempotent. Distinct from idempotency (a request-key replay cache) — this converges device state.
  • 5 layers wired: facade __all__; AC_ensure_field_value executor command (idempotently sets a native control's value via control_get_value/control_set_value); matching ac_ensure_field_value MCP tool (side-effect); Script Builder under Flow. ensure_state/ensure_toggle (arbitrary callables) are the Python-API surface.
  • Docs: EN + Zh 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, custom equals, ensure_toggle no-op / flip-once, plus facade + executor/MCP/builder wiring. All 8 green; ruff + bandit + radon clean; no float ==; package stays Qt-free.

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.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 24 complexity · 2 duplication

Metric Results
Complexity 24
Duplication 2

View in Codacy

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.

@JE-Chen JE-Chen merged commit f234751 into dev Jun 25, 2026
16 checks passed
@JE-Chen JE-Chen deleted the feat/ensure-state-batch branch June 25, 2026 22:57
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant