feat(process): add explicitly granted process API

This commit is contained in:
Marqdo Agent committed 2026-11-21 08:46:02 +08:00
1 parent 9922bfae98
commit 3ef18fb496
17 files changed
+433 -15

No files matched your search

+10 -3
View File
@@ -26,6 +26,8 @@ pub struct SandboxSettings {
pub allow_net: Vec<String>,
/// Environment variable grants (ADR-0043).
pub allow_env: Vec<String>,
/// Process program grants (ADR-0044).
pub allow_process: Vec<String>,
/// Foreign execution grant.
pub allow_foreign: bool,
/// Plugin grants.
@@ -77,6 +79,7 @@ impl SandboxSettings {
|| !self.allow_net.is_empty()
|| !self.allow_write.is_empty()
|| !self.allow_env.is_empty()
|| !self.allow_process.is_empty()
|| !self.allow_plugin.is_empty()
|| !self.plugins.is_empty()
|| self.trust_native_plugin
@@ -85,9 +88,9 @@ impl SandboxSettings {
if requested {
return Err(
"strict mode currently supports pure Marqdo and native Math only; \
--allow-read/--allow-write/--allow-env/--allow-foreign/--allow-plugin/\
--plugin/--trust-native-plugin/--kernel/--trace-file are rejected. Use \
--mode project for those capabilities."
--allow-read/--allow-write/--allow-env/--allow-process/--allow-foreign/\
--allow-plugin/--plugin/--trust-native-plugin/--kernel/--trace-file are
rejected. Use --mode project for those capabilities."
.to_string(),
);
}
@@ -103,6 +106,7 @@ impl SandboxSettings {
|| !self.allow_net.is_empty()
|| !self.allow_write.is_empty()
|| !self.allow_env.is_empty()
|| !self.allow_process.is_empty()
|| self.allow_foreign
|| !self.allow_plugin.is_empty()
{
@@ -126,6 +130,9 @@ impl SandboxSettings {
for name in &self.allow_env {
capabilities = capabilities.allow_env(name.clone());
}
for program in &self.allow_process {
capabilities = capabilities.allow_process(program.clone());
}
if self.allow_foreign {
capabilities = capabilities.allow_foreign();
}
+4
View File
@@ -95,6 +95,9 @@ struct SandboxArgs {
/// Grant read access to an environment variable (repeatable, ADR-0043).
#[arg(long = "allow-env", value_name = "NAME")]
allow_env: Vec<String>,
/// Grant execution of an exact program path (repeatable, ADR-0044).
#[arg(long = "allow-process", value_name = "PROGRAM")]
allow_process: Vec<String>,
/// Grant explicit foreign kernel execution.
#[arg(long = "allow-foreign")]
allow_foreign: bool,
@@ -147,6 +150,7 @@ impl SandboxArgs {
allow_net: self.allow_net.clone(),
allow_write: self.allow_write.clone(),
allow_env: self.allow_env.clone(),
allow_process: self.allow_process.clone(),
allow_foreign: self.allow_foreign,
allow_plugin: self.allow_plugin.clone(),
fuel: self.fuel,
+18
View File
@@ -81,6 +81,8 @@ fn product_tests() -> Vec<TestFile> {
"--allow-env",
"MARQDO_MISSING_ENV",
][..]
} else if name == "process.mq.md" {
&["--allow-process", "/bin/echo"][..]
} else {
&[][..]
};
@@ -155,6 +157,7 @@ fn every_public_stdlib_module_has_a_product_test() {
"io.mq.md",
"json.mq.md",
"path.mq.md",
"process.mq.md",
"regex.mq.md",
"stream.mq.md",
"table.mq.md",
@@ -344,6 +347,21 @@ fn env_test_reads_only_granted_names() {
assert_eq!(items[5]["value"], "env.not_found");
}
#[test]
fn process_test_runs_an_explicitly_granted_program() {
let report = run_product_test(
product_tests()
.iter()
.find(|file| file.name == "process.mq.md")
.expect("process test"),
);
let items = report["value"]["items"].as_array().expect("list");
assert_eq!(items[0]["value"], true);
assert_eq!(items[1]["decimal"], "0");
assert_eq!(items[2]["value"], "hello\n");
assert_eq!(items[3]["value"], "");
}
#[test]
fn format_test_pins_value_semantics_and_handle_observation() {
let report = run_product_test(