test(portable): fix native stack and process-fixture assumptions
ci/woodpecker/push/woodpecker Pipeline was successful
Linux strict security lane (G-C) / strict isolation escape matrix (push) Canceled after 0s
CI / fmt + clippy + test (Linux x86_64) (push) Canceled after 0s
CI / schema instance validation + consumers (push) Canceled after 0s
CI / runtime contract (macos-latest) (push) Canceled after 0s
CI / runtime contract (windows-latest) (push) Canceled after 0s
CI / release evidence manifest (push) Canceled after 0s
CI / release candidate artifact (macos-latest) (push) Canceled after 0s
CI / release candidate artifact (ubuntu-latest) (push) Canceled after 0s
ci/woodpecker/push/woodpecker Pipeline was successful
Linux strict security lane (G-C) / strict isolation escape matrix (push) Canceled after 0s
CI / fmt + clippy + test (Linux x86_64) (push) Canceled after 0s
CI / schema instance validation + consumers (push) Canceled after 0s
CI / runtime contract (macos-latest) (push) Canceled after 0s
CI / runtime contract (windows-latest) (push) Canceled after 0s
CI / release evidence manifest (push) Canceled after 0s
CI / release candidate artifact (macos-latest) (push) Canceled after 0s
CI / release candidate artifact (ubuntu-latest) (push) Canceled after 0s
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:
1 parent
3a29fce061
commit
b898c419fe
5 files changed
+102
-39
No files matched your search
@@ -37,8 +37,8 @@ struct TestFile {
|
|||||||
name: String,
|
name: String,
|
||||||
stdin: &'static str,
|
stdin: &'static str,
|
||||||
stdout: &'static str,
|
stdout: &'static str,
|
||||||
args: &'static [&'static str],
|
args: Vec<String>,
|
||||||
env: &'static [(&'static str, &'static str)],
|
env: Vec<(String, String)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn product_tests() -> Vec<TestFile> {
|
fn product_tests() -> Vec<TestFile> {
|
||||||
@@ -52,8 +52,8 @@ fn product_tests() -> Vec<TestFile> {
|
|||||||
name: String::new(),
|
name: String::new(),
|
||||||
stdin: "",
|
stdin: "",
|
||||||
stdout: "",
|
stdout: "",
|
||||||
args: &[],
|
args: Vec::new(),
|
||||||
env: &[],
|
env: Vec::new(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let name = path.file_name().unwrap().to_string_lossy().to_string();
|
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"),
|
"stream.mq.md" => ("", "stream\n"),
|
||||||
_ => ("", ""),
|
_ => ("", ""),
|
||||||
};
|
};
|
||||||
let args = if name == "fs.mq.md" {
|
let text_args = |values: &[&str]| -> Vec<String> {
|
||||||
&[
|
values.iter().map(|value| value.to_string()).collect()
|
||||||
"--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 env = if name == "env.mq.md" {
|
let (args, env) = if name == "fs.mq.md" {
|
||||||
&[("MARQDO_TEST_ENV", "env-value")][..]
|
(
|
||||||
|
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 {
|
} else {
|
||||||
&[][..]
|
(Vec::new(), Vec::new())
|
||||||
};
|
};
|
||||||
TestFile {
|
TestFile {
|
||||||
name,
|
name,
|
||||||
@@ -114,11 +129,15 @@ fn run_product_test(file: &TestFile) -> serde_json::Value {
|
|||||||
let mut child = Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
let mut child = Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
||||||
.args(["run"])
|
.args(["run"])
|
||||||
.arg(stdlib_dir().join("tests").join(&file.name))
|
.arg(stdlib_dir().join("tests").join(&file.name))
|
||||||
.args(file.args)
|
.args(file.args.iter())
|
||||||
.args(["--json"])
|
.args(["--json"])
|
||||||
.current_dir(stdlib_dir())
|
.current_dir(stdlib_dir())
|
||||||
.env("MARQDO_STDLIB_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())
|
.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(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");
|
let items = report["value"]["items"].as_array().expect("list");
|
||||||
assert_eq!(items[0]["value"], true);
|
assert_eq!(items[0]["value"], true);
|
||||||
assert_eq!(items[1]["decimal"], "0");
|
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"], "");
|
assert_eq!(items[3]["value"], "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1377,8 +1377,29 @@ mod tests {
|
|||||||
format!("{}1{}", "(".repeat(depth), ")".repeat(depth))
|
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]
|
#[test]
|
||||||
fn nesting_depth_limit_is_enforced() {
|
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());
|
assert!(parse_expression(&nested_parens(MAX_NESTING_DEPTH)).is_ok());
|
||||||
let err = parse_expression(&nested_parens(MAX_NESTING_DEPTH + 1)).unwrap_err();
|
let err = parse_expression(&nested_parens(MAX_NESTING_DEPTH + 1)).unwrap_err();
|
||||||
assert_eq!(err.code, "expr.parse");
|
assert_eq!(err.code, "expr.parse");
|
||||||
|
|||||||
@@ -27,14 +27,25 @@ pub(crate) fn run_process(
|
|||||||
ctx: &ExecutionContext,
|
ctx: &ExecutionContext,
|
||||||
) -> Result<Value, RuntimeError> {
|
) -> Result<Value, RuntimeError> {
|
||||||
const LIMIT: usize = 1024 * 1024;
|
const LIMIT: usize = 1024 * 1024;
|
||||||
let child = Command::new(program)
|
let mut command = Command::new(program);
|
||||||
|
command
|
||||||
.args(args)
|
.args(args)
|
||||||
.current_dir(root)
|
.current_dir(root)
|
||||||
.env_clear()
|
.env_clear()
|
||||||
.stdin(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped());
|
||||||
.spawn();
|
#[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 {
|
let child = match child {
|
||||||
Ok(child) => child,
|
Ok(child) => child,
|
||||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
|
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "marqdo-stdlib",
|
"name": "marqdo-stdlib",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"digest": "sha256:c3fca0cc3bd8f89f0f45d52418113613dd0613711cfdba76b514e5e6244409d2"
|
"digest": "sha256:b94f1a48ca6619689584aca3af7befac64ac9fdb7ea7c0a9ccb491df8df226b8"
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
---
|
---
|
||||||
import:
|
import:
|
||||||
|
env: "std:env"
|
||||||
process: "std:process"
|
process: "std:process"
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -7,6 +8,8 @@ import:
|
|||||||
|
|
||||||
## main
|
## main
|
||||||
|
|
||||||
**结果 = process.运行("/bin/echo", ["hello"])**
|
**程序 = env.读取("MARQDO_TEST_PROCESS_PROGRAM")**
|
||||||
|
|
||||||
|
**结果 = process.运行(程序.value, ["--version"])**
|
||||||
|
|
||||||
`return [结果.ok, 结果.value.status, 结果.value.stdout, 结果.value.stderr]`
|
`return [结果.ok, 结果.value.status, 结果.value.stdout, 结果.value.stderr]`
|
||||||
Reference in new issue
Block a user