From 71593d7a89c7fa53d7c118bd0dc84d19516aca08 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sat, 21 Nov 2026 09:22:31 -0800 Subject: [PATCH 1/3] Pin the Harness at `6efe4ad7` and use `Host::builder` The Harness at `6efe4ad7` builds a `Host` through a builder that loads the Plugins and keeps a report for each, and it takes the timer of a run in `RunSetup::new`. Workshop built its `Host` from a registry that it filled itself, kept the report of its Plugin directory beside the `Host`, and gave the `Host` its timer. `with_plugins` is now one builder chain that returns the `Host`, and the setup of each run names `TokioTimer`. - `host_packs` becomes `server_host`, which takes the finder first and returns the built `Host`, as `with_plugins` does. - `agent_finder` returns its finder inside an `Arc`, as the stock finders of the Harness do. - `load_plugin_dir` goes. The builder loads the directory, and the Harness logs each Plugin and each failure through `tracing` as it builds the `Host`. The warning for an mcp Plugin that inserted no Pack goes for the same reason. - A Plugin directory that does not exist stays a state: `with_plugins` leaves it out of the builder when `try_exists` reports that it is missing. A directory that cannot be read for another reason is a failure of its report. - `holds` asks the built `Host`, and the warning for a shipped Pack that is missing runs after the build. - `Inner` loses `_plugins`, because the `Host` keeps each Plugin that it loaded. - `setup_for` is one chain, where it used struct update syntax. - In the tests, `serving` gives one source under every name, and `run_prompt`, `run_prompt_over`, and `run_agent_on` take the built `Host`. `directory_report`, `loaded`, and `assert_no_failures` read the report of the Plugin directory from `plugin_reports`. - A test with no Plugin directory asserted that no report came back. Its `Host` has the report of the mcp Plugin, so the test asserts that this is the one report and that it holds no Plugin. - `Cargo.lock` changes its 14 `source` lines of the Harness packages and gains two lines under `harness-runner`. - No test is added or removed. --- Cargo.lock | 30 ++- Cargo.toml | 6 +- crates/workshop/agents/tests/it/support.rs | 17 +- crates/workshop/server/src/agents.rs | 163 +++++------- .../server/src/agents/bindings-tests.rs | 7 +- .../server/src/agents/language_guide/tests.rs | 45 ++-- crates/workshop/server/src/agents/tests.rs | 249 ++++++++++-------- 7 files changed, 268 insertions(+), 249 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 38ebe4e4..fd3ccf16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2242,7 +2242,7 @@ dependencies = [ [[package]] name = "harness-gateway-client" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f87bfbf5155dae6b8b6ed2752b29fb91ac29c182#f87bfbf5155dae6b8b6ed2752b29fb91ac29c182" +source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" dependencies = [ "bytes", "reqwest", @@ -2256,7 +2256,7 @@ dependencies = [ [[package]] name = "harness-plugin-loader" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f87bfbf5155dae6b8b6ed2752b29fb91ac29c182#f87bfbf5155dae6b8b6ed2752b29fb91ac29c182" +source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" dependencies = [ "libloading 0.8.9", "runvil-plugin", @@ -2267,12 +2267,14 @@ dependencies = [ [[package]] name = "harness-runner" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f87bfbf5155dae6b8b6ed2752b29fb91ac29c182#f87bfbf5155dae6b8b6ed2752b29fb91ac29c182" +source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" dependencies = [ "futures-util", + "harness-plugin-loader", "rand 0.9.5", "runvil-engine", "runvil-plugin", + "runvil-plugin-sys", "serde_json", "tracing", ] @@ -4056,7 +4058,7 @@ dependencies = [ [[package]] name = "plugin-mcp" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f87bfbf5155dae6b8b6ed2752b29fb91ac29c182#f87bfbf5155dae6b8b6ed2752b29fb91ac29c182" +source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" dependencies = [ "reqwest", "rmcp", @@ -4724,7 +4726,7 @@ dependencies = [ [[package]] name = "runvil" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f87bfbf5155dae6b8b6ed2752b29fb91ac29c182#f87bfbf5155dae6b8b6ed2752b29fb91ac29c182" +source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" dependencies = [ "harness-plugin-loader", "harness-runner", @@ -4735,7 +4737,7 @@ dependencies = [ [[package]] name = "runvil-engine" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f87bfbf5155dae6b8b6ed2752b29fb91ac29c182#f87bfbf5155dae6b8b6ed2752b29fb91ac29c182" +source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" dependencies = [ "runvil-lua", "runvil-model-client", @@ -4748,7 +4750,7 @@ dependencies = [ [[package]] name = "runvil-lua" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f87bfbf5155dae6b8b6ed2752b29fb91ac29c182#f87bfbf5155dae6b8b6ed2752b29fb91ac29c182" +source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" dependencies = [ "mlua", "runvil-markdown", @@ -4762,7 +4764,7 @@ dependencies = [ [[package]] name = "runvil-markdown" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f87bfbf5155dae6b8b6ed2752b29fb91ac29c182#f87bfbf5155dae6b8b6ed2752b29fb91ac29c182" +source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" dependencies = [ "pulldown-cmark", "serde_json", @@ -4772,7 +4774,7 @@ dependencies = [ [[package]] name = "runvil-model-client" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f87bfbf5155dae6b8b6ed2752b29fb91ac29c182#f87bfbf5155dae6b8b6ed2752b29fb91ac29c182" +source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" dependencies = [ "runvil-types", "serde", @@ -4782,7 +4784,7 @@ dependencies = [ [[package]] name = "runvil-plugin" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f87bfbf5155dae6b8b6ed2752b29fb91ac29c182#f87bfbf5155dae6b8b6ed2752b29fb91ac29c182" +source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" dependencies = [ "runvil-types", "runvil-vfs", @@ -4805,7 +4807,7 @@ source = "git+https://github.com/cppalliance/runvil-plugin-api?rev=74f9e08ba9cc5 [[package]] name = "runvil-prompt" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f87bfbf5155dae6b8b6ed2752b29fb91ac29c182#f87bfbf5155dae6b8b6ed2752b29fb91ac29c182" +source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" dependencies = [ "pulldown-cmark", "runvil-lua", @@ -4818,7 +4820,7 @@ dependencies = [ [[package]] name = "runvil-runtime" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f87bfbf5155dae6b8b6ed2752b29fb91ac29c182#f87bfbf5155dae6b8b6ed2752b29fb91ac29c182" +source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" dependencies = [ "mlua", "regex", @@ -4836,7 +4838,7 @@ dependencies = [ [[package]] name = "runvil-types" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f87bfbf5155dae6b8b6ed2752b29fb91ac29c182#f87bfbf5155dae6b8b6ed2752b29fb91ac29c182" +source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" dependencies = [ "serde", "serde_json", @@ -4846,7 +4848,7 @@ dependencies = [ [[package]] name = "runvil-vfs" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f87bfbf5155dae6b8b6ed2752b29fb91ac29c182#f87bfbf5155dae6b8b6ed2752b29fb91ac29c182" +source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" [[package]] name = "rust-embed" diff --git a/Cargo.toml b/Cargo.toml index ccafacc2..8a0ce04f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,9 +25,9 @@ repository = "https://github.com/cppalliance/runvil-workshop" # Workshop links in. All three name one commit, because two commits would # be two copies of every type the crates share. `version` beside `git` # keeps cargo-deny's wildcard check quiet. -runvil = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "f87bfbf5155dae6b8b6ed2752b29fb91ac29c182" } -harness-gateway-client = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "f87bfbf5155dae6b8b6ed2752b29fb91ac29c182" } -plugin-mcp = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "f87bfbf5155dae6b8b6ed2752b29fb91ac29c182" } +runvil = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "6efe4ad7c4d801adebb5b292e4ee7690581c5d35" } +harness-gateway-client = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "6efe4ad7c4d801adebb5b292e4ee7690581c5d35" } +plugin-mcp = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "6efe4ad7c4d801adebb5b292e4ee7690581c5d35" } # The safe layer over the C Plugin contract, version 0.6, from its own # repository, pinned by commit. Only the library Plugin crates under # `crates/workshop/` name it, for `export_plugin!`. The commit is the one diff --git a/crates/workshop/agents/tests/it/support.rs b/crates/workshop/agents/tests/it/support.rs index 1b078e36..37bca3e6 100644 --- a/crates/workshop/agents/tests/it/support.rs +++ b/crates/workshop/agents/tests/it/support.rs @@ -4,8 +4,7 @@ use std::sync::Arc; use harness_gateway_client::TokioTimer; -use runvil::harness::{FindTextPrompt, MemoryRecorder, OfflineBroker, Packs}; -use runvil::plugin::PackRegistry; +use runvil::harness::{FindTextPrompt, MemoryRecorder, OfflineBroker}; use runvil::{Host, RunSetup}; use workshop_agents::Conversation; @@ -29,12 +28,12 @@ pub(crate) fn run_for( recorder: Arc, source: String, ) -> (Arc, RunSetup) { - let host = Arc::new(Host { - packs: Packs::new(PackRegistry::new()), - prompts: Arc::new(FindTextPrompt::new(AGENT, source)), - timer: Arc::new(TokioTimer), - }); - let setup = - RunSetup::new(conversation.recorder(recorder), Arc::new(OfflineBroker)).has_user(true); + let host = Host::builder(FindTextPrompt::new(AGENT, source)).build(); + let setup = RunSetup::new( + conversation.recorder(recorder), + Arc::new(OfflineBroker), + Arc::new(TokioTimer), + ) + .has_user(true); (host, setup) } diff --git a/crates/workshop/server/src/agents.rs b/crates/workshop/server/src/agents.rs index 1c423bb2..4aae213b 100644 --- a/crates/workshop/server/src/agents.rs +++ b/crates/workshop/server/src/agents.rs @@ -5,21 +5,23 @@ //! conversations. The `/ws` workshop socket sits outside this subsystem; //! the two share only [`crate::websocket`]. //! -//! The server builds one [`Host`] at startup: its `Packs`, installed from -//! the linked mcp Plugin, over the servers of the configured `mcp.json`, -//! the library Plugins in the configured Plugin directory, the std Plugin -//! with the file-tool Pack, the bashkit Plugin with the shell Pack, and -//! the web Plugin with the web Pack among them, and the built-ins -//! subagents and user; a finder that reads each agent from the agents -//! folder through `load_agent`; and the stock tokio timer of the Gateway -//! client. Every tool call of a +//! The server builds one [`Host`] at startup, through its builder: a +//! finder that reads each agent from the agents folder through +//! `load_agent`, and its Plugins in the order they install. The linked +//! mcp Plugin is first, over the servers of the configured `mcp.json`. +//! The library Plugins in the configured Plugin directory follow, the +//! std Plugin with the file-tool Pack, the bashkit Plugin with the shell +//! Pack, and the web Plugin with the web Pack among them. Every Host has +//! the built-ins subagents and user beside their Packs. Every tool call +//! of a //! library Plugin is lent the server's [`resources`]: the Gateway the //! registry holds as the call starts, which is where the web Pack sends a //! search. Each launch opens a conversation in `workshop-agents` and builds //! that conversation's one run its own [`RunSetup`]: the conversation's //! recorder tee on a handle of the run log's [`TursoRecorder`] that names //! the launched agent, a per-run broker over the server's inference broker -//! ([`broker`]), and a user, the conversation's operator, so the run holds +//! ([`broker`]), the stock tokio timer of the Gateway client, and a user, +//! the conversation's operator, so the run holds //! `runvil/user`; the operator's messages reach the run's main chain //! through the conversation. The run makes its own instance of each Pack //! it holds and drops them when it ends. The run's model rounds reach the @@ -63,9 +65,9 @@ use std::sync::Arc; use harness_gateway_client::{ GatewayEndpoint, SecretString, TokioTimer, provide_gateway_resources, }; -use runvil::harness::{HostResources, Packs, PluginReport, RunId, insert_plugin_dir}; +use runvil::harness::{HostResources, RunId, insert_plugin_dir}; use runvil::plugin::PackRegistry; -use runvil::{Error, ErrorCode, ErrorFact, Host, RunSetup}; +use runvil::{Error, ErrorCode, ErrorFact, Host, PromptFinder, RunSetup}; use serde_json::Value; use workshop_agents::{ Conversation, ConversationId, Conversations, LaunchError, discover_agents, load_agent, @@ -85,18 +87,19 @@ pub(crate) use state::{SessionsState, register}; /// the `runs.db` every conversation's run is recorded in. const HARNESS_STATE_DIR: &str = "harness"; -/// The server's installed Packs, and what its Plugin directory loaded. +/// The server's Host, which finds its agents through `prompts`. /// `registry` holds the Gateway that each tool call of a library Plugin /// is lent ([`resources`]). `mcp` is the `[agents] mcp` setting: the mcp /// Pack is installed over the servers of the file it names. `plugins` is /// the `[agents] plugins` setting: the directory whose library Plugins /// are loaded. -fn host_packs( +fn server_host( + prompts: Arc, registry: &Registry, mcp: Option<&Path>, plugins: Option<&Path>, -) -> (Packs, Option) { - with_plugins(&resources(registry), read_mcp_servers(mcp), plugins) +) -> Arc { + with_plugins(prompts, resources(registry), read_mcp_servers(mcp), plugins) } /// The `mcpServers` object of the `mcp.json`-format file at `setting`, @@ -154,7 +157,8 @@ fn read_mcp_servers(setting: Option<&Path>) -> Value { } } -/// The Packs of the server's Host, and what its Plugin directory loaded. +/// The server's Host over its Plugins, which finds its agents through +/// `prompts`. /// /// The linked mcp Plugin installs first, over the `servers` object, with /// the handle of the runtime this is called on. It is installed only on a @@ -162,28 +166,40 @@ fn read_mcp_servers(setting: Option<&Path>) -> Value { /// is built without the mcp Pack and refuses a prompt that requires /// `mcp`. Then every library Plugin in the directory `plugins` loads, /// when the server is given one, and every tool call of its Packs is lent -/// `resources`. The std Plugin, whose Pack holds the file tools, the +/// `resources`. A directory that does not exist is a state, not a +/// failure: a build that has not placed its Plugins has none, so the Host +/// is built without that directory. The std Plugin, whose Pack holds the +/// file tools, the /// bashkit Plugin, whose Pack holds the shell, and the web Plugin, whose /// Pack holds the web tools, are three of those libraries, so a Host /// whose Plugin directory lacks one has no `std`, no `bash`, or no `web` /// Pack and refuses a prompt that requires it. A `tracing` warning says -/// so at startup. The registry also holds the built-ins `subagents` and +/// so at startup. Every Host also has the built-ins `subagents` and /// `user`, and each run makes its own instances of the Packs it holds. -/// The report lists each library Plugin that loaded and each failure. +/// +/// The Host keeps one report for each Plugin step: the mcp Plugin's, +/// when it is installed, and then the Plugin directory's, which lists +/// each library Plugin that loaded and each failure. The Harness logs +/// each of them through `tracing` as it builds the Host. fn with_plugins( - resources: &HostResources, + prompts: Arc, + resources: HostResources, servers: Value, plugins: Option<&Path>, -) -> (Packs, Option) { - let mut packs = PackRegistry::new(); - if let Ok(runtime) = tokio::runtime::Handle::try_current() - && let Err(error) = plugin_mcp::install(&mut packs, servers, runtime) - { - tracing::warn!(%error, "the mcp Plugin inserted no Pack"); +) -> Arc { + let mut builder = Host::builder(prompts).with_resources(resources); + if let Ok(runtime) = tokio::runtime::Handle::try_current() { + builder = + builder.with_rust_plugin(move |packs| plugin_mcp::install(packs, servers, runtime)); + } + // A directory that is known to be missing is a state: a build that has + // not placed its Plugins has none. + if let Some(directory) = plugins.filter(|directory| directory.try_exists().unwrap_or(true)) { + builder = builder.with_plugin_dir(directory); } - let report = plugins.and_then(|directory| load_plugin_dir(&mut packs, directory, resources)); + let host = builder.build(); for pack in SHIPPED_PACKS { - if !holds(&packs, pack) { + if !holds(&host, pack) { tracing::warn!( directory = ?plugins, pack, @@ -191,7 +207,7 @@ fn with_plugins( ); } } - (Packs::new(packs), report) + host } /// The Packs that only a library Plugin Workshop ships inserts: the file @@ -199,9 +215,9 @@ fn with_plugins( /// web tools, from the web Plugin. const SHIPPED_PACKS: [&str; 3] = ["runvil/std", "runvil/bash", "runvil/web"]; -/// Whether `packs` holds the Pack named `pack`, a vendor and a Pack id. -fn holds(packs: &PackRegistry, pack: &str) -> bool { - packs.list().any(|(info, _)| info.fqn == pack) +/// Whether `host` has the Pack named `pack`, a vendor and a Pack id. +fn holds(host: &Host, pack: &str) -> bool { + host.packs().any(|info| info.fqn == pack) } /// What the library Plugins in one directory do when they are loaded. @@ -249,49 +265,6 @@ pub fn list_plugin_dir(directory: &Path) -> io::Result { Ok(PluginListing { loaded, failed }) } -/// Loads every library Plugin in `directory` and returns the report of -/// what loaded, or `None` when the directory cannot be read. Every tool -/// call of a Plugin it loads is lent `resources`. A directory that does -/// not exist is a state, not a failure: a build that has not placed its -/// Plugins has none. Each Plugin that loaded is logged with its name, -/// version, and source, and each library that did not, with its path and -/// the reason; one failure never stops the others. -fn load_plugin_dir( - packs: &mut PackRegistry, - directory: &Path, - resources: &HostResources, -) -> Option { - let report = match insert_plugin_dir(packs, directory, resources) { - Ok(report) => report, - Err(error) if error.kind() == io::ErrorKind::NotFound => return None, - Err(error) => { - tracing::warn!( - directory = %directory.display(), - %error, - "the Plugin directory could not be read; no library Plugin is loaded" - ); - return None; - } - }; - for plugin in report.plugins() { - tracing::info!( - name = plugin.name(), - version = plugin.version(), - source = ?plugin.source(), - "loaded a library Plugin" - ); - } - for failure in report.failures() { - let path = failure - .facts - .get(&ErrorFact::Path) - .and_then(Value::as_str) - .unwrap_or_default(); - tracing::warn!(path, error = %failure, "a library Plugin did not load"); - } - Some(report) -} - /// What the server offers every library Plugin it loads: the Gateway that /// `registry` holds. The Harness asks for it as each tool call of such a /// Plugin starts, so a replaced Gateway serves the next call, and a call @@ -322,12 +295,13 @@ fn reachable_gateway(registry: &Registry) -> Option<(GatewayEndpoint, SecretStri /// The Host finder over the agents folder at `agents_path`: the source /// `load_agent` reads for each name, or its refusal as [`agent_error`]. -fn agent_finder(agents_path: PathBuf) -> impl Fn(&str) -> Result + Send + Sync { - move |name: &str| { +/// It comes inside an `Arc`, as a Host's builder takes its finder. +fn agent_finder(agents_path: PathBuf) -> Arc { + Arc::new(move |name: &str| { load_agent(&agents_path, name) .map(|(_file, source)| source) .map_err(|refusal| agent_error(&refusal)) - } + }) } /// The Host finder's failure for an agent `load_agent` refused: the @@ -370,13 +344,11 @@ struct Inner { /// The inference broker behind each run's broker. broker: WorkshopBroker, /// What every run shares: the installed Packs each run makes its - /// instances of, the finder that reads each agent from the agents - /// folder, and the stock tokio timer. + /// instances of, the built-ins among them, and the finder that reads + /// each agent from the agents folder. It also keeps each library + /// Plugin it loaded, so one that inserted no Pack still stays loaded + /// for as long as the launcher lives. host: Arc, - /// What the Plugin directory loaded, held so that a library Plugin - /// which inserted no Pack still stays loaded for as long as the - /// launcher lives. - _plugins: Option, /// The running conversations. conversations: Conversations, } @@ -402,17 +374,13 @@ impl AgentSessions { /// opens under the state directory when the first run starts. #[must_use] pub fn new(config: &Config, registry: Registry, backoff: ReconnectBackoff) -> Self { - let (packs, plugins) = host_packs( + let agents_path = config.agents.path.clone(); + let host = server_host( + agent_finder(agents_path.clone()), ®istry, config.agents.mcp.as_deref(), config.agents.plugins.as_deref(), ); - let agents_path = config.agents.path.clone(); - let host = Arc::new(Host { - packs, - prompts: Arc::new(agent_finder(agents_path.clone())), - timer: Arc::new(TokioTimer), - }); Self { inner: Arc::new(Inner { agents_path, @@ -421,7 +389,6 @@ impl AgentSessions { )), broker: WorkshopBroker::new(registry.clone()), host, - _plugins: plugins, conversations: Conversations::new(), registry, backoff, @@ -496,8 +463,8 @@ impl AgentSessions { /// The setup of `conversation`'s run before the Host state is read: /// its recorder tee over a run-log handle naming its agent, its broker, - /// its filesystem, and a user, since every conversation has an - /// operator. + /// the stock tokio timer, its filesystem, and a user, since every + /// conversation has an operator. fn setup_for(&self, conversation: &Conversation) -> RunSetup { let recorder = conversation.recorder(Arc::new( self.inner.recorder.for_agent(conversation.agent()), @@ -506,11 +473,9 @@ impl AgentSessions { self.inner.broker.clone(), conversation.clone(), )); - RunSetup { - vfs: language_guide::run_vfs(), - has_user: true, - ..RunSetup::new(recorder, broker) - } + RunSetup::new(recorder, broker, Arc::new(TokioTimer)) + .vfs(language_guide::run_vfs()) + .has_user(true) } /// The running conversation with this id, when one exists: how a diff --git a/crates/workshop/server/src/agents/bindings-tests.rs b/crates/workshop/server/src/agents/bindings-tests.rs index c2c6990a..68a3480a 100644 --- a/crates/workshop/server/src/agents/bindings-tests.rs +++ b/crates/workshop/server/src/agents/bindings-tests.rs @@ -2,6 +2,7 @@ use std::sync::Arc; +use harness_gateway_client::TokioTimer; use runvil::harness::{MemoryRecorder, OfflineBroker}; use workshop_menu::{CatalogBus, MenuBus}; @@ -9,7 +10,11 @@ use super::*; /// A setup with nothing selected. fn empty_setup() -> RunSetup { - RunSetup::new(Arc::new(MemoryRecorder::new()), Arc::new(OfflineBroker)) + RunSetup::new( + Arc::new(MemoryRecorder::new()), + Arc::new(OfflineBroker), + Arc::new(TokioTimer), + ) } #[test] diff --git a/crates/workshop/server/src/agents/language_guide/tests.rs b/crates/workshop/server/src/agents/language_guide/tests.rs index 34334e1b..d5c348ed 100644 --- a/crates/workshop/server/src/agents/language_guide/tests.rs +++ b/crates/workshop/server/src/agents/language_guide/tests.rs @@ -19,8 +19,8 @@ use workshop_registry::Registry; use super::mount_at; #[cfg(windows)] use super::{C_DRIVE_MOUNT, C_DRIVE_SOURCE}; -use crate::agents::host_packs; -use crate::agents::tests::{BASHKIT_LIBRARY, plugin_dir, plugin_dir_of, run_prompt_over}; +use crate::agents::server_host; +use crate::agents::tests::{BASHKIT_LIBRARY, plugin_dir, plugin_dir_of, run_prompt_over, serving}; /// What a test returns: any error from setup or from the VFS fails it. type Outcome = Result<(), Box>; @@ -227,9 +227,14 @@ async fn a_prompt_sees_the_directory_mapped_under_the_runvil_mount() -> Outcome let directory = local_directory()?; // The std Plugin is a library, which the Host loads from a directory. let (plugins, _library) = plugin_dir("sees-the-mapping"); - let (host, _) = host_packs(&Registry::new(), None, Some(plugins.path())); + let host = server_host( + serving(PROMPT), + &Registry::new(), + None, + Some(plugins.path()), + ); - let result = run_prompt_over(host, PROMPT.to_owned(), filesystem_with(directory.path())).await; + let result = run_prompt_over(host, filesystem_with(directory.path())).await; let Ok(Ok(final_text)) = result else { return Err(format!("the prompt did not complete: {result:?}").into()); @@ -276,14 +281,14 @@ return table.concat({ async fn the_file_tools_change_nothing_under_the_mapping() -> Outcome { let directory = local_directory()?; let (plugins, _library) = plugin_dir("changes-the-mapping"); - let (host, _) = host_packs(&Registry::new(), None, Some(plugins.path())); + let host = server_host( + serving(CHANGING_PROMPT), + &Registry::new(), + None, + Some(plugins.path()), + ); - let result = run_prompt_over( - host, - CHANGING_PROMPT.to_owned(), - filesystem_with(directory.path()), - ) - .await; + let result = run_prompt_over(host, filesystem_with(directory.path())).await; let Ok(Ok(final_text)) = result else { return Err(format!("the prompt did not complete: {result:?}").into()); @@ -334,9 +339,14 @@ async fn the_shell_changes_nothing_under_the_mapping_and_writes_beside_it() -> O let directory = local_directory()?; let vfs = filesystem_with(directory.path()); let (plugins, _library) = plugin_dir_of("shells-into-the-mapping", BASHKIT_LIBRARY); - let (host, _) = host_packs(&Registry::new(), None, Some(plugins.path())); + let host = server_host( + serving(CHANGING_SHELL_PROMPT), + &Registry::new(), + None, + Some(plugins.path()), + ); - let result = run_prompt_over(host, CHANGING_SHELL_PROMPT.to_owned(), vfs.clone()).await; + let result = run_prompt_over(host, vfs.clone()).await; let Ok(Ok(final_text)) = result else { return Err(format!("the prompt did not complete: {result:?}").into()); @@ -386,9 +396,14 @@ async fn the_shell_reads_two_directories_mapped_into_its_run() -> Outcome { let second = other_directory()?; let vfs = mount_at(filesystem_with(first.path()), OTHER_MOUNT, second.path()); let (plugins, _library) = plugin_dir_of("shells-over-the-mappings", BASHKIT_LIBRARY); - let (host, _) = host_packs(&Registry::new(), None, Some(plugins.path())); + let host = server_host( + serving(SHELL_PROMPT), + &Registry::new(), + None, + Some(plugins.path()), + ); - let result = run_prompt_over(host, SHELL_PROMPT.to_owned(), vfs).await; + let result = run_prompt_over(host, vfs).await; let Ok(Ok(final_text)) = result else { return Err(format!("the prompt did not complete: {result:?}").into()); diff --git a/crates/workshop/server/src/agents/tests.rs b/crates/workshop/server/src/agents/tests.rs index 767498c7..546605a1 100644 --- a/crates/workshop/server/src/agents/tests.rs +++ b/crates/workshop/server/src/agents/tests.rs @@ -31,17 +31,16 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::time::Duration; use harness_gateway_client::TokioTimer; -use runvil::harness::{HostResources, MemoryRecorder, OfflineBroker, Packs, PluginSource}; -use runvil::plugin::PackRegistry; +use runvil::harness::{MemoryRecorder, OfflineBroker, PluginReport, PluginSource}; use runvil::vfs::{Origin, VfsRef}; -use runvil::{Error, ErrorCode, ErrorFact, Host, RunSetup}; +use runvil::{Error, ErrorCode, ErrorFact, Host, PromptFinder, RunSetup}; use serde_json::json; use workshop_agents::{Conversations, SessionState, load_agent}; use workshop_registry::Registry; use super::{ - PluginListing, SHIPPED_PACKS, agent_finder, holds, host_packs, list_plugin_dir, - load_plugin_dir, read_mcp_servers, resources, with_plugins, + PluginListing, SHIPPED_PACKS, agent_finder, holds, list_plugin_dir, read_mcp_servers, + resources, server_host, with_plugins, }; #[path = "tests-gateway.rs"] @@ -56,25 +55,49 @@ fn requiring(pack: &str) -> String { ) } -/// Runs the prompt `source` as one conversation over `packs` and the -/// default in-memory filesystem; see [`run_prompt_over`]. -async fn run_prompt(packs: Packs, source: String) -> Result, String> { - run_prompt_over(packs, source, VfsRef::default()).await +/// A finder that gives `source` under every name. +pub(super) fn serving(source: impl Into) -> Arc { + let source = source.into(); + Arc::new(move |_: &str| -> Result { Ok(source.clone()) }) } -/// Runs the prompt `source` as one conversation over the filesystem -/// `vfs`, on a Host over `packs` whose finder gives `source` under every -/// name; see [`run_agent_on`]. +/// The report of the Plugin directory of `host`, which is the last step +/// its builder names. +fn directory_report(host: &Host) -> &PluginReport { + host.plugin_reports() + .last() + .expect("the Host names a Plugin directory") +} + +/// The name of each Plugin that the Plugin directory of `host` loaded. +fn loaded(host: &Host) -> Vec<&str> { + directory_report(host) + .plugins() + .iter() + .map(|plugin| plugin.name()) + .collect() +} + +/// Asserts that the Plugin directory of `host` reported no failure. +#[track_caller] +fn assert_no_failures(host: &Host) { + let failures = directory_report(host).failures(); + assert!(failures.is_empty(), "{failures:?}"); +} + +/// Runs the prompt that `host` finds under every name as one +/// conversation over the default in-memory filesystem; see +/// [`run_agent_on`]. +async fn run_prompt(host: Arc) -> Result, String> { + run_prompt_over(host, VfsRef::default()).await +} + +/// Runs the prompt that `host` finds under every name as one +/// conversation over the filesystem `vfs`; see [`run_agent_on`]. pub(super) async fn run_prompt_over( - packs: Packs, - source: String, + host: Arc, vfs: VfsRef, ) -> Result, String> { - let host = Host { - packs, - prompts: Arc::new(move |_: &str| -> Result { Ok(source.clone()) }), - timer: Arc::new(TokioTimer), - }; run_agent_on(host, "browses", vfs).await } @@ -84,27 +107,23 @@ pub(super) async fn run_prompt_over( /// report when the Host refused the prompt as it parsed it and no run /// began. async fn run_agent_on( - host: Host, + host: Arc, name: &str, vfs: VfsRef, ) -> Result, String> { let recorder = Arc::new(MemoryRecorder::new()); let conversation = Conversations::new().open(name); let mut errors = conversation.subscribe_errors(); - let setup = RunSetup { - vfs, - has_user: true, - ..RunSetup::new( - conversation.recorder(recorder.clone()), - Arc::new(OfflineBroker), - ) - }; - tokio::time::timeout( - Duration::from_secs(10), - conversation.run(Arc::new(host), name, setup), + let setup = RunSetup::new( + conversation.recorder(recorder.clone()), + Arc::new(OfflineBroker), + Arc::new(TokioTimer), ) - .await - .expect("the run ends in time"); + .vfs(vfs) + .has_user(true); + tokio::time::timeout(Duration::from_secs(10), conversation.run(host, name, setup)) + .await + .expect("the run ends in time"); assert_eq!( conversation.state(), SessionState::Closed, @@ -137,9 +156,9 @@ async fn every_run_holds_the_packs_the_three_plugins_add_and_the_builtins() { end\n\ return table.concat(names, ',') .. '|' .. tostring(tools.packs.get('user-input'))\n```\n"; let dir = plugin_dir_with("every-run-holds", &[STD_LIBRARY, WEB_LIBRARY]); - let (host, _) = host_packs(&Registry::new(), None, Some(dir.path())); + let host = server_host(serving(lists), &Registry::new(), None, Some(dir.path())); assert_eq!( - run_prompt(host, lists.to_owned()).await, + run_prompt(host).await, Ok(Ok("web,subagents,mcp,std,user|nil".to_owned())), "a run that declares nothing holds every runvil Pack the server installed, the \ built-ins, and the user Pack its user brings, and no user-input Pack" @@ -149,17 +168,16 @@ async fn every_run_holds_the_packs_the_three_plugins_add_and_the_builtins() { #[tokio::test] async fn a_prompt_declaring_web_prepares_on_the_servers_built_packs() { let (dir, _library) = plugin_dir_of("declares-web", WEB_LIBRARY); - let (host, report) = host_packs(&Registry::new(), None, Some(dir.path())); - let report = report.expect("the configured directory is read"); - assert!(report.failures().is_empty(), "{:?}", report.failures()); - let names: Vec<&str> = report - .plugins() - .iter() - .map(|plugin| plugin.name()) - .collect(); - assert_eq!(names, ["web"]); + let host = server_host( + serving(requiring("web")), + &Registry::new(), + None, + Some(dir.path()), + ); + assert_no_failures(&host); + assert_eq!(loaded(&host), ["web"]); assert_eq!( - run_prompt(host, requiring("web")).await, + run_prompt(host).await, Ok(Ok("browsed".to_owned())), "the web library's Pack is installed, so a prompt that requires web runs" ); @@ -167,9 +185,14 @@ async fn a_prompt_declaring_web_prepares_on_the_servers_built_packs() { #[tokio::test] async fn a_prompt_declaring_subagents_prepares_on_the_servers_built_packs() { - let (host, _) = host_packs(&Registry::new(), None, None); + let host = server_host( + serving(requiring("subagents")), + &Registry::new(), + None, + None, + ); assert_eq!( - run_prompt(host, requiring("subagents")).await, + run_prompt(host).await, Ok(Ok("browsed".to_owned())), "the server's Host installs the built-in subagents" ); @@ -184,7 +207,7 @@ fn the_finder_refuses_an_unknown_agent_as_not_found_and_an_unreadable_one_as_io( let finder = agent_finder(dir.path().to_path_buf()); for (name, code) in [("missing", ErrorCode::NotFound), ("broken", ErrorCode::Io)] { - let error = finder(name).expect_err("the finder refuses the agent"); + let error = finder.find(name).expect_err("the finder refuses the agent"); let refusal = load_agent(dir.path(), name).expect_err("the launch check refuses it too"); assert_eq!(error.code, code, "{name}"); assert_eq!(error.message, refusal.to_string(), "{name}"); @@ -204,12 +227,12 @@ async fn an_agent_executes_an_agent_of_the_folder_that_its_prompts_list_names() ## Only\n\n```lua\nreturn 'inner ran'\n```\n"; std::fs::write(dir.path().join("outer.md"), outer).expect("write fixture"); std::fs::write(dir.path().join("inner.md"), inner).expect("write fixture"); - let (packs, _) = host_packs(&Registry::new(), None, None); - let host = Host { - packs, - prompts: Arc::new(agent_finder(dir.path().to_path_buf())), - timer: Arc::new(TokioTimer), - }; + let host = server_host( + agent_finder(dir.path().to_path_buf()), + &Registry::new(), + None, + None, + ); assert_eq!( run_agent_on(host, "outer", VfsRef::default()).await, @@ -223,9 +246,9 @@ async fn a_prompt_declaring_mcp_prepares_on_a_host_built_on_a_runtime() { // The Host is built on this test's runtime, as the server builds its // own, so the mcp Pack is installed with that runtime's handle, here // over no servers. - let (host, _) = host_packs(&Registry::new(), None, None); + let host = server_host(serving(requiring("mcp")), &Registry::new(), None, None); assert_eq!( - run_prompt(host, requiring("mcp")).await, + run_prompt(host).await, Ok(Ok("browsed".to_owned())), "a Host built on a runtime installs the mcp Pack once" ); @@ -236,13 +259,13 @@ fn a_host_built_outside_a_runtime_installs_no_mcp_pack() { // A synchronous test builds the Host outside a runtime, so the Host // is built without the mcp Pack. The run itself needs a runtime, // which starts only after the Host is built. - let (host, _) = host_packs(&Registry::new(), None, None); + let host = server_host(serving(requiring("mcp")), &Registry::new(), None, None); let runtime = tokio::runtime::Builder::new_current_thread() .enable_all() .build() .expect("a runtime for the run is built"); - let result = runtime.block_on(run_prompt(host, requiring("mcp"))); + let result = runtime.block_on(run_prompt(host)); let Err(message) = result else { panic!("the Host refuses the prompt as it parses: {result:?}"); }; @@ -256,9 +279,14 @@ fn a_host_built_outside_a_runtime_installs_no_mcp_pack() { async fn the_servers_value_is_the_mcp_packs_server_list() { // A value that is neither null nor an object is the one server list // the install refuses, so only that value reaching it fails the run. - let (host, _) = with_plugins(&resources(&Registry::new()), json!([]), None); + let host = with_plugins( + serving(requiring("mcp")), + resources(&Registry::new()), + json!([]), + None, + ); - let result = run_prompt(host, requiring("mcp")).await; + let result = run_prompt(host).await; let Err(message) = result else { panic!("the Host refuses the prompt as it parses: {result:?}"); }; @@ -328,9 +356,8 @@ pub(super) fn plugin_dir(test: &str) -> (tempfile::TempDir, PathBuf) { #[test] fn a_plugin_directory_loads_the_std_plugin_from_its_library() { let (dir, library) = plugin_dir("loads-std"); - let mut packs = PackRegistry::new(); - let report = load_plugin_dir(&mut packs, dir.path(), &HostResources::new()) - .expect("the directory is read"); + let host = server_host(serving(""), &Registry::new(), None, Some(dir.path())); + let report = directory_report(&host); assert!(report.failures().is_empty(), "{:?}", report.failures()); let [plugin] = report.plugins() else { @@ -349,9 +376,8 @@ fn a_file_that_is_no_library_is_reported_and_the_std_plugin_still_loads() { let (dir, _library) = plugin_dir("reports-a-bad-file"); let bad = dir.path().join(format!("a-text-file.{DLL_EXTENSION}")); std::fs::write(&bad, "not a library").expect("write fixture"); - let mut packs = PackRegistry::new(); - let report = load_plugin_dir(&mut packs, dir.path(), &HostResources::new()) - .expect("the directory is read"); + let host = server_host(serving(""), &Registry::new(), None, Some(dir.path())); + let report = directory_report(&host); assert_eq!(report.plugins().len(), 1, "{:?}", report.plugins()); let [failure] = report.failures() else { @@ -397,32 +423,34 @@ fn a_listing_names_each_plugin_that_loads_and_each_library_that_does_not() { #[test] fn a_plugin_directory_that_does_not_exist_loads_nothing() { let (dir, _library) = plugin_dir("missing-directory"); - let mut packs = PackRegistry::new(); + // A synchronous test builds the Host outside a runtime, so the Plugin + // directory would be its one step. + let host = server_host( + serving(""), + &Registry::new(), + None, + Some(&dir.path().join("absent")), + ); assert!( - load_plugin_dir( - &mut packs, - &dir.path().join("absent"), - &HostResources::new() - ) - .is_none(), - "a missing directory is a state, not a failure" + host.plugin_reports().is_empty(), + "a missing directory is a state, not a failure: {:?}", + host.plugin_reports() ); } #[tokio::test] async fn the_servers_host_loads_its_plugin_directory_beside_the_linked_plugin() { let (dir, _library) = plugin_dir("server-host"); - let (host, report) = host_packs(&Registry::new(), None, Some(dir.path())); + let host = server_host( + serving(requiring("std")), + &Registry::new(), + None, + Some(dir.path()), + ); - let report = report.expect("the configured directory is read"); - let names: Vec<&str> = report - .plugins() - .iter() - .map(|plugin| plugin.name()) - .collect(); - assert_eq!(names, ["std"]); + assert_eq!(loaded(&host), ["std"]); assert_eq!( - run_prompt(host, requiring("std")).await, + run_prompt(host).await, Ok(Ok("browsed".to_owned())), "the library's Pack is installed, so a prompt that requires std runs" ); @@ -430,6 +458,7 @@ async fn the_servers_host_loads_its_plugin_directory_beside_the_linked_plugin() #[test] fn only_a_plugin_directory_with_a_shipped_library_gives_the_host_its_pack() { + let bare = server_host(serving(""), &Registry::new(), None, None); for (library, pack) in [ (STD_LIBRARY, "runvil/std"), (BASHKIT_LIBRARY, "runvil/bash"), @@ -437,14 +466,9 @@ fn only_a_plugin_directory_with_a_shipped_library_gives_the_host_its_pack() { ] { assert!(SHIPPED_PACKS.contains(&pack), "{pack}"); let (dir, _library) = plugin_dir_of("holds-a-shipped-pack", library); - let mut packs = PackRegistry::new(); - load_plugin_dir(&mut packs, dir.path(), &HostResources::new()) - .expect("the directory is read"); - assert!(holds(&packs, pack), "{library} inserts {pack}"); - assert!( - !holds(&PackRegistry::new(), pack), - "{pack} is not among the built-ins" - ); + let host = server_host(serving(""), &Registry::new(), None, Some(dir.path())); + assert!(holds(&host, pack), "{library} inserts {pack}"); + assert!(!holds(&bare, pack), "{pack} is not among the built-ins"); } } @@ -465,9 +489,13 @@ const READS_AND_CHANGES: &str = "---\nname: changes\ndescription: reads and chan #[tokio::test] async fn a_prompt_reads_and_changes_files_of_its_run_through_the_std_library_plugin() { let (dir, _library) = plugin_dir("reads-and-changes"); - let (host, report) = host_packs(&Registry::new(), None, Some(dir.path())); - let report = report.expect("the configured directory is read"); - assert!(report.failures().is_empty(), "{:?}", report.failures()); + let host = server_host( + serving(READS_AND_CHANGES), + &Registry::new(), + None, + Some(dir.path()), + ); + assert_no_failures(&host); let vfs = VfsRef::default(); let seed = vfs @@ -477,7 +505,7 @@ async fn a_prompt_reads_and_changes_files_of_its_run_through_the_std_library_plu .expect("the file is seeded"); seed.write("/old.md", b"old\n").expect("the file is seeded"); - let result = run_prompt_over(host, READS_AND_CHANGES.to_owned(), vfs.clone()).await; + let result = run_prompt_over(host, vfs.clone()).await; let Ok(Ok(text)) = result else { panic!("the run ends with its text: {result:?}"); }; @@ -522,10 +550,16 @@ async fn a_prompt_reads_and_changes_files_of_its_run_through_the_std_library_plu #[tokio::test] async fn without_a_plugin_directory_a_prompt_requiring_a_shipped_pack_is_refused() { for pack in ["std", "bash", "web"] { - let (host, report) = host_packs(&Registry::new(), None, None); - assert!(report.is_none(), "no directory is read"); + let host = server_host(serving(requiring(pack)), &Registry::new(), None, None); + let [mcp] = host.plugin_reports() else { + panic!( + "the linked Plugin is the one step, so no directory is read: {:?}", + host.plugin_reports() + ); + }; + assert!(mcp.plugins().is_empty(), "{:?}", mcp.plugins()); - let result = run_prompt(host, requiring(pack)).await; + let result = run_prompt(host).await; let Err(message) = result else { panic!("the Host refuses the prompt as it parses: {result:?}"); }; @@ -550,15 +584,14 @@ const RUNS_A_COMMAND: &str = "---\nname: shells\ndescription: runs a command\nru #[tokio::test] async fn a_prompt_runs_a_command_over_its_runs_files_through_the_bashkit_library_plugin() { let (dir, _library) = plugin_dir_of("runs-a-command", BASHKIT_LIBRARY); - let (host, report) = host_packs(&Registry::new(), None, Some(dir.path())); - let report = report.expect("the configured directory is read"); - assert!(report.failures().is_empty(), "{:?}", report.failures()); - let names: Vec<&str> = report - .plugins() - .iter() - .map(|plugin| plugin.name()) - .collect(); - assert_eq!(names, ["bashkit"]); + let host = server_host( + serving(RUNS_A_COMMAND), + &Registry::new(), + None, + Some(dir.path()), + ); + assert_no_failures(&host); + assert_eq!(loaded(&host), ["bashkit"]); let vfs = VfsRef::default(); vfs.acquire(Origin::new("seed")) @@ -566,7 +599,7 @@ async fn a_prompt_runs_a_command_over_its_runs_files_through_the_bashkit_library .write("/notes.md", b"hello\nworld\n") .expect("the file is seeded"); - let result = run_prompt_over(host, RUNS_A_COMMAND.to_owned(), vfs.clone()).await; + let result = run_prompt_over(host, vfs.clone()).await; let Ok(Ok(text)) = result else { panic!("the run ends with its text: {result:?}"); }; From a2d67686b6078b3c44665d0a1e1337d03dc457ce Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sat, 21 Nov 2026 09:36:38 -0800 Subject: [PATCH 2/3] Test a Plugin directory that cannot be read The automatic review of the pull request asked for a test of the one case of the Plugin directory whose outcome changed: a path that exists and cannot be read as a directory. `a_plugin_directory_that_cannot_be_read_is_a_failure_and_the_host_is_built` puts a regular file in the place of the directory and builds the server's `Host` outside a runtime. The `Host` is built with its built-ins, and its one report holds one `PluginLoadFailed` failure with the reason `directory` and the configured path. - The test of a directory that does not exist stays as it is: such a `Host` has no report. - The module doc of `tests.rs` names the new case. - No production code changes. --- crates/workshop/server/src/agents/tests.rs | 40 ++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/crates/workshop/server/src/agents/tests.rs b/crates/workshop/server/src/agents/tests.rs index 546605a1..8038135d 100644 --- a/crates/workshop/server/src/agents/tests.rs +++ b/crates/workshop/server/src/agents/tests.rs @@ -15,8 +15,10 @@ //! the launch refusal's own text, and it reads an agent that another //! names under `prompts:`, which that agent then runs with `execute`. A //! configured Plugin directory loads each library Plugin in it and -//! reports each file that is none, and a directory that does not exist -//! loads nothing. A prompt reads and changes the files of its run through +//! reports each file that is none, a directory that does not exist +//! loads nothing, and one that cannot be read is a failure of the Host's +//! report while the Host is built. A prompt reads and changes the files +//! of its run through //! the std library's `Read`, `Write`, `StrReplace`, and `Delete` tools //! and through the bashkit library's `Shell` tool, and the Host reads //! each change back after the run. A Host with no Plugin directory @@ -438,6 +440,40 @@ fn a_plugin_directory_that_does_not_exist_loads_nothing() { ); } +#[test] +fn a_plugin_directory_that_cannot_be_read_is_a_failure_and_the_host_is_built() { + let dir = tempfile::TempDir::new().expect("tempdir"); + // A regular file in the directory's place exists, so the Host names + // it, and it cannot be read as a directory. + let file = dir.path().join("plugins"); + std::fs::write(&file, "not a directory").expect("write fixture"); + // A synchronous test builds the Host outside a runtime, so the Plugin + // directory is its one step. + let host = server_host(serving(""), &Registry::new(), None, Some(&file)); + + let [report] = host.plugin_reports() else { + panic!("the directory is the one step: {:?}", host.plugin_reports()); + }; + assert!(report.plugins().is_empty(), "{:?}", report.plugins()); + let [failure] = report.failures() else { + panic!("the directory is the one failure: {:?}", report.failures()); + }; + assert_eq!(failure.code, ErrorCode::PluginLoadFailed); + assert_eq!( + failure.facts.get(&ErrorFact::Reason), + Some(&json!("directory")) + ); + assert_eq!( + failure.facts.get(&ErrorFact::Path), + Some(&json!(file.display().to_string())), + "the failure names the configured path" + ); + assert!( + holds(&host, "runvil/user") && !holds(&host, "runvil/std"), + "the Host is built, with its built-ins and no library Plugin's Pack" + ); +} + #[tokio::test] async fn the_servers_host_loads_its_plugin_directory_beside_the_linked_plugin() { let (dir, _library) = plugin_dir("server-host"); From 73e4fccd94e8f17953e6bd05e5111defcc5cd3b3 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sat, 21 Nov 2026 09:46:37 -0800 Subject: [PATCH 3/3] Name the fixture of the unreadable directory for its test A review of the pull request found that the new test made its fixture in a temporary directory with an anonymous name, so a path in a failure could not be traced to the test. The test now makes that directory with `plugin_dir_with`, which names a directory for its test, as each Plugin directory of this file is made. - The directory holds no library, so the helper gets an empty list. - No assertion changes. --- crates/workshop/server/src/agents/tests.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/workshop/server/src/agents/tests.rs b/crates/workshop/server/src/agents/tests.rs index 8038135d..29729c21 100644 --- a/crates/workshop/server/src/agents/tests.rs +++ b/crates/workshop/server/src/agents/tests.rs @@ -442,9 +442,10 @@ fn a_plugin_directory_that_does_not_exist_loads_nothing() { #[test] fn a_plugin_directory_that_cannot_be_read_is_a_failure_and_the_host_is_built() { - let dir = tempfile::TempDir::new().expect("tempdir"); // A regular file in the directory's place exists, so the Host names - // it, and it cannot be read as a directory. + // it, and it cannot be read as a directory. The directory around it + // is named for this test, as each Plugin directory here is. + let dir = plugin_dir_with("cannot-be-read", &[]); let file = dir.path().join("plugins"); std::fs::write(&file, "not a directory").expect("write fixture"); // A synchronous test builds the Host outside a runtime, so the Plugin