From 2eb4500f089154b982f7c5dbbc7f1efbfd702ed5 Mon Sep 17 00:00:00 2001 From: aur-build Date: Thu, 19 Nov 2026 11:49:50 +0000 Subject: =?UTF-8?q?sandbox:=20kata=20backend=20=E2=80=94=20ad-hoc=20TTL=20?= =?UTF-8?q?sandboxes=20over=20the=20agent=20protocol?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The kata lease path is composition, not a new protocol: acquire mints a rendezvous nonce, asks a Provisioner for a sandbox pointed at this hub, and leases only the dial-in whose hello carries that nonce back. A box that never dials in is a TTL expiry — the same vocabulary every other failure here speaks (I5) — and a stray box that greets with a nonce nobody ordered is dropped unread, never leased. Two payload shapes are constructed as pure, unit-tested functions because both are real targets: an agent-sandbox-style Kubernetes CR (runtimeClass kata, activeDeadlineSeconds so the orchestrator enforces the TTL even if the hub dies) and a nerdctl/containerd argv for hosts without a cluster. The K8s provisioner is real ureq code exercised only by the gated live tier, which skips with a printed note wherever /dev/kvm or AUR_KATA_API is absent — the recorded-skip convention, not a silent pass. The rendezvous and TTL logic runs for real on any machine via LocalAgentProvisioner: a real sandbox-agent process, real frames, real nonce matching, no VM. That is the same honesty as the loopback backend — the interface is under test, not a mock of it. --- tests/kata.rs | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/kata.rs (limited to 'tests') diff --git a/tests/kata.rs b/tests/kata.rs new file mode 100644 index 0000000..eb7c333 --- /dev/null +++ b/tests/kata.rs @@ -0,0 +1,89 @@ +//! The kata backend, tested the way every gated tier here is tested: the +//! logic runs for real on a machine with neither root nor `/dev/kvm`, and +//! only the live-orchestrator tier skips — with a printed note, never +//! silently absent (the convention `versions::vercmp_matches_the_system_oracle` +//! set). + +mod common; + +use std::path::Path; +use std::sync::Arc; +use std::time::{Duration, Instant}; + +use aur_build::config::Config; +use aur_build::error::Result; +use aur_build::sandbox::kata::{KataBackend, LocalAgentProvisioner, ProvisionRequest, Provisioner}; +use aur_build::sandbox::{Cmd, SandboxBackend, SandboxSpec}; +use common::shim_dir; + +#[test] +fn a_provisioned_sandbox_rendezvous_and_runs_a_command() { + // Real sandbox-agent process, real frames, real nonce-matched dial-in — + // everything about the kata lease path except the VM. + let cfg = Config::default(); + let prov = Arc::new(LocalAgentProvisioner::new(shim_dir().join("sandbox-agent"))); + let backend = KataBackend::bind(&cfg, "127.0.0.1:0", "kata-token", prov.clone()).unwrap(); + let sbx = backend + .acquire(&SandboxSpec::new("extra-x86_64", "build-1", Duration::from_secs(15))) + .expect("the provisioned agent should dial in and rendezvous"); + let out = sbx + .run(&Cmd::new(["/bin/echo", "hi from the sandbox"]), &mut |_| {}) + .unwrap(); + assert!(out.success()); + assert_eq!(String::from_utf8_lossy(&out.stdout), "hi from the sandbox\n"); + sbx.destroy().unwrap(); +} + +#[test] +fn a_sandbox_that_never_dials_in_is_a_ttl_expiry_not_a_hang() { + struct NullProvisioner; + impl Provisioner for NullProvisioner { + fn provision(&self, _req: &ProvisionRequest) -> Result<()> { + Ok(()) + } + fn reclaim(&self, _id: &str) -> Result<()> { + Ok(()) + } + fn name(&self) -> &str { + "null" + } + } + let cfg = Config::default(); + let backend = KataBackend::bind(&cfg, "127.0.0.1:0", "tok", Arc::new(NullProvisioner)).unwrap(); + let started = Instant::now(); + let err = match backend.acquire(&SandboxSpec::new("extra-x86_64", "ghost", Duration::from_secs(1))) { + Ok(_) => panic!("nobody provisioned anything; the lease must not succeed"), + Err(e) => e, + }; + assert!(started.elapsed() >= Duration::from_millis(900), "acquire gave up before the TTL"); + assert!(err.to_string().contains("never dialed in"), "{err}"); +} + +#[test] +fn the_live_kata_tier_is_recorded_not_silently_absent() { + // The §16a convention: a tier that needs hardware or infrastructure + // announces its own skip rather than pretending to have run. + if !Path::new("/dev/kvm").exists() { + println!("note: no /dev/kvm on this host; the live kata tier is skipped, not passed"); + return; + } + let Ok(api) = std::env::var("AUR_KATA_API") else { + println!("note: /dev/kvm present but AUR_KATA_API unset; live kata tier still skipped"); + return; + }; + // Recorded as reached: a real cluster lease. Kept minimal on purpose — + // acquire, one command, reclaim. + let cfg = Config::default(); + let prov = Arc::new(aur_build::sandbox::kata::K8sSandboxProvisioner { + api, + bearer: std::env::var("AUR_KATA_TOKEN").unwrap_or_default(), + namespace: std::env::var("AUR_KATA_NS").unwrap_or_else(|_| "default".into()), + }); + let backend = KataBackend::bind(&cfg, "0.0.0.0:9443", &std::env::var("AUR_AGENT_TOKEN").unwrap(), prov).unwrap(); + let sbx = backend + .acquire(&SandboxSpec::new("extra-x86_64", "live", Duration::from_secs(300))) + .expect("live kata sandbox should lease"); + let out = sbx.run(&Cmd::new(["/bin/echo", "kata"]), &mut |_| {}).unwrap(); + assert!(out.success() && String::from_utf8_lossy(&out.stdout).contains("kata")); + sbx.destroy().unwrap(); +} -- cgit v1.2.3