Bind typed SYSTEM service plans and qualify Domain contract on cloud Linux
Rust development slice / linux (push) Failing after 7s

This commit is contained in:
2026-11-14 05:30:21 +01:00
parent 5f356a92ac
commit e85f9ed750
10 changed files with 422 additions and 17 deletions
+89
View File
@@ -211,6 +211,9 @@ impl Action {
}
/// Shared plan/revalidation/start gate. Passive Windows never implies job support.
pub fn available_for(&self, identity: &str, capabilities: &[String]) -> bool {
if identity == "system" && !matches!(self, Self::SetServiceState { .. }) {
return false;
}
let has = |cap: &str| capabilities.iter().any(|c| c == cap);
if !has(self.name()) {
return false;
@@ -234,6 +237,17 @@ impl Action {
&& !(has("linux.base/1") && has("windows.base/1"))
&& (scope != "windows.base" || has("rmm.sync.v1"))
}
Self::SetServiceState { state, .. }
if identity == "system" || has("windows.base/1") =>
{
identity == "system"
&& has("windows.base/1")
&& !has("linux.base/1")
&& has("rmm.sync.v1")
&& has("helper.system.v1")
&& has("system:set_service_state")
&& matches!(state.as_str(), "running" | "stopped")
}
_ => !has("windows.base/1"), // Windows adapters are separately qualified.
}
}
@@ -431,6 +445,81 @@ impl JobState {
mod tests {
use super::*;
#[test]
fn windows_system_scm_is_explicit_and_preserves_linux_service_bytes() {
let caps: Vec<String> = [
"windows.base/1",
"rmm.sync.v1",
"helper.system.v1",
"system:set_service_state",
"set_service_state",
]
.into_iter()
.map(str::to_string)
.collect();
for state in ["running", "stopped"] {
let action = Action::SetServiceState {
unit: "RmmDiscoveryFixtureService".into(),
state: state.into(),
};
assert!(action.validate() && action.available_for("system", &caps));
for missing in 0..caps.len() {
let mut incomplete = caps.clone();
incomplete.remove(missing);
assert!(!action.available_for("system", &incomplete));
}
for identity in ["root", "agent_service", "SYSTEM"] {
assert!(!action.available_for(identity, &caps));
}
let mut mixed = caps.clone();
mixed.push("linux.base/1".into());
assert!(!action.available_for("system", &mixed));
assert!(!action.available_for(
"system",
&["linux.base/1".into(), "set_service_state".into()]
));
}
let restart = Action::SetServiceState {
unit: "rmm-mvp-test.service".into(),
state: "restarted".into(),
};
assert!(!restart.available_for("system", &caps));
let linux = vec!["linux.base/1".into(), "set_service_state".into()];
for identity in ["root", "agent_service"] {
assert!(restart.available_for(identity, &linux));
}
assert_eq!(
encode(&restart).unwrap(),
br#"{"action":"set_service_state","unit":"rmm-mvp-test.service","state":"restarted"}"#
);
let script = Action::RunScript {
interpreter: "powershell".into(),
script_utf8: "Write-Output 'hi'\r\n".into(),
arguments: vec![],
expected_stdout: None,
};
let mut all = caps;
all.extend(["run_script".into(), "script.powershell/1".into()]);
assert!(!script.available_for("system", &all));
let posix = Action::RunScript {
interpreter: "posix_sh".into(),
script_utf8: "printf hi\n".into(),
arguments: vec![],
expected_stdout: None,
};
let reboot = Action::Reboot {
reason: "fixed test".into(),
reconnect_timeout_seconds: 180,
dependency_group: "one-test-vm".into(),
};
let linux = ["linux.base/1", "run_script", "reboot"].map(str::to_string);
assert!(!posix.available_for("system", &linux));
assert!(!reboot.available_for("system", &linux));
for identity in ["root", "agent_service"] {
assert!(posix.available_for(identity, &linux));
assert!(reboot.available_for(identity, &linux));
}
}
#[test]
fn windows_interpreter_and_capability_contract() {
let mut action = Action::RunScript {
interpreter: "powershell".into(),