The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(process_kill, runtime_snapshot, staleness, profiles): extract test module and increase visi
Steven Enamakel14bd0dc1deda
diff --git a/crates/openhuman-app/src/process_kill.rs b/crates/openhuman-app/src/process_kill.rsindex 1d491ab301..ee03dc2619 100644--- a/crates/openhuman-app/src/process_kill.rs+++ b/crates/openhuman-app/src/process_kill.rs@@ -270,134 +270,6 @@ pub(crate) const fn is_protected_windows_pid(pid: u32) -> bool {pid == 0 || pid == 4}-#[cfg(all(test, windows))]-mod windows_tests {- use super::*;-- #[test]- fn is_protected_windows_pid_matches_kernel_pids() {- assert!(is_protected_windows_pid(0));- assert!(is_protected_windows_pid(4));- assert!(!is_protected_windows_pid(1));- assert!(!is_protected_windows_pid(8));- assert!(!is_protected_windows_pid(1234));- }-- #[test]- fn classify_taskkill_force_treats_exit_0_as_success() {- assert!(classify_taskkill_force_status(Some(0), b"", 1234).is_ok());- }-- #[test]- fn classify_taskkill_force_treats_exit_128_as_success() {- // Exit 128 = "There is no running instance of the task." — process- // already gone between the pid lookup and our kill call. The port is- // freeing on its own; recovery must NOT bail out here.- assert!(classify_taskkill_force_status(Some(128), b"", 1234).is_ok());- }-- #[test]- fn classify_taskkill_force_treats_not_found_stderr_as_success() {- // Some hosts/wrappers normalize exit codes to 1 but still emit the- // canonical "not found" message on stderr.- let stderr = b"ERROR: The process \"1234\" not found.\r\n";- assert!(classify_taskkill_force_status(Some(1), stderr, 1234).is_ok());- }-- #[test]- fn classify_taskkill_force_treats_no_running_instance_as_success() {- // The `/T` (tree) flag emits this shape when the parent is already- // gone but child traversal still runs. Pass a *non-128* exit code- // here so the test actually exercises the stderr-matching branch —- // `Some(128)` short-circuits before we ever inspect stderr.- let stderr = b"ERROR: The process with PID 1234 (child process of PID 999) \- could not be terminated.\r\n\- Reason: There is no running instance of the task.\r\n";- assert!(classify_taskkill_force_status(Some(1), stderr, 1234).is_ok());- }-- #[test]- fn classify_taskkill_force_propagates_access_denied() {- // Access-denied has the SAME "could not be terminated" prefix as- // the process-gone case, so the predicate must require additional- // tokens before treating it as success. Otherwise we silently mark- // a live, unreachable process as killed and recovery proceeds- // against a still-bound port.- let stderr = b"ERROR: The process with PID 1234 could not be terminated.\r\n\- Reason: Access is denied.\r\n";- let err = classify_taskkill_force_status(Some(1), stderr, 1234).unwrap_err();- assert!(err.contains("code Some(1)"), "got: {err}");- assert!(err.contains("Access is denied"), "got: {err}");- }-- #[test]- fn classify_taskkill_force_propagates_bare_access_denied() {- let stderr = b"ERROR: Access is denied.\r\n";- let err = classify_taskkill_force_status(Some(5), stderr, 1234).unwrap_err();- assert!(err.contains("code Some(5)"), "got: {err}");- assert!(err.contains("Access is denied"), "got: {err}");- }-- #[test]- fn kill_pid_term_refuses_protected_pids() {- assert!(kill_pid_term(0).is_err());- assert!(kill_pid_term(4).is_err());- }-- #[test]- fn kill_pid_force_refuses_protected_pids() {- assert!(kill_pid_force(0).is_err());- assert!(kill_pid_force(4).is_err());- }-- #[test]- fn kill_pid_force_no_tree_refuses_protected_pids() {- assert!(kill_pid_force_no_tree(0).is_err());- assert!(kill_pid_force_no_tree(4).is_err());- }-- /// The non-tree force-kill (issue #3900) terminates the target and is- /// idempotent on an already-gone pid, exactly like `kill_pid_force`.- #[test]- fn kill_pid_force_no_tree_terminates_real_process_and_is_idempotent() {- let mut child = std::process::Command::new("cmd")- .args(["/C", "timeout", "/T", "30", "/NOBREAK"])- .stdout(std::process::Stdio::null())- .stderr(std::process::Stdio::null())- .stdin(std::process::Stdio::null())- .spawn()- .expect("spawn child process");- let pid = child.id();-- kill_pid_force_no_tree(pid).expect("force-kill running process (no tree)");- let _ = child.wait();- kill_pid_force_no_tree(pid).expect("force-kill of already-gone pid is success");- }-- /// End-to-end-on-Windows: spawn a real child process, force-kill it, and- /// verify it exits. Also covers the "process already gone" case by- /// killing the same PID twice — the second call must succeed (this is- /// the bug the patch above fixes).- #[test]- fn kill_pid_force_terminates_real_process_and_is_idempotent() {- // `timeout` is a builtin shipped with every Windows install; sleeps- // for ~30s which is plenty for the kill round-trip.- let mut child = std::process::Command::new("cmd")- .args(["/C", "timeout", "/T", "30", "/NOBREAK"])- .stdout(std::process::Stdio::null())- .stderr(std::process::Stdio::null())- .stdin(std::process::Stdio::null())- .spawn()- .expect("spawn child process");- let pid = child.id();-- kill_pid_force(pid).expect("force-kill running process");-- // Reap so we don't leave a zombie regardless of test outcome.- let _ = child.wait();-- // Second call: same pid is now gone. Must be Ok — this is the- // regression we're guarding against.- kill_pid_force(pid).expect("force-kill of already-gone pid is success");- }-}+#[cfg(test)]+#[path = "process_kill_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/desktop/app_state/ops/runtime_snapshot.rs b/crates/openhuman-core/src/desktop/app_state/ops/runtime_snapshot.rsindex 73495839f6..1fd7916d15 100644--- a/crates/openhuman-core/src/desktop/app_state/ops/runtime_snapshot.rs+++ b/crates/openhuman-core/src/desktop/app_state/ops/runtime_snapshot.rs@@ -27,13 +27,13 @@ pub(super) const SNAPSHOT_SUB_OP_TIMEOUT: Duration = Duration::from_secs(5);#[derive(Debug, Clone)]pub(super) struct CachedRuntimeSnapshot {- snapshot: RuntimeSnapshot,- fetched_at: Instant,+ pub(super) snapshot: RuntimeSnapshot,+ pub(super) fetched_at: Instant,/// Config identity (`workspace_dir`) the snapshot was built for. The cache/// holds one entry process-wide, so a snapshot built for one config must/// never be served to another — otherwise a different user/workspace (or an/// E2E test with an injected service mock) reads a stale, foreign runtime.- config_key: PathBuf,+ pub(super) config_key: PathBuf,}pub(super) static RUNTIME_SNAPSHOT_CACHE: Lazy<Mutex<Option<CachedRuntimeSnapshot>>> =diff --git a/crates/openhuman-core/src/desktop/app_state/ops/staleness.rs b/crates/openhuman-core/src/desktop/app_state/ops/staleness.rsindex e2c3d7e767..239fa8c2b0 100644--- a/crates/openhuman-core/src/desktop/app_state/ops/staleness.rs+++ b/crates/openhuman-core/src/desktop/app_state/ops/staleness.rs@@ -36,9 +36,9 @@ pub(super) static LAST_CURRENT_USER_SUCCESS: Lazy<Mutex<Option<CurrentUserSucces/// The last successful `auth_get_me`, with the identity it belongs to.#[derive(Debug, Clone)]pub(super) struct CurrentUserSuccess {- api_base: String,- token: String,- at: Instant,+ pub(super) api_base: String,+ pub(super) token: String,+ pub(super) at: Instant,}/// Stamp a refreshed user, so the snapshot can report how old the data it isdiff --git a/crates/openhuman-core/src/security/credentials/profiles.rs b/crates/openhuman-core/src/security/credentials/profiles.rsindex c0fa184cce..7775c3ea2b 100644--- a/crates/openhuman-core/src/security/credentials/profiles.rs+++ b/crates/openhuman-core/src/security/credentials/profiles.rs@@ -7,15 +7,21 @@ use std::collections::{BTreeMap, HashMap};use std::fs::{self, OpenOptions};use std::io::Write;use std::path::{Path, PathBuf};-use std::sync::{Mutex, MutexGuard, OnceLock, TryLockError};+use std::sync::{Mutex, MutexGuard, OnceLock};use std::thread;-use std::time::{Duration, Instant};+use std::time::Duration;#[cfg(test)]-use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};+use std::sync::atomic::{AtomicBool, AtomicUsize};#[cfg(test)]use std::sync::Arc;+mod keychain;+mod lock;+mod migration;+mod persistence;+mod store_core;+const CURRENT_SCHEMA_VERSION: u32 = 1;/// Compact secret payload stored as a single keychain entry per auth profile.