code-kb-cli 1.1.1

CLI and MCP server for code-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
817
818
819
820
use std::path::Path;
use std::process::Command;

fn setup_adversarial_test_repo() -> tempfile::TempDir {
    let temp_dir = code_kb_core::safe_tempdir();
    let root = temp_dir.path().to_path_buf();

    let src_dir = root.join("src");
    std::fs::create_dir_all(&src_dir).unwrap();
    let content = "pub struct Workspace {\n    pub root: String,\n}\n\npub fn run_task() {\n    helper();\n}\n\nfn helper() {}\n";
    std::fs::write(src_dir.join("workspace.rs"), content).unwrap();

    let tests_dir = root.join("tests");
    std::fs::create_dir_all(&tests_dir).unwrap();
    let test_content = "#[test]\nfn test_run_task() {\n    run_task();\n}\n";
    std::fs::write(tests_dir.join("test_workspace.rs"), test_content).unwrap();

    // Use code-kb scan to initialize a genuine schema with artifact_metadata
    let scan_out = Command::new(env!("CARGO_BIN_EXE_code-kb"))
        .arg("--root")
        .arg(&root)
        .arg("scan")
        .output()
        .expect("Failed to initialize test repo via scan");
    assert!(
        scan_out.status.success(),
        "scan failed: {}",
        String::from_utf8_lossy(&scan_out.stderr)
    );

    // Populate a sample structural fact and literal so facts returns non-empty data with paths
    let db_path = root.join(".code-kb").join("artifact.db");
    let conn = code_kb_core::open_read_write(&db_path).unwrap();
    let file_id: String = conn
        .query_row(
            "SELECT file_id FROM files WHERE path LIKE '%workspace.rs' LIMIT 1",
            [],
            |r| r.get(0),
        )
        .unwrap();

    conn.execute(
        "INSERT INTO structural_facts (structural_fact_id, file_id, path, language, pattern_id, capture_name, node_kind, containing_symbol_id, start_line, start_column, end_line, end_column, start_byte, end_byte, confidence)
         VALUES ('sf1', ?1, 'src/workspace.rs', 'rust', 'route', 'get_index', 'route', NULL, 1, 0, 10, 1, 0, 100, 1.0)",
        [&file_id],
    )
    .unwrap();
    conn.execute(
        "INSERT INTO literals (literal_id, file_id, path, language, kind, literal_text, carrier, arg_position, containing_symbol_id, start_line, start_column, end_line, end_column, start_byte, end_byte, confidence)
         VALUES ('lit1', ?1, 'src/workspace.rs', 'rust', 'string', 'hello', 'identifier', 0, NULL, 1, 0, 1, 5, 0, 5, 1.0)",
        [&file_id],
    )
    .unwrap();

    temp_dir
}

fn invert_drive_casing(p: &Path) -> String {
    let s = p.to_string_lossy().to_string();
    if s.len() >= 2 && s.as_bytes()[1] == b':' {
        let first = s.chars().next().unwrap();
        let toggled = if first.is_ascii_uppercase() {
            first.to_ascii_lowercase()
        } else {
            first.to_ascii_uppercase()
        };
        format!("{}{}", toggled, &s[1..])
    } else {
        s
    }
}

// ============================================================================
// CHALLENGE 1: CLI Argument Path Variations Matrix
// ============================================================================
#[test]
fn test_adversarial_cli_path_variations_across_all_commands() {
    let repo = setup_adversarial_test_repo();
    let root = repo.path();
    let root_str = root.to_string_lossy().to_string();
    let inverted_root = invert_drive_casing(root);

    let abs_file = root.join("src").join("workspace.rs");
    let abs_file_str = abs_file.to_string_lossy().to_string();
    let inverted_abs_file = invert_drive_casing(&abs_file);
    let forward_abs_file = abs_file_str.replace('\\', "/");
    let file_uri_3slash = format!("file:///{}", forward_abs_file);
    let file_uri_2slash = format!("file://{}", forward_abs_file);
    let file_uri_inverted = format!("file:///{}", inverted_abs_file.replace('\\', "/"));

    let path_variations = vec![
        r"src\workspace.rs",            // native Windows backslash
        r"src/workspace.rs",            // forward slash
        r".\src/workspace.rs",          // mixed backslash and forward slash
        r"./src\workspace.rs",          // mixed forward slash and backslash
        r".\src\workspace.rs",          // dot with backslash
        r"./src/workspace.rs",          // dot with forward slash
        r"src/./workspace.rs",          // internal single dot forward
        r"src\.\workspace.rs",          // internal single dot backslash
        r"src/../src/workspace.rs",     // parent traversal forward
        r"src\..\src\workspace.rs",     // parent traversal backslash
        r".\src\..\src\.\workspace.rs", // complex mixed dots
        &abs_file_str,                  // native absolute path
        &inverted_abs_file,             // inverted drive letter absolute path
        &forward_abs_file,              // forward slash absolute path
        &file_uri_3slash,               // file:/// URI standard
        &file_uri_2slash,               // file:// URI two-slash
        &file_uri_inverted,             // file:/// URI with inverted drive letter
    ];

    for path_var in &path_variations {
        // 1. Skeleton
        let out = Command::new(env!("CARGO_BIN_EXE_code-kb"))
            .arg("--root")
            .arg(root)
            .arg("skeleton")
            .arg(path_var)
            .output()
            .unwrap_or_else(|e| panic!("Failed skeleton for '{path_var}': {e}"));
        assert!(
            out.status.success(),
            "skeleton failed for path variation '{path_var}':\nstderr: {}",
            String::from_utf8_lossy(&out.stderr)
        );
        let stdout = String::from_utf8_lossy(&out.stdout);
        assert!(
            stdout.contains("Workspace") || stdout.contains("run_task"),
            "skeleton missing symbols for '{path_var}':\n{stdout}"
        );

        // 2. Symbol with --path filter
        let out = Command::new(env!("CARGO_BIN_EXE_code-kb"))
            .arg("--root")
            .arg(root)
            .arg("symbol")
            .arg("Workspace")
            .arg("--path")
            .arg(path_var)
            .output()
            .unwrap_or_else(|e| panic!("Failed symbol for '{path_var}': {e}"));
        assert!(
            out.status.success(),
            "symbol failed for path filter '{path_var}':\nstderr: {}",
            String::from_utf8_lossy(&out.stderr)
        );
        let stdout = String::from_utf8_lossy(&out.stdout);
        assert!(
            stdout.contains("Workspace"),
            "symbol missing result for '{path_var}':\n{stdout}"
        );

        // 3. Search with --path filter
        let out = Command::new(env!("CARGO_BIN_EXE_code-kb"))
            .arg("--root")
            .arg(root)
            .arg("search")
            .arg("task")
            .arg("--path")
            .arg(path_var)
            .output()
            .unwrap_or_else(|e| panic!("Failed search for '{path_var}': {e}"));
        assert!(
            out.status.success(),
            "search failed for path filter '{path_var}':\nstderr: {}",
            String::from_utf8_lossy(&out.stderr)
        );
        let stdout = String::from_utf8_lossy(&out.stdout);
        assert!(
            stdout.contains("run_task"),
            "search missing result for '{path_var}':\n{stdout}"
        );

        // 4. Body with --file
        let out = Command::new(env!("CARGO_BIN_EXE_code-kb"))
            .arg("--root")
            .arg(root)
            .arg("body")
            .arg("run_task")
            .arg("--file")
            .arg(path_var)
            .output()
            .unwrap_or_else(|e| panic!("Failed body for '{path_var}': {e}"));
        assert!(
            out.status.success(),
            "body failed for file '{path_var}':\nstderr: {}",
            String::from_utf8_lossy(&out.stderr)
        );
        let stdout = String::from_utf8_lossy(&out.stdout);
        assert!(
            stdout.contains("helper()"),
            "body missing implementation for '{path_var}':\n{stdout}"
        );

        // 5. Slice with --file
        let out = Command::new(env!("CARGO_BIN_EXE_code-kb"))
            .arg("--root")
            .arg(root)
            .arg("slice")
            .arg("run_task")
            .arg("--file")
            .arg(path_var)
            .output()
            .unwrap_or_else(|e| panic!("Failed slice for '{path_var}': {e}"));
        assert!(
            out.status.success(),
            "slice failed for file '{path_var}':\nstderr: {}",
            String::from_utf8_lossy(&out.stderr)
        );
        let stdout = String::from_utf8_lossy(&out.stdout);
        assert!(
            stdout.contains("helper"),
            "slice missing callee for '{path_var}':\n{stdout}"
        );

        // 6. Blast radius with --file
        let out = Command::new(env!("CARGO_BIN_EXE_code-kb"))
            .arg("--root")
            .arg(root)
            .arg("blast-radius")
            .arg("helper")
            .arg("--file")
            .arg(path_var)
            .output()
            .unwrap_or_else(|e| panic!("Failed blast-radius for '{path_var}': {e}"));
        assert!(
            out.status.success(),
            "blast-radius failed for file '{path_var}':\nstderr: {}",
            String::from_utf8_lossy(&out.stderr)
        );
        let stdout = String::from_utf8_lossy(&out.stdout);
        assert!(
            stdout.contains("run_task"),
            "blast-radius missing impacted symbol for '{path_var}':\n{stdout}"
        );
    }

    // 7. Outline with scoped path variations
    let outline_path_vars = vec![
        r"src",
        r"src\",
        r"src/",
        r".\src",
        r"./src",
        r"src\..\src",
        &inverted_root,
    ];
    for opv in outline_path_vars {
        let out = Command::new(env!("CARGO_BIN_EXE_code-kb"))
            .arg("--root")
            .arg(root)
            .arg("outline")
            .arg("-p")
            .arg(opv)
            .output()
            .unwrap_or_else(|e| panic!("Failed outline -p '{opv}': {e}"));
        assert!(
            out.status.success(),
            "outline failed for path filter '{opv}':\nstderr: {}",
            String::from_utf8_lossy(&out.stderr)
        );
    }

    // 8. Global root casing, slashes, and trailing separators
    let root_variations = vec![
        root_str.clone(),
        inverted_root.clone(),
        format!(r"{}\", root_str.trim_end_matches('\\')),
        format!("{}/", root_str.replace('\\', "/")),
    ];
    for rv in root_variations {
        let out = Command::new(env!("CARGO_BIN_EXE_code-kb"))
            .arg("--root")
            .arg(&rv)
            .arg("symbol")
            .arg("Workspace")
            .output()
            .unwrap_or_else(|e| panic!("Failed symbol with root '{rv}': {e}"));
        assert!(
            out.status.success(),
            "symbol failed with root '{rv}':\nstderr: {}",
            String::from_utf8_lossy(&out.stderr)
        );
    }

    // 9. Atomic edit with backslash, mixed slash, dot traversal, and absolute paths
    let edit_file_vars = [
        r"src\workspace.rs",
        r".\src/workspace.rs",
        r"src/../src/workspace.rs",
        &abs_file_str,
        &inverted_abs_file,
    ];
    for (i, ef) in edit_file_vars.iter().enumerate() {
        let new_body = format!("{{\n    // edit variation {}\n}}", i);
        let out = Command::new(env!("CARGO_BIN_EXE_code-kb"))
            .arg("--root")
            .arg(root)
            .arg("edit")
            .arg("helper")
            .arg("--file")
            .arg(ef)
            .arg("--body")
            .arg(&new_body)
            .output()
            .unwrap_or_else(|e| panic!("Failed edit for '{ef}': {e}"));
        assert!(
            out.status.success(),
            "edit failed for file path variation '{ef}':\nstderr: {}",
            String::from_utf8_lossy(&out.stderr)
        );
        let stdout = String::from_utf8_lossy(&out.stdout);
        assert!(
            stdout.contains("Successfully replaced body"),
            "edit missing success message for '{ef}':\n{stdout}"
        );
    }
}

// ============================================================================
// CHALLENGE 2: Strict Forward-Slash Assertions on CLI --json Output
// ============================================================================
#[test]
fn test_adversarial_cli_json_strict_forward_slash_across_all_commands() {
    let repo = setup_adversarial_test_repo();
    let root = repo.path();
    let abs_file = root.join("src").join("workspace.rs");
    let abs_file_str = abs_file.to_string_lossy().to_string();
    let file_uri_3slash = format!("file:///{}", abs_file_str.replace('\\', "/"));

    fn assert_all_paths_forward_slash(val: &serde_json::Value, found_paths: &mut usize) {
        match val {
            serde_json::Value::Object(map) => {
                for (k, v) in map {
                    let k_lower = k.to_ascii_lowercase();
                    if (k_lower.contains("path") || k_lower.contains("file")) && v.is_string() {
                        let s = v.as_str().unwrap();
                        assert!(
                            !s.contains('\\'),
                            "Key '{k}' contains backslash in JSON output: '{s}'"
                        );
                        assert!(
                            !s.starts_with(r"\\?\"),
                            "Key '{k}' contains verbatim prefix in JSON output: '{s}'"
                        );
                        *found_paths += 1;
                    }
                    assert_all_paths_forward_slash(v, found_paths);
                }
            }
            serde_json::Value::Array(arr) => {
                for item in arr {
                    assert_all_paths_forward_slash(item, found_paths);
                }
            }
            _ => {}
        }
    }

    // Commands tested specifically with backslashes, mixed slashes, and dots in their arguments
    let mut test_cases: Vec<(Vec<String>, bool)> = vec![
        // (cmd_args, expect_paths)
        (vec!["--json".into(), "outline".into()], true),
        (
            vec![
                "--json".into(),
                "outline".into(),
                "-p".into(),
                r"src\workspace.rs".into(),
            ],
            true,
        ),
        (
            vec![
                "--json".into(),
                "outline".into(),
                "-p".into(),
                r".\src/workspace.rs".into(),
            ],
            true,
        ),
        (
            vec![
                "--json".into(),
                "skeleton".into(),
                r"src\workspace.rs".into(),
            ],
            true,
        ),
        (
            vec![
                "--json".into(),
                "skeleton".into(),
                r".\src/workspace.rs".into(),
            ],
            true,
        ),
        (
            vec![
                "--json".into(),
                "skeleton".into(),
                r"src/../src/workspace.rs".into(),
            ],
            true,
        ),
        (
            vec![
                "--json".into(),
                "symbol".into(),
                "Workspace".into(),
                "--path".into(),
                r"src\workspace.rs".into(),
            ],
            true,
        ),
        (
            vec![
                "--json".into(),
                "symbol".into(),
                "Workspace".into(),
                "--path".into(),
                r".\src/workspace.rs".into(),
            ],
            true,
        ),
        (
            vec![
                "--json".into(),
                "search".into(),
                "Workspace".into(),
                "--path".into(),
                r"src\workspace.rs".into(),
            ],
            true,
        ),
        (
            vec![
                "--json".into(),
                "body".into(),
                "run_task".into(),
                "--file".into(),
                r"src\workspace.rs".into(),
            ],
            true,
        ),
        (
            vec![
                "--json".into(),
                "body".into(),
                "run_task".into(),
                "--file".into(),
                r".\src/workspace.rs".into(),
            ],
            true,
        ),
        (
            vec![
                "--json".into(),
                "slice".into(),
                "run_task".into(),
                "--file".into(),
                r"src\workspace.rs".into(),
            ],
            true,
        ),
        (
            vec![
                "--json".into(),
                "slice".into(),
                "run_task".into(),
                "--file".into(),
                r".\src/workspace.rs".into(),
            ],
            true,
        ),
        (vec!["--json".into(), "refs".into(), "helper".into()], true),
        (
            vec![
                "--json".into(),
                "blast-radius".into(),
                "helper".into(),
                "--file".into(),
                r"src\workspace.rs".into(),
            ],
            true,
        ),
        (
            vec![
                "--json".into(),
                "blast-radius".into(),
                "helper".into(),
                "--file".into(),
                r".\src/workspace.rs".into(),
            ],
            true,
        ),
        (vec!["--json".into(), "facts".into()], false), // Category listing has no path fields
        (vec!["--json".into(), "facts".into(), "route".into()], true), // Facts query returns structural_facts and literals with paths
        (
            vec![
                "--json".into(),
                "edit".into(),
                "helper".into(),
                "--file".into(),
                r"src\workspace.rs".into(),
                "--body".into(),
                "{\n    // json edit test\n}".into(),
            ],
            true,
        ),
        (vec!["--json".into(), "stats".into()], false), // Stats output has counts, no paths
    ];

    // File URI and absolute path JSON queries
    test_cases.push((
        vec!["--json".into(), "skeleton".into(), file_uri_3slash.clone()],
        true,
    ));
    test_cases.push((
        vec!["--json".into(), "skeleton".into(), abs_file_str.clone()],
        true,
    ));
    test_cases.push((
        vec![
            "--json".into(),
            "body".into(),
            "run_task".into(),
            "--file".into(),
            file_uri_3slash.clone(),
        ],
        true,
    ));
    test_cases.push((
        vec![
            "--json".into(),
            "slice".into(),
            "run_task".into(),
            "--file".into(),
            file_uri_3slash.clone(),
        ],
        true,
    ));
    test_cases.push((
        vec![
            "--json".into(),
            "symbol".into(),
            "Workspace".into(),
            "--path".into(),
            file_uri_3slash.clone(),
        ],
        true,
    ));
    test_cases.push((
        vec![
            "--json".into(),
            "search".into(),
            "Workspace".into(),
            "--path".into(),
            file_uri_3slash.clone(),
        ],
        true,
    ));
    test_cases.push((
        vec![
            "--json".into(),
            "blast-radius".into(),
            "helper".into(),
            "--file".into(),
            file_uri_3slash,
        ],
        true,
    ));

    for (args, expect_paths) in test_cases {
        let out = Command::new(env!("CARGO_BIN_EXE_code-kb"))
            .arg("--root")
            .arg(root)
            .args(&args)
            .output()
            .unwrap_or_else(|e| panic!("Failed to execute {:?}: {e}", args));
        assert!(
            out.status.success(),
            "Command failed: {:?}\nstderr: {}",
            args,
            String::from_utf8_lossy(&out.stderr)
        );

        let val: serde_json::Value = serde_json::from_slice(&out.stdout).unwrap_or_else(|e| {
            panic!(
                "Failed to parse JSON for {:?}: {e}\nstdout: {}",
                args,
                String::from_utf8_lossy(&out.stdout)
            )
        });

        let mut found_paths = 0;
        assert_all_paths_forward_slash(&val, &mut found_paths);

        if expect_paths {
            assert!(
                found_paths > 0,
                "Expected at least 1 path field in JSON for command {:?}, but found 0.\nJSON: {}",
                args,
                serde_json::to_string_pretty(&val).unwrap()
            );
        }
    }
}

// ============================================================================
// CHALLENGE 3: Workspace strip_prefix_lossy and UNC Path Equality
// ============================================================================
#[test]
fn test_adversarial_strip_prefix_lossy_and_unc_matrix() {
    #[allow(unused_imports)]
    use code_kb_core::workspace::{paths_equal, strip_prefix_lossy};

    #[cfg(windows)]
    {
        // --- 1. UNC paths_equal matrix ---
        // Case insensitivity across server, share, and path components
        assert!(paths_equal(
            Path::new(r"\\server\share\file.rs"),
            Path::new(r"\\server\share\file.rs")
        ));
        assert!(paths_equal(
            Path::new(r"\\server\share\file.rs"),
            Path::new(r"\\SERVER\SHARE\file.rs")
        ));
        assert!(paths_equal(
            Path::new(r"\\server\share\folder\FILE.RS"),
            Path::new(r"\\SERVER\SHARE\FOLDER\file.rs")
        ));

        // Mixed slashes in UNC
        assert!(paths_equal(
            Path::new("//server/share/file.rs"),
            Path::new(r"\\server\share\file.rs")
        ));
        assert!(paths_equal(
            Path::new("//SERVER/SHARE/folder/file.rs"),
            Path::new(r"\\server\share\folder\file.rs")
        ));

        // Verbatim UNC (\\?\UNC\server\share) vs standard UNC
        assert!(paths_equal(
            Path::new(r"\\?\UNC\server\share\file.rs"),
            Path::new(r"\\server\share\file.rs")
        ));
        assert!(paths_equal(
            Path::new(r"\\?\UNC\SERVER\SHARE\file.rs"),
            Path::new(r"\\server\share\file.rs")
        ));
        assert!(paths_equal(
            Path::new(r"\\?\UNC\server\share\file.rs"),
            Path::new(r"\\SERVER\SHARE\file.rs")
        ));

        // Trailing slash on UNC directories
        assert!(paths_equal(
            Path::new(r"\\server\share\dir\"),
            Path::new(r"\\server\share\dir")
        ));

        // Negative UNC tests (different servers, different shares, different paths)
        assert!(!paths_equal(
            Path::new(r"\\server1\share\file.rs"),
            Path::new(r"\\server2\share\file.rs")
        ));
        assert!(!paths_equal(
            Path::new(r"\\server\share1\file.rs"),
            Path::new(r"\\server\share2\file.rs")
        ));
        assert!(!paths_equal(
            Path::new(r"\\server\share\file1.rs"),
            Path::new(r"\\server\share\file2.rs")
        ));

        // --- 2. UNC strip_prefix_lossy matrix ---
        let unc_base = Path::new(r"\\server\share\repo");
        assert_eq!(
            strip_prefix_lossy(Path::new(r"\\server\share\repo\src\lib.rs"), unc_base),
            Some(Path::new(r"src\lib.rs"))
        );
        // Casing in server/share
        assert_eq!(
            strip_prefix_lossy(Path::new(r"\\SERVER\SHARE\repo\src\lib.rs"), unc_base),
            Some(Path::new(r"src\lib.rs"))
        );
        // Casing in repo folder
        assert_eq!(
            strip_prefix_lossy(Path::new(r"\\SERVER\SHARE\REPO\src\lib.rs"), unc_base),
            Some(Path::new(r"src\lib.rs"))
        );
        // Base with trailing slash
        assert_eq!(
            strip_prefix_lossy(
                Path::new(r"\\server\share\repo\src\lib.rs"),
                Path::new(r"\\server\share\repo\")
            ),
            Some(Path::new(r"src\lib.rs"))
        );
        // Verbatim UNC path
        assert_eq!(
            strip_prefix_lossy(Path::new(r"\\?\UNC\server\share\repo\src\lib.rs"), unc_base),
            Some(Path::new(r"src\lib.rs"))
        );
        // Verbatim UNC base
        assert_eq!(
            strip_prefix_lossy(
                Path::new(r"\\server\share\repo\src\lib.rs"),
                Path::new(r"\\?\UNC\server\share\repo")
            ),
            Some(Path::new(r"src\lib.rs"))
        );
        // Negative UNC non-matching
        assert_eq!(
            strip_prefix_lossy(Path::new(r"\\server\other_share\repo\src\lib.rs"), unc_base),
            None
        );
        assert_eq!(
            strip_prefix_lossy(Path::new(r"\\other_server\share\repo\src\lib.rs"), unc_base),
            None
        );

        // --- 3. Windows drive roots strip_prefix_lossy matrix ---
        let drive_root = Path::new(r"C:\");
        assert_eq!(
            strip_prefix_lossy(Path::new(r"C:\src\lib.rs"), drive_root),
            Some(Path::new(r"src\lib.rs"))
        );
        // Drive letter casing on drive root
        assert_eq!(
            strip_prefix_lossy(Path::new(r"c:\src\lib.rs"), drive_root),
            Some(Path::new(r"src\lib.rs"))
        );
        // Inverted drive root base
        assert_eq!(
            strip_prefix_lossy(Path::new(r"C:\src\lib.rs"), Path::new(r"c:\")),
            Some(Path::new(r"src\lib.rs"))
        );
        // Root stripped from itself
        assert_eq!(
            strip_prefix_lossy(Path::new(r"C:\"), drive_root),
            Some(Path::new(""))
        );

        // --- 4. Verbatim disk prefixes strip_prefix_lossy ---
        let win_base = Path::new(r"C:\source\code-kb");
        assert_eq!(
            strip_prefix_lossy(
                Path::new(r"C:\source\code-kb\src\lib.rs"),
                Path::new(r"\\?\C:\source\code-kb")
            ),
            Some(Path::new(r"src\lib.rs"))
        );
        assert_eq!(
            strip_prefix_lossy(
                Path::new(r"C:\source\code-kb\src\lib.rs"),
                Path::new(r"\\?\c:\source\code-kb")
            ),
            Some(Path::new(r"src\lib.rs"))
        );
        assert_eq!(
            strip_prefix_lossy(
                Path::new(r"\\?\C:\source\code-kb\src\lib.rs"),
                Path::new(r"\\?\c:\source\code-kb")
            ),
            Some(Path::new(r"src\lib.rs"))
        );
        // Additional paths_equal drive root and trailing slash invariants
        assert!(paths_equal(Path::new(r"c:\repo\"), Path::new(r"C:\repo")));
        assert!(paths_equal(Path::new(r"c:\"), Path::new(r"C:\")));
        assert!(paths_equal(
            Path::new(r"\\server\share\"),
            Path::new(r"\\SERVER\SHARE")
        ));

        // UNC directory casing in strip_prefix_lossy
        assert_eq!(
            strip_prefix_lossy(
                Path::new(r"\\server\share\MY_DIR\file.rs"),
                Path::new(r"\\server\share\my_dir")
            ),
            Some(Path::new(r"file.rs"))
        );

        // Verbatim base with trailing slash
        assert_eq!(
            strip_prefix_lossy(
                Path::new(r"\\?\C:\source\code-kb\src\lib.rs"),
                Path::new(r"\\?\C:\source\code-kb\")
            ),
            Some(Path::new(r"src\lib.rs"))
        );
        assert_eq!(
            strip_prefix_lossy(
                Path::new(r"C:\source\code-kb\src\lib.rs"),
                Path::new(r"\\?\c:\source\code-kb\")
            ),
            Some(Path::new(r"src\lib.rs"))
        );

        // Shorter path than base
        assert_eq!(strip_prefix_lossy(Path::new(r"C:\source"), win_base), None);
    }

    // Relative path tests (all platforms)
    assert_eq!(
        strip_prefix_lossy(Path::new("src/lib.rs"), Path::new("src")),
        Some(Path::new("lib.rs"))
    );
    assert_eq!(
        strip_prefix_lossy(Path::new("src/lib.rs"), Path::new("src/")),
        Some(Path::new("lib.rs"))
    );
    assert_eq!(
        strip_prefix_lossy(Path::new("src/lib.rs"), Path::new("other")),
        None
    );
}