Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

chore(web): move cancel-scoping tests into core crate

Steven Enamakele89823244abb
diff --git a/crates/openhuman-core/src/web_chat/web_tests.rs b/crates/openhuman-core/src/web_chat/web_tests.rs
index 6ccc63d700..50c53480f0 100644
--- a/crates/openhuman-core/src/web_chat/web_tests.rs
+++ b/crates/openhuman-core/src/web_chat/web_tests.rs
@@ -119,6 +119,8 @@ async fn wait_for_parallel<F: Fn(&[(String, String)]) -> bool>(pred: F) -> Vec<(
.expect("parallel in-flight condition not met before timeout")
}
+#[path = "web_tests_cancel_scoping_tests.rs"]
+mod cancel_scoping_tests;
#[path = "web_tests_error_code_classification_tests.rs"]
mod error_code_classification_tests;
#[path = "web_tests_queue_acceptance_tests.rs"]
diff --git a/crates/openhuman-core/src/web_chat/web_tests_cancel_scoping_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_cancel_scoping_tests.rs
new file mode 100644
index 0000000000..e488ae3793
--- /dev/null
+++ b/crates/openhuman-core/src/web_chat/web_tests_cancel_scoping_tests.rs
@@ -0,0 +1,28 @@
+//! Request-scoped web-chat cancellation (#4760): a stale scoped cancel for a
+//! superseded request must not tear down the newer in-flight turn.
+
+use super::*;
+
+#[test]
+fn unscoped_cancel_always_targets_the_in_flight_turn() {
+ // No request_id => "stop whatever is running on this thread" (Stop button /
+ // session teardown).
+ assert!(cancel_should_target(None, "req-A"));
+ assert!(cancel_should_target(None, "req-B"));
+}
+
+#[test]
+fn scoped_cancel_fires_for_its_own_request() {
+ assert!(cancel_should_target(Some("req-A"), "req-A"));
+}
+
+#[test]
+fn stale_scoped_cancel_does_not_kill_a_newer_turn() {
+ // Request A timed out client-side and B is now in flight: A's late scoped
+ // cancel must NOT tear down B.
+ assert!(!cancel_should_target(Some("req-A"), "req-B"));
+ assert!(!cancel_should_target(
+ Some("old-request"),
+ "current-request"
+ ));
+}
diff --git a/scripts/__tests__/tauri-deb-depends.test.mjs b/scripts/__tests__/tauri-deb-depends.test.mjs
new file mode 100644
index 0000000000..8e2d75d92f
--- /dev/null
+++ b/scripts/__tests__/tauri-deb-depends.test.mjs
@@ -0,0 +1,30 @@
+// Guards the Linux .deb runtime dependency list in tauri.conf.json (moved from
+// the former tests/linux_cef_deb_runtime_e2e.rs). libxdo3 in particular keeps
+// the binary from segfaulting on launch when the legacy soname is missing.
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import { dirname, resolve } from "node:path";
+import { test } from "node:test";
+import { fileURLToPath } from "node:url";
+
+const root = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..");
+
+test("tauri.conf.json linux deb depends lists the required runtime libraries once", () => {
+ const config = JSON.parse(
+ readFileSync(resolve(root, "crates/openhuman-app/tauri.conf.json"), "utf8"),
+ );
+ const deps = config?.bundle?.linux?.deb?.depends;
+ assert.ok(Array.isArray(deps), "bundle.linux.deb.depends should be an array");
+ for (const dep of [
+ "libgtk-3-0",
+ "libwebkit2gtk-4.1-0",
+ "libx11-6",
+ "libxdo3",
+ "libgdk-pixbuf-2.0-0",
+ "libglib2.0-0",
+ ]) {
+ assert.ok(deps.includes(dep), `deb depends missing ${dep}`);
+ assert.match(dep, /^[a-z0-9][a-z0-9.+-]*[a-z0-9]$/, `invalid Debian package name ${dep}`);
+ }
+ assert.equal(deps.filter((d) => d === "libxdo3").length, 1, "libxdo3 should be listed exactly once");
+});
diff --git a/scripts/release/strip-appimage-graphics-libs.sh b/scripts/release/strip-appimage-graphics-libs.sh
index e06a235c08..5fc967b79e 100755
--- a/scripts/release/strip-appimage-graphics-libs.sh
+++ b/scripts/release/strip-appimage-graphics-libs.sh
@@ -642,7 +642,7 @@ sanitize_elf_rpaths() {
# the lib silently vanishes from the AppImage and the binary segfaults on launch
# on any host lacking the legacy soname (e.g. Arch, which ships libxdo.so.4). The
# .deb path already guards this via its `depends` (libxdo3) +
-# linux_cef_deb_runtime_e2e; the AppImage path had no equivalent. This turns a
+# scripts/__tests__/tauri-deb-depends.test.mjs; the AppImage path had no equivalent. This turns a
# silent runtime segfault into a loud build failure. CEF is staged separately
# from the ldd walk, so verify its runtime library survived bundling as well.
# anylinux.so establishes sharun's portable runtime before either dependency
diff --git a/tests/linux_cef_deb_runtime_e2e.rs b/tests/linux_cef_deb_runtime_e2e.rs
deleted file mode 100644
index 62a3262c4f..0000000000
--- a/tests/linux_cef_deb_runtime_e2e.rs
+++ /dev/null
@@ -1,400 +0,0 @@
-//! E2E: Linux CEF deb package runtime - core binary resolution
-//!
-//! Tests the core binary resolution paths introduced in PR #3:
-//! - OPENHUMAN_CORE_BIN env override
-//! - Packaged Linux paths (/usr/bin/openhuman-core, /usr/lib/OpenHuman/openhuman-core)
-//! - Staged sidecar detection in dev builds
-//! - Fallback to self-subcommand
-//!
-//! These tests validate the cross-process behavior: Tauri shell → core sidecar
-//! spawning with correct binary path resolution.
-
-use std::fs;
-use std::io::Write;
-use std::path::PathBuf;
-use std::sync::{Mutex, MutexGuard};
-
-/// Serializes every env-mutating test in this file. `std::env` is
-/// process-global; cargo runs these tests in parallel within one binary,
-/// and several mutate the SAME vars (e.g. `OPENHUMAN_CORE_BIN`), so without
-/// this an interleaving made one test read back another's value and the
-/// `assert_eq!` flaked. `EnvGuard` holds this lock for its whole lifetime,
-/// so at most one env-mutating test runs at a time. Poison-safe (a
-/// panicking test must not cascade-fail every later one).
-static ENV_LOCK: Mutex<()> = Mutex::new(());
-
-/// Guard to temporarily set/unset environment variables. Acquires
-/// [`ENV_LOCK`] for its lifetime so concurrent tests can't observe each
-/// other's mutations.
-struct EnvGuard {
- key: &'static str,
- old: Option<String>,
- _lock: MutexGuard<'static, ()>,
-}
-
-impl EnvGuard {
- fn set(key: &'static str, value: &str) -> Self {
- let lock = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
- let old = std::env::var(key).ok();
- std::env::set_var(key, value);
- Self {
- key,
- old,
- _lock: lock,
- }
- }
-
- fn unset(key: &'static str) -> Self {
- let lock = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
- let old = std::env::var(key).ok();
- std::env::remove_var(key);
- Self {
- key,
- old,
- _lock: lock,
- }
- }
-}
-
-impl Drop for EnvGuard {
- fn drop(&mut self) {
- if let Some(old) = &self.old {
- std::env::set_var(self.key, old);
- } else {
- std::env::remove_var(self.key);
- }
- }
-}
-
-/// Test helper: create a fake core binary file with executable permissions.
-fn create_fake_core_binary(dir: &std::path::Path, name: &str) -> PathBuf {
- let path = dir.join(name);
- let mut file = fs::File::create(&path).expect("create fake binary");
- file.write_all(b"#!/bin/sh\necho 'fake core'\n")
- .expect("write fake binary content");
- drop(file);
-
- #[cfg(unix)]
- {
- use std::os::unix::fs::PermissionsExt;
- let perms = fs::Permissions::from_mode(0o755);
- fs::set_permissions(&path, perms).expect("set executable permissions");
- }
-
- path
-}
-
-/// Test that OPENHUMAN_CORE_BIN override takes precedence when file exists.
-#[test]
-fn core_bin_env_override_takes_precedence_when_exists() {
- let temp_dir = std::env::temp_dir().join("openhuman-core-test-override");
- let _ = fs::remove_dir_all(&temp_dir);
- fs::create_dir_all(&temp_dir).expect("create temp dir");
-
- // Create a fake core binary
- let fake_core = create_fake_core_binary(&temp_dir, "openhuman-core");
- let fake_core_str = fake_core.to_str().unwrap();
-
- // Set the env override
- let _guard = EnvGuard::set("OPENHUMAN_CORE_BIN", fake_core_str);
-
- // Import and call the function from the tauri crate
- // We can't directly import from src-tauri, but we verify the behavior
- // by checking that the env var is set and file exists
- assert!(fake_core.exists(), "Fake core binary should exist");
- assert_eq!(
- std::env::var("OPENHUMAN_CORE_BIN").ok().as_deref(),
- Some(fake_core_str)
- );
-
- // Cleanup
- let _ = fs::remove_dir_all(&temp_dir);
-}
-
-/// Test that OPENHUMAN_CORE_BIN override gracefully handles non-existent files.
-#[test]
-fn core_bin_env_override_graceful_when_nonexistent() {
- // Set env override to a non-existent path
- let _guard = EnvGuard::set("OPENHUMAN_CORE_BIN", "/nonexistent/path/openhuman-core");
-
- // Verify the env var is set
- assert_eq!(
- std::env::var("OPENHUMAN_CORE_BIN").ok().as_deref(),
- Some("/nonexistent/path/openhuman-core")
- );
-
- // Verify the file doesn't exist
- assert!(!std::path::Path::new("/nonexistent/path/openhuman-core").exists());
-}
-
-/// Test packaged Linux paths are probed in correct order.
-#[test]
-fn core_bin_packaged_linux_paths_order() {
- // Document the expected search order for packaged Linux binaries
- let expected_paths = [
- "/usr/bin/openhuman-core",
- "/usr/lib/OpenHuman/openhuman-core",
- ];
-
- // Verify these are valid absolute paths
- for path in &expected_paths {
- let p = std::path::Path::new(path);
- assert!(p.is_absolute(), "Path should be absolute: {}", path);
- assert!(
- path.contains("openhuman-core"),
- "Path should contain 'openhuman-core': {}",
- path
- );
- }
-
- // Log the expected search order for documentation
- println!("Packaged Linux core binary search order:");
- for (i, path) in expected_paths.iter().enumerate() {
- println!(" {}. {}", i + 1, path);
- }
-}
-
-/// Test core port configuration via environment variable.
-#[test]
-fn core_port_env_configuration() {
- // Test default port
- {
- let _guard = EnvGuard::unset("OPENHUMAN_CORE_PORT");
- let port = std::env::var("OPENHUMAN_CORE_PORT")
- .ok()
- .and_then(|v| v.parse::<u16>().ok())
- .unwrap_or(7788);
- assert_eq!(port, 7788, "Default port should be 7788");
- }
-
- // Test custom port
- {
- let _guard = EnvGuard::set("OPENHUMAN_CORE_PORT", "9999");
- let port = std::env::var("OPENHUMAN_CORE_PORT")
- .ok()
- .and_then(|v| v.parse::<u16>().ok())
- .unwrap_or(7788);
- assert_eq!(port, 9999, "Custom port should be 9999");
- }
-}
-
-/// Test RPC URL format matches expected pattern.
-#[test]
-fn core_rpc_url_format() {
- let test_cases = [
- (7788, "http://127.0.0.1:7788/rpc"),
- (9999, "http://127.0.0.1:9999/rpc"),
- (18473, "http://127.0.0.1:18473/rpc"),
- ];
-
- for (port, expected_url) in &test_cases {
- let url = format!("http://127.0.0.1:{}/rpc", port);
- assert_eq!(
- &url, *expected_url,
- "RPC URL format mismatch for port {}",
- port
- );
-
- // Verify URL is well-formed
- assert!(url.starts_with("http://"));
- assert!(url.ends_with("/rpc"));
- assert!(url.contains(&format!(":{}", port)));
- }
-}
-
-/// Test OPENHUMAN_CORE_RPC_URL environment variable handling.
-#[test]
-fn core_rpc_url_env_override() {
- // Test with env var set
- let _guard = EnvGuard::set("OPENHUMAN_CORE_RPC_URL", "http://localhost:8888/rpc");
- let url = std::env::var("OPENHUMAN_CORE_RPC_URL").unwrap();
- assert_eq!(url, "http://localhost:8888/rpc");
-
- // Verify format
- assert!(url.starts_with("http://"));
- assert!(url.ends_with("/rpc"));
-}
-
-/// Test core binary detection with symlink resolution.
-#[test]
-fn core_bin_symlink_resolution() {
- #[cfg(unix)]
- {
- use std::os::unix::fs::symlink;
-
- let temp_dir = std::env::temp_dir().join("openhuman-core-test-symlink");
- let _ = fs::remove_dir_all(&temp_dir);
- fs::create_dir_all(&temp_dir).expect("create temp dir");
-
- // Create real file
- let real_file = create_fake_core_binary(&temp_dir, "real-openhuman-core");
-
- // Create symlink
- let symlink_path = temp_dir.join("symlink-openhuman-core");
- symlink(&real_file, &symlink_path).expect("create symlink");
-
- // Both paths should resolve to the same canonical path
- let real_canonical = fs::canonicalize(&real_file).expect("canonicalize real");
- let symlink_canonical = fs::canonicalize(&symlink_path).expect("canonicalize symlink");
-
- assert_eq!(
- real_canonical, symlink_canonical,
- "Symlink should resolve to same canonical path"
- );
-
- // Cleanup
- let _ = fs::remove_dir_all(&temp_dir);
- }
-
- #[cfg(not(unix))]
- {
- // On Windows, symlinks require special permissions - skip this test
- println!("Skipping symlink test on non-Unix platform");
- }
-}
-
-/// Test that tray setup on linux+cef is properly gated.
-#[test]
-fn tray_setup_linux_cef_gate() {
- // Document the conditional compilation behavior:
- // - On linux + cef: setup_tray() logs a warning and returns Ok(())
- // - On other platforms: setup_tray() creates the actual tray
-
- // This is compile-time gated via #[cfg] attributes
- // We document the expected behavior here
-
- let is_linux = cfg!(target_os = "linux");
- let has_cef_feature = false; // Would be cfg!(feature = "cef") in actual code
-
- if is_linux && has_cef_feature {
- println!("On linux+cef: setup_tray() should log warning and skip tray creation");
- } else {
- println!("On other platforms: setup_tray() should create tray normally");
- }
-
- // The actual test is that this compiles and doesn't panic
- assert!(true);
-}
-
-/// Document the core.ping JSON-RPC structure.
-///
-/// This test documents the expected request/response format for core.ping.
-/// Full integration test would require a running sidecar.
-#[test]
-fn core_ping_request_structure() {
- // Document the expected JSON-RPC request structure
- let expected_request = serde_json::json!({
- "jsonrpc": "2.0",
- "id": 1,
- "method": "core.ping",
- "params": {}
- });
-
- // Verify structure
- assert_eq!(expected_request["jsonrpc"], "2.0");
- assert_eq!(expected_request["method"], "core.ping");
- assert!(expected_request["params"].is_object());
-
- // Document expected response format
- let expected_response = serde_json::json!({
- "jsonrpc": "2.0",
- "id": 1,
- "result": {}
- });
-
- assert_eq!(expected_response["jsonrpc"], "2.0");
- assert!(expected_response["result"].is_object());
-
- println!("Core ping request structure documented");
- println!(
- "Request: {}",
- serde_json::to_string_pretty(&expected_request).unwrap()
- );
-}
-
-/// Test Debian package dependencies configuration.
-#[test]
-fn debian_package_dependencies_configured() {
- let config_path = PathBuf::from(env!("OPENHUMAN_REPOSITORY_ROOT"))
- .join("crates/openhuman-app/tauri.conf.json");
- let config_text = fs::read_to_string(&config_path).expect("read tauri.conf.json");
- let config: serde_json::Value =
- serde_json::from_str(&config_text).expect("parse tauri.conf.json");
- let configured_deps: Vec<&str> = config
- .pointer("/bundle/linux/deb/depends")
- .and_then(|value| value.as_array())
- .expect("bundle.linux.deb.depends should be an array")
- .iter()
- .map(|value| value.as_str().expect("deb dependency should be a string"))
- .collect();
-
- let expected_deps = [
- "libgtk-3-0",
- "libwebkit2gtk-4.1-0",
- "libx11-6",
- "libxdo3",
- "libgdk-pixbuf-2.0-0",
- "libglib2.0-0",
- ];
-
- for dep in &expected_deps {
- assert!(
- configured_deps.contains(dep),
- "tauri.conf.json linux deb depends missing {}",
- dep
- );
- assert!(
- dep.chars()
- .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-' || c == '.'),
- "Invalid Debian package name characters: {}",
- dep
- );
- assert!(
- !dep.starts_with('-') && !dep.ends_with('-'),
- "Debian package name should not start/end with hyphen: {}",
- dep
- );
- }
-
- assert_eq!(
- configured_deps
- .iter()
- .filter(|dep| **dep == "libxdo3")
- .count(),
- 1,
- "libxdo3 should be listed exactly once"
- );
-
- println!("Debian package dependencies:");
- for dep in &configured_deps {
- println!(" - {}", dep);
- }
-}
-
-/// Test that the logging patterns are grep-friendly.
-#[test]
-fn logging_patterns_are_grep_friendly() {
- // Document the expected log patterns that should appear in the logs
- let expected_patterns = [
- "[core] default_core_bin:",
- "[core] spawning dedicated core binary:",
- "[core] core process ready",
- "[tray] deferring tray setup to RunEvent::Ready",
- ];
-
- for pattern in &expected_patterns {
- // Verify patterns are stable and contain expected prefixes
- assert!(
- pattern.starts_with('['),
- "Log pattern should start with bracketed category: {}",
- pattern
- );
- assert!(
- pattern.contains('[') && pattern.contains(']'),
- "Log pattern should have [category] format: {}",
- pattern
- );
-
- println!("Grep-friendly pattern: {}", pattern);
- }
-}
diff --git a/tests/web_cancel_request_scoping.rs b/tests/web_cancel_request_scoping.rs
deleted file mode 100644
index 17632a895c..0000000000
--- a/tests/web_cancel_request_scoping.rs
+++ /dev/null
@@ -1,45 +0,0 @@
-//! Request-scoped web-chat cancellation (#4760).
-//!
-//! Regression for a real in-flight-teardown bug: a client that timed out on
-//! request A and then sent request B — which supersedes A on the same thread —
-//! had A's late-arriving cancel tear down B, killing the newer turn at t=0
-//! ("Cancelled by newer request"). The root cause was that `cancel_chat`
-//! cancelled *whatever* turn was in flight for the thread, unscoped by
-//! `request_id`.
-//!
-//! The fix routes the cancel decision through `cancel_should_target`: a scoped
-//! cancel (`Some(request_id)`) only fires when it matches the turn actually in
-//! flight, so a stale cancel for a superseded request becomes a no-op and the
-//! newer turn survives. An unscoped cancel (`None` — Stop button / session
-//! teardown) still stops whatever is running.
-//!
-//! These assertions pin that decision. `cancel_should_target` is a pure
-//! predicate, so this is a fast, deterministic unit test with no runtime setup.
-
-use openhuman_core::web_chat::cancel_should_target;
-
-#[test]
-fn unscoped_cancel_always_targets_the_in_flight_turn() {
- // No request_id => "stop whatever is running on this thread" (the Stop
- // button / session-teardown path). It always targets the in-flight turn.
- assert!(cancel_should_target(None, "req-A"));
- assert!(cancel_should_target(None, "req-B"));
-}
-
-#[test]
-fn scoped_cancel_fires_for_its_own_request() {
- // A client cancelling exactly the turn it started tears that turn down.
- assert!(cancel_should_target(Some("req-A"), "req-A"));
-}
-
-#[test]
-fn stale_scoped_cancel_does_not_kill_a_newer_turn() {
- // The #4760 bug: request A timed out client-side and B is now the in-flight
- // turn on this thread. A's late, request-scoped cancel must NOT tear down B.
- assert!(!cancel_should_target(Some("req-A"), "req-B"));
- // Symmetric: a cancel naming an already-finished request is inert.
- assert!(!cancel_should_target(
- Some("old-request"),
- "current-request"
- ));
-}