{{ message }}
Repository navigation
Expand file tree
/
Copy pathomp_init_test.rs
More file actions
863 lines (786 loc) · 26.7 KB
/
Copy pathomp_init_test.rs
File metadata and controls
863 lines (786 loc) · 26.7 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
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
857
858
859
860
861
862
863
//! End-to-end coverage for the Pi/Oh My Pi extension lifecycle.
use std::path::Path;
use std::process::Output;
#[cfg(unix)]
use std::os::unix::fs::symlink;
use tempfile::TempDir;
mod common;
fn run_rtk(cwd: &Path, agent_dir: &Path, args: &[&str]) -> Output {
common::rtk_command()
.env("LC_ALL", "C")
.env("HOME", cwd.join("home"))
.env("PI_CODING_AGENT_DIR", agent_dir)
.args(args)
.current_dir(cwd)
.output()
.expect("spawn rtk")
}
#[cfg(unix)]
fn run_rtk_without_agent_dir(cwd: &Path, args: &[&str]) -> Output {
common::rtk_command()
.env("LC_ALL", "C")
.env("HOME", cwd.join("home"))
.env_remove("PI_CODING_AGENT_DIR")
.args(args)
.current_dir(cwd)
.output()
.expect("spawn rtk")
}
fn stdout(output: &Output) -> String {
String::from_utf8_lossy(&output.stdout).into_owned()
}
fn stderr(output: &Output) -> String {
String::from_utf8_lossy(&output.stderr).into_owned()
}
#[test]
fn omp_dry_run_missing_includes_footer() {
let project = tempfile::tempdir().unwrap();
let agent_dir = project.path().join("omp-agent");
let output = run_rtk(
project.path(),
&agent_dir,
&[
"init",
"--agent",
"omp",
"--global",
"--uninstall",
"--dry-run",
],
);
assert!(
output.status.success(),
"OMP dry-run failed: {}",
stderr(&output)
);
assert!(
stdout(&output).contains("[dry-run] Nothing written."),
"missing dry-run footer: {}",
stdout(&output)
);
}
#[test]
fn omp_dry_run_stock_includes_footer_and_real_uninstall_mentions_restart() {
let project = tempfile::tempdir().unwrap();
let agent_dir = project.path().join("omp-agent");
let pi_install = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "pi", "--global"],
);
assert!(
pi_install.status.success(),
"Pi install failed: {}",
stderr(&pi_install)
);
let install = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "omp", "--global"],
);
assert!(
install.status.success(),
"OMP install failed: {}",
stderr(&install)
);
assert!(stderr(&install).contains("share the global extension path"));
let dry_run = run_rtk(
project.path(),
&agent_dir,
&[
"init",
"--agent",
"omp",
"--global",
"--uninstall",
"--dry-run",
],
);
assert!(
dry_run.status.success(),
"OMP uninstall dry-run failed: {}",
stderr(&dry_run)
);
assert!(
stdout(&dry_run).contains("[dry-run] would prompt before removing shared Pi/OMP extension")
);
assert!(stdout(&dry_run).contains("[dry-run] Nothing written."));
let skipped = run_rtk(
project.path(),
&agent_dir,
&[
"init",
"--agent",
"omp",
"--global",
"--uninstall",
"--no-patch",
],
);
assert!(
!skipped.status.success(),
"OMP uninstall skip unexpectedly succeeded: {}",
stderr(&skipped)
);
assert!(!stdout(&skipped).contains("Skipped removal of shared Pi/OMP extension"));
assert!(stderr(&skipped).contains("was not removed"));
assert!(agent_dir.join("extensions/rtk.ts").exists());
let uninstall = run_rtk(
project.path(),
&agent_dir,
&[
"init",
"--agent",
"omp",
"--global",
"--uninstall",
"--auto-patch",
],
);
assert!(
uninstall.status.success(),
"OMP uninstall failed: {}",
stderr(&uninstall)
);
assert!(stdout(&uninstall).contains("Restart OMP to apply changes."));
assert!(stderr(&uninstall).contains("share the global extension path"));
assert!(!agent_dir.join("extensions/rtk.ts").exists());
}
#[test]
fn pi_dry_run_modified_extension_previews_confirmation_without_error() {
let project = tempfile::tempdir().unwrap();
let agent_dir = project.path().join("pi-agent");
let extension_dir = project.path().join(".pi/extensions");
std::fs::create_dir_all(&extension_dir).unwrap();
let extension = extension_dir.join("rtk.ts");
let original = "// user-modified extension\nexport default () => {}\n";
std::fs::write(&extension, original).unwrap();
let output = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "pi", "--dry-run"],
);
assert!(
output.status.success(),
"Pi dry-run failed: {}",
stderr(&output)
);
assert!(stdout(&output).contains("[dry-run] would prompt before overwriting"));
assert!(stdout(&output).contains("[dry-run] Nothing written."));
assert_eq!(std::fs::read_to_string(&extension).unwrap(), original);
let auto_dry_run = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "pi", "--auto-patch", "--dry-run"],
);
assert!(
auto_dry_run.status.success(),
"Pi auto-patch dry-run failed: {}",
stderr(&auto_dry_run)
);
assert!(stdout(&auto_dry_run).contains("[dry-run] would overwrite non-stock"));
assert!(stdout(&auto_dry_run).contains("[dry-run] would update Pi extension"));
assert_eq!(std::fs::read_to_string(&extension).unwrap(), original);
let auto = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "pi", "--auto-patch"],
);
assert!(
auto.status.success(),
"Pi auto-patch failed: {}",
stderr(&auto)
);
assert_eq!(
std::fs::read_to_string(extension).unwrap(),
include_str!("../hooks/pi/rtk.ts")
);
}
#[test]
fn pi_relocated_global_ignores_project_omp_config_when_sidecar_is_definitive() {
let project = tempfile::tempdir().unwrap();
let agent_dir = project.path().join("pi-agent");
let install = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "pi", "--global"],
);
assert!(
install.status.success(),
"Pi global install failed: {}",
stderr(&install)
);
assert!(!stderr(&install).contains("share the global extension path"));
std::fs::create_dir_all(project.path().join(".omp")).unwrap();
let uninstall = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "pi", "--global", "--uninstall"],
);
assert!(
uninstall.status.success(),
"Pi global uninstall unexpectedly prompted or failed: {}",
stderr(&uninstall)
);
assert!(!agent_dir.join("extensions/rtk.ts").exists());
}
#[test]
fn relocated_omp_ownership_is_tracked_symmetrically() {
let project = tempfile::tempdir().unwrap();
let agent_dir = project.path().join("omp-agent");
let extension = agent_dir.join("extensions/rtk.ts");
let ownership = agent_dir.join("extensions/.rtk-agents");
let omp_install = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "omp", "--global"],
);
assert!(
omp_install.status.success(),
"OMP global install failed: {}",
stderr(&omp_install)
);
assert!(!stderr(&omp_install).contains("share the global extension path"));
assert_eq!(std::fs::read_to_string(&ownership).unwrap(), "omp\n");
let pi_uninstall = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "pi", "--global", "--uninstall"],
);
assert!(
!pi_uninstall.status.success(),
"Pi uninstall unexpectedly removed an OMP-owned shared extension: {}",
stderr(&pi_uninstall)
);
assert!(stderr(&pi_uninstall).contains("share the global extension path"));
assert!(extension.exists());
let omp_uninstall = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "omp", "--global", "--uninstall"],
);
assert!(
omp_uninstall.status.success(),
"OMP-only uninstall failed: {}",
stderr(&omp_uninstall)
);
assert!(!stderr(&omp_uninstall).contains("share the global extension path"));
assert!(!extension.exists());
assert!(!ownership.exists());
}
#[test]
fn relocated_global_legacy_fallback_warns_but_proceeds() {
let project = tempfile::tempdir().unwrap();
let agent_dir = project.path().join("pi-agent");
let extension_dir = agent_dir.join("extensions");
let extension = extension_dir.join("rtk.ts");
std::fs::create_dir_all(&extension_dir).unwrap();
std::fs::write(&extension, include_str!("../hooks/pi/rtk.ts")).unwrap();
std::fs::create_dir_all(project.path().join(".omp")).unwrap();
let uninstall = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "pi", "--global", "--uninstall"],
);
assert!(
uninstall.status.success(),
"legacy global uninstall unexpectedly used project-local OMP config: {}",
stderr(&uninstall)
);
assert!(!stderr(&uninstall).contains("share the global extension path"));
assert!(!extension.exists());
std::fs::write(&extension, include_str!("../hooks/pi/rtk.ts")).unwrap();
std::fs::create_dir_all(project.path().join("home/.omp")).unwrap();
let fallback = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "pi", "--global", "--uninstall"],
);
assert!(
fallback.status.success(),
"home-level OMP fallback should not block a legacy uninstall: {}",
stderr(&fallback)
);
assert!(stderr(&fallback).contains("could not confirm both agents' ownership"));
assert!(stderr(&fallback).contains("proceeding with Pi uninstall"));
assert!(!extension.exists());
}
#[test]
fn preexisting_shared_extension_without_sidecar_stays_uncertain() {
let project = TempDir::new().unwrap();
let agent_dir = project.path().join("pi-agent");
let extension = agent_dir.join("extensions/rtk.ts");
let ownership = agent_dir.join("extensions/.rtk-agents");
std::fs::create_dir_all(extension.parent().unwrap()).unwrap();
std::fs::write(&extension, include_str!("../hooks/pi/rtk.ts")).unwrap();
let install = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "omp", "--global"],
);
assert!(
install.status.success(),
"OMP install failed: {}",
stderr(&install)
);
assert!(stderr(&install).contains("pre-existing extension has no ownership record"));
assert!(
!ownership.exists(),
"a pre-existing extension without ownership must not become OMP-only"
);
let uninstall = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "pi", "--global", "--uninstall"],
);
assert!(
uninstall.status.success(),
"uncertain legacy uninstall should proceed: {}",
stderr(&uninstall)
);
assert!(stderr(&uninstall).contains("could not confirm both agents' ownership"));
assert!(!extension.exists());
}
#[test]
fn unreadable_ownership_sidecar_warns_without_erasing_state() {
let project = TempDir::new().unwrap();
let agent_dir = project.path().join("omp-agent");
let extension = agent_dir.join("extensions/rtk.ts");
let ownership = agent_dir.join("extensions/.rtk-agents");
let pi_install = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "pi", "--global"],
);
assert!(
pi_install.status.success(),
"Pi install failed: {}",
stderr(&pi_install)
);
std::fs::write(&ownership, [0xff, 0xfe, 0xfd]).unwrap();
let omp_install = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "omp", "--global"],
);
assert!(
omp_install.status.success(),
"OMP install should not be blocked by an unreadable ownership sidecar: {}",
stderr(&omp_install)
);
assert!(stderr(&omp_install).contains("ownership state"));
assert!(stderr(&omp_install).contains("treating ownership as unknown"));
assert!(stderr(&omp_install).contains("could not be updated because ownership is unknown"));
assert_eq!(std::fs::read(&ownership).unwrap(), [0xff, 0xfe, 0xfd]);
assert!(extension.exists());
let pi_uninstall = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "pi", "--global", "--uninstall"],
);
assert!(
pi_uninstall.status.success(),
"unknown ownership should warn and proceed with explicit uninstall: {}",
stderr(&pi_uninstall)
);
assert!(stderr(&pi_uninstall).contains("could not confirm both agents' ownership"));
assert!(stderr(&pi_uninstall).contains("proceeding with Pi uninstall"));
assert!(!extension.exists());
assert!(!ownership.exists());
}
#[test]
fn relocated_install_reconciles_stale_ownership_after_manual_delete() {
let project = TempDir::new().unwrap();
let agent_dir = project.path().join("omp-agent");
let extension = agent_dir.join("extensions/rtk.ts");
let ownership = agent_dir.join("extensions/.rtk-agents");
for agent in ["pi", "omp"] {
let install = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", agent, "--global"],
);
assert!(
install.status.success(),
"{agent} install failed: {}",
stderr(&install)
);
}
assert_eq!(std::fs::read_to_string(&ownership).unwrap(), "omp\npi\n");
std::fs::remove_file(&extension).unwrap();
let reinstall = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "pi", "--global"],
);
assert!(
reinstall.status.success(),
"Pi reinstall failed: {}",
stderr(&reinstall)
);
assert_eq!(std::fs::read_to_string(&ownership).unwrap(), "pi\n");
let uninstall = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "pi", "--global", "--uninstall"],
);
assert!(
uninstall.status.success(),
"stale OMP ownership still blocked Pi uninstall: {}",
stderr(&uninstall)
);
assert!(!stderr(&uninstall).contains("share the global extension path"));
assert!(!extension.exists());
assert!(!ownership.exists());
}
#[test]
fn pi_modified_uninstall_dry_run_is_non_failing_preview() {
let project = tempfile::tempdir().unwrap();
let agent_dir = project.path().join("pi-agent");
let extension_dir = project.path().join(".pi/extensions");
std::fs::create_dir_all(&extension_dir).unwrap();
let extension = extension_dir.join("rtk.ts");
std::fs::write(
&extension,
format!(
"{}\n// user modification\n",
include_str!("../hooks/pi/rtk.ts")
),
)
.unwrap();
let output = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "pi", "--uninstall", "--dry-run"],
);
assert!(
output.status.success(),
"Pi uninstall dry-run failed: {}",
stderr(&output)
);
assert!(stdout(&output).contains("[dry-run] would refuse to remove Pi extension"));
assert!(stdout(&output).contains("[dry-run] Nothing written."));
assert!(extension.exists());
}
#[test]
fn omp_modified_uninstall_dry_run_is_non_failing_preview() {
let project = tempfile::tempdir().unwrap();
let agent_dir = project.path().join("omp-agent");
let extension_dir = project.path().join(".omp/extensions");
std::fs::create_dir_all(&extension_dir).unwrap();
let extension = extension_dir.join("rtk.ts");
std::fs::write(
&extension,
format!(
"{}\n// user modification\n",
include_str!("../hooks/pi/rtk.ts")
),
)
.unwrap();
let output = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "omp", "--uninstall", "--dry-run"],
);
assert!(
output.status.success(),
"OMP uninstall dry-run failed: {}",
stderr(&output)
);
assert!(stdout(&output).contains("[dry-run] would refuse to remove OMP extension"));
assert!(stdout(&output).contains("[dry-run] Nothing written."));
assert!(extension.exists());
}
#[test]
fn omp_show_distinguishes_modified_and_unrelated_content() {
let project = TempDir::new().unwrap();
let agent_dir = project.path().join("omp-agent");
let extension_dir = agent_dir.join("extensions");
std::fs::create_dir_all(&extension_dir).unwrap();
std::fs::write(
extension_dir.join("rtk.ts"),
format!(
"{}\n// user modification\n",
include_str!("../hooks/pi/rtk.ts")
),
)
.unwrap();
let output = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "omp", "--global", "--show"],
);
assert!(
output.status.success(),
"OMP show failed: {}",
stderr(&output)
);
assert!(stdout(&output).contains(
"modified RTK content - rtk init will ask before overwriting; use --auto-patch to replace"
));
assert!(!stdout(&output).contains("will refuse to overwrite"));
assert!(stdout(&output).contains(&format!(
"# Configure {}",
extension_dir.join("rtk.ts").display()
)));
std::fs::write(
extension_dir.join("rtk.ts"),
"// unrelated user file\nexport default () => {}\n",
)
.unwrap();
let unrelated = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "omp", "--global", "--show"],
);
assert!(
unrelated.status.success(),
"OMP show failed for unrelated content: {}",
stderr(&unrelated)
);
assert!(stdout(&unrelated).contains(
"unrelated content - rtk init will ask before overwriting; use --auto-patch to replace"
));
}
#[test]
fn omp_show_reports_unreadable_extension_and_continues() {
let project = TempDir::new().unwrap();
let agent_dir = project.path().join("omp-agent");
let extension_dir = agent_dir.join("extensions");
std::fs::create_dir_all(&extension_dir).unwrap();
std::fs::write(extension_dir.join("rtk.ts"), [0xff, 0xfe, 0xfd]).unwrap();
let output = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "omp", "--global", "--show"],
);
assert!(
output.status.success(),
"OMP show failed for unreadable extension: {}",
stderr(&output)
);
assert!(stdout(&output).contains("Global extension:"));
assert!(stdout(&output).contains("(unreadable)"));
assert!(stdout(&output).contains("Project extension:"));
}
#[test]
fn omp_unreadable_install_is_recoverable_with_auto_patch() {
let project = TempDir::new().unwrap();
let agent_dir = project.path().join("omp-agent");
let extension_dir = agent_dir.join("extensions");
let extension = extension_dir.join("rtk.ts");
std::fs::create_dir_all(&extension_dir).unwrap();
let original = [0xff, 0xfe, 0xfd];
std::fs::write(&extension, original).unwrap();
let dry_run = run_rtk(
project.path(),
&agent_dir,
&[
"init",
"--agent",
"omp",
"--global",
"--auto-patch",
"--dry-run",
],
);
assert!(
dry_run.status.success(),
"OMP unreadable install dry-run failed: {}",
stderr(&dry_run)
);
assert!(stdout(&dry_run).contains("[dry-run] would overwrite non-stock"));
assert!(stdout(&dry_run).contains("[dry-run] would update OMP extension"));
assert_eq!(std::fs::read(&extension).unwrap(), original);
let auto = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "omp", "--global", "--auto-patch"],
);
assert!(
auto.status.success(),
"OMP unreadable install failed: {}",
stderr(&auto)
);
assert_eq!(
std::fs::read_to_string(&extension).unwrap(),
include_str!("../hooks/pi/rtk.ts")
);
}
#[test]
fn omp_unreadable_uninstall_is_dry_run_preview_but_normal_failure() {
let project = TempDir::new().unwrap();
let agent_dir = project.path().join("omp-agent");
let extension_dir = agent_dir.join("extensions");
let extension = extension_dir.join("rtk.ts");
std::fs::create_dir_all(&extension_dir).unwrap();
std::fs::write(&extension, [0xff, 0xfe, 0xfd]).unwrap();
let dry_run = run_rtk(
project.path(),
&agent_dir,
&[
"init",
"--agent",
"omp",
"--global",
"--uninstall",
"--dry-run",
],
);
assert!(
dry_run.status.success(),
"OMP unreadable uninstall dry-run failed: {}",
stderr(&dry_run)
);
assert!(stdout(&dry_run).contains("[dry-run] would leave unreadable OMP extension unchanged"));
assert!(stdout(&dry_run).contains("[dry-run] Nothing written."));
assert!(extension.exists());
let uninstall = run_rtk(
project.path(),
&agent_dir,
&["init", "--agent", "omp", "--global", "--uninstall"],
);
assert!(
!uninstall.status.success(),
"OMP unreadable uninstall unexpectedly succeeded"
);
assert!(stderr(&uninstall).contains("could not be read; leaving it alone"));
assert!(extension.exists());
}
#[cfg(unix)]
#[test]
fn symlinked_global_agent_directories_are_detected_as_shared() {
let project = TempDir::new().unwrap();
let home = project.path().join("home");
let pi_agent = home.join(".pi/agent");
let omp_agent = home.join(".omp/agent");
let extension = pi_agent.join("extensions/rtk.ts");
let ownership = pi_agent.join("extensions/.rtk-agents");
std::fs::create_dir_all(extension.parent().unwrap()).unwrap();
std::fs::create_dir_all(omp_agent.parent().unwrap()).unwrap();
symlink(&pi_agent, &omp_agent).unwrap();
let install =
run_rtk_without_agent_dir(project.path(), &["init", "--agent", "omp", "--global"]);
assert!(
install.status.success(),
"OMP install through a symlinked agent directory failed: {}",
stderr(&install)
);
assert!(stderr(&install).contains("resolve to the same global extension path"));
assert_eq!(std::fs::read_to_string(&ownership).unwrap(), "omp\n");
let uninstall = run_rtk_without_agent_dir(
project.path(),
&["init", "--agent", "pi", "--global", "--uninstall"],
);
assert!(
!uninstall.status.success(),
"Pi uninstall should protect the symlinked shared extension"
);
assert!(stderr(&uninstall).contains("share the global extension path"));
assert!(extension.exists());
}
#[cfg(unix)]
#[test]
fn symlinked_global_extension_files_share_one_ownership_state() {
let project = TempDir::new().unwrap();
let home = project.path().join("home");
let pi_extension = home.join(".pi/agent/extensions/rtk.ts");
let omp_extension = home.join(".omp/agent/extensions/rtk.ts");
let pi_ownership = pi_extension.with_file_name(".rtk-agents");
let omp_ownership = omp_extension.with_file_name(".rtk-agents");
std::fs::create_dir_all(pi_extension.parent().unwrap()).unwrap();
std::fs::create_dir_all(omp_extension.parent().unwrap()).unwrap();
std::fs::write(&pi_extension, include_str!("../hooks/pi/rtk.ts")).unwrap();
std::fs::write(&pi_ownership, "pi\n").unwrap();
symlink(&pi_extension, &omp_extension).unwrap();
let omp_install =
run_rtk_without_agent_dir(project.path(), &["init", "--agent", "omp", "--global"]);
assert!(
omp_install.status.success(),
"OMP install through a file symlink failed: {}",
stderr(&omp_install)
);
assert!(stderr(&omp_install).contains("share the global extension path"));
let pi_install =
run_rtk_without_agent_dir(project.path(), &["init", "--agent", "pi", "--global"]);
assert!(
pi_install.status.success(),
"Pi install through a file symlink failed: {}",
stderr(&pi_install)
);
assert_eq!(std::fs::read_to_string(&pi_ownership).unwrap(), "omp\npi\n");
assert!(
!omp_ownership.exists(),
"file-level aliases must not split ownership state"
);
let uninstall = run_rtk_without_agent_dir(
project.path(),
&["init", "--agent", "pi", "--global", "--uninstall"],
);
assert!(
!uninstall.status.success(),
"Pi uninstall should protect the shared file-level symlink"
);
assert!(stderr(&uninstall).contains("share the global extension path"));
assert!(pi_extension.exists());
assert!(omp_extension.exists());
let omp_uninstall = run_rtk_without_agent_dir(
project.path(),
&[
"init",
"--agent",
"omp",
"--global",
"--uninstall",
"--auto-patch",
],
);
assert!(
omp_uninstall.status.success(),
"OMP symlink uninstall failed: {}",
stderr(&omp_uninstall)
);
assert!(stderr(&omp_uninstall).contains("changes a path used by the other agent"));
assert!(!omp_extension.exists(), "the OMP symlink should be removed");
assert!(pi_extension.exists(), "the real Pi file should survive");
assert!(
!pi_ownership.exists(),
"the canonical ownership state should be removed after symlink uninstall"
);
}
#[cfg(unix)]
#[test]
fn symlinked_project_agent_directories_are_detected_as_shared() {
let project = TempDir::new().unwrap();
let pi_dir = project.path().join(".pi");
let omp_dir = project.path().join(".omp");
let pi_extension = pi_dir.join("extensions/rtk.ts");
let ownership = pi_dir.join("extensions/.rtk-agents");
std::fs::create_dir_all(pi_extension.parent().unwrap()).unwrap();
symlink(&pi_dir, &omp_dir).unwrap();
let omp_install = run_rtk_without_agent_dir(project.path(), &["init", "--agent", "omp"]);
assert!(
omp_install.status.success(),
"project-local OMP install through a symlink failed: {}",
stderr(&omp_install)
);
assert!(stderr(&omp_install).contains("resolve to the same project extension path"));
let pi_install = run_rtk_without_agent_dir(project.path(), &["init", "--agent", "pi"]);
assert!(
pi_install.status.success(),
"project-local Pi install through a symlink failed: {}",
stderr(&pi_install)
);
assert!(stderr(&pi_install).contains("share the project extension path"));
assert_eq!(std::fs::read_to_string(&ownership).unwrap(), "omp\npi\n");
let pi_uninstall = run_rtk_without_agent_dir(
project.path(),
&["init", "--agent", "pi", "--uninstall", "--no-patch"],
);
assert!(
!pi_uninstall.status.success(),
"Pi uninstall should protect the project-local shared extension"
);
assert!(stderr(&pi_uninstall).contains("share the project extension path"));
assert!(pi_extension.exists());
}
You can’t perform that action at this time.
