use std::collections::HashMap; use std::process::{Command, Output}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::{Arc, Mutex}; use serde_json::{Value, json}; use wiremock::matchers::{method, path}; use wiremock::{Mock, MockServer, Request, ResponseTemplate}; const SEVEN_POSTS: &str = include_str!("fixtures/seven_posts.json"); const SEVEN_ENGAGEMENT: &str = include_str!("fixtures/seven_engagement.json"); const FORK_POSTS: &str = include_str!("fixtures/fork_posts.json"); const DELETED_POSTS: &str = include_str!("fixtures/deleted_posts.json"); const REPLY_START_POSTS: &str = include_str!("fixtures/reply_start_posts.json"); const THRESHOLD_POSTS: &str = include_str!("fixtures/threshold_posts.json"); const EXPORT_POSTS: &str = include_str!("fixtures/export_posts.json"); const PUBLISHED_DOCUMENTS: &str = include_str!("fixtures/published_documents.json"); const EMPTY_DOCUMENTS: &str = include_str!("fixtures/empty_documents.json"); const BOB_POSTS: &str = include_str!("fixtures/bob_posts.json"); const FOLLOWS: &str = include_str!("fixtures/follows.json"); const PAGINATION_PAGE_1: &str = include_str!("fixtures/pagination_page1.json"); const PAGINATION_PAGE_2: &str = include_str!("fixtures/pagination_page2.json"); const QUOTE_VIEWS: &str = include_str!("fixtures/quote_views.json"); const PUBLICATION_POSTS: &str = include_str!("fixtures/publication_posts.json"); const PUBLICATION_DOCUMENTS: &str = include_str!("fixtures/publication_documents.json"); const LABELLED_POSTS: &str = include_str!("fixtures/labelled_posts.json"); const ALICE_DID: &str = "did:plc:alice"; const BOB_DID: &str = "did:plc:bob"; const CAROL_DID: &str = "did:plc:carol"; const DAVE_DID: &str = "did:plc:dave"; const PUBLICATION_URI: &str = "at://did:plc:alice/site.standard.publication/pub1"; #[derive(Clone)] struct Page { cursor: Option, body: Value, } #[derive(Clone)] struct Account { did: String, handle: String, profile: Value, posts: Vec, documents: Value, records: HashMap, } impl Account { fn single_page(did: &str, handle: &str, posts: &str, documents: &str) -> Self { Self { did: did.to_string(), handle: handle.to_string(), profile: json!({ "displayName": handle, "avatar": { "$type": "blob", "ref": { "$link": "bafyavatar" }, "mimeType": "image/jpeg", "size": 1, }, }), posts: vec![Page { cursor: None, body: serde_json::from_str(posts).expect("valid posts fixture"), }], documents: serde_json::from_str(documents).expect("valid documents fixture"), records: HashMap::new(), } } fn with_record(mut self, collection: &str, rkey: &str, value: Value) -> Self { self.records.insert(format!("{collection}/{rkey}"), value); self } fn opted_out(mut self) -> Self { self.profile = json!({ "labels": { "$type": "com.atproto.label.defs#selfLabels", "values": [{ "val": "!no-unauthenticated" }] } }); self } } #[derive(Default)] struct Counters { posts_pages: AtomicUsize, posts_429_remaining: AtomicUsize, posts_repos: Mutex>, } struct World { accounts: Vec, follows: Value, engagement: HashMap, views: HashMap, counters: Arc, } impl World { fn new(accounts: Vec, counters: Arc) -> Self { Self { accounts, follows: serde_json::from_str(FOLLOWS).expect("valid follows fixture"), engagement: HashMap::new(), views: HashMap::new(), counters, } } } fn views_from_fixture(fixture: &str) -> HashMap { let value: Value = serde_json::from_str(fixture).expect("valid views fixture"); value["posts"] .as_array() .expect("posts array") .iter() .map(|post| (post["uri"].as_str().expect("uri").to_string(), post.clone())) .collect() } fn engagement_from_fixture(fixture: &str) -> HashMap { let value: Value = serde_json::from_str(fixture).expect("valid engagement fixture"); value["posts"] .as_array() .expect("posts array") .iter() .map(|post| { ( post["uri"].as_str().expect("uri").to_string(), ( post["likeCount"].as_i64().unwrap_or(0), post["repostCount"].as_i64().unwrap_or(0), post["quoteCount"].as_i64().unwrap_or(0), post["replyCount"].as_i64().unwrap_or(0), ), ) }) .collect() } async fn mount(server: &MockServer, world: World) { let world = Arc::new(world); let accounts = world.accounts.clone(); let resolve_world = world.clone(); Mock::given(method("GET")) .and(path("/xrpc/com.atproto.identity.resolveHandle")) .respond_with(move |request: &Request| { let handle = query(request, "handle").unwrap_or_default(); match resolve_world .accounts .iter() .find(|account| account.handle == handle) { Some(account) => json_response(json!({ "did": account.did })), None => ResponseTemplate::new(404), } }) .mount(server) .await; for account in &accounts { let document = json!({ "id": account.did, "alsoKnownAs": [format!("at://{}", account.handle)], "service": [{ "id": "#atproto_pds", "type": "AtprotoPersonalDataServer", "serviceEndpoint": server.uri(), }], }); Mock::given(method("GET")) .and(path(format!("/{}", account.did))) .respond_with(move |_: &Request| json_response(document.clone())) .mount(server) .await; } let records_world = world.clone(); Mock::given(method("GET")) .and(path("/xrpc/com.atproto.repo.listRecords")) .respond_with(move |request: &Request| { let repo = query(request, "repo").unwrap_or_default(); let collection = query(request, "collection").unwrap_or_default(); let cursor = query(request, "cursor"); let Some(account) = records_world .accounts .iter() .find(|account| account.did == repo) else { return ResponseTemplate::new(404); }; match collection.as_str() { "app.bsky.feed.post" => { records_world .counters .posts_pages .fetch_add(1, Ordering::SeqCst); records_world .counters .posts_repos .lock() .expect("counter lock") .push(repo.clone()); let limited = records_world .counters .posts_429_remaining .try_update(Ordering::SeqCst, Ordering::SeqCst, |remaining| { remaining.checked_sub(1) }) .unwrap_or(0); if limited > 0 { return ResponseTemplate::new(429).insert_header("Retry-After", "0"); } match account.posts.iter().find(|page| page.cursor == cursor) { Some(page) => json_response(page.body.clone()), None => ResponseTemplate::new(404), } } "site.standard.document" => json_response(account.documents.clone()), _ => ResponseTemplate::new(404), } }) .mount(server) .await; let record_world = world.clone(); Mock::given(method("GET")) .and(path("/xrpc/com.atproto.repo.getRecord")) .respond_with(move |request: &Request| { let repo = query(request, "repo").unwrap_or_default(); let collection = query(request, "collection").unwrap_or_default(); let rkey = query(request, "rkey").unwrap_or_default(); let Some(account) = record_world .accounts .iter() .find(|account| account.did == repo) else { return ResponseTemplate::new(404); }; if collection == "app.bsky.actor.profile" && rkey == "self" { return json_response(json!({ "uri": format!("at://{repo}/app.bsky.actor.profile/self"), "cid": "bafyprofile", "value": account.profile, })); } match account.records.get(&format!("{collection}/{rkey}")) { Some(value) => json_response(json!({ "uri": format!("at://{repo}/{collection}/{rkey}"), "cid": "bafyrecord", "value": value, })), None => ResponseTemplate::new(404), } }) .mount(server) .await; let posts_world = world.clone(); Mock::given(method("GET")) .and(path("/xrpc/app.bsky.feed.getPosts")) .respond_with(move |request: &Request| { let uris: Vec = request .url .query_pairs() .filter(|(key, _)| key == "uris") .map(|(_, value)| value.into_owned()) .collect(); let posts: Vec = uris .iter() .map(|uri| { let (likes, reposts, quotes, replies) = posts_world .engagement .get(uri) .copied() .unwrap_or((0, 0, 0, 0)); let mut post = posts_world .views .get(uri) .cloned() .unwrap_or_else(|| json!({ "uri": uri })); if let Some(map) = post.as_object_mut() { map.insert("uri".to_string(), json!(uri)); map.insert("likeCount".to_string(), json!(likes)); map.insert("repostCount".to_string(), json!(reposts)); map.insert("quoteCount".to_string(), json!(quotes)); map.insert("replyCount".to_string(), json!(replies)); } post }) .collect(); json_response(json!({ "posts": posts })) }) .mount(server) .await; let follows = world.follows.clone(); Mock::given(method("GET")) .and(path("/xrpc/app.bsky.graph.getFollows")) .respond_with(move |_: &Request| json_response(follows.clone())) .mount(server) .await; } fn query(request: &Request, key: &str) -> Option { request .url .query_pairs() .find(|(name, _)| name == key) .map(|(_, value)| value.into_owned()) } fn json_response(value: Value) -> ResponseTemplate { ResponseTemplate::new(200).set_body_raw(value.to_string(), "application/json") } fn run(server: &MockServer, args: &[&str]) -> Output { Command::new(env!("CARGO_BIN_EXE_longread")) .args(args) .env("LONGREAD_PUBLIC_API", server.uri()) .env("LONGREAD_PLC_DIRECTORY", server.uri()) .env("RUST_LOG", "off") .output() .expect("running longread") } fn rows(output: &Output) -> Vec { assert!( output.status.success(), "longread failed: {}", String::from_utf8_lossy(&output.stderr) ); serde_json::from_slice(&output.stdout).expect("JSON output") } #[tokio::test] async fn finds_a_seven_post_thread_with_explainable_score_parts() { let server = MockServer::start().await; let counters = Arc::new(Counters::default()); let mut world = World::new( vec![Account::single_page( ALICE_DID, "alice.test", SEVEN_POSTS, EMPTY_DOCUMENTS, )], counters, ); world.engagement = engagement_from_fixture(SEVEN_ENGAGEMENT); mount(&server, world).await; let output = run( &server, &["scan", "alice.test", "--since", "36500d", "--json"], ); let rows = rows(&output); assert_eq!(rows.len(), 1); let thread = &rows[0]; assert_eq!(thread["post_count"], 7); assert_eq!(thread["graphemes"], 1400); assert_eq!(thread["likes"], 10); assert_eq!(thread["reposts"], 2); assert_eq!(thread["quotes"], 1); assert_eq!(thread["replies"], 5); assert_eq!(thread["author"]["display_name"], "alice.test"); assert!( thread["author"]["avatar"] .as_str() .expect("avatar") .contains("cid=bafyavatar") ); assert_eq!(thread["dropped_branches"], 0); assert_eq!(thread["published"], false); assert!( thread["topics"] .as_array() .expect("topics") .iter() .any(|topic| topic.as_str() == Some("fox")), "topics: {}", thread["topics"] ); assert!( thread["root_text"] .as_str() .expect("root text") .contains("quick brown fox"), "root text: {}", thread["root_text"] ); assert_eq!( thread["url"], "https://bsky.app/profile/did:plc:alice/post/p1" ); let expected_reach = 1400.0 * (1.0 + 18.0f64.ln()); let reach = thread["reach_score"].as_f64().expect("reach score"); assert!( (reach - expected_reach).abs() < 0.01, "reach {reach} should be {expected_reach}" ); let craft = thread["craft"]["score"].as_f64().expect("craft score"); assert!((0.0..=1.0).contains(&craft), "craft {craft}"); let relative = thread["relative_factor"].as_f64().expect("relative factor"); assert!( (relative - 1.25).abs() < 1e-9, "the root is far above its sampled median: {relative}" ); assert_eq!(thread["author_median"], 0.0); assert_eq!(thread["cohort_percentile"], 100.0); assert_eq!(thread["label_state"], "visible"); assert!(thread["labels"].as_array().expect("labels").is_empty()); let score = thread["score"].as_f64().expect("score"); let expected_score = reach * relative * (0.75 + 0.5 * craft); assert!( (score - expected_score).abs() < 0.01, "score {score} should be reach × relative × (0.75 + 0.5 × craft) = {expected_score}" ); } #[tokio::test] async fn labels_mark_threads_for_warning_or_hiding() { let server = MockServer::start().await; let counters = Arc::new(Counters::default()); let world = World::new( vec![Account::single_page( ALICE_DID, "alice.test", LABELLED_POSTS, EMPTY_DOCUMENTS, )], counters, ); mount(&server, world).await; let output = run( &server, &[ "scan", "alice.test", "--since", "36500d", "--min-posts", "1", "--min-graphemes", "0", "--json", ], ); let rows = rows(&output); assert_eq!(rows.len(), 2); let warned = rows .iter() .find(|row| { row["root_uri"] .as_str() .is_some_and(|uri| uri.ends_with("/warn")) }) .expect("warned row"); assert_eq!(warned["label_state"], "warn"); assert!( warned["labels"] .as_array() .expect("labels") .iter() .any(|label| label == "!warn") ); let hidden = rows .iter() .find(|row| { row["root_uri"] .as_str() .is_some_and(|uri| uri.ends_with("/hide")) }) .expect("hidden row"); assert_eq!(hidden["label_state"], "hidden"); } #[tokio::test] async fn scan_root_thumbnail_uses_the_first_image() { let server = MockServer::start().await; let counters = Arc::new(Counters::default()); let world = World::new( vec![Account::single_page( ALICE_DID, "alice.test", EXPORT_POSTS, EMPTY_DOCUMENTS, )], counters, ); mount(&server, world).await; let output = run( &server, &[ "scan", "alice.test", "--since", "36500d", "--min-posts", "5", "--min-graphemes", "0", "--json", ], ); let rows = rows(&output); assert_eq!(rows.len(), 1); let thumb = rows[0]["root_thumb"].as_str().expect("root thumb"); assert_eq!( thumb, format!( "{}/xrpc/com.atproto.sync.getBlob?did=did:plc:alice&cid=bafyimage1", server.uri() ) ); } #[tokio::test] async fn keeps_the_longest_fork_branch_and_counts_the_side_branch() { let server = MockServer::start().await; let counters = Arc::new(Counters::default()); let world = World::new( vec![Account::single_page( ALICE_DID, "alice.test", FORK_POSTS, EMPTY_DOCUMENTS, )], counters, ); mount(&server, world).await; let output = run( &server, &[ "scan", "alice.test", "--since", "36500d", "--min-posts", "2", "--min-graphemes", "0", "--json", ], ); let rows = rows(&output); assert_eq!(rows.len(), 1); assert_eq!(rows[0]["post_count"], 4); assert_eq!(rows[0]["dropped_branches"], 1); assert_eq!( rows[0]["root_uri"], "at://did:plc:alice/app.bsky.feed.post/f1" ); let forks = rows[0]["forks"].as_array().expect("forks"); assert_eq!(forks.len(), 1); assert_eq!( forks[0]["parent_uri"], "at://did:plc:alice/app.bsky.feed.post/f1" ); let options = forks[0]["options"].as_array().expect("options"); assert_eq!(options.len(), 2); assert_eq!( options .iter() .filter(|option| option["chosen"] == true) .count(), 1 ); let side = options .iter() .find(|option| { option["uri"] .as_str() .is_some_and(|uri| uri.ends_with("/f2b")) }) .expect("side branch"); assert_eq!(side["posts"], 1); assert_eq!(side["chosen"], false); } #[tokio::test] async fn a_deleted_middle_post_ends_the_chain() { let server = MockServer::start().await; let counters = Arc::new(Counters::default()); let world = World::new( vec![Account::single_page( ALICE_DID, "alice.test", DELETED_POSTS, EMPTY_DOCUMENTS, )], counters, ); mount(&server, world).await; let base = [ "scan", "alice.test", "--since", "36500d", "--min-posts", "2", "--min-graphemes", "0", "--json", ]; let default_rows = rows(&run(&server, &base)); assert_eq!(default_rows.len(), 1); assert_eq!(default_rows[0]["post_count"], 3); assert_eq!( default_rows[0]["root_uri"], "at://did:plc:alice/app.bsky.feed.post/d1" ); let with_replies = [ "scan", "alice.test", "--since", "36500d", "--min-posts", "2", "--min-graphemes", "0", "--include-replies", "--json", ]; let mut counts: Vec = rows(&run(&server, &with_replies)) .iter() .map(|row| row["post_count"].as_u64().expect("post count")) .collect(); counts.sort_unstable(); assert_eq!(counts, vec![2, 3]); } #[tokio::test] async fn a_chain_under_someone_elses_post_needs_include_replies() { let server = MockServer::start().await; let counters = Arc::new(Counters::default()); let world = World::new( vec![Account::single_page( ALICE_DID, "alice.test", REPLY_START_POSTS, EMPTY_DOCUMENTS, )], counters, ); mount(&server, world).await; let hidden = run( &server, &[ "scan", "alice.test", "--since", "36500d", "--min-posts", "2", "--min-graphemes", "0", "--json", ], ); assert!(rows(&hidden).is_empty()); let shown = run( &server, &[ "scan", "alice.test", "--since", "36500d", "--min-posts", "2", "--min-graphemes", "0", "--include-replies", "--json", ], ); let shown = rows(&shown); assert_eq!(shown.len(), 1); assert_eq!(shown[0]["post_count"], 3); } #[tokio::test] async fn both_thresholds_hide_short_or_thin_threads() { let server = MockServer::start().await; let counters = Arc::new(Counters::default()); let world = World::new( vec![Account::single_page( ALICE_DID, "alice.test", THRESHOLD_POSTS, EMPTY_DOCUMENTS, )], counters, ); mount(&server, world).await; let filtered = run( &server, &[ "scan", "alice.test", "--since", "36500d", "--min-posts", "5", "--min-graphemes", "50", "--json", ], ); assert!(rows(&filtered).is_empty()); let unfiltered = run( &server, &[ "scan", "alice.test", "--since", "36500d", "--min-posts", "2", "--min-graphemes", "0", "--json", ], ); assert_eq!(rows(&unfiltered).len(), 2); } #[tokio::test] async fn export_slices_facets_and_renders_every_embed_shape() { let server = MockServer::start().await; let counters = Arc::new(Counters::default()); let mut world = World::new( vec![ Account::single_page(ALICE_DID, "alice.test", EXPORT_POSTS, EMPTY_DOCUMENTS), Account::single_page(CAROL_DID, "carol.test", EMPTY_DOCUMENTS, EMPTY_DOCUMENTS), Account::single_page(DAVE_DID, "dave.test", EMPTY_DOCUMENTS, EMPTY_DOCUMENTS), ], counters, ); world.views = views_from_fixture(QUOTE_VIEWS); mount(&server, world).await; let output = run( &server, &["export", "at://did:plc:alice/app.bsky.feed.post/e2"], ); assert!( output.status.success(), "export failed: {}", String::from_utf8_lossy(&output.stderr) ); let markdown = String::from_utf8(output.stdout).expect("UTF-8 markdown"); assert!( markdown.contains("title: \"🦊 日本語 example link\""), "{markdown}" ); assert!(markdown.contains("date: 2026-05-01"), "{markdown}"); assert!( markdown.contains("source: https://bsky.app/profile/did:plc:alice/post/e1"), "{markdown}" ); assert!(markdown.contains("author: @alice.test"), "{markdown}"); assert!( markdown.contains("[example link](https://example.com/a)"), "facet byte offsets were not sliced correctly: {markdown}" ); assert!( markdown.contains(&format!( "![A cat on a keyboard]({}/xrpc/com.atproto.sync.getBlob?did=did:plc:alice&cid=bafyimage1)", server.uri() )), "{markdown}" ); assert!( markdown.contains("[@bob.test](https://bsky.app/profile/did:plc:bob)"), "{markdown}" ); assert!( markdown.contains("[A story](https://example.com/story)"), "{markdown}" ); assert!( markdown .contains("> **@carol.test** · [post](https://bsky.app/profile/did:plc:carol/post/q1)"), "quote was not embedded: {markdown}" ); assert!( markdown.contains("> This is the [full quoted post](https://example.com/quoted)."), "quoted facets were not rendered: {markdown}" ); assert!( markdown.contains("> [Quoted post](https://bsky.app/profile/did:plc:dave/post/q2)"), "opted-out quote should stay a link: {markdown}" ); assert!( !markdown.contains("This must not be embedded."), "opted-out quote content leaked: {markdown}" ); assert!( markdown.contains("[Video](https://bsky.app/profile/did:plc:alice/post/e4)"), "{markdown}" ); for counter in ["1/5", "2/5", "3/5", "4/5", "5/5"] { assert!( !markdown.contains(counter), "counter {counter} remained: {markdown}" ); } } #[tokio::test] async fn a_matching_document_hides_the_thread_unless_asked() { let server = MockServer::start().await; let counters = Arc::new(Counters::default()); let world = World::new( vec![Account::single_page( ALICE_DID, "alice.test", SEVEN_POSTS, PUBLISHED_DOCUMENTS, )], counters, ); mount(&server, world).await; let hidden = run( &server, &["scan", "alice.test", "--since", "36500d", "--json"], ); assert!(rows(&hidden).is_empty()); let shown = run( &server, &[ "scan", "alice.test", "--since", "36500d", "--include-published", "--json", ], ); let rows = rows(&shown); assert_eq!(rows.len(), 1); assert_eq!(rows[0]["published"], true); } #[tokio::test] async fn a_publication_view_maps_documents_and_excludes_them_from_new_threads() { let server = MockServer::start().await; let counters = Arc::new(Counters::default()); let world = World::new( vec![ Account::single_page( ALICE_DID, "alice.test", PUBLICATION_POSTS, PUBLICATION_DOCUMENTS, ) .with_record( "site.standard.publication", "pub1", json!({ "name": "Alice's blog", "url": "https://alice.example", "description": "A test publication", }), ), ], counters, ); mount(&server, world).await; let output = run( &server, &[ "publication", PUBLICATION_URI, "--scan", "--since", "36500d", "--min-posts", "2", "--min-graphemes", "0", "--json", ], ); assert!( output.status.success(), "publication failed: {}", String::from_utf8_lossy(&output.stderr) ); let result: Value = serde_json::from_slice(&output.stdout).expect("JSON output"); assert_eq!(result["publications"][0]["name"], "Alice's blog"); assert_eq!(result["documents"].as_array().expect("documents").len(), 1); assert_eq!( result["documents"][0]["source_uri"], "at://did:plc:alice/app.bsky.feed.post/pubroot" ); assert_eq!( result["documents"][0]["url"], "https://alice.example/post-1" ); let threads = result["threads"].as_array().expect("threads"); assert_eq!(threads.len(), 1); assert_eq!( threads[0]["root_uri"], "at://did:plc:alice/app.bsky.feed.post/newroot" ); } #[tokio::test] async fn follows_skips_an_opted_out_account_without_reading_its_posts() { let server = MockServer::start().await; let counters = Arc::new(Counters::default()); let mut world = World::new( vec![ Account::single_page(CAROL_DID, "carol.test", SEVEN_POSTS, EMPTY_DOCUMENTS), Account::single_page(ALICE_DID, "alice.test", SEVEN_POSTS, EMPTY_DOCUMENTS).opted_out(), Account::single_page(BOB_DID, "bob.test", BOB_POSTS, EMPTY_DOCUMENTS), ], counters.clone(), ); world.engagement.insert( "at://did:plc:bob/app.bsky.feed.post/b1".to_string(), (3, 0, 0, 0), ); mount(&server, world).await; let output = run( &server, &[ "follows", "carol.test", "--since", "36500d", "--min-posts", "1", "--min-graphemes", "0", "--json", ], ); let rows = rows(&output); assert_eq!( rows.len(), 1, "unexpected rows: {}", String::from_utf8_lossy(&output.stdout) ); assert_eq!(rows[0]["author"]["handle"], "bob.test"); assert!( !String::from_utf8_lossy(&output.stdout).contains("alice"), "alice appeared in output" ); let read_repos = counters.posts_repos.lock().expect("counter lock"); assert!( !read_repos.iter().any(|did| did == ALICE_DID), "alice's posts were read: {read_repos:?}" ); } #[tokio::test] async fn pagination_stops_at_the_since_cutoff() { let server = MockServer::start().await; let counters = Arc::new(Counters::default()); let account = Account { did: ALICE_DID.to_string(), handle: "alice.test".to_string(), profile: json!({ "displayName": "Alice" }), posts: vec![ Page { cursor: None, body: serde_json::from_str(PAGINATION_PAGE_1).expect("page one"), }, Page { cursor: Some("page2".to_string()), body: serde_json::from_str(PAGINATION_PAGE_2).expect("page two"), }, ], documents: serde_json::from_str(EMPTY_DOCUMENTS).expect("documents"), records: HashMap::new(), }; mount(&server, World::new(vec![account], counters.clone())).await; let output = run( &server, &[ "scan", "alice.test", "--since", "3650d", "--min-posts", "1", "--min-graphemes", "0", "--json", ], ); let rows = rows(&output); assert_eq!(rows.len(), 1); assert_eq!( rows[0]["root_uri"], "at://did:plc:alice/app.bsky.feed.post/new" ); assert_eq!( counters.posts_pages.load(Ordering::SeqCst), 1, "a page was fetched beyond the cutoff" ); } #[tokio::test] async fn a_429_is_retried_once_then_succeeds() { let server = MockServer::start().await; let counters = Arc::new(Counters::default()); counters.posts_429_remaining.store(1, Ordering::SeqCst); let mut world = World::new( vec![Account::single_page( ALICE_DID, "alice.test", SEVEN_POSTS, EMPTY_DOCUMENTS, )], counters.clone(), ); world.engagement = engagement_from_fixture(SEVEN_ENGAGEMENT); mount(&server, world).await; let output = run( &server, &["scan", "alice.test", "--since", "36500d", "--json"], ); let rows = rows(&output); assert_eq!(rows.len(), 1); assert_eq!(counters.posts_pages.load(Ordering::SeqCst), 2); } #[tokio::test] #[ignore = "reads the public Bluesky API"] async fn live_scan_of_a_public_account() { let output = Command::new(env!("CARGO_BIN_EXE_longread")) .args(["scan", "jay.bsky.team", "--since", "90d"]) .env("RUST_LOG", "warn") .output() .expect("running the live scan"); assert!( output.status.success(), "live scan failed: {}", String::from_utf8_lossy(&output.stderr) ); eprintln!("{}", String::from_utf8_lossy(&output.stdout)); }