dodot-lib 5.10.0

Core library for dodot dotfiles manager
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
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
//! Pack planner — the "what would we do" computation.
//!
//! Owns [`plan_pack`] (the main planner), [`plan_pack_inner`] (the
//! actual scan → preprocess → match-rules → group-by-handler →
//! to_intents pipeline), the [`PackPlan`] result type,
//! [`build_gate_table`] (`HostFacts`/`[gates]` merging), and the
//! per-pack `collect_pack_intents` API plus its diagnostic helpers
//! (`missing_target_hints`, `display_path_relative_to_home`).
//!
//! The driver in `mod.rs` calls this layer to plan one pack at a time;
//! the runner functions there then take the resulting intents and feed
//! them to the executor.

use std::path::{Path, PathBuf};

use tracing::{debug, info};

use crate::gates::{GateTable, HostFacts};
use crate::handlers;
use crate::packs::context::ExecutionContext;
use crate::packs::Pack;
use crate::rules::{self, Scanner};
use crate::Result;

// ── Built-in "up" pipeline helpers ──────────────────────────────

/// Collect handler intents for a pack **without** executing them.
///
/// Runs the scan → preprocess → match rules → group by handler →
/// to_intents pipeline and returns the generated intents. This is the
/// first half of the two-phase execution model that enables cross-pack
/// conflict detection before any mutations happen.
///
/// Uses the default preprocessor registry
/// ([`crate::preprocessing::default_registry`]).
pub fn collect_pack_intents(
    pack: &Pack,
    ctx: &ExecutionContext,
) -> Result<Vec<crate::operations::HandlerIntent>> {
    let pack_config = ctx.config_manager.config_for_pack(&pack.path)?;
    // [secret] is intentionally root-only — see SecretSection docs.
    let root_config = ctx.config_manager.root_config()?;
    let (registry, _secret_registry) = crate::preprocessing::default_registry(
        &pack_config.preprocessor,
        &root_config.secret,
        ctx.paths.as_ref(),
        ctx.command_runner.clone(),
    )?;
    collect_pack_intents_inner(pack, ctx, &pack_config, Some(&registry))
}

/// Like [`collect_pack_intents`], but accepts an explicit preprocessor
/// registry. If `None`, no preprocessing occurs.
///
/// This variant exists for testing: callers can inject a registry with
/// test preprocessors without requiring config-driven registration.
pub fn collect_pack_intents_with_preprocessors(
    pack: &Pack,
    ctx: &ExecutionContext,
    preprocessors: Option<&crate::preprocessing::PreprocessorRegistry>,
) -> Result<Vec<crate::operations::HandlerIntent>> {
    let pack_config = ctx.config_manager.config_for_pack(&pack.path)?;
    collect_pack_intents_inner(pack, ctx, &pack_config, preprocessors)
}

/// Plan for a single pack — the intents the executor will run plus
/// any soft warnings the handlers emitted during planning.
///
/// Warnings are non-fatal, human-readable strings (currently the
/// `_lib/` non-macOS skip notice from
/// `docs/proposals/macos-paths.lex` §4.2). Callers that surface
/// `PackStatusResult.warnings` should consume them; pure-execution
/// callers can ignore the field.
#[derive(Debug, Default, Clone)]
pub struct PackPlan {
    pub intents: Vec<crate::operations::HandlerIntent>,
    pub warnings: Vec<String>,
    /// Files whose handler `--no-provision` dropped before intent
    /// generation. They produce no intent and therefore no operation,
    /// so the renderers read this list to still give each one a row —
    /// otherwise a `--no-provision` run silently omits the very files
    /// the user chose to skip. Empty whenever `--no-provision` is off.
    pub provision_skipped: Vec<ProvisionSkip>,
    /// Files whose manager is not usable on this machine — absent, or
    /// impossible to probe. The dry-run renderer places their rows for
    /// the same reason as `provision_skipped`: no intent means no
    /// operation and, without a row, an absent manager reads as an
    /// empty pack.
    ///
    /// A real `up` renders through `status::status()`, which asks the
    /// same probe on its own planning pass, so this list is the
    /// dry-run half of an answer both paths compute identically. Both
    /// paths do read it for one thing: a
    /// [`ProbeFailed`](crate::provisioners::availability::Availability::ProbeFailed)
    /// entry is the only failure with no operation to carry its
    /// verdict, so `up` counts it here (ADR-0008).
    ///
    /// Ephemeral: an availability is a fact about this machine right
    /// now and is never written to the datastore.
    pub provision_unavailable: Vec<ProvisionUnavailable>,
    /// Files whose current deployment claims this plan does not
    /// contain, because passive preprocessing surfaced them without a
    /// current render and their handler reads its targets out of that
    /// render. See [`UnresolvedClaim`].
    ///
    /// Always empty for an Active plan. A caller that only executes
    /// the plan can ignore it; a caller that reads the plan as
    /// evidence about a pack — adopt's cross-pack conflict analysis —
    /// must treat a non-empty list as "the answer is unknown," not as
    /// "there is nothing here."
    pub unresolved_claims: Vec<UnresolvedClaim>,
}

/// One matched file whose deployment claims are missing from a
/// [`PackPlan`], rather than absent from the pack.
///
/// Produced only in [`PreprocessMode::Passive`](crate::preprocessing::PreprocessMode::Passive),
/// for the entries it lists in
/// [`PreprocessResult::unrendered`](crate::preprocessing::pipeline::PreprocessResult::unrendered):
/// a preprocessor entry dodot has never rendered, which surfaces as a
/// placeholder carrying no bytes, and one whose cached render was
/// produced from source bytes or a rendering context that have since
/// changed, which carries the *previous* render's bytes. A handler whose
/// [`targets_from_content`](crate::handlers::Handler::targets_from_content)
/// is true — `externals`, whose every target is a field inside
/// `externals.toml` — reads its claims out of those bytes, so for the
/// first it emits no intent at all and for the second it emits the
/// targets the pack claimed before the edit. Either way the plan is
/// not what this pack deploys next.
///
/// The remedy is one `dodot up` on the owning pack: it renders the
/// current source, writes the baseline, and every later passive plan
/// reads the claims from that baseline.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UnresolvedClaim {
    /// The pack the file belongs to.
    pub pack: String,
    /// The handler whose claims for this file the plan does not have.
    pub handler: String,
    /// The source file whose current contents are unrendered,
    /// pack-relative — the path to name when telling a user what to
    /// render, e.g. `externals.toml.tmpl`.
    pub source: String,
}

/// One file dropped from a run by `--no-provision`, carrying what the
/// renderers need to place its row: the handler that would have
/// claimed it and its pack-relative path.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProvisionSkip {
    pub handler: String,
    pub relative_path: String,
}

/// One file that produced no intent because its manager is not on
/// this machine.
///
/// Deliberately distinct from [`ProvisionSkip`]: `--no-provision` is
/// the user's own choice and absence is the machine's state, and the
/// two have different remedies — one is a flag the user dropped, the
/// other is a manager to install.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProvisionUnavailable {
    pub handler: String,
    pub relative_path: String,
    /// Absent (with the locations probed) or ProbeFailed (with the
    /// detail). Never `Present` — a present manager produces intents
    /// instead of a row here.
    pub availability: crate::provisioners::availability::Availability,
}

/// Like [`collect_pack_intents`], but returns both intents and any
/// soft warnings the handlers produced during planning.
///
/// Use this when surfacing per-pack warnings in user-facing output
/// (e.g. `commands::up` populating `PackStatusResult.warnings`). Pure
/// execution callers should keep using [`collect_pack_intents`].
///
/// `mode` controls the preprocessing envelope. Active runs (`dodot up`
/// with no `--dry-run`) pass [`PreprocessMode::Active`]; passive
/// callers (`dodot status`, `dodot up --dry-run`) pass
/// [`PreprocessMode::Passive`] so the pipeline reads from the
/// baseline cache instead of evaluating templates and writing
/// rendered files. See `docs/proposals/secrets.lex` §7.4.
pub fn plan_pack(
    pack: &Pack,
    ctx: &ExecutionContext,
    mode: crate::preprocessing::PreprocessMode,
) -> Result<PackPlan> {
    let pack_config = ctx.config_manager.config_for_pack(&pack.path)?;
    // [secret] is intentionally root-only — see SecretSection docs.
    let root_config = ctx.config_manager.root_config()?;
    let (registry, _secret_registry) = crate::preprocessing::default_registry(
        &pack_config.preprocessor,
        &root_config.secret,
        ctx.paths.as_ref(),
        ctx.command_runner.clone(),
    )?;
    plan_pack_inner(pack, ctx, &pack_config, Some(&registry), mode, &[])
}

/// [`plan_pack`], with the pack's own entries at `superseded` left out
/// of the scan and its configuration taken from `config_at` rather
/// than from the directory being scanned.
///
/// `adopt` is the caller: to decide whether the pack it is about to
/// publish into would collide with another pack, it has to plan the
/// tree that publication *will* leave, not the one on disk now. Under
/// `--force` those differ — an entry the run replaces still claims its
/// old deployment target, and planning it would refuse the run over a
/// conflict the replacement removes. Passing the in-pack paths the run
/// replaces drops them here, and the caller plans the prepared
/// replacements separately and composes the two.
///
/// `superseded` holds paths relative to the pack root **as they sit on
/// disk**, `_<label>/` gate segments included — the paths publication
/// writes, not the rewritten ones a passing directory gate produces
/// (see [`is_superseded`]). A path that names a directory excludes
/// everything under it, because an adopted directory replaces the whole
/// subtree.
///
/// A path *nested inside* a top-level entry excludes nothing, and that
/// is the tree publication leaves rather than an approximation of it:
/// replacing `lua/plugins/init.lua` leaves the `lua` directory in the
/// pack with the rest of its contents, so the entry has to stay in the
/// plan. What it claims does not change across the replacement either.
/// Only the top-level entries a pack walk returns reach the rule
/// matcher and the handlers — a directory entry is handed to its
/// handler whole, and preprocessing partitions the same top-level list
/// rather than descending — so a nested file produces no claim of its
/// own. The claims the entry does produce are derived from paths, which
/// the replacement occupies identically. The one handler that reads its
/// targets out of file content instead
/// ([`Handler::targets_from_content`](crate::handlers::Handler::targets_from_content))
/// therefore only ever reads a top-level file, which `superseded` names
/// directly.
///
/// `config_at` is the pack path whose configuration governs the scan:
/// the rules, gates, `[pack] ignore` list and preprocessor settings
/// [`ConfigManager::config_for_pack`](crate::config::ConfigManager::config_for_pack)
/// resolves there decide what the walk reads and how it reads it. It
/// is `pack.path` for a pack on disk. It is not for the prepared tree,
/// which sits in adopt's staging directory and carries no
/// `.dodot.toml` of its own: resolving configuration from that path
/// answers with the root layer and plans a pack nobody has. A
/// destination pack whose `[pack] ignore` replaces the root list would
/// then have its prospective entries dropped here while the scan of
/// the real pack keeps them — and the cross-pack conflict this plan
/// exists to find can be among exactly those entries.
pub fn plan_pack_without(
    pack: &Pack,
    config_at: &Path,
    ctx: &ExecutionContext,
    mode: crate::preprocessing::PreprocessMode,
    superseded: &[PathBuf],
) -> Result<PackPlan> {
    let pack_config = ctx.config_manager.config_for_pack(config_at)?;
    let root_config = ctx.config_manager.root_config()?;
    let (registry, _secret_registry) = crate::preprocessing::default_registry(
        &pack_config.preprocessor,
        &root_config.secret,
        ctx.paths.as_ref(),
        ctx.command_runner.clone(),
    )?;
    plan_pack_inner(pack, ctx, &pack_config, Some(&registry), mode, superseded)
}

/// Resolve the gate table for a pack: built-in seed plus any
/// user-defined `[gates]` entries from config.
fn build_gate_table(pack_config: &crate::config::DodotConfig) -> Result<GateTable> {
    let mut table = GateTable::with_builtins();
    if !pack_config.gates.is_empty() {
        table.merge_user(&pack_config.gates)?;
    }
    Ok(table)
}

/// Apply pre-preprocess gate evaluation to a freshly-walked entry list.
///
/// Three gate sources are evaluated here, all *before* `preprocess_pack`
/// runs:
///
/// - **Directory-segment gates** (`_<label>/`) — already done by
///   `walk_pack`; entries arriving with `gate_failure: Some(...)` pass
///   through untouched.
/// - **Basename gates** (`<stem>._<label>.<ext>`) — parsed here,
///   passing-suffixed entries get their `relative_path` rewritten to
///   the stripped form so the preprocessor sees `aliases.sh.tmpl` (not
///   `aliases._darwin.sh.tmpl`); failing entries flip to
///   `gate_failure: Some(...)`.
/// - **`[mappings.gates]` glob → label** — globs evaluated here so a
///   mapping-gated template/secret-bearing file never reaches the
///   preprocessor either. Same flag-as-`gate_failure` flow.
///
/// Why all three at this layer: preprocessing fires render +
/// secret-provider + baseline-cache work on every preprocessor-shaped
/// file. If any gate evaluation only happened post-preprocess, a
/// gated-out template still triggers all of that for an entry the
/// user explicitly opted out of. Putting all three here keeps gates
/// honest about "predicate false ⇒ no work."
///
/// A file carrying both a filename gate AND a matching
/// `[mappings.gates]` entry is a hard error (one source of truth).
pub(crate) fn filter_pre_preprocess_gates(
    entries: Vec<crate::rules::PackEntry>,
    gates: &GateTable,
    host: &HostFacts,
    pack_name: &str,
    mappings_gates: &std::collections::HashMap<String, String>,
) -> Result<Vec<crate::rules::PackEntry>> {
    use crate::gates::{parse_basename_gate, BasenameGate};
    use crate::rules::GateFailure;

    // Shared with `match_entries` — see `gates::compile_mapping_gates`
    // for the ordering and validation contract.
    let compiled_mapping_gates = crate::gates::compile_mapping_gates(mappings_gates, pack_name)?;

    // Helper: build a GateFailure from a label + predicate, summarising
    // the host facts the predicate cares about. Shared between the
    // basename-fail and mapping-fail branches. Same compact shape as
    // `GatePredicate::describe` so the status footnote can render
    // both sides uniformly.
    let make_failure = |label: &str, pred: &crate::gates::GatePredicate| -> GateFailure {
        let host_desc: Vec<String> = pred
            .matchers
            .iter()
            .map(|(dim, _)| {
                let actual = host.get(*dim).unwrap_or("<unset>");
                format!("{}={}", dim.as_str(), actual)
            })
            .collect();
        GateFailure {
            label: label.to_string(),
            predicate: pred.describe(),
            host: host_desc.join(", "),
        }
    };

    let mut out = Vec::with_capacity(entries.len());
    for entry in entries {
        if entry.gate_failure.is_some() {
            out.push(entry);
            continue;
        }

        let filename = entry
            .relative_path
            .file_name()
            .map(|n| n.to_string_lossy().to_string())
            .unwrap_or_default();
        let basename_gate = parse_basename_gate(&filename);
        // Forward-slash-normalised path so Windows backslashes
        // don't break globs written with `/` in config and docs.
        let rel_str = crate::gates::rel_path_for_glob(&entry.relative_path);
        let mapping_match: Option<&str> = compiled_mapping_gates
            .iter()
            .find(|(pat, _)| pat.matches(&rel_str))
            .map(|(_, label)| *label);

        if let (BasenameGate::Found { .. }, Some(map_label)) = (&basename_gate, mapping_match) {
            return Err(crate::DodotError::Config(format!(
                "gate-routing conflict in pack `{pack_name}` for `{}`: \
                 file carries both a filename gate token (`._<label>`) \
                 and a `[mappings.gates]` entry (`{map_label}`). \
                 Pick one — either rename the file (drop the suffix) \
                 or remove the `[mappings.gates]` entry.",
                entry.relative_path.display()
            )));
        }

        match basename_gate {
            BasenameGate::Found { label, stripped } => {
                let pred = gates.lookup(label).ok_or_else(|| {
                    crate::DodotError::Config(format!(
                        "unknown gate label `{label}` in pack `{pack_name}`, file `{}`: \
                         label is not in the built-in seed and not defined in [gates]. \
                         Built-ins: darwin, linux, macos, arm64, aarch64, x86_64.",
                        entry.relative_path.display()
                    ))
                })?;
                if pred.matches(host) {
                    let stripped_rel = entry.relative_path.with_file_name(&stripped);
                    out.push(crate::rules::PackEntry {
                        relative_path: stripped_rel,
                        absolute_path: entry.absolute_path,
                        is_dir: entry.is_dir,
                        gate_failure: None,
                    });
                } else {
                    out.push(crate::rules::PackEntry {
                        relative_path: entry.relative_path,
                        absolute_path: entry.absolute_path,
                        is_dir: entry.is_dir,
                        gate_failure: Some(make_failure(label, pred)),
                    });
                }
            }
            BasenameGate::None => {
                if let Some(map_label) = mapping_match {
                    let pred = gates.lookup(map_label).ok_or_else(|| {
                        crate::DodotError::Config(format!(
                            "unknown gate label `{map_label}` referenced from \
                             `[mappings.gates]` in pack `{pack_name}`: label is \
                             not in the built-in seed and not defined in [gates]."
                        ))
                    })?;
                    if pred.matches(host) {
                        out.push(entry);
                    } else {
                        out.push(crate::rules::PackEntry {
                            relative_path: entry.relative_path,
                            absolute_path: entry.absolute_path,
                            is_dir: entry.is_dir,
                            gate_failure: Some(make_failure(map_label, pred)),
                        });
                    }
                } else {
                    out.push(entry);
                }
            }
        }
    }
    Ok(out)
}

/// Does `entry` sit at one of the pack paths the caller's plan
/// replaces, or inside one of them?
///
/// The comparison is against the entry's path *as it sits in the pack*
/// — `absolute_path` minus the pack root — not against
/// `relative_path`, which the walk has already rewritten wherever a
/// directory gate passed: a `_darwin/externals.toml` on a Darwin host
/// surfaces as `externals.toml`, while the caller names the path
/// publication writes, `_darwin/externals.toml`. Comparing the
/// rewritten form would keep every entry an `--only-os` adoption
/// replaces, planning both the old claims and the new ones. Comparing
/// the on-disk path also drops the whole subtree of a gate directory
/// the caller supersedes wholesale, since each child's on-disk path
/// still carries the `_<label>/` segment.
fn is_superseded(pack_path: &Path, entry: &rules::PackEntry, superseded: &[PathBuf]) -> bool {
    let in_pack = entry
        .absolute_path
        .strip_prefix(pack_path)
        .unwrap_or(entry.absolute_path.as_path());
    superseded.iter().any(|s| in_pack.starts_with(s))
}

fn collect_pack_intents_inner(
    pack: &Pack,
    ctx: &ExecutionContext,
    pack_config: &crate::config::DodotConfig,
    preprocessors: Option<&crate::preprocessing::PreprocessorRegistry>,
) -> Result<Vec<crate::operations::HandlerIntent>> {
    plan_pack_inner(
        pack,
        ctx,
        pack_config,
        preprocessors,
        crate::preprocessing::PreprocessMode::Active,
        &[],
    )
    .map(|p| p.intents)
}

/// Same scan/preprocess/match/group/intents pipeline as
/// [`collect_pack_intents_inner`], but additionally collects
/// per-handler `warnings_for_matches` output.
///
/// Takes the pack config pre-loaded: both entrypoints load it once and
/// pass it through, so config is not re-merged per pack. `ConfigManager`
/// caches by path anyway, but threading it explicitly makes the data
/// flow obvious.
fn plan_pack_inner(
    pack: &Pack,
    ctx: &ExecutionContext,
    pack_config: &crate::config::DodotConfig,
    preprocessors: Option<&crate::preprocessing::PreprocessorRegistry>,
    mode: crate::preprocessing::PreprocessMode,
    superseded: &[PathBuf],
) -> Result<PackPlan> {
    let rules = crate::config::mappings_to_rules(&pack_config.mappings);
    let gates = build_gate_table(pack_config)?;
    let host = ctx.host_facts.as_ref();

    // [pack] os gate — short-circuit inactive packs. Without this,
    // intent collection still runs for packs the host doesn't deploy,
    // which can hit cross-pack conflict detection or trigger
    // preprocessor side-effects (template render, secret-provider
    // calls) that the user explicitly opted out of via `[pack] os`.
    if !crate::gates::pack_os_active(&pack_config.pack.os, host) {
        debug!(
            pack = %pack.name,
            allowed = ?pack_config.pack.os,
            current_os = %host.os,
            "pack inactive on this OS, returning empty plan"
        );
        // Nothing to compute and nothing left uncomputed: a pack this
        // OS excludes deploys nothing here, so an empty claim list is
        // the whole truth rather than a gap in it.
        return Ok(PackPlan {
            intents: Vec::new(),
            warnings: Vec::new(),
            provision_skipped: Vec::new(),
            provision_unavailable: Vec::new(),
            unresolved_claims: Vec::new(),
        });
    }

    // Phase 1: Walk pack directory. The walk handles directory-segment
    // gates (`_<label>/`) — passing gates expand transparently, failing
    // gates surface as PackEntry { gate_failure: Some(...) }.
    let scanner = Scanner::new(ctx.fs.as_ref());
    let entries = scanner.walk_pack(&pack.path, &pack_config.pack.ignore, &gates, host)?;
    debug!(pack = %pack.name, entries = entries.len(), "walked pack directory");

    // Phase 1.1: Drop entries a caller has told us this plan supersedes
    // — see `plan_pack_without`. Matched on each entry's on-disk path
    // rather than its `relative_path`, which the walk has already
    // rewritten for a passing directory gate; `is_superseded` says why.
    let entries = if superseded.is_empty() {
        entries
    } else {
        let kept: Vec<_> = entries
            .into_iter()
            .filter(|e| !is_superseded(&pack.path, e, superseded))
            .collect();
        debug!(pack = %pack.name, entries = kept.len(), "dropped superseded entries");
        kept
    };

    // Phase 1.5: Apply the remaining gate sources before preprocessing
    // — see `filter_pre_preprocess_gates` for why they belong here.
    // match_entries re-evaluates these gates so a failure also surfaces
    // as a `gate`-handler match.
    let entries = filter_pre_preprocess_gates(
        entries,
        &gates,
        host,
        &pack.name,
        &pack_config.mappings.gates,
    )?;

    // Phase 2: Preprocessing
    let preprocess_result = if let Some(registry) = preprocessors {
        if !registry.is_empty() && pack_config.preprocessor.enabled {
            crate::preprocessing::pipeline::preprocess_pack(
                entries,
                registry,
                pack,
                ctx.fs.as_ref(),
                ctx.datastore.as_ref(),
                ctx.paths.as_ref(),
                mode,
                ctx.force,
            )?
        } else {
            crate::preprocessing::pipeline::PreprocessResult::passthrough(entries)
        }
    } else {
        crate::preprocessing::pipeline::PreprocessResult::passthrough(entries)
    };

    // Phase 3: Merge and match rules. Reuse the gate table + host
    // facts from phase 1 so basename/dir gates see the same view.
    // (Failed basename gates were already converted to gate-handler
    // matches in phase 1.5; match_entries sees them as gate_failure
    // entries and re-emits them.)
    let all_entries = preprocess_result.merged_entries();
    let mut matches = scanner.match_entries(
        &all_entries,
        &rules,
        &pack.name,
        &gates,
        host,
        &pack_config.mappings.gates,
    )?;
    debug!(pack = %pack.name, files = matches.len(), "matched rules");

    // Propagate preprocessor source info and in-memory rendered
    // bytes onto each match. Handlers that hash rendered content
    // for sentinel construction (`install`, `homebrew`) read the
    // bytes from `m.rendered_bytes` first, falling back to disk
    // for non-template files. That decoupling is the structural
    // enabler for §7.4 Passive mode where rendered files are
    // intentionally not on disk. See issue #121.
    for m in &mut matches {
        if let Some(source) = preprocess_result.source_map.get(&m.absolute_path) {
            m.preprocessor_source = Some(source.clone());
        }
        if let Some(bytes) = preprocess_result.rendered_bytes.get(&m.absolute_path) {
            m.rendered_bytes = Some(bytes.clone());
        }
    }

    // Phase 4: Group by handler
    let groups = rules::group_by_handler(&matches);

    // Build handler registry (drives the phase-based execution order).
    let registry = handlers::create_registry(ctx.fs.as_ref());
    let order = rules::handler_execution_order(&groups, &registry);
    debug!(pack = %pack.name, handlers = ?order, "handler execution order");

    // Which matched files have no render of their current contents,
    // and therefore tell a content-reading handler nothing or tell it
    // something out of date? Only passive planning produces any
    // (`PreprocessResult::unrendered`); an active plan rendered
    // everything it surfaced, so this set is empty and the loop below
    // records nothing.
    let unrendered: std::collections::HashSet<&PathBuf> =
        preprocess_result.unrendered.iter().collect();
    let mut unresolved_claims: Vec<UnresolvedClaim> = Vec::new();

    // Generate intents from each handler
    let mut all_intents = Vec::new();
    let mut all_warnings = Vec::new();
    let mut provision_skipped: Vec<ProvisionSkip> = Vec::new();
    let mut provision_unavailable: Vec<ProvisionUnavailable> = Vec::new();

    // Surface preserved-divergent-file warnings from the preprocessing
    // pipeline. These are the §6.4 "deployed file edited" cases: dodot
    // refused to overwrite the user's edit and held the previous render
    // in place. The user resolves them via `dodot transform check`
    // (auto-merge through the clean filter) or `dodot up --force`
    // (overwrite).
    for skipped in &preprocess_result.skipped {
        let display_path = display_path_relative_to_home(&skipped.deployed_path, ctx);
        let detail = match skipped.state {
            crate::preprocessing::divergence::DivergenceState::OutputChanged => {
                "deployed file was edited since the last `dodot up`"
            }
            crate::preprocessing::divergence::DivergenceState::BothChanged => {
                "both the source template and the deployed file were edited since the last `dodot up`"
            }
            _ => "deployed file diverges from the cached baseline",
        };
        let warning = format!(
            "preserved {} ({}). Run `dodot transform check` to reconcile, or re-run with --force to overwrite.",
            display_path, detail,
        );
        tracing::warn!(pack = %pack.name, file = %skipped.virtual_relative.display(), "{warning}");
        all_warnings.push(warning);
    }
    for handler_name in &order {
        let handler = match registry.get(handler_name.as_str()) {
            Some(h) => h,
            None => {
                debug!(pack = %pack.name, handler = %handler_name, "skipping unknown handler");
                continue;
            }
        };

        if ctx.no_provision && handler.category() == handlers::HandlerCategory::CodeExecution {
            debug!(pack = %pack.name, handler = %handler_name, "skipping code-execution handler (--no-provision)");
            // Record what was dropped. No intent means no operation
            // and, without this, no row at all — the user would be
            // told nothing about the files they asked to skip.
            if let Some(handler_matches) = groups.get(handler_name) {
                for m in handler_matches {
                    if m.is_dir {
                        continue;
                    }
                    provision_skipped.push(ProvisionSkip {
                        handler: handler_name.clone(),
                        relative_path: m.relative_path.to_string_lossy().into_owned(),
                    });
                }
            }
            continue;
        }

        // Is the manager there? Asked once per provisioning handler
        // the pack actually matched files for — a machine with no
        // `Brewfile` never probes for brew — and asked before any
        // intent exists, because an absent manager must produce no
        // intent, no receipt, and no error.
        //
        // The answer comes from the one shared module `status` also
        // reads, so the two agree by construction. `install` is not
        // located by dodot and always answers present; see
        // `provisioners::availability`.
        //
        // A present answer also names *which* executable answered,
        // and that path is kept: the run has to spawn the brew the
        // probe found, not whatever `PATH` resolves later. See
        // `located_at` at its use below.
        let mut located_at: Option<PathBuf> = None;
        if crate::provisioners::descriptor_for(handler_name).is_some() {
            let availability = crate::provisioners::availability::probe(
                ctx.fs.as_ref(),
                ctx.provision_host.as_ref(),
                handler_name,
            );
            if let crate::provisioners::availability::Availability::Present { at } = &availability {
                located_at = at.clone();
            }
            if !availability.is_present() {
                debug!(
                    pack = %pack.name,
                    handler = %handler_name,
                    ?availability,
                    "skipping provisioning handler — manager unusable on this host"
                );
                if let Some(handler_matches) = groups.get(handler_name) {
                    for m in handler_matches {
                        if m.is_dir {
                            continue;
                        }
                        provision_unavailable.push(ProvisionUnavailable {
                            handler: handler_name.clone(),
                            relative_path: m.relative_path.to_string_lossy().into_owned(),
                            availability: availability.clone(),
                        });
                    }
                }
                continue;
            }
        }

        if let Some(handler_matches) = groups.get(handler_name) {
            // Reached only for a handler this run actually plans with:
            // the `--no-provision` and absent-manager branches above
            // already moved on, and a handler that generates no intent
            // leaves nothing for a caller to find incomplete. What is
            // recorded here are the files this handler was asked about
            // and cannot answer for as they stand now — a placeholder
            // or a superseded render given to a handler that reads its
            // targets out of file content.
            if !unrendered.is_empty() && handler.targets_from_content() {
                for m in handler_matches {
                    if !unrendered.contains(&m.absolute_path) {
                        continue;
                    }
                    // Name the template the user has to render, not the
                    // datastore path they have never seen.
                    let source = m
                        .preprocessor_source
                        .as_ref()
                        .and_then(|p| p.strip_prefix(&pack.path).ok())
                        .map(|p| p.to_string_lossy().into_owned())
                        .unwrap_or_else(|| m.relative_path.to_string_lossy().into_owned());
                    debug!(
                        pack = %pack.name,
                        handler = %handler_name,
                        file = %source,
                        "no current render for a handler that reads its targets from \
                         file content; the plan does not state what this pack claims"
                    );
                    unresolved_claims.push(UnresolvedClaim {
                        pack: pack.name.clone(),
                        handler: handler_name.clone(),
                        source,
                    });
                }
            }

            let mut intents = handler.to_intents(
                handler_matches,
                &pack.config,
                ctx.paths.as_ref(),
                ctx.fs.as_ref(),
            )?;
            // Run the executable the probe found, not the name.
            //
            // `command_for` names its program the way a user would
            // (`brew`, `nix`), which leaves the OS to resolve it
            // through `PATH` at spawn time — a second, different
            // question from the one the probe just answered. A brew
            // sitting at `/opt/homebrew/bin/brew` on a host whose
            // `PATH` omits it would pass the probe and then fail to
            // spawn, and the probe's whole promise is that a run
            // dodot planned is a run dodot can make. Substituting the
            // located path here keeps `command_for` a pure function
            // of the manifest path and leaves the arguments — and so
            // the manifest positions declared in
            // `provisioners::PROVISIONERS` — untouched.
            //
            // `None` for `install`, whose interpreter is a `PATH`
            // lookup by design (ADR-0007), and for any handler dodot
            // does not locate.
            //
            // Substituted only when the path can be *named* in the
            // `String` an intent's executable is. A lossy conversion
            // would be the worst of the three outcomes: the probe
            // read `$HOMEBREW_PREFIX` as bytes precisely so a
            // non-UTF-8 prefix keeps its candidate, and replacing
            // those bytes with U+FFFD here would hand the spawn a
            // path that names nothing — dodot would find brew and
            // then fail to run it, reporting "not found" about a file
            // it had just stat'd. Leaving the handler's own name
            // instead puts the row back where every provisioning row
            // was before the probe existed: the OS resolves it
            // through `PATH`, which is what `install` does by design.
            // Carrying the bytes through to the spawn means an
            // OS-native executable type across `HandlerIntent`,
            // `Operation`, `CommandSpec`, and every `CommandRunner` —
            // an epic-wide change, not this handler's to make.
            if let Some(at) = &located_at {
                match at.to_str() {
                    Some(program) => {
                        for intent in &mut intents {
                            if let crate::operations::HandlerIntent::Run { executable, .. } = intent
                            {
                                *executable = program.to_string();
                            }
                        }
                    }
                    None => {
                        let warning = format!(
                            "{handler_name} was found at {}, a path dodot cannot name exactly. \
                             Running `{handler_name}` as your shell would resolve it instead.",
                            at.display()
                        );
                        tracing::warn!(pack = %pack.name, handler = %handler_name, "{warning}");
                        all_warnings.push(warning);
                    }
                }
            }
            debug!(
                pack = %pack.name,
                handler = %handler_name,
                intents = intents.len(),
                "generated intents"
            );
            all_intents.extend(intents);

            let warnings =
                handler.warnings_for_matches(handler_matches, &pack.config, ctx.paths.as_ref());
            for w in &warnings {
                tracing::warn!(pack = %pack.name, handler = %handler_name, "{w}");
            }
            all_warnings.extend(warnings);
        }
    }

    // Missing-target hints — macOS only.
    //
    // For each Link intent that lands under `app_support_dir`, check
    // whether the immediate child folder exists on disk. If not, the
    // user is about to deploy GUI-app config to a directory the app
    // hasn't created yet — usually because the app isn't installed.
    // Surface a soft hint, optionally enriched with a matching brew
    // cask token. Resolver/intent state is unaffected.
    //
    // On Linux `app_support_dir` collapses to `xdg_config_home`, so
    // this check would fire for *every* `~/.config/<X>/` deploy —
    // not what we want. Gate on macOS strictly.
    if cfg!(target_os = "macos") {
        all_warnings.extend(missing_target_hints(&all_intents, ctx));
    }

    info!(
        pack = %pack.name,
        intents = all_intents.len(),
        warnings = all_warnings.len(),
        "collected intents"
    );
    Ok(PackPlan {
        intents: all_intents,
        warnings: all_warnings,
        provision_skipped,
        provision_unavailable,
        unresolved_claims,
    })
}

/// Render an absolute path with `$HOME` collapsed to `~` for human
/// display. Falls back to the absolute form when the path is outside
/// the home tree.
fn display_path_relative_to_home(path: &std::path::Path, ctx: &ExecutionContext) -> String {
    let home = ctx.paths.home_dir();
    match path.strip_prefix(home) {
        Ok(rel) => format!("~/{}", rel.display()),
        Err(_) => path.display().to_string(),
    }
}

/// Probe each `Link` intent that targets `app_support_dir/<X>/...` and
/// emit a soft hint when the `<X>/` folder is missing on disk.
///
/// macOS-only — caller checks `cfg!(target_os = "macos")` first to
/// avoid firing on Linux where every XDG-routed entry would otherwise
/// hit this branch.
fn missing_target_hints(
    intents: &[crate::operations::HandlerIntent],
    ctx: &ExecutionContext,
) -> Vec<String> {
    use std::collections::BTreeSet;
    let app_support = ctx.paths.app_support_dir();
    if app_support == ctx.paths.xdg_config_home() {
        // `app_uses_library = false` collapsed the app-support root
        // onto XDG; same Linux-style suppression applies.
        return Vec::new();
    }

    // Distinct `<X>` folders referenced by intents — one warning per
    // missing folder, regardless of how many files target it.
    let mut needed: BTreeSet<String> = BTreeSet::new();
    for intent in intents {
        if let crate::operations::HandlerIntent::Link { user_path, .. } = intent {
            if let Ok(rel) = user_path.strip_prefix(app_support) {
                if let Some(first) = rel.components().find_map(|c| match c {
                    std::path::Component::Normal(s) => Some(s.to_string_lossy().into_owned()),
                    _ => None,
                }) {
                    needed.insert(first);
                }
            }
        }
    }
    if needed.is_empty() {
        return Vec::new();
    }

    let mut missing: Vec<String> = Vec::new();
    for folder in &needed {
        let target = app_support.join(folder);
        if !ctx.fs.exists(&target) {
            missing.push(folder.clone());
        }
    }
    if missing.is_empty() {
        return Vec::new();
    }

    // Brew enrichment: try to associate each missing folder with an
    // *installed* cask token. Cache-only mode keeps the planner fast:
    // a stale or missing cache entry silently degrades to the
    // unenriched message rather than spawning a `brew info` subprocess
    // per installed cask. The on-demand `dodot probe app` subcommand
    // populates the cache; this hint just consumes it.
    let cache_dir = ctx.paths.probes_brew_cache_dir();
    let now = crate::probe::brew::now_secs_unix();
    let matches = crate::probe::brew::match_folders_to_installed_casks(
        &missing,
        ctx.command_runner.as_ref(),
        &cache_dir,
        now,
        ctx.fs.as_ref(),
        /*cache_only=*/ true,
    );

    missing
        .into_iter()
        .map(|folder| match matches.folder_to_token.get(&folder) {
            // The cask IS installed (we got the token from `brew list`)
            // but the folder is empty — usually the user pre-deployed
            // dotfiles before launching the app for the first time.
            Some(token) => format!(
                "cask `{token}` is installed but `{folder}/` is missing — \
                 entries will deploy, but the app may not have created its \
                 config directory yet (try launching it once)"
            ),
            None => format!(
                "target directory `{}/{folder}` doesn't exist yet — entries will \
                 deploy but no matching installed app appears to provide it",
                app_support.display()
            ),
        })
        .collect()
}

#[cfg(test)]
mod tests {
    #![allow(unused_imports)]

    use std::sync::Arc;

    use super::super::test_support::{make_context, MockCommandRunner, TestUpCommand};
    use super::super::{
        collect_pack_intents, execute, execute_intents, prepare_packs, run_handler_pipeline,
    };
    use super::{collect_pack_intents_with_preprocessors, plan_pack};
    use crate::config::ConfigManager;
    use crate::datastore::CommandRunner;
    use crate::datastore::FilesystemDataStore;
    use crate::fs::Fs;
    use crate::packs::Pack;
    use crate::paths::Pather;
    use crate::testing::TempEnvironment;

    // ── --no-provision bookkeeping ─────────────────────────────

    /// The planner is the only place that knows a code-execution
    /// handler was dropped: the drop happens before intent generation,
    /// so nothing downstream can infer it from the intents. Both
    /// renderers read this list to give the dropped files a row.
    #[test]
    fn no_provision_records_what_it_dropped() {
        let env = TempEnvironment::builder()
            .pack("vim")
            .file("vimrc", "set nocompatible")
            .file("install.sh", "#!/bin/sh\necho setup")
            .done()
            .build();

        let ctx = make_context(&env); // no_provision = true
        let pack = Pack::new(
            "vim".into(),
            env.dotfiles_root.join("vim"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("vim"))
                .unwrap()
                .to_handler_config(),
        );

        let plan = plan_pack(&pack, &ctx, crate::preprocessing::PreprocessMode::Passive).unwrap();

        assert_eq!(
            plan.provision_skipped,
            vec![super::ProvisionSkip {
                handler: "install".into(),
                relative_path: "install.sh".into(),
            }],
        );
        assert!(
            plan.intents
                .iter()
                .any(|i| matches!(i, crate::operations::HandlerIntent::Link { .. })),
            "configuration handlers must still plan normally"
        );
    }

    #[test]
    fn provisioning_runs_leave_the_skip_list_empty() {
        let env = TempEnvironment::builder()
            .pack("vim")
            .file("install.sh", "#!/bin/sh\necho setup")
            .done()
            .build();

        let mut ctx = make_context(&env);
        ctx.no_provision = false;
        let pack = Pack::new(
            "vim".into(),
            env.dotfiles_root.join("vim"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("vim"))
                .unwrap()
                .to_handler_config(),
        );

        let plan = plan_pack(&pack, &ctx, crate::preprocessing::PreprocessMode::Passive).unwrap();

        assert!(
            plan.provision_skipped.is_empty(),
            "nothing was skipped: {:?}",
            plan.provision_skipped
        );
    }

    // ── Preprocessing integration tests ────────────────────────

    #[test]
    fn preprocessing_identity_file_deploys_via_symlink_handler() {
        let env = TempEnvironment::builder()
            .pack("app")
            .file("config.toml.identity", "host = localhost")
            .done()
            .build();

        let ctx = make_context(&env);
        let pack = Pack::new(
            "app".into(),
            env.dotfiles_root.join("app"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("app"))
                .unwrap()
                .to_handler_config(),
        );

        let mut registry = crate::preprocessing::PreprocessorRegistry::new();
        registry.register(Box::new(
            crate::preprocessing::identity::IdentityPreprocessor::new(),
        ));

        let intents =
            collect_pack_intents_with_preprocessors(&pack, &ctx, Some(&registry)).unwrap();

        assert_eq!(intents.len(), 1, "intents: {intents:?}");

        match &intents[0] {
            crate::operations::HandlerIntent::Link {
                pack: p,
                handler,
                source,
                user_path,
            } => {
                assert_eq!(p, "app");
                assert_eq!(handler, "symlink");
                assert!(
                    source.to_string_lossy().contains("preprocessed"),
                    "source should be in preprocessed dir: {}",
                    source.display()
                );
                let user_str = user_path.to_string_lossy();
                assert!(
                    !user_str.contains("identity"),
                    "user_path should not have .identity: {user_str}"
                );
            }
            other => panic!("expected Link intent, got: {other:?}"),
        }
    }

    #[test]
    fn preprocessing_mixed_pack_deploys_both() {
        let env = TempEnvironment::builder()
            .pack("app")
            .file("config.toml.identity", "preprocessed content")
            .file("plain.txt", "regular content")
            .done()
            .build();

        let ctx = make_context(&env);
        let pack = Pack::new(
            "app".into(),
            env.dotfiles_root.join("app"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("app"))
                .unwrap()
                .to_handler_config(),
        );

        let mut registry = crate::preprocessing::PreprocessorRegistry::new();
        registry.register(Box::new(
            crate::preprocessing::identity::IdentityPreprocessor::new(),
        ));

        let intents =
            collect_pack_intents_with_preprocessors(&pack, &ctx, Some(&registry)).unwrap();

        assert_eq!(intents.len(), 2, "intents: {intents:?}");

        let intent_sources: Vec<String> = intents
            .iter()
            .filter_map(|i| match i {
                crate::operations::HandlerIntent::Link { source, .. } => {
                    Some(source.to_string_lossy().to_string())
                }
                _ => None,
            })
            .collect();

        let has_preprocessed = intent_sources.iter().any(|s| s.contains("preprocessed"));
        let has_regular = intent_sources
            .iter()
            .any(|s| s.contains("dotfiles/app/plain.txt"));
        assert!(
            has_preprocessed,
            "should have a preprocessed source: {intent_sources:?}"
        );
        assert!(
            has_regular,
            "should have a regular source: {intent_sources:?}"
        );
    }

    #[test]
    fn preprocessing_collision_detected() {
        let env = TempEnvironment::builder()
            .pack("app")
            .file("config.toml.identity", "preprocessed")
            .file("config.toml", "regular")
            .done()
            .build();

        let ctx = make_context(&env);
        let pack = Pack::new(
            "app".into(),
            env.dotfiles_root.join("app"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("app"))
                .unwrap()
                .to_handler_config(),
        );

        let mut registry = crate::preprocessing::PreprocessorRegistry::new();
        registry.register(Box::new(
            crate::preprocessing::identity::IdentityPreprocessor::new(),
        ));

        let err =
            collect_pack_intents_with_preprocessors(&pack, &ctx, Some(&registry)).unwrap_err();
        assert!(
            matches!(err, crate::DodotError::PreprocessorCollision { .. }),
            "expected PreprocessorCollision, got: {err}"
        );
    }

    #[test]
    fn preprocessing_disabled_via_config_treats_files_as_regular() {
        let env = TempEnvironment::builder()
            .pack("app")
            .file("config.toml.identity", "content")
            .done()
            .build();

        env.fs
            .write_file(
                &env.dotfiles_root.join(".dodot.toml"),
                b"[preprocessor]\nenabled = false\n",
            )
            .unwrap();

        let ctx = make_context(&env);
        let pack = Pack::new(
            "app".into(),
            env.dotfiles_root.join("app"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("app"))
                .unwrap()
                .to_handler_config(),
        );

        let mut registry = crate::preprocessing::PreprocessorRegistry::new();
        registry.register(Box::new(
            crate::preprocessing::identity::IdentityPreprocessor::new(),
        ));

        let intents =
            collect_pack_intents_with_preprocessors(&pack, &ctx, Some(&registry)).unwrap();

        assert_eq!(intents.len(), 1);
        match &intents[0] {
            crate::operations::HandlerIntent::Link { user_path, .. } => {
                let user_str = user_path.to_string_lossy();
                assert!(
                    user_str.contains("identity"),
                    "with preprocessing disabled, file should keep .identity extension: {user_str}"
                );
            }
            other => panic!("expected Link intent, got: {other:?}"),
        }
    }

    #[test]
    fn preprocessing_no_registry_works_like_before() {
        let env = TempEnvironment::builder()
            .pack("vim")
            .file("vimrc", "set nocompatible")
            .done()
            .build();

        let ctx = make_context(&env);
        let pack = Pack::new(
            "vim".into(),
            env.dotfiles_root.join("vim"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("vim"))
                .unwrap()
                .to_handler_config(),
        );

        let intents = collect_pack_intents_with_preprocessors(&pack, &ctx, None).unwrap();

        assert_eq!(intents.len(), 1);
        match &intents[0] {
            crate::operations::HandlerIntent::Link { source, .. } => {
                assert!(
                    source.to_string_lossy().contains("vim/vimrc"),
                    "source should be the pack file: {}",
                    source.display()
                );
            }
            other => panic!("expected Link intent, got: {other:?}"),
        }
    }

    #[test]
    fn preprocessing_end_to_end_deploy_and_verify_content() {
        let env = TempEnvironment::builder()
            .pack("app")
            .file("config.toml.identity", "host = localhost\nport = 5432")
            .done()
            .build();

        let ctx = make_context(&env);
        let pack = Pack::new(
            "app".into(),
            env.dotfiles_root.join("app"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("app"))
                .unwrap()
                .to_handler_config(),
        );

        let mut registry = crate::preprocessing::PreprocessorRegistry::new();
        registry.register(Box::new(
            crate::preprocessing::identity::IdentityPreprocessor::new(),
        ));

        let intents =
            collect_pack_intents_with_preprocessors(&pack, &ctx, Some(&registry)).unwrap();

        let user_path = match &intents[0] {
            crate::operations::HandlerIntent::Link { user_path, .. } => user_path.clone(),
            other => panic!("expected Link intent, got: {other:?}"),
        };

        let results = execute_intents(intents, &ctx).unwrap();

        assert!(
            results.iter().all(|r| r.success),
            "all operations should succeed: {results:?}"
        );

        assert!(
            ctx.fs.exists(&user_path),
            "user file should exist at: {}",
            user_path.display()
        );
        assert!(
            ctx.fs.is_symlink(&user_path),
            "user file should be a symlink"
        );

        let content = ctx.fs.read_to_string(&user_path).unwrap();
        assert_eq!(content, "host = localhost\nport = 5432");
    }

    #[test]
    fn preprocessing_error_propagates_through_pipeline() {
        // Expansion errors should propagate through the pipeline.
        // We test this at the pipeline level (not orchestration) since
        // the scanner won't see a file that doesn't exist. The pipeline
        // tests in pipeline.rs cover this case directly. Here we verify
        // that a valid preprocessor file that triggers an error during
        // a lower-level operation still propagates correctly.
        //
        // Use the unarchive preprocessor with a corrupted archive.
        let env = TempEnvironment::builder()
            .pack("tools")
            .file("bad.tar.gz", "this is not valid gzip data at all")
            .done()
            .build();

        let ctx = make_context(&env);
        let pack = Pack::new(
            "tools".into(),
            env.dotfiles_root.join("tools"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("tools"))
                .unwrap()
                .to_handler_config(),
        );

        let mut registry = crate::preprocessing::PreprocessorRegistry::new();
        registry.register(Box::new(
            crate::preprocessing::unarchive::UnarchivePreprocessor::new(),
        ));

        let err =
            collect_pack_intents_with_preprocessors(&pack, &ctx, Some(&registry)).unwrap_err();
        assert!(
            matches!(err, crate::DodotError::PreprocessorError { .. }),
            "expected PreprocessorError, got: {err}"
        );
    }

    #[test]
    fn preprocessing_multiple_types_in_registry() {
        let env = TempEnvironment::builder()
            .pack("app")
            .file("config.toml.identity", "identity content")
            .done()
            .build();

        let ctx = make_context(&env);
        let pack = Pack::new(
            "app".into(),
            env.dotfiles_root.join("app"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("app"))
                .unwrap()
                .to_handler_config(),
        );

        let mut registry = crate::preprocessing::PreprocessorRegistry::new();
        registry.register(Box::new(
            crate::preprocessing::identity::IdentityPreprocessor::new(),
        ));
        registry.register(Box::new(
            crate::preprocessing::unarchive::UnarchivePreprocessor::new(),
        ));

        let intents =
            collect_pack_intents_with_preprocessors(&pack, &ctx, Some(&registry)).unwrap();

        assert_eq!(intents.len(), 1);
        match &intents[0] {
            crate::operations::HandlerIntent::Link { source, .. } => {
                assert!(source.to_string_lossy().contains("preprocessed"));
            }
            other => panic!("expected Link intent, got: {other:?}"),
        }
    }

    #[test]
    fn collect_pack_intents_uses_default_registry() {
        // The normal `collect_pack_intents` entrypoint should wire the
        // default preprocessor registry (not pass `None`). We verify
        // this by putting a `.tar.gz` file in a pack — the default
        // registry contains `UnarchivePreprocessor`, so the archive
        // should be expanded rather than passed through.
        use flate2::write::GzEncoder;
        use flate2::Compression;

        let env = TempEnvironment::builder()
            .pack("tools")
            .file("placeholder", "")
            .done()
            .build();

        let archive_path = env.dotfiles_root.join("tools/payload.tar.gz");
        let file = std::fs::File::create(&archive_path).unwrap();
        let enc = GzEncoder::new(file, Compression::default());
        let mut builder = tar::Builder::new(enc);
        let content = b"#!/bin/sh\necho hi";
        let mut header = tar::Header::new_gnu();
        header.set_path("mytool").unwrap();
        header.set_size(content.len() as u64);
        header.set_mode(0o755);
        header.set_cksum();
        builder.append(&header, &content[..]).unwrap();
        let enc = builder.into_inner().unwrap();
        enc.finish().unwrap();

        let ctx = make_context(&env);
        let pack = Pack::new(
            "tools".into(),
            env.dotfiles_root.join("tools"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("tools"))
                .unwrap()
                .to_handler_config(),
        );

        let intents = collect_pack_intents(&pack, &ctx).unwrap();

        let has_expanded_source = intents.iter().any(|i| match i {
            crate::operations::HandlerIntent::Link { source, .. } => {
                source.to_string_lossy().contains("preprocessed")
                    && source.to_string_lossy().contains("mytool")
            }
            _ => false,
        });
        assert!(
        has_expanded_source,
        "production collect_pack_intents should expand .tar.gz via the default registry. Intents: {intents:?}"
    );
    }

    // ── Template preprocessor integration tests ─────────────────

    #[test]
    fn template_deploys_rendered_content_via_symlink_handler() {
        let env = TempEnvironment::builder()
            .pack("app")
            .file(
                "config.toml.tmpl",
                "name = \"{{ name }}\"\nos = \"{{ dodot.os }}\"",
            )
            .config("[preprocessor.template.vars]\nname = \"Alice\"\n")
            .done()
            .build();

        let ctx = make_context(&env);
        let pack = Pack::new(
            "app".into(),
            env.dotfiles_root.join("app"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("app"))
                .unwrap()
                .to_handler_config(),
        );

        let intents = collect_pack_intents(&pack, &ctx).unwrap();
        let user_path = match &intents[0] {
            crate::operations::HandlerIntent::Link { user_path, .. } => user_path.clone(),
            other => panic!("expected Link intent, got: {other:?}"),
        };

        let results = execute_intents(intents, &ctx).unwrap();
        assert!(
            results.iter().all(|r| r.success),
            "expected success: {results:?}"
        );

        let content = ctx.fs.read_to_string(&user_path).unwrap();
        let expected_os = std::env::consts::OS;
        assert_eq!(content, format!("name = \"Alice\"\nos = \"{expected_os}\""));
    }

    #[test]
    fn template_with_shell_handler_sources_rendered_content() {
        let env = TempEnvironment::builder()
            .pack("tools")
            .file("aliases.sh.tmpl", "alias hello='echo {{ greeting }}'")
            .config("[preprocessor.template.vars]\ngreeting = \"world\"\n")
            .done()
            .build();

        let ctx = make_context(&env);
        let pack = Pack::new(
            "tools".into(),
            env.dotfiles_root.join("tools"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("tools"))
                .unwrap()
                .to_handler_config(),
        );

        let intents = collect_pack_intents(&pack, &ctx).unwrap();
        assert_eq!(intents.len(), 1);

        match &intents[0] {
            crate::operations::HandlerIntent::Stage {
                handler, source, ..
            } => {
                assert_eq!(handler, "shell", "shell handler should own this");
                let content = ctx.fs.read_to_string(source).unwrap();
                assert_eq!(content, "alias hello='echo world'");
            }
            other => panic!("expected Stage intent, got: {other:?}"),
        }
    }

    #[test]
    fn template_respects_per_pack_var_overrides() {
        let env = TempEnvironment::builder()
            .pack("app")
            .file("greeting.tmpl", "hello {{ name }}")
            .config("[preprocessor.template.vars]\nname = \"Bob\"\n")
            .done()
            .build();

        env.fs
            .write_file(
                &env.dotfiles_root.join(".dodot.toml"),
                b"[preprocessor.template.vars]\nname = \"Alice\"\n",
            )
            .unwrap();

        let ctx = make_context(&env);
        let pack = Pack::new(
            "app".into(),
            env.dotfiles_root.join("app"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("app"))
                .unwrap()
                .to_handler_config(),
        );

        let intents = collect_pack_intents(&pack, &ctx).unwrap();
        match &intents[0] {
            crate::operations::HandlerIntent::Link { source, .. } => {
                let content = ctx.fs.read_to_string(source).unwrap();
                assert_eq!(content, "hello Bob", "pack-level override should win");
            }
            other => panic!("expected Link intent, got: {other:?}"),
        }
    }

    #[test]
    fn template_disabled_via_config_treats_files_as_regular() {
        let env = TempEnvironment::builder()
            .pack("app")
            .file("config.toml.tmpl", "name = \"{{ name }}\"")
            .done()
            .build();

        env.fs
            .write_file(
                &env.dotfiles_root.join(".dodot.toml"),
                b"[preprocessor]\nenabled = false\n",
            )
            .unwrap();

        let ctx = make_context(&env);
        let pack = Pack::new(
            "app".into(),
            env.dotfiles_root.join("app"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("app"))
                .unwrap()
                .to_handler_config(),
        );

        let intents = collect_pack_intents(&pack, &ctx).unwrap();
        assert_eq!(intents.len(), 1);
        match &intents[0] {
            crate::operations::HandlerIntent::Link {
                source, user_path, ..
            } => {
                assert!(
                    source.to_string_lossy().ends_with("config.toml.tmpl"),
                    "source: {}",
                    source.display()
                );
                assert!(
                    user_path.to_string_lossy().contains(".tmpl"),
                    "user_path should keep .tmpl extension: {}",
                    user_path.display()
                );
            }
            other => panic!("expected Link intent, got: {other:?}"),
        }
    }

    #[test]
    fn template_render_error_surfaces_with_source_path() {
        let env = TempEnvironment::builder()
            .pack("app")
            .file("bad.tmpl", "value = \"{{ undefined_var }}\"")
            .done()
            .build();

        let ctx = make_context(&env);
        let pack = Pack::new(
            "app".into(),
            env.dotfiles_root.join("app"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("app"))
                .unwrap()
                .to_handler_config(),
        );

        let err = collect_pack_intents(&pack, &ctx).unwrap_err();
        match err {
            crate::DodotError::TemplateRender { source_file, .. } => {
                assert!(
                    source_file.ends_with("bad.tmpl"),
                    "source_file: {}",
                    source_file.display()
                );
            }
            other => panic!("expected TemplateRender, got: {other:?}"),
        }
    }

    #[test]
    fn template_reserved_var_fails_fast() {
        // A user tries to define `dodot` as a variable — construction
        // of the preprocessor should fail before any rendering happens.
        let env = TempEnvironment::builder()
            .pack("app")
            .file("file.txt", "x")
            .done()
            .build();

        env.fs
            .write_file(
                &env.dotfiles_root.join(".dodot.toml"),
                b"[preprocessor.template.vars]\ndodot = \"pwn\"\n",
            )
            .unwrap();

        let ctx = make_context(&env);
        let pack = Pack::new(
            "app".into(),
            env.dotfiles_root.join("app"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("app"))
                .unwrap()
                .to_handler_config(),
        );

        let err = collect_pack_intents(&pack, &ctx).unwrap_err();
        assert!(
            matches!(err, crate::DodotError::TemplateReservedVar { ref name } if name == "dodot"),
            "got: {err}"
        );
    }

    #[test]
    fn template_with_install_handler_sentinel_reflects_rendered_content() {
        // install.sh.tmpl should render, and the sentinel should be
        // based on the rendered content (so vars changes re-run the
        // script). Verify by checking the sentinel name includes the
        // hash of the rendered content, not the template source.
        let env = TempEnvironment::builder()
            .pack("setup")
            .file(
                "install.sh.tmpl",
                "#!/bin/sh\necho \"installing on {{ dodot.os }}\"",
            )
            .done()
            .build();

        let mut ctx = make_context(&env);
        ctx.no_provision = false; // actually run install this time

        let pack = Pack::new(
            "setup".into(),
            env.dotfiles_root.join("setup"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("setup"))
                .unwrap()
                .to_handler_config(),
        );

        let intents = collect_pack_intents(&pack, &ctx).unwrap();
        let (sentinel, rendered_path) = match &intents[0] {
            crate::operations::HandlerIntent::Run {
                sentinel,
                arguments,
                ..
            } => (
                sentinel.clone(),
                std::path::PathBuf::from(
                    crate::provisioners::manifest_argument("install", arguments)
                        .expect("the install descriptor names the script argument"),
                ),
            ),
            other => panic!("expected Run intent, got: {other:?}"),
        };

        // Sentinel is "install.sh-{checksum}" where checksum is the
        // SHA-256 of the *rendered* script in the datastore.
        assert!(sentinel.starts_with("install.sh-"));

        let content = ctx.fs.read_to_string(&rendered_path).unwrap();
        assert!(
            content.contains(std::env::consts::OS),
            "rendered content should have OS substituted: {content}"
        );
    }

    #[test]
    fn plan_pack_surfaces_divergence_warnings() {
        // End-to-end: a template-deployed file gets edited by the user,
        // then `plan_pack` runs again. The pipeline preserves the edit
        // and `PackPlan.warnings` carries a human-readable warning that
        // mentions the deployed path, the resolution paths, and `--force`.
        let env = TempEnvironment::builder()
            .pack("app")
            .file("config.toml.tmpl", "name = original")
            .done()
            .build();

        let ctx = make_context(&env);
        let pack = Pack::new(
            "app".into(),
            env.dotfiles_root.join("app"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("app"))
                .unwrap()
                .to_handler_config(),
        );

        // First run: clean deploy, no warnings about preserved files.
        let first = plan_pack(&pack, &ctx, crate::preprocessing::PreprocessMode::Active).unwrap();
        assert!(
            first.warnings.iter().all(|w| !w.contains("preserved")),
            "first deploy must not produce a preservation warning: {:?}",
            first.warnings
        );

        // User edits the deployed file.
        let deployed = env
            .paths
            .handler_data_dir("app", "preprocessed")
            .join("config.toml");
        env.fs.write_file(&deployed, b"name = USER EDITED").unwrap();

        // Second run: warning surfaces, with the documented resolution
        // hints — `transform check` and `--force`.
        let second = plan_pack(&pack, &ctx, crate::preprocessing::PreprocessMode::Active).unwrap();
        let preserved: Vec<&String> = second
            .warnings
            .iter()
            .filter(|w| w.contains("preserved"))
            .collect();
        assert_eq!(
            preserved.len(),
            1,
            "expected one preservation warning, got: {:?}",
            second.warnings
        );
        let w = preserved[0];
        assert!(
            w.contains("config.toml"),
            "warning should name the file: {w}"
        );
        assert!(
            w.contains("transform check"),
            "warning should mention transform check: {w}"
        );
        assert!(w.contains("--force"), "warning should mention --force: {w}");
        // The user's edit must still be on disk.
        assert_eq!(
            env.fs.read_to_string(&deployed).unwrap(),
            "name = USER EDITED"
        );
    }

    #[test]
    fn plan_pack_force_overwrites_and_skips_warning() {
        // With ctx.force=true (the `--force` CLI flag), the guard is
        // bypassed: the deployed file gets re-rendered, no warning is
        // emitted. Documented escape hatch for env-var rotations and
        // similar out-of-band changes.
        let env = TempEnvironment::builder()
            .pack("app")
            .file("config.toml.tmpl", "name = original")
            .done()
            .build();

        let mut ctx = make_context(&env);
        let pack = Pack::new(
            "app".into(),
            env.dotfiles_root.join("app"),
            ctx.config_manager
                .config_for_pack(&env.dotfiles_root.join("app"))
                .unwrap()
                .to_handler_config(),
        );

        let _ = plan_pack(&pack, &ctx, crate::preprocessing::PreprocessMode::Active).unwrap();
        let deployed = env
            .paths
            .handler_data_dir("app", "preprocessed")
            .join("config.toml");
        env.fs.write_file(&deployed, b"name = USER EDITED").unwrap();

        ctx.force = true;
        let plan = plan_pack(&pack, &ctx, crate::preprocessing::PreprocessMode::Active).unwrap();
        assert!(
            plan.warnings.iter().all(|w| !w.contains("preserved")),
            "force=true must not emit preservation warnings: {:?}",
            plan.warnings
        );
        assert_eq!(
            env.fs.read_to_string(&deployed).unwrap(),
            "name = original",
            "force must overwrite the user's edit with the rendered content"
        );
    }
}