diff options
| author | aur-build <aur-build@localhost> | 2026-11-20 21:03:58 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-20 21:03:58 +0000 |
| commit | 2210c934d4a25602318f094e0eca72f42862d44a (patch) | |
| tree | 9bc80f269b05121e28f2465d3e9d1cd6d4457dfd /tests/kata.rs | |
| parent | 289560d196b65b0b257b59a92c956f088eb29fad (diff) | |
| download | aur-build-2210c934d4a25602318f094e0eca72f42862d44a.tar.gz aur-build-2210c934d4a25602318f094e0eca72f42862d44a.zip | |
db, sandbox: apply the dispositions the table decided
Six db items are now gated behind `test-support`, each with a comment
saying what it is for and why production never calls it:
builds::claim production leases a batch; `claim_batch` is
what the dispatcher runs
settings::set_setting the readers are used, the setter is not
Writer::shutdown the server runs until the process ends
snapshots::snapshot_by_commit
world::world_members production writes world snapshots, never
reads one back member by member
invariants::unapproved_index_entries
gated, not relocated: reading it needs this
module's private helpers, and widening those
to let a test out would be the wrong trade
Gating them exposed three things they were the only user of, and each is
gated with them rather than left compiling into a binary that cannot reach
it: `Msg::Shutdown` and its loop arm, and `model::json_or`.
`arch-census.py --write-budget` also stopped erasing the `test_surface`
section — two writers of one file must not delete each other's axis, or
the ratchet quietly stops checking it.
`steps::touch` is deleted, not narrowed. Nothing called it — not
production, not a test. The census had credited it to `tests/shims.rs`,
where the word appears inside a string.
In sandbox, two tests moved into `src/sandbox/kata.rs`: the container
record a lease provisions, and the TTL expiry of a sandbox that never
dials in. Neither builds a fixture. `KataBackend::shared_for`,
`provision_request`, `sandbox_cr` and `K8sSandboxProvisioner::for_config`
are `pub(crate)` as a result.
`KataBackend::reclaim` is deleted — same story as `touch`. It forwarded to
`self.provisioner.reclaim`, which the reaping site already calls itself,
and the TTL test the census credited it for implements the *trait's*
`reclaim` on a null provisioner. Same word, different function.
Two honest costs, both recorded rather than smoothed over:
- `Provisioner` and `ProvisionRequest` are now named by nobody outside
`sandbox`, yet cannot be narrowed: `LocalAgentProvisioner` is `pub`
because two fixture tests construct it, and Rust forbids a public type
implementing a private trait or taking a private parameter type.
`sandbox.deadonly` therefore rises 0 → 2, with the reason here as the
ratchet demands.
- `agent_sandbox_config()` now exists in both `tests/kata.rs` and
`src/sandbox/kata.rs`. Three of that file's remaining tests still need
it, and a test helper cannot be shared across the crate boundary without
making it public again.
sandbox: 27 pub / 15 dead -> 22 pub / 10 dead.
Suite: 284 passed, 0 failed, 0 ignored. Clippy clean.
Diffstat (limited to 'tests/kata.rs')
| -rw-r--r-- | tests/kata.rs | 113 |
1 files changed, 31 insertions, 82 deletions
diff --git a/tests/kata.rs b/tests/kata.rs index f923ea2..a0c61fa 100644 --- a/tests/kata.rs +++ b/tests/kata.rs @@ -2,14 +2,42 @@ mod common; use std::path::Path; use std::sync::Arc; -use std::time::{Duration, Instant}; +use std::time::Duration; use aur_build::config::Config; -use aur_build::error::Result; -use aur_build::sandbox::kata::{KataBackend, LocalAgentProvisioner, ProvisionRequest, Provisioner}; +use aur_build::sandbox::kata::{KataBackend, LocalAgentProvisioner}; use aur_build::sandbox::{Cmd, SandboxBackend, SandboxSpec}; use common::{env_with_fixture, shim_dir}; +// What remains drives a real sandbox agent or a real fixture build. The two +// tests that only asserted this module's own machinery — the container record a +// lease provisions, and the TTL expiry of a sandbox that never dials in — moved +// into src/sandbox/kata.rs, where that machinery is declared. + + +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 a_provisioned_sandbox_rendezvous_and_runs_a_command() { let cfg = Config::default(); @@ -27,31 +55,6 @@ fn a_provisioned_sandbox_rendezvous_and_runs_a_command() { } #[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() { if !Path::new("/dev/kvm").exists() { println!("note: no /dev/kvm on this host; the live kata tier is skipped, not passed"); @@ -76,60 +79,7 @@ fn the_live_kata_tier_is_recorded_not_silently_absent() { sbx.destroy().unwrap(); } -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")); - - 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() { @@ -183,4 +133,3 @@ fn a_fixture_builds_and_publishes_through_the_kata_lease_path() { let shimlog = env.cfg.hooks.shim_dir.clone().unwrap(); assert_eq!(aur_build::shims::called_with(&shimlog, "makepkg", ""), 1); } - |
