1use std::path::{Path, PathBuf};
26
27use crate::core::rules_canonical::{END_MARK as BLOCK_END, START_MARK as BLOCK_START};
28use crate::core::rules_channel::{COMPRESSION_BLOCK_END, COMPRESSION_BLOCK_START};
29
30#[derive(Debug, PartialEq, Eq)]
32pub enum Action {
33 DeleteFile { path: PathBuf, reason: String },
35 StripBlocks { path: PathBuf, reason: String },
37 StripCompression { path: PathBuf, reason: String },
41 Report { path: PathBuf, note: String },
43}
44
45fn is_owned_rules_file(content: &str) -> bool {
49 let starts_with_header = content
50 .trim_start()
51 .starts_with(crate::core::rules_canonical::START_MARK)
52 || (content.trim_start().starts_with("---")
54 && content.contains(crate::core::rules_canonical::START_MARK));
55 if starts_with_header && content.contains("<!-- version:") {
56 return true;
57 }
58 is_owned_legacy_rules_file(content)
59}
60
61fn is_owned_legacy_rules_file(content: &str) -> bool {
70 let mut lines = content.trim_start().lines();
71 let first = lines.next().unwrap_or_default().trim();
75 let marker_line = if first.starts_with("# lean-ctx") {
76 lines.next().unwrap_or_default().trim()
77 } else {
78 first
79 };
80 if !marker_line.starts_with(crate::core::rules_canonical::RULES_MARKER_PREFIX) {
81 return false;
82 }
83 let Some(idx) = content.rfind("<!-- /lean-ctx") else {
84 return false;
85 };
86 let Some(end) = content[idx..].find("-->") else {
87 return false;
88 };
89 content[idx + end + 3..].trim().is_empty()
90}
91
92fn strip_legacy_owned_prefix(content: &str) -> Option<String> {
98 let trimmed = content.trim_start();
99 let mut lines = trimmed.lines();
100 let first = lines.next()?.trim();
101 let marker_line = if first.starts_with("# lean-ctx") {
102 lines.next().unwrap_or_default().trim()
103 } else {
104 first
105 };
106 if !marker_line.starts_with(crate::core::rules_canonical::RULES_MARKER_PREFIX)
107 || marker_line.starts_with(BLOCK_START)
108 {
109 return None;
110 }
111 let mut offset = 0usize;
112 for line in trimmed.split_inclusive('\n') {
113 offset += line.len();
114 let t = line.trim();
115 if t == crate::core::rules_canonical::AGENTS_BLOCK_END
116 || t.starts_with("<!-- /lean-ctx-rules")
117 {
118 return Some(trimmed[offset..].to_string());
119 }
120 }
121 None
122}
123
124fn has_marker_pair(content: &str, start: &str, end: &str) -> bool {
127 crate::marked_block::contains_marker_line(content, start)
128 && crate::marked_block::contains_marker_line(content, end)
129}
130
131fn has_marked_block(content: &str) -> bool {
132 has_marker_pair(content, BLOCK_START, BLOCK_END)
133 || has_marker_pair(content, COMPRESSION_BLOCK_START, COMPRESSION_BLOCK_END)
134}
135
136pub(crate) fn strip_lean_ctx_blocks(content: &str) -> String {
138 let mut out = strip_legacy_owned_prefix(content).unwrap_or_else(|| content.to_string());
139 loop {
142 let next = if has_marker_pair(&out, BLOCK_START, BLOCK_END) {
143 crate::marked_block::remove_content(&out, BLOCK_START, BLOCK_END)
144 } else if has_marker_pair(&out, COMPRESSION_BLOCK_START, COMPRESSION_BLOCK_END) {
145 crate::marked_block::remove_content(
146 &out,
147 COMPRESSION_BLOCK_START,
148 COMPRESSION_BLOCK_END,
149 )
150 } else {
151 break;
152 };
153 if next == out {
154 break;
155 }
156 out = next;
157 }
158 let trimmed = out.trim();
159 if trimmed.is_empty() {
160 String::new()
161 } else {
162 format!("{}\n", out.trim_end().trim_start_matches('\n'))
163 }
164}
165
166fn is_whole_lean_ctx_file(content: &str) -> bool {
171 if is_owned_rules_file(content) {
172 return true;
173 }
174 content
175 .trim_start()
176 .starts_with(crate::core::rules_canonical::RULES_MARKER_PREFIX)
177 && !content
178 .lines()
179 .any(|l| l.trim_start().starts_with("<!-- /lean-ctx"))
180}
181
182fn has_strippable_region(content: &str) -> bool {
185 has_marked_block(content) || strip_legacy_owned_prefix(content).is_some()
186}
187
188pub fn retire_rules_file(path: &Path) -> Option<String> {
194 let content = std::fs::read_to_string(path).ok()?;
195 let action = if is_whole_lean_ctx_file(&content) {
196 Action::DeleteFile {
197 path: path.to_path_buf(),
198 reason: String::new(),
199 }
200 } else if has_strippable_region(&content) {
201 Action::StripBlocks {
202 path: path.to_path_buf(),
203 reason: String::new(),
204 }
205 } else {
206 return None;
207 };
208 let line = apply(&action);
209 (!line.starts_with("unchanged")).then_some(line)
210}
211
212pub(crate) fn strip_compression_block(content: &str) -> String {
216 if !(content.contains(COMPRESSION_BLOCK_START) && content.contains(COMPRESSION_BLOCK_END)) {
217 return content.to_string();
218 }
219 let stripped = crate::marked_block::remove_content(
220 content,
221 COMPRESSION_BLOCK_START,
222 COMPRESSION_BLOCK_END,
223 );
224 let trimmed = stripped.trim_end();
225 if trimmed.is_empty() {
226 String::new()
227 } else {
228 format!("{trimmed}\n")
229 }
230}
231
232fn project_owned_candidates(dir: &Path) -> Vec<PathBuf> {
235 vec![
236 dir.join(".cursor/rules/lean-ctx.mdc"),
237 dir.join(".claude/rules/lean-ctx.md"),
238 dir.join(".codebuddy/rules/lean-ctx.md"),
239 dir.join(".windsurf/rules/lean-ctx.md"),
240 dir.join(".cline/rules/lean-ctx.md"),
241 dir.join(".roo/rules/lean-ctx.md"),
242 ]
243}
244
245fn plan_duplicate_file(actions: &mut Vec<Action>, candidate: PathBuf, reason: &str) {
248 let Ok(content) = std::fs::read_to_string(&candidate) else {
249 return;
250 };
251 if is_whole_lean_ctx_file(&content) {
252 actions.push(Action::DeleteFile {
253 path: candidate,
254 reason: reason.into(),
255 });
256 } else if has_strippable_region(&content) {
257 actions.push(Action::StripBlocks {
258 path: candidate,
259 reason: format!("{reason}; text outside the lean-ctx markers is kept"),
260 });
261 } else if !content.trim().is_empty() {
262 actions.push(Action::Report {
263 path: candidate,
264 note: "contains custom edits — not lean-ctx-owned, left untouched".into(),
265 });
266 }
267}
268
269fn global_duplicate_candidates(home: &Path) -> Vec<PathBuf> {
273 vec![
274 crate::core::editor_registry::claude_rules_dir(home).join("lean-ctx.md"),
275 home.join(".codebuddy/rules/lean-ctx.md"),
276 ]
277}
278
279pub fn plan(home: &Path, project: &Path) -> Vec<Action> {
281 let mut actions = Vec::new();
282 let canonical_cursor_mdc = home.join(".cursor/rules/lean-ctx.mdc");
283
284 for candidate in global_duplicate_candidates(home) {
286 plan_duplicate_file(
287 &mut actions,
288 candidate,
289 "always-loaded duplicate of the host's CLAUDE.md/CODEBUDDY.md rules block",
290 );
291 }
292
293 let mut dir = Some(project.to_path_buf());
295 while let Some(d) = dir {
296 if d == *home {
297 break;
298 }
299 for candidate in project_owned_candidates(&d) {
300 if candidate == canonical_cursor_mdc {
301 continue;
302 }
303 plan_duplicate_file(
304 &mut actions,
305 candidate,
306 "lean-ctx-owned duplicate of the global rules file",
307 );
308 }
309 if !d.starts_with(home) {
314 break;
315 }
316 dir = d.parent().map(Path::to_path_buf);
317 }
318
319 let cursorrules = project.join(".cursorrules");
322 if let Ok(content) = std::fs::read_to_string(&cursorrules) {
323 if canonical_cursor_mdc.exists() && has_marked_block(&content) {
324 actions.push(Action::StripBlocks {
325 path: cursorrules,
326 reason: "global ~/.cursor/rules/lean-ctx.mdc already carries these blocks".into(),
327 });
328 } else if !canonical_cursor_mdc.exists() && content.contains("lean-ctx") {
329 actions.push(Action::Report {
330 path: cursorrules,
331 note: "no global Cursor mdc found — .cursorrules stays the carrier".into(),
332 });
333 } else if content.contains("lean-ctx") && !has_marked_block(&content) {
334 actions.push(Action::Report {
335 path: cursorrules,
336 note: "mentions lean-ctx without markers (manual rules) — review by hand".into(),
337 });
338 }
339 }
340
341 let agents_md = project.join("AGENTS.md");
346 if let Ok(content) = std::fs::read_to_string(&agents_md) {
347 let has_compression =
348 content.contains(COMPRESSION_BLOCK_START) && content.contains(COMPRESSION_BLOCK_END);
349 if has_compression {
350 if crate::core::rules_channel::agents_md_can_thin(home) {
351 actions.push(Action::StripCompression {
352 path: agents_md,
353 reason: "every AGENTS.md reader already loads the compression block from its own canonical file".into(),
354 });
355 } else {
356 actions.push(Action::Report {
357 path: agents_md,
358 note: "an AGENTS.md reader has no other compression source — AGENTS.md stays the carrier".into(),
359 });
360 }
361 }
362 }
363
364 actions
365}
366
367pub fn apply(action: &Action) -> String {
369 match action {
370 Action::DeleteFile { path, .. } => match std::fs::remove_file(path) {
371 Ok(()) => format!("deleted {}", path.display()),
372 Err(e) => format!("FAILED {} ({e})", path.display()),
373 },
374 Action::StripBlocks { path, .. } => {
375 let Ok(content) = std::fs::read_to_string(path) else {
376 return format!("FAILED {} (unreadable)", path.display());
377 };
378 let stripped = strip_lean_ctx_blocks(&content);
379 if stripped == content {
380 return format!("unchanged {}", path.display());
381 }
382 let bak = path.with_extension("bak");
383 if let Err(e) = crate::config_io::write_backup_nofollow(path, &bak, content.as_bytes())
384 {
385 return format!("FAILED {} (backup: {e})", path.display());
386 }
387 if stripped.is_empty() {
388 match std::fs::remove_file(path) {
389 Ok(()) => format!(
390 "deleted {} (only lean-ctx blocks, backup: {})",
391 path.display(),
392 bak.display()
393 ),
394 Err(e) => format!("FAILED {} ({e})", path.display()),
395 }
396 } else {
397 match std::fs::write(path, &stripped) {
398 Ok(()) => format!("stripped {} (backup: {})", path.display(), bak.display()),
399 Err(e) => format!("FAILED {} ({e})", path.display()),
400 }
401 }
402 }
403 Action::StripCompression { path, .. } => {
404 let Ok(content) = std::fs::read_to_string(path) else {
405 return format!("FAILED {} (unreadable)", path.display());
406 };
407 let stripped = strip_compression_block(&content);
408 if stripped == content {
409 return format!("unchanged {}", path.display());
410 }
411 let bak = path.with_extension("bak");
412 if let Err(e) = crate::config_io::write_backup_nofollow(path, &bak, content.as_bytes())
413 {
414 return format!("FAILED {} (backup: {e})", path.display());
415 }
416 match std::fs::write(path, &stripped) {
417 Ok(()) => format!("thinned {} (backup: {})", path.display(), bak.display()),
418 Err(e) => format!("FAILED {} ({e})", path.display()),
419 }
420 }
421 Action::Report { path, note } => format!("info {} — {note}", path.display()),
422 }
423}
424
425pub fn auto_apply(home: &Path, project: &Path) -> Vec<String> {
430 plan(home, project)
431 .iter()
432 .filter(|a| !matches!(a, Action::Report { .. }))
433 .map(apply)
434 .collect()
435}
436
437#[cfg(test)]
438mod tests {
439 use super::*;
440
441 fn owned_mdc() -> String {
442 format!(
443 "---\ndescription: lean-ctx\n---\n{}\n<!-- version: 1 -->\nbody\n",
444 crate::core::rules_canonical::START_MARK
445 )
446 }
447
448 #[test]
449 fn detects_owned_dedicated_files() {
450 assert!(is_owned_rules_file(&owned_mdc()));
451 assert!(is_owned_rules_file(&format!(
452 "{}\n<!-- version: 1 -->\nbody\n",
453 crate::core::rules_canonical::START_MARK
454 )));
455 assert!(!is_owned_rules_file("# My rules\nuse lean-ctx tools\n"));
457 assert!(!is_owned_rules_file(&format!(
459 "# my header\n{}\n<!-- version: 1 -->\n",
460 crate::core::rules_canonical::START_MARK
461 )));
462 }
463
464 #[cfg(unix)]
465 #[test]
466 fn retire_does_not_follow_a_planted_backup_symlink() {
467 let dir = tempfile::tempdir().unwrap();
468 let rules = dir.path().join("project/.claude/rules");
469 std::fs::create_dir_all(&rules).unwrap();
470 let file = rules.join("lean-ctx.md");
471 std::fs::write(
472 &file,
473 format!("user line\n{BLOCK_START}\nour rules\n{BLOCK_END}\n"),
474 )
475 .unwrap();
476 let outside = dir.path().join("outside.txt");
477 std::os::unix::fs::symlink(&outside, rules.join("lean-ctx.bak")).unwrap();
478
479 let line = retire_rules_file(&file).unwrap();
480
481 assert!(line.starts_with("FAILED"), "{line}");
482 assert!(!outside.exists());
483 assert!(
484 std::fs::read_to_string(&file)
485 .unwrap()
486 .contains("our rules")
487 );
488 }
489
490 #[test]
491 fn strip_removes_rules_and_compression_blocks() {
492 let content = format!(
493 "user line\n{BLOCK_START}\nour rules\n{BLOCK_END}\nmore user\n{COMPRESSION_BLOCK_START}\nstyle\n{COMPRESSION_BLOCK_END}\n",
494 );
495 let out = strip_lean_ctx_blocks(&content);
496 assert!(out.contains("user line"));
497 assert!(out.contains("more user"));
498 assert!(!out.contains("our rules"));
499 assert!(!out.contains("style"));
500 assert!(!out.contains("lean-ctx-compression"));
501 }
502
503 #[test]
504 fn strip_of_pure_block_file_yields_empty() {
505 let content = format!("{BLOCK_START}\nonly ours\n{BLOCK_END}\n");
506 assert_eq!(strip_lean_ctx_blocks(&content), "");
507 }
508
509 #[test]
512 fn legacy_marker_files_owned_only_when_wholly_lean_ctx() {
513 let pristine = "# lean-ctx — Context Engineering Layer\n\
514 <!-- lean-ctx-rules-v9 -->\n\n\
515 PREFER lean-ctx MCP tools.\n\
516 Write, Delete, Glob → use normally.\n\
517 <!-- /lean-ctx -->\n";
518 assert!(is_owned_rules_file(pristine));
519
520 let user_extended = format!("{pristine}\n## My own precedence rules\nkeep me\n");
521 assert!(!is_owned_rules_file(&user_extended));
522
523 assert!(!is_owned_rules_file(
525 "my notes\nabout <!-- lean-ctx-rules-v9 --> markers\n<!-- /lean-ctx -->\n"
526 ));
527 }
528
529 #[test]
530 fn plan_deletes_project_and_parent_owned_files_only() {
531 let tmp = tempfile::tempdir().unwrap();
532 let home = tmp.path();
533 let parent = home.join("projects");
534 let project = parent.join("app");
535
536 std::fs::create_dir_all(home.join(".cursor/rules")).unwrap();
538 std::fs::write(home.join(".cursor/rules/lean-ctx.mdc"), owned_mdc()).unwrap();
539 std::fs::create_dir_all(project.join(".cursor/rules")).unwrap();
541 std::fs::write(project.join(".cursor/rules/lean-ctx.mdc"), owned_mdc()).unwrap();
542 std::fs::create_dir_all(parent.join(".cursor/rules")).unwrap();
543 std::fs::write(parent.join(".cursor/rules/lean-ctx.mdc"), owned_mdc()).unwrap();
544 std::fs::create_dir_all(project.join(".claude/rules")).unwrap();
546 std::fs::write(
547 project.join(".claude/rules/lean-ctx.md"),
548 "# customized by user\nkeep me\n",
549 )
550 .unwrap();
551
552 let actions = plan(home, &project);
553 let deletes: Vec<&PathBuf> = actions
554 .iter()
555 .filter_map(|a| match a {
556 Action::DeleteFile { path, .. } => Some(path),
557 _ => None,
558 })
559 .collect();
560 assert_eq!(deletes.len(), 2, "project + parent copies: {actions:?}");
561 assert!(deletes.iter().all(|p| !p.starts_with(home.join(".cursor"))));
562 assert!(actions.iter().any(|a| matches!(
563 a,
564 Action::Report { path, .. } if path.ends_with(".claude/rules/lean-ctx.md")
565 )));
566 }
567
568 #[test]
572 fn plan_parent_walk_stays_inside_home() {
573 let tmp = tempfile::tempdir().unwrap();
574 let home = tmp.path().join("home");
575 let outside = tmp.path().join("elsewhere");
576 let project = outside.join("app");
577 std::fs::create_dir_all(&home).unwrap();
578 std::fs::create_dir_all(outside.join(".cursor/rules")).unwrap();
579 std::fs::create_dir_all(project.join(".cursor/rules")).unwrap();
580 std::fs::write(outside.join(".cursor/rules/lean-ctx.mdc"), owned_mdc()).unwrap();
581 std::fs::write(project.join(".cursor/rules/lean-ctx.mdc"), owned_mdc()).unwrap();
582
583 let paths: Vec<PathBuf> = plan(&home, &project)
584 .into_iter()
585 .filter_map(|a| match a {
586 Action::DeleteFile { path, .. } | Action::StripBlocks { path, .. } => Some(path),
587 _ => None,
588 })
589 .collect();
590 assert_eq!(paths, vec![project.join(".cursor/rules/lean-ctx.mdc")]);
591 }
592
593 #[test]
594 fn plan_strips_cursorrules_only_with_canonical_mdc() {
595 let tmp = tempfile::tempdir().unwrap();
596 let home = tmp.path();
597 let project = home.join("app");
598 std::fs::create_dir_all(&project).unwrap();
599 let rules = format!("{BLOCK_START}\npointer\n{BLOCK_END}\n");
600 std::fs::write(project.join(".cursorrules"), rules).unwrap();
601
602 let actions = plan(home, &project);
604 assert!(
605 !actions
606 .iter()
607 .any(|a| matches!(a, Action::StripBlocks { .. })),
608 "{actions:?}"
609 );
610
611 std::fs::create_dir_all(home.join(".cursor/rules")).unwrap();
613 std::fs::write(home.join(".cursor/rules/lean-ctx.mdc"), owned_mdc()).unwrap();
614 let actions = plan(home, &project);
615 assert!(
616 actions.iter().any(|a| matches!(
617 a,
618 Action::StripBlocks { path, .. } if path.ends_with(".cursorrules")
619 )),
620 "{actions:?}"
621 );
622 }
623
624 #[test]
625 fn apply_strip_writes_backup_and_keeps_user_content() {
626 let tmp = tempfile::tempdir().unwrap();
627 let path = tmp.path().join(".cursorrules");
628 std::fs::write(
629 &path,
630 format!("my custom rule\n{BLOCK_START}\nours\n{BLOCK_END}\n"),
631 )
632 .unwrap();
633
634 let msg = apply(&Action::StripBlocks {
635 path: path.clone(),
636 reason: String::new(),
637 });
638 assert!(msg.starts_with("stripped"), "{msg}");
639 let after = std::fs::read_to_string(&path).unwrap();
640 assert_eq!(after, "my custom rule\n");
641 let bak = std::fs::read_to_string(path.with_extension("bak")).unwrap();
642 assert!(bak.contains("ours"));
643 }
644
645 #[test]
646 fn strip_compression_keeps_pointer_and_user_content() {
647 let content = format!(
648 "# Agent Instructions\n\n{BLOCK_START}\npointer\n{BLOCK_END}\n\n{COMPRESSION_BLOCK_START}\nOUTPUT STYLE\n{COMPRESSION_BLOCK_END}\n",
649 );
650 let out = strip_compression_block(&content);
651 assert!(out.contains("# Agent Instructions"));
652 assert!(out.contains(BLOCK_START));
653 assert!(out.contains("pointer"));
654 assert!(!out.contains("lean-ctx-compression"));
655 assert!(!out.contains("OUTPUT STYLE"));
656 }
657
658 #[test]
659 fn plan_thins_agents_md_when_cursor_covered_and_no_codex() {
660 let _guard = crate::core::data_dir::test_env_lock();
661 let tmp = tempfile::tempdir().unwrap();
662 let home = tmp.path();
663 let project = home.join("app");
664 std::fs::create_dir_all(&project).unwrap();
665 crate::test_env::set_var("CODEX_HOME", home.join(".codex"));
667
668 std::fs::create_dir_all(home.join(".cursor/rules")).unwrap();
670 std::fs::write(
671 home.join(".cursor/rules/lean-ctx.mdc"),
672 format!(
673 "{}\n<!-- version: 1 -->\n{COMPRESSION_BLOCK_START}\nstyle\n{COMPRESSION_BLOCK_END}\n",
674 crate::core::rules_canonical::START_MARK
675 ),
676 )
677 .unwrap();
678
679 std::fs::write(
681 project.join("AGENTS.md"),
682 format!(
683 "# Agent Instructions\n\n{BLOCK_START}\npointer\n{BLOCK_END}\n\n{COMPRESSION_BLOCK_START}\nstyle\n{COMPRESSION_BLOCK_END}\n"
684 ),
685 )
686 .unwrap();
687
688 let actions = plan(home, &project);
689 assert!(
690 actions.iter().any(|a| matches!(
691 a,
692 Action::StripCompression { path, .. } if path.ends_with("AGENTS.md")
693 )),
694 "{actions:?}"
695 );
696 crate::test_env::remove_var("CODEX_HOME");
697 }
698
699 #[test]
700 fn plan_keeps_agents_md_carrier_when_cursor_uncovered() {
701 let _guard = crate::core::data_dir::test_env_lock();
702 let tmp = tempfile::tempdir().unwrap();
703 let home = tmp.path();
704 let project = home.join("app");
705 std::fs::create_dir_all(&project).unwrap();
706 crate::test_env::set_var("CODEX_HOME", home.join(".codex"));
707
708 std::fs::write(
710 project.join("AGENTS.md"),
711 format!(
712 "# Agent Instructions\n\n{BLOCK_START}\npointer\n{BLOCK_END}\n\n{COMPRESSION_BLOCK_START}\nstyle\n{COMPRESSION_BLOCK_END}\n"
713 ),
714 )
715 .unwrap();
716
717 let actions = plan(home, &project);
718 assert!(
719 !actions
720 .iter()
721 .any(|a| matches!(a, Action::StripCompression { .. })),
722 "{actions:?}"
723 );
724 assert!(
726 actions.iter().any(|a| matches!(
727 a,
728 Action::Report { path, .. } if path.ends_with("AGENTS.md")
729 )),
730 "{actions:?}"
731 );
732 crate::test_env::remove_var("CODEX_HOME");
733 }
734
735 #[test]
736 fn apply_strip_compression_thins_and_backs_up() {
737 let tmp = tempfile::tempdir().unwrap();
738 let path = tmp.path().join("AGENTS.md");
739 std::fs::write(
740 &path,
741 format!(
742 "# Agent Instructions\n\n{BLOCK_START}\npointer\n{BLOCK_END}\n\n{COMPRESSION_BLOCK_START}\nstyle\n{COMPRESSION_BLOCK_END}\n"
743 ),
744 )
745 .unwrap();
746
747 let msg = apply(&Action::StripCompression {
748 path: path.clone(),
749 reason: String::new(),
750 });
751 assert!(msg.starts_with("thinned"), "{msg}");
752 let after = std::fs::read_to_string(&path).unwrap();
753 assert!(after.contains(BLOCK_START));
754 assert!(!after.contains("lean-ctx-compression"));
755 let bak = std::fs::read_to_string(path.with_extension("bak")).unwrap();
756 assert!(bak.contains("lean-ctx-compression"));
757 }
758
759 #[test]
760 fn apply_strip_deletes_file_that_was_only_ours() {
761 let tmp = tempfile::tempdir().unwrap();
762 let path = tmp.path().join(".cursorrules");
763 std::fs::write(&path, format!("{BLOCK_START}\nours\n{BLOCK_END}\n")).unwrap();
764
765 let msg = apply(&Action::StripBlocks {
766 path: path.clone(),
767 reason: String::new(),
768 });
769 assert!(msg.starts_with("deleted"), "{msg}");
770 assert!(!path.exists());
771 assert!(path.with_extension("bak").exists());
772 }
773}