Repository navigation
Expand file tree
/
Copy pathquery_tests.rs
More file actions
816 lines (765 loc) · 27.9 KB
/
Copy pathquery_tests.rs
File metadata and controls
816 lines (765 loc) · 27.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
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::<Vec<_>>();
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::<Vec<_>>();
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::<Vec<_>>(),
["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::<Vec<_>>()
};
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::<Vec<_>>();
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 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::<Vec<_>>()
};
// 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<usize> {
let documents = texts.iter().map(|text| vec![*text]).collect::<Vec<_>>();
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::<Vec<_>>();
let exact = score(
&refs,
&[0, 1, 2, 3],
&ParsedQuery::parse("opencode"),
false,
&vocabulary,
);
assert_eq!(exact.iter().map(|hit| hit.passage).collect::<Vec<_>>(), [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::<Vec<_>>(),
[(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());
}