From d58ee390864d53ac200d8fe79fc46f1a836b4048 Mon Sep 17 00:00:00 2001 From: ScottW514 Date: Thu, 10 Sep 2026 10:13:16 -0400 Subject: [PATCH] Hand lid_policy back unset where the machine had it unset motion.lid-policy-hold read the setting as was = (fc.settings() or {}).get("lid_policy") or "cancel" and wrote `was` back at the end. On a machine that has never set the policy the setting reads as the empty string and behaves as cancel, so the `or` turned "unset" into the word and the test handed the machine back carrying a setting it did not arrive with. The hand-back reported it, restored it, and failed the test. The value is now captured exactly, empty included, and restored as captured; the default belongs to reading the value, never to writing it back. The read-back check gets the same default, so it no longer compares None with the empty string. lid_policy_in_force carries the effective policy into the evidence, which is what the old expression was reaching for. Found on the bench reference, on the run after the position dead band let motion.lid-cancel-home through. The four other places in the suite that read a setting with `or` are safe: two default to the empty string, which is what unset is, and two feed a check rather than a restore. The shared Restore helper captures raw values and writes the empty string back for unset, as this now does. Only this test's earlier passes are invalidated: the change is inside its own body, and the per-test source hash of the other eleven motion tests is unchanged (checked against the file before the edit). --- forgetest/forgetest/suite/motion.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/forgetest/forgetest/suite/motion.py b/forgetest/forgetest/suite/motion.py index 5782d12..01eece9 100644 --- a/forgetest/forgetest/suite/motion.py +++ b/forgetest/forgetest/suite/motion.py @@ -1285,8 +1285,13 @@ def interlock_cancel_home(ctx): def lid_policy_hold(ctx): ev = ctx.evidence fc = ctx.forgectrl - was = (fc.settings() or {}).get("lid_policy") or "cancel" + # What the machine had, exactly: an unset lid_policy reads as the empty + # string and behaves as cancel, and writing the word back where the + # machine had nothing is a leftover the hand-back reports. The default + # is for reading the value, never for restoring it. + was = (fc.settings() or {}).get("lid_policy", "") ev["lid_policy_before"] = was + ev["lid_policy_in_force"] = was or "cancel" st, _b = fc.post("/settings", data={"lid_policy": "hold"}) ctx.check(st == 200, "could not set lid_policy=hold (%s)", st) ctx.check(((fc.settings() or {}).get("lid_policy")) == "hold", "lid_policy did not take") @@ -1333,7 +1338,7 @@ def lid_policy_hold(ctx): machine_idle(ctx) finally: st, _b = fc.post("/settings", data={"lid_policy": was}) - ev["lid_policy_restored"] = (fc.settings() or {}).get("lid_policy") + ev["lid_policy_restored"] = (fc.settings() or {}).get("lid_policy", "") ctx.log("lid_policy restored to %s", ev["lid_policy_restored"]) ctx.check(ev["lid_policy_restored"] == was, "lid_policy was not restored to %r", was) ctx.log("PASS: lid_policy=hold parked the job in Door and the cycle start finished it (%.3f mm)",