Share signed job core and verify native Linux then Windows contracts
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-14 00:52:40 +01:00
parent 1fef7f6ce9
commit 31278bedec
32 changed files with 4452 additions and 1715 deletions
+121 -2
View File
@@ -100,7 +100,10 @@ impl Action {
arguments,
expected_stdout,
} => {
matches!(interpreter.as_str(), "posix_sh" | "bash")
matches!(interpreter.as_str(), "posix_sh" | "bash" | "powershell")
&& (interpreter != "powershell"
|| script_utf8.is_ascii()
|| script_utf8.starts_with('\u{feff}'))
&& !script_utf8.is_empty()
&& script_utf8.len() <= 32768
&& !script_utf8.contains('\0')
@@ -110,7 +113,9 @@ impl Action {
.all(|a| a.len() <= 4096 && !a.contains('\0'))
&& expected_stdout.as_ref().is_none_or(|s| s.len() <= 65536)
}
Self::RefreshInventory { scope } => scope == "linux.base",
Self::RefreshInventory { scope } => {
matches!(scope.as_str(), "linux.base" | "windows.base")
}
Self::QueryLogs {
unit: u,
since,
@@ -193,6 +198,45 @@ impl Action {
}
}
}
/// Interpreter identity is part of the immutable action, never inferred at execution.
pub fn script_platform(&self) -> Option<&'static str> {
match self {
Self::RunScript { interpreter, .. } => match interpreter.as_str() {
"posix_sh" | "bash" => Some("linux"),
"powershell" => Some("windows"),
_ => None,
},
_ => None,
}
}
/// Shared plan/revalidation/start gate. Passive Windows never implies job support.
pub fn available_for(&self, identity: &str, capabilities: &[String]) -> bool {
let has = |cap: &str| capabilities.iter().any(|c| c == cap);
if !has(self.name()) {
return false;
}
match self {
Self::RunScript { interpreter, .. } if interpreter == "powershell" => {
identity == "agent_service"
&& has("windows.base/1")
&& !has("linux.base/1")
&& has("rmm.sync.v1")
&& has("script.powershell/1")
}
Self::RunScript { .. } => {
self.script_platform() == Some("linux")
&& has("linux.base/1")
&& !has("windows.base/1")
}
Self::RefreshInventory { scope } => {
(identity == "agent_service" || scope == "linux.base")
&& has(&format!("{scope}/1"))
&& !(has("linux.base/1") && has("windows.base/1"))
&& (scope != "windows.base" || has("rmm.sync.v1"))
}
_ => !has("windows.base/1"), // Windows adapters are separately qualified.
}
}
pub fn resource(&self) -> &'static str {
match self {
Self::EnsurePackage { .. }
@@ -387,6 +431,81 @@ impl JobState {
mod tests {
use super::*;
#[test]
fn windows_interpreter_and_capability_contract() {
let mut action = Action::RunScript {
interpreter: "powershell".into(),
script_utf8: "Write-Output 'Hello'\r\n".into(),
arguments: vec![],
expected_stdout: Some("Hello\r\n".into()),
};
let caps: Vec<String> = [
"windows.base/1",
"rmm.sync.v1",
"run_script",
"script.powershell/1",
]
.into_iter()
.map(str::to_string)
.collect();
assert!(action.validate());
assert!(action.available_for("agent_service", &caps));
for missing in 0..caps.len() {
let mut short = caps.clone();
short.remove(missing);
assert!(!action.available_for("agent_service", &short));
}
assert!(!action.available_for("root", &caps));
assert!(!action.available_for("SYSTEM", &caps));
assert!(!action.available_for(
"agent_service",
&["linux.base/1".into(), "run_script".into()]
));
let mut both = caps.clone();
both.push("linux.base/1".into());
assert!(!action.available_for("agent_service", &both));
if let Action::RunScript {
interpreter,
script_utf8,
..
} = &mut action
{
*script_utf8 = "Write-Output 'é'".into();
assert!(interpreter == "powershell");
}
assert!(!action.validate());
if let Action::RunScript { script_utf8, .. } = &mut action {
*script_utf8 = "\u{feff}Write-Output 'é'\r\n".into();
}
assert!(action.validate());
let bytes = encode(&action).unwrap();
assert_eq!(serde_json::from_slice::<Action>(&bytes).unwrap(), action);
if let Action::RunScript { interpreter, .. } = &mut action {
*interpreter = "pwsh".into();
}
assert!(!action.validate());
assert!(!action.available_for("agent_service", &caps));
let refresh = Action::RefreshInventory {
scope: "windows.base".into(),
};
assert!(refresh.validate());
assert!(refresh.available_for(
"agent_service",
&[
"windows.base/1".into(),
"rmm.sync.v1".into(),
"refresh_inventory".into()
]
));
assert!(!refresh.available_for(
"root",
&[
"windows.base/1".into(),
"rmm.sync.v1".into(),
"refresh_inventory".into()
]
));
}
#[test]
fn codec_golden_and_exact_script_bytes() {
let a = Action::RunScript {
interpreter: "posix_sh".into(),