T-202: M2.2t (retry of T-201) — tools/curate-etl: curate-macro CLI command (file mode) wiring the existing run_curate_macro into cli.rs + main.rs with parser tests and a binary end-to-end test (no new crates, no bench changes, no live Mongo)
This commit is contained in:
parent
ccb37b793b
commit
9279bb0f08
3 changed files with 519 additions and 0 deletions
|
|
@ -66,6 +66,7 @@ use crate::run_curate_fundamentals::{
|
||||||
};
|
};
|
||||||
use crate::run_curate_fx::{is_supported_te_symbol, CurateFx1dArgs, DEFAULT_TE_SYMBOL};
|
use crate::run_curate_fx::{is_supported_te_symbol, CurateFx1dArgs, DEFAULT_TE_SYMBOL};
|
||||||
use crate::run_curate_fx_1m::CurateFx1mArgs;
|
use crate::run_curate_fx_1m::CurateFx1mArgs;
|
||||||
|
use crate::run_curate_macro::CurateMacroArgs;
|
||||||
use crate::run_curate_posts::{
|
use crate::run_curate_posts::{
|
||||||
CuratePostsArgs, DEFAULT_MAPPING_SOURCE as DEFAULT_POSTS_MAPPING_SOURCE,
|
CuratePostsArgs, DEFAULT_MAPPING_SOURCE as DEFAULT_POSTS_MAPPING_SOURCE,
|
||||||
};
|
};
|
||||||
|
|
@ -97,6 +98,7 @@ pub enum CliAction {
|
||||||
CurateFx1m(CurateFx1mArgs),
|
CurateFx1m(CurateFx1mArgs),
|
||||||
CuratePosts(CuratePostsArgs),
|
CuratePosts(CuratePostsArgs),
|
||||||
CurateFundamentals(CurateFundamentalsArgs),
|
CurateFundamentals(CurateFundamentalsArgs),
|
||||||
|
CurateMacro(CurateMacroArgs),
|
||||||
SendIlp(SendIlpArgs),
|
SendIlp(SendIlpArgs),
|
||||||
BenchSplit(usize),
|
BenchSplit(usize),
|
||||||
BenchAdj(usize),
|
BenchAdj(usize),
|
||||||
|
|
@ -167,6 +169,8 @@ pub fn format_usage(name: &str, version: &str) -> String {
|
||||||
Curate ceoPosts from BSON + provider_mapping TSV into <out>/events/year=YYYY/part.parquet using a dedicated --out directory (--timestamp-unit has no default; defaults: --key-field {DEFAULT_POSTS_KEY_FIELD}, --spiel-id-field {DEFAULT_POSTS_SPIEL_ID_FIELD}, --timestamp-field {DEFAULT_POSTS_TIMESTAMP_FIELD}, --edited-field {DEFAULT_POSTS_EDITED_FIELD}, --bot-field {DEFAULT_POSTS_BOT_FIELD}, --user-id-field {DEFAULT_POSTS_USER_ID_FIELD}, --text-field {DEFAULT_POSTS_TEXT_FIELD}, --mapping-source {DEFAULT_POSTS_MAPPING_SOURCE})\n\
|
Curate ceoPosts from BSON + provider_mapping TSV into <out>/events/year=YYYY/part.parquet using a dedicated --out directory (--timestamp-unit has no default; defaults: --key-field {DEFAULT_POSTS_KEY_FIELD}, --spiel-id-field {DEFAULT_POSTS_SPIEL_ID_FIELD}, --timestamp-field {DEFAULT_POSTS_TIMESTAMP_FIELD}, --edited-field {DEFAULT_POSTS_EDITED_FIELD}, --bot-field {DEFAULT_POSTS_BOT_FIELD}, --user-id-field {DEFAULT_POSTS_USER_ID_FIELD}, --text-field {DEFAULT_POSTS_TEXT_FIELD}, --mapping-source {DEFAULT_POSTS_MAPPING_SOURCE})\n\
|
||||||
{name} curate-fundamentals --qm-financials <path> --qm-filings <path> --provider-mapping <path> --listing-venues <path> --out <dir> --currency-field <name> --filings-form-type-field <name> --k <N> (--fiscal-period <quarterly|annual> | [--quarterly-tokens <a,b,..>] [--annual-tokens <a,b,..>]) [--financials-key-field <name>] [--period-end-field <name>] [--report-date-field <name>] [--report-period-field <name>] [--revenue-field <path>] [--net-income-field <path>] [--operating-cash-flow-field <path>] [--total-assets-field <path>] [--total-equity-field <path>] [--shares-outstanding-field <path>] [--filings-key-field <name>] [--filings-timefiled-field <name>] [--filings-filing-id-field <name>] [--filings-url-field <name>] [--mapping-source <name>]\n\
|
{name} curate-fundamentals --qm-financials <path> --qm-filings <path> --provider-mapping <path> --listing-venues <path> --out <dir> --currency-field <name> --filings-form-type-field <name> --k <N> (--fiscal-period <quarterly|annual> | [--quarterly-tokens <a,b,..>] [--annual-tokens <a,b,..>]) [--financials-key-field <name>] [--period-end-field <name>] [--report-date-field <name>] [--report-period-field <name>] [--revenue-field <path>] [--net-income-field <path>] [--operating-cash-flow-field <path>] [--total-assets-field <path>] [--total-equity-field <path>] [--shares-outstanding-field <path>] [--filings-key-field <name>] [--filings-timefiled-field <name>] [--filings-filing-id-field <name>] [--filings-url-field <name>] [--mapping-source <name>]\n\
|
||||||
Curate point-in-time fundamentals from qmFinancials + qmFilings BSON + provider_mapping/listing_venues TSVs into fundamentals_pit/year=YYYY/part.parquet (file mode only; defaults: --financials-key-field {DEFAULT_QM_FINANCIALS_KEY_FIELD}, --period-end-field {DEFAULT_QM_FINANCIALS_PERIOD_END_FIELD}, --report-date-field {DEFAULT_QM_FINANCIALS_REPORT_DATE_FIELD}, --report-period-field {DEFAULT_QM_FINANCIALS_REPORT_PERIOD_FIELD}, --filings-key-field {DEFAULT_FILINGS_KEY_FIELD}, --filings-timefiled-field {DEFAULT_FILINGS_TIMEFILED_FIELD}, --mapping-source {DEFAULT_FUNDAMENTALS_MAPPING_SOURCE})\n\
|
Curate point-in-time fundamentals from qmFinancials + qmFilings BSON + provider_mapping/listing_venues TSVs into fundamentals_pit/year=YYYY/part.parquet (file mode only; defaults: --financials-key-field {DEFAULT_QM_FINANCIALS_KEY_FIELD}, --period-end-field {DEFAULT_QM_FINANCIALS_PERIOD_END_FIELD}, --report-date-field {DEFAULT_QM_FINANCIALS_REPORT_DATE_FIELD}, --report-period-field {DEFAULT_QM_FINANCIALS_REPORT_PERIOD_FIELD}, --filings-key-field {DEFAULT_FILINGS_KEY_FIELD}, --filings-timefiled-field {DEFAULT_FILINGS_TIMEFILED_FIELD}, --mapping-source {DEFAULT_FUNDAMENTALS_MAPPING_SOURCE})\n\
|
||||||
|
{name} curate-macro --te-data <path> --series-map <path> --out <dir>\n\
|
||||||
|
Curate macro regime series from a teData BSON dump + series-map TSV into <out>/macro/part.parquet (file mode only)\n\
|
||||||
{name} send-ilp --dir <dir> --prefix <bars_1m|bars_1m_qm|fx_1m> --addr <host:port>\n\
|
{name} send-ilp --dir <dir> --prefix <bars_1m|bars_1m_qm|fx_1m> --addr <host:port>\n\
|
||||||
Stream published ILP v2 shard files to an explicit QuestDB TCP endpoint (no default address; success means bytes were accepted by local sockets, not rows committed — verify row counts via PGWire; ILP v2 binary doubles over TCP on QuestDB 10.2.0 are unverified until the manual quant load check)\n\
|
Stream published ILP v2 shard files to an explicit QuestDB TCP endpoint (no default address; success means bytes were accepted by local sockets, not rows committed — verify row counts via PGWire; ILP v2 binary doubles over TCP on QuestDB 10.2.0 are unverified until the manual quant load check)\n\
|
||||||
{name} bench-split [rows] Run fixed-seed split lookup + un-adjust benchmark (default: {DEFAULT_BENCH_ROWS})\n\
|
{name} bench-split [rows] Run fixed-seed split lookup + un-adjust benchmark (default: {DEFAULT_BENCH_ROWS})\n\
|
||||||
|
|
@ -221,6 +225,7 @@ pub fn format_usage_stderr(name: &str) -> String {
|
||||||
{name} curate-fx-1m --eod-intraday <path> --out <dir> --shards <N>\n\
|
{name} curate-fx-1m --eod-intraday <path> --out <dir> --shards <N>\n\
|
||||||
{name} curate-posts --ceo-posts <path> --provider-mapping <path> --out <dir> --timestamp-unit <seconds|millis> [--key-field <name>] [--spiel-id-field <name>] [--timestamp-field <name>] [--edited-field <name>] [--bot-field <name>] [--user-id-field <name>] [--text-field <name>] [--mapping-source <name>]\n\
|
{name} curate-posts --ceo-posts <path> --provider-mapping <path> --out <dir> --timestamp-unit <seconds|millis> [--key-field <name>] [--spiel-id-field <name>] [--timestamp-field <name>] [--edited-field <name>] [--bot-field <name>] [--user-id-field <name>] [--text-field <name>] [--mapping-source <name>]\n\
|
||||||
{name} curate-fundamentals --qm-financials <path> --qm-filings <path> --provider-mapping <path> --listing-venues <path> --out <dir> --currency-field <name> --filings-form-type-field <name> --k <N> (--fiscal-period <quarterly|annual> | [--quarterly-tokens <a,b,..>] [--annual-tokens <a,b,..>]) [--financials-key-field <name>] [--period-end-field <name>] [--report-date-field <name>] [--report-period-field <name>] [--revenue-field <path>] [--net-income-field <path>] [--operating-cash-flow-field <path>] [--total-assets-field <path>] [--total-equity-field <path>] [--shares-outstanding-field <path>] [--filings-key-field <name>] [--filings-timefiled-field <name>] [--filings-filing-id-field <name>] [--filings-url-field <name>] [--mapping-source <name>]\n\
|
{name} curate-fundamentals --qm-financials <path> --qm-filings <path> --provider-mapping <path> --listing-venues <path> --out <dir> --currency-field <name> --filings-form-type-field <name> --k <N> (--fiscal-period <quarterly|annual> | [--quarterly-tokens <a,b,..>] [--annual-tokens <a,b,..>]) [--financials-key-field <name>] [--period-end-field <name>] [--report-date-field <name>] [--report-period-field <name>] [--revenue-field <path>] [--net-income-field <path>] [--operating-cash-flow-field <path>] [--total-assets-field <path>] [--total-equity-field <path>] [--shares-outstanding-field <path>] [--filings-key-field <name>] [--filings-timefiled-field <name>] [--filings-filing-id-field <name>] [--filings-url-field <name>] [--mapping-source <name>]\n\
|
||||||
|
{name} curate-macro --te-data <path> --series-map <path> --out <dir>\n\
|
||||||
{name} send-ilp --dir <dir> --prefix <bars_1m|bars_1m_qm|fx_1m> --addr <host:port>\n\
|
{name} send-ilp --dir <dir> --prefix <bars_1m|bars_1m_qm|fx_1m> --addr <host:port>\n\
|
||||||
{name} bench-split [rows]\n\
|
{name} bench-split [rows]\n\
|
||||||
{name} bench-adj [events]\n\
|
{name} bench-adj [events]\n\
|
||||||
|
|
@ -1626,6 +1631,63 @@ fn parse_curate_fundamentals_args_inner(args: &[&str]) -> Result<CliAction, Stri
|
||||||
Ok(CliAction::CurateFundamentals(parsed))
|
Ok(CliAction::CurateFundamentals(parsed))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_curate_macro_args(args: &[&str]) -> Result<CliAction, String> {
|
||||||
|
parse_curate_macro_args_inner(args).map_err(|e| sanitize_single_line(&e))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_curate_macro_args_inner(args: &[&str]) -> Result<CliAction, String> {
|
||||||
|
let mut te_data: Option<PathBuf> = None;
|
||||||
|
let mut series_map: Option<PathBuf> = None;
|
||||||
|
let mut out_dir: Option<PathBuf> = None;
|
||||||
|
|
||||||
|
let mut i = 0usize;
|
||||||
|
while i < args.len() {
|
||||||
|
let token = args[i];
|
||||||
|
if !token.starts_with("--") {
|
||||||
|
return Err(format!(
|
||||||
|
"unexpected positional argument '{token}' for curate-macro"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let flag_name = token.split_once('=').map_or(token, |(flag, _)| flag);
|
||||||
|
if !matches!(flag_name, "--te-data" | "--series-map" | "--out") {
|
||||||
|
return Err(format!("unknown flag '{flag_name}' for curate-macro"));
|
||||||
|
}
|
||||||
|
|
||||||
|
let (flag, value) = if let Some((flag, v)) = token.split_once('=') {
|
||||||
|
i += 1;
|
||||||
|
(flag, v)
|
||||||
|
} else {
|
||||||
|
let Some(&v) = args.get(i + 1) else {
|
||||||
|
return Err(format!("missing value for flag '{token}'"));
|
||||||
|
};
|
||||||
|
if v.starts_with("--") {
|
||||||
|
return Err(format!("missing value for flag '{token}'"));
|
||||||
|
}
|
||||||
|
i += 2;
|
||||||
|
(token, v)
|
||||||
|
};
|
||||||
|
|
||||||
|
match flag {
|
||||||
|
"--te-data" => set_path(&mut te_data, "--te-data", value)?,
|
||||||
|
"--series-map" => set_path(&mut series_map, "--series-map", value)?,
|
||||||
|
"--out" => set_path(&mut out_dir, "--out", value)?,
|
||||||
|
other => return Err(format!("unknown flag '{other}' for curate-macro")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let te_data = te_data.ok_or_else(|| "missing required flag '--te-data'".to_string())?;
|
||||||
|
let series_map =
|
||||||
|
series_map.ok_or_else(|| "missing required flag '--series-map'".to_string())?;
|
||||||
|
let out_dir = out_dir.ok_or_else(|| "missing required flag '--out'".to_string())?;
|
||||||
|
|
||||||
|
Ok(CliAction::CurateMacro(CurateMacroArgs {
|
||||||
|
te_data,
|
||||||
|
series_map,
|
||||||
|
out_dir,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_curate_events_args(args: &[&str]) -> Result<CliAction, String> {
|
fn parse_curate_events_args(args: &[&str]) -> Result<CliAction, String> {
|
||||||
let mut mongo = MongoFlagState::default();
|
let mut mongo = MongoFlagState::default();
|
||||||
let mut qm_filings: Option<PathBuf> = None;
|
let mut qm_filings: Option<PathBuf> = None;
|
||||||
|
|
@ -2247,6 +2309,7 @@ pub fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
||||||
["curate-fx-1m", rest @ ..] => parse_curate_fx_1m_args(rest),
|
["curate-fx-1m", rest @ ..] => parse_curate_fx_1m_args(rest),
|
||||||
["curate-posts", rest @ ..] => parse_curate_posts_args(rest),
|
["curate-posts", rest @ ..] => parse_curate_posts_args(rest),
|
||||||
["curate-fundamentals", rest @ ..] => parse_curate_fundamentals_args(rest),
|
["curate-fundamentals", rest @ ..] => parse_curate_fundamentals_args(rest),
|
||||||
|
["curate-macro", rest @ ..] => parse_curate_macro_args(rest),
|
||||||
["send-ilp", rest @ ..] => parse_send_ilp_args(rest),
|
["send-ilp", rest @ ..] => parse_send_ilp_args(rest),
|
||||||
["bench-split"] => Ok(CliAction::BenchSplit(DEFAULT_BENCH_ROWS)),
|
["bench-split"] => Ok(CliAction::BenchSplit(DEFAULT_BENCH_ROWS)),
|
||||||
["bench-split", raw] => match raw.parse::<usize>() {
|
["bench-split", raw] => match raw.parse::<usize>() {
|
||||||
|
|
@ -5687,6 +5750,208 @@ mod tests {
|
||||||
assert!(err.contains("bad\\nline\\rarg"), "{err:?}");
|
assert!(err.contains("bad\\nline\\rarg"), "{err:?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn curate_macro_parsing_validation_and_usage() {
|
||||||
|
let usage = format_usage("curate-etl", "0.1.0");
|
||||||
|
let stderr_usage = format_usage_stderr("curate-etl");
|
||||||
|
for text in [&usage, &stderr_usage] {
|
||||||
|
assert!(
|
||||||
|
text.contains("curate-macro --te-data <path> --series-map <path> --out <dir>"),
|
||||||
|
"{text}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
assert!(usage.contains("<out>/macro/part.parquet"), "{usage}");
|
||||||
|
assert!(usage.contains("file mode only"), "{usage}");
|
||||||
|
|
||||||
|
let expected = CliAction::CurateMacro(CurateMacroArgs {
|
||||||
|
te_data: PathBuf::from("teData.bson"),
|
||||||
|
series_map: PathBuf::from("macro_series_map.tsv"),
|
||||||
|
out_dir: PathBuf::from("macro_out"),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Happy path: space-separated flags
|
||||||
|
assert_eq!(
|
||||||
|
parse_args(&to_args(&[
|
||||||
|
"curate-macro",
|
||||||
|
"--te-data",
|
||||||
|
"teData.bson",
|
||||||
|
"--series-map",
|
||||||
|
"macro_series_map.tsv",
|
||||||
|
"--out",
|
||||||
|
"macro_out",
|
||||||
|
])),
|
||||||
|
Ok(expected.clone())
|
||||||
|
);
|
||||||
|
|
||||||
|
// Reordered flags with mixed `--flag value` and `--flag=value` forms
|
||||||
|
assert_eq!(
|
||||||
|
parse_args(&to_args(&[
|
||||||
|
"curate-macro",
|
||||||
|
"--out=macro_out",
|
||||||
|
"--te-data",
|
||||||
|
"teData.bson",
|
||||||
|
"--series-map=macro_series_map.tsv",
|
||||||
|
])),
|
||||||
|
Ok(expected.clone())
|
||||||
|
);
|
||||||
|
|
||||||
|
// All `--flag=value` form in another order
|
||||||
|
assert_eq!(
|
||||||
|
parse_args(&to_args(&[
|
||||||
|
"curate-macro",
|
||||||
|
"--series-map=macro_series_map.tsv",
|
||||||
|
"--out=macro_out",
|
||||||
|
"--te-data=teData.bson",
|
||||||
|
])),
|
||||||
|
Ok(expected)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Omission of each required flag
|
||||||
|
let required: [(&str, &str); 3] = [
|
||||||
|
("--te-data", "teData.bson"),
|
||||||
|
("--series-map", "macro_series_map.tsv"),
|
||||||
|
("--out", "macro_out"),
|
||||||
|
];
|
||||||
|
for omit in 0..required.len() {
|
||||||
|
let mut argv = vec!["curate-macro"];
|
||||||
|
for (idx, &(flag, val)) in required.iter().enumerate() {
|
||||||
|
if idx != omit {
|
||||||
|
argv.push(flag);
|
||||||
|
argv.push(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let err = parse_args(&to_args(&argv)).unwrap_err();
|
||||||
|
let missing_flag = required[omit].0;
|
||||||
|
assert_eq!(err, format!("missing required flag '{missing_flag}'"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Missing value at end or before another flag
|
||||||
|
for (args, expected_flag) in [
|
||||||
|
(&["curate-macro", "--te-data"][..], "--te-data"),
|
||||||
|
(&["curate-macro", "--series-map"][..], "--series-map"),
|
||||||
|
(&["curate-macro", "--out"][..], "--out"),
|
||||||
|
(
|
||||||
|
&["curate-macro", "--te-data", "--out", "macro_out"][..],
|
||||||
|
"--te-data",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
&[
|
||||||
|
"curate-macro",
|
||||||
|
"--series-map",
|
||||||
|
"--te-data",
|
||||||
|
"teData.bson",
|
||||||
|
][..],
|
||||||
|
"--series-map",
|
||||||
|
),
|
||||||
|
] {
|
||||||
|
let err = parse_args(&to_args(args)).unwrap_err();
|
||||||
|
assert_eq!(err, format!("missing value for flag '{expected_flag}'"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Empty values in both `--flag=` and `--flag ""` forms
|
||||||
|
for (args, expected_flag) in [
|
||||||
|
(&["curate-macro", "--te-data="][..], "--te-data"),
|
||||||
|
(&["curate-macro", "--series-map="][..], "--series-map"),
|
||||||
|
(&["curate-macro", "--out="][..], "--out"),
|
||||||
|
(&["curate-macro", "--te-data", ""][..], "--te-data"),
|
||||||
|
(&["curate-macro", "--series-map", ""][..], "--series-map"),
|
||||||
|
(&["curate-macro", "--out", ""][..], "--out"),
|
||||||
|
] {
|
||||||
|
let err = parse_args(&to_args(args)).unwrap_err();
|
||||||
|
assert_eq!(err, format!("empty value for flag '{expected_flag}'"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Duplicate flags across forms
|
||||||
|
for (dup_flag, args) in [
|
||||||
|
(
|
||||||
|
"--te-data",
|
||||||
|
&[
|
||||||
|
"curate-macro",
|
||||||
|
"--te-data",
|
||||||
|
"a.bson",
|
||||||
|
"--te-data=b.bson",
|
||||||
|
"--series-map",
|
||||||
|
"map.tsv",
|
||||||
|
"--out",
|
||||||
|
"out",
|
||||||
|
][..],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"--series-map",
|
||||||
|
&[
|
||||||
|
"curate-macro",
|
||||||
|
"--series-map=a.tsv",
|
||||||
|
"--series-map",
|
||||||
|
"b.tsv",
|
||||||
|
"--te-data",
|
||||||
|
"te.bson",
|
||||||
|
"--out",
|
||||||
|
"out",
|
||||||
|
][..],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"--out",
|
||||||
|
&[
|
||||||
|
"curate-macro",
|
||||||
|
"--out",
|
||||||
|
"out1",
|
||||||
|
"--out=out2",
|
||||||
|
"--te-data",
|
||||||
|
"te.bson",
|
||||||
|
"--series-map",
|
||||||
|
"map.tsv",
|
||||||
|
][..],
|
||||||
|
),
|
||||||
|
] {
|
||||||
|
let err = parse_args(&to_args(args)).unwrap_err();
|
||||||
|
assert_eq!(err, format!("duplicate flag '{dup_flag}'"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unknown flags including --mongo-uri and --from-mongo (rejected before consuming a value)
|
||||||
|
for (args, expected_flag) in [
|
||||||
|
(&["curate-macro", "--bogus", "1"][..], "--bogus"),
|
||||||
|
(&["curate-macro", "--from-mongo"][..], "--from-mongo"),
|
||||||
|
(
|
||||||
|
&["curate-macro", "--from-mongo", "--out", "o"][..],
|
||||||
|
"--from-mongo",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
&["curate-macro", "--from-mongo=true"][..],
|
||||||
|
"--from-mongo",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
&["curate-macro", "--mongo-uri", "mongodb://host"][..],
|
||||||
|
"--mongo-uri",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
&["curate-macro", "--mongo-uri-env=MONGODB_READ_URI"][..],
|
||||||
|
"--mongo-uri-env",
|
||||||
|
),
|
||||||
|
] {
|
||||||
|
let err = parse_args(&to_args(args)).unwrap_err();
|
||||||
|
assert_eq!(
|
||||||
|
err,
|
||||||
|
format!("unknown flag '{expected_flag}' for curate-macro")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unexpected positional argument rejected
|
||||||
|
let err = parse_args(&to_args(&["curate-macro", "extra"])).unwrap_err();
|
||||||
|
assert_eq!(err, "unexpected positional argument 'extra' for curate-macro");
|
||||||
|
|
||||||
|
// CR/LF in arguments are escaped to a single diagnostic line
|
||||||
|
let err = parse_args(&to_args(&["curate-macro", "bad\nline\rarg"])).unwrap_err();
|
||||||
|
assert!(!err.contains('\n') && !err.contains('\r'), "{err:?}");
|
||||||
|
assert_eq!(
|
||||||
|
err,
|
||||||
|
"unexpected positional argument 'bad\\nline\\rarg' for curate-macro"
|
||||||
|
);
|
||||||
|
|
||||||
|
let err = parse_args(&to_args(&["curate-macro", "--bad\nflag\r=1"])).unwrap_err();
|
||||||
|
assert!(!err.contains('\n') && !err.contains('\r'), "{err:?}");
|
||||||
|
assert_eq!(err, "unknown flag '--bad\\nflag\\r' for curate-macro");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_send_ilp_valid_space_and_equals_forms_and_all_allowed_prefixes() {
|
fn parse_send_ilp_valid_space_and_equals_forms_and_all_allowed_prefixes() {
|
||||||
for prefix in ["bars_1m", "bars_1m_qm", "fx_1m"] {
|
for prefix in ["bars_1m", "bars_1m_qm", "fx_1m"] {
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ use curate_etl::run_curate_fundamentals::{
|
||||||
};
|
};
|
||||||
use curate_etl::run_curate_fx::{format_curate_fx_report, run_curate_fx_1d};
|
use curate_etl::run_curate_fx::{format_curate_fx_report, run_curate_fx_1d};
|
||||||
use curate_etl::run_curate_fx_1m::{format_curate_fx_1m_report, run_curate_fx_1m};
|
use curate_etl::run_curate_fx_1m::{format_curate_fx_1m_report, run_curate_fx_1m};
|
||||||
|
use curate_etl::run_curate_macro::{format_curate_macro_report, run_curate_macro};
|
||||||
use curate_etl::run_curate_posts::{format_curate_posts_report, run_curate_posts};
|
use curate_etl::run_curate_posts::{format_curate_posts_report, run_curate_posts};
|
||||||
use curate_etl::run_curate_shorts::{format_curate_shorts_report, run_curate_shorts};
|
use curate_etl::run_curate_shorts::{format_curate_shorts_report, run_curate_shorts};
|
||||||
use curate_etl::run_mongo::{
|
use curate_etl::run_mongo::{
|
||||||
|
|
@ -246,6 +247,16 @@ fn main() -> ExitCode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(CliAction::CurateMacro(curate_args)) => match run_curate_macro(&curate_args) {
|
||||||
|
Ok(report) => {
|
||||||
|
println!("{}", format_curate_macro_report(&report));
|
||||||
|
ExitCode::SUCCESS
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("error: {err}");
|
||||||
|
ExitCode::FAILURE
|
||||||
|
}
|
||||||
|
},
|
||||||
Ok(CliAction::SendIlp(send_args)) => match run_send_ilp(&send_args) {
|
Ok(CliAction::SendIlp(send_args)) => match run_send_ilp(&send_args) {
|
||||||
Ok(report) => {
|
Ok(report) => {
|
||||||
println!("{}", format_ilp_send_report(&report));
|
println!("{}", format_ilp_send_report(&report));
|
||||||
|
|
|
||||||
243
tools/curate-etl/tests/curate_macro.rs
Normal file
243
tools/curate-etl/tests/curate_macro.rs
Normal file
|
|
@ -0,0 +1,243 @@
|
||||||
|
//! End-to-end tests for the file-mode `curate-macro` CLI.
|
||||||
|
|
||||||
|
use std::fs::{self, File};
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::process::Command;
|
||||||
|
use std::sync::atomic::{AtomicU64, Ordering};
|
||||||
|
|
||||||
|
use bson::raw::{cstr, RawArrayBuf, RawDocumentBuf};
|
||||||
|
use bson::DateTime;
|
||||||
|
use curate_etl::macro_series::{MACRO_KNOWN_AT_SOURCE, POLICY_RATE_LAG_DAYS};
|
||||||
|
use curate_etl::run_curate_macro::{
|
||||||
|
format_curate_macro_report, run_curate_macro, CurateMacroArgs, MACRO_SERIES_MAP_HEADER,
|
||||||
|
};
|
||||||
|
use curate_etl::split::ymd_to_epoch_days;
|
||||||
|
use parquet::file::reader::{FileReader, SerializedFileReader};
|
||||||
|
use parquet::record::{Field, Row};
|
||||||
|
|
||||||
|
const MICROS_PER_DAY: i64 = 86_400_000_000;
|
||||||
|
|
||||||
|
static TEMP_SEQ: AtomicU64 = AtomicU64::new(0);
|
||||||
|
|
||||||
|
struct TempDir(PathBuf);
|
||||||
|
|
||||||
|
impl TempDir {
|
||||||
|
fn new(label: &str) -> Self {
|
||||||
|
let seq = TEMP_SEQ.fetch_add(1, Ordering::Relaxed);
|
||||||
|
let path = std::env::temp_dir().join(format!(
|
||||||
|
"curate-macro-cli-{label}-{}-{seq}",
|
||||||
|
std::process::id()
|
||||||
|
));
|
||||||
|
let _ = fs::remove_dir_all(&path);
|
||||||
|
fs::create_dir_all(&path).expect("create isolated test directory");
|
||||||
|
Self(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for TempDir {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
let _ = fs::remove_dir_all(&self.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cli() -> Command {
|
||||||
|
let mut command = Command::new(env!("CARGO_BIN_EXE_curate-etl"));
|
||||||
|
command.arg("curate-macro");
|
||||||
|
command
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_point_doc(d: &str, v: f64) -> RawDocumentBuf {
|
||||||
|
let mut pt = RawDocumentBuf::new();
|
||||||
|
pt.append(cstr!("d"), d);
|
||||||
|
pt.append(cstr!("v"), v);
|
||||||
|
pt
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_te_data_doc(
|
||||||
|
te_symbol: &str,
|
||||||
|
country: &str,
|
||||||
|
category: &str,
|
||||||
|
data_points: &[(&str, f64)],
|
||||||
|
forecast_points: &[(&str, f64)],
|
||||||
|
) -> RawDocumentBuf {
|
||||||
|
let mut data_arr = RawArrayBuf::new();
|
||||||
|
for &(d, v) in data_points {
|
||||||
|
data_arr.push(make_point_doc(d, v));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut forecast_arr = RawArrayBuf::new();
|
||||||
|
for &(d, v) in forecast_points {
|
||||||
|
forecast_arr.push(make_point_doc(d, v));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut doc = RawDocumentBuf::new();
|
||||||
|
doc.append(cstr!("teSymbol"), te_symbol);
|
||||||
|
doc.append(cstr!("name"), format!("{country} {category}"));
|
||||||
|
doc.append(cstr!("unit"), "percent");
|
||||||
|
doc.append(cstr!("source"), "TradingEconomics");
|
||||||
|
doc.append(cstr!("frequency"), "Monthly");
|
||||||
|
doc.append(cstr!("country"), country);
|
||||||
|
doc.append(cstr!("category"), category);
|
||||||
|
doc.append(cstr!("data"), data_arr);
|
||||||
|
doc.append(cstr!("forecast"), forecast_arr);
|
||||||
|
doc.append(
|
||||||
|
cstr!("lastUpdated"),
|
||||||
|
DateTime::from_millis(1_710_000_000_000),
|
||||||
|
);
|
||||||
|
doc.append(cstr!("createdAt"), DateTime::from_millis(1_700_000_000_000));
|
||||||
|
doc
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_policy_rate_fixture(dir: &Path) -> (PathBuf, PathBuf) {
|
||||||
|
let te_data_path = dir.join("teData.bson");
|
||||||
|
let series_map_path = dir.join("macro_series_map.tsv");
|
||||||
|
|
||||||
|
let doc = make_te_data_doc(
|
||||||
|
"FDTR",
|
||||||
|
"United States",
|
||||||
|
"Interest Rate",
|
||||||
|
&[("2024-03-20", 5.5)],
|
||||||
|
&[("2025-01-01", 99.0)],
|
||||||
|
);
|
||||||
|
fs::write(&te_data_path, doc.as_bytes()).expect("write teData.bson");
|
||||||
|
|
||||||
|
let tsv = format!(
|
||||||
|
"{MACRO_SERIES_MAP_HEADER}\nFDTR\tUnited States\tInterest Rate\tUS\tfed_funds_rate\tpolicy_rate\n"
|
||||||
|
);
|
||||||
|
fs::write(&series_map_path, tsv).expect("write macro_series_map.tsv");
|
||||||
|
|
||||||
|
(te_data_path, series_map_path)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn col<'a>(row: &'a Row, name: &str) -> &'a Field {
|
||||||
|
row.get_column_iter()
|
||||||
|
.find(|(col_name, _)| col_name.as_str() == name)
|
||||||
|
.unwrap_or_else(|| panic!("missing Parquet column '{name}'"))
|
||||||
|
.1
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn cli_publishes_runner_equivalent_macro_parquet_and_excludes_forecast_sentinel() {
|
||||||
|
let dir = TempDir::new("e2e");
|
||||||
|
let (te_data_path, series_map_path) = write_policy_rate_fixture(&dir.0);
|
||||||
|
|
||||||
|
let baseline_out = dir.0.join("baseline_out");
|
||||||
|
let baseline_report = run_curate_macro(&CurateMacroArgs {
|
||||||
|
te_data: te_data_path.clone(),
|
||||||
|
series_map: series_map_path.clone(),
|
||||||
|
out_dir: baseline_out.clone(),
|
||||||
|
})
|
||||||
|
.expect("run library baseline");
|
||||||
|
let expected_stdout = format!("{}\n", format_curate_macro_report(&baseline_report));
|
||||||
|
|
||||||
|
let cli_out = dir.0.join("cli_out");
|
||||||
|
let result = cli()
|
||||||
|
.current_dir(&dir.0)
|
||||||
|
.args([
|
||||||
|
"--te-data",
|
||||||
|
"teData.bson",
|
||||||
|
"--series-map=macro_series_map.tsv",
|
||||||
|
"--out",
|
||||||
|
"cli_out",
|
||||||
|
])
|
||||||
|
.output()
|
||||||
|
.expect("run curate-macro");
|
||||||
|
|
||||||
|
assert!(result.status.success(), "{result:?}");
|
||||||
|
assert!(
|
||||||
|
result.stderr.is_empty(),
|
||||||
|
"unexpected stderr: {}",
|
||||||
|
String::from_utf8_lossy(&result.stderr)
|
||||||
|
);
|
||||||
|
let stdout = String::from_utf8(result.stdout).expect("utf-8 stdout");
|
||||||
|
assert_eq!(stdout, expected_stdout);
|
||||||
|
|
||||||
|
let cli_parquet = cli_out.join("macro/part.parquet");
|
||||||
|
let baseline_parquet = baseline_out.join("macro/part.parquet");
|
||||||
|
assert!(cli_parquet.is_file(), "expected {}", cli_parquet.display());
|
||||||
|
assert_eq!(
|
||||||
|
fs::read(&cli_parquet).expect("read cli parquet"),
|
||||||
|
fs::read(&baseline_parquet).expect("read baseline parquet"),
|
||||||
|
"CLI Parquet output must match library runner bytes"
|
||||||
|
);
|
||||||
|
|
||||||
|
let reader = SerializedFileReader::new(File::open(&cli_parquet).expect("open parquet"))
|
||||||
|
.expect("open parquet reader");
|
||||||
|
let rows: Vec<Row> = reader
|
||||||
|
.get_row_iter(None)
|
||||||
|
.expect("row iter")
|
||||||
|
.map(|row| row.expect("decode row"))
|
||||||
|
.collect();
|
||||||
|
assert_eq!(
|
||||||
|
rows.len(),
|
||||||
|
1,
|
||||||
|
"expected exactly one mapped policy-rate row and no forecast sentinel row"
|
||||||
|
);
|
||||||
|
|
||||||
|
let expected_period_date = ymd_to_epoch_days(2024, 3, 20).expect("valid date");
|
||||||
|
let expected_known_at = i64::from(expected_period_date + POLICY_RATE_LAG_DAYS) * MICROS_PER_DAY;
|
||||||
|
assert_eq!(POLICY_RATE_LAG_DAYS, 1);
|
||||||
|
|
||||||
|
let row = &rows[0];
|
||||||
|
assert_eq!(col(row, "country_iso"), &Field::Str("US".to_string()));
|
||||||
|
assert_eq!(
|
||||||
|
col(row, "indicator"),
|
||||||
|
&Field::Str("fed_funds_rate".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(col(row, "period_date"), &Field::Date(expected_period_date));
|
||||||
|
assert_eq!(
|
||||||
|
col(row, "known_at"),
|
||||||
|
&Field::TimestampMicros(expected_known_at)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
col(row, "known_at_source"),
|
||||||
|
&Field::Str(MACRO_KNOWN_AT_SOURCE.to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(col(row, "value"), &Field::Double(5.5));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn cli_missing_te_data_exits_nonzero_with_single_line_escaped_error_and_no_parquet() {
|
||||||
|
let dir = TempDir::new("missing-te-data");
|
||||||
|
let (_, series_map_path) = write_policy_rate_fixture(&dir.0);
|
||||||
|
|
||||||
|
let missing_path = dir.0.join("missing\nte_data\r.bson");
|
||||||
|
let cli_out = dir.0.join("cli_out");
|
||||||
|
|
||||||
|
let result = cli()
|
||||||
|
.arg("--te-data")
|
||||||
|
.arg(&missing_path)
|
||||||
|
.arg("--series-map")
|
||||||
|
.arg(&series_map_path)
|
||||||
|
.arg("--out")
|
||||||
|
.arg(&cli_out)
|
||||||
|
.output()
|
||||||
|
.expect("run curate-macro");
|
||||||
|
|
||||||
|
assert_eq!(result.status.code(), Some(1), "{result:?}");
|
||||||
|
assert!(
|
||||||
|
result.stdout.is_empty(),
|
||||||
|
"unexpected stdout: {}",
|
||||||
|
String::from_utf8_lossy(&result.stdout)
|
||||||
|
);
|
||||||
|
|
||||||
|
let stderr = String::from_utf8(result.stderr).expect("utf-8 stderr");
|
||||||
|
assert_eq!(
|
||||||
|
stderr.lines().count(),
|
||||||
|
1,
|
||||||
|
"expected 1 stderr line: {stderr:?}"
|
||||||
|
);
|
||||||
|
assert!(!stderr.contains('\r'), "stderr must escape CR: {stderr:?}");
|
||||||
|
assert!(stderr.starts_with("error: "), "{stderr:?}");
|
||||||
|
assert!(stderr.contains("te-data"), "{stderr:?}");
|
||||||
|
assert!(
|
||||||
|
stderr.contains("missing\\nte_data\\r.bson"),
|
||||||
|
"expected escaped path in stderr: {stderr:?}"
|
||||||
|
);
|
||||||
|
assert!(!stderr.contains("Usage:"), "{stderr:?}");
|
||||||
|
assert!(
|
||||||
|
!cli_out.join("macro/part.parquet").exists(),
|
||||||
|
"macro/part.parquet must not be written on failure"
|
||||||
|
);
|
||||||
|
assert!(!cli_out.exists(), "out dir must not be created on failure");
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue