From 63311f0741d543093e083b9c6004aef6bf2a8421 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 1 Dec 2026 12:51:55 +0000 Subject: enstate: refused submissions, visible A submission the switch refuses is moved to STATE/refused/NAME with NAME.json next to it: when, and why ("refused" if nothing more). The check's message names the waiting submission's path. --status lists what waits in the incoming directory, planned against the running generation (one the check refused stays waiting, and refuses switches while it does), and what was refused, with the reasons (and --json as data); it exits with 1 if something needs attention: a refused submission, a waiting one the running generation would refuse, an unfilled required slot, so that a deployment running it notices. --forget NAME removes a waiting or refused submission. After hrm's review. --- tests/migrations.rs | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'tests/migrations.rs') diff --git a/tests/migrations.rs b/tests/migrations.rs index c892f72..18451a7 100644 --- a/tests/migrations.rs +++ b/tests/migrations.rs @@ -401,13 +401,74 @@ fn incoming_submissions() { let check = host.migrate(&s2, true); assert!(!check.accepted); assert!( - check.refused[0].starts_with("incoming 4: required item secrets/nope"), + check.refused[0].starts_with("incoming 4 (") + && check.refused[0].contains("/state/incoming/4): required item secrets/nope"), "{check:?}" ); assert!(host.root.join("state/incoming/4").exists()); + // Waiting, and refused by the running generation: --status says so, and why. + let (code, stdout) = enstate(&host, &["--status", "--json"]); + assert_eq!(code, Some(1)); + let status: Value = serde_json::from_str(&stdout).unwrap(); + assert_eq!(status["incoming"][0]["name"], json!("4")); + assert_eq!(status["incoming"][0]["refused"], json!(true)); + assert!( + status["incoming"][0]["reasons"][0] + .as_str() + .unwrap() + .contains("secrets/nope") + ); let migration = host.migrate(&s2, false); assert!(!migration.accepted); assert!(host.root.join("state/refused/4").exists()); + // Visible, with why and when: in the store, and by --status, which exits with 1. + let refusals = host.store().refused().unwrap(); + assert_eq!(refusals.len(), 1); + assert_eq!(refusals[0].name, "4"); + assert!( + refusals[0].reasons[0].contains("secrets/nope"), + "{refusals:?}" + ); + assert!( + refusals[0].at.ends_with('Z') && refusals[0].at.len() == 20, + "{refusals:?}" + ); + let (code, stdout) = enstate(&host, &["--status", "--json"]); + assert_eq!(code, Some(1)); + let output = stdout; + let status: Value = serde_json::from_str(&output).unwrap(); + assert_eq!(status["attention"], json!(true)); + assert_eq!(status["refused"][0]["name"], json!("4")); assert!(!host.root.join("state/incoming/4").exists()); assert_eq!(host.view("a", "a").unwrap(), b"C"); + // Forgotten, and nothing needs attention any more. + let (code, stdout) = enstate(&host, &["--forget", "4"]); + assert_eq!(code, Some(0), "{stdout}"); + assert!(!host.root.join("state/refused/4").exists()); + assert!(!host.root.join("state/refused/4.json").exists()); + let (code, _) = enstate(&host, &["--status"]); + assert_eq!(code, Some(0)); + let (code, _) = enstate(&host, &["--forget", "4"]); + assert_eq!(code, Some(2)); +} + +/// Runs enstate on `host`'s store with `arguments`: its exit status and output. +fn enstate(host: &Host, arguments: &[&str]) -> (Option, String) { + let mut command = std::process::Command::new(env!("CARGO_BIN_EXE_enstate")); + command + .args(arguments) + .arg(format!("--state-dir={}", host.root.join("state").display())); + if arguments[0] != "--forget" { + command + .arg(format!("--run-dir={}", host.root.join("run").display())) + .arg(format!( + "--schema={}", + host.root.join("schema.json").display() + )); + } + let output = command.output().unwrap(); + ( + output.status.code(), + String::from_utf8_lossy(&output.stdout).into_owned(), + ) } -- cgit v1.3.1