T-114: M1.2ad — tools/curate-etl: fifth runnable command curate-shorts (concatenated-BSON ceoShorts file + provider_mapping TSV → shorts/part.parquet) with a zero-copy ceoShorts decoder, end-to-end tests and local benchmark (no new crates, no MongoDB connection)
This commit is contained in:
parent
d4671f39d5
commit
0de120e7c8
6 changed files with 493 additions and 73 deletions
|
|
@ -400,4 +400,88 @@ fn failure_modes_exit_nonzero_without_usage_and_preserve_preexisting_parquet() {
|
|||
assert!(out.contains("dropped_unmapped=1"), "{out}");
|
||||
assert!(out.contains("rows_written=0"), "{out}");
|
||||
assert_eq!(fs::read(&sentinel_path).unwrap(), sentinel);
|
||||
|
||||
// 5. Corrupt UTF-8 in an unused text field of an otherwise valid, mapped report ->
|
||||
// must fail closed with non-zero exit and preserve pre-existing shorts/part.parquet.
|
||||
let mut unused_corrupt_doc = RawDocumentBuf::new();
|
||||
unused_corrupt_doc.append(cstr!("symbol"), "RY");
|
||||
unused_corrupt_doc.append(
|
||||
cstr!("timestamp"),
|
||||
BsonDateTime::from_millis(i64::from(day(2024, 3, 15)) * 86_400_000),
|
||||
);
|
||||
unused_corrupt_doc.append(cstr!("sharesShort"), 100.0_f64);
|
||||
unused_corrupt_doc.append(cstr!("unusedNote"), "CORRUPT");
|
||||
let mut unused_corrupt_bytes = unused_corrupt_doc.into_bytes();
|
||||
let pos = unused_corrupt_bytes
|
||||
.windows(7)
|
||||
.position(|w| w == b"CORRUPT")
|
||||
.expect("locate CORRUPT marker");
|
||||
unused_corrupt_bytes[pos] = 0xff;
|
||||
unused_corrupt_bytes[pos + 1] = 0xfe;
|
||||
|
||||
let unused_corrupt_bson = dir.path.join("unused_corrupt.bson");
|
||||
write_bytes(&unused_corrupt_bson, &unused_corrupt_bytes);
|
||||
let res = run(&[
|
||||
"curate-shorts",
|
||||
"--ceo-shorts",
|
||||
unused_corrupt_bson.to_str().unwrap(),
|
||||
"--provider-mapping",
|
||||
valid_map.to_str().unwrap(),
|
||||
"--out",
|
||||
out_dir.to_str().unwrap(),
|
||||
"--shares-short-field",
|
||||
"sharesShort",
|
||||
]);
|
||||
assert!(!res.status.success(), "corrupt unused string must fail closed");
|
||||
assert!(stdout(&res).is_empty());
|
||||
let err = stderr(&res);
|
||||
assert_eq!(err.lines().count(), 1, "single-line stderr expected: {err}");
|
||||
assert!(!err.contains("Usage:"), "{err}");
|
||||
assert_eq!(
|
||||
fs::read(&sentinel_path).unwrap(),
|
||||
sentinel,
|
||||
"existing shorts/part.parquet must remain byte-identical"
|
||||
);
|
||||
|
||||
// 6. Malformed element inside an unused embedded document -> must also fail closed.
|
||||
let mut inner = RawDocumentBuf::new();
|
||||
inner.append(cstr!("k"), 7_i32);
|
||||
let mut nested_corrupt_doc = RawDocumentBuf::new();
|
||||
nested_corrupt_doc.append(cstr!("symbol"), "RY");
|
||||
nested_corrupt_doc.append(
|
||||
cstr!("timestamp"),
|
||||
BsonDateTime::from_millis(i64::from(day(2024, 3, 15)) * 86_400_000),
|
||||
);
|
||||
nested_corrupt_doc.append(cstr!("sharesShort"), 100.0_f64);
|
||||
nested_corrupt_doc.append(cstr!("meta"), inner);
|
||||
let mut nested_corrupt_bytes = nested_corrupt_doc.into_bytes();
|
||||
let k_pos = nested_corrupt_bytes
|
||||
.windows(3)
|
||||
.position(|w| w == [0x10, b'k', 0x00])
|
||||
.expect("locate nested int32 element");
|
||||
nested_corrupt_bytes[k_pos] = 0x7e;
|
||||
|
||||
let nested_corrupt_bson = dir.path.join("nested_corrupt.bson");
|
||||
write_bytes(&nested_corrupt_bson, &nested_corrupt_bytes);
|
||||
let res = run(&[
|
||||
"curate-shorts",
|
||||
"--ceo-shorts",
|
||||
nested_corrupt_bson.to_str().unwrap(),
|
||||
"--provider-mapping",
|
||||
valid_map.to_str().unwrap(),
|
||||
"--out",
|
||||
out_dir.to_str().unwrap(),
|
||||
"--shares-short-field",
|
||||
"sharesShort",
|
||||
]);
|
||||
assert!(!res.status.success(), "corrupt embedded doc must fail closed");
|
||||
assert!(stdout(&res).is_empty());
|
||||
let err = stderr(&res);
|
||||
assert_eq!(err.lines().count(), 1, "single-line stderr expected: {err}");
|
||||
assert!(!err.contains("Usage:"), "{err}");
|
||||
assert_eq!(
|
||||
fs::read(&sentinel_path).unwrap(),
|
||||
sentinel,
|
||||
"existing shorts/part.parquet must remain byte-identical"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue