code-kb-core 1.1.3

Core library for code-kb AST fact querying, slicing, and progressive disclosure
Documentation
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
use code_kb_core::{
    Workspace, ensure_fresh_file, ensure_index_matches_extractor, find_julie_extract_binary,
    get_symbol_by_name, installed_extractor_version, open_read_only, open_read_write,
    reconcile_offline_edits, safe_tempdir, scan_workspace,
};
use std::fs;
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;

#[test]
fn test_ensure_fresh_file_detects_equal_size_edit() {
    let _extract_bin =
        find_julie_extract_binary().expect("julie-extract binary must be present for tests");

    let temp_dir = safe_tempdir();
    let root = temp_dir.path().to_path_buf();

    let src_dir = root.join("src");
    fs::create_dir_all(&src_dir).unwrap();
    let file_path = src_dir.join("calc.rs");

    // 40 bytes
    let initial_code = "pub fn foo_fn() -> i32 {\n    100\n}\n";
    fs::write(&file_path, initial_code).unwrap();

    let ws = Workspace::new(root.clone());
    let db_path = root.join("test.db");

    scan_workspace(&ws, &db_path, true).expect("Scan failed");
    let conn = open_read_only(&db_path).unwrap();

    // Modify file with exactly equal length (40 bytes): replace 'foo_fn' with 'bar_fn'
    let modified_code = "pub fn bar_fn() -> i32 {\n    100\n}\n";
    assert_eq!(initial_code.len(), modified_code.len());
    fs::write(&file_path, modified_code).unwrap();

    // ensure_fresh_file should detect content change via content_hash check
    let changed = ensure_fresh_file(&ws, &db_path, &conn, "src/calc.rs").unwrap();
    assert!(changed, "ensure_fresh_file should report file changed");

    // Symbol in database should now be bar_fn
    let symbol = get_symbol_by_name(&conn, "bar_fn", Some("src/calc.rs"))
        .unwrap()
        .expect("bar_fn should exist in db");
    assert_eq!(symbol.name, "bar_fn");
}

#[test]
fn test_ensure_fresh_file_removes_deleted_file_from_index() {
    let _extract_bin =
        find_julie_extract_binary().expect("julie-extract binary must be present for tests");

    let temp_dir = safe_tempdir();
    let root = temp_dir.path().to_path_buf();
    let src_dir = root.join("src");
    fs::create_dir_all(&src_dir).unwrap();
    let file_path = src_dir.join("removed.rs");
    fs::write(&file_path, "pub fn removed_symbol() {}\n").unwrap();

    let ws = Workspace::new(root.clone());
    let db_path = root.join("test.db");
    scan_workspace(&ws, &db_path, true).unwrap();
    let conn = open_read_only(&db_path).unwrap();

    fs::remove_file(&file_path).unwrap();

    assert!(ensure_fresh_file(&ws, &db_path, &conn, "src/removed.rs").unwrap());
    assert!(
        get_symbol_by_name(&conn, "removed_symbol", Some("src/removed.rs"))
            .unwrap()
            .is_none()
    );
}

#[cfg(unix)]
#[test]
fn test_ensure_fresh_file_propagates_read_failure() {
    let _extract_bin =
        find_julie_extract_binary().expect("julie-extract binary must be present for tests");

    let temp_dir = safe_tempdir();
    let root = temp_dir.path().to_path_buf();
    let src_dir = root.join("src");
    fs::create_dir_all(&src_dir).unwrap();
    let file_path = src_dir.join("unreadable.rs");
    fs::write(&file_path, "pub fn unreadable_symbol() {}\n").unwrap();

    let ws = Workspace::new(root.clone());
    let db_path = root.join("test.db");
    scan_workspace(&ws, &db_path, true).unwrap();
    let conn = open_read_only(&db_path).unwrap();

    fs::set_permissions(&file_path, fs::Permissions::from_mode(0o000)).unwrap();
    let result = ensure_fresh_file(&ws, &db_path, &conn, "src/unreadable.rs");
    fs::set_permissions(&file_path, fs::Permissions::from_mode(0o644)).unwrap();

    assert!(result.is_err());
}

#[test]
fn test_reconcile_offline_edits_equal_size() {
    let _extract_bin =
        find_julie_extract_binary().expect("julie-extract binary must be present for tests");

    let temp_dir = safe_tempdir();
    let root = temp_dir.path().to_path_buf();

    let src_dir = root.join("src");
    fs::create_dir_all(&src_dir).unwrap();
    let file_path = src_dir.join("calc.rs");

    let initial_code = "pub fn foo_fn() -> i32 {\n    100\n}\n";
    fs::write(&file_path, initial_code).unwrap();

    let ws = Workspace::new(root.clone());
    let db_path = root.join("test.db");

    scan_workspace(&ws, &db_path, true).expect("Scan failed");
    let conn = open_read_only(&db_path).unwrap();

    // Equal-size edit: replace 'foo_fn' with 'bar_fn'
    let modified_code = "pub fn bar_fn() -> i32 {\n    100\n}\n";
    assert_eq!(initial_code.len(), modified_code.len());
    fs::write(&file_path, modified_code).unwrap();

    let report =
        reconcile_offline_edits(&ws, &db_path, &conn).expect("reconcile_offline_edits failed");

    assert!(
        report.modified.contains(&"src/calc.rs".to_string()),
        "Equal-size modified file must appear in reconcile report.modified, got: {:?}",
        report.modified
    );
}

#[test]
fn test_get_symbol_body_fresh_after_comment_added() {
    let _extract_bin =
        find_julie_extract_binary().expect("julie-extract binary must be present for tests");

    let temp_dir = safe_tempdir();
    let root = temp_dir.path().to_path_buf();

    let src_dir = root.join("src");
    fs::create_dir_all(&src_dir).unwrap();
    let file_path = src_dir.join("calc.rs");

    let initial_code = "pub fn my_function() -> i32 {\n    12345\n}\n";
    fs::write(&file_path, initial_code).unwrap();

    let ws = Workspace::new(root.clone());
    let db_path = root.join("test.db");

    scan_workspace(&ws, &db_path, true).expect("Scan failed");
    let conn = open_read_only(&db_path).unwrap();

    // Now prepend 5 lines of comments before the function
    let modified_code = "// Line 1\n// Line 2\n// Line 3\n// Line 4\n// Line 5\npub fn my_function() -> i32 {\n    12345\n}\n";
    fs::write(&file_path, modified_code).unwrap();

    // Call get_symbol_body_op (without passing file_path explicitly)
    let (symbol, body) =
        code_kb_core::get_symbol_body_op(&ws, &db_path, &conn, "my_function", None)
            .expect("get_symbol_body_op failed");

    assert!(
        body.contains("12345"),
        "Body must contain 12345, got: {}",
        body
    );
    assert!(
        !body.contains("// Line"),
        "Body must not contain comments from above, got: {}",
        body
    );
    assert_eq!(
        symbol.start_line, 6,
        "Symbol line number must be refreshed to line 6"
    );
}

#[test]
fn test_reconcile_offline_edits_added_and_deleted() {
    let _extract_bin =
        find_julie_extract_binary().expect("julie-extract binary must be present for tests");

    let temp_dir = safe_tempdir();
    let root = temp_dir.path().to_path_buf();

    let src_dir = root.join("src");
    fs::create_dir_all(&src_dir).unwrap();
    let a_path = src_dir.join("a.rs");
    let b_path = src_dir.join("b.rs");

    fs::write(&a_path, "pub fn func_a() {}\n").unwrap();
    fs::write(&b_path, "pub fn func_b() {}\n").unwrap();

    let ws = Workspace::new(root.clone());
    let db_path = root.join("test.db");

    scan_workspace(&ws, &db_path, true).expect("Scan failed");
    let conn = open_read_only(&db_path).unwrap();

    // Delete b.rs and add c.rs
    fs::remove_file(&b_path).unwrap();
    let c_path = src_dir.join("c.rs");
    fs::write(&c_path, "pub fn func_c() {}\n").unwrap();

    let report =
        reconcile_offline_edits(&ws, &db_path, &conn).expect("reconcile_offline_edits failed");

    assert!(
        report.deleted.contains(&"src/b.rs".to_string()),
        "Deleted file must be detected, got: {:?}",
        report.deleted
    );
    assert!(
        report.added.contains(&"src/c.rs".to_string()),
        "Added file must be detected, got: {:?}",
        report.added
    );
}

#[cfg(unix)]
#[test]
fn test_reconcile_offline_edits_preserves_unreadable_directory_records() {
    let _extract_bin =
        find_julie_extract_binary().expect("julie-extract binary must be present for tests");

    let temp_dir = safe_tempdir();
    let root = temp_dir.path().to_path_buf();
    let src_dir = root.join("src");
    fs::create_dir_all(&src_dir).unwrap();
    let file_path = src_dir.join("locked.rs");
    fs::write(&file_path, "pub fn locked_symbol() {}\n").unwrap();

    let ws = Workspace::new(root.clone());
    let db_path = root.join("test.db");
    scan_workspace(&ws, &db_path, true).unwrap();
    let conn = open_read_only(&db_path).unwrap();

    // Add a new file at root that should still be indexed even if src is unreadable
    let new_file = root.join("top.rs");
    fs::write(&new_file, "pub fn top_symbol() {}\n").unwrap();

    fs::set_permissions(&src_dir, fs::Permissions::from_mode(0o000)).unwrap();
    let result = reconcile_offline_edits(&ws, &db_path, &conn);
    fs::set_permissions(&src_dir, fs::Permissions::from_mode(0o755)).unwrap();

    let report = result.expect("reconciliation should not abort on unreadable directory");
    assert!(report.added.contains(&"top.rs".to_string()));
    assert!(
        get_symbol_by_name(&conn, "locked_symbol", Some("src/locked.rs"))
            .unwrap()
            .is_some(),
        "Unreadable directory files must not be deleted from database"
    );
}

#[cfg(unix)]
#[test]
fn test_reconcile_offline_edits_continues_when_individual_update_fails() {
    let _extract_bin =
        find_julie_extract_binary().expect("julie-extract binary must be present for tests");

    let temp_dir = safe_tempdir();
    let root = temp_dir.path().to_path_buf();
    let src_dir = root.join("src");
    fs::create_dir_all(&src_dir).unwrap();
    fs::write(src_dir.join("valid.rs"), "pub fn valid_symbol() {}\n").unwrap();

    let ws = Workspace::new(root.clone());
    let db_path = root.join("test.db");
    scan_workspace(&ws, &db_path, true).unwrap();
    let conn = open_read_only(&db_path).unwrap();

    // Add another valid file and an unreadable file that will fail during update_file
    fs::write(src_dir.join("another.rs"), "pub fn another_symbol() {}\n").unwrap();
    let unreadable_path = src_dir.join("unreadable.rs");
    fs::write(&unreadable_path, "pub fn unreadable_symbol() {}\n").unwrap();
    fs::set_permissions(&unreadable_path, fs::Permissions::from_mode(0o000)).unwrap();

    let result = reconcile_offline_edits(&ws, &db_path, &conn);
    // Restore permissions so cleanup succeeds
    fs::set_permissions(&unreadable_path, fs::Permissions::from_mode(0o644)).unwrap();

    let report =
        result.expect("reconciliation should succeed even when an individual update fails");
    assert!(report.added.contains(&"src/another.rs".to_string()));
    assert!(report.added.contains(&"src/unreadable.rs".to_string()));
    assert!(
        get_symbol_by_name(&conn, "another_symbol", Some("src/another.rs"))
            .unwrap()
            .is_some(),
        "Valid file must be successfully indexed into database"
    );
    assert!(
        get_symbol_by_name(&conn, "unreadable_symbol", Some("src/unreadable.rs"))
            .unwrap()
            .is_none(),
        "Failed file must not be indexed into database"
    );
}

#[test]
fn test_codebase_outline_depth_bounded_symbols() {
    let _extract_bin =
        find_julie_extract_binary().expect("julie-extract binary must be present for tests");

    let temp_dir = safe_tempdir();
    let root = temp_dir.path().to_path_buf();

    let deep_dir = root.join("src").join("nested");
    fs::create_dir_all(&deep_dir).unwrap();

    let root_file = root.join("root.rs");
    let mid_file = root.join("src").join("lib.rs");
    let deep_file = deep_dir.join("deep.rs");

    fs::write(&root_file, "pub fn root_fn() {}\n").unwrap();
    fs::write(&mid_file, "pub fn mid_fn() {}\n").unwrap();
    fs::write(&deep_file, "pub fn deep_fn() {}\n").unwrap();

    let ws = Workspace::new(root.clone());
    let db_path = root.join("test.db");

    scan_workspace(&ws, &db_path, true).expect("Scan failed");
    let conn = open_read_only(&db_path).unwrap();

    // With depth = 1 and no filter, only files at depth 1 (0 slashes) should load symbols
    let syms_depth1 = code_kb_core::load_scoped_outline_symbols(&conn, None, 1, 5)
        .expect("load_scoped_outline_symbols failed");

    assert!(
        syms_depth1.contains_key("root.rs"),
        "root.rs must have symbols at depth 1"
    );
    assert!(
        !syms_depth1.contains_key("src/lib.rs"),
        "src/lib.rs must NOT have symbols at depth 1"
    );
    assert!(
        !syms_depth1.contains_key("src/nested/deep.rs"),
        "deep.rs must NOT have symbols at depth 1"
    );

    // With depth = 2, root.rs and src/lib.rs (<= 1 slash) load symbols, but deep.rs (2 slashes) does not
    let syms_depth2 = code_kb_core::load_scoped_outline_symbols(&conn, None, 2, 5)
        .expect("load_scoped_outline_symbols failed");

    assert!(syms_depth2.contains_key("root.rs"));
    assert!(syms_depth2.contains_key("src/lib.rs"));
    assert!(
        !syms_depth2.contains_key("src/nested/deep.rs"),
        "deep.rs must NOT have symbols at depth 2"
    );

    // Verify codebase_outline_op outputs correctly
    let outline =
        code_kb_core::codebase_outline_op(&ws, &conn, 1, None).expect("codebase_outline_op failed");
    assert!(outline.contains("root.rs"));
    assert!(outline.contains("src/"));
    // At depth 1, src/lib.rs should not be rendered as a file
    assert!(!outline.contains("lib.rs"));
}

#[test]
fn test_reconcile_offline_edits_preserves_hidden_files() {
    let _extract_bin =
        find_julie_extract_binary().expect("julie-extract binary must be present for tests");

    let temp_dir = safe_tempdir();
    let root = temp_dir.path().to_path_buf();

    let hidden_dir = root.join(".config");
    fs::create_dir_all(&hidden_dir).unwrap();
    let file_path = hidden_dir.join("helper.rs");
    fs::write(&file_path, "pub fn hidden_helper() -> i32 { 42 }\n").unwrap();

    let ws = Workspace::new(root.clone());
    let db_path = root.join("test.db");

    scan_workspace(&ws, &db_path, true).expect("Scan failed");
    let conn = open_read_only(&db_path).unwrap();

    // Verify it was indexed
    let sym = code_kb_core::get_symbol_by_name(&conn, "hidden_helper", Some(".config/helper.rs"))
        .unwrap();
    assert!(sym.is_some(), "Symbol in hidden dir should be indexed");

    // Run reconciliation without changing the file
    let report =
        reconcile_offline_edits(&ws, &db_path, &conn).expect("reconcile_offline_edits failed");

    // Hidden file must NOT be reported as deleted
    assert!(
        !report.deleted.contains(&".config/helper.rs".to_string()),
        "Hidden file should not be reported as deleted: {:?}",
        report.deleted
    );

    // Verify symbol still exists in DB
    let sym_after =
        code_kb_core::get_symbol_by_name(&conn, "hidden_helper", Some(".config/helper.rs"))
            .unwrap();
    assert!(
        sym_after.is_some(),
        "Symbol in hidden dir should still exist after reconciliation"
    );
}

#[test]
fn test_index_from_other_extractor_version_is_rebuilt() {
    find_julie_extract_binary().expect("julie-extract binary must be present for tests");
    let temp_dir = safe_tempdir();
    let root = temp_dir.path().to_path_buf();
    fs::create_dir_all(root.join("src")).unwrap();
    fs::write(
        root.join("src").join("calc.rs"),
        "pub fn foo_fn() -> i32 {\n    100\n}\n",
    )
    .unwrap();
    let ws = Workspace::new(root.clone());
    let db_path = root.join(".code-kb").join("artifact.db");
    scan_workspace(&ws, &db_path, true).expect("Scan failed");
    let installed = installed_extractor_version();
    assert!(!ensure_index_matches_extractor(&ws, &db_path, &installed).unwrap());

    {
        let conn = rusqlite::Connection::open(&db_path).unwrap();
        conn.execute(
            "UPDATE artifact_metadata SET value = '0.0.1' WHERE key = 'binary_version'",
            [],
        )
        .unwrap();
    }
    assert!(ensure_index_matches_extractor(&ws, &db_path, &installed).unwrap());
    assert!(!ensure_index_matches_extractor(&ws, &db_path, &installed).unwrap());

    let conn = open_read_only(&db_path).unwrap();
    let version: String = conn
        .query_row(
            "SELECT value FROM artifact_metadata WHERE key = 'binary_version'",
            [],
            |r| r.get(0),
        )
        .unwrap();
    assert_ne!(version, "0.0.1");
    assert!(get_symbol_by_name(&conn, "foo_fn", None).unwrap().is_some());
}

#[test]
fn test_index_written_by_the_installed_extractor_is_kept_even_when_it_is_not_the_pinned_build() {
    find_julie_extract_binary().expect("julie-extract binary must be present for tests");
    let temp_dir = safe_tempdir();
    let root = temp_dir.path().to_path_buf();
    fs::create_dir_all(root.join("src")).unwrap();
    fs::write(
        root.join("src").join("calc.rs"),
        "pub fn foo_fn() -> i32 {\n    100\n}\n",
    )
    .unwrap();
    let ws = Workspace::new(root.clone());
    let db_path = root.join(".code-kb").join("artifact.db");
    scan_workspace(&ws, &db_path, true).expect("Scan failed");
    {
        let conn = rusqlite::Connection::open(&db_path).unwrap();
        conn.execute(
            "UPDATE artifact_metadata SET value = '0.0.1' WHERE key = 'binary_version'",
            [],
        )
        .unwrap();
        conn.execute(
            "UPDATE extraction_revisions SET binary_version = '0.0.1'",
            [],
        )
        .unwrap();
    }

    assert!(!ensure_index_matches_extractor(&ws, &db_path, "0.0.1").unwrap());

    let conn = open_read_only(&db_path).unwrap();
    let version: String = conn
        .query_row(
            "SELECT value FROM artifact_metadata WHERE key = 'binary_version'",
            [],
            |r| r.get(0),
        )
        .unwrap();
    assert_eq!(version, "0.0.1");
}

#[test]
fn test_scan_replaces_an_empty_artifact_file() {
    find_julie_extract_binary().expect("julie-extract binary must be present for tests");
    let temp_dir = safe_tempdir();
    let root = temp_dir.path().to_path_buf();
    fs::create_dir_all(root.join("src")).unwrap();
    fs::write(
        root.join("src").join("calc.rs"),
        "pub fn foo_fn() -> i32 {\n    100\n}\n",
    )
    .unwrap();
    let db_path = root.join(".code-kb").join("artifact.db");
    fs::create_dir_all(db_path.parent().unwrap()).unwrap();
    fs::write(&db_path, b"").unwrap();
    let ws = Workspace::new(root.clone());

    scan_workspace(&ws, &db_path, false).expect("scan must replace an empty artifact");

    let conn = open_read_only(&db_path).unwrap();
    assert!(get_symbol_by_name(&conn, "foo_fn", None).unwrap().is_some());
}

#[test]
fn test_index_at_another_extraction_level_is_rebuilt() {
    find_julie_extract_binary().expect("julie-extract binary must be present for tests");
    let temp_dir = safe_tempdir();
    let root = temp_dir.path().to_path_buf();
    fs::create_dir_all(root.join("src")).unwrap();
    fs::write(
        root.join("src").join("calc.rs"),
        "pub fn foo_fn() -> i32 {\n    100\n}\n",
    )
    .unwrap();
    let ws = Workspace::new(root.clone());
    let db_path = root.join(".code-kb").join("artifact.db");
    scan_workspace(&ws, &db_path, true).expect("Scan failed");
    let installed = installed_extractor_version();
    assert!(!ensure_index_matches_extractor(&ws, &db_path, &installed).unwrap());
    {
        let conn = rusqlite::Connection::open(&db_path).unwrap();
        conn.execute(
            "UPDATE artifact_metadata SET value = 'full' WHERE key = 'index_level'",
            [],
        )
        .unwrap();
    }

    assert!(ensure_index_matches_extractor(&ws, &db_path, &installed).unwrap());

    let conn = open_read_only(&db_path).unwrap();
    let level: String = conn
        .query_row(
            "SELECT value FROM artifact_metadata WHERE key = 'index_level'",
            [],
            |r| r.get(0),
        )
        .unwrap();
    assert_eq!(level, "facts");
}

#[test]
fn test_ensure_index_matches_extractor_rebuilds_when_a_file_revision_differs() {
    let _extract_bin =
        find_julie_extract_binary().expect("julie-extract binary must be present for tests");
    let temp_dir = safe_tempdir();
    let root = temp_dir.path().to_path_buf();
    fs::create_dir_all(root.join("src")).unwrap();
    fs::write(root.join("src/lib.rs"), "pub fn stable() {}\n").unwrap();
    let ws = Workspace::new(root.clone());
    let db_path = root.join(".code-kb/artifact.db");
    scan_workspace(&ws, &db_path, true).expect("Scan failed");
    let installed = installed_extractor_version();

    assert!(!ensure_index_matches_extractor(&ws, &db_path, &installed).unwrap());

    {
        let conn = open_read_write(&db_path).unwrap();
        conn.execute(
            "UPDATE extraction_revisions SET binary_version = '0.0.1'",
            [],
        )
        .unwrap();
    }

    assert!(ensure_index_matches_extractor(&ws, &db_path, &installed).unwrap());

    let conn = open_read_only(&db_path).unwrap();
    let stale: i64 = conn
        .query_row(
            "SELECT COUNT(*) FROM files f JOIN extraction_revisions r ON r.revision_id = f.last_revision_id WHERE r.binary_version != ?1",
            [&installed],
            |r| r.get(0),
        )
        .unwrap();
    assert_eq!(stale, 0);
}