feat(compress): add bounded gzip product codec
This commit is contained in:
1 parent
ff3f19a2ea
commit
efbb8007e1
16 files changed
+372
-9
No files matched your search
Generated
+49
@@ -2,6 +2,12 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "adler2"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "1.0.0"
|
||||
@@ -192,6 +198,15 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b929dd2a135771f40afabd1073f85eed59c800b7c61901e5c254270497dad64"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.7"
|
||||
@@ -275,6 +290,17 @@ version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ded33109e99472f809cb7495544506eea45e366725dacf2a383e184f660456"
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "626d4928326b646e70f65ed36fc7cf9f206bdb68a0019ee7c6b4709da4e084c4"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"miniz_oxide",
|
||||
"zlib-rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
@@ -448,6 +474,7 @@ dependencies = [
|
||||
name = "marqdo-host"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"getrandom 0.4.3",
|
||||
"glob",
|
||||
"libloading",
|
||||
@@ -609,6 +636,16 @@ dependencies = [
|
||||
"fearless_simd_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c"
|
||||
dependencies = [
|
||||
"adler2",
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.4.8"
|
||||
@@ -980,6 +1017,12 @@ version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
||||
|
||||
[[package]]
|
||||
name = "simd-adler32"
|
||||
version = "0.3.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "1.0.4"
|
||||
@@ -1252,6 +1295,12 @@ version = "1.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85ccff8a4805aba1eaa4cd4afcd49f7557dd2cf5fd79ffc37f8959466effc5aa"
|
||||
|
||||
[[package]]
|
||||
name = "zlib-rs"
|
||||
version = "0.6.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.23"
|
||||
|
||||
@@ -53,6 +53,7 @@ semver = "1"
|
||||
hex = "0.4"
|
||||
libloading = "0.8"
|
||||
tempfile = "3"
|
||||
flate2 = "1"
|
||||
getrandom = "0.4"
|
||||
rustls = { version = "0.23", default-features = false, features = ["ring", "std", "tls12"] }
|
||||
rustls-native-certs = "0.8"
|
||||
|
||||
@@ -148,6 +148,7 @@ fn every_public_stdlib_module_has_a_product_test() {
|
||||
names,
|
||||
vec![
|
||||
"clock.mq.md",
|
||||
"compress.mq.md",
|
||||
"console.mq.md",
|
||||
"csv.mq.md",
|
||||
"datetime.mq.md",
|
||||
@@ -384,6 +385,21 @@ fn random_test_reads_bounded_entropy() {
|
||||
assert_eq!(items[4]["value"], true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compress_test_round_trips_gzip_text() {
|
||||
let report = run_product_test(
|
||||
product_tests()
|
||||
.iter()
|
||||
.find(|file| file.name == "compress.mq.md")
|
||||
.expect("compress test"),
|
||||
);
|
||||
let items = report["value"]["items"].as_array().expect("list");
|
||||
assert_eq!(items[0]["value"], true);
|
||||
assert_eq!(items[1]["value"], true);
|
||||
assert_eq!(items[2]["value"], true);
|
||||
assert_eq!(items[3]["value"], "hello 世界");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_test_pins_value_semantics_and_handle_observation() {
|
||||
let report = run_product_test(
|
||||
|
||||
@@ -13,6 +13,7 @@ libloading = { workspace = true }
|
||||
rustls = { workspace = true }
|
||||
rustls-native-certs = { workspace = true }
|
||||
marqdo-plugin-abi = { workspace = true }
|
||||
flate2 = { workspace = true }
|
||||
getrandom = { workspace = true }
|
||||
glob = { workspace = true }
|
||||
marqdo-span = { workspace = true }
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
//! execution, not at parse/compile time.
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::io::{Read, Write};
|
||||
use std::net::{TcpListener, TcpStream, ToSocketAddrs, UdpSocket};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
||||
@@ -628,6 +629,14 @@ impl StdHost {
|
||||
}
|
||||
}
|
||||
|
||||
fn result_error(code: &str, message: &str) -> Value {
|
||||
let mut map = BTreeMap::new();
|
||||
map.insert("ok".to_string(), Value::Bool(false));
|
||||
map.insert("code".to_string(), Value::text(code));
|
||||
map.insert("message".to_string(), Value::text(message));
|
||||
Value::Map(map)
|
||||
}
|
||||
|
||||
impl Host for StdHost {
|
||||
fn invoke(
|
||||
&mut self,
|
||||
@@ -836,6 +845,146 @@ impl Host for StdHost {
|
||||
self.record_resource_effect("resource.request", ctx, started, "process.run");
|
||||
return Ok(result);
|
||||
}
|
||||
if operation == "compress.gzip" {
|
||||
if args.len() != 1 {
|
||||
return Err(RuntimeError::new(
|
||||
ErrorCategory::Arity,
|
||||
ctx.span,
|
||||
format!(
|
||||
"resource operation `compress.gzip` expects 1 argument, got {}",
|
||||
args.len()
|
||||
),
|
||||
));
|
||||
}
|
||||
let text_type = args[0].type_name();
|
||||
let Value::Text(text) = args[0].clone() else {
|
||||
return Err(RuntimeError::type_error(
|
||||
ctx.span,
|
||||
format!("compress.gzip expects Text, got {text_type}"),
|
||||
));
|
||||
};
|
||||
if text.len() > 8 * 1024 * 1024 {
|
||||
return Err(RuntimeError::new(
|
||||
ErrorCategory::ResourceExhausted,
|
||||
ctx.span,
|
||||
"compress.gzip input exceeds 8 MiB",
|
||||
));
|
||||
}
|
||||
let mut encoder =
|
||||
flate2::write::GzEncoder::new(Vec::new(), flate2::Compression::default());
|
||||
encoder.write_all(text.as_bytes()).map_err(|error| {
|
||||
RuntimeError::new(
|
||||
ErrorCategory::HostError,
|
||||
ctx.span,
|
||||
format!("gzip failed: {error}"),
|
||||
)
|
||||
})?;
|
||||
let bytes = encoder.finish().map_err(|error| {
|
||||
RuntimeError::new(
|
||||
ErrorCategory::HostError,
|
||||
ctx.span,
|
||||
format!("gzip failed: {error}"),
|
||||
)
|
||||
})?;
|
||||
let values = bytes
|
||||
.into_iter()
|
||||
.map(|byte| Value::int(byte as i64))
|
||||
.collect();
|
||||
self.record_semantic(
|
||||
"resource.request",
|
||||
None,
|
||||
Some(&ctx.module_id),
|
||||
ctx.span,
|
||||
Some("op=compress.gzip"),
|
||||
);
|
||||
self.record_resource_effect("resource.request", ctx, started, "compress.gzip");
|
||||
let mut map = BTreeMap::new();
|
||||
map.insert("ok".to_string(), Value::Bool(true));
|
||||
map.insert("value".to_string(), Value::List(values));
|
||||
return Ok(Value::Map(map));
|
||||
}
|
||||
if operation == "compress.gunzip" {
|
||||
if args.len() != 1 {
|
||||
return Err(RuntimeError::new(
|
||||
ErrorCategory::Arity,
|
||||
ctx.span,
|
||||
format!(
|
||||
"resource operation `compress.gunzip` expects 1 argument, got {}",
|
||||
args.len()
|
||||
),
|
||||
));
|
||||
}
|
||||
let list_type = args[0].type_name();
|
||||
let Value::List(values) = args[0].clone() else {
|
||||
return Err(RuntimeError::type_error(
|
||||
ctx.span,
|
||||
format!("compress.gunzip expects List<Int>, got {list_type}"),
|
||||
));
|
||||
};
|
||||
if values.len() > 8 * 1024 * 1024 {
|
||||
return Err(RuntimeError::new(
|
||||
ErrorCategory::ResourceExhausted,
|
||||
ctx.span,
|
||||
"compress.gunzip input exceeds 8 MiB",
|
||||
));
|
||||
}
|
||||
let mut bytes = Vec::with_capacity(values.len());
|
||||
for value in values {
|
||||
let Value::Int(value) = value else {
|
||||
return Err(RuntimeError::type_error(
|
||||
ctx.span,
|
||||
"compress.gunzip bytes must be Int",
|
||||
));
|
||||
};
|
||||
let Some(byte) = value.to_string().parse::<u8>().ok() else {
|
||||
return Err(RuntimeError::new(
|
||||
ErrorCategory::Type,
|
||||
ctx.span,
|
||||
format!("`{value}` is not a byte in 0..=255"),
|
||||
));
|
||||
};
|
||||
bytes.push(byte);
|
||||
}
|
||||
let mut decoder = flate2::read::GzDecoder::new(bytes.as_slice());
|
||||
let mut output = Vec::new();
|
||||
if let Err(error) = decoder
|
||||
.by_ref()
|
||||
.take(8 * 1024 * 1024 + 1)
|
||||
.read_to_end(&mut output)
|
||||
{
|
||||
return Ok(result_error(
|
||||
"compress.invalid",
|
||||
&format!("gunzip failed: {error}"),
|
||||
));
|
||||
}
|
||||
if output.len() > 8 * 1024 * 1024 {
|
||||
return Ok(result_error(
|
||||
"compress.too_large",
|
||||
"gunzip output exceeds 8 MiB",
|
||||
));
|
||||
}
|
||||
let text = match String::from_utf8(output) {
|
||||
Ok(text) => text,
|
||||
Err(_) => {
|
||||
return Ok(result_error(
|
||||
"compress.not_utf8",
|
||||
"gunzip output is not UTF-8",
|
||||
))
|
||||
}
|
||||
};
|
||||
self.record_semantic(
|
||||
"resource.request",
|
||||
None,
|
||||
Some(&ctx.module_id),
|
||||
ctx.span,
|
||||
Some("op=compress.gunzip"),
|
||||
);
|
||||
self.record_resource_effect("resource.request", ctx, started, "compress.gunzip");
|
||||
let mut map = BTreeMap::new();
|
||||
map.insert("ok".to_string(), Value::Bool(true));
|
||||
map.insert("value".to_string(), Value::text(text));
|
||||
return Ok(Value::Map(map));
|
||||
}
|
||||
if operation == "random.bytes" {
|
||||
if args.len() != 1 {
|
||||
return Err(RuntimeError::new(
|
||||
|
||||
@@ -1091,3 +1091,29 @@ fn tls_requires_project_mode_and_a_host_grant() {
|
||||
.unwrap_err();
|
||||
assert_eq!(error.category, ErrorCategory::PermissionDenied);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compression_round_trips_and_rejects_invalid_gzip() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut host = StdHost::new(SandboxMode::Project, Capabilities::project(), dir.path());
|
||||
let ctx = context();
|
||||
let compressed = host
|
||||
.resource_request("compress.gzip", vec![Value::text("hello 世界")], &ctx)
|
||||
.unwrap();
|
||||
assert_eq!(field(&compressed, "ok"), &Value::Bool(true));
|
||||
let bytes = field(&compressed, "value").clone();
|
||||
let decompressed = host
|
||||
.resource_request("compress.gunzip", vec![bytes], &ctx)
|
||||
.unwrap();
|
||||
assert_eq!(field(&decompressed, "value"), &Value::text("hello 世界"));
|
||||
|
||||
let invalid = host
|
||||
.resource_request(
|
||||
"compress.gunzip",
|
||||
vec![Value::List(vec![Value::int(1), Value::int(2)])],
|
||||
&ctx,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(field(&invalid, "ok"), &Value::Bool(false));
|
||||
assert_eq!(field(&invalid, "code"), &Value::text("compress.invalid"));
|
||||
}
|
||||
+4
-5
@@ -58,7 +58,7 @@ byte-identical).
|
||||
cargo fmt --all -- --check PASS
|
||||
cargo clippy --workspace --all-targets -- -D warnings PASS
|
||||
cargo test --workspace --locked PASS
|
||||
488 passed, 0 failed, 2 ignored; includes 7/7 Linux security tests
|
||||
490 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
|
||||
@@ -209,10 +209,9 @@ This is still a **local VM lane**, not a self-hosted GitHub Actions security URL
|
||||
runs an exact `--allow-process PROGRAM` grant with 5 s timeout and 1 MiB caps
|
||||
(ADR-0044, not an OS sandbox); `random.字节` reads explicitly granted
|
||||
`random.bytes` entropy (ADR-0046). File watch, binary offset reads, streaming
|
||||
JSON/CSV, a JSON depth bound, regex groups/alternation and compression remain
|
||||
open.
|
||||
JSON/CSV, a JSON depth bound and regex groups/alternation remain open.
|
||||
- Bundled standard library (CM-A10, ADR-0028): `stdlib/` ships
|
||||
`format`/`text`/`io`/`fs`/`data`/`path`/`regex`/`datetime`/`clock`/`env`/`process`/`random`; explicit `std:` imports resolve only inside the bundle;
|
||||
`format`/`text`/`io`/`fs`/`data`/`path`/`regex`/`datetime`/`clock`/`env`/`process`/`random`/`compress`; explicit `std:` imports resolve only inside the bundle;
|
||||
a SHA-256 digest over `*.mq.md` is verified before loading; Analysis records
|
||||
`project.stdlib`; a frozen-binary test asserts the CLI hash is unchanged after
|
||||
running a `std:io` project and that tampering is rejected. `打印/print` is
|
||||
@@ -238,7 +237,7 @@ This is still a **local VM lane**, not a self-hosted GitHub Actions security URL
|
||||
status/index links and SHA-pinned evidence; `crates/cli/tests/architecture_boundaries.rs`
|
||||
pins the workspace graph, `marqdo-runtime -> marqdo-host`, the bundled stdlib
|
||||
digest and the stdio/file/TCP endpoints; `crates/cli/tests/stdlib_product.rs`
|
||||
runs every public stdlib module (`clock/console/csv/datetime/demo/env/format/fs/http/io/json/path/process/random/regex/stream/table/text/utf8`)
|
||||
runs every public stdlib module (`clock/compress/console/csv/datetime/demo/env/format/fs/http/io/json/path/process/random/regex/stream/table/text/utf8`)
|
||||
through `std:` imports over `stdlib/tests/*.mq.md`. `tools/pack-stdlib.py`
|
||||
now sorts `.mq.md` by the same relative path key as the CLI. Source/test baseline
|
||||
`0d40de7`; later docs-only commits keep code/test bytes identical. Evidence:
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
# ADR-0049: gzip compression resource operations
|
||||
|
||||
Status: **Accepted**
|
||||
Date: 2026-11-21
|
||||
Relates to: ADR-0041
|
||||
Specs: `spec/evaluation.md`
|
||||
Evidence: `docs/evidence/2026-11-21-compress-product.md`
|
||||
|
||||
## Context
|
||||
|
||||
Compression is pure computation, but implementing gzip in `.mq.md` would either
|
||||
duplicate a large algorithm or under-deliver. Adding a new Rust builtin would
|
||||
expand the language surface; the existing non-streaming `resource.request`
|
||||
channel is a better fit for an explicitly bounded codec operation.
|
||||
|
||||
## Decision
|
||||
|
||||
Add two project-mode operations:
|
||||
|
||||
```text
|
||||
resource.request("compress.gzip", [text]) -> {ok:true, value:List<Int>}
|
||||
resource.request("compress.gunzip", [bytes]) -> {ok:true, value:Text}
|
||||
| {ok:false, code:"compress.invalid"}
|
||||
| {ok:false, code:"compress.not_utf8"}
|
||||
| {ok:false, code:"compress.too_large"}
|
||||
```
|
||||
|
||||
* `gzip` takes Text, caps input at 8 MiB, writes a deterministic gzip header
|
||||
(no filename/time) and returns a byte list.
|
||||
* `gunzip` takes a `List<Int>` of bytes, caps input and output at 8 MiB,
|
||||
returns Text on success, and maps bad gzip/UTF-8/oversize output to the
|
||||
recoverable codes above.
|
||||
* No new capability flag is added: compression is deterministic CPU work and
|
||||
does not disclose external state. It remains project-mode only because all
|
||||
`resource.request` operations do; `pure`/`strict` refuse it.
|
||||
* `flate2` (miniz_oxide backend) is the implementation. No new builtin,
|
||||
`HostOp`, parser node or wire value is added.
|
||||
* `stdlib/compress.mq.md` exposes `压缩`/`解压`.
|
||||
|
||||
## Consequences
|
||||
|
||||
* Callers can compress data without a second language surface, but must pass
|
||||
byte lists through ordinary `List<Int>` values.
|
||||
* Streaming gzip, raw deflate, zstd/brotli and binary `Memory` output remain
|
||||
open. A streaming codec would need a new Resource kind.
|
||||
@@ -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`: **488 passed, 0 failed, 2 ignored** on Linux x86_64 at the baseline | `docs/STATUS.md` §3 |
|
||||
| Tested locally | `cargo test --workspace --locked`: **490 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 |
|
||||
|
||||
@@ -101,6 +101,7 @@ review RFC, not a new crate per provider.
|
||||
| `std:env` | `env.读取/存在` -> `resource.request("env.get", [name])`; exact `--allow-env` grant | implemented (project mode; no `env.list`) | `resource_streams`, `stdlib_product` |
|
||||
| `std:process` | `process.运行(程序, 参数列表)` -> `resource.request("process.run", ...)`; exact `--allow-process` grant, 5 s timeout, 1 MiB caps | implemented (project mode; not an OS sandbox) | `resource_streams`, `stdlib_product` |
|
||||
| `std:random` | `random.字节/整数` -> `resource.request("random.bytes", [count])`; exact `--allow-random` grant | implemented (project mode; byte-list RNG) | `resource_streams`, `stdlib_product` |
|
||||
| `std:compress` | `compress.压缩/解压` -> gzip byte list <-> Text; 8 MiB caps | implemented (project mode; no grant) | `resource_streams`, `stdlib_product` |
|
||||
| network endpoints | `tcp`/`udp`/`tcp-listener`/`tls` open + `resource.accept`; exact host grant, DNS after grant, TLS certificate validation | implemented (project mode) | `resource_streams` |
|
||||
| file metadata / directory / rename / remove / mkdir | not part of the current Resource contract | **not implemented**; needs a separate Resource Operation ADR | — |
|
||||
| TCP | `resource.open("tcp", ip:port, ["read","write"])`; exact IP grant, 5 s timeout | implemented; no DNS/TLS/server socket/UDP | `tcp_endpoint`, `http_over_tcp` |
|
||||
@@ -133,7 +134,7 @@ that a phase is complete.
|
||||
| P1 | CLI split into `commands/{sandbox,run,check,inspect,init,package,tool}.rs`; host split into `host/{resource_ops,providers,effects,dispatch}.rs` plus `process.rs`; `commands.rs` keeps shared project/runtime helpers and `host.rs` keeps the `Host` trait methods and capability checks | split; shared helpers and trait methods remain by design |
|
||||
| P2 | HTTP parsing is Unicode-codepoint oriented; a general byte body is not the only path | open; convert before a general network release |
|
||||
| P2 | DNS, UDP, TCP listener and TLS client endpoints are implemented; no TLS server/mTLS or custom-CA CLI | open |
|
||||
| P2 | `std:path`, a regex subset, `std:datetime`, `std:clock`, `std:env`, `std:process` and `std:random` are implemented; no compression | open |
|
||||
| P2 | `std:path`, regex subset, `std:datetime`, `std:clock`, `std:env`, `std:process`, `std:random` and gzip compression are implemented; no streaming/zstd/brotli | open |
|
||||
| P2 | Memory limits: 16 MiB per region, 64 MiB per run | current budget, not a product limit |
|
||||
| P3 | No concurrency tasks, atomics or cancellable long-running scheduling | open; separate ADR |
|
||||
| P3 | No native optimizer/JIT or columnar numeric backend | open; benchmark-first |
|
||||
@@ -171,5 +172,6 @@ that a phase is complete.
|
||||
- [ADR-0046: `random.bytes`](../adr/0046-random-resource-operation.md) — accepted explicitly granted OS entropy.
|
||||
- [ADR-0047: DNS/UDP/TCP listener](../adr/0047-net-dns-udp-listener.md) — accepted project-mode network endpoints.
|
||||
- [ADR-0048: TLS client endpoint](../adr/0048-tls-resource-endpoint.md) — accepted validated rustls client; system + embedder DER roots.
|
||||
- [ADR-0049: gzip compression](../adr/0049-compression-resource-operations.md) — accepted bounded gzip byte-list codec.
|
||||
- [Compute-machine RFC-0001](../MARQDO_COMPUTE_MACHINE_RFC_0001.md) and [core/stdlib RFC-0002](../MARQDO_COMPUTE_CORE_STDLIB_MIGRATION_RFC_0002.md) — design input.
|
||||
- [Architecture audit and refactor RFC](Marqdo_CLI_Latest_Architecture_Audit_and_Refactor_RFC.md) — review input for this migration.
|
||||
@@ -53,6 +53,7 @@ The implemented first slices of these RFCs are recorded in `CURRENT.md` and
|
||||
| `random.bytes` resource operation | [0046](../adr/0046-random-resource-operation.md) | Accepted (explicit `--allow-random`, project only) |
|
||||
| DNS/UDP/TCP-listener endpoints | [0047](../adr/0047-net-dns-udp-listener.md) | Accepted (project only, exact host grant, no TLS) |
|
||||
| TLS client endpoint | [0048](../adr/0048-tls-resource-endpoint.md) | Accepted (rustls, validated, project only) |
|
||||
| gzip compression operations | [0049](../adr/0049-compression-resource-operations.md) | Accepted (bounded byte-list gzip) |
|
||||
| Table physical storage (T1/T2/T3), strict stdin/stderr/file/network resources | — | **Not decided**; do not implement by implication |
|
||||
|
||||
## Evidence and status
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
# Evidence: `std:compress`
|
||||
|
||||
Date: 2026-11-21 (Asia/Shanghai)
|
||||
Source baseline: `ff3f19a2eaf9c2bd40a66335e682079b1d85dd9f`
|
||||
Repository: `marqdo-cli`
|
||||
Decision record: [ADR-0049](../adr/0049-compression-resource-operations.md)
|
||||
|
||||
## Implemented
|
||||
|
||||
`resource.request("compress.gzip", [text])` and
|
||||
`resource.request("compress.gunzip", [bytes])` use `flate2`/miniz_oxide:
|
||||
|
||||
- gzip: Text -> List<Int>, 8 MiB input cap, deterministic header.
|
||||
- gunzip: List<Int> -> Text, 8 MiB input/output caps; bad gzip/UTF-8/oversize
|
||||
output are recoverable `compress.invalid`/`compress.not_utf8`/
|
||||
`compress.too_large`.
|
||||
- Project-mode only; no new grant or builtin.
|
||||
|
||||
`stdlib/compress.mq.md` exposes `压缩`/`解压`.
|
||||
|
||||
## Tests
|
||||
|
||||
`stdlib/tests/compress.mq.md` round-trips `hello 世界`.
|
||||
`crates/marqdo-host/tests/resource_streams.rs` round-trips text and rejects
|
||||
bad gzip (33 host tests).
|
||||
|
||||
```text
|
||||
cargo fmt --all -- --check PASS
|
||||
cargo clippy --workspace --all-targets -- -D warnings PASS
|
||||
cargo test --workspace 490 passed, 0 failed, 2 ignored
|
||||
cargo test -p marqdo-host --test resource_streams 33 passed
|
||||
cargo test -p marqdo-cli --test stdlib_product 16 passed
|
||||
python3 tools/pack-stdlib.py PASS
|
||||
```
|
||||
|
||||
## Not covered
|
||||
|
||||
No streaming gzip, raw deflate, zstd/brotli, binary Memory output or
|
||||
decompression of untrusted data beyond the 8 MiB output cap.
|
||||
@@ -213,6 +213,8 @@ resource.request("fs.walk", [dir]) -> {ok:true, value:List<Text>}
|
||||
resource.request("clock.now", []) -> {ok:true, value:UnixMillis}
|
||||
resource.request("env.get", [name]) -> {ok:true, value:Text}
|
||||
resource.request("random.bytes", [count]) -> {ok:true, value:List<Int>}
|
||||
resource.request("compress.gzip", [text]) -> {ok:true, value:List<Int>}
|
||||
resource.request("compress.gunzip", [bytes]) -> {ok:true, value:Text}
|
||||
resource.request("process.run", [program, args])-> {ok:true, value:{status, stdout, stderr}}
|
||||
```
|
||||
|
||||
@@ -242,6 +244,9 @@ resource.request("process.run", [program, args])-> {ok:true, value:{status, stdo
|
||||
* `env.get` takes one exact variable name and requires an `--allow-env NAME`
|
||||
grant; un-granted names are `permission.denied`, missing names are recoverable
|
||||
`env.not_found` and non-UTF-8 values are `env.not_unicode` (ADR-0043).
|
||||
* `compress.gzip`/`compress.gunzip` codec UTF-8 Text through a byte List;
|
||||
input/output are capped at 8 MiB and bad gzip/UTF-8 is recoverable
|
||||
`compress.invalid`/`compress.not_utf8` (ADR-0049).
|
||||
* `random.bytes` takes an Int count in `1..=65536`, requires
|
||||
`--allow-random`, and returns a List of 0–255 OS entropy bytes (ADR-0046).
|
||||
* `process.run` takes an exact program path and a List of Text arguments,
|
||||
|
||||
+2
-1
@@ -17,6 +17,7 @@ module; a mismatch is a hard error.
|
||||
- `data/table.mq.md` — value-returning table select/filter/sort/append/set/join/group/GFM
|
||||
- `env.mq.md` — explicitly granted `env.get` names over `resource.request`
|
||||
- `process.mq.md` — explicitly granted `process.run` with timeout/output caps
|
||||
- `compress.mq.md` — deterministic gzip compress/decompress over byte lists
|
||||
- `random.mq.md` — explicitly granted OS entropy bytes/integers
|
||||
- `datetime.mq.md` — UTC ISO-8601 format/parse over Unix milliseconds (pure)
|
||||
- `clock.mq.md` — project-mode `clock.now` over `resource.request`
|
||||
@@ -24,7 +25,7 @@ module; a mismatch is a hard error.
|
||||
- `regex.mq.md` — `^ $ . * + ? [...]` matcher and search (no groups)
|
||||
- `net/http.mq.md` — HTTP/1.1 response parsing (headers/chunked) and request builder
|
||||
- `tests/` — product self-tests for every public module
|
||||
(`clock`, `console`, `csv`, `datetime`, `demo`, `env`, `format`, `fs`, `http`,
|
||||
(`clock`, `compress`, `console`, `csv`, `datetime`, `demo`, `env`, `format`, `fs`, `http`,
|
||||
`io`, `json`, `path`, `process`, `random`, `regex`, `stream`, `table`, `text`, `utf8`)
|
||||
|
||||
The digest is a SHA-256 over sorted `*.mq.md` relative paths, a NUL, file
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
## 压缩
|
||||
|
||||
`(文本)`
|
||||
|
||||
把 UTF-8 文本压缩为 gzip 字节列表(`List<Int>`,0–255)。输入上限
|
||||
8 MiB;结果确定(不写入时间戳/文件名)。
|
||||
|
||||
*resource.request("compress.gzip", [文本])*
|
||||
|
||||
## 解压
|
||||
|
||||
`(字节列表)`
|
||||
|
||||
解压 gzip 字节列表并校验 UTF-8。输出上限 8 MiB;坏 gzip 返回
|
||||
`compress.invalid`,非 UTF-8 返回 `compress.not_utf8`。
|
||||
|
||||
*resource.request("compress.gunzip", [字节列表])*
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "marqdo-stdlib",
|
||||
"version": "0.1.0",
|
||||
"digest": "sha256:171c0d31cab5ae70ce6b16fc4c1cf819ab5a8e1895a801d5b2286b642dee5866"
|
||||
"digest": "sha256:1e5087c05a3c1f5ce0581c834a061d12b88cc0e9eed098b766d4ff1a2ecf859e"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
import:
|
||||
compress: "std:compress"
|
||||
---
|
||||
|
||||
## main
|
||||
|
||||
**压缩结果 = compress.压缩("hello 世界")**
|
||||
|
||||
**解压结果 = compress.解压(压缩结果.value)**
|
||||
|
||||
*[压缩结果.ok, 长度(压缩结果.value) > 0, 解压结果.ok, 解压结果.value]*
|
||||
Reference in new issue
Block a user