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
561
562
563
use std::ffi::OsStr;
use std::path::{Path, PathBuf};

use nativeview_engine::HotPatchMsg;

use super::*;

#[test]
fn hot_reload_helpers_cover_platform_paths_and_filters() {
    let dylib = dylib_path_for_package_in(Path::new("target"), "nativeview-example-kitchen-sink");
    let s = dylib.to_string_lossy();
    assert!(s.contains("nativeview_example_kitchen_sink"), "unexpected path: {s}");
    if cfg!(target_os = "macos") {
        assert_eq!(s, "target/debug/libnativeview_example_kitchen_sink.dylib");
    } else if cfg!(target_os = "windows") {
        assert_eq!(s, "target/debug/nativeview_example_kitchen_sink.dll");
    } else {
        assert_eq!(s, "target/debug/libnativeview_example_kitchen_sink.so");
    }

    let custom_dylib = dylib_path_for_package_in(Path::new("/var/cache/cargo"), "nativeview-studio-workspace");
    assert!(custom_dylib.starts_with("/var/cache/cargo/debug"));

    assert_eq!(ws_bind_addr("0.0.0.0", 8089), "0.0.0.0:8089");
    assert_eq!(ws_bind_addr("::1", 8089), "[::1]:8089");
    assert!(is_relevant_source_path(Path::new(
        "examples/studio-workspace/src/ui.rs"
    )));
    assert!(!is_relevant_source_path(Path::new(
        "examples/studio-workspace/src/.ui.rs.swp"
    )));

    let msg = make_dylib_reload_msg(3, &dylib, 180);
    assert_eq!(
        HotPatchMsg::from_bytes(&msg.to_bytes().unwrap()).unwrap(),
        msg
    );

    use notify::event::{AccessKind, CreateKind, ModifyKind, RemoveKind};
    assert!(should_trigger_rebuild(&notify::EventKind::Create(
        CreateKind::File
    )));
    assert!(should_trigger_rebuild(&notify::EventKind::Modify(
        ModifyKind::Any
    )));
    assert!(!should_trigger_rebuild(&notify::EventKind::Access(
        AccessKind::Any
    )));
    assert!(should_trigger_rebuild(&notify::EventKind::Remove(
        RemoveKind::File
    )));
}

#[test]
fn skia_shell_subprocess_resolution_and_args_reject_missing_override() {
    let err = resolve_explicit_skia_shell_bin(OsStr::new("/nonexistent/path/to/nativeview-skia-shell"))
        .expect_err("non-existent NV_SKIA_SHELL_BIN must return explicit error");
    assert!(err.contains("NV_SKIA_SHELL_BIN"), "unexpected err: {err}");
    assert!(resolve_explicit_skia_shell_bin(OsStr::new("")).is_err());

    let parsed =
        cargo_env::parse_cargo_target_dir(br#"{"target_directory":"/tmp/custom target"}"#).unwrap();
    assert_eq!(parsed, PathBuf::from("/tmp/custom target"));
    assert!(cargo_env::parse_cargo_target_dir(br#"{"target_directory":""}"#).is_err());
    assert!(cargo_env::parse_cargo_target_dir(b"{}").is_err());

    let args = skia_shell_args(
        Path::new("target/debug/libapp.dylib"),
        "ws://127.0.0.1:8089",
        &NvManifest::default(),
    );
    assert_eq!(
        args,
        vec![
            std::ffi::OsString::from("--dylib"),
            std::ffi::OsString::from("target/debug/libapp.dylib"),
            std::ffi::OsString::from("--ws"),
            std::ffi::OsString::from("ws://127.0.0.1:8089"),
        ]
    );
}

#[test]
fn child_process_guard_drop_kills_and_reaps_running_child() {
    use std::io::Read as _;
    use std::process::Stdio;

    let mut cmd = if cfg!(windows) {
        let mut c = ProcessCommand::new("ping");
        c.args(["-n", "30", "127.0.0.1"]);
        c
    } else {
        let mut c = ProcessCommand::new("sleep");
        c.arg("30");
        c
    };
    let mut child = cmd
        .stdout(Stdio::piped())
        .stderr(Stdio::null())
        .spawn()
        .expect("spawn sleep child");
    let mut stdout = child.stdout.take().expect("piped stdout");
    let guard = ChildProcessGuard(Some(child));

    let t0 = Instant::now();
    drop(guard);

    let mut buf = Vec::new();
    stdout.read_to_end(&mut buf).expect("stdout pipe closes on child exit");
    assert!(
        t0.elapsed() < Duration::from_secs(5),
        "ChildProcessGuard drop must terminate child promptly (took {:?})",
        t0.elapsed()
    );
}

#[test]
fn deferred_skia_launch_waits_for_first_successful_rebuild() {
    let (tx, rx) = bounded::<()>(1);
    assert!(wait_for_skia_launch_ready(true, &rx).is_ok());

    let handle = std::thread::spawn(move || wait_for_skia_launch_ready(false, &rx));
    tx.try_send(()).expect("signal first successful rebuild");
    assert!(handle.join().expect("join waiter").is_ok());

    let (tx_drop, rx_drop) = bounded::<()>(1);
    drop(tx_drop);
    assert!(wait_for_skia_launch_ready(false, &rx_drop).is_err());
}

#[test]
fn watch_classifier_forces_tier2_rebuild_until_first_build_succeeds() {
    let dir = std::env::temp_dir().join(format!(
        "nv-dev-watch-guard-{}",
        std::process::id()
    ));
    let _ = std::fs::create_dir_all(&dir);
    let file = dir.join("sample.rs");
    std::fs::write(&file, "fn view() { let _ = \"hello\"; }\n").expect("write temp rs");

    let mut cache = hot_diff::WatchCache::new();
    let paths = vec![file.clone()];
    // Before the first build succeeds, even a save must force a Tier-2 rebuild (never NoOp/Tier1).
    let (patches, reason) = classify_watch_changes(false, &paths, &mut cache, 2);
    assert!(patches.is_empty());
    assert_eq!(reason.as_deref(), Some("awaiting first successful build"));

    // Once built and seeded, an unchanged file is classified as a no-op.
    cache.seed_dir(&dir);
    let (patches_after, reason_after) = classify_watch_changes(true, &paths, &mut cache, 3);
    assert!(patches_after.is_empty());
    assert!(reason_after.is_none());

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

#[test]
fn watch_classifier_forwards_one_message_per_changed_element_for_typed_edits() {
    let dir = std::env::temp_dir().join(format!("nv-dev-watch-typed-{}", std::process::id()));
    let _ = std::fs::create_dir_all(&dir);
    let file = dir.join("ui.rs");
    let base = "fn ui() -> impl View {\n    view! {\n        Column {\n            Node(test_id: \"a\", padding: 8.0)\n            Node(test_id: \"b\", opacity: 0.5)\n        }\n    }\n}\n";
    std::fs::write(&file, base).expect("write temp rs");
    let mut cache = hot_diff::WatchCache::new();
    cache.seed_dir(&dir);

    let edited = base.replace("padding: 8.0", "padding: 12.5").replace("0.5", "0.75");
    let rel = hot_diff::cache::workspace_relative_path(&file);
    let anchor = |path: &[u16]| nativeview_view_syntax::compute_anchor_key(&rel, 0, path).0;
    std::fs::write(&file, &edited).expect("rewrite temp rs");
    let (patches, reason) = classify_watch_changes(true, std::slice::from_ref(&file), &mut cache, 5);
    assert_eq!(reason, None);
    let [(path, messages)] = patches.as_slice() else {
        panic!("expected one file's messages: {patches:?}");
    };
    assert_eq!(path, &hot_diff::cache::canonicalize_preserving_missing(&file));
    let updates: Vec<_> = messages
        .iter()
        .map(|msg| match msg {
            HotPatchMsg::TemplatePatch {
                row_patch_words,
                template_key,
                ..
            } => {
                let view = nativeview_store::RowPatchView::from_words(row_patch_words)
                    .expect("valid binary RowPatch");
                (
                    *template_key,
                    view.get_prop(nativeview_tables::tables::Layout::PADDING_TOP),
                    view.get_prop(nativeview_tables::tables::Visual::OPACITY),
                )
            }
            other => panic!("unexpected {other:?}"),
        })
        .collect();
    assert_eq!(
        updates,
        vec![
            (
                anchor(&[0, 0]),
                Some(nativeview_store::Length::points(12.5)),
                None
            ),
            (anchor(&[0, 1]), None, Some(0.75)),
        ]
    );

    // A non-literal value in the next save forces Tier-2 and keeps the typed baseline.
    std::fs::write(&file, edited.replace("12.5", "gap")).expect("rewrite temp rs");
    let (patches, reason) = classify_watch_changes(true, std::slice::from_ref(&file), &mut cache, 6);
    assert!(patches.is_empty());
    assert!(reason.is_some_and(|r| r.contains("not a Tier-1 constant")));

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

#[test]
fn web_dev_redirect_wires_bare_urls_to_the_daemon_socket_and_respects_explicit_modes() {
    let r = |target, host| web_dev_redirect(target, host, 8089);
    assert_eq!(r("/", Some("127.0.0.1:8088")).as_deref(), Some("/?ws=ws://127.0.0.1:8089"));
    assert_eq!(
        r("/index.html?app=kitchen-sink", Some("192.168.1.20:8088")).as_deref(),
        Some("/index.html?app=kitchen-sink&ws=ws://192.168.1.20:8089"),
        "LAN clients get the host they used; other params survive"
    );
    assert_eq!(r("/", Some("[::1]:8088")).as_deref(), Some("/?ws=ws://[::1]:8089"));
    assert_eq!(r("/", Some("devbox")).as_deref(), Some("/?ws=ws://devbox:8089"));
    assert_eq!(r("/", None).as_deref(), Some("/?ws=ws://127.0.0.1:8089"));
    assert_eq!(r("/", Some("")).as_deref(), Some("/?ws=ws://127.0.0.1:8089"));
    assert_eq!(
        web_dev_redirect("/?app=studio", None, 9001).as_deref(),
        Some("/?app=studio&ws=ws://127.0.0.1:9001")
    );
    for target in [
        "/?ws=off",
        "/?dev",
        "/?dev=1",
        "/?pair=ws://x&token=t",
        "/?bundle=studio",
        "/?app=kitchen-sink&ws=ws://h:1",
    ] {
        assert_eq!(r(target, Some("h:8088")), None, "{target}");
    }
    for target in [
        "/pkg/dev/manifest.json",
        "/pkg/dev/0123456789abcdef/nativeview_web_shell.js",
        "/pkg/dev/0123456789abcdef/nativeview_web_shell_bg.wasm",
        "/e2e/run_e2e.mjs",
    ] {
        assert_eq!(r(target, Some("h:8088")), None, "{target}");
    }
    assert_eq!(r("/?wsx=1", None).as_deref(), Some("/?wsx=1&ws=ws://127.0.0.1:8089"));
}

fn synthetic_app(
    package_name: &str,
    lib_name: &str,
    manifest_dir: PathBuf,
    target_dir: PathBuf,
    has_web_feature: bool,
) -> cargo_env::AppContext {
    cargo_env::AppContext {
        manifest_path: manifest_dir.join("Cargo.toml"),
        manifest_dir: manifest_dir.clone(),
        workspace_root: manifest_dir,
        target_directory: target_dir,
        package_id: format!("{package_name}@0.1.0"),
        package_name: package_name.to_owned(),
        package_version: "0.1.0".to_owned(),
        lib_name: lib_name.to_owned(),
        has_web_feature,
        has_lockfile: false,
        host_modules: Vec::new(),
        path_deps: Vec::new(),
    }
}

#[test]
fn dev_web_topology_distinguishes_web_shell_standalone_and_unsupported_apps() {
    let sdk_root_path = cargo_env::find_workspace_root();
    let sdk_root = cargo_env::NvSdkRoot(sdk_root_path.clone());
    let target_dir = sdk_root_path.join("target");
    let default_manifest = NvManifest::default();

    // 1. Workspace hosts/web-shell apps keep the fast `web_shell.rs` path even though they also
    //    declare a `[features] web` feature.
    for (pkg, expected_features) in [
        ("nativeview-studio-workspace", Vec::<String>::new()),
        ("nativeview-example-kitchen-sink", Vec::<String>::new()),
        ("nativeview-example-issues-client", vec!["app-issues".to_owned()]),
    ] {
        let app = synthetic_app(
            pkg,
            &pkg.replace('-', "_"),
            sdk_root_path.join("examples/studio-workspace"),
            target_dir.clone(),
            true,
        );
        let topo = resolve_dev_web_topology(&app, Some(&sdk_root), &default_manifest, false, false, false, false)
            .expect("workspace web-shell app resolves");
        assert_eq!(
            topo,
            DevWebTopology::WorkspaceWebShell {
                web_shell_dir: sdk_root_path.join("hosts/web-shell"),
                web_out_dir: sdk_root_path.join("hosts/web-shell/pkg/dev"),
                extra_features: expected_features,
                app_assets_dir: app.manifest_dir.join("assets"),
            }
        );
        // `--no-web` and `--skia` default cleanly disable web builds.
        assert_eq!(
            resolve_dev_web_topology(&app, Some(&sdk_root), &default_manifest, true, true, false, false).unwrap(),
            DevWebTopology::Disabled
        );
        assert_eq!(
            resolve_dev_web_topology(&app, Some(&sdk_root), &default_manifest, false, false, true, false).unwrap(),
            DevWebTopology::Disabled
        );
    }

    // Fictional package name must NOT be mapped to `hosts/web-shell`.
    let fictional = synthetic_app(
        "nv-example-fullstack-issues",
        "nv_example_fullstack_issues",
        sdk_root_path.join("examples/fullstack-issues"),
        target_dir.clone(),
        false,
    );
    assert_eq!(
        resolve_dev_web_topology(&fictional, Some(&sdk_root), &default_manifest, false, false, false, false)
            .unwrap(),
        DevWebTopology::Disabled
    );

    // 2. Standalone `[features] web` app uses `build_web_app` and serves `<out_dir>/pwa/`, even with ZERO NV_SDK_ROOT.
    let mut custom_web_manifest = NvManifest::default();
    custom_web_manifest.web.index = "app.html".to_owned();
    let standalone = synthetic_app(
        "nativeview-example-camera-demo",
        "nativeview_camera_demo",
        sdk_root_path.join("packages/modules/camera/example"),
        target_dir.clone(),
        true,
    );
    let standalone_topo = resolve_dev_web_topology(
        &standalone,
        None,
        &custom_web_manifest,
        true,
        false,
        false,
        false,
    )
    .expect("standalone web app resolves without NV_SDK_ROOT");
    assert_eq!(
        standalone_topo,
        DevWebTopology::StandaloneApp {
            out_dir: target_dir.join("nv-apps/nativeview_camera_demo/web"),
            pwa_dir: target_dir.join("nv-apps/nativeview_camera_demo/web/pwa"),
            web_index: "app.html".to_owned(),
        }
    );

    // 3. Unsupported app (no `web` feature, not in `hosts/web-shell`):
    //    - implicit default skips web cleanly (never silently rebuilds `hosts/web-shell`)
    //    - explicit `--web` returns an actionable error.
    let no_web = synthetic_app(
        "nativeview-example-widgets-demo",
        "nativeview_widgets_demo",
        sdk_root_path.join("packages/modules/widgets/example"),
        target_dir,
        false,
    );
    assert_eq!(
        resolve_dev_web_topology(&no_web, Some(&sdk_root), &default_manifest, false, false, false, false)
            .unwrap(),
        DevWebTopology::Disabled
    );
    let err = resolve_dev_web_topology(&no_web, Some(&sdk_root), &default_manifest, true, false, false, false)
        .expect_err("explicit --web on non-web app must error");
    assert!(err.contains("nativeview-example-widgets-demo"), "got: {err}");
    assert!(err.contains("web"), "got: {err}");
}

#[test]
fn dev_skia_launch_plan_handles_plain_camera_tcc_and_app_scene_adaptive_manifests() {
    let root = cargo_env::find_workspace_root();
    let target_dir = root.join("target");
    let dylib = target_dir.join("debug/libdemo.dylib");
    let ws_url = "ws://127.0.0.1:8089";

    // 1. Plain app (default manifest): direct launch even on macOS.
    let plain_app = synthetic_app(
        "nativeview-studio-workspace",
        "nativeview_studio_workspace",
        root.join("examples/studio-workspace"),
        target_dir.clone(),
        true,
    );
    let plain_manifest = NvManifest::default();
    assert!(!plain_manifest.requires_macos_app_bundle());
    let plain_plan = plan_skia_dev_launch(&plain_app, &plain_manifest, &dylib, ws_url, true);
    assert_eq!(plain_plan.mode, SkiaLaunchMode::Direct);
    assert_eq!(
        plain_plan.args,
        vec![
            std::ffi::OsString::from("--dylib"),
            dylib.as_os_str().to_os_string(),
            std::ffi::OsString::from("--ws"),
            std::ffi::OsString::from(ws_url),
        ]
    );

    // 2. `packages/modules/camera/example`: TCC bundle (`io.github.nativeview.camera.demo.skia`) on macOS,
    //    explicit `--dylib` + `--ws` + `--width 920 --height 860`.
    let cam_dir = root.join("packages/modules/camera/example");
    let cam_manifest = NvManifest::load_for_dir(&cam_dir).expect("load camera nativeview.toml");
    assert!(cam_manifest.requires_macos_app_bundle());
    let cam_app = synthetic_app(
        "nativeview-example-camera-demo",
        "nativeview_camera_demo",
        cam_dir,
        target_dir.clone(),
        true,
    );
    let cam_macos = plan_skia_dev_launch(&cam_app, &cam_manifest, &dylib, ws_url, true);
    assert_eq!(
        cam_macos.mode,
        SkiaLaunchMode::MacosAppBundle {
            out_dir: target_dir.join("nv-dev/bundles/nativeview_camera_demo"),
            bundle_id: "io.github.nativeview.camera.demo.skia".to_owned(),
        }
    );
    assert_eq!(
        cam_macos.args,
        vec![
            std::ffi::OsString::from("--dylib"),
            dylib.as_os_str().to_os_string(),
            std::ffi::OsString::from("--ws"),
            std::ffi::OsString::from(ws_url),
            std::ffi::OsString::from("--width"),
            std::ffi::OsString::from("920"),
            std::ffi::OsString::from("--height"),
            std::ffi::OsString::from("860"),
        ]
    );
    let cam_linux = plan_skia_dev_launch(&cam_app, &cam_manifest, &dylib, ws_url, false);
    assert_eq!(cam_linux.mode, SkiaLaunchMode::Direct);
    assert_eq!(cam_linux.args, cam_macos.args);

    // 3. `packages/modules/app-scene/example`: adaptive presence -> macOS `.app` bundle + `--presence adaptive`.
    let scene_dir = root.join("packages/modules/app-scene/example");
    let scene_manifest = NvManifest::load_for_dir(&scene_dir).expect("load app-scene nativeview.toml");
    assert!(scene_manifest.requires_macos_app_bundle());
    let scene_app = synthetic_app(
        "nativeview-example-app-scene-demo",
        "nativeview_app_scene_demo",
        scene_dir,
        target_dir.clone(),
        true,
    );
    let scene_macos = plan_skia_dev_launch(&scene_app, &scene_manifest, &dylib, ws_url, true);
    assert_eq!(
        scene_macos.mode,
        SkiaLaunchMode::MacosAppBundle {
            out_dir: target_dir.join("nv-dev/bundles/nativeview_app_scene_demo"),
            bundle_id: "io.github.nativeview.appscene.demo.skia".to_owned(),
        }
    );
    assert_eq!(
        scene_macos.args,
        vec![
            std::ffi::OsString::from("--dylib"),
            dylib.as_os_str().to_os_string(),
            std::ffi::OsString::from("--ws"),
            std::ffi::OsString::from(ws_url),
            std::ffi::OsString::from("--presence"),
            std::ffi::OsString::from("adaptive"),
        ]
    );
    let scene_linux = plan_skia_dev_launch(&scene_app, &scene_manifest, &dylib, ws_url, false);
    assert_eq!(scene_linux.mode, SkiaLaunchMode::Direct);
    assert_eq!(scene_linux.args, scene_macos.args);
}

#[test]
fn resolve_watch_roots_and_session_root_cover_standalone_camera_example() {
    let root = cargo_env::find_workspace_root();
    let cam_dir = root.join("packages/modules/camera/example");
    let selector = AppSelector {
        app_path: Some(cam_dir.clone()),
        package: None,
    };
    let (app, sdk_root) = cargo_env::resolve_app_and_sdk(
        &selector,
        Some(&root),
        &root,
        cargo_env::host_target_triple(),
    )
    .expect("resolve standalone camera example");
    assert_eq!(app.package_name, "nativeview-example-camera-demo");
    assert_eq!(app.lib_name, "nativeview_camera_demo");
    assert!(app.has_web_feature);

    let roots = resolve_watch_roots(&[], &app, &[]);
    let canon_cam_src = std::fs::canonicalize(cam_dir.join("src")).unwrap();
    let canon_mod_src = std::fs::canonicalize(root.join("packages/modules/camera/src")).unwrap();
    let canon_ui_src = std::fs::canonicalize(root.join("packages/framework/ui/src")).unwrap();
    assert_eq!(roots[0], canon_cam_src, "primary watch root must be app's src/");
    assert!(
        roots.contains(&canon_mod_src),
        "watch roots must include direct path dep packages/modules/camera/src: {roots:?}"
    );
    assert!(
        roots.contains(&canon_ui_src),
        "watch roots must include path dep packages/framework/ui/src: {roots:?}"
    );

    // Session root for in-SDK standalone examples matches fast_workspace_and_target_dir_from from
    // BOTH the repo root and inside the example directory.
    let canon_sdk = std::fs::canonicalize(sdk_root.path()).unwrap();
    let session_root = std::fs::canonicalize(app.dev_session_root(Some(&sdk_root))).unwrap();
    assert_eq!(session_root, canon_sdk);
    let (fast_from_example, _) =
        super::session::fast_workspace_and_target_dir_from(&cam_dir)
            .expect("fast workspace lookup from standalone example dir");
    assert_eq!(std::fs::canonicalize(fast_from_example).unwrap(), canon_sdk);
}

#[test]
fn watch_classifier_dispatches_view_macro_files_with_anchor_key_and_empty_node_path() {
    let dir = std::env::temp_dir().join(format!("nv-dev-watch-view-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&dir);
    let src = dir.join("src");
    std::fs::create_dir_all(&src).expect("create temp src");
    std::fs::write(
        dir.join("Cargo.toml"),
        "[package]\nname = \"view-demo\"\nversion = \"0.1.0\"\nedition = \"2024\"\n",
    )
    .expect("write Cargo.toml");
    let file = src.join("ui.rs");
    let base = "fn ui() -> impl View {\n    view! { Column(padding: 8.0) { \"Hello\" } }\n}\n";
    std::fs::write(&file, base).expect("write ui.rs");

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

    let edited = base.replace("padding: 8.0", "padding: 16.0").replace("\"Hello\"", "\"World\"");
    std::fs::write(&file, &edited).expect("rewrite ui.rs");
    let (patches, reason) = classify_watch_changes(true, std::slice::from_ref(&file), &mut cache, 9);
    assert_eq!(reason, None);
    assert_eq!(patches.len(), 1);
    let (_, messages) = &patches[0];
    assert_eq!(messages.len(), 2);
    for msg in messages {
        let HotPatchMsg::TemplatePatch { node_path, .. } = msg else {
            panic!("expected TemplatePatch, got {msg:?}");
        };
        assert!(node_path.is_empty(), "view! patches must use empty node_path");
    }

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