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.

test(host): give dev server tests a server that listens at once

leepokaid77a3450464c
diff --git a/host/tests/common/mod.rs b/host/tests/common/mod.rs
index 1d00d445..8b194aaf 100644
--- a/host/tests/common/mod.rs
+++ b/host/tests/common/mod.rs
@@ -132,6 +132,13 @@ pub fn python_agent(script: &Path) -> String {
}
}
+/// The command of a program that listens on `port` of this computer until it's stopped.
+#[allow(dead_code, reason = "only the tests of dev servers use it")]
+pub fn port_server(port: u16) -> String {
+ let script = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/port_server.py");
+ format!("{} {port}", python_agent(&script))
+}
+
/// What a client holds after the event stream's catch-up: `{"rev", "bots": [...], "entries": [...]}`,
/// the newest row per id. Reads until the stream goes quiet.
pub async fn snapshot(base: &str, token: &str) -> serde_json::Value {
diff --git a/host/tests/dev_server_e2e.rs b/host/tests/dev_server_e2e.rs
index fbca93b2..2315f464 100644
--- a/host/tests/dev_server_e2e.rs
+++ b/host/tests/dev_server_e2e.rs
@@ -33,7 +33,7 @@ fn serves(port: u16) -> bool {
}
fn server_command(port: u16) -> String {
- format!("{} -m http.server {port} --bind 127.0.0.1", common::python())
+ common::port_server(port)
}
/// A program that keeps running and never listens.
diff --git a/host/tests/e2e/wire_shape.rs b/host/tests/e2e/wire_shape.rs
index 807f0344..0984233f 100644
--- a/host/tests/e2e/wire_shape.rs
+++ b/host/tests/e2e/wire_shape.rs
@@ -160,8 +160,7 @@ async fn wire_shape_matches_the_snapshot() {
assert!(made["data"]["text"].as_str().unwrap().starts_with("Done: "), "{made}");
// A running dev server: its `devServers`.
let port = std::net::TcpListener::bind("127.0.0.1:0").unwrap().local_addr().unwrap().port();
- let arguments =
- json!({"command": format!("{} -m http.server {port} --bind 127.0.0.1", common::python()), "name": "web"});
+ let arguments = json!({"command": common::port_server(port), "name": "web"});
let server =
host.call("chatCall", json!({"botId": lead, "name": "start_dev_server", "arguments": arguments})).await;
assert_eq!(server["ports"][0]["port"], port, "{server}");
diff --git a/host/tests/fixtures/port_server.py b/host/tests/fixtures/port_server.py
new file mode 100644
index 00000000..8b7315ad
--- /dev/null
+++ b/host/tests/fixtures/port_server.py
@@ -0,0 +1,13 @@
+"""A dev server for tests: listens on `port_server.py <port>` until stopped. Not `python -m http.server`, which looks up
+its own name before it listens: on CI's macOS machines that takes 35 s."""
+
+import socket
+import sys
+
+listener = socket.create_server(("127.0.0.1", int(sys.argv[1])))
+try:
+ while True:
+ connection, _ = listener.accept()
+ connection.close()
+except KeyboardInterrupt:
+ pass
diff --git a/host/tests/fixtures/shell_server_agent.py b/host/tests/fixtures/shell_server_agent.py
index 0f2d6d2b..71d26b7e 100644
--- a/host/tests/fixtures/shell_server_agent.py
+++ b/host/tests/fixtures/shell_server_agent.py
@@ -33,7 +33,7 @@ for line in sys.stdin:
elif method == "session/prompt":
if PORT and server is None:
server = subprocess.Popen(
- [sys.executable, "-m", "http.server", str(PORT), "--bind", "127.0.0.1"],
+ [sys.executable, os.path.join(os.path.dirname(os.path.abspath(__file__)), "port_server.py"), str(PORT)],
# On Windows a child starting on this process's stdin hangs while the loop below is reading it.
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,