nativeview-cli 0.1.0-rc.1

Developer CLI (`nv`) for Native View Engine: dev hot-reload, builds, pairing, SDK management, app scaffolding, and docs.
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
//! Regression tests covering all 13 adversarial review findings for `view_diff` and
//! `hot_diff` workspace / style-chain integration.

use nativeview_engine::HotPatchMsg;
use nativeview_hot_reload::{AnchorKey as HotAnchorKey, HotPatchIndex};
use nativeview_store::{ChangeSet, Length, NodeId, NodeStore, RowPatchView};
use nativeview_tables::tables::{
    DebugId, Layout, Position, TextContent, register_core_tables,
};
use nativeview_view_syntax::compute_anchor_key;

use crate::hot_diff::WatchCache;
use crate::hot_diff::cache::workspace_relative_path;

use super::super::{ViewDiffOutcome, diff_view_source, has_view_macro};
use super::{expect_tier1, expect_tier2};

#[test]
fn finding1_attrs_match_arm_attrs_leading_colon_and_generics_require_tier2() {
    let base = r#"
fn ui(mode: u8) -> impl View {
    view! {
        #[cfg(feature = "a")]
        Column(gap: 8.0) {
            match mode {
                #[cfg(feature = "a")]
                0 => { "Zero" }
                _ => { "Other" }
            }
        }
    }
}
"#;
    let edit_node_attr = base.replacen("feature = \"a\"", "feature = \"b\"", 1);
    assert!(
        expect_tier2(diff_view_source("src/ui.rs", base, &edit_node_attr, 1))
            .contains("node attribute changed")
    );

    let edit_arm_attr = base.replace(
        "#[cfg(feature = \"a\")]\n                0 =>",
        "#[cfg(feature = \"b\")]\n                0 =>",
    );
    assert!(
        expect_tier2(diff_view_source("src/ui.rs", base, &edit_arm_attr, 1))
            .contains("match` arm attribute changed")
    );

    let colon_base = "fn ui() -> impl View { view! { Column(gap: 8.0) } }";
    let colon_edit = "fn ui() -> impl View { view! { ::Column(gap: 8.0) } }";
    assert!(
        expect_tier2(diff_view_source("src/ui.rs", colon_base, colon_edit, 1))
            .contains("element tag changed")
    );

    let gen_base = "fn ui() -> impl View { view! { Column::<A>(gap: 8.0) } }";
    let gen_changed = "fn ui() -> impl View { view! { Column::<B>(gap: 8.0) } }";
    assert!(
        expect_tier2(diff_view_source("src/ui.rs", gen_base, gen_changed, 1))
            .contains("element generics changed")
    );

    // Generic `Column::<A>` is NOT direct-root patchable -> editing its prop is Tier-2.
    let gen_prop_edit = "fn ui() -> impl View { view! { Column::<A>(gap: 16.0) } }";
    assert!(
        expect_tier2(diff_view_source("src/ui.rs", gen_base, gen_prop_edit, 1))
            .contains("composite component")
    );
}

#[test]
fn finding2_cfg_attributed_view_args_require_tier2_on_edit() {
    let base = r#"
fn ui() -> impl View {
    view! {
        Column(
            #[cfg(target_os = "ios")]
            padding: 12.0,
            #[cfg(debug_assertions)]
            test_id: "dbg",
            gap: 8.0,
        ) {
            Text(#[cfg(feature = "alt")] "Hello")
        }
    }
}
"#;
    let edit_named_cfg = base.replace("padding: 12.0", "padding: 20.0");
    assert!(
        expect_tier2(diff_view_source("src/ui.rs", base, &edit_named_cfg, 1))
            .contains("cfg-attributed argument changed")
    );

    let edit_pos_cfg = base.replace("\"Hello\"", "\"World\"");
    assert!(
        expect_tier2(diff_view_source("src/ui.rs", base, &edit_pos_cfg, 1))
            .contains("cfg-attributed argument changed")
    );

    // Editing an unattributed disjoint arg while cfg args are unchanged still Tier-1 patches.
    let edit_disjoint = base.replace("gap: 8.0", "gap: 16.0");
    let msgs = expect_tier1(diff_view_source("src/ui.rs", base, &edit_disjoint, 2));
    assert_eq!(msgs.len(), 1);
}

#[test]
fn finding3_unmounted_keyed_anchor_sharing_test_id_never_corrupts_live_node() {
    register_core_tables();
    let rel_file = "src/panel.rs";
    let base = r#"
fn panel(show: bool) -> impl View {
    view! {
        Column {
            if show {
                Column(test_id: "shared-id", padding: 8.0) {
                    Text("Hidden branch", test_id: "shared-text")
                }
            }
        }
    }
}
"#;
    let edited = base
        .replace("padding: 8.0", "padding: 32.0")
        .replace("\"Hidden branch\"", "\"Mutated branch\"");

    let msgs = expect_tier1(diff_view_source(rel_file, base, &edited, 5));
    assert_eq!(msgs.len(), 2);
    for msg in &msgs {
        let HotPatchMsg::TemplatePatch {
            template_key,
            target_test_id,
            ..
        } = msg
        else {
            unreachable!();
        };
        assert_ne!(*template_key, 0);
        assert!(
            target_test_id.is_none(),
            "keyed view! patch must never populate target_test_id fallback"
        );
    }

    // Mount two UNRELATED live nodes that happen to share the exact same `test_id` values.
    let mut store = NodeStore::new();
    let mut changes = ChangeSet::default();
    let mut index = HotPatchIndex::new();
    let (other_col, other_txt) = {
        let mut tx = store.tx();
        let col = tx.create();
        tx.edit::<Layout>(col).padding_top(Length::points(4.0));
        tx.edit::<DebugId>(col).test_id("shared-id");
        let txt = tx.create();
        tx.edit::<TextContent>(txt).text("Hidden branch");
        tx.edit::<DebugId>(txt).test_id("shared-text");
        tx.set_children(col, &[txt]);
        tx.set_children(NodeId::ROOT, &[col]);
        tx.commit_into(&mut changes);
        (col, txt)
    };
    index.register_anchor(
        other_col,
        HotAnchorKey::new(compute_anchor_key("src/other.rs", 0, &[0]).0),
    );
    index.register_anchor(
        other_txt,
        HotAnchorKey::new(compute_anchor_key("src/other.rs", 0, &[0, 0]).0),
    );

    {
        let mut tx = store.tx();
        for msg in &msgs {
            assert!(
                !index.apply_hot_patch_now(&mut tx, msg),
                "unmounted keyed anchor patch must not fall back to shared test_id"
            );
        }
        tx.commit_into(&mut changes);
    }

    assert_eq!(
        store.try_row::<Layout>(other_col).unwrap().padding_top(),
        Length::points(4.0)
    );
    assert_eq!(
        store.try_row::<TextContent>(other_txt).unwrap().text(),
        "Hidden branch"
    );
}

#[test]
fn finding4_shadowed_direct_props_style_precedence_and_unknown_props_fail_closed() {
    let cases = [
        // Direct prop shadowed by `style:` chain setting the same slot.
        (
            "Column(style: Style::col().padding(8.0), padding: 12.0)",
            "Column(style: Style::col().padding(8.0), padding: 20.0)",
        ),
        // Direct prop alongside non-chain `style:` expression.
        (
            "Column(style: card_style, padding: 12.0)",
            "Column(style: card_style, padding: 20.0)",
        ),
        // Direct prop alongside `.merge(...)` style chain.
        (
            "Column(style: Style::col().merge(extra), padding: 12.0)",
            "Column(style: Style::col().merge(extra), padding: 20.0)",
        ),
        // Multiple `style:` / `nv_style:` arguments when either changes.
        (
            "Column(style: Style::col().padding(8.0), nv_style: Style::new().gap(4.0))",
            "Column(style: Style::col().padding(16.0), nv_style: Style::new().gap(4.0))",
        ),
        // Bidirectional `layout_ext` gap overlap (`row_gap` before `gap`).
        (
            "Column(row_gap: 4.0, gap: 8.0)",
            "Column(row_gap: 4.0, gap: 16.0)",
        ),
        // Bidirectional `layout_ext` inline padding/margin overlaps.
        (
            "Column(padding_inline_start: 4.0, padding_x: 8.0)",
            "Column(padding_inline_start: 4.0, padding_x: 16.0)",
        ),
        (
            "Column(margin_inline_end: 4.0, margin_x: 8.0)",
            "Column(margin_inline_end: 4.0, margin_x: 16.0)",
        ),
        // Known shorthand props shadowing earlier direct props.
        (
            "Column(border_width: 1.0, border: (2.0, Rgba::BLACK))",
            "Column(border_width: 3.0, border: (2.0, Rgba::BLACK))",
        ),
        (
            "Column(padding: 8.0, padding_insets: insets)",
            "Column(padding: 16.0, padding_insets: insets)",
        ),
        (
            "Column(bg: Rgba::WHITE, surface: card_surface)",
            "Column(bg: Rgba::BLACK, surface: card_surface)",
        ),
        (
            "Text(\"Hi\", color: Rgba::WHITE, text_style: heading)",
            "Text(\"Hi\", color: Rgba::BLACK, text_style: heading)",
        ),
        // Unknown non-identity/non-event direct prop fails closed as `prop_bits::ALL`.
        (
            "Column(mystery_shorthand: foo, padding: 8.0)",
            "Column(mystery_shorthand: foo, padding: 16.0)",
        ),
    ];

    for (old_el, new_el) in cases {
        let old_src = format!("fn ui() -> impl View {{ view! {{ {old_el} }} }}");
        let new_src = format!("fn ui() -> impl View {{ view! {{ {new_el} }} }}");
        let reason = expect_tier2(diff_view_source("src/ui.rs", &old_src, &new_src, 1));
        assert!(!reason.is_empty(), "expected Tier-2 for `{old_el}` -> `{new_el}`");
    }

    // Disjoint `style:` + direct prop + identity/event props still Tier-1 patch cleanly.
    let ok_old = "fn ui() -> impl View { view! { Column(test_id: \"c\", on_press: move |_| {}, style: Style::col().padding(8.0), gap: 4.0) } }";
    let ok_new = ok_old.replace("gap: 4.0", "gap: 12.0");
    let msgs = expect_tier1(diff_view_source("src/ui.rs", ok_old, &ok_new, 2));
    assert_eq!(msgs.len(), 1);
}

#[test]
fn finding5_workspace_relative_path_parses_toml_tables_and_respects_exclude_and_explicit_root() {
    let base_dir = std::env::temp_dir().join(format!("nv-ws-rel-test-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&base_dir);

    // 1. Parent workspace with explicit `members` and `exclude`.
    let member_src = base_dir.join("crates/member/src");
    let excluded_src = base_dir.join("examples/standalone/src");
    let comment_ws_dir = base_dir.join("examples/comment_only");
    let comment_src = comment_ws_dir.join("src");
    std::fs::create_dir_all(&member_src).unwrap();
    std::fs::create_dir_all(&excluded_src).unwrap();
    std::fs::create_dir_all(&comment_src).unwrap();

    std::fs::write(
        base_dir.join("Cargo.toml"),
        "[workspace]\nmembers = [\"crates/*\"]\nexclude = [\"examples/standalone\"]\n",
    )
    .unwrap();
    std::fs::write(
        base_dir.join("crates/member/Cargo.toml"),
        "[package]\nname = \"member\"\nversion = \"0.1.0\"\nedition = \"2024\"\n",
    )
    .unwrap();
    std::fs::write(
        base_dir.join("examples/standalone/Cargo.toml"),
        "[package]\nname = \"standalone\"\nversion = \"0.1.0\"\nedition = \"2024\"\n",
    )
    .unwrap();
    // Comment/string containing `[workspace]` must NOT be treated as a real `[workspace]` table.
    std::fs::write(
        comment_ws_dir.join("Cargo.toml"),
        "# [workspace]\n[package]\nname = \"comment_only\"\ndescription = \"not a [workspace]\"\nversion = \"0.1.0\"\nedition = \"2024\"\n",
    )
    .unwrap();

    let member_file = member_src.join("lib.rs");
    let excluded_file = excluded_src.join("main.rs");
    let comment_file = comment_src.join("main.rs");
    std::fs::write(&member_file, "").unwrap();
    std::fs::write(&excluded_file, "").unwrap();
    std::fs::write(&comment_file, "").unwrap();

    assert_eq!(workspace_relative_path(&member_file), "crates/member/src/lib.rs");
    assert_eq!(workspace_relative_path(&excluded_file), "src/main.rs");
    assert_eq!(workspace_relative_path(&comment_file), "src/main.rs");

    // Explicit `workspace_root` passed to `WatchCache::with_workspace_root` takes precedence.
    let v0 = "fn ui() -> impl View { view! { Text(\"A\") } }\n";
    let v1 = "fn ui() -> impl View { view! { Text(\"B\") } }\n";
    std::fs::write(&excluded_file, v0).unwrap();
    let mut cache = WatchCache::with_workspace_root(&base_dir);
    cache.seed_dir(&excluded_src);
    std::fs::write(&excluded_file, v1).unwrap();
    let batch = cache
        .classify_batch(std::slice::from_ref(&excluded_file), 1)
        .expect("tier1 patch");
    let HotPatchMsg::TemplatePatch { template_key, .. } = &batch[0].messages[0] else {
        unreachable!();
    };
    assert_eq!(
        *template_key,
        compute_anchor_key("examples/standalone/src/main.rs", 0, &[0]).0
    );

    let _ = std::fs::remove_dir_all(&base_dir);
}

#[test]
fn finding6_view_macro_supports_parens_brackets_and_rejects_dot_view() {
    assert!(has_view_macro("fn a() { view!(Text(\"hi\")); }"));
    assert!(has_view_macro("fn a() { view![Text(\"hi\")]; }"));
    assert!(has_view_macro("fn a() { view! { Text(\"hi\") }; }"));
    assert!(!has_view_macro("fn a() { obj.view! { Text(\"hi\") }; }"));
    assert!(!has_view_macro("fn a() { obj . view!(Text(\"hi\")); }"));
    assert!(!has_view_macro("macro_rules! m { () => { view! { Text(\"hi\") } }; }"));

    let paren_old = "fn a() -> impl View { view!(Text(\"Old\")) }";
    let paren_new = "fn a() -> impl View { view!(Text(\"New\")) }";
    assert_eq!(
        expect_tier1(diff_view_source("src/a.rs", paren_old, paren_new, 1)).len(),
        1
    );

    let bracket_old = "fn a() -> impl View { view![Text(\"Old\")] }";
    let bracket_new = "fn a() -> impl View { view![Text(\"New\")] }";
    assert_eq!(
        expect_tier1(diff_view_source("src/a.rs", bracket_old, bracket_new, 1)).len(),
        1
    );
}

#[test]
fn finding7_nested_view_inside_unparsed_err_outer_view_requires_tier2() {
    // Outer `view!` has invalid syntax (`if { ... }` missing condition) in BOTH old and new,
    // while the nested `view!` parses cleanly. Editing the nested `view!` must NEVER Tier-1 patch.
    let base = r#"
fn broken() {
    view! {
        if {
            let _ = view! { Text("Inner") };
        }
    }
}

fn healthy() -> impl View {
    view! { Text("Healthy") }
}
"#;
    let edit_nested = base.replace("\"Inner\"", "\"Changed\"");
    assert!(
        expect_tier2(diff_view_source("src/nested.rs", base, &edit_nested, 1))
            .contains("unparsed view! block changed")
    );

    // Editing the healthy sibling while the unparsed outer `view!` is untouched still Tier-1 patches.
    let edit_sibling = base.replace("\"Healthy\"", "\"Still Healthy\"");
    let msgs = expect_tier1(diff_view_source("src/nested.rs", base, &edit_sibling, 2));
    assert_eq!(msgs.len(), 1);
}

#[test]
fn finding8_position_fixed_patches_via_view_diff() {
    let base = "fn ui() -> impl View { view! { Node(position: Position::Relative) } }";
    let edited = "fn ui() -> impl View { view! { Node(position: Position::Fixed) } }";
    let msgs = expect_tier1(diff_view_source("src/pos.rs", base, edited, 1));
    assert_eq!(msgs.len(), 1);
    let HotPatchMsg::TemplatePatch { row_patch_words, .. } = &msgs[0] else {
        unreachable!();
    };
    let rp = RowPatchView::from_words(row_patch_words).expect("valid RowPatch");
    assert_eq!(rp.get_prop(Layout::POSITION), Some(Position::Fixed));
}

#[test]
fn finding10_empty_static_text_updates_roundtrip_through_hot_patch_index() {
    register_core_tables();
    let rel_file = "src/empty_text.rs";
    let base = r#"
fn ui() -> impl View {
    view! {
        Column {
            ""
            Text("")
        }
    }
}
"#;
    let edited = base
        .replace("\"\"", "\"Hello\"")
        .replace("Text(\"Hello\")", "Text(\"World\")");

    let msgs = expect_tier1(diff_view_source(rel_file, base, &edited, 3));
    assert_eq!(msgs.len(), 2);

    for (msg, expected_text) in msgs.iter().zip(["Hello", "World"]) {
        let HotPatchMsg::TemplatePatch {
            text_updates,
            text_replacements,
            ..
        } = msg
        else {
            unreachable!();
        };
        assert!(text_replacements.is_empty());
        assert_eq!(text_updates.as_slice(), &[(0, expected_text.to_owned())]);
    }

    let mut store = NodeStore::new();
    let mut changes = ChangeSet::default();
    let mut index = HotPatchIndex::new();
    let (lit_id, txt_id) = {
        let mut tx = store.tx();
        let col = tx.create();
        let lit = tx.create();
        tx.edit::<TextContent>(lit).text("");
        let txt = tx.create();
        tx.edit::<TextContent>(txt).text("");
        tx.set_children(col, &[lit, txt]);
        tx.set_children(NodeId::ROOT, &[col]);
        tx.commit_into(&mut changes);
        (lit, txt)
    };
    index.register_anchor(
        lit_id,
        HotAnchorKey::new(compute_anchor_key(rel_file, 0, &[0, 0]).0),
    );
    index.register_anchor(
        txt_id,
        HotAnchorKey::new(compute_anchor_key(rel_file, 0, &[0, 1]).0),
    );

    {
        let mut tx = store.tx();
        for msg in &msgs {
            let bytes = msg.to_bytes().expect("serialize");
            let decoded = HotPatchMsg::from_bytes(&bytes).expect("decode");
            assert!(index.apply_hot_patch_now(&mut tx, &decoded));
        }
        tx.commit_into(&mut changes);
    }
    assert_eq!(store.try_row::<TextContent>(lit_id).unwrap().text(), "Hello");
    assert_eq!(store.try_row::<TextContent>(txt_id).unwrap().text(), "World");

    // Non-leaf `Text("") { "child" }` rejects empty text edit to Tier-2.
    let non_leaf_old = "fn ui() -> impl View { view! { Text(\"\") { \"child\" } } }";
    let non_leaf_new = "fn ui() -> impl View { view! { Text(\"World\") { \"child\" } } }";
    assert!(
        expect_tier2(diff_view_source(rel_file, non_leaf_old, non_leaf_new, 4))
            .contains("non-leaf `Text`")
    );
}

#[test]
fn finding11_test_id_with_braces_unescapes_for_logs_without_setting_target_test_id() {
    let base = "fn ui() -> impl View { view! { Column(test_id: \"card-{0}\", gap: 4.0) } }";
    let edited = base.replace("gap: 4.0", "gap: 12.0");
    let ViewDiffOutcome::Tier1Patch { patch, messages } =
        diff_view_source("src/id.rs", base, &edited, 1)
    else {
        unreachable!("expected Tier1Patch");
    };
    assert!(
        patch.log_lines().iter().any(|l| l.contains("test_id \"card-{0}\"")),
        "expected unescaped brace test_id in log lines: {:?}",
        patch.log_lines()
    );
    let HotPatchMsg::TemplatePatch { target_test_id, .. } = &messages[0] else {
        unreachable!();
    };
    assert!(target_test_id.is_none());
}

#[test]
fn finding12_deduplicates_batch_paths_and_preserves_view_tier2_reason() {
    let dir = std::env::temp_dir().join(format!("nv-dedup-hybrid-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&dir);
    let src_dir = dir.join("src");
    std::fs::create_dir_all(&src_dir).unwrap();
    std::fs::write(
        dir.join("Cargo.toml"),
        "[package]\nname = \"hybrid\"\nversion = \"0.1.0\"\nedition = \"2024\"\n",
    )
    .unwrap();

    let hybrid = src_dir.join("hybrid.rs");
    let base = r#"
fn v() -> impl View {
    view! {
        Column(gap: 8.0) {
            Button(label: "Save")
        }
    }
}
fn helper() -> u32 {
    4
}
"#;
    std::fs::write(&hybrid, base).unwrap();

    let mut cache = WatchCache::new();
    cache.seed_dir(&src_dir);

    // 1. Duplicate normalized paths in one batch produce a single ClassifiedFilePatch.
    let v1 = base.replace("gap: 8.0", "gap: 16.0");
    std::fs::write(&hybrid, &v1).unwrap();
    let dup_path = dir.join("src").join(".").join("hybrid.rs");
    let batch = cache
        .classify_batch(&[hybrid.clone(), dup_path], 1)
        .expect("deduplicated Tier-1 batch");
    assert_eq!(batch.len(), 1, "duplicate paths must be deduplicated");

    // 2. Rust logic edits outside `view!` require Tier-2 and keep the old baseline.
    let v2 = v1.replace("    4\n", "    12\n");
    std::fs::write(&hybrid, &v2).unwrap();
    cache
        .classify_batch(std::slice::from_ref(&hybrid), 2)
        .expect_err("Rust logic edit outside view! must require Tier-2");
    std::fs::write(&hybrid, &v1).unwrap();
    let v2 = v1.clone();

    // 3. Hybrid file edit on composite `Button` inside `view!` preserves `view_diff`'s specific reason.
    let v3 = v2.replace("\"Save\"", "\"Submit\"");
    std::fs::write(&hybrid, &v3).unwrap();
    let err = cache
        .classify_batch(std::slice::from_ref(&hybrid), 3)
        .expect_err("composite Button edit must require Tier-2");
    assert!(
        err.contains("Button"),
        "expected view_diff's specific `Button` reason to be preserved, got: {err}"
    );

    let _ = std::fs::remove_dir_all(&dir);
}