Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix(host): start Windows setup terminals and run fixtures there

leepokai6c78d6e6a9e3
diff --git a/host/src/agent/term.rs b/host/src/agent/term.rs
index 8efc0bae..21825c2f 100644
--- a/host/src/agent/term.rs
+++ b/host/src/agent/term.rs
@@ -174,6 +174,18 @@ impl Terms {
}
}
+/// Windows' pseudo console asks where the cursor is (`ESC[6n`) before the program starts,
+/// and waits for the answer. The host answers it (the line under the `$ command` header) and
+/// keeps the question from clients, which would answer it a second time into the program.
+const CURSOR_QUERY: &[u8] = b"\x1b[6n";
+const CURSOR_REPLY: &[u8] = b"\x1b[2;1R";
+
+/// `chunk` without its cursor query, if it has one.
+fn without_cursor_query(chunk: &[u8]) -> Option<Vec<u8>> {
+ let at = chunk.windows(CURSOR_QUERY.len()).position(|w| w == CURSOR_QUERY)?;
+ Some([&chunk[..at], &chunk[at + CURSOR_QUERY.len()..]].concat())
+}
+
fn size(cols: u16, rows: u16) -> PtySize {
PtySize { rows: rows.max(4), cols: cols.max(20), pixel_width: 0, pixel_height: 0 }
}
@@ -201,9 +213,17 @@ async fn run(
let term = term.clone();
tokio::task::spawn_blocking(move || {
let mut buf = vec![0u8; 16 * 1024];
+ let mut answered = !cfg!(windows);
// EOF or an error once the child and its children are gone.
while let Ok(n @ 1..) = reader.read(&mut buf) {
- term.push(&buf[..n]);
+ match without_cursor_query(&buf[..n]).filter(|_| !answered) {
+ Some(rest) => {
+ answered = true;
+ let _ = term.input.send(Input::Data(CURSOR_REPLY.to_vec()));
+ term.push(&rest);
+ }
+ None => term.push(&buf[..n]),
+ }
}
})
};
@@ -245,6 +265,12 @@ async fn run(
mod tests {
use super::*;
+ #[test]
+ fn takes_out_the_cursor_query() {
+ assert_eq!(without_cursor_query(b"a\x1b[6nb").as_deref(), Some(&b"ab"[..]));
+ assert_eq!(without_cursor_query(b"plain"), None);
+ }
+
#[tokio::test]
async fn runs_in_a_pty_and_takes_input() {
let terms = Arc::new(Terms::default());
diff --git a/host/src/chat/group.rs b/host/src/chat/group.rs
index 5f883c79..d9e947d4 100644
--- a/host/src/chat/group.rs
+++ b/host/src/chat/group.rs
@@ -338,7 +338,7 @@ mod tests {
std::fs::create_dir_all(&cwd).unwrap();
let cfg: BotConfig = serde_json::from_value(json!({
"id": id, "name": id, "backend": "fixture", "cwd": cwd,
- "command": format!("python3 -u '{}'", agent.display()), "notify": false,
+ "command": crate::shell::python(&agent), "notify": false,
}))
.unwrap();
store.save_bot(&cfg).unwrap();
@@ -405,7 +405,7 @@ mod tests {
async fn shutdown(self) {
self.hub.shutdown().await;
- std::fs::remove_dir_all(self.dir).unwrap();
+ let _ = std::fs::remove_dir_all(self.dir);
}
}
diff --git a/host/src/chat/team.rs b/host/src/chat/team.rs
index 92ff755c..ffc6297e 100644
--- a/host/src/chat/team.rs
+++ b/host/src/chat/team.rs
@@ -306,7 +306,7 @@ mod tests {
std::fs::create_dir_all(&cwd).unwrap();
let cfg: BotConfig = serde_json::from_value(json!({
"id": id, "name": id, "backend": "fixture", "cwd": cwd,
- "command": format!("python3 -u '{}'", agent.display().to_string().replace('\'', "'\\''")),
+ "command": crate::shell::python(&agent),
"notify": false, "permission": "ask",
}))
.unwrap();
@@ -361,7 +361,8 @@ mod tests {
async fn shutdown(self) {
self.hub.shutdown().await;
- std::fs::remove_dir_all(self.dir).unwrap();
+ // Windows may still hold files of an agent that just exited.
+ let _ = std::fs::remove_dir_all(self.dir);
}
}
@@ -517,7 +518,7 @@ mod tests {
assert!(f.request("start failure").await.unwrap().unwrap_err().to_string().contains("couldn't start"));
assert!(f.hub.team.0.locked().pending.is_empty());
let agent = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/team_agent.py");
- f.hub.update_bot(&json!({"id": "b", "command": format!("python3 -u '{}'", agent.display())})).unwrap();
+ f.hub.update_bot(&json!({"id": "b", "command": crate::shell::python(&agent)})).unwrap();
let request = f.request("BLOCK delete while working");
f.until(|| f.prompts().len() == 1).await;
f.hub.delete_bot("b").unwrap();
diff --git a/host/src/shell.rs b/host/src/shell.rs
index bd7d8f3b..1606dc8a 100644
--- a/host/src/shell.rs
+++ b/host/src/shell.rs
@@ -84,6 +84,13 @@ pub fn program(name: &str) -> PathBuf {
crate::agent::backends::which(name).unwrap_or_else(|| name.into())
}
+/// The command that runs a Python test fixture.
+#[cfg(test)]
+pub fn python(script: &std::path::Path) -> String {
+ let python = if cfg!(windows) { "python" } else { "python3" };
+ format!("{python} -u {}", quote(&script.to_string_lossy()))
+}
+
/// Leading `KEY=value` words (an optional `env` first), and the command after them.
#[cfg(any(windows, test))]
fn split_env(line: &str) -> (Vec<(String, String)>, &str) {
diff --git a/host/src/tui/app/input.rs b/host/src/tui/app/input.rs
index a96e0102..760f723e 100644
--- a/host/src/tui/app/input.rs
+++ b/host/src/tui/app/input.rs
@@ -436,10 +436,11 @@ fn dropped_files(s: &str) -> Option<Vec<std::path::PathBuf>> {
(!paths.is_empty() && paths.iter().all(|p| p.is_absolute() && p.is_file())).then_some(paths)
}
-#[cfg(test)]
+#[cfg(all(test, unix))]
mod tests {
use super::*;
+ // Terminals escape dropped paths the way Unix shells do.
#[test]
fn dropped_paths_are_files_only() {
let dir = std::env::temp_dir().join(format!("codync-drop-{}", std::process::id()));
diff --git a/host/tests/common/mod.rs b/host/tests/common/mod.rs
index 17c4cc38..f5eed406 100644
--- a/host/tests/common/mod.rs
+++ b/host/tests/common/mod.rs
@@ -18,3 +18,18 @@ pub fn stop(child: &mut Child) {
let _ = child.kill();
let _ = child.wait();
}
+
+/// Python as the test machine names it.
+pub fn python() -> &'static str {
+ if cfg!(windows) { "python" } else { "python3" }
+}
+
+/// The agent command that runs a Python fixture (quoted for `sh -c` / `cmd /c`).
+pub fn python_agent(script: &std::path::Path) -> String {
+ let path = script.display().to_string();
+ if cfg!(windows) {
+ format!("{} -u \"{path}\"", python())
+ } else {
+ format!("{} -u '{}'", python(), path.replace('\'', "'\\''"))
+ }
+}
diff --git a/host/tests/e2e.rs b/host/tests/e2e.rs
index 44e0de90..0954ae8c 100644
--- a/host/tests/e2e.rs
+++ b/host/tests/e2e.rs
@@ -113,8 +113,8 @@ async fn termination_exits_with_an_open_event_stream() {
#[tokio::test]
async fn turn_with_approval_reaches_a_final_reply() {
- if Command::new("python3").arg("--version").output().is_err() {
- eprintln!("skipping: python3 not available");
+ if Command::new(common::python()).arg("--version").output().is_err() {
+ eprintln!("skipping: Python not available");
return;
}
let host = start_host().await;
@@ -123,7 +123,7 @@ async fn turn_with_approval_reaches_a_final_reply() {
.call(
"createBot",
json!({
- "name": "Tester", "backend": "custom", "command": format!("python3 '{}'", agent.display()),
+ "name": "Tester", "backend": "custom", "command": common::python_agent(&agent),
"cwd": host.home.to_string_lossy(), "permission": "ask",
}),
)
@@ -162,8 +162,8 @@ async fn turn_with_approval_reaches_a_final_reply() {
#[tokio::test]
async fn sent_messages_are_the_reply() {
- if Command::new("python3").arg("--version").output().is_err() {
- eprintln!("skipping: python3 not available");
+ if Command::new(common::python()).arg("--version").output().is_err() {
+ eprintln!("skipping: Python not available");
return;
}
let host = start_host().await;
@@ -172,7 +172,7 @@ async fn sent_messages_are_the_reply() {
.call(
"createBot",
json!({
- "name": "Tester", "backend": "custom", "command": format!("python3 '{}'", agent.display()),
+ "name": "Tester", "backend": "custom", "command": common::python_agent(&agent),
"cwd": host.home.to_string_lossy(), "permission": "ask",
}),
)
@@ -318,8 +318,8 @@ fn query_param(url: &str, name: &str) -> String {
#[tokio::test]
async fn phone_pairs_and_chats_over_the_direct_channel() {
- if Command::new("python3").arg("--version").output().is_err() {
- eprintln!("skipping: python3 not available");
+ if Command::new(common::python()).arg("--version").output().is_err() {
+ eprintln!("skipping: Python not available");
return;
}
let host = start_host().await;
@@ -352,7 +352,7 @@ async fn phone_pairs_and_chats_over_the_direct_channel() {
2,
"createBot",
json!({
- "name": "Tester", "backend": "custom", "command": format!("python3 '{}'", agent.display()),
+ "name": "Tester", "backend": "custom", "command": common::python_agent(&agent),
"cwd": host.home.to_string_lossy(), "permission": "auto",
}),
)
@@ -382,10 +382,7 @@ async fn personal_workspaces_are_unique_persistent_and_optional() {
let host = start_host().await;
let agent = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/workspace_agent.py");
let first = host
- .call(
- "createBot",
- json!({"name": "One", "backend": "custom", "command": format!("python3 '{}'", agent.display())}),
- )
+ .call("createBot", json!({"name": "One", "backend": "custom", "command": common::python_agent(&agent)}))
.await;
let second = host.call("createBot", json!({"name": "Two", "backend": "claude", "cwd": ""})).await;
let first = &first["bot"];
@@ -534,8 +531,8 @@ async fn catch_up(host: &Host) -> Vec<Value> {
/// re-recorded. New fields only need recording (`CODYNC_UPDATE_WIRE_SHAPE=1`).
#[tokio::test]
async fn wire_shape_matches_the_snapshot() {
- if Command::new("python3").arg("--version").output().is_err() {
- eprintln!("skipping: python3 not available");
+ if Command::new(common::python()).arg("--version").output().is_err() {
+ eprintln!("skipping: Python not available");
return;
}
let host = start_host().await;
@@ -544,7 +541,7 @@ async fn wire_shape_matches_the_snapshot() {
.call(
"createBot",
json!({
- "name": "Tester", "backend": "custom", "command": format!("python3 '{}'", agent.display()),
+ "name": "Tester", "backend": "custom", "command": common::python_agent(&agent),
"cwd": host.home.to_string_lossy(), "permission": "ask",
}),
)
diff --git a/host/tests/routines_e2e.rs b/host/tests/routines_e2e.rs
index d245cfbf..53c1505c 100644
--- a/host/tests/routines_e2e.rs
+++ b/host/tests/routines_e2e.rs
@@ -100,7 +100,7 @@ impl Host {
"createBot",
json!({
"name": name, "backend": "custom", "cwd": cwd, "permission": "ask", "notify": false,
- "command": format!("python3 -u '{}'", agent.display().to_string().replace('\'', "'\\''")),
+ "command": common::python_agent(&agent),
}),
)
.await["bot"]["id"]
diff --git a/host/tests/team_e2e.rs b/host/tests/team_e2e.rs
index 9a33644e..b905d0b2 100644
--- a/host/tests/team_e2e.rs
+++ b/host/tests/team_e2e.rs
@@ -72,7 +72,7 @@ impl Host {
"createBot",
json!({
"name": name, "backend": "custom", "cwd": cwd, "permission": "ask", "notify": false,
- "command": format!("python3 -u '{}'", agent.display().to_string().replace('\'', "'\\''")),
+ "command": common::python_agent(&agent),
}),
)
.await["bot"]["id"]