test(stdlib): cover every bundled module through std imports
This commit is contained in:
1 parent
a8ccac9e67
commit
04eae8746e
13 files changed
+246
-5
No files matched your search
@@ -29,6 +29,8 @@ jobs:
|
||||
run: cargo test -p marqdo-cli --test docs_consistency
|
||||
- name: Architecture boundaries
|
||||
run: cargo test -p marqdo-cli --test architecture_boundaries
|
||||
- name: Whole stdlib product tests
|
||||
run: cargo test -p marqdo-cli --test stdlib_product
|
||||
- name: Validate public JSON schemas
|
||||
run: |
|
||||
python3 - <<'PY'
|
||||
|
||||
@@ -18,6 +18,7 @@ steps:
|
||||
- cargo test --workspace --locked
|
||||
- cargo test -p marqdo-cli --test docs_consistency
|
||||
- cargo test -p marqdo-cli --test architecture_boundaries
|
||||
- cargo test -p marqdo-cli --test stdlib_product
|
||||
|
||||
build:
|
||||
image: rust:1.100-bookworm
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
//! Product-level tests for the whole bundled `marqdo-stdlib` tree.
|
||||
//!
|
||||
//! Every public module in `stdlib/README.md` has a `.mq.md` self-test under
|
||||
//! `stdlib/tests/`, and this lane runs the whole directory through the real
|
||||
//! user import path (`std:` + the verified bundle), not through a conformance
|
||||
//! fixture or a Rust shortcut.
|
||||
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
fn repo_root() -> PathBuf {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.parent()
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap()
|
||||
.to_path_buf()
|
||||
}
|
||||
|
||||
fn stdlib_dir() -> PathBuf {
|
||||
repo_root().join("stdlib")
|
||||
}
|
||||
|
||||
struct TestFile {
|
||||
name: String,
|
||||
stdin: &'static str,
|
||||
stdout: &'static str,
|
||||
}
|
||||
|
||||
fn product_tests() -> Vec<TestFile> {
|
||||
let dir = stdlib_dir().join("tests");
|
||||
let mut files: Vec<TestFile> = std::fs::read_dir(&dir)
|
||||
.expect("read stdlib tests")
|
||||
.map(|entry| {
|
||||
let path = entry.unwrap().path();
|
||||
let name = path.file_name().unwrap().to_string_lossy().to_string();
|
||||
let (stdin, stdout) = match name.as_str() {
|
||||
"console.mq.md" => ("hello\n", ""),
|
||||
"io.mq.md" => ("", "stdlib self-test\n"),
|
||||
"stream.mq.md" => ("", "stream\n"),
|
||||
_ => ("", ""),
|
||||
};
|
||||
TestFile {
|
||||
name,
|
||||
stdin,
|
||||
stdout,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
files.sort_by(|left, right| left.name.cmp(&right.name));
|
||||
files
|
||||
}
|
||||
|
||||
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(["--json"])
|
||||
.current_dir(stdlib_dir())
|
||||
.env("MARQDO_STDLIB_DIR", stdlib_dir())
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.expect("spawn marqdo");
|
||||
child
|
||||
.stdin
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.write_all(file.stdin.as_bytes())
|
||||
.unwrap();
|
||||
let output = child.wait_with_output().expect("wait marqdo");
|
||||
assert_eq!(
|
||||
output.status.code(),
|
||||
Some(0),
|
||||
"{} failed: {}",
|
||||
file.name,
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
serde_json::from_slice(&output.stdout).expect("json report")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_public_stdlib_module_has_a_product_test() {
|
||||
let names: Vec<String> = product_tests().into_iter().map(|file| file.name).collect();
|
||||
assert_eq!(
|
||||
names,
|
||||
vec![
|
||||
"console.mq.md",
|
||||
"format.mq.md",
|
||||
"http.mq.md",
|
||||
"io.mq.md",
|
||||
"stream.mq.md",
|
||||
"table.mq.md",
|
||||
"text.mq.md",
|
||||
"utf8.mq.md",
|
||||
],
|
||||
"a public stdlib module is missing a product test"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_whole_bundled_library_runs_through_std_imports() {
|
||||
for file in product_tests() {
|
||||
let report = run_product_test(&file);
|
||||
assert_eq!(report["success"], true, "{}", file.name);
|
||||
assert_eq!(
|
||||
report["stdout"], file.stdout,
|
||||
"{} wrote unexpected stdout",
|
||||
file.name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_test_pins_value_semantics_and_handle_observation() {
|
||||
let report = run_product_test(
|
||||
product_tests()
|
||||
.iter()
|
||||
.find(|file| file.name == "format.mq.md")
|
||||
.expect("format test"),
|
||||
);
|
||||
let items = report["value"]["items"].as_array().expect("list");
|
||||
assert_eq!(items[0]["decimal"], "3");
|
||||
assert_eq!(items[1]["value"], "[\"文本\", 2, 1.5]");
|
||||
assert_eq!(items[2]["value"], "{a: 1}");
|
||||
assert_eq!(items[3]["value"], "[\"a\", 2]");
|
||||
assert_eq!(items[4]["value"], "None");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_and_utf8_tests_agree_on_the_byte_encoding() {
|
||||
let text = run_product_test(
|
||||
product_tests()
|
||||
.iter()
|
||||
.find(|file| file.name == "text.mq.md")
|
||||
.expect("text test"),
|
||||
);
|
||||
let utf8 = run_product_test(
|
||||
product_tests()
|
||||
.iter()
|
||||
.find(|file| file.name == "utf8.mq.md")
|
||||
.expect("utf8 test"),
|
||||
);
|
||||
assert_eq!(text["value"]["items"][0]["decimal"], "2");
|
||||
assert_eq!(text["value"]["items"][1]["decimal"], "195");
|
||||
assert_eq!(text["value"]["items"][2]["decimal"], "169");
|
||||
assert_eq!(utf8["value"]["items"][0]["decimal"], "2");
|
||||
assert_eq!(utf8["value"]["items"][1]["value"], "é");
|
||||
assert_eq!(utf8["value"]["items"][2]["value"], false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stream_and_console_use_the_resource_endpoints() {
|
||||
let stream = run_product_test(
|
||||
product_tests()
|
||||
.iter()
|
||||
.find(|file| file.name == "stream.mq.md")
|
||||
.expect("stream test"),
|
||||
);
|
||||
assert_eq!(stream["value"]["items"][0]["value"], true);
|
||||
assert_eq!(stream["value"]["items"][1]["decimal"], "7");
|
||||
|
||||
let console = run_product_test(
|
||||
product_tests()
|
||||
.iter()
|
||||
.find(|file| file.name == "console.mq.md")
|
||||
.expect("console test"),
|
||||
);
|
||||
assert_eq!(console["value"]["items"][0]["value"], true);
|
||||
assert_eq!(console["value"]["items"][1]["value"], "hello");
|
||||
assert!(
|
||||
console["trace"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|event| event["op"] == "resource.read" || event["op"] == "resource.open"),
|
||||
"console test did not go through a resource endpoint"
|
||||
);
|
||||
}
|
||||
+3
-1
@@ -58,11 +58,13 @@ byte-identical).
|
||||
cargo fmt --all -- --check PASS
|
||||
cargo clippy --workspace --all-targets -- -D warnings PASS
|
||||
cargo test --workspace --locked PASS
|
||||
449 passed, 0 failed, 2 ignored; includes 7/7 Linux security tests
|
||||
463 passed, 0 failed, 2 ignored; includes 7/7 Linux security tests
|
||||
```
|
||||
|
||||
The documentation and test migration is local work; re-run this block after it
|
||||
lands and update the count from the log rather than copying the number.
|
||||
`docs_consistency`, `architecture_boundaries` and `stdlib_product` run inside
|
||||
this workspace suite.
|
||||
|
||||
### G-C security lane (disposable Ubuntu 26.04 VM, ordinary user `dev`)
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ platform".
|
||||
| Dimension | Current state | Source |
|
||||
|---|---|---|
|
||||
| Implemented | Rust workspace `0.1.0`: Markdown/frontend/IR, tree-walk runtime, `Memory`, capability host, Tool/Analysis/Trace, Plugin ABI, Foreign kernels, bundled stdlib, CLI composition root | `Cargo.toml`, `crates/`, `stdlib/` |
|
||||
| Tested locally | `cargo test --workspace --locked`: **449 passed, 0 failed, 2 ignored** on Linux x86_64 at the baseline | `docs/STATUS.md` §3 |
|
||||
| Tested locally | `cargo test --workspace --locked`: **463 passed, 0 failed, 2 ignored** on Linux x86_64 at the baseline | `docs/STATUS.md` §3 |
|
||||
| Bundled stdlib released | In-repo bundle `marqdo-stdlib@0.1.0`, SHA-256 digest verified before loading; it is **not** an external registry package | `stdlib/stdlib.json`, `stdlib/README.md` |
|
||||
| Multi-platform verified | Linux local gate is the only executed lane here; Windows/macOS native lanes are **UNVERIFIED**, and the GitHub security lane remains a **VM-only** gate | `docs/STATUS.md` §1, §4 |
|
||||
|
||||
|
||||
+2
-1
@@ -13,7 +13,8 @@ module; a mismatch is a hard error.
|
||||
- `demo.mq.md` — side-by-side comparison with builtin `打印`
|
||||
- `data/table.mq.md` — value-returning table select/filter/sort/append/set/join/group/GFM
|
||||
- `net/http.mq.md` — HTTP/1.1 response parsing (headers/chunked) and request builder
|
||||
- `tests/` — bundle self-tests
|
||||
- `tests/` — product self-tests for every public module
|
||||
(`console`, `format`, `http`, `io`, `stream`, `table`, `text`, `utf8`)
|
||||
|
||||
The digest is a SHA-256 over sorted `*.mq.md` relative paths, a NUL, file
|
||||
bytes, and a NUL. It excludes `stdlib.json` and non-`.mq.md` files. After any
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "marqdo-stdlib",
|
||||
"version": "0.1.0",
|
||||
"digest": "sha256:bf11fbdd5fedcaf596308630bdd9590600d9ffac6658c9af483215b4b91aa13f"
|
||||
"digest": "sha256:86edd79cb84057dba847cc66136a6d6a647d44ea889fff537bd8d162707a3285"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
import:
|
||||
console: "std:io/console"
|
||||
---
|
||||
|
||||
## main
|
||||
|
||||
**行 = console.读取行()**
|
||||
|
||||
*[行.ok, 行.value]*
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
import:
|
||||
format: "std:format"
|
||||
---
|
||||
|
||||
## main
|
||||
|
||||
*[format.字节长度("Aé"), format.显示(["文本", 2, 1.5]), format.显示({a: 1}), format.列表显示(["a", 2]), format.显示(None)]*
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
import:
|
||||
stream: "std:io/stream"
|
||||
---
|
||||
|
||||
## main
|
||||
|
||||
**结果 = stream.写文本("stream\n")**
|
||||
|
||||
*[结果.ok, 结果.value.count]*
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
import:
|
||||
text: "std:text"
|
||||
---
|
||||
|
||||
## main
|
||||
|
||||
**内存 = memory.new(1, 1)**
|
||||
|
||||
**长度 = text.utf8编码("é", 内存, 0)**
|
||||
|
||||
*[长度, 内存[0], 内存[1]]*
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
import:
|
||||
utf8: "std:text/utf8"
|
||||
---
|
||||
|
||||
## main
|
||||
|
||||
**内存 = memory.new(1, 1)**
|
||||
|
||||
**长度 = utf8.编码("é", 内存, 0)**
|
||||
|
||||
*[长度, utf8.解码(内存, 0, 长度).value, utf8.解码(内存, 0, 1).ok]*
|
||||
@@ -20,7 +20,9 @@ DIST = ROOT / "dist"
|
||||
|
||||
def tree_digest() -> str:
|
||||
digest = hashlib.sha256()
|
||||
for path in sorted(STDLIB.rglob("*.mq.md")):
|
||||
for path in sorted(
|
||||
STDLIB.rglob("*.mq.md"), key=lambda p: p.relative_to(STDLIB).as_posix()
|
||||
):
|
||||
relative = path.relative_to(STDLIB).as_posix()
|
||||
digest.update(relative.encode())
|
||||
digest.update(b"\0")
|
||||
|
||||
Reference in new issue
Block a user