From 41aa545b62e29df6107fee9d27ee2db578f99131 Mon Sep 17 00:00:00 2001 From: Sebastian Gieseler Date: Thu, 19 Nov 2026 11:47:56 +0100 Subject: [PATCH] feat(pool): a setup dialog before the share switch goes on (ADR-0113) Switched on, the share switch opens a dialog: what sharing does, the WSL distribution, the caps and what the node agent needs, checked before the switch goes on (POST /hub/pool/share/check), then the start; an admin can grant the machine in the same step. The switch and the sidebar tile are green only while the agent runs and the machine is granted, amber with a link into the dialog while something is missing. A check's `fix` is the command alone; `fix_note` says where it runs. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 12 + crates/devstack-hub/src/lib.rs | 1 + crates/devstack-hub/src/nodehost.rs | 144 +++++++-- crates/devstack-hub/src/share.rs | 48 +++ ...13-the-share-switch-runs-the-node-agent.md | 29 ++ docs/adr/README.md | 50 +-- docs/dashboard-api.md | 3 +- docs/pool.md | 8 + ui/src/App.vue | 2 + ui/src/api/mock/index.ts | 1 + ui/src/api/mock/pool.ts | 55 ++-- ui/src/api/transport.ts | 1 + ui/src/api/types.ts | 6 +- ui/src/components/ShareChecks.vue | 96 ++++++ ui/src/components/ShareSetupDialog.vue | 304 ++++++++++++++++++ ui/src/components/ShareSwitch.test.ts | 63 +++- ui/src/components/ShareSwitch.vue | 105 +++--- ui/src/stores/pool.ts | 17 +- 18 files changed, 785 insertions(+), 160 deletions(-) create mode 100644 ui/src/components/ShareChecks.vue create mode 100644 ui/src/components/ShareSetupDialog.vue diff --git a/CHANGELOG.md b/CHANGELOG.md index 58657ad6..5c91ddce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,18 @@ and listed with their assets on the ## [Unreleased] +### Changed + +- **Sharing a machine starts with a setup dialog.** Switched on, the share + switch no longer turns green at once and then says "Not ready yet": a + dialog says what sharing does, checks what the node agent needs before + anything is switched (`POST /hub/pool/share/check`), gives the command for + each missing piece, and starts it; an admin can grant the machine as a + node in the same step. The switch is green only while the agent runs and + the machine is granted, amber with a link back into the dialog while + something is missing. A check's command is copied without the words about + where it runs (`fix_note`). + ### Fixed - **The MCP server no longer promises to follow an agent into a worktree.** diff --git a/crates/devstack-hub/src/lib.rs b/crates/devstack-hub/src/lib.rs index 109d2ca8..5ed82e95 100644 --- a/crates/devstack-hub/src/lib.rs +++ b/crates/devstack-hub/src/lib.rs @@ -693,6 +693,7 @@ fn router(state: AppState) -> axum::Router { ) .route("/hub/pool", get(pool::overview)) .route("/hub/pool/share", get(share::get).put(share::put)) + .route("/hub/pool/share/check", post(share::check)) .route("/hub/pool/shared", get(shared::list)) .route("/hub/pool/shared/{lease}/open", post(shared::open)) .route("/hub/pool/shared/{lease}/connect", post(shared::connect)) diff --git a/crates/devstack-hub/src/nodehost.rs b/crates/devstack-hub/src/nodehost.rs index dab20a86..c684ca38 100644 --- a/crates/devstack-hub/src/nodehost.rs +++ b/crates/devstack-hub/src/nodehost.rs @@ -57,6 +57,8 @@ pub const WSL_DIR: &str = "/var/lib/devstack-node"; #[cfg_attr(not(windows), allow(dead_code))] pub const FIREWALL_RULE: &str = "devstack-node"; +const MAC: &str = "A Mac cannot run other members' lanes yet."; + /// The switch of one pool, in `node-host.json` beside its membership. A file /// of its own: the `share.json` of releases before 0.23 may still say /// `enabled`, which must not start an agent now. @@ -136,9 +138,12 @@ pub struct Check { pub ok: bool, /// What was found. pub detail: String, - /// What to run when it is missing. + /// What to run when it is missing: the command alone, to be copied. #[serde(skip_serializing_if = "Option::is_none")] pub fix: Option, + /// Where `fix` runs, or what comes before it ("In `Ubuntu` as root"). + #[serde(skip_serializing_if = "Option::is_none")] + pub fix_note: Option, /// Missing, the agent still starts (the GPU, the firewall rule). #[serde(skip_serializing_if = "std::ops::Not::not")] pub optional: bool, @@ -472,7 +477,7 @@ fn round(pool: &str, dir: &Path, poked: bool) { if cfg!(target_os = "macos") { set(pool, |h| { h.state = State::Unsupported; - h.detail = Some("A Mac cannot run other members' lanes yet.".into()); + h.detail = Some(MAC.into()); }); return; } @@ -684,22 +689,61 @@ fn round(pool: &str, dir: &Path, poked: bool) { } } -/// Whether what the agent needs is there; the checks go to the pool's -/// [`Host`]. On Linux the agent's own start says what is missing. -fn ready(pool: &str, sw: &Switch) -> Result<(), String> { +/// What the agent would find with a switch, before it is on: the setup +/// dialog shows it (`POST /hub/pool/share/check`), and a start goes by it. +#[derive(Debug, Clone, Default, Serialize)] +pub struct Preflight { + /// Every required check passes: the agent would start. + pub ready: bool, + /// Why it would not. + #[serde(skip_serializing_if = "Option::is_none")] + pub problem: Option, + #[serde(skip_serializing_if = "Vec::is_empty")] + pub checks: Vec, + /// Windows: the distributions there are (Docker Desktop's left out). + #[serde(skip_serializing_if = "Vec::is_empty")] + pub distros: Vec, + /// For a coding agent: how to set up what `checks` misses. + #[serde(skip_serializing_if = "Option::is_none")] + pub prompt: Option, +} + +impl Preflight { + fn not(problem: String) -> Self { + Self { + problem: Some(problem), + ..Self::default() + } + } +} + +/// Runs the checks (on Windows `wsl.exe` and PowerShell, seconds): not on an +/// async thread. +pub fn preflight(sw: &Switch) -> Preflight { + if cfg!(target_os = "macos") { + return Preflight::not(MAC.into()); + } + if let Some(why) = sw.problem() { + return Preflight::not(why); + } + needs(sw) +} + +/// Whether what the agent needs is there. On Linux the agent's own start +/// says what is missing. +fn needs(sw: &Switch) -> Preflight { #[cfg(windows)] { let distros = wsl::distros(); - set(pool, |h| h.distros = distros.clone()); let Some(distro) = sw.distro.clone() else { - set(pool, |h| { - h.checks.clear(); - h.prompt = Some(wsl::prompt(None, &[], sw.port())); - }); - return Err( - "Choose the WSL distribution the node agent runs in (one with Docker Engine of its own, not Docker Desktop's)." - .into(), - ); + return Preflight { + prompt: Some(wsl::prompt(None, &[], sw.port())), + distros, + ..Preflight::not( + "Choose the WSL distribution the node agent runs in (one with Docker Engine of its own, not Docker Desktop's)." + .into(), + ) + }; }; let checks = wsl::checks(&distro, &distros, sw.port()); let missing = checks.iter().any(|c| !c.ok && !c.optional); @@ -707,24 +751,39 @@ fn ready(pool: &str, sw: &Switch) -> Result<(), String> { .iter() .any(|c| !c.ok) .then(|| wsl::prompt(Some(&distro), &checks, sw.port())); - set(pool, |h| { - h.checks = checks; - h.prompt = prompt; - }); - if missing { - return Err(format!( - "The WSL distribution `{distro}` lacks what the node agent needs: see the checks." - )); + Preflight { + ready: !missing, + problem: missing.then(|| { + format!( + "The WSL distribution `{distro}` lacks what the node agent needs: see the checks." + ) + }), + checks, + distros, + prompt, } - Ok(()) } #[cfg(not(windows))] { - let _ = (pool, sw); - Ok(()) + let _ = sw; + Preflight { + ready: true, + ..Preflight::default() + } } } +/// [`needs`], with the checks put on the pool's [`Host`]. +fn ready(pool: &str, sw: &Switch) -> Result<(), String> { + let p = needs(sw); + set(pool, |h| { + h.distros = p.distros; + h.checks = p.checks; + h.prompt = p.prompt; + }); + p.problem.map_or(Ok(()), Err) +} + /// Last lines of output kept per agent. #[cfg_attr(target_os = "macos", allow(dead_code))] const KEEP_LINES: usize = 40; @@ -924,6 +983,7 @@ echo "memory=$(awk '/MemTotal/ {print $2 * 1024}' /proc/meminfo)""#; format!("no WSL distribution `{distro}`") }, fix: (!exists).then(|| format!("wsl --install -d {distro}")), + fix_note: (!exists).then(|| "In PowerShell".into()), optional: false, }]; if !exists { @@ -934,8 +994,9 @@ echo "memory=$(awk '/MemTotal/ {print $2 * 1024}' /proc/meminfo)""#; name: "networking".into(), ok: mode == "mirrored", detail: format!("networking mode: {}", if mode.is_empty() { "unknown" } else { mode }), - fix: (mode != "mirrored").then(|| { - "In %UserProfile%\\.wslconfig under [wsl2]: networkingMode=mirrored, then `wsl --shutdown` (ends Docker Desktop too: start it again)".into() + fix: (mode != "mirrored").then(|| "wsl --shutdown".into()), + fix_note: (mode != "mirrored").then(|| { + "In %UserProfile%\\.wslconfig under [wsl2] set networkingMode=mirrored, then in PowerShell (ends Docker Desktop too: start it again)".into() }), optional: false, }); @@ -951,9 +1012,10 @@ echo "memory=$(awk '/MemTotal/ {print $2 * 1024}' /proc/meminfo)""#; } else { "`docker` talks to Docker Desktop".into() }, - fix: (!own).then(|| { + fix: (!own).then(|| "curl -fsSL https://get.docker.com | sh".into()), + fix_note: (!own).then(|| { format!( - "Turn Docker Desktop's WSL integration off for `{distro}`, then in it as root: curl -fsSL https://get.docker.com | sh" + "Turn Docker Desktop's WSL integration off for `{distro}`, then in `{distro}` as root" ) }), optional: false, @@ -970,9 +1032,10 @@ echo "memory=$(awk '/MemTotal/ {print $2 * 1024}' /proc/meminfo)""#; }, fix: (!same).then(|| { format!( - "In `{distro}` as root: curl -fsSL https://github.com/nuetzliches/devstack/releases/latest/download/install.sh | sh -s -- --version {version}" + "curl -fsSL https://github.com/nuetzliches/devstack/releases/latest/download/install.sh | sh -s -- --version {version}" ) }), + fix_note: (!same).then(|| format!("In `{distro}` as root")), optional: false, }); let gpus: u32 = get("gpus").parse().unwrap_or(0); @@ -986,7 +1049,10 @@ echo "memory=$(awk '/MemTotal/ {print $2 * 1024}' /proc/meminfo)""#; (n, false) => format!("{n} NVIDIA GPU(s), but Docker has no `nvidia` runtime"), }, fix: (gpus > 0 && !runtime).then(|| { - "Install the NVIDIA Container Toolkit in the distribution, then: nvidia-ctk runtime configure --runtime=docker && systemctl restart docker".into() + "nvidia-ctk runtime configure --runtime=docker && systemctl restart docker".into() + }), + fix_note: (gpus > 0 && !runtime).then(|| { + format!("Install the NVIDIA Container Toolkit in `{distro}`, then in it as root") }), optional: true, }); @@ -998,9 +1064,10 @@ echo "memory=$(awk '/MemTotal/ {print $2 * 1024}' /proc/meminfo)""#; Some(false) => format!("no Hyper-V firewall rule `{FIREWALL_RULE}`: other members may not reach port {port}"), None => "the Hyper-V firewall rule could not be read".into(), }, + fix_note: (firewall != Some(true)).then(|| "In an elevated PowerShell".into()), fix: (firewall != Some(true)).then(|| { format!( - "In an elevated PowerShell: New-NetFirewallHyperVRule -Name {FIREWALL_RULE} -DisplayName \"devstack node agent\" -Direction Inbound -VMCreatorId '{{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}}' -Protocol TCP -LocalPorts {port}" + "New-NetFirewallHyperVRule -Name {FIREWALL_RULE} -DisplayName \"devstack node agent\" -Direction Inbound -VMCreatorId '{{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}}' -Protocol TCP -LocalPorts {port}" ) }), optional: true, @@ -1063,8 +1130,10 @@ echo "memory=$(awk '/MemTotal/ {print $2 * 1024}' /proc/meminfo)""#; for c in checks.iter().filter(|c| !c.ok) { n += 1; p.push_str(&format!("{n}. {}: {}", c.name, c.detail)); - if let Some(f) = &c.fix { - p.push_str(&format!(". {f}")); + match (&c.fix_note, &c.fix) { + (Some(w), Some(f)) => p.push_str(&format!(". {w}: `{f}`")), + (None, Some(f)) => p.push_str(&format!(". `{f}`")), + _ => {} } p.push('\n'); } @@ -1379,6 +1448,13 @@ mod tests { .collect(); assert_eq!(required, ["networking", "docker", "devstack"]); assert!(c.iter().filter(|c| !c.ok).all(|c| c.fix.is_some())); + // The command alone is copied: where it runs stays beside it. + let devstack = c.iter().find(|c| c.name == "devstack").unwrap(); + assert!( + devstack.fix.as_deref().unwrap().starts_with("curl -fsSL "), + "{devstack:?}" + ); + assert_eq!(devstack.fix_note.as_deref(), Some("In `Ubuntu` as root")); let p = wsl::prompt(Some("Ubuntu"), &c, 4261); assert!( p.contains("--version 0.50.0") && p.contains("networkingMode=mirrored"), diff --git a/crates/devstack-hub/src/share.rs b/crates/devstack-hub/src/share.rs index a983e819..889e4cfc 100644 --- a/crates/devstack-hub/src/share.rs +++ b/crates/devstack-hub/src/share.rs @@ -14,6 +14,8 @@ //! - `GET /hub/pool/share?pool=`: what is measured, the last report, the //! coordinator's devstack, the switch and its agent (`switch`, `host`) //! - `PUT /hub/pool/share?pool=`: change the switch (`nodehost::Switch`) +//! - `POST /hub/pool/share/check?pool=`: what the agent would find with a +//! switch, before it is on (`nodehost::Preflight`) use axum::Json; use axum::extract::Query; @@ -319,6 +321,52 @@ pub async fn put(Query(q): Query, Json(new): Json, + Json(sw): Json, +) -> Response { + let bad = |m: String| { + ( + StatusCode::BAD_REQUEST, + Json(serde_json::json!({ "error": m })), + ) + .into_response() + }; + let Some(pool) = q.name() else { + return bad("pool: a-z, 0-9, `-` and `_`, at most 32".into()); + }; + let member = match devstack_node::member::Local::new(&dir(&pool)).membership() { + Ok(Some(m)) if m.state == State::Approved => m, + _ => { + return bad(format!( + "this machine is no approved member of the pool `{pool}`" + )); + } + }; + let found = tokio::task::spawn_blocking(move || { + let mut p = crate::nodehost::preflight(&sw); + if p.ready && crate::nodehost::local_address(&member.coordinator).is_none() { + p.ready = false; + p.problem = Some(format!( + "No address of this machine reaches the coordinator at {}.", + member.coordinator + )); + } + p + }) + .await; + match found { + Ok(p) => Json(p).into_response(), + Err(e) => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ "error": e.to_string() })), + ) + .into_response(), + } +} + #[cfg(test)] mod tests { use super::{Round, round}; diff --git a/docs/adr/0113-the-share-switch-runs-the-node-agent.md b/docs/adr/0113-the-share-switch-runs-the-node-agent.md index 196c9064..c0f18fd3 100644 --- a/docs/adr/0113-the-share-switch-runs-the-node-agent.md +++ b/docs/adr/0113-the-share-switch-runs-the-node-agent.md @@ -131,3 +131,32 @@ Decided while building, not on the card: `crates/devstack-node/src/node.rs` (`sharing` from the settings), `crates/devstack/src/poolcmd.rs` (`--membership`, `--no-new-lanes`), `ui/src/components/ShareSwitch.vue`. + +## Addendum 2026-11-19: a setup dialog before the switch + +Switched on, the switch went green at once and then said "Not ready yet", +while what was missing stood only on the page "This machine", and the +admin's grant ("Runs the pool's lanes") was a second switch elsewhere +without a visible link to it. The owner approved the card on 2026-11-19: + +1. Switching it on opens a setup dialog instead of saving `enabled`: what + sharing does (and that an admin has to grant the machine), the WSL + distribution, the caps and the checks with the command for each missing + piece, then the start. +2. The hub checks without switching: `POST /hub/pool/share/check` runs what + a start runs (the switch's own problems, on Windows the distribution's + checks, the address toward the coordinator) and saves nothing. Before, + the checks ran only once the switch was on. +3. The switch and the sidebar tile are green only while the agent runs and + the machine is granted; amber, with a link into the dialog, while the + agent is blocked or failed; the accent colour while it starts or waits + for an admin. +4. The last step shows the admin's grant as its own state; an admin can + grant the machine there. + +A check's `fix` is now the command alone, to be copied; `fix_note` says +where it runs. Decided while building: the page keeps its caps form for +later changes; an admin's grant in the dialog is a checkbox, on by default; +turning the switch off needs no dialog. Enforced by +`crates/devstack-hub/src/share.rs` (`check`), `nodehost.rs` (`preflight`), +`ui/src/components/ShareSetupDialog.vue`, `ShareChecks.vue`. diff --git a/docs/adr/README.md b/docs/adr/README.md index 63317bd3..3e2d72b3 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -165,35 +165,35 @@ stay. | [0080](0080-the-main-tree-answers-as-a-lane-shared-is-deprecated.md) | The main working tree answers as the lane `main`; `singleton` replaces `lanes = false`; `shared` is deprecated | Accepted (card in the pull request) | | [0081](0081-a-stack-has-a-page-every-lane-the-same-view.md) | A stack has a page of its own; every lane, `main` included, has the same view | Accepted (card in the pull request); its *Start stack* gone, *Stop stack* and *Restart stack* renamed by ADR-0095 | | [0082](0082-the-ports-of-a-machine.md) | The ports of a machine: every stack says what it holds, a stack can run shifted | Accepted (card in the pull request); built: points 1 (`/v1/ports`, `/hub/ports`, `doctor`) and 2 (the graph) in 0.33.0, points 3 to 7 (the shift, the claims, `up --shift`) after it; point 6 amended by ADR-0096 (a port in use now refuses the start) | -| [0083](0083-the-hub-takes-out-what-an-agent-switched-off-leaves.md) | The hub takes out what an agent switched off leaves: devstack's generated skills, and the folders a removed skill empties | Accepted (card in the pull request); built | +| [0083](0083-the-hub-takes-out-what-an-agent-switched-off-leaves.md) | The hub takes out what an agent switched off leaves: devstack's generated skills, and the folders a removed skill empties | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | | [0084](0084-the-sidebar-orders-stacks-by-name-or-last-opened.md) | The sidebar orders the stacks by name or by last opened, a choice kept in the browser | Accepted (card in the pull request); built; point 1 amended by ADR-0086 (favourites); extended by ADR-0102 (last edited) | -| [0085](0085-a-connection-to-a-shared-lane-outlasts-its-restarts.md) | A connection to a shared lane is to the lane: it outlasts the lane's restarts and the hub's; a sharing with nothing to open is refused | Accepted (card in the pull request); built | +| [0085](0085-a-connection-to-a-shared-lane-outlasts-its-restarts.md) | A connection to a shared lane is to the lane: it outlasts the lane's restarts and the hub's; a sharing with nothing to open is refused | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | | [0086](0086-favourite-stacks-list-first.md) | Favourite stacks list first, marked by a star kept in the browser | Accepted (card in the pull request); built; point 5 decided by ADR-0102 (hiding) | -| [0087](0087-the-generated-skills-are-the-hubs-no-tool-reports-them-outdated.md) | The generated skills are the hub's to keep current; no tool reports them outdated, `skills check` finds tracked copies | Accepted (card in the pull request); built | -| [0088](0088-a-lane-shows-how-far-its-branch-is-ahead-and-behind.md) | A lane shows how far its branch is ahead of and behind its upstream, from the local refs only | Accepted (card in the pull request); built | -| [0089](0089-a-folder-scan-filters-and-adds-repositories-not-set-up.md) | A folder scan filters by git and stack file, one level deep by default, and adds a repository without a stack file as not set up | Accepted (card in the pull request); built | +| [0087](0087-the-generated-skills-are-the-hubs-no-tool-reports-them-outdated.md) | The generated skills are the hub's to keep current; no tool reports them outdated, `skills check` finds tracked copies | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0088](0088-a-lane-shows-how-far-its-branch-is-ahead-and-behind.md) | A lane shows how far its branch is ahead of and behind its upstream, from the local refs only | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0089](0089-a-folder-scan-filters-and-adds-repositories-not-set-up.md) | A folder scan filters by git and stack file, one level deep by default, and adds a repository without a stack file as not set up | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | | [0090](0090-a-service-can-get-a-public-link-by-hand.md) | A service can get a public link, by its owner's hand: a Cloudflare Quick Tunnel to its fixed port | Accepted (card in the pull request); built; extended by ADR-0091 (the user's own named tunnel) | | [0091](0091-public-links-through-the-users-own-named-tunnel.md) | Public links can go through the user's own named tunnel, at stable addresses; the hub runs its one connector | Accepted (card in the pull request); built; its step 3, the pool, built by ADR-0092; amended 2026-11-17 (the router keeps its connections, checked per request, #559) | -| [0092](0092-public-links-through-the-pool.md) | A pool can give its members public links below a zone of its own; the coordinator holds the token, each machine gets its own tunnel | Accepted (card in the pull request); built | -| [0093](0093-the-main-tree-takes-its-profile-when-it-starts.md) | The main working tree takes its profile when it starts; the daemon carries none | Accepted (card in the pull request); built | +| [0092](0092-public-links-through-the-pool.md) | A pool can give its members public links below a zone of its own; the coordinator holds the token, each machine gets its own tunnel | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0093](0093-the-main-tree-takes-its-profile-when-it-starts.md) | The main working tree takes its profile when it starts; the daemon carries none | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | | [0094](0094-a-skill-carries-hooks-that-give-text-to-the-agents.md) | A skill carries hooks that give text to the agents; the hub writes one entry per agent and event, `devstack hook` picks the texts | Accepted (card in the pull request); built; addenda 2026-11-06 (end-of-session events `lane-stop`, `session-end`; an upstream the agent has set up itself counts) | -| [0095](0095-the-daemon-ends-with-the-last-tree.md) | The daemon ends with the last tree; a stack has no start of its own, a stop always takes a tree's containers | Accepted (card in the pull request); built | -| [0096](0096-a-port-held-now-refuses-the-start-one-up-of-a-tree-at-a-time.md) | A port held now refuses the start, whoever holds it (a stopped stack's containers too); one `up` of a tree at a time | Accepted (card in the pull request); built | -| [0097](0097-the-dashboards-mark-says-what-needs-attention.md) | The dashboard's mark and favicon carry a red or yellow dot for what needs attention, from an `attention` event of the hub; the mark flips to the nut | Accepted (card in the pull request); built | +| [0095](0095-the-daemon-ends-with-the-last-tree.md) | The daemon ends with the last tree; a stack has no start of its own, a stop always takes a tree's containers | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0096](0096-a-port-held-now-refuses-the-start-one-up-of-a-tree-at-a-time.md) | A port held now refuses the start, whoever holds it (a stopped stack's containers too); one `up` of a tree at a time | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0097](0097-the-dashboards-mark-says-what-needs-attention.md) | The dashboard's mark and favicon carry a red or yellow dot for what needs attention, from an `attention` event of the hub; the mark flips to the nut | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | | [0098](0098-the-skills-page-shows-the-flow-of-the-hooks-and-the-agents-activity.md) | The Skills page shows the flow of the hooks and the agents' activity; devstack keeps only what happened, on this machine, for a week | Accepted (card in the pull request); built; its activity list moved to a lane's timeline (ADR-0099) | -| [0099](0099-a-lane-shows-its-agents-sessions-in-time-from-their-transcripts-when-switched-on.md) | A lane shows its agents' sessions in time; the hub reads their transcripts when switched on, and takes only times, counts and names | Accepted (card in the pull request); built | -| [0100](0100-the-user-chooses-devstacks-mcp-server-for-every-folder.md) | The user can register devstack's MCP server for every folder; the hub writes only its own entry `devstack` | Accepted (card in the pull request); built | -| [0101](0101-a-services-link-can-come-from-its-output-and-stays-on-this-machine.md) | A service's link can come from its output; it belongs to the running instance and stays on this machine | Accepted (card in the pull request); built | -| [0102](0102-the-stacks-list-orders-by-last-commit-hides-stacks-and-filters.md) | The stacks list can order by last commit, hide stacks, and filter by stack or worktree | Accepted (card in the pull request); built | -| [0103](0103-a-pool-lease-waits-for-the-lanes-starting-on-a-node-to-settle.md) | A pool lease waits for the lanes starting on a node to settle rather than be refused | Accepted (card in the pull request); built | -| [0104](0104-the-start-page-shows-every-stack-as-a-tile.md) | The start page shows every stack as a tile, with the hub's figures and the favourite programs | Accepted (card in the pull request); built | -| [0105](0105-a-service-can-be-a-shortcut-card-on-the-overview.md) | A service can be a shortcut card on the overview, marked in the stack file | Accepted (card in the pull request); built | -| [0106](0106-a-running-job-is-running-and-measured.md) | A running job is `running` and measured; it counts as done only when it completed | Accepted (card in the pull request); built | -| [0107](0107-the-start-page-has-a-search-and-a-state-filter.md) | The start page has a search by name or folder and a filter by state | Accepted (card in the pull request); built | -| [0108](0108-the-start-page-has-large-and-small-tiles-and-a-list.md) | The start page shows the stacks as large tiles, small tiles or a sortable list | Accepted (card in the pull request); built | -| [0109](0109-the-order-of-the-stacks-is-one-choice-for-the-sidebar-and-the-start-page.md) | The order of the stacks is one choice for the sidebar and the start page | Accepted (card in the pull request); built | +| [0099](0099-a-lane-shows-its-agents-sessions-in-time-from-their-transcripts-when-switched-on.md) | A lane shows its agents' sessions in time; the hub reads their transcripts when switched on, and takes only times, counts and names | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0100](0100-the-user-chooses-devstacks-mcp-server-for-every-folder.md) | The user can register devstack's MCP server for every folder; the hub writes only its own entry `devstack` | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0101](0101-a-services-link-can-come-from-its-output-and-stays-on-this-machine.md) | A service's link can come from its output; it belongs to the running instance and stays on this machine | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0102](0102-the-stacks-list-orders-by-last-commit-hides-stacks-and-filters.md) | The stacks list can order by last commit, hide stacks, and filter by stack or worktree | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0103](0103-a-pool-lease-waits-for-the-lanes-starting-on-a-node-to-settle.md) | A pool lease waits for the lanes starting on a node to settle rather than be refused | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0104](0104-the-start-page-shows-every-stack-as-a-tile.md) | The start page shows every stack as a tile, with the hub's figures and the favourite programs | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0105](0105-a-service-can-be-a-shortcut-card-on-the-overview.md) | A service can be a shortcut card on the overview, marked in the stack file | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0106](0106-a-running-job-is-running-and-measured.md) | A running job is `running` and measured; it counts as done only when it completed | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0107](0107-the-start-page-has-a-search-and-a-state-filter.md) | The start page has a search by name or folder and a filter by state | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0108](0108-the-start-page-has-large-and-small-tiles-and-a-list.md) | The start page shows the stacks as large tiles, small tiles or a sortable list | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0109](0109-the-order-of-the-stacks-is-one-choice-for-the-sidebar-and-the-start-page.md) | The order of the stacks is one choice for the sidebar and the start page | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | | [0110](0110-a-static-service-forwards-paths-to-another-server.md) | A static service forwards paths to another server, as a reverse proxy in front of it would | Accepted (card in the pull request); built; amended 2026-11-17 (connections to the target kept, #556) | -| [0111](0111-the-dashboards-advisory-gate-counts-what-the-bundle-holds.md) | The dashboard's advisory gate counts what the bundle holds, not npm's runtime tree | Accepted (card in the pull request); built | -| [0112](0112-a-node-gives-a-lane-the-gpus-it-asked-for.md) | A node gives a lane the GPUs it asked for, and no other lane | Accepted (card in the pull request); built | -| [0113](0113-the-share-switch-runs-the-node-agent.md) | The share switch runs the node agent: in the hub on Linux, in WSL2 on Windows | Accepted (card in the pull request); built | -| [0114](0114-a-start-in-the-pool-can-ask-for-gpus.md) | A start in the pool can ask for GPUs, and the dashboard shows where they are | Accepted (card in the pull request); built | +| [0111](0111-the-dashboards-advisory-gate-counts-what-the-bundle-holds.md) | The dashboard's advisory gate counts what the bundle holds, not npm's runtime tree | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0112](0112-a-node-gives-a-lane-the-gpus-it-asked-for.md) | A node gives a lane the GPUs it asked for, and no other lane | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0113](0113-the-share-switch-runs-the-node-agent.md) | The share switch runs the node agent: in the hub on Linux, in WSL2 on Windows | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | +| [0114](0114-a-start-in-the-pool-can-ask-for-gpus.md) | A start in the pool can ask for GPUs, and the dashboard shows where they are | Accepted (card in the pull request); built; amended 2026-11-19 (a setup dialog before the switch) | diff --git a/docs/dashboard-api.md b/docs/dashboard-api.md index 4bfece0b..258b2976 100644 --- a/docs/dashboard-api.md +++ b/docs/dashboard-api.md @@ -150,8 +150,9 @@ and `Referrer-Policy: no-referrer`. The dashboard has no inline script. | `POST /hub/pool/nodes/{id}/policy` (a `NodePolicy` or `null`) | cookie + Origin | admins only: what the node lets run on it, `{allow, repos, memory_headroom?, max_cpus?, share_percent?, network: "lan"\|"internet"\|"none"}`; `null` lifts it | | `POST /hub/pool/join {"coordinator", "fingerprint", "name"?}` | cookie + Origin | ask a pool to admit this machine (`devstack join` without waiting); `GET /hub/pool` shows it pending until an admin approves. `coordinator` is `https://[:]` and nothing more (`400` otherwise). Errors of every `/hub/pool...` route pass on the coordinator's own `{"error"}` only, never the body of whatever else answered | | `POST /hub/pool/members/{id}/role {"role"}` | cookie + Origin | admins only: `member` or `admin`; `409 {"error"}` for the last admin. A member who is no admin gets `403` from all three | -| `GET /hub/pool/share?pool=` | cookie | this machine in the pool, per pool: what it has and what is free (`total`, `free`), whether it is an approved member, the last report (`reported_at`, `error`), whether a node agent of the same membership runs here and reports the machine instead of the hub (`agent`, [#170](https://github.com/nuetzliches/devstack/issues/170)), the `PoolRelease` the coordinator answered it with (`coordinator?`), the machine's GPUs as measured (`gpus?`: `[{name, memory, memory_used, load, offered}]`), the share switch (`switch`: `{enabled, max_cpus?, max_memory?, distro?, port?}`) and the node agent it runs (`host`: `{state: off\|unsupported\|blocked\|starting\|running\|draining\|failed\|foreign, detail?, api?, granted?, guests, checks?: [{name, ok, detail, fix?, optional?}], distros?, prompt?, output?}`, [ADR-0113](adr/0113-the-share-switch-runs-the-node-agent.md)) | +| `GET /hub/pool/share?pool=` | cookie | this machine in the pool, per pool: what it has and what is free (`total`, `free`), whether it is an approved member, the last report (`reported_at`, `error`), whether a node agent of the same membership runs here and reports the machine instead of the hub (`agent`, [#170](https://github.com/nuetzliches/devstack/issues/170)), the `PoolRelease` the coordinator answered it with (`coordinator?`), the machine's GPUs as measured (`gpus?`: `[{name, memory, memory_used, load, offered}]`), the share switch (`switch`: `{enabled, max_cpus?, max_memory?, distro?, port?}`) and the node agent it runs (`host`: `{state: off\|unsupported\|blocked\|starting\|running\|draining\|failed\|foreign, detail?, api?, granted?, guests, checks?: [{name, ok, detail, fix?, fix_note?, optional?}], distros?, prompt?, output?}`, [ADR-0113](adr/0113-the-share-switch-runs-the-node-agent.md)); `fix` is the command alone, `fix_note` where it runs ("In `Ubuntu` as root"; since 0.51.0, before that `fix` said both) | | `PUT /hub/pool/share?pool= {enabled, max_cpus?, max_memory?, distro?, port?}` | cookie + Origin | change the share switch: saved in `node-host.json` beside the membership and acted on within seconds; answers like `GET`. `400 {"error"}` for a machine that is no approved member, a cap of 0 or less, port 0, or a distribution name `wsl -l` would not show | +| `POST /hub/pool/share/check?pool= {enabled, max_cpus?, max_memory?, distro?, port?}` | cookie + Origin | what the node agent would find with that switch, without saving or starting anything (since 0.51.0): `{ready, problem?, checks?, distros?, prompt?}` as in `host` above; `ready` is false while a required check fails, the switch is impossible, no address of this machine reaches the coordinator, or on macOS. Runs the checks (on Windows `wsl.exe` and PowerShell, seconds). `400 {"error"}` for a machine that is no approved member. The setup dialog asks it before the switch goes on | | `POST /hub/shutdown` | `Authorization: Bearer ` | `202`; the hub exits (`devstack hub stop`) | | `POST /hub/pair` | `Authorization: Bearer ` | `{"code": "...", "url": "http://127.0.0.1:4250/auth?code=..."}` (CLI only) | diff --git a/docs/pool.md b/docs/pool.md index b57ce207..2a137f09 100644 --- a/docs/pool.md +++ b/docs/pool.md @@ -78,6 +78,14 @@ knows the agent it runs itself. ### The share switch +Switching it on opens a setup dialog: what sharing does, then the WSL +distribution and the caps with what the agent needs checked before the +switch goes on (`POST /hub/pool/share/check`), each missing piece with the +command that sets it up, then the start; an admin can grant the machine as +a node in the same step. The switch turns green only while the agent runs +and the machine is granted; amber, with a link back into the dialog, while +something is missing. + On, the hub runs the node agent for the current pool and starts it again when it ends (after a failed start, a minute later); the switch, its caps, the WSL distribution and the port are kept in `node-host.json` beside the diff --git a/ui/src/App.vue b/ui/src/App.vue index 1a22522a..6803557a 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -8,6 +8,7 @@ import { ago, useNow } from '@/lib/format'; import TopBar from '@/components/TopBar.vue'; import Toasts from '@/components/Toasts.vue'; import GlobalDialogs from '@/components/GlobalDialogs.vue'; +import ShareSetupDialog from '@/components/ShareSetupDialog.vue'; import CommandPalette from '@/components/CommandPalette.vue'; import Icon from '@/components/icons/Icon.vue'; import Sidebar from '@/components/Sidebar.vue'; @@ -189,6 +190,7 @@ async function startHub() { + diff --git a/ui/src/api/mock/index.ts b/ui/src/api/mock/index.ts index 4e2e88bd..43a9c577 100644 --- a/ui/src/api/mock/index.ts +++ b/ui/src/api/mock/index.ts @@ -828,6 +828,7 @@ export class MockTransport implements Transport { if (p === '/hub/pool' && method === 'GET') return json(200, hub.pool.overview()); if (p === '/hub/pool/share' && method === 'GET') return json(200, hub.pool.share()); if (p === '/hub/pool/share' && method === 'PUT') return json(200, hub.pool.setShare(body as unknown as ShareSwitch)); + if (p === '/hub/pool/share/check' && method === 'POST') return json(200, hub.pool.preflight(body as unknown as ShareSwitch)); const pn = /^\/hub\/pool\/nodes\/([^/]+)\/(pause|resume)$/.exec(p); if (pn && method === 'POST') { const r = hub.pool.pause(decodeURIComponent(pn[1]), pn[2] === 'pause'); diff --git a/ui/src/api/mock/pool.ts b/ui/src/api/mock/pool.ts index 0a12f4b9..539781f7 100644 --- a/ui/src/api/mock/pool.ts +++ b/ui/src/api/mock/pool.ts @@ -3,7 +3,7 @@ // no pool, `?mock=poolmember` one without the admin role. A provisioner made // two nodes (ADR-0051): one runs a lane, one waits for an admin to confirm it; // a third machine's enrolment token was used twice (an alarm). -import type { PoolAuditEntry, PoolLease, PoolMember, PoolNode, PoolOverview, PoolRole, Provisioning, ShareHost, ShareStatus, ShareSwitch } from '../types'; +import type { PoolAuditEntry, PoolLease, PoolMember, PoolNode, PoolOverview, PoolRole, Provisioning, ShareHost, SharePreflight, ShareStatus, ShareSwitch } from '../types'; type R = { status: number; body: unknown }; @@ -36,46 +36,47 @@ export class MockPool { } private host(): ShareHost { - const distros = ['Ubuntu', 'Ubuntu-24.04']; const sw = this.switch; - if (!sw.enabled) return { state: 'off', guests: 0, distros }; - if (!sw.distro) - return { - state: 'blocked', - detail: 'Choose the WSL distribution the node agent runs in (one with Docker Engine of its own, not Docker Desktop\'s).', - guests: 0, - distros, - prompt: 'Set up a WSL2 distribution on this Windows machine so that devstack can run its node agent there…', - }; - if (sw.distro === 'Ubuntu') + const p = this.preflight(sw); + if (!sw.enabled) return { state: 'off', guests: 0, distros: p.distros }; + if (!p.ready) return { state: 'blocked', detail: p.problem, guests: 0, distros: p.distros, checks: p.checks, prompt: p.prompt }; + const me = this.members.find((m) => m.id === this.me); + return { state: 'running', api: 'https://10.0.0.21:4261', granted: !!me?.node, guests: 0, distros: p.distros, checks: p.checks }; + } + + /** `POST /hub/pool/share/check`: what the agent would find with `sw`. */ + preflight(sw: ShareSwitch): SharePreflight { + const distros = ['Ubuntu', 'Ubuntu-24.04']; + const prompt = 'Set up a WSL2 distribution on this Windows machine so that devstack can run its node agent there…'; + if (!sw.distro) return { ready: false, problem: "Choose the WSL distribution the node agent runs in (one with Docker Engine of its own, not Docker Desktop's).", distros, prompt }; + const d = sw.distro; + const optional = [ + { name: 'gpu', ok: true, detail: '1 NVIDIA GPU(s), the container toolkit is set up', optional: true }, + { name: 'firewall', ok: true, detail: 'Hyper-V firewall rule `devstack-node` is there', optional: true }, + ]; + if (d === 'Ubuntu') return { - state: 'blocked', - detail: 'The WSL distribution `Ubuntu` lacks what the node agent needs: see the checks.', - guests: 0, + ready: false, + problem: 'The WSL distribution `Ubuntu` lacks what the node agent needs: see the checks.', distros, checks: [ { name: 'distribution', ok: true, detail: '`Ubuntu` is there' }, { name: 'networking', ok: true, detail: 'networking mode: mirrored' }, - { name: 'docker', ok: false, detail: '`docker` talks to Docker Desktop', fix: "Turn Docker Desktop's WSL integration off for `Ubuntu`, then in it as root: curl -fsSL https://get.docker.com | sh" }, - { name: 'devstack', ok: false, detail: 'devstack is not installed in the distribution', fix: 'In `Ubuntu` as root: curl -fsSL https://github.com/nuetzliches/devstack/releases/latest/download/install.sh | sh -s -- --version 0.50.0' }, - { name: 'gpu', ok: true, detail: '1 NVIDIA GPU(s), the container toolkit is set up', optional: true }, - { name: 'firewall', ok: true, detail: 'Hyper-V firewall rule `devstack-node` is there', optional: true }, + { name: 'docker', ok: false, detail: '`docker` talks to Docker Desktop', fix: 'curl -fsSL https://get.docker.com | sh', fix_note: "Turn Docker Desktop's WSL integration off for `Ubuntu`, then in `Ubuntu` as root" }, + { name: 'devstack', ok: false, detail: 'devstack is not installed in the distribution', fix: 'curl -fsSL https://github.com/nuetzliches/devstack/releases/latest/download/install.sh | sh -s -- --version 0.50.0', fix_note: 'In `Ubuntu` as root' }, + ...optional, ], - prompt: 'Set up a WSL2 distribution on this Windows machine so that devstack can run its node agent there…', + prompt, }; return { - state: 'running', - api: 'https://10.0.0.21:4261', - granted: true, - guests: 0, + ready: true, distros, checks: [ - { name: 'distribution', ok: true, detail: `\`${sw.distro}\` is there` }, + { name: 'distribution', ok: true, detail: `\`${d}\` is there` }, { name: 'networking', ok: true, detail: 'networking mode: mirrored' }, { name: 'docker', ok: true, detail: 'Docker Engine: Ubuntu 24.04.5 LTS' }, { name: 'devstack', ok: true, detail: 'devstack 0.50.0 (this machine: 0.50.0)' }, - { name: 'gpu', ok: true, detail: '1 NVIDIA GPU(s), the container toolkit is set up', optional: true }, - { name: 'firewall', ok: true, detail: 'Hyper-V firewall rule `devstack-node` is there', optional: true }, + ...optional, ], }; } diff --git a/ui/src/api/transport.ts b/ui/src/api/transport.ts index ebc1f83c..456d134e 100644 --- a/ui/src/api/transport.ts +++ b/ui/src/api/transport.ts @@ -98,6 +98,7 @@ export const paths = { poolPlacement: (pool: string, repo: string, lane: string, profile?: string, gpus?: number) => `/hub/pool/placement?repo=${enc(repo)}&lane=${enc(lane)}${pool !== 'default' ? `&pool=${enc(pool)}` : ''}${profile ? `&profile=${enc(profile)}` : ''}${gpus ? `&gpus=${gpus}` : ''}`, poolShare: '/hub/pool/share', + poolShareCheck: '/hub/pool/share/check', poolApprove: (id: string) => `/hub/pool/members/${enc(id)}/approve`, poolRemove: (id: string) => `/hub/pool/members/${enc(id)}/remove`, poolRole: (id: string) => `/hub/pool/members/${enc(id)}/role`, diff --git a/ui/src/api/types.ts b/ui/src/api/types.ts index 09b522d4..97c6f213 100644 --- a/ui/src/api/types.ts +++ b/ui/src/api/types.ts @@ -936,8 +936,10 @@ export type ShareStatus = { }; /** The share switch of one pool: `PUT /hub/pool/share`. `distro` is the WSL distribution on Windows. */ export type ShareSwitch = { enabled: boolean; max_cpus?: number; max_memory?: number; distro?: string; port?: number }; -/** One thing the node agent needs, and whether this machine has it; `optional`: it starts without. */ -export type ShareCheck = { name: string; ok: boolean; detail: string; fix?: string; optional?: boolean }; +/** One thing the node agent needs, and whether this machine has it; `optional`: it starts without. `fix` is the command alone, `fix_note` where it runs (absent from an older hub, whose `fix` says both). */ +export type ShareCheck = { name: string; ok: boolean; detail: string; fix?: string; fix_note?: string; optional?: boolean }; +/** `POST /hub/pool/share/check`: what the node agent would find with a switch, before it is on. */ +export type SharePreflight = { ready: boolean; problem?: string; checks?: ShareCheck[]; distros?: string[]; prompt?: string }; /** The node agent the share switch runs, as the hub last saw it. */ export type ShareHost = { state: 'off' | 'unsupported' | 'blocked' | 'starting' | 'running' | 'draining' | 'failed' | 'foreign'; diff --git a/ui/src/components/ShareChecks.vue b/ui/src/components/ShareChecks.vue new file mode 100644 index 00000000..fb852246 --- /dev/null +++ b/ui/src/components/ShareChecks.vue @@ -0,0 +1,96 @@ + + + + + diff --git a/ui/src/components/ShareSetupDialog.vue b/ui/src/components/ShareSetupDialog.vue new file mode 100644 index 00000000..08dffcd9 --- /dev/null +++ b/ui/src/components/ShareSetupDialog.vue @@ -0,0 +1,304 @@ + + + + + diff --git a/ui/src/components/ShareSwitch.test.ts b/ui/src/components/ShareSwitch.test.ts index 2bf03fc5..0611c09f 100644 --- a/ui/src/components/ShareSwitch.test.ts +++ b/ui/src/components/ShareSwitch.test.ts @@ -58,18 +58,24 @@ describe('the share switch', () => { distros: ['Ubuntu', 'Ubuntu-24.04'], checks: [ { name: 'networking', ok: true, detail: 'networking mode: mirrored' }, - { name: 'docker', ok: false, detail: '`docker` talks to Docker Desktop', fix: 'curl -fsSL https://get.docker.com | sh' }, + { name: 'docker', ok: false, detail: '`docker` talks to Docker Desktop', fix: 'curl -fsSL https://get.docker.com | sh', fix_note: 'In `Ubuntu` as root' }, { name: 'firewall', ok: false, detail: 'no Hyper-V firewall rule', fix: 'New-NetFirewallHyperVRule …', optional: true }, ], prompt: 'Set up a WSL2 distribution …', }, }), ); - expect(el.querySelector('[data-testid="share-state"]')?.textContent).toContain('Not ready yet'); + expect(el.querySelector('[data-testid="share-state"]')?.textContent).toContain('Setup incomplete'); + expect(el.querySelector('[data-testid="share"]')?.classList).toContain('tone-warn'); const checks = el.querySelector('[data-testid="share-checks"]')!; expect(checks.querySelectorAll('li.warn')).toHaveLength(1); - expect(checks.textContent).toContain('curl -fsSL https://get.docker.com | sh'); + // The command alone is copied; where it runs stands above it. + expect(checks.querySelector('[data-testid="share-fix"]')?.textContent).toBe('curl -fsSL https://get.docker.com | sh'); + expect(checks.querySelector('[data-testid="share-fix-note"]')?.textContent).toBe('In `Ubuntu` as root:'); expect(el.querySelector('[data-testid="share-prompt"]')).not.toBeNull(); + // The state and the button open the setup dialog. + el.querySelector('[data-testid="share-finish"]')!.click(); + expect(usePool().shareSetup).toBe(true); const select = el.querySelector('[data-testid="share-distro"]')!; expect([...select.options].map((o) => o.value)).toEqual(['', 'Ubuntu', 'Ubuntu-24.04']); expect(select.value).toBe('Ubuntu'); @@ -101,18 +107,63 @@ describe('the share switch', () => { expect(cpus.value).toBe('2'); }); - it('sends the switch with the chosen distribution', async () => { + it('is green only while the agent runs and the machine is granted', async () => { + const el = await mounted(status({ switch: { enabled: true }, host: { state: 'running', granted: true, guests: 0 } })); + expect(el.querySelector('[data-testid="share"]')?.classList).toContain('tone-ok'); + usePool().share = status({ switch: { enabled: true }, host: { state: 'running', granted: false, guests: 0 } }); + await nextTick(); + expect(el.querySelector('[data-testid="share"]')?.classList).not.toContain('tone-ok'); + }); + + it('switched on, opens the setup instead of sending the switch', async () => { const el = await mounted(status({ switch: { enabled: false }, host: { state: 'off', guests: 0, distros: ['Ubuntu-24.04'] } })); + el.querySelector('[data-testid="share-switch"]')!.click(); + await nextTick(); + expect(usePool().shareSetup).toBe(true); + expect(t.current!.requests.filter((r) => r.method === 'PUT')).toHaveLength(0); + }); +}); + +describe('the share setup dialog', () => { + it('checks before the switch goes on, then sends it with the chosen distribution', async () => { const fake = t.current!; + const checked: unknown[] = []; + fake.on('/hub/pool/share/check', (_m, _p, body) => { + checked.push(body); + const d = (body as { distro?: string }).distro; + return ok( + d === 'Ubuntu-24.04' + ? { ready: true, distros: ['Ubuntu', 'Ubuntu-24.04'], checks: [{ name: 'docker', ok: true, detail: 'Docker Engine' }] } + : { ready: false, problem: 'Choose the WSL distribution', distros: ['Ubuntu', 'Ubuntu-24.04'] }, + ); + }); let sent: unknown = null; fake.on('/hub/pool/share', (method, _path, body) => { if (method === 'PUT') sent = body; return ok(status({ switch: { enabled: true, distro: 'Ubuntu-24.04' }, host: { state: 'starting', guests: 0 } })); }); - const select = el.querySelector('[data-testid="share-distro"]')!; + usePool().share = status({ switch: { enabled: false }, host: { state: 'off', guests: 0 } }); + const Dialog = (await import('./ShareSetupDialog.vue')).default; + const el = document.createElement('div'); + document.body.appendChild(el); + createApp({ render: () => h(Dialog) }).mount(el); + usePool().shareSetup = true; + await vi.waitFor(() => expect(checked).toHaveLength(1)); + const q = (id: string) => document.querySelector(`[data-testid="${id}"]`); + expect(q('share-setup-about')).not.toBeNull(); + q('share-setup-next')!.click(); + await vi.waitFor(() => expect(q('share-setup-problem')?.textContent).toContain('Choose')); + expect((q('share-setup-next') as HTMLButtonElement).disabled).toBe(true); + + const select = q('share-setup-distro') as HTMLSelectElement; select.value = 'Ubuntu-24.04'; select.dispatchEvent(new Event('change')); - el.querySelector('[data-testid="share-switch"]')!.click(); + await vi.waitFor(() => expect(q('share-setup-ready')).not.toBeNull()); + expect(sent).toBeNull(); + q('share-setup-next')!.click(); + await nextTick(); + q('share-setup-go')!.click(); await vi.waitFor(() => expect(sent).toEqual({ enabled: true, distro: 'Ubuntu-24.04' })); + await vi.waitFor(() => expect(q('share-setup-outcome')).not.toBeNull()); }); }); diff --git a/ui/src/components/ShareSwitch.vue b/ui/src/components/ShareSwitch.vue index 4b2bd904..7e84b888 100644 --- a/ui/src/components/ShareSwitch.vue +++ b/ui/src/components/ShareSwitch.vue @@ -4,15 +4,16 @@ // granted it; on Windows in a WSL distribution the user names, whose checks // and setup prompt are shown here. Off while others' lanes run, the agent // takes no new ones and ends with the last. `compact` is the sidebar tile. +// Switched on, it opens the setup dialog, which turns it on once the checks +// pass; green only while the agent runs and the machine is granted. import { computed, onBeforeUnmount, ref, watch } from 'vue'; import type { ShareHost, ShareSwitch } from '@/api/types'; import { bytes } from '@/lib/format'; import { usePool } from '@/stores/pool'; -import { useUi } from '@/stores/ui'; +import ShareChecks from './ShareChecks.vue'; const props = defineProps<{ compact?: boolean }>(); const pool = usePool(); -const ui = useUi(); const s = computed(() => pool.share); const sw = computed(() => s.value?.switch ?? { enabled: false }); const host = computed(() => s.value?.host); @@ -60,8 +61,12 @@ const changed = computed(() => { async function toggle() { if (!s.value) return; + if (!on.value) { + pool.shareSetup = true; + return; + } busy.value = true; - await pool.setShare(props.compact ? { ...sw.value, enabled: !on.value } : form(!on.value)); + await pool.setShare(props.compact ? { ...sw.value, enabled: false } : form(false)); busy.value = false; } async function save() { @@ -89,7 +94,7 @@ const stateText = computed(() => { case 'draining': return `No new lanes; ${h.guests} of others still run here`; case 'blocked': - return 'Not ready yet'; + return 'Setup incomplete: finish it'; case 'failed': return 'The node agent ended'; case 'foreign': @@ -106,29 +111,22 @@ const stateClass = computed(() => { if (st === 'blocked' || st === 'failed') return 'warn'; return 'muted'; }); +/** Switched on, its agent does not run: the setup dialog says what is missing. */ +const stuck = computed(() => on.value && (host.value?.state === 'blocked' || host.value?.state === 'failed')); const windows = computed(() => !!host.value?.distros?.length || !!sw.value.distro); -const missing = computed(() => (host.value?.checks ?? []).filter((c) => !c.ok)); - -async function copy(text: string, what: string) { - try { - await navigator.clipboard.writeText(text); - ui.toast('success', `${what} copied`, ''); - } catch { - ui.toast('error', 'Could not copy', 'The browser did not allow it.'); - } -}