mirror of
https://github.com/storytold/cadcraft.git
synced 2026-12-01 18:25:32 -06:00
A LISP expression at Command: runs in 400,000-step slices, and only the window's per-frame lisp_tick carries a routine on. Session::script gave its next input right away and returned, so outside the window a routine longer than one slice stopped after it for good: cadcraft-cli run and the headless MCP server reported success with the routine cut short, and the next LISP line got "a LISP routine is already running". Session::lisp_run_until_input carries on such a routine until it ends or waits for input (a get... prompt or a command pause). A script calls it before each input it gives and once it ends, so the input goes to what the routine waits for, or comes after it. The headless MCP backend calls it after a command line and after Enter, since it has no frames either. The window's own command line keeps its slices and Esc; a script in the window, which already runs synchronously, now holds it until the routine ends or waits. Nobody can stop such a routine by hand, so it stops after Limits::frameless_steps steps (BLOCKING_CAP, as a programmatic lisp call) with the same "routine stopped after N steps" error; an endless *error* handler is stopped one slice later. Tests: lisp::tests::a_script_runs_a_long_routine_on_before_its_next_input, lisp::tests::a_script_stops_an_endless_routine, cadcraft-cli lisp_script::a_long_routine_in_a_script_draws_before_the_save and cadcraft-mcp tests::headless_lisp_routines_run_to_their_end; all fail without the change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
44 lines
1.7 KiB
Rust
44 lines
1.7 KiB
Rust
//! A LISP routine in a `run` script runs to its end before the script goes on and the drawing is
|
|
//! saved, however many slices it takes (#3635).
|
|
|
|
use std::process::{Command, Output};
|
|
|
|
fn cli(args: &[&str]) -> Output {
|
|
Command::new(env!("CARGO_BIN_EXE_cadcraft-cli")).args(args).output().unwrap()
|
|
}
|
|
|
|
/// A fresh scratch directory that is removed on drop, also when an assertion fails.
|
|
struct Scratch(std::path::PathBuf);
|
|
|
|
impl Scratch {
|
|
fn new(tag: &str) -> Self {
|
|
let dir = std::env::temp_dir().join(format!("cc-cli-{tag}-{}", std::process::id()));
|
|
let _ = std::fs::remove_dir_all(&dir);
|
|
std::fs::create_dir(&dir).expect("create scratch dir");
|
|
Scratch(dir)
|
|
}
|
|
}
|
|
|
|
impl Drop for Scratch {
|
|
fn drop(&mut self) {
|
|
let _ = std::fs::remove_dir_all(&self.0);
|
|
}
|
|
}
|
|
|
|
/// The loop takes many slices: the circle drawn after it is in the saved drawing, and the next
|
|
/// line runs once the routine has ended.
|
|
#[test]
|
|
fn a_long_routine_in_a_script_draws_before_the_save() {
|
|
let scratch = Scratch::new("lisp-script");
|
|
let saved = scratch.0.join("out.dxf");
|
|
let saved = saved.to_str().unwrap();
|
|
let script = r#"(progn (repeat 1000000 (setq x 1)) (command "circle" "0,0" "5") (princ "done"))\n(princ (+ x 1))"#;
|
|
let out = cli(&["run", "--metric", "--script", script, "--save", saved]);
|
|
let err = String::from_utf8_lossy(&out.stderr);
|
|
assert!(out.status.success(), "{:?}: {err}", out.status);
|
|
assert!(err.lines().any(|l| l == "done") && err.lines().any(|l| l == "2"), "{err}");
|
|
let info = cli(&["info", saved]);
|
|
let v: serde_json::Value = serde_json::from_slice(&info.stdout).unwrap();
|
|
assert_eq!(v["counts"]["Circle"], 1, "{v}");
|
|
}
|