feat(domain): R4.5e wasm proof export, resources per page, N-1 and TS-engine read-back, cost comparison
export_pdf_for_test on the proofs build (ExportInput JSON + base64 rasters): the 14 O2 runs give the native digests through wasm; the frozen O11 scanner reads every R4 PDF and the N-1 Zod readers accept its envelope; a stripped R4 PDF answers attachment_stripped; the TypeScript engine reads the R4 PDFs back to the R3 outcome; E2 size ≤ R3 + 5 %. Page resources list the images the page draws (listing every embed cost 9 MB on CAP). Node, stub rasters, TS → Rust: demo 198 → 36 ms, L 772 → 57 ms, CAP 5.7 s → 0.22 s; files 236 KB, 386 KB, 1.6 MB against 243 KB, 463 KB, 2.2 MB. Module with the writer linked (proofs build): 531.6 KB gzip; shipped unchanged at 426 KB until R4.6 links it.
This commit is contained in:
1 parent
4d45de5745
commit
50c8fe0b33
21 files changed
+485
-19
No files matched your search
@@ -15,11 +15,13 @@ path = "src/lib.rs"
|
||||
default = []
|
||||
# The R0 trap proofs (panic_for_test, recurse_for_test): built for the proofs, never for the
|
||||
# module the application ships (scripts/wasm-build.sh passes it until R2 wires the real loader).
|
||||
proofs = []
|
||||
proofs = ["dep:serde_json"]
|
||||
|
||||
[dependencies]
|
||||
faunosteo-core = { path = "../core", features = ["pdf-read", "pdf-write"] }
|
||||
wasm-bindgen.workspace = true
|
||||
# The proofs build reads the test rasters' JSON (never shipped).
|
||||
serde_json = { workspace = true, optional = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -124,6 +124,54 @@ pub fn import_pdf_unbounded_for_test(bundle: &str, bytes: &[u8]) -> Result<Strin
|
||||
})
|
||||
}
|
||||
|
||||
/// R4.5 proof: one export through the module from an `ExportInput` JSON and the rasters
|
||||
/// as `{ "headerLogo"|"footerLogo"|"poweredBy"|"partner": base64|null, "views": [{
|
||||
/// "observationId", "viewId", "png": base64 }] }`, so the wasm output can be compared to the
|
||||
/// native digests and the module's size with the writer linked be measured. Never shipped:
|
||||
/// the application's export goes through the R4.6 session.
|
||||
#[cfg(feature = "proofs")]
|
||||
#[wasm_bindgen]
|
||||
pub fn export_pdf_for_test(input: &str, rasters: &str) -> Result<Vec<u8>, JsError> {
|
||||
use faunosteo_core::domain::js::parse_json;
|
||||
use faunosteo_core::pdf::write::export::export_pdf;
|
||||
use faunosteo_core::pdf::write::input::{ExportInput, Rasters};
|
||||
use faunosteo_core::pdf::write::layout::png::base64_bytes;
|
||||
let input: ExportInput = parse_json(input)
|
||||
.ok()
|
||||
.and_then(|v| serde_json::from_value(v).ok())
|
||||
.ok_or_else(|| JsError::new("invalid input"))?;
|
||||
let spec = parse_json(rasters).map_err(|e| JsError::new(&e.to_string()))?;
|
||||
let slot = |key: &str| {
|
||||
spec.get(key)
|
||||
.and_then(|v| v.as_str())
|
||||
.and_then(base64_bytes)
|
||||
};
|
||||
let mut set = Rasters {
|
||||
header_logo: slot("headerLogo"),
|
||||
footer_logo: slot("footerLogo"),
|
||||
powered_by: slot("poweredBy"),
|
||||
partner: slot("partner"),
|
||||
views: Default::default(),
|
||||
};
|
||||
for view in spec
|
||||
.get("views")
|
||||
.and_then(|v| v.as_array())
|
||||
.into_iter()
|
||||
.flatten()
|
||||
{
|
||||
let key = (
|
||||
view["observationId"].as_str().unwrap_or("").to_owned(),
|
||||
view["viewId"].as_str().unwrap_or("").to_owned(),
|
||||
);
|
||||
if let Some(png) = view["png"].as_str().and_then(base64_bytes) {
|
||||
set.views.insert(key, png);
|
||||
}
|
||||
}
|
||||
export_pdf(input, &set)
|
||||
.map(|result| result.pdf)
|
||||
.map_err(|error| JsError::new(&format!("{}: {}", error.kind.as_str(), error.detail)))
|
||||
}
|
||||
|
||||
/// R4.2e proof: the linear memory ceiling (`--max-memory`, `.cargo/config.toml`). Allocates
|
||||
/// and touches `mib` MiB; past the ceiling the allocation fails and Rust aborts, a trap.
|
||||
#[cfg(feature = "proofs")]
|
||||
|
||||
Reference in new issue
Block a user