use std::fs; use std::path::{Path, PathBuf}; use std::time::SystemTime; use super::*; const NOW: u64 = 1_790_100_000_000; const WEEKLY: &str = "1790000000000-1001"; const ROADMAP: &str = "1790000500000-1002"; const STANDUP: &str = "1790001000000-1003"; fn fixtures() -> PathBuf { Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/meetings") } fn library() -> Library { Library::new(fixtures()) } fn list(library: &Library, include_in_progress: bool) -> String { library .list( &ListQuery { since: None, until: None, query: None, limit: 20, include_in_progress, }, NOW, ) .unwrap() } fn search(query: &str, fuzzy: bool) -> String { library() .search( &SearchQuery { query: query.into(), since: None, until: None, meeting_id: None, limit: 10, fuzzy, include_in_progress: true, vocabulary: Vec::new(), }, NOW, ) .unwrap() } fn transcript(id: &str, configure: impl FnOnce(&mut TranscriptQuery)) -> String { let mut query = TranscriptQuery { meeting_id: id.into(), start: None, end: None, speaker: None, max_chars: 20_000, cursor: None, }; configure(&mut query); library().transcript(&query, NOW).unwrap() } fn hit_lines(output: &str) -> Vec<&str> { output .lines() .filter(|line| line.starts_with('[')) .collect() } #[test] fn lists_meetings_skipping_unreadable_folders_and_labeling_unfinished_ones() { let output = list(&library(), true); let lines = output.lines().collect::>(); assert!(lines[0].starts_with("3 of 3 meetings"), "{output}"); // Newest first. assert!(lines[1].starts_with(&format!("- {STANDUP}")), "{output}"); assert!(lines[1].contains("interrupted · rolling transcript")); let weekly = lines.iter().find(|line| line.contains(WEEKLY)).unwrap(); assert!(weekly.contains("\"Weekly sync\"")); assert!(weekly.contains("· 00:40 · complete · final transcript")); assert!(weekly.contains("participants: You, Them (Zoom)")); assert!(weekly.contains("notes: yes")); assert!(output.contains("warning: skipped 1 unreadable lines in transcript.ndjson")); assert!(output.contains( "Skipped 1 unreadable folders:\n- 1790001500000-1004: could not decode manifest.json" )); } #[test] fn list_filters_by_title_and_time() { let library = library(); let query = |since: Option<&str>, until: Option<&str>, title: Option<&str>| { library .list( &ListQuery { since: since.map(Into::into), until: until.map(Into::into), query: title.map(Into::into), limit: 20, include_in_progress: true, }, NOW, ) .unwrap() }; let roadmap = query(None, None, Some("ROADMAP")); assert!( roadmap.starts_with("1 of 1 meetings") && roadmap.contains(ROADMAP), "{roadmap}" ); let after = query(Some("1790000500000"), None, None); assert!( !after.contains(WEEKLY) && after.contains(ROADMAP), "{after}" ); let before = query(None, Some("2026-09-21T00:00:00Z"), None); assert!(before.starts_with("No meetings match"), "{before}"); } #[test] fn search_ranks_names_and_tolerates_recognition_misspellings() { let output = search("Dax", true); let hits = hit_lines(&output); assert!(hits[0].contains(WEEKLY), "{output}"); assert!( output.contains("hit: Sure. **Dax**, can you walk"), "{output}" ); assert!( hits.iter().any(|line| line.contains("matched dack~dax")), "Dacks should match Dax: {output}" ); let exact_rank = hits .iter() .position(|line| line.contains("matched dax")) .unwrap(); let fuzzy_rank = hits .iter() .position(|line| line.contains("dack~dax")) .unwrap(); assert!(exact_rank < fuzzy_rank, "{output}"); let exact = search("Dacks", false); assert_eq!(hit_lines(&exact).len(), 1, "{exact}"); assert!(exact.contains("**Dacks** thinks")); } /// A storage discussion at 02:00–02:40 amid chatter full of `made`, `blog`, /// `Bob`, and `believe`, which are one edit or a Soundex code away from /// `media` and `blob`. `blob` is said in three passages (the third at 03:30), /// so it is no longer rare. fn ranked(query: &str) -> String { Library::new(Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/meetings-ranking")) .search( &SearchQuery { query: query.into(), since: None, until: None, meeting_id: None, limit: 10, fuzzy: true, include_in_progress: true, vocabulary: Vec::new(), }, NOW, ) .unwrap() } fn offset(hit: &str) -> &str { hit.split(" · ") .nth(1) .and_then(|when| when.split(' ').next()) .unwrap() } #[test] fn exact_stems_outrank_loose_matches_to_common_words() { let output = ranked("images database blob storage media"); let hits = hit_lines(&output); let mut top = hits .iter() .take(5) .map(|hit| offset(hit)) .collect::>(); top.sort_unstable(); assert_eq!( top, ["02:00", "02:10", "02:20", "02:30", "02:40"], "{output}" ); // `made` is said throughout, so it never stands in for `media`. assert!(!output.contains("mad~media"), "{output}"); // `blob` is spelled that way in three passages, so it no longer reaches // `blog`, `Bob`, or `believe`. assert!(!output.contains("~blob"), "{output}"); let blob = ranked("blob"); let blobs = hit_lines(&blob); assert_eq!( blobs.iter().map(|hit| offset(hit)).collect::>(), ["02:00", "02:10", "03:30"], "{blob}" ); assert!( blobs.iter().all(|hit| hit.ends_with("matched blob")), "{blob}" ); } #[test] fn a_term_found_in_fewer_passages_still_reaches_its_neighbours() { // The fixture's `blob` story with only two exact passages. let texts = [ "keep the images in blob storage", "the blob store sits behind a CDN", "I wrote a blog post", "the onboarding video is done", ]; let documents = texts.map(|text| vec![text]); let matched = |documents: &[Vec<&str>]| { search_texts(documents, "blob", &[]) .unwrap() .into_iter() .map(|hit| hit.index) .collect::>() }; assert_eq!(matched(&documents), [0, 1, 2]); let mut common = documents.to_vec(); common.push(vec!["one more blob"]); assert_eq!(matched(&common), [4, 0, 1]); } #[test] fn an_all_exact_passage_outranks_a_higher_scoring_partial_one() { // `storage` is rare and `blob` common, so a short passage repeating // `storage` alone outscores a long one that has both words. let mut texts = vec![ "blob first, then a long tangent about the quarter, the hiring plan, the offsite, the \ budget review, and the roadmap before we finally got back to storage", "storage storage storage storage", ]; texts.extend(["the blob again"; 8]); let documents = texts.iter().map(|text| vec![*text]).collect::>(); let hits = search_texts(&documents, "blob storage", &[]).unwrap(); assert_eq!(hits[0].index, 0); let partial = hits.iter().find(|hit| hit.index == 1).unwrap(); assert!(partial.score > hits[0].score, "{hits:?}"); } #[test] fn passages_matching_every_term_exactly_rank_first() { let output = ranked("blob storage"); let hits = hit_lines(&output); assert!(hits.len() > 3, "{output}"); let exact = hits .iter() .take_while(|hit| hit.ends_with("matched blob, storag")) .count(); assert_eq!(exact, 2, "{output}"); assert!( hits[exact..] .iter() .all(|hit| !hit.ends_with("matched blob, storag")), "{output}" ); } #[test] fn a_misspelled_rare_word_still_finds_its_passage() { let output = ranked("thumbnial"); let hits = hit_lines(&output); assert_eq!(hits.len(), 1, "{output}"); assert_eq!(offset(hits[0]), "02:30", "{output}"); assert!(hits[0].ends_with("matched thumbnail~thumbnial"), "{output}"); } #[test] fn spelling_fallbacks_need_rare_terms_and_uncommon_candidates() { let common = 5.0; assert!(admits(MatchKind::Edit(1), 2, 4, common)); assert!(admits(MatchKind::Edit(2), 2, 4, common)); // The term is spelled this way often enough; neighbours are other words. assert!(!admits(MatchKind::Edit(1), RARE_EXACT_PASSAGES, 1, common)); assert!(!admits(MatchKind::Sound, RARE_EXACT_PASSAGES, 1, common)); // `made` for `media`. assert!(!admits(MatchKind::Sound, 1, 9, common)); assert!(!admits(MatchKind::Edit(1), 1, 9, common)); // A plain typo of a common word still reaches it, but only by one edit. assert!(admits(MatchKind::Edit(1), 0, 9, common)); assert!(!admits(MatchKind::Edit(2), 0, 9, common)); assert!(!admits(MatchKind::Sound, 0, 9, common)); assert!(admits(MatchKind::Prefix, 50, 50, common)); } #[test] fn search_stems_folds_accents_and_requires_quoted_phrases() { let schedule = search("schedule", true); assert!( schedule.contains(WEEKLY) && schedule.contains(ROADMAP), "{schedule}" ); assert!( schedule.contains("**schedule**, like a cron job"), "{schedule}" ); let cafe = search("cafe", true); assert!(cafe.contains("the **Café** dashboard"), "{cafe}"); let phrase = search("\"scheduled sessions\"", true); assert!(!phrase.contains(ROADMAP), "{phrase}"); let hits = hit_lines(&phrase); assert!(hits.iter().any(|line| line.contains("Notes")), "{phrase}"); assert!( phrase.contains("the **scheduled** **sessions** idea"), "{phrase}" ); assert!(hits.iter().all(|line| line.contains(WEEKLY)), "{phrase}"); let missing = search("\"sessions scheduled\"", true); assert!(missing.starts_with("0 matching passages"), "{missing}"); } #[test] fn search_reports_context_and_labels_unfinished_meetings() { let output = search("cron", true); assert!( output.contains( "before (You 00:04): Sure. Dax, can you walk us through the scheduled sessions idea?" ), "{output}" ); assert!( output.contains("interrupted (rolling transcript)"), "{output}" ); assert!( output.contains("Rolling text mentions **cron** again."), "{output}" ); } #[test] fn transcript_merges_turns_and_continues_from_a_cursor() { let full = transcript(WEEKLY, |_| {}); assert!(full.contains( "] Them: Yeah, so the plan is that agents can run on a schedule, like a cron job, \ without anyone watching. Recurring sessions would wake up in the background and report back." )); assert!(full.ends_with("(end of range)\n"), "{full}"); let first = transcript(WEEKLY, |query| query.max_chars = 500); assert!(!first.contains("Great, I'll write the spec.")); let cursor = first .lines() .find_map(|line| line.strip_prefix("next_cursor: ")) .and_then(|rest| rest.split_whitespace().next()) .unwrap() .to_string(); let second = transcript(WEEKLY, |query| { query.max_chars = 500; query.cursor = Some(cursor); }); assert!(second.contains("Great, I'll write the spec."), "{second}"); assert!(!second.contains("thanks for joining"), "{second}"); let you = transcript(WEEKLY, |query| query.speaker = Some("you".into())); assert!( !you.contains("Them:") && you.contains("You: Sure. Dax"), "{you}" ); let window = transcript(WEEKLY, |query| { query.start = Some("0:20".into()); query.end = Some("30".into()); }); assert!(window.contains("Showing 00:16–00:31"), "{window}"); assert!(!window.contains("thanks for joining") && !window.contains("write the spec")); } #[test] fn ranges_keep_overlapping_entries_and_reject_inverted_or_late_ones() { let query = |start: &str, end: &str| { library().transcript( &TranscriptQuery { meeting_id: WEEKLY.into(), start: Some(start.into()), end: Some(end.into()), speaker: None, max_chars: 20_000, cursor: None, }, NOW, ) }; // 00:16.5–00:22 overlaps 00:20 and is kept whole. let window = query("0:00:20", "30").unwrap(); assert!(window.contains("Showing 00:16–00:31"), "{window}"); let inverted = query("0:30", "0:20").unwrap_err().to_string(); assert_eq!( inverted, "The range start 00:30 must be earlier than its end 00:20." ); let late = query("0:41", "").unwrap_err().to_string(); assert_eq!( late, "The range starts at 00:41, after the meeting's end at 00:40." ); assert!(query("soon", "").is_err()); // A rolling draft's Markdown, limited to the range. let markdown = |from: Option<&str>, to: Option<&str>| { library().markdown(STANDUP, OffsetRange::parse(from, to).unwrap(), NOW) }; let draft = markdown(Some("0:04"), Some("9")).unwrap(); assert!(draft.contains("- Range: 00:04–00:09\n"), "{draft}"); assert!( draft.contains("Rolling text mentions cron again.") && draft.contains("I agree with that."), "{draft}" ); assert!(!draft.contains("background worker"), "{draft}"); assert!( markdown(None, Some("0:03")) .unwrap() .contains("- Range: 00:00–00:03\n") ); let late = markdown(Some("0:10"), None).unwrap_err().to_string(); assert!(late.contains("after the meeting's end at 00:10"), "{late}"); } #[test] fn transcript_of_an_unfinished_meeting_is_labeled_as_a_draft() { let output = transcript(STANDUP, |_| {}); assert!(output.contains("No final transcript was published; this is the unfinished draft.")); assert!( output.contains("Them: Rolling text about the background worker."), "{output}" ); assert!(output.contains("You: I agree with that."), "{output}"); } #[test] fn notes_are_read_and_their_absence_is_explicit() { // An older manifest with action items and decisions reads as title and summary. let notes = library().notes(WEEKLY).unwrap(); assert!(notes.contains("Title: Scheduled Sessions Plan"), "{notes}"); assert!(notes.contains("Summary: Dax proposed scheduled sessions for agents.")); assert!(!notes.contains("Prototype the runner") && !notes.contains("Decisions")); assert!(notes.contains("Read the transcript with get_transcript")); let missing = library().notes(ROADMAP).unwrap(); assert!(missing.contains("No Apple Intelligence notes are stored for this meeting.")); assert!(missing.contains("Last notes attempt failed: Apple Intelligence is not available")); assert!(missing.contains("Use get_transcript")); let unknown = library().notes("nope").unwrap_err().to_string(); assert!(unknown.contains("list_meetings"), "{unknown}"); // Unique prefixes resolve; path-like ids never escape the folder. assert!(library().notes("1790000500").is_ok()); assert!(library().notes("../meetings").is_err()); } #[test] fn a_held_lock_marks_the_meeting_in_progress() { let root = std::env::temp_dir().join(format!( "hex-meeting-query-{}-{}", std::process::id(), crate::desktop::events::now_ms() )); let directory = root.join(STANDUP); fs::create_dir_all(&directory).unwrap(); for entry in fs::read_dir(fixtures().join(STANDUP)).unwrap() { let path = entry.unwrap().path(); fs::copy(&path, directory.join(path.file_name().unwrap())).unwrap(); } let lock = File::create(directory.join("active.lock")).unwrap(); let library = Library::new(&root); assert!(list(&library, true).contains("interrupted")); fs2::FileExt::lock_exclusive(&lock).unwrap(); let output = list(&library, true); assert!( output.contains("recording (in progress) · rolling transcript"), "{output}" ); assert!(list(&library, false).starts_with("No meetings match")); let notes = library.notes(STANDUP).unwrap(); assert!( notes.contains("No notes yet: the meeting is still recording."), "{notes}" ); // A recording in progress runs until now, past its rolling transcript. let ahead = library .markdown( STANDUP, OffsetRange::parse(Some("0:11"), Some("0:20")).unwrap(), NOW, ) .unwrap(); assert!( ahead.contains("## Transcript\n\nNo transcript entries in this range."), "{ahead}" ); let rolling = library .markdown( STANDUP, OffsetRange::parse(Some("0:05"), None).unwrap(), NOW, ) .unwrap(); assert!( rolling.contains("Rolling text mentions cron again."), "{rolling}" ); let late = library .markdown( STANDUP, OffsetRange::parse(Some("30:00:00"), None).unwrap(), NOW, ) .unwrap_err() .to_string(); assert_eq!( late, format!( "The range starts at 1800:00, after the meeting's end at {} so far.", format_duration(NOW - 1_790_001_000_000) ) ); fs2::FileExt::unlock(&lock).unwrap(); assert!(list(&library, true).contains("interrupted")); fs::remove_dir_all(root).unwrap(); } fn snapshot(root: &Path) -> Vec<(PathBuf, u64, SystemTime)> { let mut files = Vec::new(); let mut pending = vec![root.to_path_buf()]; while let Some(directory) = pending.pop() { let metadata = fs::metadata(&directory).unwrap(); files.push(( directory.clone(), metadata.len(), metadata.modified().unwrap(), )); for entry in fs::read_dir(&directory).unwrap() { let path = entry.unwrap().path(); if path.is_dir() { pending.push(path); } else { let metadata = fs::metadata(&path).unwrap(); files.push((path, metadata.len(), metadata.modified().unwrap())); } } } files.sort(); files } #[test] fn queries_never_write_to_the_meetings_folder() { let before = snapshot(&fixtures()); let library = library(); list(&library, true); search("scheduled sessions cron", true); for id in [WEEKLY, ROADMAP, STANDUP] { transcript(id, |_| {}); library.notes(id).unwrap(); library.markdown(id, OffsetRange::default(), NOW).unwrap(); } assert_eq!(before, snapshot(&fixtures())); } #[test] fn incomplete_final_publication_stays_a_draft_until_explicit_recovery() { let root = std::env::temp_dir().join(format!("hex-publication-{}", std::process::id())); let directory = root.join(STANDUP); fs::create_dir_all(&directory).unwrap(); for entry in fs::read_dir(fixtures().join(STANDUP)).unwrap() { let path = entry.unwrap().path(); fs::copy(&path, directory.join(path.file_name().unwrap())).unwrap(); } fs::copy( fixtures().join(WEEKLY).join("transcript.ndjson"), directory.join("transcript.ndjson"), ) .unwrap(); let library = Library::new(&root); let draft = library.meeting(STANDUP).unwrap(); assert_eq!(draft.source, TranscriptSource::Rolling); assert_eq!(draft.status, MeetingStatus::Interrupted); assert!(!super::super::final_transcript_exists(&directory)); fs::write(directory.join("transcript.md.tmp"), "# Ready to publish\n").unwrap(); let before = snapshot(&root); assert_eq!( library.meeting(STANDUP).unwrap().source, TranscriptSource::Rolling ); assert_eq!(before, snapshot(&root), "queries must not recover files"); super::super::recover_final_publication(&directory).unwrap(); assert!(super::super::final_transcript_exists(&directory)); assert_eq!( library.meeting(STANDUP).unwrap().source, TranscriptSource::Final ); fs::remove_dir_all(root).unwrap(); } #[test] fn pending_final_keeps_an_expired_draft_visible_even_in_a_warm_query_cache() { let root = std::env::temp_dir().join(format!("hex-read-admission-{}", std::process::id())); let directory = root.join(STANDUP); fs::create_dir_all(&directory).unwrap(); for entry in fs::read_dir(fixtures().join(STANDUP)).unwrap() { let path = entry.unwrap().path(); fs::copy(&path, directory.join(path.file_name().unwrap())).unwrap(); } let path = directory.join("manifest.json"); let mut manifest: MeetingManifest = serde_json::from_slice(&fs::read(&path).unwrap()).unwrap(); manifest.retention_applies = true; manifest.created_at_ms = 1; manifest.ended_at_ms = Some(2); fs::write(path, serde_json::to_vec(&manifest).unwrap()).unwrap(); let library = Library::new(&root); assert!(library.scan().unwrap().meetings.is_empty()); let pending = directory.join(super::super::FINAL_PENDING_FILE); fs::write(&pending, "").unwrap(); assert_eq!( library.meeting(STANDUP).unwrap().source, TranscriptSource::Rolling ); fs::remove_file(pending).unwrap(); assert!(library.scan().unwrap().meetings.is_empty()); fs::remove_dir_all(root).unwrap(); } #[test] fn markdown_has_metadata_notes_and_turns() { let markdown = library() .markdown(WEEKLY, OffsetRange::default(), NOW) .unwrap(); assert!(markdown.starts_with("# Weekly sync\n\n- Meeting: 1790000000000-1001\n")); assert!(markdown.contains("- App: Zoom")); assert!(markdown.contains("## Summary")); assert!(markdown.contains("## Transcript\n\n**Them** · 00:00\nHey Kit, thanks for joining.")); } #[test] fn parses_times_offsets_and_words() { assert_eq!( parse_time("2026-10-15T21:58:31Z", NOW, false).unwrap(), 1_792_101_511_000 ); assert_eq!( parse_time("2026-10-15T14:58:31-07:00", NOW, false).unwrap(), 1_792_101_511_000 ); assert_eq!( parse_time("1792101511335", NOW, false).unwrap(), 1_792_101_511_335 ); assert_eq!(parse_time("7d", NOW, false).unwrap(), NOW - 7 * 86_400_000); let day = parse_time("2026-10-15", NOW, false).unwrap(); assert_eq!( parse_time("2026-10-15", NOW, true).unwrap() - day, 86_400_000 ); assert_eq!( parse_time("yesterday", NOW, true).unwrap(), parse_time("today", NOW, false).unwrap() ); assert!(parse_time("last tuesday", NOW, false).is_err()); assert_eq!(parse_offset("12:34").unwrap(), 754_000); assert_eq!(parse_offset("1:02:03").unwrap(), 3_723_000); assert_eq!(parse_offset("90").unwrap(), 90_000); assert_eq!(parse_offset("1.5m").unwrap(), 90_000); assert_eq!(parse_offset("1.14").unwrap(), 1_140); assert_eq!(parse_offset("113:03").unwrap(), 6_783_000); assert_eq!(parse_offset("0:59.5").unwrap(), 59_500); for invalid in [ "soon", "1:-30", "-1:30", "-5", "0:99", "1:99:00", "0:inf", "inf", "NaN", "1.5:00", "1:2.5:00", "0:60", "1:60:00", ":30", "1:2:3:4", "1e300h", ] { assert!(parse_offset(invalid).is_err(), "{invalid}"); } for (word, expected) in [ ("scheduled", "schedul"), ("schedule", "schedul"), ("scheduling", "schedul"), ("sessions", "session"), ("recurring", "recur"), ("recur", "recur"), ("automated", "automat"), ("dax", "dax"), ("class", "class"), ] { assert_eq!(stem(word), expected, "{word}"); } let vocabulary = [ "schedul", "settl", "steal", "still", "dack", "deck", "docker", ] .map(String::from); let matches = |term: &str| { expand(term, vocabulary.iter(), true) .into_iter() .map(|(stem, _)| stem) .collect::>() }; // Sound-alikes apply to short, name-like words only. assert_eq!(matches("schedul"), ["schedul"]); assert_eq!(matches("dax"), ["dack", "deck"]); assert_eq!(soundex("dax"), soundex("dack")); assert_ne!(soundex("dax"), soundex("max")); assert_eq!(fold("Café DAX"), "cafe dax"); assert_eq!(edit_distance("cron", "corn", 1), Some(1)); assert_eq!(edit_distance("cron", "crane", 1), None); } fn entry(term: &str, sounds_like: &[&str]) -> VocabularyEntry { VocabularyEntry { term: term.into(), sounds_like: sounds_like.iter().map(|&text| text.into()).collect(), } } fn matched(texts: &[&str], query: &str, vocabulary: &[VocabularyEntry]) -> Vec { let documents = texts.iter().map(|text| vec![*text]).collect::>(); search_texts(&documents, query, vocabulary) .unwrap() .into_iter() .map(|hit| hit.index) .collect() } #[test] fn a_vocabulary_term_finds_its_mis_transcriptions_below_exact_hits() { let texts = [ "the cappuccino guides cover release notes and a long list of other things", "capuchin capuchin capuchin", "lunch was great", "cappuccino has the skills", ]; let vocabulary = [entry("cappuccino", &[])]; // Without the vocabulary, `capuchin` is too far from `cappuccino` to match. assert_eq!(matched(&texts, "cappuccino", &[]), [3, 0]); // With it, `capuchin` sounds alike, yet ranks after every exact hit even // though its repeated word scores higher. assert_eq!(matched(&texts, "cappuccinos", &vocabulary), [3, 0, 1]); let documents = texts.map(|text| vec![text]); let hits = search_texts(&documents, "cappuccino", &vocabulary).unwrap(); assert_eq!(hits[2].snippet, "**capuchin** **capuchin** **capuchin**"); } #[test] fn sounds_like_spellings_and_split_words_alias_a_term() { let texts = [ "the open coat release went out", "opencode beta shipped", "we should open code review to everyone", "the coat is open", ]; let vocabulary = [entry("OpenCode", &["open coat"])]; assert_eq!(matched(&texts, "opencode", &[]), [1]); let hits = matched(&texts, "OpenCode", &vocabulary); assert_eq!(hits[0], 1); let mut aliased = hits[1..].to_vec(); aliased.sort_unstable(); assert_eq!(aliased, [0, 2], "only adjacent words alias the term"); // Fuzzy off searches the words as written. let passages = texts.map(|text| Passage::new(PassageKind::Notes, 0, text.into())); let refs = passages.iter().collect::>(); let exact = score( &refs, &[0, 1, 2, 3], &ParsedQuery::parse("opencode"), false, &vocabulary, ); assert_eq!(exact.iter().map(|hit| hit.passage).collect::>(), [1]); } #[test] fn vocabulary_never_pulls_in_common_words() { // `Rune` has one consonant sound, so sound-alikes come only from its // "sounds like" spellings: the vocabulary changes nothing here. let chatter = [ "rune ships the new layout", "I went for a run", "the rain stopped", "the room is booked", "ruin the surprise", "rain again tomorrow", ]; assert_eq!( matched(&chatter, "rune", &[entry("Rune", &[])]), matched(&chatter, "rune", &[]) ); // `scroll` sounds like `Scrawl`; once it is a common word here, it is // never treated as a mis-transcription. let mut texts = vec!["scrawl captures the page", "I fixed the scroll bug"]; let vocabulary = [entry("Scrawl", &[])]; assert_eq!(matched(&texts, "scrawl", &vocabulary), [0, 1]); texts.extend(["scroll down"; 5]); texts.extend(["the standup ran long"; 20]); assert_eq!(matched(&texts, "scrawl", &vocabulary), [0]); // A spelling the person wrote is always used. let written = [entry("Scrawl", &["scroll"])]; assert_eq!(matched(&texts, "scrawl", &written).len(), 7); assert_eq!(matched(&texts, "scrawl", &written)[0], 0); } #[test] fn sound_alikes_need_two_consonant_sounds_and_few_changes() { assert_eq!(sound_key("cappuccino"), sound_key("capuchin")); assert!(sounds_alike("cappuccino", "capuchin")); assert!(sounds_alike("claud", "cloud")); assert!(sounds_alike("scrawl", "scroll")); // One consonant sound matches too many words. assert!(!sounds_alike("rune", "rain")); assert!(!sounds_alike("dax", "docks")); // The first letter and most letters must agree. assert!(!sounds_alike("effect", "affect")); assert!(!sounds_alike("parakeet", "pirate")); assert!(!sounds_alike("capuchin", "capuchin")); // Soundex itself is unchanged by the uncapped key. assert_eq!(soundex("cappuccino").as_deref(), Some("c125")); assert_eq!(soundex("dax").as_deref(), Some("d200")); assert_eq!(soundex("moonshine").as_deref(), Some("m525")); } #[test] fn chapters_list_spans_and_lines_and_say_when_there_are_none() { let chaptered = Library::new( Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/meetings-chapters"), ); let text = chaptered.chapters("1790003000000-1005", NOW).unwrap(); assert!( text.starts_with( "1790003000000-1005 \"Team sync: Image storage, Motion lint, Chat app name\"" ), "{text}" ); assert!( text.ends_with( "\n3 chapters, boundaries corrected over the whole transcript:\n\ 1. 00:00–03:00 · Image storage\n Where uploaded images live and how long they are kept.\n\ 2. 03:00–06:30 · Motion lint\n A lint that flags animations which snap instead of easing.\n\ 3. 06:30–09:00 · Chat app name\n Picking a name for the chat app.\n\ \nModel-written names that may be wrong. Read a chapter with get_transcript (start and \ end as shown) or `hex meetings show 1790003000000-1005 --chapter N`.\n" ), "{text}" ); let meeting = chaptered.meeting("1790003000000-1005").unwrap(); let views = meeting.chapter_views(NOW); assert_eq!( views .iter() .map(|view| (view.number, view.end_ms, view.entries.len())) .collect::>(), [(1, 180_000, 3), (2, 390_000, 3), (3, 540_000, 2)] ); assert!( views[2] .markdown() .starts_with("## Chat app name\n\nPicking a name") ); let none = library().chapters(WEEKLY, NOW).unwrap(); assert!( none.contains("No chapters are stored for this meeting."), "{none}" ); assert!(chaptered.chapters("missing", NOW).is_err()); } #[test] fn imported_meetings_render_speaker_consistently_across_export_query_chapters_and_search() { let root = std::env::temp_dir().join(format!("hex-imported-markdown-{}", std::process::id())); let _ = fs::remove_dir_all(&root); let id = "1790004000000-2001"; let dir = root.join(id); fs::create_dir_all(&dir).unwrap(); let manifest = MeetingManifest { schema_version: 1, id: id.into(), title: "Imported interview".into(), provisional_title: None, title_source: Some(crate::meeting::TitleSource::User), created_at_ms: 1_790_004_000_000, ended_at_ms: Some(1_790_004_060_000), duration_ms: Some(60_000), app: None, calendar: None, status: MeetingStatus::Complete, system: crate::meeting::TrackManifest::default(), microphone: crate::meeting::TrackManifest::default(), echo_suppressed_utterances: 0, notes: None, notes_error: None, notes_export_path: None, notes_export_sha256: None, notes_export_removed: false, live_transcription_error: None, export_path: None, export_sha256: None, export_error: None, error: None, chapters: vec![Chapter { title: "Opening".into(), summary: "Intro notes.".into(), start_ms: 0, }], chapters_refined: true, retention_applies: false, audio_removed_at_ms: None, imported: true, }; let entries = vec![ TranscriptEntry { source: MeetingSource::System, start_ms: 1_000, end_ms: 2_000, text: " Hello ".into(), }, TranscriptEntry { source: MeetingSource::System, start_ms: 3_000, end_ms: 4_000, text: ", welcome to the podcast.".into(), }, TranscriptEntry { source: MeetingSource::Microphone, start_ms: 10_000, end_ms: 12_000, text: "Thanks for having me on the roadmap episode.".into(), }, ]; fs::write( dir.join("manifest.json"), serde_json::to_string_pretty(&manifest).unwrap(), ) .unwrap(); let ndjson = entries .iter() .map(|entry| format!("{}\n", serde_json::to_string(entry).unwrap())) .collect::(); fs::write(dir.join("transcript.ndjson"), ndjson).unwrap(); let exported = super::super::markdown::render_document(&manifest, &entries); fs::write(dir.join("transcript.md"), &exported).unwrap(); assert!( exported.contains("**Speaker** · 00:01\nHello, welcome to the podcast."), "{exported}" ); assert!( exported.contains("**Speaker** · 00:10\nThanks for having me on the roadmap episode."), "{exported}" ); assert!( !exported.contains("**You**") && !exported.contains("**Them**"), "{exported}" ); let lib = Library::new(&root); let md = lib.markdown(id, OffsetRange::default(), NOW).unwrap(); assert!( md.contains("**Speaker** · 00:01\nHello, welcome to the podcast."), "{md}" ); assert!( md.contains("**Speaker** · 00:10\nThanks for having me on the roadmap episode."), "{md}" ); assert!(!md.contains("**You**") && !md.contains("**Them**"), "{md}"); let chapter_md = lib.chapter_markdown(id, 1, NOW).unwrap(); assert!( chapter_md.contains("**Speaker** · 00:01\nHello, welcome to the podcast."), "{chapter_md}" ); assert!( !chapter_md.contains("**You**") && !chapter_md.contains("**Them**"), "{chapter_md}" ); let transcript = lib .transcript( &TranscriptQuery { meeting_id: id.into(), start: None, end: None, speaker: None, max_chars: 20_000, cursor: None, }, NOW, ) .unwrap(); assert!( transcript.contains("] Speaker: Hello, welcome to the podcast."), "{transcript}" ); assert!( !transcript.contains("] You:") && !transcript.contains("] Them:"), "{transcript}" ); let search = lib .search( &SearchQuery { query: "roadmap".into(), since: None, until: None, meeting_id: Some(id.into()), limit: 10, fuzzy: false, include_in_progress: true, vocabulary: Vec::new(), }, NOW, ) .unwrap(); assert!(search.contains("· Speaker ·"), "{search}"); assert!(search.contains("before (Speaker 00:01):"), "{search}"); assert!( !search.contains("· You ·") && !search.contains("· Them ·"), "{search}" ); let listed = list(&lib, true); assert!(listed.contains("participants: Speaker"), "{listed}"); fs::remove_dir_all(&root).unwrap(); }