From 14cffbcbe6cf28c1a1f676fff729cf6f15dcab43 Mon Sep 17 00:00:00 2001 From: Valentin Klein Date: Sat, 10 Oct 2026 18:16:05 +0200 Subject: [PATCH] MCP plate test: finish TEXT before undo and check the centre line survives (#171) The scripted TEXT ended with a single newline, so TEXT was still asking for the next line when the test ran undo. Undo then reverted to before the centre line (taking the uncommitted text with it), and the only post-undo check, "no Text", passed anyway. The script now ends TEXT with a blank line (Enter), as an AutoCAD script would, and the test asserts no command is running afterwards. After undo it checks that exactly the text was undone and that the four circles, the outline and the Center-layer line are still there. Fixes #51. Co-authored-by: Claude Opus 5.5 --- crates/mcp/src/tests.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/mcp/src/tests.rs b/crates/mcp/src/tests.rs index d2491e7..7fc6607 100644 --- a/crates/mcp/src/tests.rs +++ b/crates/mcp/src/tests.rs @@ -43,8 +43,10 @@ fn agent_draws_a_plate_with_holes() { tool(&mut s, "execute", json!({"command": "layer.new", "params": {"name": "Center", "color": "red", "current": true}})); tool(&mut s, "command_line", json!({"text": "line -5,30 105,30"})); tool(&mut s, "command_line", json!({"text": ""})); - // Task 4: a script with text. - tool(&mut s, "script", json!({"text": "TEXT 0,-10 5 0 PLATE 100x60\n"})); + // Task 4: a script with text. TEXT keeps asking for further lines until an empty one, as in + // AutoCAD, so the script ends it with a blank line (= Enter). + let r = tool(&mut s, "script", json!({"text": "TEXT 0,-10 5 0 PLATE 100x60\n\n"})); + assert_eq!(r["state"]["running"], Value::Null, "TEXT must be finished: {r}"); // Verify only through MCP. let d = tool(&mut s, "inspect_drawing", json!({})); assert_eq!(d["counts"]["Circle"], 4); @@ -54,9 +56,15 @@ fn agent_draws_a_plate_with_holes() { let lines = tool(&mut s, "query_entities", json!({"type": "Line", "layer": "Center"})); assert_eq!(lines["count"], 1); // Task 5: undo the text, check, then render. - tool(&mut s, "execute", json!({"command": "undo"})); + let u = tool(&mut s, "execute", json!({"command": "undo"})); + assert_eq!(u["undone"], json!(["Single Line Text"]), "{u}"); let d = tool(&mut s, "inspect_drawing", json!({"entities": false})); assert!(d["counts"].get("Text").is_none()); + assert_eq!(d["counts"]["Circle"], 4); + assert_eq!(d["counts"]["Polyline"], 1); + assert_eq!(d["counts"]["Line"], 1); + let lines = tool(&mut s, "query_entities", json!({"type": "Line", "layer": "Center"})); + assert_eq!(lines["count"], 1, "the centre line must survive undoing the text"); let img = tool(&mut s, "render", json!({"width": 320, "height": 200})); assert_eq!(img["type"], "image"); assert!(img["data"].as_str().unwrap().len() > 100);