test(portable): fix native stack and process-fixture assumptions
CI / fmt + clippy + test (Linux x86_64) (push) Waiting to run
CI / runtime contract (macos-latest) (push) Waiting to run
CI / runtime contract (windows-latest) (push) Waiting to run
Linux strict security lane (G-C) / strict isolation escape matrix (push) Waiting to run
CI / schema instance validation + consumers (push) Waiting to run
ci/woodpecker/push/woodpecker Pipeline was successful

macOS arm64 aborted in nesting_depth_limit_is_enforced because the test-harness
thread stack is smaller than a production main thread. Run that contract test
on an explicit 8 MiB stack; the 128-level parser bound itself is unchanged.

The stdlib process product test hard-coded /bin/echo, which does not exist on
Windows. Use the test CLI itself as the granted program: the fixture reads
MARQDO_TEST_PROCESS_PROGRAM from the granted env, runs it with --version, and
the harness compares against the same invocation. process.run now forwards
SYSTEMROOT/WINDIR on Windows (process creation/DLL loading, not a capability),
and the bundled stdlib digest is regenerated for the changed test fixture.
This commit is contained in:
cflmy committed 2026-11-21 18:35:33 +08:00
1 parent 3a29fce061
commit b898c419fe
5 files changed
+102 -39

No files matched your search

+62 -34
View File
@@ -37,8 +37,8 @@ struct TestFile {
name: String,
stdin: &'static str,
stdout: &'static str,
args: &'static [&'static str],
env: &'static [(&'static str, &'static str)],
args: Vec<String>,
env: Vec<(String, String)>,
}
fn product_tests() -> Vec<TestFile> {
@@ -52,8 +52,8 @@ fn product_tests() -> Vec<TestFile> {
name: String::new(),
stdin: "",
stdout: "",
args: &[],
env: &[],
args: Vec::new(),
env: Vec::new(),
};
}
let name = path.file_name().unwrap().to_string_lossy().to_string();
@@ -63,35 +63,50 @@ fn product_tests() -> Vec<TestFile> {
"stream.mq.md" => ("", "stream\n"),
_ => ("", ""),
};
let args = if name == "fs.mq.md" {
&[
"--allow-read",
"out",
"--allow-read",
"out/**",
"--allow-write",
"out",
"--allow-write",
"out/**",
][..]
} else if name == "env.mq.md" {
&[
"--allow-env",
"MARQDO_TEST_ENV",
"--allow-env",
"MARQDO_MISSING_ENV",
][..]
} else if name == "process.mq.md" {
&["--allow-process", "/bin/echo"][..]
} else if name == "random.mq.md" {
&["--allow-random"][..]
} else {
&[][..]
let text_args = |values: &[&str]| -> Vec<String> {
values.iter().map(|value| value.to_string()).collect()
};
let env = if name == "env.mq.md" {
&[("MARQDO_TEST_ENV", "env-value")][..]
let (args, env) = if name == "fs.mq.md" {
(
text_args(&[
"--allow-read",
"out",
"--allow-read",
"out/**",
"--allow-write",
"out",
"--allow-write",
"out/**",
]),
Vec::new(),
)
} else if name == "env.mq.md" {
(
text_args(&[
"--allow-env",
"MARQDO_TEST_ENV",
"--allow-env",
"MARQDO_MISSING_ENV",
]),
vec![("MARQDO_TEST_ENV".to_string(), "env-value".to_string())],
)
} else if name == "process.mq.md" {
// Use the test binary itself as the granted program: it exists
// on every native platform, unlike the old `/bin/echo` fixture.
let program = env!("CARGO_BIN_EXE_marqdo").to_string();
(
vec![
"--allow-env".to_string(),
"MARQDO_TEST_PROCESS_PROGRAM".to_string(),
"--allow-process".to_string(),
program.clone(),
],
vec![("MARQDO_TEST_PROCESS_PROGRAM".to_string(), program)],
)
} else if name == "random.mq.md" {
(text_args(&["--allow-random"]), Vec::new())
} else {
&[][..]
(Vec::new(), Vec::new())
};
TestFile {
name,
@@ -114,11 +129,15 @@ fn run_product_test(file: &TestFile) -> serde_json::Value {
let mut child = Command::new(env!("CARGO_BIN_EXE_marqdo"))
.args(["run"])
.arg(stdlib_dir().join("tests").join(&file.name))
.args(file.args)
.args(file.args.iter())
.args(["--json"])
.current_dir(stdlib_dir())
.env("MARQDO_STDLIB_DIR", stdlib_dir())
.envs(file.env.iter().copied())
.envs(
file.env
.iter()
.map(|(key, value)| (key.as_str(), value.as_str())),
)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
@@ -380,7 +399,16 @@ fn process_test_runs_an_explicitly_granted_program() {
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");
let expected = Command::new(env!("CARGO_BIN_EXE_marqdo"))
.arg("--version")
.output()
.expect("run marqdo --version");
let expected_stdout = String::from_utf8_lossy(&expected.stdout);
assert_eq!(
items[2]["value"].as_str().expect("process stdout"),
expected_stdout.as_ref(),
"process stdout must match the granted program"
);
assert_eq!(items[3]["value"], "");
}
+21
View File
@@ -1377,8 +1377,29 @@ mod tests {
format!("{}1{}", "(".repeat(depth), ")".repeat(depth))
}
/// Run a deeply recursive parser test on an explicit stack.
///
/// The test harness gives each test thread a small stack on some native
/// platforms (macOS arm64 aborted with a stack overflow at the 128-level
/// nesting check). Production parsing happens on the main thread; pinning
/// this test to 8 MiB keeps the contract test meaningful without depending
/// on the harness default.
fn with_parser_stack<F: FnOnce() + Send + 'static>(body: F) {
std::thread::Builder::new()
.name("parser-nesting-depth".to_string())
.stack_size(8 * 1024 * 1024)
.spawn(body)
.expect("spawn parser nesting thread")
.join()
.expect("parser nesting thread panicked");
}
#[test]
fn nesting_depth_limit_is_enforced() {
with_parser_stack(nesting_depth_limit_is_enforced_body);
}
fn nesting_depth_limit_is_enforced_body() {
assert!(parse_expression(&nested_parens(MAX_NESTING_DEPTH)).is_ok());
let err = parse_expression(&nested_parens(MAX_NESTING_DEPTH + 1)).unwrap_err();
assert_eq!(err.code, "expr.parse");
+14 -3
View File
@@ -27,14 +27,25 @@ pub(crate) fn run_process(
ctx: &ExecutionContext,
) -> Result<Value, RuntimeError> {
const LIMIT: usize = 1024 * 1024;
let child = Command::new(program)
let mut command = Command::new(program);
command
.args(args)
.current_dir(root)
.env_clear()
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn();
.stderr(Stdio::piped());
#[cfg(windows)]
{
// Windows process creation and DLL loading require the system root;
// this is not a package-resolution path or a capability grant.
for name in ["SYSTEMROOT", "WINDIR"] {
if let Some(value) = std::env::var_os(name) {
command.env(name, value);
}
}
}
let child = command.spawn();
let child = match child {
Ok(child) => child,
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
+1 -1
View File
@@ -1,5 +1,5 @@
{
"name": "marqdo-stdlib",
"version": "0.1.0",
"digest": "sha256:c3fca0cc3bd8f89f0f45d52418113613dd0613711cfdba76b514e5e6244409d2"
"digest": "sha256:b94f1a48ca6619689584aca3af7befac64ac9fdb7ea7c0a9ccb491df8df226b8"
}
+4 -1
View File
@@ -1,5 +1,6 @@
---
import:
env: "std:env"
process: "std:process"
---
@@ -7,6 +8,8 @@ import:
## main
**结果 = process.运行("/bin/echo", ["hello"])**
**程序 = env.读取("MARQDO_TEST_PROCESS_PROGRAM")**
**结果 = process.运行(程序.value, ["--version"])**
`return [结果.ok, 结果.value.status, 结果.value.stdout, 结果.value.stderr]`