devscout-rs 0.9.0

Fast code index for C# and TypeScript codebases -- map, find, refs, impact from the CLI.
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
use super::*;
use std::collections::HashMap;
use std::fs;

mod qualified_receiver;

// --- The v13 cache generation --------------------------

#[test]
fn rebuild_graph_writes_the_v13_caches_and_deletes_every_superseded_generation() {
    let dir = temp_dir("rebuild-v13");
    fs::create_dir_all(graph_dir(&dir)).unwrap();
    // The v9 pair joined this list when fragments gained def
    // `typeParams`/`baseGenericArgs` and the `ctor-param` ref kind, so a v9
    // fragment read back today carries none and every ctor-DI fact would be
    // missing from the graph. The v10 pair joined when a markup
    // fragment gained the `x:Class` def and its element/binding refs, so a
    // v10 markup fragment read back carries names only and every XAML
    // declaration and instantiation would be missing from the graph. The v11
    // pair joined when a `.ts/.tsx/.js/.jsx` file gained a reference
    // fragment where it previously had none at all, so a v11 cache read back
    // would leave every TS/JS rel looking like a file the worker never saw.
    // This side records no TS fragment yet, but the cache generation is
    // shared -- two writers putting two generations into one git dir would
    // have each delete the other's cache on every map. The v12 pair joined
    // when defs gained propertyTypes and refs
    // gained receiverPropertyOwner and the receiverCallOwner/
    // receiverCallMember pair, so a v12 fragment read back carries none and
    // every property hop and every var-from-invocation receiver would
    // silently stay unresolved.
    assert_eq!(SUPERSEDED_CACHE_FILES.len(), 64, "v1..v32 pairs");
    for stale in SUPERSEDED_CACHE_FILES {
        fs::write(graph_dir(&dir).join(stale), b"{}").unwrap();
    }

    let fragment = Fragment {
        defs: vec![FragDef {
            id: "App.A".into(),
            name: "A".into(),
            namespace: "App".into(),
            kind: "class".into(),
            line: 1,
            methods: vec![],
            properties: vec![],
            fields: vec![],
            method_returns: OrderedMap::new(),
            extension_methods: vec![],
            bases: vec![],
            type_params: vec![],
            base_generic_args: OrderedMap::new(),
            test_methods: vec![],
            property_types: OrderedMap::new(),
            field_types: OrderedMap::new(),
            method_return_args: OrderedMap::new(),
            non_public_methods: vec![],
            method_arities: OrderedMap::new(),
            method_type_arities: OrderedMap::new(),
            method_type_param_sites: OrderedMap::new(),
            method_params: OrderedMap::new(),
            override_methods: vec![],
            base_type_args: OrderedMap::new(),
            property_message_args: Vec::new(),
            array_message_bases: Vec::new(),
            delegate_signature: None,
            end_line: 1,
        }],
        usings: vec![],
        refs: vec![],
        names: vec![],
        registrations: vec![],
        publishes: vec![],
        handler_registrations: vec![],
    };
    let mut fresh = HashMap::new();
    fresh.insert("src/A.cs".to_string(), AnyFragment::Cs(fragment));
    let graph_files = vec![GraphFile {
        rel: "src/A.cs".to_string(),
        mtime: 222,
    }];
    rebuild_graph(&dir, &graph_files, &fresh, true, None, None).unwrap();

    assert!(
        graph_dir(&dir).join("fragments-v33.json").exists(),
        "the v33 payload cache is what gets written"
    );
    assert!(
        graph_dir(&dir).join("fragments-index-v33.json").exists(),
        "and its mtime-only index alongside it"
    );
    for stale in SUPERSEDED_CACHE_FILES {
        assert!(
            !graph_dir(&dir).join(stale).exists(),
            "{stale} must be deleted -- rename IS the invalidation"
        );
    }
}

// --- The v33 cache generation --------------------------

#[test]
fn fragments_cache_v33_supersedes_earlier_generations() {
    let dir = temp_dir("fragments-cache-v33-paths");
    assert_eq!(
        fragments_cache_path(&dir),
        graph_dir(&dir).join("fragments-v33.json")
    );
    assert_eq!(
        fragments_index_path(&dir),
        graph_dir(&dir).join("fragments-index-v33.json")
    );
    assert!(
        SUPERSEDED_CACHE_FILES.contains(&"fragments-v26.json"),
        "v26 joined the superseded list when the v29 bump landed"
    );
    assert!(
        SUPERSEDED_CACHE_FILES.contains(&"fragments-index-v26.json"),
        "its index pairs with it, same as every other generation"
    );
    for generation in ["v27", "v28", "v29", "v30", "v31", "v32"] {
        assert!(SUPERSEDED_CACHE_FILES.contains(&format!("fragments-{generation}.json").as_str()));
        assert!(
            SUPERSEDED_CACHE_FILES.contains(&format!("fragments-index-{generation}.json").as_str())
        );
    }

    let dir = temp_dir("rebuild-v33");
    fs::create_dir_all(graph_dir(&dir)).unwrap();
    fs::write(graph_dir(&dir).join("fragments-v32.json"), b"{}").unwrap();
    fs::write(graph_dir(&dir).join("fragments-index-v32.json"), b"{}").unwrap();

    let fragment = Fragment {
        defs: vec![],
        usings: vec![],
        refs: vec![],
        names: vec![],
        registrations: vec![],
        publishes: vec![],
        handler_registrations: vec![],
    };
    let mut fresh = HashMap::new();
    fresh.insert("src/A.cs".to_string(), AnyFragment::Cs(fragment));
    let graph_files = vec![GraphFile {
        rel: "src/A.cs".to_string(),
        mtime: 1,
    }];
    rebuild_graph(&dir, &graph_files, &fresh, true, None, None).unwrap();

    assert!(graph_dir(&dir).join("fragments-v33.json").exists());
    assert!(graph_dir(&dir).join("fragments-index-v33.json").exists());
    assert!(
        !graph_dir(&dir).join("fragments-v32.json").exists(),
        "the v32 pair is deleted -- rename IS the invalidation"
    );
    assert!(!graph_dir(&dir).join("fragments-index-v32.json").exists());
}

// A Rust fragment an earlier generation wrote, at the same mtime as the
// fresh one: it names an item the fresh fragment lacks, so reading it would
// show in the graph.
#[test]
fn a_planted_earlier_rust_pair_is_never_read_and_is_removed() {
    for generation in [
        "-v25", "-v26", "-v27", "-v28", "-v29", "-v30", "-v31", "-v32",
    ] {
        let dir = temp_dir(&format!("planted{generation}-rust-pair"));
        fs::create_dir_all(graph_dir(&dir)).unwrap();
        let planted = serde_json::to_string(&serde_json::json!({
            "src/lib.rs": {"mtime": 5, "fragment": {"rs": 1, "items": [
                {"name": "stale", "kind": "fn", "path": "stale", "line": 1, "nameLine": 1, "endLine": 1}
            ]}},
        }))
        .unwrap();
        plant_cache_pair(&dir, &planted, r#"{"src/lib.rs":5}"#, generation);

        let mut fresh = HashMap::new();
        fresh.insert(
            "src/lib.rs".to_string(),
            AnyFragment::Rs(crate::extract::RsFragment::default()),
        );
        let graph_files = vec![GraphFile {
            rel: "src/lib.rs".to_string(),
            mtime: 5,
        }];
        let g = match rebuild_graph(&dir, &graph_files, &fresh, true, None, None).unwrap() {
            RebuildOutcome::Rebuilt(g) => g,
            RebuildOutcome::NotRebuilt => unreachable!("changed is true"),
        };
        assert!(g.defs.iter().all(|d| d.name != "stale"), "{generation}");
        assert!(graph_dir(&dir).join("fragments-v33.json").exists());
        assert!(graph_dir(&dir).join("fragments-index-v33.json").exists());
        assert!(!graph_dir(&dir)
            .join(format!("fragments{generation}.json"))
            .exists());
        assert!(!graph_dir(&dir)
            .join(format!("fragments-index{generation}.json"))
            .exists());
    }
}

fn planted_def_fragment() -> Fragment {
    Fragment {
        defs: vec![FragDef {
            id: "App.Planted".into(),
            name: "Planted".into(),
            namespace: "App".into(),
            kind: "class".into(),
            line: 1,
            methods: vec![],
            properties: vec![],
            fields: vec![],
            method_returns: OrderedMap::new(),
            extension_methods: vec![],
            bases: vec![],
            type_params: vec![],
            base_generic_args: OrderedMap::new(),
            test_methods: vec![],
            property_types: OrderedMap::new(),
            field_types: OrderedMap::new(),
            method_return_args: OrderedMap::new(),
            non_public_methods: vec![],
            method_arities: OrderedMap::new(),
            method_type_arities: OrderedMap::new(),
            method_type_param_sites: OrderedMap::new(),
            method_params: OrderedMap::new(),
            override_methods: vec![],
            base_type_args: OrderedMap::new(),
            property_message_args: Vec::new(),
            array_message_bases: Vec::new(),
            delegate_signature: None,
            end_line: 1,
        }],
        usings: vec![],
        refs: vec![],
        names: vec![],
        registrations: vec![],
        publishes: vec![],
        handler_registrations: vec![],
    }
}

fn rebuilt_over_a_planted_pair(label: &str, generation: &str) -> (std::path::PathBuf, Graph) {
    let dir = temp_dir(label);
    fs::create_dir_all(graph_dir(&dir)).unwrap();
    let planted = serde_json::to_string(&serde_json::json!({
        "src/A.cs": {"mtime": 5, "fragment": planted_def_fragment()},
    }))
    .unwrap();
    plant_cache_pair(&dir, &planted, r#"{"src/A.cs":5}"#, generation);

    let fresh_fragment = Fragment {
        defs: vec![],
        usings: vec![],
        refs: vec![],
        names: vec![],
        registrations: vec![],
        publishes: vec![],
        handler_registrations: vec![],
    };
    let mut fresh = HashMap::new();
    fresh.insert("src/A.cs".to_string(), AnyFragment::Cs(fresh_fragment));
    let graph_files = vec![GraphFile {
        rel: "src/A.cs".to_string(),
        mtime: 5,
    }];
    let g = match rebuild_graph(&dir, &graph_files, &fresh, true, None, None).unwrap() {
        RebuildOutcome::Rebuilt(g) => g,
        RebuildOutcome::NotRebuilt => unreachable!("changed is true"),
    };
    (dir, g)
}

#[test]
fn a_planted_v32_pair_is_never_read_and_is_removed() {
    let (dir, g) = rebuilt_over_a_planted_pair("planted-v32-pair", "-v32");
    assert!(
        g.defs.iter().all(|d| d.id != "App.Planted"),
        "the previous generation's entry is never reused, even at a matching mtime"
    );
    assert!(graph_dir(&dir).join("fragments-v33.json").exists());
    assert!(graph_dir(&dir).join("fragments-index-v33.json").exists());
    assert!(!graph_dir(&dir).join("fragments-v32.json").exists());
    assert!(!graph_dir(&dir).join("fragments-index-v32.json").exists());

    // The same entry at the current generation is reused on its matching
    // mtime, so the rename, not the payload, is what keeps it out.
    let (_, control) = rebuilt_over_a_planted_pair("planted-v33-pair", "-v33");
    assert!(control.defs.iter().any(|d| d.id == "App.Planted"));
}

// --- The rename as the bus-hop invalidation ------------------------------

// Cache payloads here are built as JSON rather than as struct literals
// because the entry under test is one an OLDER generation wrote: it has to
// be missing a field the current type has, which no literal can express.
fn cs_def(id: &str, name: &str) -> serde_json::Value {
    serde_json::json!({
        "id": id,
        "name": name,
        "namespace": "App.Bus",
        "kind": "class",
        "line": 1,
        "methods": [],
    })
}

fn message_and_consumer() -> Vec<(String, AnyFragment)> {
    let consumer = serde_json::json!({
        "id": "App.Bus.Handler",
        "name": "Handler",
        "namespace": "App.Bus",
        "kind": "class",
        "line": 1,
        "methods": [],
        "bases": ["IConsumer"],
        "baseGenericArgs": {"IConsumer": ["LoanRequested"]},
    });
    vec![
        (
            "Bus/Messages.cs".to_string(),
            cs_fragment(serde_json::json!({
                "defs": [cs_def("App.Bus.LoanRequested", "LoanRequested")],
                "usings": [],
                "refs": [],
            })),
        ),
        (
            "Bus/Consumers.cs".to_string(),
            cs_fragment(serde_json::json!({
                "defs": [consumer],
                "usings": [],
                "refs": [],
            })),
        ),
    ]
}

fn publisher_with_publish() -> serde_json::Value {
    serde_json::json!({
        "defs": [cs_def("App.Bus.Publisher", "Publisher")],
        "usings": [],
        "refs": [],
        "publishes": [{
            "verb": "Publish",
            "message": "LoanRequested",
            "namespace": "App.Bus",
            "line": 10,
        }],
    })
}

// The same file as the previous generation recorded it: parsed, so its
// mtime is current and the entry looks reusable, but carrying no publish
// key at all because the field did not exist when it was written.
fn publisher_without_publishes() -> serde_json::Value {
    serde_json::json!({
        "defs": [cs_def("App.Bus.Publisher", "Publisher")],
        "usings": [],
        "refs": [],
    })
}

fn cs_fragment(value: serde_json::Value) -> AnyFragment {
    serde_json::from_value(value).unwrap()
}

fn plant_cache_pair(dir: &std::path::Path, payload: &str, index: &str, generation: &str) {
    fs::write(
        graph_dir(dir).join(format!("fragments{generation}.json")),
        payload,
    )
    .unwrap();
    fs::write(
        graph_dir(dir).join(format!("fragments-index{generation}.json")),
        index,
    )
    .unwrap();
}

fn bus_files() -> Vec<GraphFile> {
    ["Bus/Messages.cs", "Bus/Consumers.cs", "Bus/Publisher.cs"]
        .iter()
        .map(|rel| GraphFile {
            rel: (*rel).to_string(),
            mtime: 7,
        })
        .collect()
}

fn fresh_bus_fragments() -> HashMap<String, AnyFragment> {
    let mut fresh: HashMap<String, AnyFragment> = message_and_consumer().into_iter().collect();
    fresh.insert(
        "Bus/Publisher.cs".to_string(),
        cs_fragment(publisher_with_publish()),
    );
    fresh
}

fn rebuilt(dir: &std::path::Path) -> Graph {
    match rebuild_graph(dir, &bus_files(), &fresh_bus_fragments(), true, None, None).unwrap() {
        RebuildOutcome::Rebuilt(g) => g,
        RebuildOutcome::NotRebuilt => unreachable!("changed is true"),
    }
}

fn hop_count(g: &Graph) -> usize {
    g.edges
        .iter()
        .filter(|e| matches!(e, Edge::BusHop { .. }))
        .count()
}

#[test]
fn a_pre_bump_fragment_cache_cannot_leave_a_supported_hop_unfound() {
    let stale = serde_json::to_string(&serde_json::json!({
        "Bus/Publisher.cs": {"mtime": 7, "fragment": publisher_without_publishes()},
    }))
    .unwrap();
    let index = r#"{"Bus/Publisher.cs":7}"#;

    let dir = temp_dir("bus-hop-pre-bump-cache");
    fs::create_dir_all(graph_dir(&dir)).unwrap();
    plant_cache_pair(&dir, &stale, index, "-v21");
    let g = rebuilt(&dir);
    assert_eq!(
        hop_count(&g),
        1,
        "the publish fact comes from this run's extraction, never from the older generation"
    );
    assert_eq!(g.stats.edges_by_kind.bus_hop, Some(1));
    assert!(!graph_dir(&dir).join("fragments-v21.json").exists());

    // The control: the identical entry sitting at the CURRENT generation is
    // reused on its matching mtime and the hop goes missing with nothing on
    // disk to show for it. That is the loss the rename prevents, so this
    // half fails the moment the rename is reverted.
    let reused = temp_dir("bus-hop-current-generation-cache");
    fs::create_dir_all(graph_dir(&reused)).unwrap();
    plant_cache_pair(&reused, &stale, index, "-v33");
    let g = rebuilt(&reused);
    assert_eq!(hop_count(&g), 0);
    assert_eq!(g.stats.edges_by_kind.bus_hop, None);
}

#[test]
fn a_rebuild_with_no_publish_site_writes_no_bus_hop_counter_at_all() {
    let dir = temp_dir("bus-hop-counter-absent");
    let files: Vec<GraphFile> = message_and_consumer()
        .iter()
        .map(|(rel, _)| GraphFile {
            rel: rel.clone(),
            mtime: 7,
        })
        .collect();
    let fresh: HashMap<String, AnyFragment> = message_and_consumer().into_iter().collect();
    let g = match rebuild_graph(&dir, &files, &fresh, true, None, None).unwrap() {
        RebuildOutcome::Rebuilt(g) => g,
        RebuildOutcome::NotRebuilt => unreachable!("changed is true"),
    };

    assert_eq!(hop_count(&g), 0);
    assert_eq!(g.stats.edges_by_kind.bus_hop, None);
    let written = fs::read_to_string(graph_dir(&dir).join("graph.json")).unwrap();
    assert!(
        !written.contains("bus-hop"),
        "an absent key, not a zero -- a zero would move every bus-free artifact's bytes"
    );
}

// --- The v22 generation carried no array fact ----------------------------

fn array_message_and_consumers() -> Vec<(String, AnyFragment)> {
    let array_consumer = serde_json::json!({
        "id": "App.Bus.ArrayHandler",
        "name": "ArrayHandler",
        "namespace": "App.Bus",
        "kind": "class",
        "line": 1,
        "methods": [],
        "bases": ["IConsumer"],
        "baseGenericArgs": {"IConsumer": ["Foo"]},
        "arrayMessageBases": ["IConsumer"],
    });
    let single_consumer = serde_json::json!({
        "id": "App.Bus.SingleHandler",
        "name": "SingleHandler",
        "namespace": "App.Bus",
        "kind": "class",
        "line": 1,
        "methods": [],
        "bases": ["IConsumer"],
        "baseGenericArgs": {"IConsumer": ["Foo"]},
    });
    vec![
        (
            "Bus/Messages.cs".to_string(),
            cs_fragment(serde_json::json!({
                "defs": [cs_def("App.Bus.Foo", "Foo")],
                "usings": [],
                "refs": [],
            })),
        ),
        (
            "Bus/Consumers.cs".to_string(),
            cs_fragment(serde_json::json!({
                "defs": [array_consumer, single_consumer],
                "usings": [],
                "refs": [],
            })),
        ),
    ]
}

fn array_publisher_with_publish() -> serde_json::Value {
    serde_json::json!({
        "defs": [cs_def("App.Bus.Publisher", "Publisher")],
        "usings": [],
        "refs": [],
        "publishes": [{
            "verb": "Publish",
            "message": "Foo[]",
            "namespace": "App.Bus",
            "line": 10,
        }],
    })
}

// The same consumer file as a v22 cache would have recorded it: parsed, so
// its mtime is current and the entry looks reusable, but with no
// `arrayMessageBases` key at all -- v22 never wrote one, so `ArrayHandler`
// reads back indistinguishable from `SingleHandler`.
fn array_consumers_without_array_message_bases() -> serde_json::Value {
    serde_json::json!({
        "defs": [
            {
                "id": "App.Bus.ArrayHandler",
                "name": "ArrayHandler",
                "namespace": "App.Bus",
                "kind": "class",
                "line": 1,
                "methods": [],
                "bases": ["IConsumer"],
                "baseGenericArgs": {"IConsumer": ["Foo"]},
            },
            {
                "id": "App.Bus.SingleHandler",
                "name": "SingleHandler",
                "namespace": "App.Bus",
                "kind": "class",
                "line": 1,
                "methods": [],
                "bases": ["IConsumer"],
                "baseGenericArgs": {"IConsumer": ["Foo"]},
            },
        ],
        "usings": [],
        "refs": [],
    })
}

fn array_bus_files() -> Vec<GraphFile> {
    ["Bus/Messages.cs", "Bus/Consumers.cs", "Bus/Publisher.cs"]
        .iter()
        .map(|rel| GraphFile {
            rel: (*rel).to_string(),
            mtime: 7,
        })
        .collect()
}

fn fresh_array_bus_fragments() -> HashMap<String, AnyFragment> {
    let mut fresh: HashMap<String, AnyFragment> =
        array_message_and_consumers().into_iter().collect();
    fresh.insert(
        "Bus/Publisher.cs".to_string(),
        cs_fragment(array_publisher_with_publish()),
    );
    fresh
}

fn array_handler_names(g: &Graph) -> Vec<String> {
    let mut names: Vec<String> = g
        .edges
        .iter()
        .filter_map(|e| match e {
            Edge::BusHop { to, .. } => Some(
                to.rsplit_once('.')
                    .map_or(to.clone(), |(_, t)| t.to_string()),
            ),
            _ => None,
        })
        .collect();
    names.sort();
    names
}

#[test]
fn a_warm_v22_cache_is_rebuilt_rather_than_read_without_array_facts() {
    let stale = serde_json::to_string(&serde_json::json!({
        "Bus/Consumers.cs": {"mtime": 7, "fragment": array_consumers_without_array_message_bases()},
    }))
    .unwrap();
    let index = r#"{"Bus/Consumers.cs":7}"#;

    let dir = temp_dir("bus-array-warm-v22-cache");
    fs::create_dir_all(graph_dir(&dir)).unwrap();
    plant_cache_pair(&dir, &stale, index, "-v22");
    let g = match rebuild_graph(
        &dir,
        &array_bus_files(),
        &fresh_array_bus_fragments(),
        true,
        None,
        None,
    )
    .unwrap()
    {
        RebuildOutcome::Rebuilt(g) => g,
        RebuildOutcome::NotRebuilt => unreachable!("changed is true"),
    };
    assert_eq!(
        array_handler_names(&g),
        vec!["ArrayHandler".to_string()],
        "a fresh extraction, never the warm v22 payload, is what decides the array \
         consumer's own identity"
    );
    assert!(!graph_dir(&dir).join("fragments-v22.json").exists());

    // The control: the SAME degraded entry, planted at the CURRENT
    // generation and reused on its matching mtime, loses the array bit --
    // both handlers then read as plain `Foo` consumers, so the `Foo[]`
    // publish's own identity (rank 1) matches NEITHER of them and the
    // array route silently disappears. That is the loss the rename
    // prevents, so this half fails the moment the rename is reverted.
    let reused = temp_dir("bus-array-current-generation-cache");
    fs::create_dir_all(graph_dir(&reused)).unwrap();
    plant_cache_pair(&reused, &stale, index, "-v33");
    let g = match rebuild_graph(
        &reused,
        &array_bus_files(),
        &fresh_array_bus_fragments(),
        true,
        None,
        None,
    )
    .unwrap()
    {
        RebuildOutcome::Rebuilt(g) => g,
        RebuildOutcome::NotRebuilt => unreachable!("changed is true"),
    };
    assert_eq!(
        array_handler_names(&g),
        Vec::<String>::new(),
        "reusing a degraded entry at the current generation is exactly the loss the rename \
         prevents: the array bit is gone, so the array publish's own identity (rank 1) \
         matches neither handler's now-plain (rank 0) identity, and the route silently \
         disappears rather than reaching ArrayHandler"
    );
}