tldr-cli 0.1.5

CLI binary for TLDR code analysis tool
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
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
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
//! L5 Class-Level Diff Tests
//!
//! These tests define the expected behavior for `--granularity class` in the
//! `tldr diff` command. They reference types and functions that DO NOT EXIST
//! yet (DiffGranularity, BaseChanges, ASTChange.children, NodeKind::Field,
//! run_class_diff). They are designed to fail at compilation until the L5
//! implementation is complete.
//!
//! Spec: thoughts/shared/plans/multi-level-diff-spec.md, Section 4.1
//!
//! Algorithm summary:
//! 1. Parse both files, extract ClassInfo (via ModuleInfo)
//! 2. Match classes by name (exact -> rename detection -> insert/delete)
//! 3. For matched pairs: diff methods, diff fields, diff bases
//! 4. Unmatched classes = Insert/Delete
//! 5. Output: DiffReport with nested ASTChange children for member changes

use std::io::Write;
use std::path::PathBuf;

use tempfile::NamedTempFile;

// Existing types
use tldr_cli::commands::remaining::types::{
    ASTChange, ChangeType, DiffReport, DiffSummary, Location, NodeKind,
};

// New types that will be added for L5 (these imports will fail until implemented)
use tldr_cli::commands::remaining::types::{BaseChanges, DiffGranularity};

// The class-level diff entry point (will be added to diff module)
use tldr_cli::commands::remaining::diff::run_class_diff;

// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------

/// Create a temporary Python file from an inline source string.
fn write_temp_py(content: &str) -> NamedTempFile {
    let mut f = NamedTempFile::with_suffix(".py").unwrap();
    write!(f, "{}", content).unwrap();
    f
}

/// Convenience: run class-level diff on two inline Python source strings.
/// Returns the DiffReport for assertion.
fn diff_classes(source_a: &str, source_b: &str) -> DiffReport {
    let file_a = write_temp_py(source_a);
    let file_b = write_temp_py(source_b);
    run_class_diff(
        &PathBuf::from(file_a.path()),
        &PathBuf::from(file_b.path()),
        false, // semantic_only
    )
    .expect("run_class_diff should succeed")
}

/// Find a change in the report by name and change_type.
fn find_change<'a>(
    changes: &'a [ASTChange],
    name: &str,
    change_type: ChangeType,
) -> Option<&'a ASTChange> {
    changes
        .iter()
        .find(|c| c.change_type == change_type && c.name.as_deref() == Some(name))
}

/// Find a child change within a parent ASTChange by name and change_type.
fn find_child_change<'a>(
    parent: &'a ASTChange,
    name: &str,
    change_type: ChangeType,
) -> Option<&'a ASTChange> {
    parent.children.as_ref().and_then(|children| {
        children
            .iter()
            .find(|c| c.change_type == change_type && c.name.as_deref() == Some(name))
    })
}

// ===========================================================================
// Test 1: Identical classes
// ===========================================================================

#[test]
fn test_class_identical() {
    let source = r#"
class Calculator:
    """A simple calculator."""

    def __init__(self, value=0):
        self.value = value

    def add(self, x):
        self.value += x
        return self

    def result(self):
        return self.value
"#;

    let report = diff_classes(source, source);

    assert!(report.identical, "Identical class files should produce identical=true");
    assert!(
        report.changes.is_empty(),
        "Identical class files should have zero changes, got {}",
        report.changes.len()
    );
    assert_eq!(
        report.granularity,
        DiffGranularity::Class,
        "Report granularity should be Class"
    );
}

// ===========================================================================
// Test 2: Class with a method added
// ===========================================================================

#[test]
fn test_class_method_added() {
    let source_a = r#"
class Calculator:
    def __init__(self, value=0):
        self.value = value

    def add(self, x):
        self.value += x
        return self
"#;

    let source_b = r#"
class Calculator:
    def __init__(self, value=0):
        self.value = value

    def add(self, x):
        self.value += x
        return self

    def subtract(self, x):
        self.value -= x
        return self
"#;

    let report = diff_classes(source_a, source_b);

    assert!(!report.identical, "Files should not be identical");

    // Top-level: Calculator class is Updated (its members changed)
    let calc_change = find_change(&report.changes, "Calculator", ChangeType::Update)
        .expect("Calculator should appear as an Update change");
    assert_eq!(calc_change.node_kind, NodeKind::Class);

    // Children: subtract method was inserted
    let children = calc_change
        .children
        .as_ref()
        .expect("Updated class should have children vec");
    let subtract_insert = find_child_change(calc_change, "subtract", ChangeType::Insert)
        .expect("subtract method should be an Insert child");
    assert_eq!(subtract_insert.node_kind, NodeKind::Method);

    // Existing methods (__init__, add) should NOT appear as changes
    assert!(
        find_child_change(calc_change, "__init__", ChangeType::Update).is_none(),
        "__init__ did not change, should not appear in children"
    );
    assert!(
        find_child_change(calc_change, "add", ChangeType::Update).is_none(),
        "add did not change, should not appear in children"
    );
}

// ===========================================================================
// Test 3: Class with a method removed
// ===========================================================================

#[test]
fn test_class_method_removed() {
    let source_a = r#"
class Logger:
    def info(self, msg):
        print(f"INFO: {msg}")

    def debug(self, msg):
        print(f"DEBUG: {msg}")

    def trace(self, msg):
        print(f"TRACE: {msg}")
"#;

    let source_b = r#"
class Logger:
    def info(self, msg):
        print(f"INFO: {msg}")

    def debug(self, msg):
        print(f"DEBUG: {msg}")
"#;

    let report = diff_classes(source_a, source_b);

    assert!(!report.identical);

    let logger_change = find_change(&report.changes, "Logger", ChangeType::Update)
        .expect("Logger should appear as Update");
    assert_eq!(logger_change.node_kind, NodeKind::Class);

    let trace_delete = find_child_change(logger_change, "trace", ChangeType::Delete)
        .expect("trace method should be a Delete child");
    assert_eq!(trace_delete.node_kind, NodeKind::Method);

    // info and debug unchanged
    assert!(find_child_change(logger_change, "info", ChangeType::Update).is_none());
    assert!(find_child_change(logger_change, "debug", ChangeType::Update).is_none());
}

// ===========================================================================
// Test 4: Class with a method body updated
// ===========================================================================

#[test]
fn test_class_method_updated() {
    let source_a = r#"
class Formatter:
    def format(self, text):
        return text.strip()

    def validate(self, text):
        return len(text) > 0
"#;

    let source_b = r#"
class Formatter:
    def format(self, text):
        return text.strip().lower()

    def validate(self, text):
        return len(text) > 0
"#;

    let report = diff_classes(source_a, source_b);

    assert!(!report.identical);

    let fmt_change = find_change(&report.changes, "Formatter", ChangeType::Update)
        .expect("Formatter should appear as Update");

    let format_update = find_child_change(fmt_change, "format", ChangeType::Update)
        .expect("format method should be an Update child");
    assert_eq!(format_update.node_kind, NodeKind::Method);

    // The updated method should have a similarity score between 0.0 and 1.0
    let sim = format_update
        .similarity
        .expect("Updated method should have a similarity score");
    assert!(
        sim > 0.0 && sim < 1.0,
        "Similarity for modified method should be between 0 and 1, got {}",
        sim
    );

    // validate was not changed
    assert!(find_child_change(fmt_change, "validate", ChangeType::Update).is_none());
}

// ===========================================================================
// Test 5: Class with a field added
// ===========================================================================

#[test]
fn test_class_field_added() {
    let source_a = r#"
class Config:
    debug = False

    def __init__(self):
        self.name = "default"
"#;

    let source_b = r#"
class Config:
    debug = False
    verbose = True

    def __init__(self):
        self.name = "default"
"#;

    let report = diff_classes(source_a, source_b);

    assert!(!report.identical);

    let config_change = find_change(&report.changes, "Config", ChangeType::Update)
        .expect("Config should appear as Update");

    let verbose_insert = find_child_change(config_change, "verbose", ChangeType::Insert)
        .expect("verbose field should be an Insert child");
    assert_eq!(
        verbose_insert.node_kind,
        NodeKind::Field,
        "Inserted field should have NodeKind::Field"
    );
}

// ===========================================================================
// Test 6: Class with a field removed
// ===========================================================================

#[test]
fn test_class_field_removed() {
    let source_a = r#"
class Settings:
    timeout = 30
    retries = 3
    verbose = False
"#;

    let source_b = r#"
class Settings:
    timeout = 30
    retries = 3
"#;

    let report = diff_classes(source_a, source_b);

    assert!(!report.identical);

    let settings_change = find_change(&report.changes, "Settings", ChangeType::Update)
        .expect("Settings should appear as Update");

    let verbose_delete = find_child_change(settings_change, "verbose", ChangeType::Delete)
        .expect("verbose field should be a Delete child");
    assert_eq!(verbose_delete.node_kind, NodeKind::Field);
}

// ===========================================================================
// Test 7: Class base classes changed
// ===========================================================================

#[test]
fn test_class_base_changed() {
    let source_a = r#"
class MyWidget(BaseWidget, Serializable):
    def render(self):
        pass
"#;

    let source_b = r#"
class MyWidget(BaseWidget, Cacheable):
    def render(self):
        pass
"#;

    let report = diff_classes(source_a, source_b);

    assert!(!report.identical);

    let widget_change = find_change(&report.changes, "MyWidget", ChangeType::Update)
        .expect("MyWidget should appear as Update (bases changed)");

    let base_changes = widget_change
        .base_changes
        .as_ref()
        .expect("Updated class with base changes should have base_changes field");

    assert!(
        base_changes.removed.contains(&"Serializable".to_string()),
        "Serializable should be in removed bases, got: {:?}",
        base_changes.removed
    );
    assert!(
        base_changes.added.contains(&"Cacheable".to_string()),
        "Cacheable should be in added bases, got: {:?}",
        base_changes.added
    );

    // BaseWidget is in both, should not appear in changes
    assert!(
        !base_changes.removed.contains(&"BaseWidget".to_string()),
        "BaseWidget is unchanged, should not be in removed"
    );
    assert!(
        !base_changes.added.contains(&"BaseWidget".to_string()),
        "BaseWidget is unchanged, should not be in added"
    );
}

// ===========================================================================
// Test 8: New class inserted
// ===========================================================================

#[test]
fn test_class_inserted() {
    let source_a = r#"
class Alpha:
    def run(self):
        return 1
"#;

    let source_b = r#"
class Alpha:
    def run(self):
        return 1

class Beta:
    def run(self):
        return 2
"#;

    let report = diff_classes(source_a, source_b);

    assert!(!report.identical);

    // Alpha should be unchanged (no entry or identical)
    assert!(
        find_change(&report.changes, "Alpha", ChangeType::Update).is_none(),
        "Alpha is unchanged, should not appear as Update"
    );
    assert!(
        find_change(&report.changes, "Alpha", ChangeType::Delete).is_none(),
        "Alpha exists in both, should not be Delete"
    );

    // Beta is new
    let beta_insert = find_change(&report.changes, "Beta", ChangeType::Insert)
        .expect("Beta should appear as Insert");
    assert_eq!(beta_insert.node_kind, NodeKind::Class);
    assert!(
        beta_insert.new_location.is_some(),
        "Inserted class should have new_location"
    );
    assert!(
        beta_insert.old_location.is_none(),
        "Inserted class should not have old_location"
    );
}

// ===========================================================================
// Test 9: Class deleted
// ===========================================================================

#[test]
fn test_class_deleted() {
    let source_a = r#"
class Keeper:
    def keep(self):
        return True

class Disposable:
    def dispose(self):
        return False
"#;

    let source_b = r#"
class Keeper:
    def keep(self):
        return True
"#;

    let report = diff_classes(source_a, source_b);

    assert!(!report.identical);

    // Keeper unchanged
    assert!(find_change(&report.changes, "Keeper", ChangeType::Update).is_none());

    // Disposable deleted
    let disposable_delete = find_change(&report.changes, "Disposable", ChangeType::Delete)
        .expect("Disposable should appear as Delete");
    assert_eq!(disposable_delete.node_kind, NodeKind::Class);
    assert!(
        disposable_delete.old_location.is_some(),
        "Deleted class should have old_location"
    );
    assert!(
        disposable_delete.new_location.is_none(),
        "Deleted class should not have new_location"
    );
}

// ===========================================================================
// Test 10: Class renamed (body similar, name different)
// ===========================================================================

#[test]
fn test_class_renamed() {
    let source_a = r#"
class OldProcessor:
    def __init__(self):
        self.count = 0

    def process(self, item):
        self.count += 1
        return item.upper()

    def get_count(self):
        return self.count
"#;

    let source_b = r#"
class NewProcessor:
    def __init__(self):
        self.count = 0

    def process(self, item):
        self.count += 1
        return item.upper()

    def get_count(self):
        return self.count
"#;

    let report = diff_classes(source_a, source_b);

    assert!(!report.identical);

    // Should be detected as a rename, not as delete+insert
    let rename_change = find_change(&report.changes, "OldProcessor", ChangeType::Rename)
        .expect("OldProcessor should appear as Rename");
    assert_eq!(rename_change.node_kind, NodeKind::Class);

    // old_text should be the old name, new_text should be the new name
    assert_eq!(
        rename_change.old_text.as_deref(),
        Some("OldProcessor"),
        "old_text should be the old class name"
    );
    assert_eq!(
        rename_change.new_text.as_deref(),
        Some("NewProcessor"),
        "new_text should be the new class name"
    );

    // Similarity should be high (>= 0.8) since only the name changed
    let sim = rename_change
        .similarity
        .expect("Renamed class should have similarity score");
    assert!(
        sim >= 0.8,
        "Rename similarity should be >= 0.8 for identical bodies, got {}",
        sim
    );

    // Should NOT also appear as separate delete + insert
    assert!(
        find_change(&report.changes, "OldProcessor", ChangeType::Delete).is_none(),
        "Renamed class should not also appear as Delete"
    );
    assert!(
        find_change(&report.changes, "NewProcessor", ChangeType::Insert).is_none(),
        "Renamed class should not also appear as Insert"
    );
}

// ===========================================================================
// Test 11: Multiple classes - mixed changes
// ===========================================================================

#[test]
fn test_multiple_classes() {
    let source_a = r#"
class Unchanged:
    def method_a(self):
        return "a"

class Modified:
    def old_method(self):
        return "old"

    def shared_method(self):
        return "shared"

class Removed:
    def goodbye(self):
        return "bye"
"#;

    let source_b = r#"
class Unchanged:
    def method_a(self):
        return "a"

class Modified:
    def new_method(self):
        return "new"

    def shared_method(self):
        return "shared"

class Added:
    def hello(self):
        return "hi"
"#;

    let report = diff_classes(source_a, source_b);

    assert!(!report.identical);

    // 1. Unchanged should NOT appear in changes
    assert!(
        find_change(&report.changes, "Unchanged", ChangeType::Update).is_none(),
        "Unchanged class should not appear in changes"
    );
    assert!(
        find_change(&report.changes, "Unchanged", ChangeType::Insert).is_none(),
        "Unchanged class should not appear as Insert"
    );
    assert!(
        find_change(&report.changes, "Unchanged", ChangeType::Delete).is_none(),
        "Unchanged class should not appear as Delete"
    );

    // 2. Modified should appear as Update with method changes
    let modified_change = find_change(&report.changes, "Modified", ChangeType::Update)
        .expect("Modified should appear as Update");
    assert_eq!(modified_change.node_kind, NodeKind::Class);

    let children = modified_change
        .children
        .as_ref()
        .expect("Modified class should have children");

    // old_method was deleted (only in source_a)
    let old_method_delete = find_child_change(modified_change, "old_method", ChangeType::Delete);
    // new_method was inserted (only in source_b)
    let new_method_insert = find_child_change(modified_change, "new_method", ChangeType::Insert);

    // Either old_method is deleted and new_method is inserted,
    // OR old_method was renamed to new_method (body differs, so likely delete+insert)
    // The algorithm should detect at least one of these patterns
    let has_delete_insert = old_method_delete.is_some() && new_method_insert.is_some();
    let has_rename = children
        .iter()
        .any(|c| c.change_type == ChangeType::Rename);
    assert!(
        has_delete_insert || has_rename,
        "old_method->new_method should be detected as either delete+insert or rename"
    );

    // shared_method is unchanged within Modified
    assert!(
        find_child_change(modified_change, "shared_method", ChangeType::Update).is_none(),
        "shared_method did not change, should not appear"
    );

    // 3. Removed class was deleted
    let removed_delete = find_change(&report.changes, "Removed", ChangeType::Delete)
        .expect("Removed should appear as Delete");
    assert_eq!(removed_delete.node_kind, NodeKind::Class);

    // 4. Added class was inserted
    let added_insert = find_change(&report.changes, "Added", ChangeType::Insert)
        .expect("Added should appear as Insert");
    assert_eq!(added_insert.node_kind, NodeKind::Class);

    // Verify summary counts make sense
    if let Some(ref summary) = report.summary {
        assert!(
            summary.total_changes >= 3,
            "Should have at least 3 changes (Modified update, Removed delete, Added insert), got {}",
            summary.total_changes
        );
    }
}

// ===========================================================================
// Test 12: DiffReport has correct granularity field
// ===========================================================================

#[test]
fn test_report_granularity_field() {
    let source = r#"
class Foo:
    pass
"#;
    let report = diff_classes(source, source);

    assert_eq!(
        report.granularity,
        DiffGranularity::Class,
        "Class diff report should have granularity=Class"
    );
}

// ===========================================================================
// Test 13: Class with both method and field changes
// ===========================================================================

#[test]
fn test_class_method_and_field_changes() {
    let source_a = r#"
class Service:
    timeout = 30

    def connect(self):
        return True
"#;

    let source_b = r#"
class Service:
    timeout = 60
    max_retries = 3

    def connect(self):
        return True

    def disconnect(self):
        return False
"#;

    let report = diff_classes(source_a, source_b);

    assert!(!report.identical);

    let service_change = find_change(&report.changes, "Service", ChangeType::Update)
        .expect("Service should appear as Update");

    let children = service_change
        .children
        .as_ref()
        .expect("Service should have children");

    // Should have field changes (max_retries added, timeout possibly updated)
    let has_field_changes = children.iter().any(|c| c.node_kind == NodeKind::Field);
    assert!(
        has_field_changes,
        "Should detect field-level changes in children"
    );

    // max_retries is a new field
    let max_retries_insert = find_child_change(service_change, "max_retries", ChangeType::Insert);
    assert!(
        max_retries_insert.is_some(),
        "max_retries field should be detected as Insert"
    );
    if let Some(field_change) = max_retries_insert {
        assert_eq!(field_change.node_kind, NodeKind::Field);
    }

    // disconnect is a new method
    let disconnect_insert = find_child_change(service_change, "disconnect", ChangeType::Insert);
    assert!(
        disconnect_insert.is_some(),
        "disconnect method should be detected as Insert"
    );
    if let Some(method_change) = disconnect_insert {
        assert_eq!(method_change.node_kind, NodeKind::Method);
    }
}

// ===========================================================================
// Test 14: Empty classes
// ===========================================================================

#[test]
fn test_empty_class_to_populated() {
    let source_a = r#"
class Stub:
    pass
"#;

    let source_b = r#"
class Stub:
    value = 42

    def compute(self):
        return self.value * 2
"#;

    let report = diff_classes(source_a, source_b);

    assert!(!report.identical);

    let stub_change = find_change(&report.changes, "Stub", ChangeType::Update)
        .expect("Stub should appear as Update");

    let children = stub_change
        .children
        .as_ref()
        .expect("Stub should have children for added members");

    // Should have at least a field insert and a method insert
    let field_inserts: Vec<_> = children
        .iter()
        .filter(|c| c.change_type == ChangeType::Insert && c.node_kind == NodeKind::Field)
        .collect();
    let method_inserts: Vec<_> = children
        .iter()
        .filter(|c| c.change_type == ChangeType::Insert && c.node_kind == NodeKind::Method)
        .collect();

    assert!(
        !field_inserts.is_empty(),
        "Should detect field insertion (value)"
    );
    assert!(
        !method_inserts.is_empty(),
        "Should detect method insertion (compute)"
    );
}

// ===========================================================================
// Test 15: Base changes only (no method/field changes)
// ===========================================================================

#[test]
fn test_base_change_only() {
    let source_a = r#"
class Handler(BaseHandler):
    def handle(self):
        return "handled"
"#;

    let source_b = r#"
class Handler(BaseHandler, Loggable):
    def handle(self):
        return "handled"
"#;

    let report = diff_classes(source_a, source_b);

    assert!(!report.identical);

    let handler_change = find_change(&report.changes, "Handler", ChangeType::Update)
        .expect("Handler should appear as Update (base changed)");

    let base_changes = handler_change
        .base_changes
        .as_ref()
        .expect("Handler should have base_changes");

    assert!(
        base_changes.added.contains(&"Loggable".to_string()),
        "Loggable should be in added bases"
    );
    assert!(
        base_changes.removed.is_empty(),
        "No bases were removed, got: {:?}",
        base_changes.removed
    );

    // Methods are unchanged, so children should be None or empty
    let has_method_changes = handler_change
        .children
        .as_ref()
        .map(|c| !c.is_empty())
        .unwrap_or(false);
    assert!(
        !has_method_changes,
        "No method/field changes, children should be empty or None"
    );
}