Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions crates/minimal/src/cmd/boxes/attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use minimal_client::box_registration::resume_box_row;
/// before handing off to the interactive shell. Suppressed under `--no-input`
/// and when stderr is not a terminal, so scripted and CI callers — which read
/// the session id from stdout — see nothing extra.
pub(crate) fn should_announce_session(global: &GlobalArgs) -> bool {
pub(crate) fn should_announce_box(global: &GlobalArgs) -> bool {
!global.no_input && std::io::stderr().is_terminal()
}

Expand All @@ -17,7 +17,7 @@ pub(crate) fn should_announce_session(global: &GlobalArgs) -> bool {
/// session is unnamed. The short id is the leading block of the UUID — enough
/// to tell two same-named sessions built from the same directory apart without
/// the full 36-character id.
pub(crate) fn session_announce_label(id: &boxes::SessionId, name: Option<&str>) -> String {
pub(crate) fn box_announce_label(id: &boxes::SessionId, name: Option<&str>) -> String {
let id = id.to_string();
let short = id.split('-').next().unwrap_or(&id);
match name {
Expand Down Expand Up @@ -52,13 +52,10 @@ pub(crate) async fn resolve_attach_target_version_gated(
Some(resolved) => {
// The operator never chose the VM the way they chose the
// session, so tell them which one they're landing in.
if should_announce_session(global) {
if should_announce_box(global) {
eprintln!(
"Attaching to session {} on VM {}",
session_announce_label(
&resolved.record.id,
resolved.record.name.as_deref()
),
box_announce_label(&resolved.record.id, resolved.record.name.as_deref()),
resolved.vm
);
}
Expand Down Expand Up @@ -91,10 +88,10 @@ pub(crate) fn resolve_smart_attach(
// Unambiguous auto-resolve: the operator never chose this session,
// so tell them which one they're landing in. The picker path below
// needs no such line — the selection is its own confirmation.
if should_announce_session(global) {
if should_announce_box(global) {
eprintln!(
"Attaching to session {}{}",
session_announce_label(&entry.id, entry.name.as_deref()),
box_announce_label(&entry.id, entry.name.as_deref()),
crate::attach::created_from_suffix(&entry, &cwd)
);
}
Expand Down Expand Up @@ -200,7 +197,7 @@ pub(crate) fn ensure_interactive_attach_tty(stdin_is_tty: bool) -> Result<(), an
/// Neither path returns normally: on success the error is a [`Handoff`]
/// (exec ssh, or exit with the attach's status) that [`run`] finishes once
/// the command's `cmd` span has ended, so callers return it untouched.
pub(crate) async fn session_via_ssh(
pub(crate) async fn box_via_ssh(
sock: &std::path::Path,
id: boxes::SessionId,
wire: Option<String>,
Expand All @@ -226,7 +223,7 @@ pub(crate) async fn session_via_ssh(
// back, and the in-VM daemon's own row check decides the launch.
let mut record_unreadable = false;
let record = match control_sock_beside(sock).filter(|control| control.exists()) {
Some(_) => match attached_session_record(sock, id).await {
Some(_) => match attached_box_record(sock, id).await {
Ok(record) => record,
Err(error) => {
tracing::warn!(
Expand Down
30 changes: 15 additions & 15 deletions crates/minimal/src/cmd/boxes/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ fn refuse_unhonourable_grants(
Ok(())
}

/// One named step of [`activate_session`], in the order the activation runs
/// One named step of [`activate_box`], in the order the activation runs
/// them. Each step runs inside its own `activation_step` span, so a log read
/// under `RUST_LOG=info` shows where an activation spent its time and which
/// step ended it.
Expand Down Expand Up @@ -233,7 +233,7 @@ pub(crate) enum ActivationStep {
}

impl ActivationStep {
/// Every step, in the order [`activate_session`] runs them.
/// Every step, in the order [`activate_box`] runs them.
#[cfg(test)]
pub(crate) const ORDER: [Self; 13] = [
Self::CheckArguments,
Expand Down Expand Up @@ -293,7 +293,7 @@ impl ActivationStep {
}
}

pub(crate) async fn activate_session(
pub(crate) async fn activate_box(
global: &GlobalArgs,
args: ActivateArgs,
offer_scaffold: bool,
Expand Down Expand Up @@ -1553,10 +1553,10 @@ pub(crate) async fn activate_session(
// bare id printed to stdout above is the scripting contract, while this
// stderr line tells an interactive operator which session they just
// created and are entering.
if should_announce_session(global) {
if should_announce_box(global) {
eprintln!(
"Created session {}",
session_announce_label(&id, config.name.as_deref())
box_announce_label(&id, config.name.as_deref())
);
}
let attach_args = AttachArgs {
Expand Down Expand Up @@ -1679,7 +1679,7 @@ mod tests {
no_prompt: true,
attach: false,
};
let err = activate_session(&global, args, false)
let err = activate_box(&global, args, false)
.await
.expect_err("the grant box is refused");
let refused = err
Expand Down Expand Up @@ -1736,7 +1736,7 @@ mod tests {
no_prompt: true,
attach: false,
};
let err = activate_session(&global, args, false)
let err = activate_box(&global, args, false)
.await
.expect_err("the broken project file is refused");
assert!(
Expand Down Expand Up @@ -1925,16 +1925,16 @@ mod activation_step_tests {
}
}

/// The step names [`super::activate_session`] runs, in source order.
fn steps_in_activate_session() -> Vec<String> {
/// The step names [`super::activate_box`] runs, in source order.
fn steps_in_activate_box() -> Vec<String> {
let text = include_str!("create.rs");
let start = text
.find("pub(crate) async fn activate_session(")
.expect("create.rs defines activate_session");
.find("pub(crate) async fn activate_box(")
.expect("create.rs defines activate_box");
let body = &text[start..];
let end = body
.find("\nfn normalize_subnets(")
.expect("normalize_subnets follows activate_session");
.expect("normalize_subnets follows activate_box");
// Comment lines name steps too; only code runs them.
let body: String = body[..end]
.lines()
Expand Down Expand Up @@ -1965,7 +1965,7 @@ mod activation_step_tests {
.iter()
.map(|step| format!("{step:?}"))
.collect();
assert_eq!(steps_in_activate_session(), declared);
assert_eq!(steps_in_activate_box(), declared);

// Each step opens its own span, and the failing step names itself
// while its error passes through unchanged.
Expand Down Expand Up @@ -2021,7 +2021,7 @@ mod activation_step_tests {
}

#[tokio::test(flavor = "current_thread")]
async fn activation_steps_run_in_order_and_name_the_failing_step_in_activate_session() {
async fn activation_steps_run_in_order_and_name_the_failing_step_in_activate_box() {
use clap::Parser as _;
// A project path that does not exist ends the real activation in its
// first step, before any daemon is started or contacted.
Expand All @@ -2032,7 +2032,7 @@ mod activation_step_tests {
let subscriber = tracing_subscriber::registry().with(Capture(seen.clone()));
let _guard = tracing::subscriber::set_default(subscriber);

let error = super::activate_session(&crate::cli::GlobalArgs::default(), cli.args, false)
let error = super::activate_box(&crate::cli::GlobalArgs::default(), cli.args, false)
.await
.expect_err("a missing project path ends the activation");
let expected = format!("Cannot resolve project path '{}'", missing.display());
Expand Down
18 changes: 9 additions & 9 deletions crates/minimal/src/cmd/boxes/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,25 @@ pub(crate) fn destroy_gate(
/// Best-effort fetch of the session's at-risk report for the destroy
/// confirm. Any failure — RPC error, timeout, a daemon predating the RPC —
/// reads as `None` (unknowable), and the confirm renders without a listing.
pub(crate) async fn session_delta(
pub(crate) async fn box_delta(
client: &mut client::Client,
id: boxes::SessionId,
) -> Option<minimald_rpc::SessionDeltaResponse> {
/// Client-side ceiling on the fetch. The daemon bounds each of its
/// computations at 5 s; this sits just above so a slow-but-healthy
/// answer still lands while a wedged daemon cannot stall the confirm.
const SESSION_DELTA_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(6);
const BOX_DELTA_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(6);
use minimald_rpc::{SessionDelta, SessionDeltaRequest};
tokio::time::timeout(
SESSION_DELTA_TIMEOUT,
BOX_DELTA_TIMEOUT,
client.oneshot_rpc::<SessionDelta>(SessionDeltaRequest { id }),
)
.await
.ok()?
.ok()
}

pub(crate) async fn destroy_all_sessions(
pub(crate) async fn destroy_all_boxes(
global: &GlobalArgs,
client: &mut client::Client,
force: bool,
Expand Down Expand Up @@ -175,7 +175,7 @@ pub(crate) async fn destroy_all_sessions(
.ok()
.and_then(|resp| resp.record)
.and_then(|record| record.box_addresses);
if let Err(error) = destroy_session(
if let Err(error) = destroy_box(
client,
global,
session.id,
Expand All @@ -201,7 +201,7 @@ pub(crate) async fn destroy_all_sessions(
Ok(())
}

pub(crate) async fn destroy_session(
pub(crate) async fn destroy_box(
client: &mut client::Client,
global: &GlobalArgs,
id: boxes::SessionId,
Expand Down Expand Up @@ -534,19 +534,19 @@ mod tests {
let global = GlobalArgs::default();

// The first destroy wins the race.
destroy_session(&mut client, &global, id, Some("web"), None, false)
destroy_box(&mut client, &global, id, Some("web"), None, false)
.await
.expect("the first destroy succeeds");

// The loser is told the session is already gone: under `--force`
// that is the goal state, reported and not a failure.
destroy_session(&mut client, &global, id, Some("web"), None, true)
destroy_box(&mut client, &global, id, Some("web"), None, true)
.await
.expect("a forced destroy of a destroyed session succeeds");

// Without `--force` the same answer is an error — one that names
// the session rather than forwarding the daemon's internals.
let err = destroy_session(&mut client, &global, id, Some("web"), None, false)
let err = destroy_box(&mut client, &global, id, Some("web"), None, false)
.await
.expect_err("an unforced destroy of a destroyed session fails");
assert!(
Expand Down
32 changes: 16 additions & 16 deletions crates/minimal/src/cmd/boxes/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::*;
///
/// The opt-out half of the scope is the caller's to check: the daemon, not
/// the client, knows whether it set its opt-out (NET-077), so
/// [`activate_session`] reads it off the create reply and stays silent for
/// [`activate_box`] reads it off the create reply and stays silent for
/// a box the default does not bind.
pub fn deny_all_default_notice(phase: boxes::EgressDefaultPhase) -> Option<&'static str> {
match phase {
Expand Down Expand Up @@ -835,9 +835,9 @@ impl PolicyJsonFailure {
/// as a claim that the box published nothing.
async fn fetch_live_ingress(
client: &mut client::Client,
session: &str,
box_name: &str,
) -> Result<Vec<minimald_rpc::LiveMapping>, String> {
let live_lookup = match SessionLookup::parse(session) {
let live_lookup = match SessionLookup::parse(box_name) {
SessionLookup::Id(id) => minimald_rpc::GetLiveIngressRequest::Id(id),
SessionLookup::Name(n) => minimald_rpc::GetLiveIngressRequest::Name(n),
};
Expand All @@ -863,9 +863,9 @@ async fn fetch_live_ingress(
/// the one rendering that may put it there.
pub(crate) async fn fetch_live_ingress_degrading(
client: &mut client::Client,
session: &str,
box_name: &str,
) -> Vec<minimald_rpc::LiveMapping> {
fetch_live_ingress(client, session)
fetch_live_ingress(client, box_name)
.await
.unwrap_or_else(|warning| {
eprintln!("warning: {warning}");
Expand All @@ -881,9 +881,9 @@ pub(crate) async fn fetch_live_ingress_degrading(
/// renderings degrade differently (see [`fetch_live_ingress`]): the
/// document says the unknown itself, so nothing is printed for it on a
/// stderr the error object has alone.
async fn session_policy_json_inputs(
async fn box_policy_json_inputs(
global: &GlobalArgs,
session: &str,
box_name: &str,
) -> Result<
(
boxes::Record,
Expand All @@ -904,19 +904,19 @@ async fn session_policy_json_inputs(
// lookup the text walk uses, with the failure kinds told apart where
// they can be: an RPC the daemon never answered is no daemon to ask;
// a lookup that answered with nothing is the not-found itself.
let resp = get_session_record(&mut client, session)
let resp = get_session_record(&mut client, box_name)
.await
.map_err(|error| match error.downcast_ref::<AmbiguousIdPrefix>() {
Some(ambiguous) => PolicyJsonFailure::SessionNotFound(ambiguous.to_string()),
None => PolicyJsonFailure::DaemonUnreachable(format!("{error:#}")),
})?;
let record = named_record(resp.record, session)
let record = named_record(resp.record, box_name)
.map_err(|error| PolicyJsonFailure::SessionNotFound(error.to_string()))?;
// By the resolved id, as the text walk does.
let session = &record.id.to_string();
let box_id = &record.id.to_string();

use minimald_rpc::{GetEffectiveSessionPolicy, GetEffectiveSessionPolicyRequest};
let lookup = match SessionLookup::parse(session) {
let lookup = match SessionLookup::parse(box_id) {
SessionLookup::Id(id) => GetEffectiveSessionPolicyRequest::Id(id),
SessionLookup::Name(n) => GetEffectiveSessionPolicyRequest::Name(n),
};
Expand All @@ -925,13 +925,13 @@ async fn session_policy_json_inputs(
.await
.map_err(|error| PolicyJsonFailure::PolicyUnavailable(format!("{error:#}")))?;

let live = fetch_live_ingress(&mut client, session).await;
let live = fetch_live_ingress(&mut client, box_id).await;
// The listen publishes the audit log refused (NET-046) and the yielded
// shared-address ports (NET-129), from the runtime facts the text walk
// reads them from. Optional facts: a daemon that cannot answer — an older
// build, a session mid-teardown — leaves both keys out, as a box with
// nothing to say does.
let facts_lookup = match SessionLookup::parse(session) {
let facts_lookup = match SessionLookup::parse(box_id) {
SessionLookup::Id(id) => minimald_rpc::GetSessionRuntimeFactsRequest::Id(id),
SessionLookup::Name(n) => minimald_rpc::GetSessionRuntimeFactsRequest::Name(n),
};
Expand Down Expand Up @@ -967,12 +967,12 @@ async fn session_policy_json_inputs(
/// `main`'s machine-mode error emitter — keyed on the output mode, shared
/// by every command that takes `-o json` — writes, so the error path is
/// one mechanism rather than a per-command one.
pub(crate) async fn session_policy_as_json(
pub(crate) async fn box_policy_as_json(
global: &GlobalArgs,
session: &str,
box_name: &str,
) -> Result<(), anyhow::Error> {
let (record, policy, live, unaudited_listen_ports, shared_port_collisions) =
match session_policy_json_inputs(global, session).await {
match box_policy_json_inputs(global, box_name).await {
Ok(inputs) => inputs,
Err(failure) => return Err(failure.machine_failure().into()),
};
Expand Down
Loading
Loading