T-113: M1.2ac — tools/curate-etl: fourth runnable command curate-fx-1d (concatenated-BSON eodPrices CAD.FOREX + teMarketData USDCAD files → fx_1d/part.parquet) with a zero-copy teMarketData decoder, end-to-end tests and local benchmark (no new crates, no MongoDB connection)
This commit is contained in:
parent
234573a19e
commit
cffcbe23a6
11 changed files with 3636 additions and 5 deletions
|
|
@ -1056,3 +1056,153 @@ fn bench_curate_corporate_actions_cmd_small_run_is_deterministic_and_reports_sta
|
|||
assert_eq!(field(&text_a, "checksum="), field(&text_b, "checksum="));
|
||||
assert_eq!(field(&text_a, "rows_out="), field(&text_b, "rows_out="));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn curate_fx_1d_cli_flag_errors_exit_nonzero_with_usage() {
|
||||
for args in [
|
||||
&["curate-fx-1d"][..],
|
||||
&[
|
||||
"curate-fx-1d",
|
||||
"--eod-prices",
|
||||
"e.bson",
|
||||
"--te-market-data",
|
||||
"t.bson",
|
||||
][..],
|
||||
&[
|
||||
"curate-fx-1d",
|
||||
"--eod-prices",
|
||||
"e.bson",
|
||||
"--te-market-data",
|
||||
"t.bson",
|
||||
"--te-symbol",
|
||||
"USDCAD",
|
||||
"--te-symbol=USDCAD",
|
||||
"--out",
|
||||
"out",
|
||||
][..],
|
||||
&[
|
||||
"curate-fx-1d",
|
||||
"--eod-prices",
|
||||
"e.bson",
|
||||
"--te-market-data",
|
||||
"t.bson",
|
||||
"--out",
|
||||
"out",
|
||||
"--unknown",
|
||||
"1",
|
||||
][..],
|
||||
] {
|
||||
let out = run(args);
|
||||
assert!(!out.status.success(), "{args:?} should fail");
|
||||
assert_eq!(out.status.code(), Some(1), "{args:?}");
|
||||
assert!(stdout(&out).is_empty(), "{args:?} wrote to stdout");
|
||||
let err = stderr(&out);
|
||||
assert!(err.contains("error:"), "{args:?}: {err}");
|
||||
assert!(err.contains("Usage:"), "{args:?}: {err}");
|
||||
assert!(err.contains("curate-fx-1d"), "{args:?}: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn curate_fx_1d_cli_happy_path_and_single_line_runtime_error() {
|
||||
use bson::raw::{cstr, RawArrayBuf, RawDocumentBuf};
|
||||
|
||||
let dir = CliTempDir::new("fx-1d-cli");
|
||||
let eod_path = dir.path.join("eodPrices.bson");
|
||||
let te_path = dir.path.join("teMarketData.bson");
|
||||
let empty_eod_path = dir.path.join("empty_eod.bson");
|
||||
let empty_te_path = dir.path.join("empty_te.bson");
|
||||
let out_dir = dir.path.join("out");
|
||||
let out_fail = dir.path.join("out_fail");
|
||||
|
||||
let mut eod_doc = RawDocumentBuf::new();
|
||||
eod_doc.append(cstr!("eodSearchCode"), "CAD.FOREX");
|
||||
eod_doc.append(cstr!("date"), "2025-01-02");
|
||||
eod_doc.append(cstr!("open"), 1.430_f64);
|
||||
eod_doc.append(cstr!("high"), 1.440_f64);
|
||||
eod_doc.append(cstr!("low"), 1.425_f64);
|
||||
eod_doc.append(cstr!("close"), 1.435_f64);
|
||||
eod_doc.append(cstr!("volume"), 0.0_f64);
|
||||
write_file(&eod_path, eod_doc.as_bytes());
|
||||
|
||||
let mut daily = RawArrayBuf::new();
|
||||
let mut pt = RawDocumentBuf::new();
|
||||
pt.append(cstr!("t"), 1_767_312_000_000_i64); // 2026-01-02 UTC in ms
|
||||
pt.append(cstr!("o"), 1.380_f64);
|
||||
pt.append(cstr!("h"), 1.390_f64);
|
||||
pt.append(cstr!("l"), 1.375_f64);
|
||||
pt.append(cstr!("c"), 1.385_f64);
|
||||
daily.push(pt);
|
||||
let mut te_doc = RawDocumentBuf::new();
|
||||
te_doc.append(cstr!("teSymbol"), "USDCAD");
|
||||
te_doc.append(cstr!("daily"), daily);
|
||||
write_file(&te_path, te_doc.as_bytes());
|
||||
|
||||
write_file(&empty_eod_path, b"");
|
||||
write_file(&empty_te_path, b"");
|
||||
|
||||
// 1. Happy path
|
||||
let res = run(&[
|
||||
"curate-fx-1d",
|
||||
"--eod-prices",
|
||||
eod_path.to_str().unwrap(),
|
||||
"--te-market-data",
|
||||
te_path.to_str().unwrap(),
|
||||
"--out",
|
||||
out_dir.to_str().unwrap(),
|
||||
]);
|
||||
assert!(res.status.success(), "{}", stderr(&res));
|
||||
assert!(stderr(&res).is_empty(), "{}", stderr(&res));
|
||||
let text = stdout(&res);
|
||||
assert!(text.contains("curate-etl curate-fx-1d"), "{text}");
|
||||
assert!(text.contains("rows_written=2"), "{text}");
|
||||
assert!(out_dir.join("fx_1d/part.parquet").is_file());
|
||||
|
||||
// 2. Runtime error (zero decoded bars) -> single-line stderr, no Usage, no output
|
||||
let res_fail = run(&[
|
||||
"curate-fx-1d",
|
||||
"--eod-prices",
|
||||
empty_eod_path.to_str().unwrap(),
|
||||
"--te-market-data",
|
||||
empty_te_path.to_str().unwrap(),
|
||||
"--out",
|
||||
out_fail.to_str().unwrap(),
|
||||
]);
|
||||
assert!(!res_fail.status.success());
|
||||
assert_eq!(res_fail.status.code(), Some(1));
|
||||
assert!(stdout(&res_fail).is_empty());
|
||||
let err = stderr(&res_fail);
|
||||
assert_eq!(err.lines().count(), 1, "expected single-line stderr: {err}");
|
||||
assert!(err.contains("no FX bars decoded"), "{err}");
|
||||
assert!(!err.contains("Usage:"), "{err}");
|
||||
assert!(!out_fail.join("fx_1d").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bench_curate_fx_cmd_small_run_is_deterministic_and_reports_stages() {
|
||||
let a = run(&["bench-curate-fx-cmd", "1000"]);
|
||||
let b = run(&["bench-curate-fx-cmd", "1000"]);
|
||||
assert!(a.status.success(), "{}", stderr(&a));
|
||||
assert!(b.status.success(), "{}", stderr(&b));
|
||||
assert!(stderr(&a).is_empty(), "{}", stderr(&a));
|
||||
assert!(stderr(&b).is_empty(), "{}", stderr(&b));
|
||||
|
||||
let text_a = stdout(&a);
|
||||
let text_b = stdout(&b);
|
||||
assert!(text_a.contains("curate-etl bench-curate-fx-cmd"), "{text_a}");
|
||||
assert!(text_a.contains("rows=1000 "), "{text_a}");
|
||||
assert!(text_a.contains("decode:"), "{text_a}");
|
||||
assert!(text_a.contains("curate:"), "{text_a}");
|
||||
assert!(text_a.contains("write:"), "{text_a}");
|
||||
assert!(text_a.contains("total:"), "{text_a}");
|
||||
assert!(text_a.contains("overlap:"), "{text_a}");
|
||||
assert!(text_a.contains("checksum=0x"), "{text_a}");
|
||||
|
||||
let field = |s: &str, prefix: &str| {
|
||||
s.split_whitespace()
|
||||
.find(|t| t.starts_with(prefix))
|
||||
.map(str::to_owned)
|
||||
};
|
||||
assert_eq!(field(&text_a, "checksum="), field(&text_b, "checksum="));
|
||||
assert_eq!(field(&text_a, "rows_out="), field(&text_b, "rows_out="));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue