qet-mcp: qet_diff no longer reports untouched elements as changed

QElectroTech writes an empty label as an empty <elementInformation> and
drops it on the next save. qet_diff compared the raw information bags, so
re-saving grafcet.qet with no edit reported 9 of its 37 elements as
info_changed ({"label": ""} -> {}), and Projet_vierge.qet 4.

An empty field and a missing one now compare equal, and info_changed lists
only fields that hold a value. The resave test now also requires an empty
info_changed; it failed on grafcet.qet and Projet_vierge.qet before this
change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-09-28 11:12:25 +13:00
parent 37674d836f
commit 40ed284b7a
2 changed files with 28 additions and 2 deletions
+7 -2
View File
@@ -492,9 +492,14 @@ def tool_diff(before: str, after: str) -> dict:
if a["label"] != b["label"]:
relabelled.append({"uuid": k, "name": a["name"],
"from": a["label"], "to": b["label"]})
if a["info"] != b["info"]:
# An empty field and a missing one mean the same thing, and
# QElectroTech drops empty ones when it saves, so compare only the
# fields that hold a value.
a_info = {n: v for n, v in a["info"].items() if v}
b_info = {n: v for n, v in b["info"].items() if v}
if a_info != b_info:
changed_info.append({"uuid": k, "name": a["name"],
"from": a["info"], "to": b["info"]})
"from": a_info, "to": b_info})
a_co = {r["key"]: r for i, c, ix in _conductors(_root(before))
for r in [_conductor_row(i, c, ix)]}
+21
View File
@@ -777,6 +777,26 @@ class Diff(unittest.TestCase):
b = self.project("b.qet", version="0.200.1-dev")
self.assertEqual(m.tool_diff(a, b)["folios"]["changed"], [])
def test_empty_information_and_a_missing_one_are_the_same(self):
"""QElectroTech writes an empty label as <elementInformation name="label"/>
and drops it on the next save, so comparing the raw bags made every
unlabelled element of a re-saved project look edited."""
def proj(infos):
return (f'<project><diagram><elements><element uuid="{{e}}" type="x" x="0" y="0">'
f'<elementInformations>{infos}</elementInformations>'
f'</element></elements><conductors/></diagram></project>')
a = self.dir / "a.qet"
b = self.dir / "b.qet"
c = self.dir / "c.qet"
a.write_text(proj('<elementInformation show="1" name="label"></elementInformation>'
'<elementInformation show="1" name="comment"> </elementInformation>'))
b.write_text(proj(''))
c.write_text(proj('<elementInformation show="1" name="label">K1</elementInformation>'))
self.assertEqual(m.tool_diff(str(a), str(b))["elements"]["info_changed"], [])
# A value that really appears or disappears is still reported.
changed = m.tool_diff(str(b), str(c))["elements"]["info_changed"]
self.assertEqual([(x["from"], x["to"]) for x in changed], [({}, {"label": "K1"})])
def test_element_text_field_moves_and_restyles_are_reported(self):
def proj(x, size, frame, extra=""):
return (f'<project><diagram><elements><element uuid="{{e}}"><dynamic_texts>'
@@ -2747,6 +2767,7 @@ class CorpusIntegration(unittest.TestCase):
if "unstable_keys" not in c:
self.assertEqual((len(c["added"]), len(c["removed"])), (0, 0))
self.assertEqual(r["diff"]["elements"]["moved_count"], 0)
self.assertEqual(r["diff"]["elements"]["info_changed"], [])
finally:
sb.close()