Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
Fix "Text file busy" test flake; Settings wording since 0.6.3
Lin (kwant bot)db9158bffe97
diff --git a/docs/bot-actions.md b/docs/bot-actions.mdindex e902d3cf..dba67c7d 100644--- a/docs/bot-actions.md+++ b/docs/bot-actions.md@@ -61,13 +61,13 @@ New setting: `GET/POST /api/settings` has `timezone` (IANA name; `""` means not| Category | Where the person goes ||---|---|-| API keys, tokens, passwords, webhook URL (any `*key*`, `*token*`, `*secret*`, `*webhook*` setting) | Space settings → Accounts / App settings → Notifications |-| Engines, sign-in and sign-out, Ollama URL, profiles | Space settings → Accounts / App settings |+| API keys, tokens, passwords, webhook URL (any `*key*`, `*token*`, `*secret*`, `*webhook*` setting) | Settings › This space › Accounts / Settings › All spaces › Notifications |+| Engines, sign-in and sign-out, Ollama URL, profiles | Settings › This space › Accounts / Settings › All spaces || How people sign in to kwnt (auth) | The host computer || Approvals and questions | The card in the chat (there is no tool for these) |-| Computer, sandbox or VM | App settings → Computer for browsing and commands |-| `agent_tools` | App settings, person only |-| Installing MCP servers, and MCP env or header values | `mcp_suggest` card; Space settings → Tools |+| Computer, sandbox or VM | Settings › All spaces › Computer for browsing and commands |+| `agent_tools` | Settings › All spaces, person only |+| Installing MCP servers, and MCP env or header values | `mcp_suggest` card; Settings › This space › Tools |`bot_update.mcp_servers` only assigns servers that are already installed in the space. Passing `env`, `headers`, `api_key`, `password` or `token` to `bot_create`/`bot_update` is refused.@@ -113,7 +113,7 @@ Each action posts a message from the bot (`sender_role: "kwant"`, `sender_id: <bSuggested buttons:- **Undo** when `can_undo`.- **Confirm** and **Decline** when `needs_confirmation`.-- For routines, **Edit** and **Pause** can open the routine in Space settings → Routines (`target_id`), or call `PUT /api/routines/:id` directly. Those edits are the person's own and are not bot actions.+- For routines, **Edit** and **Pause** can open the routine in Settings › This space › Routines (`target_id`), or call `PUT /api/routines/:id` directly. Those edits are the person's own and are not bot actions.## Routes (person only)diff --git a/src/doctor.rs b/src/doctor.rsindex 03bb241c..84a6f238 100644--- a/src/doctor.rs+++ b/src/doctor.rs@@ -76,7 +76,7 @@ pub fn cli_install_fix(engine: Engine, p: Platform) -> &'static str {(Engine::Codex, Platform::Mac) => "kwnt setup --clis codex (or: brew install --cask codex, or npm install -g @openai/codex)",(Engine::Codex, _) => "kwnt setup --clis codex (or: npm install -g @openai/codex; needs Node.js 18+)",(Engine::Grok, _) => "kwnt setup --clis grok (or: curl -fsSL https://x.ai/cli/install.sh | bash)",- (Engine::Custom, _) => "Add a Custom API account in the app: Space settings → Accounts",+ (Engine::Custom, _) => "Add a Custom API account in the app: Settings › This space › Accounts",}}@@ -92,7 +92,7 @@ pub fn cli_sign_in_fix(engine: Engine, p: Platform) -> String {Platform::Docker => format!("docker compose exec kwnt {cmd}"),_ => cmd.to_string(),};- format!("{run} (or set {key}, or use Sign in / an API key in the app: Space settings → Accounts)")+ format!("{run} (or set {key}, or use Sign in / an API key in the app: Settings › This space › Accounts)")}#[derive(Clone, Copy, Debug, PartialEq, Eq)]@@ -266,7 +266,7 @@ pub fn checks(f: &Facts, p: Platform) -> Vec<Check> {"AI account",Status::Warn,"no CLI is signed in here (API keys added in the app aren't checked by doctor)",- Some("Sign one CLI in (see above) or add an API key in the app: Space settings → Accounts".into()),+ Some("Sign one CLI in (see above) or add an API key in the app: Settings › This space › Accounts".into()),));}diff --git a/src/drivers/api.rs b/src/drivers/api.rsindex ef2efd1a..c1dbbab0 100644--- a/src/drivers/api.rs+++ b/src/drivers/api.rs@@ -59,7 +59,7 @@ async fn api_model_name(Some(m) => Ok(m.id),None if engine == super::engines::EngineId::AnthropicApi => Ok(DEFAULT_CLAUDE_MODEL.into()),None => Err(format!(- "Couldn't find a model to run on the {}: its model list didn't load. Check the key in Space settings → Accounts.",+ "Couldn't find a model to run on the {}: its model list didn't load. Check the key in Settings › This space › Accounts.",engine.name())),}@@ -1241,7 +1241,7 @@ impl Driver for ApiDriver {if custom && input.model.is_none() {return Err(DriverError::Execution(- "This Custom API account has no model to run: enter a model id for it under Space settings → Accounts, or pin one on the bot (\"custom:<model>\").".into(),+ "This Custom API account has no model to run: enter a model id for it under Settings › This space › Accounts, or pin one on the bot (\"custom:<model>\").".into(),));}let model = match api_model_name(target_model, input.model.as_deref(), &url, api_key.as_deref(), effort).await {diff --git a/src/drivers/engines.rs b/src/drivers/engines.rsindex 83356448..9581515b 100644--- a/src/drivers/engines.rs+++ b/src/drivers/engines.rs@@ -16,11 +16,11 @@ use std::time::Duration;pub const PROBE_TIMEOUT: Duration = Duration::from_secs(10);/// What a turn gets when no engine at all can run.-pub const NO_ENGINE_MESSAGE: &str = "No account can run bots here yet. Add one in Space settings → Accounts.";+pub const NO_ENGINE_MESSAGE: &str = "No account can run bots here yet. Add one in Settings › This space › Accounts.";/// What a turn gets when This machine is off in the space and no other account is on.pub const HOST_OFF_MESSAGE: &str =- "This machine is off in this space and no other account is on. Turn one on in Space settings → Accounts.";+ "This machine is off in this space and no other account is on. Turn one on in Settings › This space › Accounts.";/// The chat message `bot` leaves when nothing can run its turn, and its `meta`: kind/// `setup_needed`, so the app shows a card with a button to Accounts instead of a reply.@@ -880,11 +880,11 @@ impl EngineRegistry {}/// What Engines says about Custom API, which has nothing on the host to check.-pub const CUSTOM_API_DETAIL: &str = "Runs on this space's Custom API accounts: add one under Space settings → Accounts";+pub const CUSTOM_API_DETAIL: &str = "Runs on this space's Custom API accounts: add one under Settings › This space › Accounts";/// A turn on Custom API with no account of the space that can take it.pub const NO_CUSTOM_ACCOUNT: &str =- "No Custom API account is on in this space. Add one under Space settings → Accounts.";+ "No Custom API account is on in this space. Add one under Settings › This space › Accounts.";/// The model a turn runs on one engine.#[derive(Debug, Clone, PartialEq)]@@ -1009,7 +1009,7 @@ fn unavailable(target_model: &str, reports: &[EngineReport]) -> String {}).collect();format!(- "'{target_model}' can't run right now ({}). Fix it in Space settings → Accounts, or pick another engine for this bot.",+ "'{target_model}' can't run right now ({}). Fix it in Settings › This space › Accounts, or pick another engine for this bot.",why.join("; "))}@@ -1022,13 +1022,13 @@ mod tests {fn no_engine_notice_flags_the_setup_card() {let (text, meta) = no_engine_notice("Architect", false);assert_eq!(text, format!("⚠️ [Architect] {NO_ENGINE_MESSAGE}"));- assert!(text.contains("Space settings → Accounts"));+ assert!(text.contains("Settings › This space › Accounts"));assert!(!text.contains("Settings → Engines"));assert_eq!(meta, serde_json::json!({ "kind": "setup_needed", "reason": "no_account" }));let (text, meta) = no_engine_notice("DevOps", true);assert!(text.starts_with("⚠️ [DevOps] This machine is off"));- assert!(text.contains("Space settings → Accounts"));+ assert!(text.contains("Settings › This space › Accounts"));assert_eq!(meta["kind"], "setup_needed");assert_eq!(meta["reason"], "host_off");}diff --git a/src/server/bot_actions.rs b/src/server/bot_actions.rsindex c329fa6a..2c1b834f 100644--- a/src/server/bot_actions.rs+++ b/src/server/bot_actions.rs@@ -278,17 +278,17 @@ pub fn tools() -> Vec<Value> {// Refusals: what stays with the person, and where they do itconst SECRETS: &str = "Keys, tokens, passwords and webhook addresses are secrets you never handle. Ask the person to enter it \- themselves: API keys and engine accounts in Space settings → Accounts, the notification webhook in App settings → Notifications.";-const ENGINES: &str = "Engines and their sign-in are the person's. Ask them to sign in, sign out or point to Ollama in Space settings → Accounts \- or App settings.";+ themselves: API keys and engine accounts in Settings › This space › Accounts, the notification webhook in Settings › All spaces › Notifications.";+const ENGINES: &str = "Engines and their sign-in are the person's. Ask them to sign in, sign out or point to Ollama in Settings › This space › Accounts \+ or Settings › All spaces.";const AUTH: &str = "How people sign in to kwnt is the person's alone; ask them to change it on the computer kwnt runs on.";const APPROVALS: &str = "Approvals and questions are answered by the person, never by a bot: ask them to answer the card in the chat.";const APPROVALS_MODE: &str = "Whether bots ask before their tools run is the person's choice alone: only they can change it, in the app.";-const COMPUTER: &str = "Where bots browse and run commands is the person's choice: ask them in App settings → Computer for browsing and commands.";-const AGENT_TOOLS: &str = "Refused: you can't switch bots' own tools on or off. Only the person can: tell them to open App settings \- (the gear at the bottom of the space rail, or Space settings → App settings) and flip the \"Bots can use their own tools\" switch.";+const COMPUTER: &str = "Where bots browse and run commands is the person's choice: ask them in Settings › All spaces › Computer for browsing and commands.";+const AGENT_TOOLS: &str = "Refused: you can't switch bots' own tools on or off. Only the person can: tell them to open Settings \+ (the gear next to the space's name) › All spaces and flip the \"Bots can use their own tools\" switch.";const MCP: &str = "Tool servers are installed by the person. Use mcp_suggest to offer one; they see an Install card. \- Their keys and headers are entered by the person in Space settings → Tools.";+ Their keys and headers are entered by the person in Settings › This space › Tools.";/// Why an agent may not change setting `key`, with where the person does it; `None` when it may./// The person's zone and city from the settings, for each turn's "[Current date]" block.@@ -1029,7 +1029,7 @@ impl Ctx<'_> {e.g. claude/claude-sonnet-5-5.\n",);if profiles.is_empty() {- out.push_str("Accounts: none in this space yet (the person adds them in Space settings → Accounts).\n");+ out.push_str("Accounts: none in this space yet (the person adds them in Settings › This space › Accounts).\n");} else {out.push_str("Accounts (profile_id for that engine):\n");for p in profiles.iter().filter(|p| p.enabled) {@@ -1985,8 +1985,8 @@ mod tests {for key in ["agent_tools", "Agent_Tools", "agent_tools_enabled", "tools"] {let why = refused_setting(key).unwrap();assert!(why.starts_with("Refused"), "{key}: {why}");- assert!(why.contains("App settings"), "{key}: {why}");- assert!(why.contains("gear at the bottom of the space rail"), "{key}: the exact way there: {why}");+ assert!(why.contains("› All spaces"), "{key}: {why}");+ assert!(why.contains("the gear next to the space's name"), "{key}: the exact way there: {why}");assert!(why.contains("\"Bots can use their own tools\" switch"), "{key}: the control's own label: {why}");}}diff --git a/src/server/budget.rs b/src/server/budget.rsindex a4926d7c..b1b33735 100644--- a/src/server/budget.rs+++ b/src/server/budget.rs@@ -77,7 +77,7 @@ pub(super) async fn pause_if_over(scope: &TurnScope, spoken: &[String], replies:tracing::info!(job = %scope.job_id, used, budget, waiting = ?waiting, "chain over its token budget: hand-offs paused");let text = format!("Paused before handing on to {}: this request has used {} fresh tokens, over the {} budget. \- Say \"continue\" to let them take their turn, or change the budget in App settings → Usage.",+ Say \"continue\" to let them take their turn, or change the budget in Settings › All spaces › Usage.",waiting.join(", "),short(used),short(budget),diff --git a/src/server/continuity.rs b/src/server/continuity.rsindex 37bdae80..10eb4d40 100644--- a/src/server/continuity.rs+++ b/src/server/continuity.rs@@ -133,8 +133,8 @@ pub async fn prompt_block(with Undo; afterwards say in one sentence what will happen. The user may undo a change later, so check with the list tools \before relying on an earlier one. Deleting a bot, a space or an account only asks the user to confirm. \Never handle keys, passwords or sign-ins, answer approvals, install tool servers, switch bots' tools on or off or change the computer: those tools \- tell you where in Settings the user does it. Bots' own tools are the user's switch in App settings (gear at the \- bottom of the space rail) → \"Bots can use their own tools\"; say that outright.\n\+ tell you where in Settings the user does it. Bots' own tools are the user's switch in Settings › All spaces → \+ \"Bots can use their own tools\"; say that outright.\n\- `propose_hire` proposes a new bot for work a specialist would do better; the person decides. `hire_status` shows \the space's hire policy and decisions.\n\n\[How to work]\n\diff --git a/src/server/hires.rs b/src/server/hires.rsindex 672dc7c0..66831b35 100644--- a/src/server/hires.rs+++ b/src/server/hires.rs@@ -275,7 +275,7 @@ async fn propose(state: &AppState, scope: &SelfScope, space: &SpaceId, args: &Vaif let Some(k) = ["env", "headers", "api_key", "password", "token", "mcp_env", "profile_id"].iter().find(|k| args.get(**k).is_some()) {return fail(format!("Nothing was proposed: {k} is not something you can give a new bot. A new bot gets no keys or accounts; the person adds \- them in Space settings → Accounts or Tools."+ them in Settings › This space › Accounts or Tools."));}if let Some(t) = &scope.turn_id {diff --git a/tests/account_notice_test.rs b/tests/account_notice_test.rsindex 9db2f657..2c133315 100644--- a/tests/account_notice_test.rs+++ b/tests/account_notice_test.rs@@ -2,6 +2,9 @@//! even when this machine's env points Claude Code at another provider, and its first status//! line names the account. Its own test binary: it changes PATH and the process env.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -84,12 +87,7 @@ async fn personal_turn_names_its_account_and_ignores_this_machines_provider() {let bin = tmp.path().join("bin");std::fs::create_dir_all(&bin).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));// This machine's Claude Code runs on Bedrock through a proxy; Personal must notstd::env::set_var("CLAUDE_CODE_USE_BEDROCK", "1");diff --git a/tests/bot_actions_test.rs b/tests/bot_actions_test.rsindex 4a7bb0f4..a9459d46 100644--- a/tests/bot_actions_test.rs+++ b/tests/bot_actions_test.rs@@ -534,7 +534,7 @@ async fn switching_bots_tools_off_is_refused_directly() {let token = turn(&e, "t-tools").await;for key in ["agent_tools", "agent_tools_enabled", "tools"] {let text = refused(&e, &token, "settings_update", json!({"settings": {key: false}})).await;- assert!(text.contains("Refused") && text.contains("App settings") && !text.contains("no setting"), "{key}: {text}");+ assert!(text.contains("Refused") && text.contains("› All spaces") && !text.contains("no setting"), "{key}: {text}");}assert!(actions(&e).await.is_empty());}diff --git a/tests/browser_user_agent_test.rs b/tests/browser_user_agent_test.rsindex c4b1c317..8bb6975e 100644--- a/tests/browser_user_agent_test.rs+++ b/tests/browser_user_agent_test.rs@@ -1,8 +1,10 @@//! The user agent for `web_fetch` asks the local Chrome for its version without stalling the async//! worker it runs on. Its own test binary, since the answer is worked out once per process.#![cfg(unix)]+#[path = "common/exe.rs"]+mod exe;+use kwnt::sandbox::computer;-use std::os::unix::fs::PermissionsExt;use std::sync::atomic::{AtomicU32, Ordering};use std::sync::Arc;use std::time::Duration;@@ -12,8 +14,7 @@ async fn a_slow_chrome_version_does_not_block_the_worker() {// a Chrome whose `--version` takes a second, like a snap wrapper on a cold startlet dir = tempfile::tempdir().unwrap();let chrome = dir.path().join("chrome");- std::fs::write(&chrome, "#!/bin/sh\nsleep 1\necho 'Chromium 150.1.2.3'\n").unwrap();- std::fs::set_permissions(&chrome, std::fs::Permissions::from_mode(0o755)).unwrap();+ exe::write_executable(&chrome, "#!/bin/sh\nsleep 1\necho 'Chromium 150.1.2.3'\n");std::env::set_var(computer::CHROME_PATH_ENV, &chrome);// on a one-thread runtime, this only ticks while the probe leaves the thread freediff --git a/tests/chain_budget_test.rs b/tests/chain_budget_test.rsindex 98279ff6..903c7d6f 100644--- a/tests/chain_budget_test.rs+++ b/tests/chain_budget_test.rs@@ -2,6 +2,9 @@//! heavy usage (mostly cache reads) and @mentions a teammate when asked to, so one person message//! can start a chain of hand-offs. Its own test binary: it changes PATH.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -45,12 +48,7 @@ fn fake_cli() {let bin = tempfile::tempdir().unwrap().keep().join("bin");std::fs::create_dir_all(&bin).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));bin});diff --git a/tests/chain_order_test.rs b/tests/chain_order_test.rsindex aecd8552..8a826f40 100644--- a/tests/chain_order_test.rs+++ b/tests/chain_order_test.rs@@ -5,6 +5,9 @@//! results. A first line "FAIL" fails the turn and "WAIT:<file>" holds it until that file exists.//! Every prompt is saved as `$KWNT_TEST_PROMPTS/<name>-<ns>`. Its own test binary: it changes PATH.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -68,12 +71,7 @@ fn dirs() -> &'static Dirs {std::fs::create_dir_all(d).unwrap();}let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("KWNT_TEST_PROMPTS", &prompts);std::env::set_var("KWNT_TEST_BEHAVE", &behave);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));diff --git a/tests/channel_decisions_test.rs b/tests/channel_decisions_test.rsindex d1d7cee0..80c56129 100644--- a/tests/channel_decisions_test.rs+++ b/tests/channel_decisions_test.rs@@ -2,6 +2,9 @@//! (choice chips), as in direct chats, and a garbled block is never shown raw. A fake claude CLI//! answers by keyword. Its own test binary: it changes PATH.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -48,12 +51,7 @@ fn fake_cli() {let bin = tempfile::tempdir().unwrap().keep().join("bin");std::fs::create_dir_all(&bin).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));bin});diff --git a/tests/channel_routing_test.rs b/tests/channel_routing_test.rsindex b3739d29..71897dd8 100644--- a/tests/channel_routing_test.rs+++ b/tests/channel_routing_test.rs@@ -3,6 +3,9 @@//! a channel that starts with one bot gets Laya once `PATCH /api/channels/:id` adds members.//! A fake claude CLI answers turns. Its own test binary: it changes PATH.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -40,12 +43,7 @@ fn fake_cli() {let bin = tempfile::tempdir().unwrap().keep().join("bin");std::fs::create_dir_all(&bin).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));bin});diff --git a/tests/common/exe.rs b/tests/common/exe.rsnew file mode 100644index 00000000..6620745e--- /dev/null+++ b/tests/common/exe.rs@@ -0,0 +1,25 @@+//! Fake CLIs that a test writes and then runs.+//!+//! `std::fs::write` followed by running the file is racy in a test binary: while this process+//! has the file open for writing, any other test thread that spawns a process forks a child+//! holding a copy of that write descriptor until the child execs, and running a file that some+//! process still has open for writing fails with ETXTBSY ("Text file busy"). So the bytes go to a+//! sibling file and `install`, its own process whose descriptors no fork of ours can inherit,+//! makes the executable, which is then renamed into place (a new inode, even when replacing).++use std::path::{Path, PathBuf};++pub fn write_executable(path: impl AsRef<Path>, body: impl AsRef<[u8]>) {+ let path = path.as_ref();+ let with_suffix = |s: &str| -> PathBuf {+ let mut p = path.as_os_str().to_owned();+ p.push(s);+ p.into()+ };+ let (src, staged) = (with_suffix(".body"), with_suffix(".staged"));+ std::fs::write(&src, body).unwrap();+ let status = std::process::Command::new("install").arg("-m").arg("755").arg(&src).arg(&staged).status().unwrap();+ assert!(status.success(), "install {} failed: {status}", staged.display());+ std::fs::rename(&staged, path).unwrap();+ std::fs::remove_file(&src).unwrap();+}diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex 1758ad8c..8d82e279 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -11,6 +11,8 @@//! Each test file that uses it is its own binary, because it changes PATH.#![allow(dead_code)]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -94,12 +96,7 @@ pub fn prompts_dir() -> &'static PathBuf {std::fs::create_dir_all(&bin).unwrap();std::fs::create_dir_all(&prompts).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("KWNT_TEST_PROMPTS", &prompts);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));promptsdiff --git a/tests/decide_first_test.rs b/tests/decide_first_test.rsindex 3c17c505..b3c5c7b1 100644--- a/tests/decide_first_test.rs+++ b/tests/decide_first_test.rs@@ -3,6 +3,9 @@//! that keeps a note of how the person decides. A fake claude CLI answers by keyword. Its own test//! binary: it changes PATH.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -50,12 +53,7 @@ fn fake_cli() {let bin = tempfile::tempdir().unwrap().keep().join("bin");std::fs::create_dir_all(&bin).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));bin});diff --git a/tests/delegation_test.rs b/tests/delegation_test.rsindex 3b24386b..fe4a3b96 100644--- a/tests/delegation_test.rs+++ b/tests/delegation_test.rs@@ -2,6 +2,9 @@//! prompt and holds a "LONGTASK:<file>" turn until that file exists, so a test can keep a delegated//! turn running while it talks to the same agent elsewhere. Its own test binary: it changes PATH.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -68,12 +71,7 @@ fn prompts_dir() -> &'static PathBuf {std::fs::create_dir_all(&bin).unwrap();std::fs::create_dir_all(&prompts).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("KWNT_TEST_PROMPTS", &prompts);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));promptsdiff --git a/tests/engine_login_test.rs b/tests/engine_login_test.rsindex a94061a3..e36dde8a 100644--- a/tests/engine_login_test.rs+++ b/tests/engine_login_test.rs@@ -2,6 +2,9 @@//! against a fake `claude` that prints a sign-in link and waits for the pasted code.#![cfg(unix)]+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -59,12 +62,10 @@ struct Env {}async fn setup_with(timeout: Duration) -> Env {- use std::os::unix::fs::PermissionsExt;logs();let tmp = tempdir().unwrap();let bin = tmp.path().join("claude");- std::fs::write(&bin, FAKE_CLAUDE).unwrap();- std::fs::set_permissions(&bin, std::fs::Permissions::from_mode(0o755)).unwrap();+ exe::write_executable(&bin, FAKE_CLAUDE);let home = tmp.path().join("claude-home");let db = Database::init(tmp.path()).await.unwrap();let config = Config { data_dir: tmp.path().to_path_buf(), ..Config::default() };diff --git a/tests/engine_model_test.rs b/tests/engine_model_test.rsindex 75835366..e6cad82a 100644--- a/tests/engine_model_test.rs+++ b/tests/engine_model_test.rs@@ -2,6 +2,9 @@//! turned off in Settings are never checked, routed to or offered to Laya. Fake claude, codex//! and grok CLIs log their argv. Its own test binary: it changes PATH, HOME and the process env.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -147,12 +150,7 @@ async fn laya_picks_model_tier_pins_and_engine_switches() {std::fs::create_dir_all(&bin).unwrap();for (name, script) in [("claude", FAKE_CLAUDE), ("codex", FAKE_CODEX), ("grok", FAKE_GROK)] {let fake = bin.join(name);- std::fs::write(&fake, script).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, script);}std::env::set_var("PATH", format!("{}:/usr/bin:/bin", bin.display()));std::env::set_var("HOME", tmp.path());diff --git a/tests/engine_probe_test.rs b/tests/engine_probe_test.rsindex d0baeb01..cbc9e533 100644--- a/tests/engine_probe_test.rs+++ b/tests/engine_probe_test.rs@@ -1,6 +1,9 @@//! Each engine check against fake CLIs (signed in, signed out, broken, hanging) and a fake//! provider API, so every status and reason is pinned without touching real accounts.+#[path = "common/exe.rs"]+mod exe;+use axum::{extract::State,http::{HeaderMap, StatusCode},@@ -14,12 +17,7 @@ use std::time::{Duration, Instant};fn script(dir: &Path, name: &str, body: &str) -> Option<String> {let path = dir.join(name);- std::fs::write(&path, format!("#!/bin/sh\n{body}\n")).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&path, format!("#!/bin/sh\n{body}\n"));Some(path.to_string_lossy().into_owned())}diff --git a/tests/engine_routing_test.rs b/tests/engine_routing_test.rsindex 2c197e00..98cea658 100644--- a/tests/engine_routing_test.rs+++ b/tests/engine_routing_test.rs@@ -2,6 +2,9 @@//! and with nothing usable the turn says so instead of using another engine. A fake claude CLI//! is the only engine on PATH. Its own test binary: it changes PATH, HOME and the process env.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -89,12 +92,7 @@ async fn turns_skip_engines_that_cannot_run() {let bin = tmp.path().join("bin");std::fs::create_dir_all(&bin).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);// Only the fake claude: no real CLIs from PATH or ~/.local/bin, no host keysstd::env::set_var("PATH", format!("{}:/usr/bin:/bin", bin.display()));std::env::set_var("HOME", tmp.path());@@ -184,7 +182,7 @@ async fn turns_skip_engines_that_cannot_run() {// 4. Nothing can run now: a clear message, and no CLI is startedlet text = turn_text(&app, &state, &kid).await;- assert!(text.contains("No account can run bots here yet. Add one in Space settings → Accounts."), "{text}");+ assert!(text.contains("No account can run bots here yet. Add one in Settings › This space › Accounts."), "{text}");assert_eq!(turns_run(tmp.path()), 2);// 5. Signed in again and re-checked: claude is back. A kwant pinned to codex (not installed)diff --git a/tests/fixtures/truth_ledger_off_prompt_895a96c.txt b/tests/fixtures/truth_ledger_off_prompt_895a96c.txtindex abfb319c..69ff83f1 100644--- a/tests/fixtures/truth_ledger_off_prompt_895a96c.txt+++ b/tests/fixtures/truth_ledger_off_prompt_895a96c.txt@@ -15,7 +15,7 @@ If you have the `kwnt_tools` tools:- `page_source` reads a public page's HTML source: the <head> (title, meta description, canonical, robots, hreflang, Open Graph), headings, image alt text, links and structured data, none of which WebFetch or the browser shows. It never needs the user's approval.- When a request needs an app you can't reach (Google Search Console, Google Analytics, a CRM…), `connection_suggest` posts a one-tap connection card. Post it in the same turn rather than asking whether to: it connects nothing until the user signs in. Never end with an offer to post one ("I can suggest a connection if you'd like"): post it, then carry on with everything you can do without it.- Before you call anything impossible, try the fallback: `page_source` for a page's tags and attributes, the browser for a site's own free tool (pagespeed.web.dev when the PageSpeed API is rate-limited), web search for public data. When access is truly missing, offer the concrete fix: `connection_suggest` for an app, `mcp_search` and `mcp_suggest` for a tool server, or the exact key and where the user adds it. A bare "not possible" with no offered fix is the exception; then say what you tried.-- You can set up and manage the app yourself; when asked, do it in that same turn instead of telling the user how. When the user wants something to happen on its own ("every morning", "each Friday", "remind me at 5"), `routine_create` schedules it (it runs as you and replies in this chat by default; calendar rules like "the 1st of each month" use a monthly or cron schedule); `follow_up_create` schedules a one-off check-in by you here; `routine_list`, `routine_update`, `routine_pause`, `routine_resume`, `routine_run_now` and `routine_delete` manage routines. `bot_list`, `bot_create` and `bot_update` add and change bots, `settings_get`/`settings_update` change non-secret settings such as the time zone, and `space_*` and `channel_*` manage your space and its channels. Each change applies at once and the user sees a card with Undo; afterwards say in one sentence what will happen. The user may undo a change later, so check with the list tools before relying on an earlier one. Deleting a bot, a space or an account only asks the user to confirm. Never handle keys, passwords or sign-ins, answer approvals, install tool servers, switch bots' tools on or off or change the computer: those tools tell you where in Settings the user does it. Bots' own tools are the user's switch in App settings (gear at the bottom of the space rail) → "Bots can use their own tools"; say that outright.+- You can set up and manage the app yourself; when asked, do it in that same turn instead of telling the user how. When the user wants something to happen on its own ("every morning", "each Friday", "remind me at 5"), `routine_create` schedules it (it runs as you and replies in this chat by default; calendar rules like "the 1st of each month" use a monthly or cron schedule); `follow_up_create` schedules a one-off check-in by you here; `routine_list`, `routine_update`, `routine_pause`, `routine_resume`, `routine_run_now` and `routine_delete` manage routines. `bot_list`, `bot_create` and `bot_update` add and change bots, `settings_get`/`settings_update` change non-secret settings such as the time zone, and `space_*` and `channel_*` manage your space and its channels. Each change applies at once and the user sees a card with Undo; afterwards say in one sentence what will happen. The user may undo a change later, so check with the list tools before relying on an earlier one. Deleting a bot, a space or an account only asks the user to confirm. Never handle keys, passwords or sign-ins, answer approvals, install tool servers, switch bots' tools on or off or change the computer: those tools tell you where in Settings the user does it. Bots' own tools are the user's switch in Settings › All spaces → "Bots can use their own tools"; say that outright.- `propose_hire` proposes a new bot for work a specialist would do better; the person decides. `hire_status` shows the space's hire policy and decisions.[How to work]diff --git a/tests/grok_driver_test.rs b/tests/grok_driver_test.rsindex a00fe36f..45b37342 100644--- a/tests/grok_driver_test.rs+++ b/tests/grok_driver_test.rs@@ -2,6 +2,9 @@//! only the user's model settings and login, and cleans up after itself.#![cfg(unix)]+#[path = "common/exe.rs"]+mod exe;+use kwnt::{db::models::Kwant,db::models::McpServer,@@ -94,9 +97,7 @@ impl FakeGrok {{body}\n");let path = dir.path().join("grok");- std::fs::write(&path, script).unwrap();- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)).unwrap();+ exe::write_executable(&path, script);Self { dir, user_home }}diff --git a/tests/handoff_continue_test.rs b/tests/handoff_continue_test.rsindex c37fe5ab..c5dec11b 100644--- a/tests/handoff_continue_test.rs+++ b/tests/handoff_continue_test.rs@@ -6,6 +6,9 @@//! prompt unless it is a carry-on turn and holds a "LONGTASK:<file>" turn until that file exists.//! Its own test binary: it changes PATH.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -54,12 +57,7 @@ fn prompts_dir() -> &'static PathBuf {std::fs::create_dir_all(&bin).unwrap();std::fs::create_dir_all(&prompts).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("KWNT_TEST_PROMPTS", &prompts);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));promptsdiff --git a/tests/handoff_folder_test.rs b/tests/handoff_folder_test.rsindex 9915f7bc..51fb0ac0 100644--- a/tests/handoff_folder_test.rs+++ b/tests/handoff_folder_test.rs@@ -4,6 +4,9 @@//! in its own folder and found nothing). A fake claude CLI on PATH records the folder each audit//! turn runs in. Its own test binary: it changes PATH.+#[path = "common/exe.rs"]+mod exe;+use kwnt::{broker::PermissionBroker,config::Config,@@ -41,12 +44,7 @@ fn cwd_dir() -> &'static PathBuf {std::fs::create_dir_all(&bin).unwrap();std::fs::create_dir_all(&cwd).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("KWNT_TEST_CWD", &cwd);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));cwddiff --git a/tests/handoff_review_test.rs b/tests/handoff_review_test.rsindex c9c42c9a..1ea003e6 100644--- a/tests/handoff_review_test.rs+++ b/tests/handoff_review_test.rs@@ -7,6 +7,9 @@//! turn, and a one-way hand-off is closed. A fake claude CLI on PATH answers every turn with//! "done" (so a lead never calls task_review). Its own test binary: it changes PATH.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -51,12 +54,7 @@ fn prompts_dir() -> &'static PathBuf {std::fs::create_dir_all(&bin).unwrap();std::fs::create_dir_all(&prompts).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("KWNT_TEST_PROMPTS", &prompts);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));promptsdiff --git a/tests/initiative_test.rs b/tests/initiative_test.rsindex 94c83aa7..deba7de2 100644--- a/tests/initiative_test.rs+++ b/tests/initiative_test.rs@@ -337,6 +337,6 @@ async fn bots_with_tools_are_told_how_to_work_and_bots_without_are_not() {assert!(section.contains(words), "{words}: {section}");}// Bots' own tools can only be refused by name: the prompt says where the person switches them- assert!(with.contains("App settings (gear at the bottom of the space rail) → \"Bots can use their own tools\""), "{with}");+ assert!(with.contains("Settings › All spaces → \"Bots can use their own tools\""), "{with}");assert!(section.len() < 2000, "keep it tight: {} bytes", section.len());}diff --git a/tests/mcp_runtime_test.rs b/tests/mcp_runtime_test.rsindex dc54b15b..8e4e4e3d 100644--- a/tests/mcp_runtime_test.rs+++ b/tests/mcp_runtime_test.rs@@ -1,5 +1,8 @@//! Turn-time MCP: broker approvals, the claude permission endpoint and the claude config file.+#[path = "common/exe.rs"]+mod exe;+use kwnt::{broker::{ApprovalDecision, PermissionBroker},config::Config,@@ -313,16 +316,7 @@ fn turn(mcp: Option<McpTurnContext>) -> TurnInput {async fn fake_cli_run(kind: &str, mcp: Option<McpTurnContext>) -> String {let dir = tempdir().unwrap();let script = dir.path().join("fake-cli");- std::fs::write(- &script,- "#!/bin/sh\necho \"ARGS: $*\"\nwhile [ $# -gt 0 ]; do\n if [ \"$1\" = --mcp-config ]; then echo \"MODE: $(stat -c %a \"$2\")\"; fi\n shift\ndone\necho \"TOOL_TIMEOUT: $MCP_TOOL_TIMEOUT\"\n",- )- .unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&script, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&script, "#!/bin/sh\necho \"ARGS: $*\"\nwhile [ $# -gt 0 ]; do\n if [ \"$1\" = --mcp-config ]; then echo \"MODE: $(stat -c %a \"$2\")\"; fi\n shift\ndone\necho \"TOOL_TIMEOUT: $MCP_TOOL_TIMEOUT\"\n");let driver = CliDriver::new(Some(script.to_string_lossy().into_owned()), Some(kind.into()));let (tx, mut rx) = tokio::sync::mpsc::channel(64);let drain = tokio::spawn(async move { while rx.recv().await.is_some() {} });@@ -375,20 +369,14 @@ async fn fake_agent_run(kind: &str, mcp: Option<McpTurnContext>, mcp_list: Optio}None => "exit 3".to_string(),};- std::fs::write(+ exe::write_executable(&script,format!("#!/bin/sh\nif [ \"$1 $2 $3\" = \"mcp list --json\" ]; then {list_cmd}; fi\necho \"$*\" > {}\necho \"${{KWNT_MCP_GATEWAY_TOKEN:-unset}}\" > {}\n",log.display(),env_log.display()),- )- .unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&script, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ );let driver = CliDriver::new(Some(script.to_string_lossy().into_owned()), Some(kind.into()));let (tx, mut rx) = tokio::sync::mpsc::channel(64);let drain = tokio::spawn(async move {@@ -498,15 +486,7 @@ async fn aborting_a_cli_turn_kills_the_cli() {let dir = tempdir().unwrap();let script = dir.path().join("codex");let pid_file = dir.path().join("pid");- std::fs::write(- &script,- format!("#!/bin/sh\nif [ \"$1\" = mcp ]; then echo '[]'; exit 0; fi\necho $$ > {}\nexec sleep 60\n", pid_file.display()),- )- .unwrap();- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&script, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&script, format!("#!/bin/sh\nif [ \"$1\" = mcp ]; then echo '[]'; exit 0; fi\necho $$ > {}\nexec sleep 60\n", pid_file.display()));let driver = CliDriver::new(Some(script.to_string_lossy().into_owned()), Some("codex".into()));let (tx, mut rx) = tokio::sync::mpsc::channel(64);tokio::spawn(async move { while rx.recv().await.is_some() {} });diff --git a/tests/mission_autofix_test.rs b/tests/mission_autofix_test.rsindex 0d73d24d..79ad70ba 100644--- a/tests/mission_autofix_test.rs+++ b/tests/mission_autofix_test.rs@@ -5,6 +5,9 @@//! numbered as there. Its own test binary: it changes PATH and listens on a real port the//! stand-in CLI calls back on.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -71,8 +74,7 @@ fn fake_cli() -> PathBuf {let bin = tempfile::tempdir().unwrap().keep().join("bin");std::fs::create_dir_all(&bin).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));bin})diff --git a/tests/mission_checkpoints_test.rs b/tests/mission_checkpoints_test.rsindex 90491d54..28d6b22a 100644--- a/tests/mission_checkpoints_test.rs+++ b/tests/mission_checkpoints_test.rs@@ -5,6 +5,9 @@//! gaps: the retry `Idempotency-Key` and the drift scan's limits. Its own test binary: it changes//! PATH and listens on a real port the stand-in CLI calls back on.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -75,8 +78,7 @@ fn fake_cli() {let bin = tempfile::tempdir().unwrap().keep().join("bin");std::fs::create_dir_all(&bin).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));bin});diff --git a/tests/mission_spend_test.rs b/tests/mission_spend_test.rsindex 390f31d2..ea4edf51 100644--- a/tests/mission_spend_test.rs+++ b/tests/mission_spend_test.rs@@ -6,6 +6,9 @@//! double count), and the mission budget must use that number. Its own test binary: it changes//! PATH and listens on a real port the CLI calls back on.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -72,12 +75,7 @@ fn fake_cli() {let bin = tempfile::tempdir().unwrap().keep().join("bin");std::fs::create_dir_all(&bin).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));bin});diff --git a/tests/profile_failover_test.rs b/tests/profile_failover_test.rsindex 07a95f96..ec9dfa46 100644--- a/tests/profile_failover_test.rs+++ b/tests/profile_failover_test.rs@@ -1,6 +1,9 @@//! A turn whose profile is out of usage moves to the engine's next profile, with a fake claude//! CLI on PATH. Its own test binary: it changes PATH and the process env.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -86,12 +89,7 @@ async fn out_of_usage_profile_fails_over_once_and_pinned_turns_give_up() {let bin = tmp.path().join("bin");std::fs::create_dir_all(&bin).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("PATH",format!(diff --git a/tests/routine_failure_test.rs b/tests/routine_failure_test.rsindex ad7aff69..239050e9 100644--- a/tests/routine_failure_test.rs+++ b/tests/routine_failure_test.rs@@ -1,6 +1,9 @@//! A routine whose engine can't run records why in its history, not just that it failed. Uses a//! signed-out fake claude CLI on PATH, so it is its own test binary: it changes the process env.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -55,12 +58,7 @@ async fn failed_routine_run_records_the_engine_error() {let bin = tmp.path().join("bin");std::fs::create_dir_all(&bin).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);let crash = tmp.path().join("crash");std::env::set_var("CRASH", &crash);std::env::set_var(diff --git a/tests/spaces_api_test.rs b/tests/spaces_api_test.rsindex 758b39f1..5e2f9def 100644--- a/tests/spaces_api_test.rs+++ b/tests/spaces_api_test.rs@@ -3,6 +3,9 @@//! restore, the Default archive refusal and team folder collisions are covered too. A fake claude//! CLI on PATH answers turns, so no real engine is ever called. Its own test binary: it changes PATH.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -37,12 +40,7 @@ fn fake_cli() {let bin = tempfile::tempdir().unwrap().keep().join("bin");std::fs::create_dir_all(&bin).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));bin});diff --git a/tests/spaces_isolation_test.rs b/tests/spaces_isolation_test.rsindex 64be7c21..2d0414ce 100644--- a/tests/spaces_isolation_test.rs+++ b/tests/spaces_isolation_test.rs@@ -4,6 +4,9 @@//! CLI on PATH records the folder it ran in and the prompt, so no real engine is ever called.//! Its own test binary: it changes PATH.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -53,12 +56,7 @@ fn prompts_dir() -> &'static PathBuf {std::fs::create_dir_all(&bin).unwrap();std::fs::create_dir_all(&prompts).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("KWNT_TEST_PROMPTS", &prompts);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));promptsdiff --git a/tests/spaces_s2_fixes_test.rs b/tests/spaces_s2_fixes_test.rsindex e995754c..b35ea18e 100644--- a/tests/spaces_s2_fixes_test.rs+++ b/tests/spaces_s2_fixes_test.rs@@ -5,6 +5,9 @@//! A fake claude CLI on PATH answers turns; `SLEEPY:<tag>` in the prompt makes it start a `sleep`//! child, write both pids under `KWNT_S2_PIDS`, and wait. Its own test binary: it changes PATH.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -51,12 +54,7 @@ fn pids_dir() -> &'static PathBuf {std::fs::create_dir_all(&bin).unwrap();std::fs::create_dir_all(&pids).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("KWNT_S2_PIDS", &pids);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));pidsdiff --git a/tests/turn_recovery_test.rs b/tests/turn_recovery_test.rsindex 3f623d9e..eea3d899 100644--- a/tests/turn_recovery_test.rs+++ b/tests/turn_recovery_test.rs@@ -2,6 +2,9 @@//! visible reason (but not while a tool runs, and never an API reply that is just slow), and//! replies cut short by a restart are marked interrupted on the next start.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -50,12 +53,7 @@ fn fake_claude() {let bin = tempfile::tempdir().unwrap().keep().join("bin");std::fs::create_dir_all(&bin).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));bin});diff --git a/tests/waiting_test.rs b/tests/waiting_test.rsindex adae0e00..8cb0bb7c 100644--- a/tests/waiting_test.rs+++ b/tests/waiting_test.rs@@ -5,6 +5,9 @@//! a first line "ASK:<question>" makes it call `AskUserQuestion` (choices Yes / No) before it//! replies with the rest. Its own test binary: it changes PATH.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -57,12 +60,7 @@ fn behave_dir() -> &'static PathBuf {std::fs::create_dir_all(d).unwrap();}let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("KWNT_TEST_BEHAVE", &behave);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));behavediff --git a/tests/work_ahead_test.rs b/tests/work_ahead_test.rsindex 2c39e5b4..bf5aeca5 100644--- a/tests/work_ahead_test.rs+++ b/tests/work_ahead_test.rs@@ -3,6 +3,9 @@//! a second run before the person writes again all start nothing. A fake claude CLI answers by//! keyword. Its own test binary: it changes PATH.+#[path = "common/exe.rs"]+mod exe;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -51,12 +54,7 @@ fn fake_cli() {let bin = tempfile::tempdir().unwrap().keep().join("bin");std::fs::create_dir_all(&bin).unwrap();let fake = bin.join("claude");- std::fs::write(&fake, FAKE_CLAUDE).unwrap();- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();- }+ exe::write_executable(&fake, FAKE_CLAUDE);std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));bin});