Skip to content

Commit 4eeee5d

Browse files
committed
test(codec): ignore the zstd encoder tests on wasm32 rather than abort the suite
`nodedb-codec` gates its codec by target already: C libzstd off wasm, ruzstd on it (`Cargo.toml:31-36`), and `compress_native`'s wasm arm is an explicit stub returning `CompressFailed` (`src/zstd_codec.rs:312-320`). The eight tests that call `encode`/`encode_with_level` therefore panic, and on `wasm32-wasip1` a panic aborts the process: the binary dies at the first one and reports nothing after it. The stub is a design choice rather than a missing dependency: ruzstd 0.9 ships an encoder (`ruzstd::encoding`) this crate has not adopted, and the C library would need a C-to-WASM toolchain. Wiring up either one changes what the wasm build does and is a change of its own; this commit only stops the absent encoder from killing the suite. No fallback exists in this crate — `pipeline` propagates `CompressFailed` for `ColumnCodec::Zstd`. The stub's own comments said it was a fallback that encodes "a minimal Zstd frame", which it never did; they now describe the stub. They are gated with `#[cfg_attr(target_arch = "wasm32", ignore = "…")]` rather than `#[cfg(not(target_arch = "wasm32"))]`. The attribute keeps them compiled and listed by `--list` on that target, so the gap is visible in the run instead of absent from it, and they keep running natively. Red arm, with the four tests other changes own skipped: $ cargo test --profile ci --target wasm32-wasip1 -p nodedb-codec -- <4 skips> test zstd_codec::tests::better_ratio_than_lz4 ... Error: failed to run main module exit 134 Green arm, same command: test result: ok. 252 passed; 0 failed; 8 ignored; 0 measured; 4 filtered out Each ignored test prints its reason: test zstd_codec::tests::empty_data ... ignored, nodedb-codec has no wasm encoder: encode() returns CompressFailed Native is unchanged at 263 passed, 0 failed, 0 ignored. The module's other four tests stay live on both targets: three are decode-side, and `streaming_input_limit_precedes_buffer_growth` drives the encoder's declared-limit check, which rejects before any encoder work. Why an in-source ignore and not a `--skip` list in the consumer: the gap is categorical — the target has no encoder at all, not a threshold that moves — and a named skip in someone else's workflow records it as a number rather than as a property of this crate. fmt clean; clippy clean for this crate on native and on `wasm32-wasip1`.
1 parent 1ff3551 commit 4eeee5d

1 file changed

Lines changed: 44 additions & 8 deletions

File tree

‎nodedb-codec/src/zstd_codec.rs‎

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,17 +303,16 @@ fn decompress_native(frame: &[u8], expected_size: usize) -> Result<Vec<u8>, Code
303303
Ok(output)
304304
}
305305

306-
// WASM: use ruzstd for decompression. Compression on WASM uses a simple
307-
// fallback (ruzstd is decode-only; if full Zstd encoding is needed on WASM,
308-
// we'd need the zstd crate compiled to WASM via C-to-WASM toolchain).
309-
// For Pattern C (Lite-local), cold compression happens infrequently, so
310-
// we fall back to LZ4 encoding on WASM and only support Zstd decoding.
306+
// WASM: decoding uses ruzstd. Encoding returns `CompressFailed`: the C library is
307+
// not built for this target and ruzstd's encoder is not adopted here, so a wasm
308+
// caller that needs compression picks another codec. Adopting `ruzstd::encoding`
309+
// is a change of its own; getting the C library there would need a C-to-WASM
310+
// toolchain.
311311

312312
#[cfg(target_arch = "wasm32")]
313313
fn compress_native(_data: &[u8], _level: i32) -> Result<Vec<u8>, CodecError> {
314-
// ruzstd is decode-only. On WASM, we encode using a minimal Zstd frame.
315-
// For production WASM builds that need Zstd encoding, compile the C zstd
316-
// library to WASM. For now, return an error directing callers to use LZ4.
314+
// No encoder is wired up here. This is a stub, not a fallback: it encodes
315+
// nothing, and the error below is what every caller sees.
317316
Err(CodecError::CompressFailed {
318317
detail: "Zstd encoding not available on WASM — use LZ4 codec instead".into(),
319318
})
@@ -431,14 +430,27 @@ impl ZstdDecoder {
431430
mod tests {
432431
use super::*;
433432

433+
// The eight encoder tests are ignored on `wasm32` rather than removed:
434+
// `compress_native` returns `CompressFailed` there by design, so `encode`
435+
// cannot succeed. `cfg_attr(ignore)` keeps them running natively and visible
436+
// in `--list` on wasm; the tests that do not encode stay live on both.
437+
434438
#[test]
439+
#[cfg_attr(
440+
target_arch = "wasm32",
441+
ignore = "nodedb-codec has no wasm encoder: encode() returns CompressFailed"
442+
)]
435443
fn empty_data() {
436444
let encoded = encode(&[]).unwrap();
437445
let decoded = decode(&encoded).unwrap();
438446
assert!(decoded.is_empty());
439447
}
440448

441449
#[test]
450+
#[cfg_attr(
451+
target_arch = "wasm32",
452+
ignore = "nodedb-codec has no wasm encoder: encode() returns CompressFailed"
453+
)]
442454
fn small_data_roundtrip() {
443455
let data = b"hello world, zstd compression test";
444456
let encoded = encode(data).unwrap();
@@ -447,6 +459,10 @@ mod tests {
447459
}
448460

449461
#[test]
462+
#[cfg_attr(
463+
target_arch = "wasm32",
464+
ignore = "nodedb-codec has no wasm encoder: encode() returns CompressFailed"
465+
)]
450466
fn large_data_roundtrip() {
451467
let line = "2024-01-15 ERROR database connection timeout host=db-prod-01 retry=3\n";
452468
let data: Vec<u8> = line.as_bytes().repeat(1000);
@@ -462,6 +478,10 @@ mod tests {
462478
}
463479

464480
#[test]
481+
#[cfg_attr(
482+
target_arch = "wasm32",
483+
ignore = "nodedb-codec has no wasm encoder: encode() returns CompressFailed"
484+
)]
465485
fn high_compression_level() {
466486
let data: Vec<u8> = (0..10_000).map(|i| (i % 256) as u8).collect();
467487
let default_encoded = encode(&data).unwrap();
@@ -476,6 +496,10 @@ mod tests {
476496
}
477497

478498
#[test]
499+
#[cfg_attr(
500+
target_arch = "wasm32",
501+
ignore = "nodedb-codec has no wasm encoder: encode() returns CompressFailed"
502+
)]
479503
fn header_metadata() {
480504
let data = vec![42u8; 1000];
481505
let encoded = encode_with_level(&data, 7).unwrap();
@@ -485,6 +509,10 @@ mod tests {
485509
}
486510

487511
#[test]
512+
#[cfg_attr(
513+
target_arch = "wasm32",
514+
ignore = "nodedb-codec has no wasm encoder: encode() returns CompressFailed"
515+
)]
488516
fn better_ratio_than_lz4() {
489517
// Structured data where Zstd should beat LZ4.
490518
let mut data = Vec::new();
@@ -552,6 +580,10 @@ mod tests {
552580
}
553581

554582
#[test]
583+
#[cfg_attr(
584+
target_arch = "wasm32",
585+
ignore = "nodedb-codec has no wasm encoder: encode() returns CompressFailed"
586+
)]
555587
fn streaming_encoder() {
556588
let parts: Vec<&[u8]> = vec![b"part one ", b"part two ", b"part three"];
557589
let full: Vec<u8> = parts.iter().flat_map(|p| p.iter().copied()).collect();
@@ -585,6 +617,10 @@ mod tests {
585617
}
586618

587619
#[test]
620+
#[cfg_attr(
621+
target_arch = "wasm32",
622+
ignore = "nodedb-codec has no wasm encoder: encode() returns CompressFailed"
623+
)]
588624
fn level_clamping() {
589625
let data = b"test data for clamping";
590626
// Level 0 → clamped to 1, level 99 → clamped to 22.

0 commit comments

Comments
 (0)