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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V3syn2fN2LNo5pvTSqc6eh
This commit is contained in:
hermes 2026-10-19 10:37:57 +00:00
commit 054dd9df54

View file

@ -2438,29 +2438,35 @@ fn msn_screen_flags_idx_rows_behind_the_session() {
#[test] #[test]
fn quote_read_from_a_0_3_3_cache_entry_is_behind_the_session() { fn quote_read_from_a_0_3_3_cache_entry_is_behind_the_session() {
let root = test_env_dir("quote-behind-session"); // IDX's session rule says nothing about other exchanges.
let mut warm = mock_bin_with_root(&root); for (symbol, file, behind) in [
run_success_json(warm.args(["-o", "json", "stocks", "quote", "BBCA"])); ("BBCA", "BBCA.JK.json", true),
let entry = fs::read_dir(root.join("cache")) ("AAPL.US", "AAPL.US.json", false),
.unwrap() ] {
.flat_map(|dir| fs::read_dir(dir.unwrap().path()).unwrap()) let root = test_env_dir(&format!("quote-behind-session-{symbol}"));
.flat_map(|bucket| fs::read_dir(bucket.unwrap().path()).unwrap()) let mut warm = mock_bin_with_root(&root);
.map(|file| file.unwrap().path()) run_success_json(warm.args(["-o", "json", "stocks", "quote", symbol]));
.find(|path| path.ends_with("BBCA.JK.json")) let entry = fs::read_dir(root.join("cache"))
.expect("cached quote"); .unwrap()
// 0.3.3 wrote quotes without the field; this one last traded long ago. .flat_map(|dir| fs::read_dir(dir.unwrap().path()).unwrap())
let mut cached: serde_json::Value = .flat_map(|bucket| fs::read_dir(bucket.unwrap().path()).unwrap())
serde_json::from_str(&fs::read_to_string(&entry).unwrap()).unwrap(); .map(|file| file.unwrap().path())
let data = cached["data"].as_object_mut().unwrap(); .find(|path| path.ends_with(file))
data.remove("behind_session") .expect("cached quote");
.expect("field is cached unmarked"); // 0.3.3 wrote quotes without the field; this one last traded long ago.
data.insert("as_of".into(), "2026-01-02T16:15:00+07:00".into()); let mut cached: serde_json::Value =
fs::write(&entry, cached.to_string()).unwrap(); serde_json::from_str(&fs::read_to_string(&entry).unwrap()).unwrap();
let mut offline = mock_bin_with_root(&root); let data = cached["data"].as_object_mut().unwrap();
let quotes = data.remove("behind_session")
run_success_json(offline.args(["--offline", "-o", "json", "stocks", "quote", "BBCA"])); .expect("field is cached unmarked");
assert_eq!(quotes[0]["behind_session"], true); data.insert("as_of".into(), "2026-01-02T16:15:00+07:00".into());
fs::remove_dir_all(root).unwrap(); 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] #[test]