64 lines
3.0 KiB
Python
64 lines
3.0 KiB
Python
"""Review three changes in a single live editor dialog, then undo with one confirmation."""
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
from mcp_smoke import Client
|
|
|
|
|
|
def verify(exe, root, offline=False):
|
|
def snapshot():
|
|
return {p.relative_to(root): p.read_bytes() for p in root.rglob("*") if p.is_file()}
|
|
|
|
initial = snapshot()
|
|
client = Client(exe, root, "--allow-write")
|
|
try:
|
|
summary = client.call("get_project_summary")
|
|
if offline:
|
|
assert summary.get("source") != "editor"
|
|
recipe = summary["DefaultRecipeId"]
|
|
else:
|
|
assert summary["source"] == "editor"
|
|
recipe = summary["currentRecipeId"]
|
|
|
|
def named(kind, name):
|
|
return next(x["id"] for x in client.call("list_objects", kind=kind, recipeId=recipe)["items"] if x["name"] == name)
|
|
|
|
vision = named("VisionFunctions", "检查")
|
|
workflow = named("Workflows", "调度")
|
|
control = named("CustomControls", "显示")
|
|
refs = client.call("find_references", kind="VisionFunctions", id=vision)
|
|
assert refs["hits"]
|
|
script = client.call("get_object", kind="Workflows", id=workflow)["Code"]
|
|
marker = "批次验收"
|
|
operations = [
|
|
{"action": "update", "kind": "VisionFunctions", "id": vision, "properties": {"Comment": marker}},
|
|
{"action": "update", "kind": "CustomControls", "id": control, "properties": {"Comment": marker}},
|
|
{"action": "update", "kind": "Workflows", "id": workflow, "properties": {"Code": script + "\n// " + marker + "\n"}},
|
|
]
|
|
draft = client.call("preview_batch", operations=operations)
|
|
batch = draft["Batch"]
|
|
assert draft["Status"] == "pending" and batch["Compiled"] and batch["Workflows"]
|
|
assert len(batch["Steps"]) == 3 and any(s["Edit"]["ManualReferences"] for s in batch["Steps"])
|
|
assert initial == snapshot()
|
|
print("ANALYZED", len(refs["hits"]), "references;", len(batch["Workflows"]), "compiled workflows", flush=True)
|
|
assert client.call("apply_changes", draftId=draft["DraftId"])["Status"] == "saved"
|
|
saved = snapshot()
|
|
assert {p for p in initial if initial[p] != saved[p]} == set(map(Path, batch["ChangedFiles"]))
|
|
for op in operations:
|
|
row = client.call("get_object", kind=op["kind"], id=op["id"])
|
|
assert all(row[k] == v for k, v in op["properties"].items())
|
|
undo = client.call("preview_undo", draftId=draft["DraftId"])
|
|
assert undo["Batch"]["UndoOf"] == draft["DraftId"] and saved == snapshot()
|
|
print("SAVED", batch["ChangedFiles"], flush=True)
|
|
assert client.call("apply_changes", draftId=undo["DraftId"])["Status"] == "saved"
|
|
assert client.call("get_change_status", draftId=draft["DraftId"])["Status"] == "undone"
|
|
assert snapshot() == initial
|
|
print("PASS", len(initial), "files;", sum(map(len, initial.values())), "bytes")
|
|
finally:
|
|
client.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
verify(Path(sys.argv[1]), Path(sys.argv[2]), offline="--offline" in sys.argv[3:])
|
|
|