diff options
| author | aur-build <aur-build@localhost> | 2026-11-19 15:45:38 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-19 15:45:38 +0000 |
| commit | 8dcdce879b51b19603d8163d8a9bfb5f61ff1558 (patch) | |
| tree | 57ba7dee86414eaf24de114a1df8209149e7b5bd /tests/kata.rs | |
| parent | ec80c312b80ba51271fff0548c6d1e293d373455 (diff) | |
| download | aur-build-8dcdce879b51b19603d8163d8a9bfb5f61ff1558.tar.gz aur-build-8dcdce879b51b19603d8163d8a9bfb5f61ff1558.zip | |
sandbox: agent-sandbox is a backend now, and nerdctl is gone
`sandbox_backend` was a string and `backend_for` matched it with `_ => loopback`,
so the documented Kata backend was unreachable from configuration: a hub told to
use agent-sandbox would have quietly built untrusted PKGBUILDs as its own user.
The kind now parses, validates, and produces a real `KataBackend` over
`K8sSandboxProvisioner`, with the CR's `runtimeClass`, `activeDeadlineSeconds`,
nonce, image and cluster coordinates all traced back to the config that produced
them.
Kata shares a *backend* per configuration rather than only a listener: it routes
each dial-in by the nonce in its `Hello` into a map that belongs to it, so two
backends on one address would each see half the dial-ins and neither could
complete a rendezvous. The cache key is a digest of the distinguishing fields so
the token and bearer are not copied into a second place.
The containerd/`nerdctl` payload builder is deleted rather than left unused. It
was a second deployment shape with no provisioner, no config path and no live
tier — a builder that advertises a route the configuration refuses is worse than
no builder, because someone will eventually assume the route exists. DESIGN.md
now names one provisioning shape, which is the one that exists.
Diffstat (limited to 'tests/kata.rs')
| -rw-r--r-- | tests/kata.rs | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/kata.rs b/tests/kata.rs index eb7c333..12aa607 100644 --- a/tests/kata.rs +++ b/tests/kata.rs @@ -87,3 +87,91 @@ fn the_live_kata_tier_is_recorded_not_silently_absent() { assert!(out.success() && String::from_utf8_lossy(&out.stdout).contains("kata")); sbx.destroy().unwrap(); } + +// --------------------------------------------------------------------------- +// agent-sandbox as a configuration, not a wish. +// +// `sandbox_backend = "kata"` used to fall through to loopback. The kind is +// `agent-sandbox` now, it parses, and it produces a Kata backend — so the path +// from a config file to the CR that would boot a VM is worth asserting end to +// end, starting from parsed JSON rather than a hand-built request. +// --------------------------------------------------------------------------- + +/// A config file as an operator would write it, parsed by the real loader. +fn agent_sandbox_config() -> Config { + let tmp = tempfile::tempdir().unwrap(); + std::fs::write( + tmp.path().join("config.json"), + r#"{ + "sandbox": { + "kind": "agent-sandbox", + "api": "https://k8s.test:6443", + "namespace": "builds", + "bearer": "kube-bearer", + "image": "aur-build-sandbox:test", + "listen": "127.0.0.1:0", + "token": "kata-cfg-token", + "shared_workspace": true + } +}"#, + ) + .unwrap(); + let cfg = Config::load(tmp.path()).unwrap(); + cfg.validate().expect("the config must survive the startup guard"); + cfg +} + +#[test] +fn an_agent_sandbox_config_provisions_a_kata_vm_per_lease() { + let cfg = agent_sandbox_config(); + let backend = aur_build::sandbox::kata::KataBackend::shared_for(&cfg).unwrap(); + let spec = SandboxSpec::new("extra-x86_64", "build-9", Duration::from_secs(77)); + let cr = aur_build::sandbox::kata::sandbox_cr(&backend.provision_request(&spec, "sbx-nonce-9")); + + assert_eq!(cr["spec"]["runtimeClass"], "kata", "the VM boundary is the point"); + assert_eq!( + cr["spec"]["activeDeadlineSeconds"], 77, + "the orchestrator enforces the lease TTL even if the hub dies" + ); + assert_eq!( + cr["metadata"]["name"], "sbx-nonce-9", + "the nonce names the box, so a stray sandbox cannot be leased to the wrong build" + ); + assert_eq!(cr["spec"]["template"]["spec"]["containers"][0]["image"], "aur-build-sandbox:test"); + let args: Vec<String> = cr["spec"]["template"]["spec"]["containers"][0]["args"] + .as_array() + .unwrap() + .iter() + .map(|v| v.as_str().unwrap().to_string()) + .collect(); + assert!(args.windows(2).any(|w| w[0] == "--agent-id" && w[1] == "sbx-nonce-9")); + assert!(args.windows(2).any(|w| w[0] == "--ttl" && w[1] == "77")); + + // The cluster coordinates come from the same config, not from a default. + let prov = aur_build::sandbox::kata::K8sSandboxProvisioner::for_config(&cfg).unwrap(); + assert_eq!(prov.api, "https://k8s.test:6443"); + assert_eq!(prov.namespace, "builds"); + assert_eq!(prov.bearer, "kube-bearer"); +} + +#[test] +fn agent_sandbox_is_a_backend_not_a_fallthrough_to_loopback() { + let cfg = agent_sandbox_config(); + let backend = aur_build::sandbox::backend_for(&cfg).unwrap(); + let id = backend.status().unwrap()[0].id.clone(); + assert!(id.contains("kata@"), "expected a kata backend, got {id}"); + + // One backend per process, for the same reason the listener is: a second + // concurrent build must not race the first for the dial-ins it routes. + let again = aur_build::sandbox::backend_for(&cfg).unwrap(); + assert_eq!(again.status().unwrap()[0].id, id, "two builds must share one kata backend"); +} + +#[test] +fn a_loopback_config_never_becomes_agent_sandbox_or_vice_versa() { + // The fallthrough in both directions, closed. + let local = Config::default(); + let id = aur_build::sandbox::backend_for(&local).unwrap().status().unwrap()[0].id.clone(); + assert!(!id.contains("kata@"), "loopback must not report kata: {id}"); + assert!(!id.contains("remote@"), "loopback must not report remote: {id}"); +} |
