T-179: tests

This commit is contained in:
Studio 2026-12-02 18:27:11 -05:00
parent 958cefb40c
commit 6138230252

View file

@ -1869,3 +1869,130 @@ fn qa_missing_intraday_input_fails_before_creating_out_dir() {
assert!(err.source().is_some());
assert!(!out_dir.exists());
}
/// QA (T-179): a truncated `qmSplits` tail is a fatal reference-load error in file mode. The run
/// must return `LoadReference(BsonStream { label: "qm-splits" })` and publish nothing: no final
/// `bars_1m.shard-*.ilp` and no staging file, and a pre-existing unrelated file is untouched.
#[test]
fn qa_truncated_qm_splits_fails_closed_in_file_mode_without_outputs() {
let dir = TempDirGuard::new("bars1m-qa-trunc-splits");
let mapping_path = write_mapping_tsv(
dir.path(),
&["eod\tAAA.US\t2020-01-01\t\t11", "qm\tAAA\t2020-01-01\t\t11"],
);
let mut splits_bytes = concat_docs(&[
make_split_doc("AAA", "2025-05-06", 1.0, 2.0),
make_split_doc("AAA", "2025-07-01", 1.0, 3.0),
]);
splits_bytes.truncate(splits_bytes.len() - 5);
let splits_path = dir.path().join("qmSplits.bson");
fs::write(&splits_path, &splits_bytes).unwrap();
let intraday_path = dir.path().join("eodIntraday1M.bson");
fs::write(
&intraday_path,
concat_docs(&[make_intraday_doc(
"AAA.US",
et_ts_sec(2025, 5, 5, 10, 0),
10.0,
10.5,
9.5,
10.2,
100.0,
)]),
)
.unwrap();
let out_dir = dir.path().join("out");
fs::create_dir_all(&out_dir).unwrap();
fs::write(out_dir.join("keep.txt"), b"keep").unwrap();
let args = make_args(
mapping_path,
splits_path,
intraday_path,
out_dir.clone(),
2,
1,
BsonStreamOptions::default(),
);
let err = run_curate_bars_1m(&args).unwrap_err();
assert!(
matches!(
err,
RunCurateBars1mError::LoadReference(RunCurateBarsError::BsonStream {
label: "qm-splits",
..
})
),
"{err:?}"
);
assert!(err.source().is_some());
assert_eq!(list_dir_names(&out_dir), vec!["keep.txt"]);
assert_eq!(fs::read(out_dir.join("keep.txt")).unwrap(), b"keep");
}
/// QA (T-179): listing-keyed splits apply to every `"eod"` alias of the same listing. Two EOD
/// tickers mapped to listing 77 over consecutive ranges both receive the 2:1 split (ex-date
/// 2025-06-02); an unrelated listing without splits is untouched.
#[test]
fn qa_listing_split_applies_to_all_eod_aliases_of_the_listing() {
let dir = TempDirGuard::new("bars1m-qa-aliases");
let mapping_path = write_mapping_tsv(
dir.path(),
&[
"eod\tOLD.US\t2020-01-01\t2025-05-15\t77",
"eod\tNEW.US\t2025-05-16\t\t77",
"qm\tNEWQ\t2020-01-01\t\t77",
"eod\tOTH.US\t2020-01-01\t\t88",
],
);
let splits_bytes = concat_docs(&[make_split_doc("NEWQ", "2025-06-02", 1.0, 2.0)]);
let intraday_bytes = concat_docs(&[
make_intraday_doc("OLD.US", et_ts_sec(2025, 5, 14, 10, 0), 10.0, 11.0, 9.0, 10.5, 200.0),
make_intraday_doc("NEW.US", et_ts_sec(2025, 5, 20, 10, 0), 12.0, 13.0, 11.0, 12.5, 400.0),
make_intraday_doc("NEW.US", et_ts_sec(2025, 6, 2, 10, 0), 6.0, 6.5, 5.5, 6.25, 800.0),
make_intraday_doc("OTH.US", et_ts_sec(2025, 5, 20, 10, 0), 20.0, 21.0, 19.0, 20.5, 50.0),
// OLD.US after its mapping range closed: unmapped, never mis-attributed.
make_intraday_doc("OLD.US", et_ts_sec(2025, 5, 20, 10, 0), 1.0, 1.0, 1.0, 1.0, 1.0),
]);
let mut sink = Vec::new();
let writer = IlpShardedWriter::new(vec![&mut sink], IlpWriterOptions::default()).unwrap();
let args = make_args(
mapping_path,
dir.path().join("qmSplits.bson"),
dir.path().join("eodIntraday1M.bson"),
dir.path().join("out"),
1,
42,
BsonStreamOptions::default(),
);
let report = run_curate_bars_1m_with_readers(
&args,
Cursor::new(&intraday_bytes),
Cursor::new(&splits_bytes),
writer,
)
.expect("alias run should succeed");
assert_report_conservation(&report);
assert_eq!(report.split_rekey.splits_applied, 1);
assert_eq!(report.curate_stats.dropped_unmapped, 1);
assert_eq!(report.rows_written, 4);
let rows = decode_ilp_bars_1m(&sink);
let get = |id: i32, ts: i64| {
rows.iter()
.find(|r| r.listing_id == id && r.ts == ts * 1_000_000)
.expect("row")
.clone()
};
let old = get(77, et_ts_sec(2025, 5, 14, 10, 0));
assert_eq!((old.close, old.volume), (21.0, 100.0));
let new_pre = get(77, et_ts_sec(2025, 5, 20, 10, 0));
assert_eq!((new_pre.close, new_pre.volume), (25.0, 200.0));
let new_ex = get(77, et_ts_sec(2025, 6, 2, 10, 0));
assert_eq!((new_ex.close, new_ex.volume), (6.25, 800.0));
let oth = get(88, et_ts_sec(2025, 5, 20, 10, 0));
assert_eq!((oth.close, oth.volume), (20.5, 50.0));
}