use std::collections::{BTreeMap, BTreeSet};
use super::procs::{ProcState, MESSAGE_ROW};
pub use crate::snapshot::{ContainerStatus, InstanceRow, SandboxRow, ServiceRow, Snapshot};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FetchError {
pub unreachable: bool,
pub reason: String,
}
impl FetchError {
pub fn line(&self) -> String {
if self.unreachable {
format!("needs devsandbox serve: {}", self.reason)
} else {
self.reason.clone()
}
}
fn short(&self) -> String {
if self.unreachable {
return "needs devsandbox serve".into();
}
const MAX: usize = 40;
match self.reason.char_indices().nth(MAX) {
Some((cut, _)) => format!("{}…", &self.reason[..cut]),
None => self.reason.clone(),
}
}
}
pub const ORPHANS_NAME: &str = "(not in config)";
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Node {
Sandbox(usize),
Instance(usize),
Empty(usize),
Orphans,
Proc { instance: usize, row: usize },
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum GroupKey {
Mesh { root: String, sandbox: String },
Host { machine: Option<String>, root: Option<String>, sandbox: String },
}
impl GroupKey {
pub fn collapse_key(&self) -> String {
const SEP: char = '\u{1f}';
match self {
GroupKey::Mesh { root, sandbox } => format!("mesh{SEP}{root}{SEP}{sandbox}"),
GroupKey::Host { machine, root, sandbox } => format!(
"host{SEP}{}{SEP}{}{SEP}{sandbox}",
machine.as_deref().unwrap_or(""),
root.as_deref().unwrap_or("")
),
}
}
}
pub fn group_key(r: &SandboxRow) -> GroupKey {
match &r.mesh_root {
Some(root) => GroupKey::Mesh { root: root.clone(), sandbox: r.name.clone() },
None => GroupKey::Host { machine: r.machine.clone(), root: r.root.clone(), sandbox: r.name.clone() },
}
}
fn tree_rank(sandboxes: &[SandboxRow], i: usize) -> (Option<&str>, &str, usize) {
match &sandboxes[i].machine {
None => (None, "", i),
Some(m) => (Some(m.as_str()), sandboxes[i].name.as_str(), i),
}
}
fn representative(sandboxes: &[SandboxRow], i: usize) -> usize {
let key = group_key(&sandboxes[i]);
(0..sandboxes.len())
.filter(|&j| group_key(&sandboxes[j]) == key)
.min_by(|&a, &b| tree_rank(sandboxes, a).cmp(&tree_rank(sandboxes, b)))
.unwrap_or(i)
}
pub fn group_of(sandboxes: &[SandboxRow], inst: &InstanceRow) -> Option<usize> {
let named = |s: &SandboxRow| s.name == inst.sandbox;
let same = |s: &SandboxRow| named(s) && s.machine == inst.machine;
let found = inst
.mesh_root
.as_ref()
.and_then(|m| sandboxes.iter().position(|s| named(s) && s.mesh_root.as_ref() == Some(m)))
.or_else(|| match &inst.root {
Some(root) => sandboxes.iter().position(|s| same(s) && s.root.as_ref() == Some(root)),
None => sandbox_order(sandboxes)
.into_iter()
.find(|&i| named(&sandboxes[i]) && sandboxes[i].mesh_root.is_some()),
})
.or_else(|| sandboxes.iter().position(same))?;
Some(representative(sandboxes, found))
}
pub fn sandbox_order(sandboxes: &[SandboxRow]) -> Vec<usize> {
let mut order: Vec<usize> = (0..sandboxes.len()).collect();
order.sort_by(|&a, &b| tree_rank(sandboxes, a).cmp(&tree_rank(sandboxes, b)));
let mut seen: Vec<GroupKey> = Vec::new();
order.retain(|&i| {
let key = group_key(&sandboxes[i]);
let new = !seen.contains(&key);
if new {
seen.push(key);
}
new
});
order
}
pub fn visible_nodes(
sandboxes: &[SandboxRow],
instances: &[InstanceRow],
collapsed: &BTreeSet<String>,
expanded_procs: &BTreeSet<String>,
procs: &BTreeMap<String, ProcState>,
) -> Vec<Node> {
let mut nodes = Vec::new();
let groups: Vec<Option<usize>> = instances.iter().map(|inst| group_of(sandboxes, inst)).collect();
for si in sandbox_order(sandboxes) {
nodes.push(Node::Sandbox(si));
if collapsed.contains(&group_key(&sandboxes[si]).collapse_key()) {
continue;
}
let mut any = false;
for (ii, inst) in instances.iter().enumerate() {
if groups[ii] == Some(si) {
nodes.push(Node::Instance(ii));
push_proc_nodes(&mut nodes, ii, inst, expanded_procs, procs);
any = true;
}
}
if !any {
nodes.push(Node::Empty(si));
}
}
let mut orphans: Vec<usize> = (0..instances.len()).filter(|&ii| groups[ii].is_none()).collect();
orphans.sort_by_key(|&ii| instances[ii].machine.is_some());
if !orphans.is_empty() {
nodes.push(Node::Orphans);
if !collapsed.contains(ORPHANS_NAME) {
for ii in orphans {
nodes.push(Node::Instance(ii));
push_proc_nodes(&mut nodes, ii, &instances[ii], expanded_procs, procs);
}
}
}
nodes
}
fn push_proc_nodes(
nodes: &mut Vec<Node>,
instance: usize,
inst: &InstanceRow,
expanded_procs: &BTreeSet<String>,
procs: &BTreeMap<String, ProcState>,
) {
let key = super::remote::instance_key(inst);
if !expanded_procs.contains(&key) {
return;
}
match procs.get(&key) {
Some(ProcState::Rows { rows, .. }) => {
for row in 0..rows.len() {
nodes.push(Node::Proc { instance, row });
}
}
_ => nodes.push(Node::Proc { instance, row: MESSAGE_ROW }),
}
}
pub fn dispatcher_label(row: &InstanceRow, instances: &[InstanceRow]) -> Option<String> {
let id = row.dispatcher.as_deref()?;
Some(match instances.iter().find(|i| i.instance_id == id && i.machine == row.machine) {
Some(owner) => format!("⇠ {}", owner.name),
None => format!("⇠ {id} (orphan)"),
})
}
pub fn sandbox_stats(instances: usize, running: usize) -> String {
format!("{running}/{instances} running")
}
pub use crate::render::humanize_secs;
pub const STALE_AFTER_SECS: u64 = 10;
pub fn totals_line(snapshot: &Snapshot, age: std::time::Duration, error: Option<&FetchError>) -> String {
let running = snapshot
.instances
.iter()
.filter(|r| matches!(r.status, ContainerStatus::Running(_)))
.count();
let stopped = snapshot
.instances
.iter()
.filter(|r| matches!(r.status, ContainerStatus::Exited(_) | ContainerStatus::Missing))
.count();
let service_containers: usize = snapshot
.services
.iter()
.flat_map(|s| &s.containers)
.filter(|(_, st)| !matches!(st, ContainerStatus::Missing | ContainerStatus::Unknown))
.count();
let runtime = match snapshot.no_runtime {
true => "no runtime".to_string(),
false => format!("{} {}", snapshot.runtime_name, snapshot.runtime_version.as_deref().unwrap_or("?")),
};
let mut line = format!(
"{} {} · {running} running / {stopped} stopped · {service_containers} service {} · {runtime}",
snapshot.sandbox_count,
plural(snapshot.sandbox_count, "sandbox", "sandboxes"),
plural(service_containers, "container", "containers"),
);
match error {
Some(e) => line.push_str(&format!(" (stale {}s: {})", age.as_secs(), e.short())),
None if age.as_secs() >= STALE_AFTER_SECS => line.push_str(&format!(" (stale {}s)", age.as_secs())),
None => {}
}
line
}
pub fn identity_line(snapshot: &Snapshot) -> Option<String> {
let n = snapshot
.sandboxes
.iter()
.filter(|s| s.identity.iter().any(|note| !note.acked))
.count();
(n > 0).then(|| format!("{n} {} /root (U to update)", plural(n, "sandbox uses", "sandboxes use")))
}
fn plural<'a>(n: usize, singular: &'a str, plural: &'a str) -> &'a str {
if n == 1 { singular } else { plural }
}
#[cfg(test)]
mod tests {
use super::*;
use std::time::Instant;
#[test]
fn humanize_secs_scales() {
assert_eq!(humanize_secs(0), "0s");
assert_eq!(humanize_secs(40), "40s");
assert_eq!(humanize_secs(60), "1m");
assert_eq!(humanize_secs(12 * 60), "12m");
assert_eq!(humanize_secs(2 * 3600 + 5 * 60), "2h05m");
assert_eq!(humanize_secs(3 * 86_400 + 4 * 3600 + 30 * 60), "3d4h");
}
fn inst(name: &str, status: ContainerStatus) -> InstanceRow {
InstanceRow {
name: name.into(),
sandbox: "s".into(),
container: format!("devsandbox-{name}"),
status,
uptime_secs: 0,
cpu: None,
mem: None,
folder: "/f".into(),
worktree: false,
services: Vec::new(),
workspace: "/w".into(),
remote_user: None,
remote_env_len: 0,
base_folder: "/f".into(),
drift: false,
instance_id: String::new(),
dispatcher: None,
done: false,
profile: None,
profile_disallowed: false,
browser_sandbox: None, github_repos: Vec::new(), build_notes: Vec::new(),
phase: None,
root: None,
mesh_root: None,
machine: None,
}
}
fn svc_row(containers: Vec<ContainerStatus>) -> ServiceRow {
ServiceRow {
name: "db".into(),
scope: "global".into(),
source: "image x".into(),
ports: Vec::new(),
containers: containers
.into_iter()
.enumerate()
.map(|(i, s)| (format!("c{i}"), s))
.collect(),
used_by: Vec::new(),
env_len: 0,
command: None,
config_hash: String::new(),
drift: false,
root: None,
mesh_root: None,
machine: None,
}
}
fn snap(
instances: Vec<InstanceRow>,
services: Vec<ServiceRow>,
sandbox_count: usize,
runtime_version: Option<&str>,
) -> Snapshot {
Snapshot {
instances,
sandboxes: Vec::new(),
services,
sandbox_count,
runtime_name: "docker".into(),
runtime_version: runtime_version.map(str::to_string),
collected_at: Instant::now(),
depth: crate::snapshot::Depth::Full,
error: None,
no_runtime: false,
}
}
#[test]
fn totals_line_counts_running_stopped_and_service_containers() {
let s = snap(
vec![
inst("a", ContainerStatus::Running("Up".into())),
inst("b", ContainerStatus::Exited("Exited".into())),
inst("c", ContainerStatus::Missing),
],
vec![svc_row(vec![
ContainerStatus::Running("Up".into()),
ContainerStatus::Missing,
])],
3,
Some("24.0.7"),
);
assert_eq!(
totals_line(&s, std::time::Duration::from_secs(0), None),
"3 sandboxes · 1 running / 2 stopped · 1 service container · docker 24.0.7",
);
}
#[test]
fn totals_line_skips_unlisted_rows() {
let s = snap(
vec![inst("a", ContainerStatus::Unknown)],
vec![svc_row(vec![ContainerStatus::Unknown])],
1,
None,
);
assert_eq!(
totals_line(&s, std::time::Duration::from_secs(0), None),
"1 sandbox · 0 running / 0 stopped · 0 service containers · docker ?",
);
}
#[test]
fn totals_line_pluralizes_and_marks_missing_version() {
let s = snap(vec![inst("a", ContainerStatus::Running("Up".into()))], Vec::new(), 1, None);
assert_eq!(
totals_line(&s, std::time::Duration::from_secs(0), None),
"1 sandbox · 1 running / 0 stopped · 0 service containers · docker ?",
);
}
#[test]
fn totals_line_names_no_runtime_on_a_driver() {
let s = Snapshot { no_runtime: true, ..snap(Vec::new(), Vec::new(), 1, None) };
assert_eq!(
totals_line(&s, std::time::Duration::from_secs(0), None),
"1 sandbox · 0 running / 0 stopped · 0 service containers · no runtime",
);
}
#[test]
fn totals_line_flags_stale_data() {
let s = snap(Vec::new(), Vec::new(), 0, Some("24.0.7"));
let out = totals_line(&s, std::time::Duration::from_secs(STALE_AFTER_SECS + 2), None);
assert!(out.ends_with(" (stale 12s)"), "got: {out}");
let fresh = totals_line(&s, std::time::Duration::from_secs(1), None);
assert!(!fresh.contains("stale"), "got: {fresh}");
}
#[test]
fn totals_line_says_why_a_refresh_failed() {
let s = snap(Vec::new(), Vec::new(), 0, Some("24.0.7"));
let down = FetchError { unreachable: true, reason: "devsandbox serve did not answer on /run/x within 5s".into() };
let out = totals_line(&s, std::time::Duration::from_secs(3), Some(&down));
assert!(out.ends_with(" (stale 3s: needs devsandbox serve)"), "got: {out}");
assert_eq!(down.line(), "needs devsandbox serve: devsandbox serve did not answer on /run/x within 5s");
let refused = FetchError { unreachable: false, reason: "no directory /gone".into() };
let out = totals_line(&s, std::time::Duration::from_secs(12), Some(&refused));
assert!(out.ends_with(" (stale 12s: no directory /gone)"), "got: {out}");
assert_eq!(refused.line(), "no directory /gone");
let long = FetchError { unreachable: false, reason: "é".repeat(50) };
let out = totals_line(&s, std::time::Duration::from_secs(12), Some(&long));
assert!(out.ends_with(&format!(": {}…)", "é".repeat(40))), "got: {out}");
}
fn sb(name: &str) -> SandboxRow {
SandboxRow {
name: name.into(),
source: "image x".into(),
folder: None,
services: Vec::new(),
extends: Vec::new(),
config_hash: "hash".into(),
build_hash: String::new(),
issues: Vec::new(),
identity: Vec::new(),
dispatcher: false,
worktree_branch: None,
profiles: Vec::new(),
root: None,
mesh_root: None,
machine: None,
}
}
#[test]
fn identity_line_counts_sandboxes_with_unacked_notes() {
use crate::snapshot::IdentityNote;
let note = |acked| IdentityNote { id: "i".into(), text: "t".into(), acked };
let mut s = snap(Vec::new(), Vec::new(), 0, None);
s.sandboxes = vec![sb("clean")];
assert_eq!(identity_line(&s), None);
let mut acked = sb("acked");
acked.identity = vec![note(true)];
s.sandboxes.push(acked);
assert_eq!(identity_line(&s), None, "acked notes don't count");
let mut one = sb("one");
one.identity = vec![note(true), note(false)];
s.sandboxes.push(one.clone());
assert_eq!(identity_line(&s).as_deref(), Some("1 sandbox uses /root (U to update)"));
s.sandboxes.push(one);
assert_eq!(identity_line(&s).as_deref(), Some("2 sandboxes use /root (U to update)"));
}
#[test]
fn dispatcher_label_names_the_owner_or_marks_an_orphan() {
let mut owner = inst("pr-dispatcher", ContainerStatus::Missing);
owner.instance_id = "d-1".into();
let mut child = inst("web-pr-1", ContainerStatus::Missing);
child.instance_id = "c-1".into();
child.dispatcher = Some("d-1".into());
let mut orphan = inst("web-pr-2", ContainerStatus::Missing);
orphan.dispatcher = Some("gone-7".into());
let rows = vec![owner.clone(), child.clone(), orphan.clone()];
assert_eq!(dispatcher_label(&owner, &rows), None, "user-created");
assert_eq!(dispatcher_label(&child, &rows).as_deref(), Some("⇠ pr-dispatcher"));
assert_eq!(dispatcher_label(&orphan, &rows).as_deref(), Some("⇠ gone-7 (orphan)"));
assert_eq!(dispatcher_label(&child, &rows[1..]).as_deref(), Some("⇠ d-1 (orphan)"));
}
fn inst_in(name: &str, sandbox: &str) -> InstanceRow {
let mut row = inst(name, ContainerStatus::Missing);
row.sandbox = sandbox.into();
row
}
fn collapsed(names: &[&str]) -> BTreeSet<String> {
names.iter().map(|s| s.to_string()).collect()
}
fn local_key(name: &str) -> String {
group_key(&sb(name)).collapse_key()
}
fn no_procs() -> (BTreeSet<String>, BTreeMap<String, ProcState>) {
(BTreeSet::new(), BTreeMap::new())
}
#[test]
fn visible_nodes_expands_sandboxes_with_instances() {
let sandboxes = vec![sb("a"), sb("b")];
let instances = vec![
inst_in("a1", "a"),
inst_in("b1", "b"),
inst_in("a2", "a"),
];
let (ep, pm) = no_procs();
let nodes = visible_nodes(&sandboxes, &instances, &BTreeSet::new(), &ep, &pm);
assert_eq!(
nodes,
vec![
Node::Sandbox(0),
Node::Instance(0), Node::Instance(2), Node::Sandbox(1),
Node::Instance(1), ],
);
}
#[test]
fn visible_nodes_empty_sandbox_gets_marker() {
let sandboxes = vec![sb("a")];
let (ep, pm) = no_procs();
let nodes = visible_nodes(&sandboxes, &[], &BTreeSet::new(), &ep, &pm);
assert_eq!(nodes, vec![Node::Sandbox(0), Node::Empty(0)]);
}
#[test]
fn visible_nodes_collapsed_sandbox_hides_children() {
let sandboxes = vec![sb("a"), sb("b")];
let instances = vec![inst_in("a1", "a"), inst_in("b1", "b")];
let (ep, pm) = no_procs();
let nodes = visible_nodes(&sandboxes, &instances, &collapsed(&[&local_key("a")]), &ep, &pm);
assert_eq!(
nodes,
vec![Node::Sandbox(0), Node::Sandbox(1), Node::Instance(1)],
);
}
#[test]
fn visible_nodes_orphans_group_at_bottom() {
let sandboxes = vec![sb("a")];
let instances = vec![inst_in("a1", "a"), inst_in("x1", "gone")];
let (ep, pm) = no_procs();
let nodes = visible_nodes(&sandboxes, &instances, &BTreeSet::new(), &ep, &pm);
assert_eq!(
nodes,
vec![
Node::Sandbox(0),
Node::Instance(0),
Node::Orphans,
Node::Instance(1),
],
);
let nodes = visible_nodes(&sandboxes, &instances, &collapsed(&[ORPHANS_NAME]), &ep, &pm);
assert_eq!(
nodes,
vec![Node::Sandbox(0), Node::Instance(0), Node::Orphans],
);
}
#[test]
fn visible_nodes_no_orphan_group_when_all_configured() {
let sandboxes = vec![sb("a")];
let instances = vec![inst_in("a1", "a")];
let (ep, pm) = no_procs();
let nodes = visible_nodes(&sandboxes, &instances, &BTreeSet::new(), &ep, &pm);
assert!(!nodes.contains(&Node::Orphans));
}
fn proc_row(pid: &str) -> super::super::procs::ProcRow {
super::super::procs::ProcRow { pid: pid.into(), depth: 0, args: "x".into() }
}
#[test]
fn visible_nodes_emits_proc_rows_under_expanded_instance() {
let sandboxes = vec![sb("a")];
let instances = vec![inst_in("a1", "a")];
let expanded: BTreeSet<String> = ["a1".to_string()].into_iter().collect();
let mut procs = BTreeMap::new();
procs.insert(
"a1".to_string(),
ProcState::Rows { rows: vec![proc_row("1"), proc_row("2")], signalable: true, sessions: None },
);
let nodes = visible_nodes(&sandboxes, &instances, &BTreeSet::new(), &expanded, &procs);
assert_eq!(
nodes,
vec![
Node::Sandbox(0),
Node::Instance(0),
Node::Proc { instance: 0, row: 0 },
Node::Proc { instance: 0, row: 1 },
],
);
}
#[test]
fn visible_nodes_message_row_when_not_fetched_or_error() {
let sandboxes = vec![sb("a")];
let instances = vec![inst_in("a1", "a")];
let expanded: BTreeSet<String> = ["a1".to_string()].into_iter().collect();
let nodes =
visible_nodes(&sandboxes, &instances, &BTreeSet::new(), &expanded, &BTreeMap::new());
assert_eq!(nodes.last(), Some(&Node::Proc { instance: 0, row: MESSAGE_ROW }));
let mut procs = BTreeMap::new();
procs.insert("a1".to_string(), ProcState::Message("(not running)".into()));
let nodes = visible_nodes(&sandboxes, &instances, &BTreeSet::new(), &expanded, &procs);
assert_eq!(
nodes,
vec![
Node::Sandbox(0),
Node::Instance(0),
Node::Proc { instance: 0, row: MESSAGE_ROW },
],
);
}
#[test]
fn visible_nodes_collapsed_sandbox_hides_expanded_procs() {
let sandboxes = vec![sb("a")];
let instances = vec![inst_in("a1", "a")];
let expanded: BTreeSet<String> = ["a1".to_string()].into_iter().collect();
let mut procs = BTreeMap::new();
procs.insert(
"a1".to_string(),
ProcState::Rows { rows: vec![proc_row("1")], signalable: true, sessions: None },
);
let nodes = visible_nodes(&sandboxes, &instances, &collapsed(&[&local_key("a")]), &expanded, &procs);
assert_eq!(nodes, vec![Node::Sandbox(0)]);
}
fn sb_at(name: &str, machine: Option<&str>, root: &str, mesh: Option<&str>) -> SandboxRow {
let mut row = sb(name);
row.machine = machine.map(str::to_string);
row.root = Some(root.into());
row.mesh_root = mesh.map(str::to_string);
row
}
fn inst_at(name: &str, sandbox: &str, machine: Option<&str>, root: Option<&str>, mesh: Option<&str>) -> InstanceRow {
let mut row = inst_in(name, sandbox);
row.machine = machine.map(str::to_string);
row.root = root.map(str::to_string);
row.mesh_root = mesh.map(str::to_string);
row
}
#[test]
fn group_keys_are_distinct_and_never_the_orphans() {
let keys = [
group_key(&sb_at("s", None, "/a", Some("tree"))),
group_key(&sb_at("s", Some("box"), "/a", Some("tree"))),
group_key(&sb_at("s", None, "/a", None)),
group_key(&sb_at("s", Some("box"), "/a", None)),
group_key(&sb_at("s", None, "/b", None)),
group_key(&sb("s")),
];
assert_eq!(keys[0], keys[1], "one mesh root across machines");
let strings: BTreeSet<String> = keys[1..].iter().map(GroupKey::collapse_key).collect();
assert_eq!(strings.len(), 5);
assert!(!strings.contains(ORPHANS_NAME));
}
#[test]
fn sandbox_order_yields_one_representative_per_group() {
let rows = vec![
sb_at("z", Some("box"), "/r", Some("tree")), sb_at("b", Some("box"), "/r", None), sb_at("y", Some("ant"), "/r", Some("tree")), sb_at("z", None, "/here", Some("tree")), sb_at("a", None, "/here", None), sb_at("y", Some("box"), "/r", Some("tree")), sb_at("a", None, "/other", None), ];
assert_eq!(sandbox_order(&rows), vec![3, 4, 6, 2, 1]);
}
#[test]
fn group_of_returns_the_groups_representative() {
let rows = vec![
sb_at("s", Some("box"), "/r", Some("tree")), sb_at("s", None, "/here", Some("tree")), sb_at("u", Some("box"), "/r", None), sb_at("u", None, "/here", None), sb_at("u", None, "/two", None), sb_at("t", Some("lap"), "/l", None), sb_at("t", Some("box"), "/r", Some("tree")), ];
let of = |i: InstanceRow| group_of(&rows, &i);
assert_eq!(of(inst_at("a", "s", Some("box"), Some("/r"), Some("tree"))), Some(1));
assert_eq!(of(inst_at("b", "s", None, Some("/here"), Some("tree"))), Some(1));
assert_eq!(of(inst_at("c", "u", Some("box"), Some("/r"), None)), Some(2));
assert_eq!(of(inst_at("d", "u", None, Some("/two"), None)), Some(4));
assert_eq!(of(inst_at("e", "u", None, Some("/gone"), None)), Some(3));
assert_eq!(of(inst_at("f", "u", None, Some("/two"), Some("tree"))), Some(4));
assert_eq!(of(inst_at("g", "s", Some("lap"), None, None)), Some(1));
assert_eq!(of(inst_at("h", "t", Some("lap"), None, None)), Some(6));
assert_eq!(of(inst_at("i", "u", Some("box"), None, None)), Some(2));
assert_eq!(of(inst_at("j", "u", Some("lap"), Some("/l"), None)), None);
assert_eq!(of(inst_at("k", "gone", None, None, None)), None);
}
#[test]
fn sandbox_stats_formats_running_over_total() {
assert_eq!(sandbox_stats(0, 0), "0/0 running");
assert_eq!(sandbox_stats(3, 1), "1/3 running");
}
}