From 054dd9df54239ecaf5b5270953d27561db855fb7 Mon Sep 17 00:00:00 2001 From: hermes Date: Mon, 19 Oct 2026 10:37:57 +0000 Subject: [PATCH] test(cli): a non-IDX quote is never behind the IDX session From Pullfrog's review of 834e47b: nothing exercised the `.JK` guard on quotes. The cache-entry test now also reads AAPL.US with an old as_of and expects behind_session false. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01V3syn2fN2LNo5pvTSqc6eh --- crates/idx-cli/tests/cli.rs | 52 +++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/crates/idx-cli/tests/cli.rs b/crates/idx-cli/tests/cli.rs index f2bc244..abdade7 100644 --- a/crates/idx-cli/tests/cli.rs +++ b/crates/idx-cli/tests/cli.rs @@ -2438,29 +2438,35 @@ fn msn_screen_flags_idx_rows_behind_the_session() { #[test] fn quote_read_from_a_0_3_3_cache_entry_is_behind_the_session() { - let root = test_env_dir("quote-behind-session"); - let mut warm = mock_bin_with_root(&root); - run_success_json(warm.args(["-o", "json", "stocks", "quote", "BBCA"])); - let entry = fs::read_dir(root.join("cache")) - .unwrap() - .flat_map(|dir| fs::read_dir(dir.unwrap().path()).unwrap()) - .flat_map(|bucket| fs::read_dir(bucket.unwrap().path()).unwrap()) - .map(|file| file.unwrap().path()) - .find(|path| path.ends_with("BBCA.JK.json")) - .expect("cached quote"); - // 0.3.3 wrote quotes without the field; this one last traded long ago. - let mut cached: serde_json::Value = - serde_json::from_str(&fs::read_to_string(&entry).unwrap()).unwrap(); - let data = cached["data"].as_object_mut().unwrap(); - data.remove("behind_session") - .expect("field is cached unmarked"); - data.insert("as_of".into(), "2026-01-02T16:15:00+07:00".into()); - fs::write(&entry, cached.to_string()).unwrap(); - let mut offline = mock_bin_with_root(&root); - let quotes = - run_success_json(offline.args(["--offline", "-o", "json", "stocks", "quote", "BBCA"])); - assert_eq!(quotes[0]["behind_session"], true); - fs::remove_dir_all(root).unwrap(); + // IDX's session rule says nothing about other exchanges. + for (symbol, file, behind) in [ + ("BBCA", "BBCA.JK.json", true), + ("AAPL.US", "AAPL.US.json", false), + ] { + let root = test_env_dir(&format!("quote-behind-session-{symbol}")); + let mut warm = mock_bin_with_root(&root); + run_success_json(warm.args(["-o", "json", "stocks", "quote", symbol])); + let entry = fs::read_dir(root.join("cache")) + .unwrap() + .flat_map(|dir| fs::read_dir(dir.unwrap().path()).unwrap()) + .flat_map(|bucket| fs::read_dir(bucket.unwrap().path()).unwrap()) + .map(|file| file.unwrap().path()) + .find(|path| path.ends_with(file)) + .expect("cached quote"); + // 0.3.3 wrote quotes without the field; this one last traded long ago. + let mut cached: serde_json::Value = + serde_json::from_str(&fs::read_to_string(&entry).unwrap()).unwrap(); + let data = cached["data"].as_object_mut().unwrap(); + data.remove("behind_session") + .expect("field is cached unmarked"); + data.insert("as_of".into(), "2026-01-02T16:15:00+07:00".into()); + fs::write(&entry, cached.to_string()).unwrap(); + let mut offline = mock_bin_with_root(&root); + let quotes = + run_success_json(offline.args(["--offline", "-o", "json", "stocks", "quote", symbol])); + assert_eq!(quotes[0]["behind_session"], behind, "{symbol}"); + fs::remove_dir_all(root).unwrap(); + } } #[test]