|
| 1 | +//! 本地裸机 Trae 测试:验证 .trae/steering/GLOBAL.md 正确生成, |
| 2 | +//! .trae-cn/ 不被输出,且清理时兼容清理旧的 .trae-cn/。 |
| 3 | +
|
| 4 | +use std::fs; |
| 5 | + |
| 6 | +use tnmsc_local_tests::LocalTestRunner; |
| 7 | + |
| 8 | +#[test] |
| 9 | +fn binary_exists_before_tests() { |
| 10 | + let binary = tnmsc_local_tests::binary_path(); |
| 11 | + assert!( |
| 12 | + binary.is_file(), |
| 13 | + "binary not found at: {}\n\nplease compile it first:\n cargo build -p tnmsc\n", |
| 14 | + binary.display() |
| 15 | + ); |
| 16 | +} |
| 17 | + |
| 18 | +#[test] |
| 19 | +fn local_trae_steering_generated_after_install() { |
| 20 | + let runner = LocalTestRunner::new(); |
| 21 | + runner.assert_project_ready(); |
| 22 | + |
| 23 | + let clean = runner.clean(); |
| 24 | + clean.assert_success("tnmsc clean before install"); |
| 25 | + |
| 26 | + let install = runner.install(); |
| 27 | + install.assert_success("tnmsc install"); |
| 28 | + |
| 29 | + assert!( |
| 30 | + runner.trae_steering_file_exists(), |
| 31 | + ".trae/steering/GLOBAL.md should be generated after install, stdout:\n{}\nstderr:\n{}", |
| 32 | + install.stdout, |
| 33 | + install.stderr |
| 34 | + ); |
| 35 | + |
| 36 | + assert!( |
| 37 | + !runner.trae_cn_file_exists(), |
| 38 | + ".trae-cn/user_rules/GLOBAL.md must NOT be generated after install" |
| 39 | + ); |
| 40 | +} |
| 41 | + |
| 42 | +#[test] |
| 43 | +fn local_trae_steering_idempotent() { |
| 44 | + let runner = LocalTestRunner::new(); |
| 45 | + runner.assert_project_ready(); |
| 46 | + |
| 47 | + let clean = runner.clean(); |
| 48 | + clean.assert_success("tnmsc clean before install"); |
| 49 | + |
| 50 | + let first = runner.install(); |
| 51 | + first.assert_success("first tnmsc install"); |
| 52 | + assert!(runner.trae_steering_file_exists()); |
| 53 | + |
| 54 | + let content_first = |
| 55 | + fs::read_to_string(runner.cwd().join(".trae").join("steering").join("GLOBAL.md")).unwrap(); |
| 56 | + |
| 57 | + let second = runner.install(); |
| 58 | + second.assert_success("second tnmsc install"); |
| 59 | + |
| 60 | + let content_second = |
| 61 | + fs::read_to_string(runner.cwd().join(".trae").join("steering").join("GLOBAL.md")).unwrap(); |
| 62 | + |
| 63 | + assert_eq!( |
| 64 | + content_first, content_second, |
| 65 | + "consecutive installs should produce identical .trae/steering/GLOBAL.md" |
| 66 | + ); |
| 67 | +} |
| 68 | + |
| 69 | +#[test] |
| 70 | +fn local_trae_steering_removed_after_clean() { |
| 71 | + let runner = LocalTestRunner::new(); |
| 72 | + runner.assert_project_ready(); |
| 73 | + |
| 74 | + let clean = runner.clean(); |
| 75 | + clean.assert_success("tnmsc clean before install"); |
| 76 | + |
| 77 | + let install = runner.install(); |
| 78 | + install.assert_success("tnmsc install"); |
| 79 | + assert!(runner.trae_steering_file_exists()); |
| 80 | + |
| 81 | + let clean = runner.clean(); |
| 82 | + clean.assert_success("tnmsc clean"); |
| 83 | + |
| 84 | + assert!( |
| 85 | + !runner.trae_steering_file_exists(), |
| 86 | + ".trae/steering/GLOBAL.md should be removed after clean" |
| 87 | + ); |
| 88 | +} |
| 89 | + |
| 90 | +#[test] |
| 91 | +fn local_trae_cn_cleaned_for_compatibility() { |
| 92 | + let runner = LocalTestRunner::new(); |
| 93 | + runner.assert_project_ready(); |
| 94 | + |
| 95 | + let clean = runner.clean(); |
| 96 | + clean.assert_success("tnmsc clean before install"); |
| 97 | + |
| 98 | + let install = runner.install(); |
| 99 | + install.assert_success("tnmsc install"); |
| 100 | + assert!(runner.trae_steering_file_exists()); |
| 101 | + |
| 102 | + // Simulate old-style .trae-cn/ output (should be cleaned up) |
| 103 | + let trae_cn_path = runner.cwd().join(".trae-cn").join("user_rules").join("GLOBAL.md"); |
| 104 | + fs::create_dir_all(trae_cn_path.parent().unwrap()).unwrap(); |
| 105 | + fs::write(&trae_cn_path, "# legacy\n").unwrap(); |
| 106 | + assert!(runner.trae_cn_file_exists(), "fake .trae-cn should exist before clean"); |
| 107 | + |
| 108 | + let clean = runner.clean(); |
| 109 | + clean.assert_success("tnmsc clean removes legacy .trae-cn"); |
| 110 | + |
| 111 | + assert!( |
| 112 | + !runner.trae_cn_file_exists(), |
| 113 | + "legacy .trae-cn/user_rules/GLOBAL.md should be removed during clean for compatibility" |
| 114 | + ); |
| 115 | + |
| 116 | + // .trae/steering/GLOBAL.md should also be removed |
| 117 | + assert!( |
| 118 | + !runner.trae_steering_file_exists(), |
| 119 | + ".trae/steering/GLOBAL.md should also be removed after clean" |
| 120 | + ); |
| 121 | +} |
0 commit comments