adrs-core 0.11.0

Core library for managing Architecture Decision Records
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
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
//! Class-level write-path matrices for metadata and body updates.
//!
//! These pin *classes* of inputs × write APIs, not single string repros:
//! people-YAML shapes under metadata writes, nested/mixed fences under body
//! patches, and Consequences append after a suppressed trailing newline.

use adrs_core::{AdrStatus, BodySectionPatch, LinkKind, Repository};
use std::fs;
use tempfile::TempDir;

fn write_ng_fixture(repo: &Repository, number: u32, content: &str) {
    let name = format!("{number:04}-class-fixture.md");
    fs::write(repo.adr_path().join(name), content).unwrap();
}

fn frontmatter_after_status(content: &str) -> String {
    content
        .split("---\n")
        .nth(1)
        .unwrap_or("")
        .split("\n---")
        .next()
        .unwrap_or("")
        .to_string()
}

/// People-field YAML shapes that must survive metadata writes.
fn people_yaml_cases() -> Vec<(&'static str, &'static str)> {
    vec![
        (
            "block-scalar",
            r#"---
number: 2
title: Block scalar
date: 2024-06-01
status: proposed
consulted: >-
  the platform team
---

## Context

C.

## Decision

D.

## Consequences

X.
"#,
        ),
        (
            "zero-indent",
            r#"---
number: 2
title: Zero indent
date: 2024-06-01
status: proposed
consulted:
- alice
- bob
---

## Context

C.

## Decision

D.

## Consequences

X.
"#,
        ),
        (
            "comment-between",
            r#"---
number: 2
title: Comment between
date: 2024-06-01
status: proposed
consulted:
  # people
  - alice
---

## Context

C.

## Decision

D.

## Consequences

X.
"#,
        ),
        (
            "four-space",
            r#"---
number: 2
title: Four space
date: 2024-06-01
status: proposed
consulted:
    - alice
    - bob
---

## Context

C.

## Decision

D.

## Consequences

X.
"#,
        ),
        (
            "scalar-decision-makers",
            r#"---
number: 2
title: Scalar makers
date: 2024-06-01
status: proposed
decision-makers: alice
---

## Context

C.

## Decision

D.

## Consequences

X.
"#,
        ),
    ]
}

#[test]
fn people_yaml_noop_metadata_byte_identical() {
    for (name, fixture) in people_yaml_cases() {
        let temp = TempDir::new().unwrap();
        let repo = Repository::init(temp.path(), None, true).unwrap();
        write_ng_fixture(&repo, 2, fixture);
        let path = repo.adr_path().join("0002-class-fixture.md");
        let before = fs::read(&path).unwrap();
        let adr = repo.get(2).unwrap();
        repo.update_metadata(&adr).unwrap();
        let after = fs::read(&path).unwrap();
        assert_eq!(
            before, after,
            "{name}: no-op update_metadata must be byte-identical"
        );
    }
}

#[test]
fn people_yaml_set_status_keeps_adr_listable() {
    // Primary surface: adrs status / Repository::set_status.
    for (name, fixture) in people_yaml_cases() {
        let temp = TempDir::new().unwrap();
        let repo = Repository::init(temp.path(), None, true).unwrap();
        write_ng_fixture(&repo, 2, fixture);
        let path = repo.adr_path().join("0002-class-fixture.md");

        repo.set_status(2, AdrStatus::Accepted, None)
            .unwrap_or_else(|e| panic!("{name}: set_status failed: {e}"));

        let after = fs::read_to_string(&path).unwrap();
        let listed = repo.get(2).unwrap_or_else(|e| {
            panic!("{name}: ADR disappeared from list after set_status: {e}\n{after}")
        });
        assert_eq!(listed.status, AdrStatus::Accepted);
        assert!(
            after.contains("status: accepted"),
            "{name}: status line missing\n{after}"
        );

        // Orphaned continuation / duplicated list items are the failure mode.
        if name == "block-scalar" {
            assert!(
                !after.contains("consulted:\n  - the platform team\n  the platform team")
                    && !after.contains("consulted:\n  - the platform team\n\n  the platform team"),
                "{name}: block-scalar continuation orphaned\n{after}"
            );
        }
        if name == "zero-indent" || name == "four-space" {
            let fm = frontmatter_after_status(&after);
            assert!(
                !(fm.contains("  - alice") && fm.contains("\n- alice")),
                "{name}: list items orphaned beside canonical form\n{fm}"
            );
        }
        if name == "comment-between" {
            assert!(
                after.matches("- alice").count() <= 1,
                "{name}: values duplicated\n{after}"
            );
        }
    }
}

#[test]
fn people_yaml_intentional_consulted_change_stays_parseable() {
    // When the caller actually changes consulted, the file must still parse.
    for (name, fixture) in people_yaml_cases() {
        let temp = TempDir::new().unwrap();
        let repo = Repository::init(temp.path(), None, true).unwrap();
        write_ng_fixture(&repo, 2, fixture);
        let path = repo.adr_path().join("0002-class-fixture.md");

        let mut adr = repo.get(2).unwrap();
        adr.set_consulted(vec!["alice".into(), "dave".into()]);
        repo.update_metadata(&adr)
            .unwrap_or_else(|e| panic!("{name}: update_metadata failed: {e}"));

        let after = fs::read_to_string(&path).unwrap();
        repo.get(2).unwrap_or_else(|e| {
            panic!("{name}: ADR unreadable after intentional consulted change: {e}\n{after}")
        });
        // Classic regex splice failure: canonical block written, old items left behind.
        assert!(
            !(after.contains("  - alice\n  - dave") && after.contains("\n- alice\n- bob")),
            "{name}: must not leave orphaned zero-indent items beside rewrite\n{after}"
        );
        assert!(
            !after.contains("  - dave\n- alice"),
            "{name}: orphaned list items after splice\n{after}"
        );
    }
}

fn fence_patch_cases() -> Vec<(&'static str, &'static str)> {
    vec![
        (
            "nested-backticks",
            r#"---
number: 2
title: Nested backticks
date: 2024-06-01
status: accepted
---

## Decision Outcome

Chosen: X.

````md
```
## Consequences

Example nested.
```
````

Trailing after nested.

### Consequences

* Old good

### Confirmation

Keep me.
"#,
        ),
        (
            "tilde-wraps-backticks",
            r#"---
number: 2
title: Tilde wraps backticks
date: 2024-06-01
status: accepted
---

## Decision Outcome

Chosen: Y.

~~~md
```markdown
## Consequences

Example tilde-wrapped.
```
~~~

Trailing after tilde.

### Consequences

* Old good

### Confirmation

Keep me.
"#,
        ),
        (
            "backticks-wrap-tilde",
            r#"---
number: 2
title: Backticks wrap tilde
date: 2024-06-01
status: accepted
---

## Decision Outcome

Chosen: Z.

```md
~~~
## Consequences

Example backtick-wrapped tilde.
~~~
```

Trailing after mixed.

### Consequences

* Old good

### Confirmation

Keep me.
"#,
        ),
        (
            "four-space-indented-fence-lookalike",
            // At 4 spaces, CommonMark treats ``` as indented code, not a fence.
            // Heading lookalikes inside must not toggle fence state.
            r#"---
number: 2
title: Indented code lookalike
date: 2024-06-01
status: accepted
---

## Decision Outcome

Chosen: W.

    ```
    ## Consequences
    not a fence
    ```

### Consequences

* Old good

### Confirmation

Keep me.
"#,
        ),
    ]
}

#[test]
fn fence_forms_consequences_patch_preserves_samples() {
    for (name, fixture) in fence_patch_cases() {
        let temp = TempDir::new().unwrap();
        let repo = Repository::init(temp.path(), None, true).unwrap();
        write_ng_fixture(&repo, 2, fixture);
        let path = repo.adr_path().join("0002-class-fixture.md");

        let mut adr = repo.get(2).unwrap();
        adr.consequences = "* New good.".into();
        repo.update(
            &adr,
            BodySectionPatch::new().with_consequences("* New good."),
        )
        .unwrap_or_else(|e| panic!("{name}: update failed: {e}"));

        let after = fs::read_to_string(&path).unwrap();
        assert!(
            after.contains("### Confirmation") && after.contains("Keep me."),
            "{name}: trailing H3 destroyed\n{after}"
        );
        assert!(
            after.contains("* New good."),
            "{name}: real consequences not patched\n{after}"
        );
        assert!(
            after.contains("Trailing after") || name == "four-space-indented-fence-lookalike",
            "{name}: trailing text after fence destroyed\n{after}"
        );
        match name {
            "nested-backticks" => assert!(
                after.matches("````").count() >= 2,
                "{name}: outer fence not closed\n{after}"
            ),
            "tilde-wraps-backticks" => assert!(
                after.matches("~~~").count() >= 2,
                "{name}: outer tilde fence not closed\n{after}"
            ),
            "backticks-wrap-tilde" => assert!(
                after.contains("Example backtick-wrapped tilde."),
                "{name}: inner sample lost\n{after}"
            ),
            "four-space-indented-fence-lookalike" => assert!(
                after.contains("not a fence"),
                "{name}: indented sample lost\n{after}"
            ),
            _ => {}
        }
    }
}

#[test]
fn append_consequences_after_no_trailing_newline_is_not_glued() {
    let temp = TempDir::new().unwrap();
    let repo = Repository::init(temp.path(), None, true).unwrap();

    // No trailing newline; Decision Outcome has no ### Consequences yet.
    let content = "---\nnumber: 2\ntitle: No trailing newline append\ndate: 2024-06-01\nstatus: accepted\n---\n\n## Decision Outcome\n\nChosen option only.";
    let path = repo.adr_path().join("0002-class-fixture.md");
    fs::write(&path, content).unwrap();
    assert_ne!(fs::read(&path).unwrap().last(), Some(&b'\n'));

    let mut adr = repo.get(2).unwrap();
    adr.consequences = "* Appended.".into();
    repo.update(
        &adr,
        BodySectionPatch::new().with_consequences("* Appended."),
    )
    .unwrap();

    let after = fs::read_to_string(&path).unwrap();
    assert!(
        !after.contains("only.### Consequences") && !after.contains("only.###"),
        "### Consequences must not glue onto prior line\n{after}"
    );
    assert!(
        after.contains("\n### Consequences\n"),
        "### Consequences must be on its own line\n{after}"
    );
    assert!(after.contains("* Appended."));
}

#[test]
fn create_then_append_consequences_not_glued() {
    // repo.create() often produces no trailing newline.
    let temp = TempDir::new().unwrap();
    let repo = Repository::init(temp.path(), None, true).unwrap();
    let mut adr = adrs_core::Adr::new(2, "Create append");
    adr.status = AdrStatus::Accepted;
    adr.decision = "Chosen option only.".into();
    let path = repo.create(&adr).unwrap();
    let raw = fs::read(&path).unwrap();
    // Precondition worth knowing; do not fail the test solely on it.
    let _ends_without_nl = raw.last() != Some(&b'\n');

    // Force MADR-style Decision Outcome without ### Consequences, no trailing NL.
    let forced = "---\nnumber: 2\ntitle: Create append\ndate: 2024-06-01\nstatus: accepted\n---\n\n## Decision Outcome\n\nChosen option only.";
    fs::write(&path, forced).unwrap();
    let mut adr = repo.get(2).unwrap();
    adr.consequences = "* From create path.".into();
    repo.update(
        &adr,
        BodySectionPatch::new().with_consequences("* From create path."),
    )
    .unwrap();

    let after = fs::read_to_string(&path).unwrap();
    assert!(
        !after.contains("only.### Consequences"),
        "create/append path glued heading\n{after}"
    );
    assert!(
        after.contains("\n### Consequences\n"),
        "expected standalone ### Consequences\n{after}"
    );
}

#[test]
fn madr_consequences_h2_before_decision_outcome_is_not_duplicated() {
    // When ## Consequences appears before ## Decision Outcome, a consequences
    // patch must update that H2 once and must not also inject ### Consequences.
    let fixture = r#"---
number: 2
title: Consequences before Decision Outcome
date: 2024-06-01
status: accepted
---

## Context and Problem Statement

Context.

## Consequences

* Old consequence

## Decision Outcome

Chosen option: X.

### Confirmation

Keep me.
"#;
    let temp = TempDir::new().unwrap();
    let repo = Repository::init(temp.path(), None, true).unwrap();
    write_ng_fixture(&repo, 2, fixture);
    let path = repo.adr_path().join("0002-class-fixture.md");

    repo.update(
        &repo.get(2).unwrap(),
        BodySectionPatch::new().with_consequences("* New consequence"),
    )
    .unwrap();

    let after = fs::read_to_string(&path).unwrap();
    assert!(
        after.contains("* New consequence"),
        "existing ## Consequences H2 must be patched\n{after}"
    );
    assert!(
        !after.contains("### Consequences"),
        "must not inject ### Consequences when ## Consequences already exists\n{after}"
    );
    assert_eq!(
        after.matches("* New consequence").count(),
        1,
        "consequence text must appear once\n{after}"
    );
    assert!(
        after.contains("Chosen option: X.") && after.contains("### Confirmation"),
        "Decision Outcome intro and Confirmation must survive\n{after}"
    );
    assert!(
        !after.contains("* Old consequence"),
        "old H2 body should be replaced\n{after}"
    );
}

#[test]
fn set_status_preserves_unknown_frontmatter_keys() {
    // Progressive baseline: unmanaged frontmatter keys must survive set_status
    // when the YAML Mapping is re-emitted.
    let fixture = r#"---
number: 2
title: Unknown keys
date: 2024-06-01
status: proposed
custom-meta: keep-me
extra-list:
  - one
  - two
---

## Context

C.

## Decision

D.

## Consequences

X.
"#;
    let temp = TempDir::new().unwrap();
    let repo = Repository::init(temp.path(), None, true).unwrap();
    write_ng_fixture(&repo, 2, fixture);
    let path = repo.adr_path().join("0002-class-fixture.md");

    repo.set_status(2, AdrStatus::Accepted, None).unwrap();

    let after = fs::read_to_string(&path).unwrap();
    assert!(
        after.contains("custom-meta: keep-me") || after.contains("custom-meta:keep-me"),
        "unmanaged scalar key must survive set_status\n{after}"
    );
    assert!(
        after.contains("extra-list:") && after.contains("one") && after.contains("two"),
        "unmanaged list key must survive set_status\n{after}"
    );
    assert!(after.contains("status: accepted"));
    repo.get(2).unwrap();
}

#[test]
fn set_status_scalar_makers_does_not_corrupt_block_scalar_consulted() {
    // Cross-field: scalar decision-makers + block-scalar consulted on status write.
    let fixture = r#"---
number: 2
title: Cross-field people
date: 2024-06-01
status: proposed
decision-makers: alice
consulted: >-
  the platform team
---

## Context

C.

## Decision

D.

## Consequences

X.
"#;
    let temp = TempDir::new().unwrap();
    let repo = Repository::init(temp.path(), None, true).unwrap();
    write_ng_fixture(&repo, 2, fixture);
    let path = repo.adr_path().join("0002-class-fixture.md");

    repo.set_status(2, AdrStatus::Accepted, None)
        .unwrap_or_else(|e| panic!("set_status failed: {e}"));

    let after = fs::read_to_string(&path).unwrap();
    let listed = repo
        .get(2)
        .unwrap_or_else(|e| panic!("ADR disappeared after set_status (cross-field): {e}\n{after}"));
    assert_eq!(listed.status, AdrStatus::Accepted);
    assert!(
        after.contains("the platform team"),
        "consulted value lost\n{after}"
    );
    assert!(
        !after.contains("consulted:\n  - the platform team\n  the platform team")
            && !after.contains("consulted:\n  - the platform team\n\n  the platform team"),
        "block-scalar consulted must not be orphaned beside list rewrite\n{after}"
    );
}

#[test]
fn add_link_preserves_block_scalar_consulted() {
    // link() on block-scalar people YAML must not drop the ADR from list.
    let source = r#"---
number: 2
title: Link source
date: 2024-06-01
status: proposed
consulted: >-
  the platform team
---

## Context

C.

## Decision

D.

## Consequences

X.
"#;
    let target = r#"---
number: 3
title: Link target
date: 2024-06-01
status: accepted
---

## Context

C.

## Decision

D.

## Consequences

X.
"#;
    let temp = TempDir::new().unwrap();
    let repo = Repository::init(temp.path(), None, true).unwrap();
    write_ng_fixture(&repo, 2, source);
    write_ng_fixture(&repo, 3, target);
    let path = repo.adr_path().join("0002-class-fixture.md");

    repo.link(2, 3, LinkKind::Amends, LinkKind::AmendedBy)
        .unwrap_or_else(|e| panic!("link failed: {e}"));

    let after = fs::read_to_string(&path).unwrap();
    let listed = repo
        .get(2)
        .unwrap_or_else(|e| panic!("ADR disappeared after link: {e}\n{after}"));
    assert!(
        listed.links.iter().any(|l| l.target == 3),
        "link not recorded\n{after}"
    );
    assert!(
        after.contains("the platform team"),
        "consulted value lost after link\n{after}"
    );
    assert!(
        !after.contains("consulted:\n  - the platform team\n  the platform team")
            && !after.contains("consulted:\n  - the platform team\n\n  the platform team"),
        "block-scalar consulted must not be orphaned after link\n{after}"
    );
}

#[test]
fn noop_metadata_preserves_zero_indent_tags_or_links() {
    // Pins tags/links zero-indent lists (same YAML class as people fields).
    let fixture = r#"---
number: 2
title: Zero indent tags links
date: 2024-06-01
status: proposed
tags:
- alpha
- beta
links:
- target: 3
  kind: amends
---

## Context

C.

## Decision

D.

## Consequences

X.
"#;
    let temp = TempDir::new().unwrap();
    let repo = Repository::init(temp.path(), None, true).unwrap();
    write_ng_fixture(&repo, 2, fixture);
    let path = repo.adr_path().join("0002-class-fixture.md");

    let adr = repo.get(2).unwrap();
    repo.update_metadata(&adr)
        .unwrap_or_else(|e| panic!("update_metadata failed: {e}"));

    let after = fs::read_to_string(&path).unwrap();
    repo.get(2)
        .unwrap_or_else(|e| panic!("ADR unreadable after noop tags/links: {e}\n{after}"));
    let fm = frontmatter_after_status(&after);
    assert!(
        !(fm.contains("  - alpha") && fm.contains("\n- alpha")),
        "tags must not leave orphaned zero-indent items beside rewrite\n{fm}"
    );
    assert!(
        after.contains("alpha") && after.contains("beta"),
        "tag values lost\n{after}"
    );
    assert!(
        after.contains("target: 3") && after.contains("kind: amends"),
        "link lost after noop metadata\n{after}"
    );
}

#[test]
fn baseline_body_only_preserves_non_canonical_status() {
    // Progressive baseline — must stay green (finding 4).
    let temp = TempDir::new().unwrap();
    let repo = Repository::init(temp.path(), None, false).unwrap();
    let content = r#"# 2. Non-canonical status

Date: 2026-01-15

## Status

Approved by the architecture board 2024-06-01

## Context

Original context.

## Decision

D.

## Consequences

C.
"#;
    let path = repo.adr_path().join("0002-status-prose.md");
    fs::write(&path, content).unwrap();
    repo.update(
        &repo.get(2).unwrap(),
        BodySectionPatch::new().with_context("Updated context."),
    )
    .unwrap();
    let after = fs::read_to_string(&path).unwrap();
    assert!(after.contains("Approved by the architecture board"));
    assert!(after.contains("Updated context."));
}

#[test]
fn baseline_simple_fence_consequences_patch() {
    // Progressive baseline — must stay green (exact fence repro).
    let temp = TempDir::new().unwrap();
    let repo = Repository::init(temp.path(), None, true).unwrap();
    let content = r#"---
number: 2
title: Simple fence
date: 2024-06-01
status: accepted
---

## Decision Outcome

Chosen.

```markdown
## Consequences

Inside.
```

Trailing.

### Consequences

* Old

### Confirmation

Keep.
"#;
    let path = repo.adr_path().join("0002-simple-fence.md");
    fs::write(&path, content).unwrap();
    let mut adr = repo.get(2).unwrap();
    adr.consequences = "* New".into();
    repo.update(&adr, BodySectionPatch::new().with_consequences("* New"))
        .unwrap();
    let after = fs::read_to_string(&path).unwrap();
    assert!(after.contains("Inside."));
    assert!(after.contains("### Confirmation"));
    assert!(after.contains("* New"));
}

#[test]
fn baseline_decision_patch_no_trailing_newline() {
    // Progressive baseline — must stay green (exact append_lines repro).
    let temp = TempDir::new().unwrap();
    let repo = Repository::init(temp.path(), None, false).unwrap();
    let content = "# 2. Compact\n\nDate: 2026-01-15\n\n## Status\n\nAccepted\n\n## Context\n\nOld context.\n\n## Decision\n\nOld decision.\n\n## Consequences\n\nOld consequences.";
    let path = repo.adr_path().join("0002-compact.md");
    fs::write(&path, content).unwrap();
    repo.update(
        &repo.get(2).unwrap(),
        BodySectionPatch::new().with_decision("New decision."),
    )
    .unwrap();
    let after = fs::read_to_string(&path).unwrap();
    assert!(!after.contains("Old context.## Decision"));
    assert!(after.contains("New decision."));
}