dissolve-python 0.3.0

A tool to dissolve deprecated calls in Python codebases
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
// Test cases for specific migration issues found in dulwich
// These tests reproduce bugs found when migrating the dulwich codebase

#[cfg(test)]
mod tests {
    use crate::core::{ConstructType, ParameterInfo, ReplaceInfo};
    use crate::migrate_ruff::migrate_file;
    use crate::tests::test_utils::TestContext;
    use crate::types::TypeIntrospectionMethod;
    use std::collections::HashMap;
    use std::path::Path;

    // Helper function to migrate source code with replacements
    fn migrate_source_with_replacements(
        source: &str,
        replacements: HashMap<String, ReplaceInfo>,
    ) -> String {
        let test_ctx = TestContext::new(source);
        let mut type_context = test_ctx.create_type_context(TypeIntrospectionMethod::PyrightLsp);
        let result = migrate_file(
            source,
            "test_module",
            Path::new(&test_ctx.file_path),
            &mut type_context,
            replacements,
            HashMap::new(),
        )
        .unwrap();
        // Keep test_ctx alive until after migration completes
        drop(test_ctx);
        result
    }

    // Helper function to create a test module with base classes
    fn create_test_with_base_classes(test_code: &str) -> String {
        format!(
            r#"
# Test base classes
class BaseRepo:
    def do_commit(self, message, **kwargs):
        pass
    
    def stage(self, fs_paths):
        pass
    
    def get_worktree(self):
        return WorkTree()
    
    def reset_index(self, tree=None):
        pass
    
    def do_something(self, **kwargs):
        pass

class WorkTree:
    def stage(self, fs_paths):
        pass
    
    def unstage(self, fs_paths):
        pass
    
    def commit(self, message=None, **kwargs):
        pass
    
    def reset_index(self, tree=None):
        pass

class Repo(BaseRepo):
    def stage(self, fs_paths):
        pass
    
    @staticmethod
    def init(path) -> 'Repo':
        return Repo()

class Index:
    def __init__(self, path):
        pass
    
    def get_entry(self, path):
        return IndexEntry()

class IndexEntry:
    def stage(self):
        return 0

{}
"#,
            test_code
        )
    }

    // Helper function to create a simple replacement info
    fn create_replacement_info(
        old_name: &str,
        replacement_expr: &str,
        parameters: Vec<&str>,
    ) -> ReplaceInfo {
        // Create a synthetic Python function to parse and extract the AST from
        // This mimics what happens in production when parsing @replace_me functions
        let param_list = parameters.join(", ");

        // Convert the replacement expression to valid Python by handling special cases
        let mut python_return = replacement_expr.to_string();

        // Handle special placeholders first
        python_return = python_return.replace("{**kwargs}", "**kwargs");
        python_return = python_return.replace("{*args}", "*args");

        // Handle parameters in the replacement - convert {param} to param
        for param in &parameters {
            let param_clean = param.trim_start_matches("**").trim_start_matches("*");
            if !param.starts_with("**") && !param.starts_with("*") {
                python_return = python_return.replace(&format!("{{{}}}", param), param_clean);
            }
        }

        // Handle any remaining placeholders
        python_return = python_return
            .replace("{self}", "self")
            .replace("{", "")
            .replace("}", "");

        // Extract just the function name (without module) for the Python function definition
        let func_name_only = old_name.split('.').next_back().unwrap_or(old_name);
        let function_code = format!(
            "def {}({}):\n    return {}",
            func_name_only, param_list, python_return
        );

        // Parse the function to get the AST
        let replacement_ast = match rustpython_parser::parse(
            &function_code,
            rustpython_parser::Mode::Module,
            "<test>",
        ) {
            Ok(rustpython_ast::Mod::Module(module)) => {
                // Extract the return statement's value
                if let Some(rustpython_ast::Stmt::FunctionDef(func)) = module.body.first() {
                    if let Some(rustpython_ast::Stmt::Return(ret)) = func.body.first() {
                        ret.value.clone()
                    } else {
                        None
                    }
                } else {
                    None
                }
            }
            _ => None,
        };

        ReplaceInfo {
            old_name: old_name.to_string(),
            replacement_expr: replacement_expr.to_string(),
            replacement_ast,
            construct_type: ConstructType::Function,
            parameters: parameters
                .iter()
                .map(|&name| {
                    if let Some(stripped) = name.strip_prefix("**") {
                        ParameterInfo::kwarg(stripped)
                    } else if let Some(stripped) = name.strip_prefix("*") {
                        ParameterInfo::vararg(stripped)
                    } else {
                        ParameterInfo::new(name)
                    }
                })
                .collect(),
            return_type: None,
            since: None,
            remove_in: None,
            message: None,
        }
    }

    #[test]
    fn test_worktree_double_access_issue() {
        // This tests the specific issue where self.worktree is already a WorkTree object,
        // so we should NOT migrate self.worktree.stage() to
        // self.worktree.get_worktree().stage()
        let test_code = r#"
def test_worktree_operations():
    # Create a WorkTree instance
    worktree: WorkTree = WorkTree()
    
    # This should NOT be migrated - worktree is already a WorkTree object
    worktree.stage(["file.txt"])
    worktree.unstage(["file.txt"])
"#;
        let source = create_test_with_base_classes(test_code);

        let mut replacements = HashMap::new();
        replacements.insert(
            "test_module.Repo.stage".to_string(),
            create_replacement_info(
                "stage",
                "{self}.get_worktree().stage({fs_paths})",
                vec!["self", "fs_paths"],
            ),
        );

        // Try with pyright which should handle self.worktree properly
        let test_ctx = TestContext::new(&source);
        let mut type_context = test_ctx.create_type_context(TypeIntrospectionMethod::PyrightLsp);
        let result = migrate_file(
            &source,
            "test_module",
            Path::new(&test_ctx.file_path),
            &mut type_context,
            replacements,
            HashMap::new(),
        )
        .unwrap();
        drop(test_ctx);

        // The migration should NOT change worktree.stage calls
        assert!(result.contains("worktree.stage"));
        assert!(result.contains("worktree.unstage"));
        assert!(!result.contains("worktree.get_worktree().stage"));
        assert!(!result.contains("worktree.get_worktree().unstage"));
    }

    #[test]
    fn test_parameter_expansion_with_kwargs() {
        // Test that parameters are correctly expanded when some are passed as kwargs
        let test_code = r#"
repo = BaseRepo()
repo.do_commit(
    b"Initial commit",
    committer=b"Test Committer <test@nodomain.com>",
    author=b"Test Author <test@nodomain.com>",
    commit_timestamp=12345,
    commit_timezone=0,
    author_timestamp=12345,
    author_timezone=0,
)
"#;
        let source = create_test_with_base_classes(test_code);

        let mut replacements = HashMap::new();
        replacements.insert(
            "test_module.BaseRepo.do_commit".to_string(),
            create_replacement_info(
                "do_commit",
                "{self}.get_worktree().commit(message={message}, {**kwargs})",
                vec!["self", "message", "**kwargs"],
            ),
        );

        let result = migrate_source_with_replacements(&source, replacements);

        // Should expand properly with all kwargs
        if !result.contains("message=b\"Initial commit\"") {
            eprintln!("Expected 'message=b\"Initial commit\"', got:\n{}", result);
        }
        assert!(result.contains("repo.get_worktree().commit("));
        assert!(result.contains("message=b\"Initial commit\""));
        assert!(result.contains("committer=b\"Test Committer <test@nodomain.com>\""));

        // Check that the migrated call doesn't have tree= parameter
        // Extract just the migrated line
        let lines: Vec<&str> = result.lines().collect();
        let commit_line = lines
            .iter()
            .find(|line| line.contains("repo.get_worktree().commit("))
            .expect("Should find the migrated commit line");
        assert!(
            !commit_line.contains("tree="),
            "The migrated commit call should not have tree= parameter"
        );
    }

    #[test]
    fn test_default_parameter_pollution() {
        // Test that we don't add unnecessary default parameters
        let test_code = r#"
repo = BaseRepo()
repo.do_commit(b"Simple commit")
"#;
        let source = create_test_with_base_classes(test_code);

        let mut replacements = HashMap::new();
        let params = vec![
            ParameterInfo {
                name: "self".to_string(),
                has_default: false,
                default_value: None,
                is_vararg: false,
                is_kwarg: false,
                is_kwonly: false,
            },
            ParameterInfo {
                name: "message".to_string(),
                has_default: true,
                default_value: Some("None".to_string()),
                is_vararg: false,
                is_kwarg: false,
                is_kwonly: false,
            },
            // Many more optional parameters...
            ParameterInfo {
                name: "tree".to_string(),
                has_default: true,
                default_value: Some("None".to_string()),
                is_vararg: false,
                is_kwarg: false,
                is_kwonly: false,
            },
            ParameterInfo {
                name: "encoding".to_string(),
                has_default: true,
                default_value: Some("None".to_string()),
                is_vararg: false,
                is_kwarg: false,
                is_kwonly: false,
            },
        ];

        replacements.insert(
            "test_module.BaseRepo.do_commit".to_string(),
            ReplaceInfo {
                old_name: "do_commit".to_string(),
                // The replacement expression should only include placeholders for params that will be provided
                replacement_expr: "{self}.get_worktree().commit(message={message})".to_string(),
                replacement_ast: None,
                construct_type: ConstructType::Function,
                parameters: params,
                return_type: None,
                since: None,
                remove_in: None,
                message: None,
            },
        );

        let result = migrate_source_with_replacements(&source, replacements);

        // Should only include the message parameter, not defaults
        assert!(result.contains("repo.get_worktree().commit(message=b\"Simple commit\")"));
        // Check that the migrated call doesn't have tree= or encoding= parameters
        let commit_call = "repo.get_worktree().commit(message=b\"Simple commit\")";
        assert!(result.contains(commit_call));
        assert!(!result.contains("commit(message=b\"Simple commit\", tree="));
        assert!(!result.contains("commit(message=b\"Simple commit\", encoding="));
    }

    #[test]
    fn test_incomplete_migration_stage_and_commit() {
        // Test that both stage and do_commit in the same block are migrated
        let test_code = r#"
# Inline the operations so pyright can track the type
r = Repo()
r.stage(["file.txt"])
r.do_commit("test commit")
"#;
        let source = create_test_with_base_classes(test_code);

        let mut replacements = HashMap::new();
        replacements.insert(
            "test_module.Repo.stage".to_string(),
            create_replacement_info(
                "stage",
                "{self}.get_worktree().stage({fs_paths})",
                vec!["self", "fs_paths"],
            ),
        );
        replacements.insert(
            "test_module.BaseRepo.do_commit".to_string(),
            create_replacement_info(
                "do_commit",
                "{self}.get_worktree().commit(message={message})",
                vec!["self", "message"],
            ),
        );

        let result = migrate_source_with_replacements(&source, replacements);

        // Both should be migrated
        if !result.contains("r.get_worktree().commit(message=\"test commit\")") {
            eprintln!("Expected commit migration, got:");
            for line in result.lines() {
                if line.contains("commit") || line.contains("do_commit") {
                    eprintln!("  {}", line);
                }
            }
        }
        assert!(result.contains("r.get_worktree().stage([\"file.txt\"])"));
        assert!(result.contains("r.get_worktree().commit(message=\"test commit\")"));
    }

    #[test]
    fn test_worktree_stage_calls() {
        // Test that worktree.stage() calls are NOT migrated
        let test_code = r#"
wt = WorkTree()
wt.stage(["file1.txt", "file2.txt"])
"#;
        let source = create_test_with_base_classes(test_code);

        let mut replacements = HashMap::new();
        replacements.insert(
            "test_module.Repo.stage".to_string(),
            create_replacement_info(
                "stage",
                "{self}.get_worktree().stage({fs_paths})",
                vec!["self", "fs_paths"],
            ),
        );

        let result = migrate_source_with_replacements(&source, replacements);

        // Should NOT be migrated - it's already a WorkTree
        assert!(result.contains("wt.stage([\"file1.txt\", \"file2.txt\"])"));
        assert!(!result.contains("wt.get_worktree()"));
    }

    #[test]
    fn test_unprovided_parameter_placeholders() {
        // Regression test: placeholders like {tree} should be removed when parameters aren't provided
        let test_code = r#"
repo = BaseRepo()
target = repo
target.reset_index()
"#;
        let source = create_test_with_base_classes(test_code);

        let mut replacements = HashMap::new();
        let params = vec![
            ParameterInfo {
                name: "self".to_string(),
                has_default: false,
                default_value: None,
                is_vararg: false,
                is_kwarg: false,
                is_kwonly: false,
            },
            ParameterInfo {
                name: "tree".to_string(),
                has_default: true,
                default_value: Some("None".to_string()),
                is_vararg: false,
                is_kwarg: false,
                is_kwonly: false,
            },
        ];

        // Create AST for the replacement expression
        let python_return = "{self}.get_worktree().reset_index({tree})"
            .replace("{self}", "self")
            .replace("{tree}", "tree");
        let function_code = format!("def reset_index(self, tree):\n    return {}", python_return);
        let replacement_ast = match rustpython_parser::parse(
            &function_code,
            rustpython_parser::Mode::Module,
            "<test>",
        ) {
            Ok(rustpython_ast::Mod::Module(module)) => {
                if let Some(rustpython_ast::Stmt::FunctionDef(func)) = module.body.first() {
                    if let Some(rustpython_ast::Stmt::Return(ret)) = func.body.first() {
                        ret.value.clone()
                    } else {
                        None
                    }
                } else {
                    None
                }
            }
            _ => None,
        };

        replacements.insert(
            "test_module.BaseRepo.reset_index".to_string(),
            ReplaceInfo {
                old_name: "reset_index".to_string(),
                replacement_expr: "{self}.get_worktree().reset_index({tree})".to_string(),
                replacement_ast,
                construct_type: ConstructType::Function,
                parameters: params,
                return_type: None,
                since: None,
                remove_in: None,
                message: None,
            },
        );

        let result = migrate_source_with_replacements(&source, replacements);

        println!("Test source:\n{}", source);
        println!("Migration result:\n{}", result);

        // Should remove the unprovided parameter placeholder
        assert!(result.contains("target.get_worktree().reset_index()"));
        assert!(!result.contains("{tree}"));
    }

    #[test]
    fn test_kwarg_pattern_detection() {
        // Test that keyword={param} patterns are correctly detected and replaced
        let test_code = r#"
def process(data, mode="fast"):
    process_v2(data, mode)
"#;
        let source = create_test_with_base_classes(test_code);

        let mut replacements = HashMap::new();
        replacements.insert(
            "test_module.process_v2".to_string(),
            create_replacement_info(
                "process_v2",
                "process_v2({data}, processing_mode={mode})",
                vec!["data", "mode"],
            ),
        );

        let result = migrate_source_with_replacements(&source, replacements);

        // Should detect and replace the keyword pattern
        assert!(result.contains("process_v2(data, processing_mode=mode)"));
    }

    #[test]
    fn test_kwargs_passthrough() {
        // Test that **kwargs are passed through correctly
        let test_code = r#"
repo = BaseRepo()
repo.do_something(a=1, b=2, c=3)
"#;
        let source = create_test_with_base_classes(test_code);

        let mut replacements = HashMap::new();
        replacements.insert(
            "test_module.BaseRepo.do_something".to_string(),
            create_replacement_info(
                "do_something",
                "{self}.new_method({**kwargs})",
                vec!["self", "**kwargs"],
            ),
        );

        let result = migrate_source_with_replacements(&source, replacements);

        assert!(result.contains("repo.new_method(a=1, b=2, c=3)"));
    }

    #[test]
    fn test_kwargs_with_dict_expansion() {
        // Test that dict expansions like **commit_kwargs are preserved
        let test_code = r#"
repo = BaseRepo()
commit_kwargs = {"author": "Test"}
repo.do_something(**commit_kwargs)
"#;
        let source = create_test_with_base_classes(test_code);

        let mut replacements = HashMap::new();
        replacements.insert(
            "test_module.BaseRepo.do_something".to_string(),
            create_replacement_info(
                "do_something",
                "{self}.new_method({**kwargs})",
                vec!["self", "**kwargs"],
            ),
        );

        let result = migrate_source_with_replacements(&source, replacements);

        // Should preserve dict expansion
        assert!(result.contains("repo.new_method(**commit_kwargs)"));
    }

    #[test]
    fn test_dict_unpacking_without_kwarg_param() {
        // Test that **dict is preserved even when function doesn't have **kwargs
        let test_code = r#"
def process_data(a, b):
    return a + b

extra_args = {"b": 2}
result = process_data(1, **extra_args)
"#;
        let source = create_test_with_base_classes(test_code);

        let mut replacements = HashMap::new();
        replacements.insert(
            "test_module.process_data".to_string(),
            create_replacement_info(
                "test_module.process_data",
                "new_process({a}, {b})",
                vec!["a", "b"],
            ),
        );

        let result = migrate_source_with_replacements(&source, replacements);

        // The dict expansion should be preserved
        // When replacing within the same module, no prefix is needed
        if !result.contains("result = new_process(1, **extra_args)") {
            eprintln!("Expected 'result = new_process(1, **extra_args)', got:");
            for line in result.lines() {
                if line.contains("new_process") {
                    eprintln!("  {}", line);
                }
            }
        }
        assert!(result.contains("result = new_process(1, **extra_args)"));
    }

    #[test]
    fn test_dict_unpacking_no_extra_comma() {
        // Test that we don't add an unnecessary comma before **kwargs when it's the only argument
        let test_code = r#"
def func(**kwargs):
    pass

d = {"key": "value"}
func(**d)
"#;
        let source = create_test_with_base_classes(test_code);

        let mut replacements = HashMap::new();
        replacements.insert(
            "test_module.func".to_string(),
            create_replacement_info("func", "new_func({**kwargs})", vec!["**kwargs"]),
        );

        let result = migrate_source_with_replacements(&source, replacements);

        assert!(result.contains("new_func(**d)"));
        assert!(!result.contains("new_func(, **d)")); // No extra comma
    }

    #[test]
    fn test_method_call_on_variable_repo() {
        // Test method calls on variables holding repo objects
        let test_code = r#"
r = BaseRepo()
r.do_commit(b"Test commit", author=b"Test Author <test@example.com>")
"#;
        let source = create_test_with_base_classes(test_code);

        let mut replacements = HashMap::new();
        replacements.insert(
            "test_module.BaseRepo.do_commit".to_string(),
            create_replacement_info(
                "do_commit",
                "{self}.get_worktree().commit(message={message}, {**kwargs})",
                vec!["self", "message", "**kwargs"],
            ),
        );

        let result = migrate_source_with_replacements(&source, replacements);

        // Different variable names should still work
        assert!(result.contains("r.get_worktree().commit("));
        // Check for the message parameter (allowing for escaped strings)
        assert!(
            result.contains("message=b\"Test")
                && (result.contains("commit\"") || result.contains("commit\""))
        );
        // Check for the author parameter (allowing for escaped strings)
        assert!(result.contains("author=b\"Test") && result.contains("example.com"));
    }

    #[test]
    fn test_import_replacement_function() {
        // Test that function imports are updated when the function is replaced
        let test_code = r#"
# Import at module level
from test_module import checkout_branch

def test_module_import():
    # Module-qualified call should be replaced with FQN
    test_module.checkout_branch(repo, "main")
    
def test_direct_call():
    # Direct call without module prefix
    checkout_branch(repo, "feature")
"#;
        let source = create_test_with_base_classes(test_code);

        let mut replacements = HashMap::new();
        replacements.insert(
            "test_module.checkout_branch".to_string(),
            create_replacement_info(
                "checkout_branch",
                "test_module.checkout({repo}, {target})",
                vec!["repo", "target"],
            ),
        );

        let result = migrate_source_with_replacements(&source, replacements);

        println!("test_import_replacement_function debug:");
        println!("{}", result);

        // The import should remain as-is since we're using FQN for the replacement
        assert!(result.contains("from test_module import checkout_branch"));

        // Module-qualified call should be replaced with FQN
        assert!(result.contains("test_module.checkout(repo, \"main\")"));

        // Direct call should also be replaced with FQN
        assert!(result.contains("test_module.checkout(repo, \"feature\")"));
    }

    #[test]
    fn test_no_migration_without_type_info() {
        // Test that without type information, we don't migrate
        // This tests the case where we can't determine the type of 'entry'
        let source = r#"
def test_unknown_type():
    # entry type is unknown - we don't know if it's IndexEntry or something else
    stage_num = entry.stage()
"#;

        let mut replacements = HashMap::new();
        replacements.insert(
            "test_module.Repo.stage".to_string(),
            create_replacement_info(
                "stage",
                "{self}.get_worktree().stage({fs_paths})",
                vec!["self", "fs_paths"],
            ),
        );

        // This should not migrate because we can't determine the type of 'entry'
        let result = migrate_source_with_replacements(source, replacements);
        assert!(result.contains("entry.stage()"));
        assert!(!result.contains("get_worktree()"));
    }

    #[test]
    fn test_method_on_known_type() {
        // Test that we DO migrate when we have type information
        let test_code = r#"
def test_repo_stage():
    repo = Repo.init(".")
    repo.stage(["file.txt"])
"#;
        let source = create_test_with_base_classes(test_code);

        let mut replacements = HashMap::new();
        replacements.insert(
            "test_module.Repo.stage".to_string(),
            create_replacement_info(
                "stage",
                "{self}.get_worktree().stage({fs_paths})",
                vec!["self", "fs_paths"],
            ),
        );

        let result = migrate_source_with_replacements(&source, replacements);

        println!("Test source:\n{}", source);
        println!("\nMigration result:\n{}", result);

        // Should be migrated because we know repo is a Repo instance
        assert!(result.contains("repo.get_worktree().stage([\"file.txt\"])"));
    }
}