diff --git a/Cargo.lock b/Cargo.lock index 6fbc5268..f88e6da6 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=f75aadb2b45d9624ca576b516307a32991f361e5#f75aadb2b45d9624ca576b516307a32991f361e5" +source = "git+https://github.com/cppalliance/runvil-harness?rev=fb29b8a29131ca298d517a2e40e9801c7bd6d694#fb29b8a29131ca298d517a2e40e9801c7bd6d694" 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=f75aadb2b45d9624ca576b516307a32991f361e5#f75aadb2b45d9624ca576b516307a32991f361e5" +source = "git+https://github.com/cppalliance/runvil-harness?rev=fb29b8a29131ca298d517a2e40e9801c7bd6d694#fb29b8a29131ca298d517a2e40e9801c7bd6d694" dependencies = [ "libloading 0.8.9", "runvil-plugin", @@ -2267,7 +2267,7 @@ dependencies = [ [[package]] name = "harness-runner" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f75aadb2b45d9624ca576b516307a32991f361e5#f75aadb2b45d9624ca576b516307a32991f361e5" +source = "git+https://github.com/cppalliance/runvil-harness?rev=fb29b8a29131ca298d517a2e40e9801c7bd6d694#fb29b8a29131ca298d517a2e40e9801c7bd6d694" dependencies = [ "futures-util", "rand 0.9.5", @@ -4056,7 +4056,7 @@ dependencies = [ [[package]] name = "plugin-mcp" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f75aadb2b45d9624ca576b516307a32991f361e5#f75aadb2b45d9624ca576b516307a32991f361e5" +source = "git+https://github.com/cppalliance/runvil-harness?rev=fb29b8a29131ca298d517a2e40e9801c7bd6d694#fb29b8a29131ca298d517a2e40e9801c7bd6d694" dependencies = [ "reqwest", "rmcp", @@ -4724,7 +4724,7 @@ dependencies = [ [[package]] name = "runvil" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f75aadb2b45d9624ca576b516307a32991f361e5#f75aadb2b45d9624ca576b516307a32991f361e5" +source = "git+https://github.com/cppalliance/runvil-harness?rev=fb29b8a29131ca298d517a2e40e9801c7bd6d694#fb29b8a29131ca298d517a2e40e9801c7bd6d694" dependencies = [ "harness-plugin-loader", "harness-runner", @@ -4735,7 +4735,7 @@ dependencies = [ [[package]] name = "runvil-engine" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f75aadb2b45d9624ca576b516307a32991f361e5#f75aadb2b45d9624ca576b516307a32991f361e5" +source = "git+https://github.com/cppalliance/runvil-harness?rev=fb29b8a29131ca298d517a2e40e9801c7bd6d694#fb29b8a29131ca298d517a2e40e9801c7bd6d694" dependencies = [ "runvil-lua", "runvil-model-client", @@ -4748,7 +4748,7 @@ dependencies = [ [[package]] name = "runvil-lua" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f75aadb2b45d9624ca576b516307a32991f361e5#f75aadb2b45d9624ca576b516307a32991f361e5" +source = "git+https://github.com/cppalliance/runvil-harness?rev=fb29b8a29131ca298d517a2e40e9801c7bd6d694#fb29b8a29131ca298d517a2e40e9801c7bd6d694" dependencies = [ "mlua", "runvil-markdown", @@ -4762,7 +4762,7 @@ dependencies = [ [[package]] name = "runvil-markdown" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f75aadb2b45d9624ca576b516307a32991f361e5#f75aadb2b45d9624ca576b516307a32991f361e5" +source = "git+https://github.com/cppalliance/runvil-harness?rev=fb29b8a29131ca298d517a2e40e9801c7bd6d694#fb29b8a29131ca298d517a2e40e9801c7bd6d694" dependencies = [ "pulldown-cmark", "serde_json", @@ -4772,7 +4772,7 @@ dependencies = [ [[package]] name = "runvil-model-client" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f75aadb2b45d9624ca576b516307a32991f361e5#f75aadb2b45d9624ca576b516307a32991f361e5" +source = "git+https://github.com/cppalliance/runvil-harness?rev=fb29b8a29131ca298d517a2e40e9801c7bd6d694#fb29b8a29131ca298d517a2e40e9801c7bd6d694" dependencies = [ "runvil-types", "serde", @@ -4782,7 +4782,7 @@ dependencies = [ [[package]] name = "runvil-plugin" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f75aadb2b45d9624ca576b516307a32991f361e5#f75aadb2b45d9624ca576b516307a32991f361e5" +source = "git+https://github.com/cppalliance/runvil-harness?rev=fb29b8a29131ca298d517a2e40e9801c7bd6d694#fb29b8a29131ca298d517a2e40e9801c7bd6d694" dependencies = [ "runvil-types", "runvil-vfs", @@ -4805,7 +4805,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=f75aadb2b45d9624ca576b516307a32991f361e5#f75aadb2b45d9624ca576b516307a32991f361e5" +source = "git+https://github.com/cppalliance/runvil-harness?rev=fb29b8a29131ca298d517a2e40e9801c7bd6d694#fb29b8a29131ca298d517a2e40e9801c7bd6d694" dependencies = [ "pulldown-cmark", "runvil-lua", @@ -4818,7 +4818,7 @@ dependencies = [ [[package]] name = "runvil-runtime" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f75aadb2b45d9624ca576b516307a32991f361e5#f75aadb2b45d9624ca576b516307a32991f361e5" +source = "git+https://github.com/cppalliance/runvil-harness?rev=fb29b8a29131ca298d517a2e40e9801c7bd6d694#fb29b8a29131ca298d517a2e40e9801c7bd6d694" dependencies = [ "mlua", "regex", @@ -4836,7 +4836,7 @@ dependencies = [ [[package]] name = "runvil-types" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f75aadb2b45d9624ca576b516307a32991f361e5#f75aadb2b45d9624ca576b516307a32991f361e5" +source = "git+https://github.com/cppalliance/runvil-harness?rev=fb29b8a29131ca298d517a2e40e9801c7bd6d694#fb29b8a29131ca298d517a2e40e9801c7bd6d694" dependencies = [ "serde", "serde_json", @@ -4846,7 +4846,7 @@ dependencies = [ [[package]] name = "runvil-vfs" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=f75aadb2b45d9624ca576b516307a32991f361e5#f75aadb2b45d9624ca576b516307a32991f361e5" +source = "git+https://github.com/cppalliance/runvil-harness?rev=fb29b8a29131ca298d517a2e40e9801c7bd6d694#fb29b8a29131ca298d517a2e40e9801c7bd6d694" [[package]] name = "rust-embed" diff --git a/Cargo.toml b/Cargo.toml index a62721fd..f3c65878 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 = "f75aadb2b45d9624ca576b516307a32991f361e5" } -harness-gateway-client = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "f75aadb2b45d9624ca576b516307a32991f361e5" } -plugin-mcp = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "f75aadb2b45d9624ca576b516307a32991f361e5" } +runvil = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "fb29b8a29131ca298d517a2e40e9801c7bd6d694" } +harness-gateway-client = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "fb29b8a29131ca298d517a2e40e9801c7bd6d694" } +plugin-mcp = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "fb29b8a29131ca298d517a2e40e9801c7bd6d694" } # 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/registry/src/lib.rs b/crates/workshop/registry/src/lib.rs index 8b890f75..44aa1e4e 100644 --- a/crates/workshop/registry/src/lib.rs +++ b/crates/workshop/registry/src/lib.rs @@ -7,10 +7,8 @@ //! announce itself. //! //! The runtime links the subsystem-named seams carry: the gateway -//! drives the menu through [`MenuPush`], publishing a model catalog -//! forces a menu reconcile through [`Push::push_models_catalog`], and -//! agent sessions read the workspace's granted roots through -//! [`WorkspaceRoots`]. +//! drives the menu through [`MenuPush`], and publishing a model catalog +//! forces a menu reconcile through [`Push::push_models_catalog`]. //! //! ## Invariants //! @@ -21,8 +19,8 @@ //! only this crate implements them: registrants plug in through the //! adapters provided here, never by implementing a trait downstream. //! - Subsystem names live in the sealed traits ([`MenuSink`], -//! [`CatalogSink`], [`StatusChannel`], [`StatusSink`], -//! [`WorkspaceRoots`]) and in the [`MenuPush`] struct behind +//! [`CatalogSink`], [`StatusChannel`], [`StatusSink`]) and in the +//! [`MenuPush`] struct behind //! [`Push::menu`], the facade's one per-subsystem accessor; the //! collections stay keyed by type, never by a per-subsystem field. A //! new subsystem adds its trait and adapter here, a compose helper in @@ -46,5 +44,5 @@ pub use registry::{MissingContribution, Registration, Registry}; pub use traits::{ BackgroundTask, BackgroundTaskAdapter, CatalogSink, CatalogSinkAdapter, MenuSink, MenuSinkAdapter, RouteRegistrar, RouteRegistrarAdapter, ShutdownHandle, StatusChannel, - StatusChannelAdapter, StatusSink, StatusSinkAdapter, WorkspaceRoots, WorkspaceRootsAdapter, + StatusChannelAdapter, StatusSink, StatusSinkAdapter, }; diff --git a/crates/workshop/registry/src/traits.rs b/crates/workshop/registry/src/traits.rs index 3e35e21b..ff615fc1 100644 --- a/crates/workshop/registry/src/traits.rs +++ b/crates/workshop/registry/src/traits.rs @@ -1,6 +1,6 @@ //! The sealed subsystem traits: one per contribution kind in the //! decomposition's inventory (routes, background tasks, push channels -//! and sinks, shared views). +//! and sinks). //! //! All are sealed behind a private supertrait, so only this crate can //! implement them. A registrant plugs its subsystem in through an @@ -8,11 +8,10 @@ //! downstream. use std::fmt; -use std::path::PathBuf; use std::pin::Pin; use axum::Router; -use tokio::sync::{broadcast, watch}; +use tokio::sync::broadcast; use workshop_protocol::StatusBarUpdate; @@ -245,68 +244,6 @@ impl

fmt::Debug for CatalogSinkAdapter

{ } } -/// The workspace subsystem's granted-root view: the narrow state handle -/// the server's agent-session bindings read through the registry. -/// Registered by `workshop-workspace`'s `handles.rs`. -pub trait WorkspaceRoots: Sealed + Send + Sync { - /// The granted workspace roots in stable sorted order. - fn granted_roots(&self) -> Vec; - /// A watch on the grant-set generation: it changes on every grant, - /// revoke, and workspace switch, so a consumer re-reads - /// [`WorkspaceRoots::granted_roots`] when it wakes. - fn subscribe(&self) -> watch::Receiver; -} - -/// A [`WorkspaceRoots`] backed by two closures over the workspace's grant -/// set, one reading the roots and one subscribing to its generation: the -/// registration adapter for the workspace subsystem. The registry's -/// traits are sealed, so the registrant plugs its state in through this -/// adapter rather than implementing the trait itself. -pub struct WorkspaceRootsAdapter { - roots: F, - subscribe: S, -} - -impl WorkspaceRootsAdapter -where - F: Fn() -> Vec + Send + Sync, - S: Fn() -> watch::Receiver + Send + Sync, -{ - /// Builds the adapter from the workspace's granted-roots closure and - /// its grant-set generation subscribe closure. - #[must_use] - pub fn new(roots: F, subscribe: S) -> Self { - Self { roots, subscribe } - } -} - -impl Sealed for WorkspaceRootsAdapter -where - F: Fn() -> Vec + Send + Sync, - S: Fn() -> watch::Receiver + Send + Sync, -{ -} - -impl WorkspaceRoots for WorkspaceRootsAdapter -where - F: Fn() -> Vec + Send + Sync, - S: Fn() -> watch::Receiver + Send + Sync, -{ - fn granted_roots(&self) -> Vec { - (self.roots)() - } - - fn subscribe(&self) -> watch::Receiver { - (self.subscribe)() - } -} - -impl fmt::Debug for WorkspaceRootsAdapter { - fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { - formatter.debug_struct("WorkspaceRootsAdapter").finish() - } -} - /// A [`RouteRegistrar`] backed by one closure building the subsystem's /// router: the registration adapter for a subsystem's routes. The /// registry's traits are sealed, so the registrant plugs its routes in diff --git a/crates/workshop/registry/tests/it/main.rs b/crates/workshop/registry/tests/it/main.rs index 3b2788da..a859f80c 100644 --- a/crates/workshop/registry/tests/it/main.rs +++ b/crates/workshop/registry/tests/it/main.rs @@ -4,7 +4,7 @@ use std::sync::{Arc, Mutex, PoisonError}; -use tokio::sync::{broadcast, watch}; +use tokio::sync::broadcast; use workshop_protocol::{Activity, Severity, StatusBarUpdate}; use workshop_registry::{Registry, StatusChannel, StatusChannelAdapter}; @@ -130,59 +130,6 @@ fn registry_clones_share_the_same_collections() { ); } -#[test] -fn the_workspace_roots_handle_serves_the_registrants_grants() { - use std::path::PathBuf; - - use workshop_registry::{WorkspaceRoots, WorkspaceRootsAdapter}; - - let registry = Registry::new(); - assert!( - registry.state::().is_none(), - "an unregistered roots handle is a graceful no-op" - ); - let registration = registry.register_state::(Arc::new( - WorkspaceRootsAdapter::new(|| vec![PathBuf::from("/granted")], || watch::channel(0).1), - )); - let roots = registry - .state::() - .expect("the registered roots handle is served"); - assert_eq!(roots.granted_roots(), vec![PathBuf::from("/granted")]); - drop(registration); - assert!( - registry.state::().is_none(), - "the key empties when the guard drops" - ); -} - -#[test] -fn the_workspace_roots_handle_serves_the_registrants_change_signal() { - use std::path::PathBuf; - - use workshop_registry::{WorkspaceRoots, WorkspaceRootsAdapter}; - - let registry = Registry::new(); - let generation = watch::Sender::new(0_u64); - let _registration = registry.register_state::(Arc::new( - WorkspaceRootsAdapter::new(Vec::::new, { - let generation = generation.clone(); - move || generation.subscribe() - }), - )); - let mut receiver = registry - .state::() - .expect("the registered roots handle is served") - .subscribe(); - generation.send_modify(|value| *value += 1); - assert!( - receiver - .has_changed() - .expect("the registrant's sender is alive"), - "a bump through the registrant's sender reaches the subscriber" - ); - assert_eq!(*receiver.borrow_and_update(), 1); -} - #[test] fn route_registrants_build_their_routers_in_registration_order() { use workshop_registry::RouteRegistrarAdapter; diff --git a/crates/workshop/server/src/agents.rs b/crates/workshop/server/src/agents.rs index 404a2d44..94b1dcdf 100644 --- a/crates/workshop/server/src/agents.rs +++ b/crates/workshop/server/src/agents.rs @@ -355,8 +355,8 @@ pub struct AgentSessions { /// The shared state behind the cloneable handle. struct Inner { - /// The subsystem registry: the gateway and menu handles, the - /// workspace roots, and the push facade are read through it. + /// The subsystem registry: the gateway and menu handles and the push + /// facade are read through it. registry: Registry, /// Reset on completed replies: an agent reply is useful gateway work. backoff: ReconnectBackoff, @@ -478,10 +478,9 @@ impl AgentSessions { } /// Runs `conversation`'s one run of its agent. The setup's selected - /// model and workspace roots are read once the menu's catalog holds a - /// chat-capable model, so a pick made while the catalog was empty is - /// the one the run binds; a close during that wait ends the run before - /// it begins. + /// model is read once the menu's catalog holds a chat-capable model, + /// so a pick made while the catalog was empty is the one the run + /// binds; a close during that wait ends the run before it begins. async fn drive(self, conversation: Conversation) { tokio::select! { () = conversation.closing() => {} diff --git a/crates/workshop/server/src/agents/bindings-tests.rs b/crates/workshop/server/src/agents/bindings-tests.rs index ba6ccc42..f0e80520 100644 --- a/crates/workshop/server/src/agents/bindings-tests.rs +++ b/crates/workshop/server/src/agents/bindings-tests.rs @@ -1,33 +1,26 @@ -//! Host binding tests: a run's setup takes the selection and the granted -//! roots. +//! Host binding tests: a run's setup takes the menu's selection. use std::sync::Arc; use runvil::harness::MemoryRecorder; -use tokio::sync::watch; use workshop_menu::{CatalogBus, MenuBus}; -use workshop_registry::{WorkspaceRoots, WorkspaceRootsAdapter}; use super::*; use crate::agents::tests::OfflineBroker; -/// A setup with nothing selected and no roots. +/// A setup with nothing selected. fn empty_setup() -> RunSetup { RunSetup::new(Arc::new(MemoryRecorder::new()), Arc::new(OfflineBroker)) } #[test] -fn a_runs_setup_takes_the_selection_and_the_granted_roots() { +fn a_runs_setup_takes_the_menus_selection() { let registry = Registry::new(); let empty = with_host_state(®istry, empty_setup()); assert_eq!( empty.selected_model, None, "an unregistered menu serves no selection" ); - assert!( - empty.workspace_roots.is_empty(), - "an unregistered workspace serves no roots" - ); let catalog = CatalogBus::new(); let menu = MenuBus::new(catalog.clone(), None); @@ -41,22 +34,7 @@ fn a_runs_setup_takes_the_selection_and_the_granted_roots() { catalog.publish(vec![serde_json::json!({ "id": "test-model" })]); menu.set_selected("test-model") .expect("the id is in the catalog"); - let dir = tempfile::TempDir::new().expect("tempdir"); - let granted = dir.path().to_path_buf(); - let _roots = - registry.register_state::(Arc::new(WorkspaceRootsAdapter::new( - { - let granted = granted.clone(); - move || vec![granted.clone()] - }, - || watch::channel(0).1, - ))); let setup = with_host_state(®istry, empty_setup()); assert_eq!(setup.selected_model.as_deref(), Some("test-model")); - assert_eq!( - setup.workspace_roots, - vec![granted], - "the roots are read through the registry's WorkspaceRoots slot" - ); } diff --git a/crates/workshop/server/src/agents/bindings.rs b/crates/workshop/server/src/agents/bindings.rs index b987645b..f998627b 100644 --- a/crates/workshop/server/src/agents/bindings.rs +++ b/crates/workshop/server/src/agents/bindings.rs @@ -1,29 +1,21 @@ //! The Host state a conversation's run carries in its setup: the menu's -//! selected model and the workspace's granted roots, read through the -//! registry as the run starts, which the run's `ui()` and model -//! resolution read for the whole run. +//! selected model, read through the registry as the run starts. The +//! Harness resolves the run's model from it. use runvil::RunSetup; use workshop_menu::MenuHandles; -use workshop_registry::{Registry, WorkspaceRoots}; +use workshop_registry::Registry; -/// `setup` with its selected model and workspace roots read from -/// `registry`: `selected_model` from the menu's retained workbench state -/// and the granted workspace roots from the registry's roots slot, so this -/// crate reads the workspace through the slot the workspace subsystem -/// registered. An unregistered subsystem's part reads as no selection or -/// no roots. +/// `setup` with its selected model read from `registry`: `selected_model` +/// from the menu's retained workbench state. An unregistered menu reads +/// as no selection. pub(super) fn with_host_state(registry: &Registry, setup: RunSetup) -> RunSetup { let selected_model = registry .state::() .and_then(|handles| handles.menu().latest()) .and_then(|snapshot| snapshot.selected_model); - let workspace_roots = registry - .state::() - .map_or_else(Vec::new, |roots| roots.granted_roots()); RunSetup { selected_model, - workspace_roots, ..setup } } diff --git a/crates/workshop/server/src/app.rs b/crates/workshop/server/src/app.rs index afe7a0a0..69bd6656 100644 --- a/crates/workshop/server/src/app.rs +++ b/crates/workshop/server/src/app.rs @@ -53,7 +53,7 @@ pub struct AppState { /// The registration guards keeping every subsystem's self-registrations /// alive: the push channels, the producer sinks, the state handles, the -/// route registrars, the background tasks, and the workspace roots view. +/// route registrars, and the background tasks. #[derive(Clone)] struct Registrations { guards: Vec>, diff --git a/crates/workshop/server/src/app/compose.rs b/crates/workshop/server/src/app/compose.rs index 9a84f70e..73f2d26f 100644 --- a/crates/workshop/server/src/app/compose.rs +++ b/crates/workshop/server/src/app/compose.rs @@ -9,7 +9,7 @@ use workshop_gateway::{GatewayBinding, GatewayHandles, GatewayHealth, ResolvedGa use workshop_menu::MenuHandles; use workshop_menu::catalog::CatalogBus; use workshop_menu::menu::MenuBus; -use workshop_registry::{Push, Registry, WorkspaceRoots}; +use workshop_registry::{Push, Registry}; use workshop_status::StatusBus; use workshop_support::{Config, ReconnectBackoff}; use workshop_user_state::UserStateStore; @@ -60,7 +60,6 @@ pub(super) fn compose( registry.require::()?; registry.require::()?; registry.require::()?; - registry.require::()?; registry.require::()?; push.push_idle(); Ok(AppState { @@ -148,8 +147,8 @@ fn register_gateway( Ok(backoff) } -/// The workspace subsystem: its file handle plus the routes, state, -/// roots, and shutdown task it self-registers. +/// The workspace subsystem: its file handle plus the routes, state, and +/// shutdown task it self-registers. fn register_workspace( registry: &Registry, registrations: &mut Registrations, @@ -164,7 +163,6 @@ fn register_workspace( let regs = workshop_workspace::register(registry, &workspace); registrations.hold(regs.routes); registrations.hold(regs.state); - registrations.hold(regs.roots); // The shutdown lever that closes the workspace file inside the // graceful stop, so a quit leaves one complete file and no // sidecar. diff --git a/crates/workshop/server/src/lib.rs b/crates/workshop/server/src/lib.rs index bb4a7035..093d4bf1 100644 --- a/crates/workshop/server/src/lib.rs +++ b/crates/workshop/server/src/lib.rs @@ -47,9 +47,6 @@ //! they outlive sockets on purpose. //! - Status-bar reporting for a conversation is derived in the server //! from the conversation's events, deltas, and failure reports. -//! - The workspace's granted roots are read through the registry's -//! `WorkspaceRoots` slot, never by naming the workspace crate's -//! internals: subsystems meet through the registry. //! - Every API route sits behind `cross_site::guard`, which refuses //! cross-site requests and any `Host` that names a non-loopback //! authority; `/health` and the UI assets stay outside it. diff --git a/crates/workshop/server/tests/it/agents.rs b/crates/workshop/server/tests/it/agents.rs index b452f7f1..3e05e4b9 100644 --- a/crates/workshop/server/tests/it/agents.rs +++ b/crates/workshop/server/tests/it/agents.rs @@ -48,7 +48,7 @@ while true do return end messages:user(text) - models.loop(models.get('test-model')) + models.loop() end ``` "; @@ -85,8 +85,9 @@ fn record_request(requests: &Mutex>, body: &str) { /// Binds the workshop router against an echoing SSE mock gateway, with /// one discovered agent (`echo`) and the retained catalog already -/// holding `test-model`. Returns the server's base `ws://` URL, the -/// tempdir keeping the state alive, and the shared state handle. +/// holding `test-model`, which the menu selects. Returns the server's +/// base `ws://` URL, the tempdir keeping the state alive, and the shared +/// state handle. async fn spawn_agent_server() -> (String, tempfile::TempDir, AppState) { let base_url = spawn_gateway(with_typed_catalog( Router::new().route("/v1/chat/completions", post(echo_completions)), @@ -115,6 +116,13 @@ async fn spawn_agent_server_for_gateway(base_url: String) -> (String, tempfile:: state .catalog() .publish(vec![json!({ "id": "test-model", "object": "model" })]); + // The Gateway's catalog lists `model-a` first, so a run with no + // selection would bind that model. The menu selects `test-model`, the + // one model the test prompts run on. + state + .menu() + .set_selected("test-model") + .expect("the selected model is in the retained catalog"); (base, dir, state) } @@ -220,5 +228,4 @@ pub(crate) fn delta_text(turn: &Turn) -> String { mod lifecycle; mod refusals; mod replacement; -mod revoke; mod turns; diff --git a/crates/workshop/server/tests/it/agents/revoke.rs b/crates/workshop/server/tests/it/agents/revoke.rs deleted file mode 100644 index e8eba3bf..00000000 --- a/crates/workshop/server/tests/it/agents/revoke.rs +++ /dev/null @@ -1,114 +0,0 @@ -//! Workspace revokes against agent conversations: a root revoked while one -//! conversation runs is gone from the Host snapshot the next -//! conversation's run reads, and the running one keeps its launch -//! snapshot. - -use tokio::sync::mpsc; -use workshop_workspace::Workspace; - -use super::*; - -/// The roots agent: its run opens with a model round naming the `ui()` -/// snapshot's workspace root, then echoes each input with the root its -/// `ui()` reports at that turn. -const ROOTS_MD: &str = r"--- -name: roots -description: The roots test agent on the unified runtime. -runvil: 0 -uses: - - user ---- - -## Conversation - -```lua -messages:user('launch@' .. tostring(ui().workspace_root)) -models.loop(models.get('test-model')) -while true do - local text = tasks.receive() - messages:user(text .. '@' .. tostring(ui().workspace_root)) - models.loop(models.get('test-model')) -end -``` -"; - -/// The last message of the next model round the gateway received. -async fn next_round(rounds: &mut mpsc::UnboundedReceiver) -> String { - tokio::time::timeout(Duration::from_secs(10), rounds.recv()) - .await - .expect("the model round arrives in time") - .expect("the gateway is alive") -} - -/// The content of a completion request's last message. -fn last_content(body: &str) -> String { - let body: serde_json::Value = serde_json::from_str(body).expect("the request is JSON"); - body["messages"] - .as_array() - .and_then(|messages| messages.last()) - .and_then(|message| message["content"].as_str()) - .expect("the request includes a message") - .to_owned() -} - -#[tokio::test] -async fn a_revoke_reaches_the_next_conversation_and_a_running_one_keeps_its_launch_snapshot() { - let (rounds_tx, mut rounds) = mpsc::unbounded_channel(); - let gateway = spawn_gateway(with_typed_catalog(Router::new().route( - "/v1/chat/completions", - post(move |body: String| { - let rounds_tx = rounds_tx.clone(); - async move { - let _ = rounds_tx.send(last_content(&body)); - echo_completions(body).await - } - }), - ))) - .await; - let (base, dir, state) = spawn_agent_server_for_gateway(gateway).await; - std::fs::write(dir.path().join("agents").join("roots.md"), ROOTS_MD) - .expect("the roots agent writes"); - let workspace = state - .registry() - .state::() - .expect("the workspace is registered"); - let folder = tempfile::TempDir::new().expect("tempdir"); - let granted = workspace - .grant_and_persist(folder.path()) - .await - .expect("the folder grants"); - - let mut running = JsonSocket::connect(&format!("{base}/agents/ws")).await; - assert_eq!(running.recv_json().await["type"], "agents"); - let _running = launch(&mut running, "roots").await; - assert_eq!( - next_round(&mut rounds).await, - format!("launch@{}", granted.display()), - "the launch reads the granted folder" - ); - next_wait(&mut running).await; - - // The revoke lands while the first conversation waits on its inbox. - workspace - .revoke_and_persist(&granted) - .await - .expect("the folder revokes"); - - let mut next = JsonSocket::connect(&format!("{base}/agents/ws")).await; - assert_eq!(next.recv_json().await["type"], "agents"); - let _next = launch(&mut next, "roots").await; - assert_eq!( - next_round(&mut rounds).await, - "launch@nil", - "the next conversation reads roots without the revoked folder" - ); - - answer(&mut running, "turn").await; - assert_eq!( - next_round(&mut rounds).await, - format!("turn@{}", granted.display()), - "the running conversation keeps the snapshot it launched with" - ); - running.close().await; - next.close().await; -} diff --git a/crates/workshop/server/tests/it/agents/turns.rs b/crates/workshop/server/tests/it/agents/turns.rs index 1e73453e..21a70803 100644 --- a/crates/workshop/server/tests/it/agents/turns.rs +++ b/crates/workshop/server/tests/it/agents/turns.rs @@ -28,7 +28,7 @@ uses: tools.offer('web') while true do messages:user(tasks.receive()) - models.loop(models.get('test-model')) + models.loop() end ``` "; diff --git a/crates/workshop/server/tests/it/chat_gate.rs b/crates/workshop/server/tests/it/chat_gate.rs index e7b97bfe..79674084 100644 --- a/crates/workshop/server/tests/it/chat_gate.rs +++ b/crates/workshop/server/tests/it/chat_gate.rs @@ -101,8 +101,8 @@ async fn spawn_chat_server(models: &[&str]) -> GateServer { } /// Spawns the gate server with an explicit menu selection. `None` keeps -/// the catalog available to the launched agent while its live `ui()` -/// snapshot has no selected binding. +/// the catalog available to the launched agent while the menu has no +/// selected model. async fn spawn_chat_server_with_selection(models: &[&str], selected: Option<&str>) -> GateServer { let captured = CapturedRequests::default(); let mock = Arc::clone(&captured); diff --git a/crates/workshop/workspace/src/handles.rs b/crates/workshop/workspace/src/handles.rs index 8acbad3f..7b1e98ab 100644 --- a/crates/workshop/workspace/src/handles.rs +++ b/crates/workshop/workspace/src/handles.rs @@ -1,24 +1,20 @@ //! The workspace subsystem's registration and any handle types. It //! registers its `/workspace/*` routes, merged into the server's API -//! router, the workspace itself as its state handle set, its -//! granted-roots view and change signal, which the server's -//! agent-session bindings read through the registry, and the shutdown -//! lever that closes the workspace file inside the server's graceful -//! stop. +//! router, the workspace itself as its state handle set, and the +//! shutdown lever that closes the workspace file inside the server's +//! graceful stop. use std::sync::Arc; use workshop_registry::{ BackgroundTaskAdapter, Registration, Registry, RouteRegistrarAdapter, ShutdownHandle, - WorkspaceRoots, WorkspaceRootsAdapter, }; use crate::handlers; use crate::workspace::Workspace; -/// The workspace subsystem's registration guards: its routes, its state -/// handle, and its granted-roots view. Dropping them deregisters the -/// subsystem. +/// The workspace subsystem's registration guards: its routes and its +/// state handle. Dropping them deregisters the subsystem. #[derive(Debug)] #[must_use = "dropping the registrations deregisters the subsystem"] pub struct WorkspaceRegistrations { @@ -26,40 +22,21 @@ pub struct WorkspaceRegistrations { pub routes: Registration, /// The workspace itself as its state handle. pub state: Registration, - /// The granted-roots view the server's agent-session bindings read. - pub roots: Registration, } /// Registers the workspace subsystem into the registry: its /// `/workspace/*` routes (the confined filesystem and the /// `/workspace/file/*` document routes), merged into the server's API -/// router, the workspace itself as its state handle set, and its -/// granted-roots view and change signal, which the server's agent-session -/// bindings read through the registry. The returned guards keep the -/// registrations alive; the composition root holds them for the process -/// lifetime. +/// router, and the workspace itself as its state handle set. The +/// returned guards keep the registrations alive; the composition root +/// holds them for the process lifetime. pub fn register(registry: &Registry, workspace: &Workspace) -> WorkspaceRegistrations { let routes = registry.register_routes(Arc::new(RouteRegistrarAdapter::new({ let workspace = workspace.clone(); move || handlers::routes(workspace.clone()) }))); let state = registry.register_state::(Arc::new(workspace.clone())); - let roots = - registry.register_state::(Arc::new(WorkspaceRootsAdapter::new( - { - let workspace = workspace.clone(); - move || workspace.granted_roots() - }, - { - let workspace = workspace.clone(); - move || workspace.subscribe_roots() - }, - ))); - WorkspaceRegistrations { - routes, - state, - roots, - } + WorkspaceRegistrations { routes, state } } /// Registers the subsystem's one background task: the shutdown lever diff --git a/crates/workshop/workspace/src/workspace.rs b/crates/workshop/workspace/src/workspace.rs index 86c876df..21cde074 100644 --- a/crates/workshop/workspace/src/workspace.rs +++ b/crates/workshop/workspace/src/workspace.rs @@ -22,7 +22,6 @@ use std::sync::atomic::AtomicBool; use std::sync::{Arc, PoisonError, RwLock}; use serde::Serialize; -use tokio::sync::watch; use crate::error::WorkspaceError; use crate::rfc3339::now_rfc3339; @@ -197,8 +196,6 @@ pub struct Workspace { /// Where the last-used file is remembered between runs; `None` when /// built without a state directory (see [`Workspace::with_state_dir`]). pointer: Option, - /// The grant-set generation behind [`Workspace::subscribe_roots`]. - roots_generation: watch::Sender, #[cfg(feature = "test-fixtures")] stall: Arc, } @@ -213,7 +210,6 @@ impl Default for Workspace { switches: Arc::default(), closed: Arc::default(), pointer: None, - roots_generation: watch::Sender::default(), #[cfg(feature = "test-fixtures")] stall: Arc::new(stall::WriteStall::new()), } @@ -282,8 +278,6 @@ impl Workspace { added_at: (self.now)(), }) .clone(); - drop(grants); - self.bump_roots(); Ok((root, meta)) } @@ -336,7 +330,6 @@ impl Workspace { if !removed { return Err(WorkspaceError::NotGranted); } - self.bump_roots(); Ok(()) } @@ -352,22 +345,6 @@ impl Workspace { .collect() } - /// A watch on the grant-set generation, which every grant, revoke, - /// and workspace switch bumps, so a subscriber re-reads - /// [`Workspace::granted_roots`] when it changes. - #[must_use] - pub(crate) fn subscribe_roots(&self) -> watch::Receiver { - self.roots_generation.subscribe() - } - - /// Bumps the grant-set generation, waking every roots subscriber. - /// Called after the grants lock is released, so a woken subscriber - /// reads the new set. - fn bump_roots(&self) { - self.roots_generation - .send_modify(|generation| *generation = generation.wrapping_add(1)); - } - /// Reads a confined UTF-8 text file with its size and conflict /// token. Binary and oversized files are rejected. /// diff --git a/crates/workshop/workspace/src/workspace/backing.rs b/crates/workshop/workspace/src/workspace/backing.rs index 1a79d015..13b677ab 100644 --- a/crates/workshop/workspace/src/workspace/backing.rs +++ b/crates/workshop/workspace/src/workspace/backing.rs @@ -343,8 +343,6 @@ impl Workspace { }, ); } - drop(map); - self.bump_roots(); } /// Closes the backing file and leaves the workspace ephemeral: the @@ -447,7 +445,6 @@ impl Workspace { path: path.to_path_buf(), ui_state, }); - self.bump_roots(); self.remember(path).await; if let Some(previous) = previous { previous.file.close().await; diff --git a/crates/workshop/workspace/src/workspace/tests/grants.rs b/crates/workshop/workspace/src/workspace/tests/grants.rs index 0720aff0..328ec04f 100644 --- a/crates/workshop/workspace/src/workspace/tests/grants.rs +++ b/crates/workshop/workspace/src/workspace/tests/grants.rs @@ -1,8 +1,7 @@ //! Grant order and time in memory: save-as writes the grants in the //! order they were made, each with its own time, whether the workspace //! was file-backed or ephemeral, and positions loaded from a file -//! survive a save-as unchanged. Every grant, revoke, and switch -//! signals a roots change. +//! survive a save-as unchanged. use super::*; @@ -186,50 +185,3 @@ async fn replace_all_preserves_stored_positions_through_save_as() { "b before a with the stored positions and times intact" ); } - -#[tokio::test] -async fn grants_revokes_and_switches_each_signal_a_roots_change() { - let files = tempfile::TempDir::new().expect("tempdir"); - let current = files.path().join("current.rvwork"); - let other = files.path().join("other.rvwork"); - let writer = Workspace::new(); - writer - .save_as(&other) - .await - .expect("the other file creates"); - writer.close_backing().await; - let dir = tempfile::TempDir::new().expect("tempdir"); - let workspace = Workspace::new(); - let mut roots = workspace.subscribe_roots(); - let mut signalled = |what: &str| { - assert!( - roots.has_changed().expect("the workspace holds the sender"), - "{what} signals a roots change" - ); - roots.mark_unchanged(); - }; - - workspace - .grant_and_persist(dir.path()) - .await - .expect("the grant lands"); - signalled("a grant"); - workspace - .revoke_and_persist(dir.path()) - .await - .expect("the revoke lands"); - signalled("a revoke"); - workspace.save_as(¤t).await.expect("save as creates"); - signalled("a save as"); - workspace - .open_file(&other) - .await - .expect("the other file opens"); - signalled("an open of another file"); - workspace - .open_file(&other) - .await - .expect("the current file reloads"); - signalled("a reload of the current file"); - workspace.close_backing().await; -} diff --git a/crates/workshop/workspace/tests/it/main.rs b/crates/workshop/workspace/tests/it/main.rs index 429f0f02..e0217526 100644 --- a/crates/workshop/workspace/tests/it/main.rs +++ b/crates/workshop/workspace/tests/it/main.rs @@ -1,5 +1,5 @@ //! Integration tests for `workshop-workspace`: the registration -//! contract - routes and the granted-roots handle served through the +//! contract - routes and the workspace's state handle served through the //! registry's contribution collections - and the save timeout on the //! workspace routes. @@ -11,7 +11,7 @@ use axum::body::Body; use axum::http::{Request, StatusCode}; use axum::response::Response; use tower::ServiceExt as _; -use workshop_registry::{Registry, WorkspaceRoots}; +use workshop_registry::Registry; use workshop_workspace::{Workspace, register}; #[tokio::test] @@ -38,8 +38,7 @@ async fn the_registered_routes_serve_the_workspace_api() { .expect("the router is infallible"); assert_eq!(response.status(), StatusCode::OK); - // A grant over HTTP becomes visible through the registered roots - // handle immediately. + // A grant over HTTP is in the roots listing of the next request. let body = serde_json::json!({ "path": dir.path() }).to_string(); let request = Request::builder() .method("POST") @@ -48,18 +47,37 @@ async fn the_registered_routes_serve_the_workspace_api() { .body(Body::from(body)) .expect("static request parts are valid"); let response = router + .clone() .oneshot(request) .await .expect("the router is infallible"); assert_eq!(response.status(), StatusCode::OK); - let roots = registry - .state::() - .expect("the roots handle is registered") - .granted_roots(); + let request = Request::builder() + .uri("/workspace/tree") + .body(Body::empty()) + .expect("static request parts are valid"); + let response = router + .oneshot(request) + .await + .expect("the router is infallible"); + assert_eq!(response.status(), StatusCode::OK); + let bytes = axum::body::to_bytes(response.into_body(), usize::MAX) + .await + .expect("the body is in memory already"); + let listing: serde_json::Value = serde_json::from_slice(&bytes).expect("the body is JSON"); + let roots = listing["entries"] + .as_array() + .expect("the listing holds its entries"); assert_eq!(roots.len(), 1, "the grant reached the shared state"); + let granted = roots[0]["path"].as_str().expect("an entry names its path"); + let name = dir + .path() + .file_name() + .and_then(|name| name.to_str()) + .expect("a named tempdir"); assert!( - roots[0].ends_with(dir.path().file_name().expect("a named tempdir")), - "the granted root is the dropped directory: {roots:?}" + granted.ends_with(name), + "the granted root is the dropped directory: {granted}" ); } @@ -109,9 +127,7 @@ async fn dropping_the_guards_deregisters_every_contribution() { let guards = register(®istry, &workspace); assert!(!registry.routes().is_empty()); assert!(registry.state::().is_some()); - assert!(registry.state::().is_some()); drop(guards); assert!(registry.routes().is_empty()); assert!(registry.state::().is_none()); - assert!(registry.state::().is_none()); }