proa-cli 0.1.1

CLI for scaffolding, inspecting, formatting, and validating Proa web projects
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
// Copyright Proa Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use std::{
    collections::BTreeMap,
    fs,
    path::{Component, Path, PathBuf},
};

use anyhow::{Context, Result};
use reqwest::Url;
use serde::{Deserialize, Serialize};

pub const CONFIG_FILE: &str = "proa.config.json";
pub const LOCK_FILE: &str = "proa.lock.json";
pub const CONFIG_SCHEMA_URL: &str = "https://proa.so/schema/proa.config.json";
pub const LOCK_SCHEMA_URL: &str = "https://proa.so/schema/proa.lock.json";

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct ProjectConfig {
    #[serde(rename = "$schema", skip_serializing_if = "Option::is_none")]
    pub schema: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub application: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub database: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ui: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub representations: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub styling: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub deploy: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "BTreeMap::is_empty")]
    pub tasks: BTreeMap<String, serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub test: Option<serde_json::Value>,
    pub paths: ProjectPaths,
    pub registries: BTreeMap<String, String>,
    pub dev: DevConfig,
    pub build: BuildConfig,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct ProjectPaths {
    pub components: PathBuf,
    pub assets: PathBuf,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pages: Option<PathBuf>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub endpoints: Option<PathBuf>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub layouts: Option<PathBuf>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub models: Option<PathBuf>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub public: Option<PathBuf>,
    #[serde(rename = "runtimeData", skip_serializing_if = "Option::is_none")]
    pub runtime_data: Option<PathBuf>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct DevConfig {
    pub command: Vec<String>,
    pub host: String,
    pub port: u16,
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub before: Vec<String>,
    pub watch: Vec<PathBuf>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct BuildConfig {
    pub command: Vec<String>,
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub before: Vec<String>,
    /// `None` when the key is absent, so a Tailwind asset can be inferred.
    /// `Some(vec![])` is an explicit "build no assets" and is left alone --
    /// with a plain `Vec` the two were indistinguishable and an empty array
    /// silently grew a Tailwind step back.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub assets: Option<Vec<AssetConfig>>,
}

impl BuildConfig {
    pub fn assets(&self) -> &[AssetConfig] {
        self.assets.as_deref().unwrap_or_default()
    }
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct AssetConfig {
    pub kind: String,
    pub command: Vec<String>,
    pub input: PathBuf,
    pub output: PathBuf,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub config: Option<PathBuf>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct ComponentLockFile {
    #[serde(rename = "$schema", skip_serializing_if = "Option::is_none")]
    pub schema: Option<String>,
    pub components: BTreeMap<String, InstalledComponent>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default, rename_all = "camelCase")]
pub struct InstalledComponent {
    pub version: String,
    pub registry: String,
    pub mode: String,
    pub source_hash: String,
    pub local_hash_at_install: String,
    pub installed_files: Vec<PathBuf>,
    pub dependencies: Vec<String>,
    pub rust_modules: Vec<InstalledRustModules>,
    pub cargo_dependencies: Vec<InstalledCargoDependency>,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct InstalledRustModules {
    pub target: PathBuf,
    pub modules: Vec<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct InstalledCargoDependency {
    pub name: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub path: Option<PathBuf>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub version: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub git: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub registry: Option<String>,
    pub features: Vec<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub default_features: Option<bool>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ConfigInitReport {
    pub root: PathBuf,
    pub config_path: PathBuf,
    pub lock_path: PathBuf,
    pub wrote_config: bool,
    pub wrote_lock: bool,
}

impl Default for ProjectConfig {
    fn default() -> Self {
        Self {
            schema: Some(CONFIG_SCHEMA_URL.into()),
            application: None,
            database: None,
            ui: None,
            representations: None,
            styling: None,
            deploy: None,
            content: None,
            tasks: BTreeMap::new(),
            test: None,
            paths: ProjectPaths::default(),
            registries: default_registries(),
            dev: DevConfig::default(),
            build: BuildConfig::default(),
        }
    }
}

impl Default for ProjectPaths {
    fn default() -> Self {
        Self {
            components: PathBuf::from("src/components"),
            // Must sit under the directory the generated server actually serves.
            // `static/` is the URL prefix, not the folder: the axum scaffold mounts
            // `public/` at `/static`, so assets written to `static/proa` were never
            // reachable and every documented `/static/proa/...` link 404'd.
            assets: PathBuf::from("public/proa"),
            pages: None,
            endpoints: None,
            layouts: None,
            models: None,
            public: None,
            runtime_data: None,
        }
    }
}

impl Default for DevConfig {
    fn default() -> Self {
        Self {
            command: vec!["cargo".into(), "run".into()],
            host: "127.0.0.1".into(),
            port: 3000,
            before: Vec::new(),
            watch: default_watch_paths(),
        }
    }
}

impl Default for BuildConfig {
    fn default() -> Self {
        Self {
            command: vec!["cargo".into(), "build".into(), "--release".into()],
            before: Vec::new(),
            assets: None,
        }
    }
}

impl Default for AssetConfig {
    fn default() -> Self {
        Self {
            kind: "command".into(),
            command: Vec::new(),
            input: PathBuf::new(),
            output: PathBuf::new(),
            config: None,
        }
    }
}

impl Default for ComponentLockFile {
    fn default() -> Self {
        Self {
            schema: Some(LOCK_SCHEMA_URL.into()),
            components: BTreeMap::new(),
        }
    }
}

impl Default for InstalledComponent {
    fn default() -> Self {
        Self {
            version: String::new(),
            registry: String::new(),
            mode: "source".into(),
            source_hash: String::new(),
            local_hash_at_install: String::new(),
            installed_files: Vec::new(),
            dependencies: Vec::new(),
            rust_modules: Vec::new(),
            cargo_dependencies: Vec::new(),
        }
    }
}

pub fn load_project_config(root: &Path) -> Result<ProjectConfig> {
    let (config, unknown_keys) = load_project_config_with_unknown_keys(root)?;
    // A misspelled key silently falling back to its default is the most
    // confusing config failure mode; always say something.
    for key in &unknown_keys {
        eprintln!("warning: {CONFIG_FILE}: unknown key `{key}` is ignored");
    }
    Ok(config)
}

pub fn load_project_config_with_unknown_keys(root: &Path) -> Result<(ProjectConfig, Vec<String>)> {
    let path = root.join(CONFIG_FILE);
    if path.exists() {
        let source =
            fs::read_to_string(&path).with_context(|| format!("read {}", path.display()))?;
        let mut unknown_keys = Vec::new();
        let mut deserializer = serde_json::Deserializer::from_str(&source);
        let mut config: ProjectConfig = serde_ignored::deserialize(&mut deserializer, |ignored| {
            unknown_keys.push(ignored.to_string());
        })
        .with_context(|| format!("parse {}", path.display()))?;
        fill_inferred_defaults(root, &mut config);
        Ok((config, unknown_keys))
    } else {
        Ok((inferred_project_config(root), Vec::new()))
    }
}

#[derive(Debug, Serialize)]
pub struct ConfigValidation {
    pub config_path: Option<PathBuf>,
    pub warnings: Vec<String>,
    pub errors: Vec<String>,
}

pub fn validate_project_config(root: &Path) -> Result<ConfigValidation> {
    let path = root.join(CONFIG_FILE);
    let mut validation = ConfigValidation {
        config_path: path.exists().then_some(path),
        warnings: Vec::new(),
        errors: Vec::new(),
    };

    let (config, unknown_keys) = load_project_config_with_unknown_keys(root)?;
    if validation.config_path.is_none() {
        validation
            .warnings
            .push(format!("{CONFIG_FILE} not found; using inferred defaults"));
    }
    for key in unknown_keys {
        validation
            .warnings
            .push(format!("unknown key `{key}` is ignored"));
    }

    if config.dev.command.is_empty() {
        validation
            .errors
            .push("dev.command is empty; `proa dev` cannot start a server".to_string());
    }
    if config.build.command.is_empty() {
        validation
            .errors
            .push("build.command is empty; `proa build` has nothing to run".to_string());
    }
    if config.dev.watch.is_empty() {
        validation
            .warnings
            .push("dev.watch is empty; `proa dev` will never restart on changes".to_string());
    }

    for (name, path) in [
        ("paths.components", &config.paths.components),
        ("paths.assets", &config.paths.assets),
    ] {
        if let Err(error) = validate_project_relative_path(path) {
            validation.errors.push(format!("{name}: {error}"));
        }
    }
    if config.paths.components == config.paths.assets {
        validation
            .errors
            .push("paths.components and paths.assets must be different".to_string());
    }

    if !config.registries.contains_key("@proa") {
        validation
            .errors
            .push("registries.@proa is required".to_string());
    }
    for (registry, template) in &config.registries {
        if let Err(error) = validate_registry_template(template) {
            validation
                .errors
                .push(format!("registries.{registry}: {error}"));
        }
    }

    for (index, asset) in config.build.assets().iter().enumerate() {
        match asset.kind.as_str() {
            "tailwind" => {
                if !root.join(&asset.input).exists() {
                    validation.warnings.push(format!(
                        "build.assets[{index}]: tailwind input `{}` does not exist; the asset build will be skipped",
                        asset.input.display()
                    ));
                }
                if asset.output.as_os_str().is_empty() {
                    validation.errors.push(format!(
                        "build.assets[{index}]: tailwind asset has no output path"
                    ));
                }
            }
            "command" => {
                if asset.command.is_empty() {
                    validation.warnings.push(format!(
                        "build.assets[{index}]: command asset with an empty command does nothing"
                    ));
                }
            }
            other => validation.errors.push(format!(
                "build.assets[{index}]: unknown kind `{other}` (expected `tailwind` or `command`)"
            )),
        }
    }

    Ok(validation)
}

fn validate_project_relative_path(path: &Path) -> std::result::Result<(), String> {
    if path.as_os_str().is_empty() || path.is_absolute() {
        return Err(format!(
            "`{}` must be a non-empty project-relative path",
            path.display()
        ));
    }
    if path
        .components()
        .any(|component| !matches!(component, Component::Normal(_)))
    {
        return Err(format!(
            "`{}` contains an unsafe path component",
            path.display()
        ));
    }
    Ok(())
}

fn validate_registry_template(template: &str) -> std::result::Result<(), String> {
    if template.matches("{name}").count() != 1 {
        return Err(format!(
            "`{template}` must contain exactly one `{{name}}` placeholder"
        ));
    }
    let rendered = template.replace("{name}", "button");
    if rendered.starts_with("https://") || rendered.starts_with("http://") {
        let url = Url::parse(&rendered)
            .map_err(|error| format!("`{template}` is not a valid registry URL: {error}"))?;
        if url.scheme() == "http"
            && !matches!(url.host_str(), Some("localhost" | "127.0.0.1" | "::1"))
        {
            return Err("HTTP is only allowed for localhost registries; use HTTPS".to_string());
        }
        return Ok(());
    }
    if rendered.starts_with("file://") {
        let url = Url::parse(&rendered)
            .map_err(|error| format!("`{template}` is not a valid file URL: {error}"))?;
        url.to_file_path()
            .map_err(|_| format!("`{template}` is not a valid file URL"))?;
        return Ok(());
    }
    if rendered.contains("://") {
        return Err(format!("`{template}` uses an unsupported URL scheme"));
    }
    if rendered.trim().is_empty() {
        return Err("registry path cannot be empty".to_string());
    }
    Ok(())
}

pub fn load_component_lock(root: &Path) -> Result<ComponentLockFile> {
    let path = root.join(LOCK_FILE);
    if path.exists() {
        let source =
            fs::read_to_string(&path).with_context(|| format!("read {}", path.display()))?;
        let mut lock: ComponentLockFile =
            serde_json::from_str(&source).with_context(|| format!("parse {}", path.display()))?;
        if lock.schema.is_none() {
            lock.schema = Some(LOCK_SCHEMA_URL.into());
        }
        Ok(lock)
    } else {
        Ok(ComponentLockFile::default())
    }
}

pub fn generated_project_config(tailwind: bool) -> Result<String> {
    let mut config = ProjectConfig::default();
    // Always write the key, even empty. A generated `--no-tailwind` project
    // states "no asset builds" outright, so dropping a `styles/input.css` in
    // later cannot silently reintroduce a Tailwind step nobody configured.
    config.build.assets = Some(if tailwind {
        vec![tailwind_asset()]
    } else {
        Vec::new()
    });
    Ok(serde_json::to_string_pretty(&config)? + "\n")
}

pub fn generated_component_lock() -> Result<String> {
    Ok(serde_json::to_string_pretty(&ComponentLockFile::default())? + "\n")
}

pub fn init_project_files(root: &Path, force: bool) -> Result<ConfigInitReport> {
    fs::create_dir_all(root).with_context(|| format!("create {}", root.display()))?;

    let config_path = root.join(CONFIG_FILE);
    let lock_path = root.join(LOCK_FILE);
    let mut wrote_config = false;
    let mut wrote_lock = false;

    if force || !config_path.exists() {
        fs::write(&config_path, generated_project_config(false)?)
            .with_context(|| format!("write {}", config_path.display()))?;
        wrote_config = true;
    }

    if force || !lock_path.exists() {
        fs::write(&lock_path, generated_component_lock()?)
            .with_context(|| format!("write {}", lock_path.display()))?;
        wrote_lock = true;
    }

    Ok(ConfigInitReport {
        root: root.to_path_buf(),
        config_path,
        lock_path,
        wrote_config,
        wrote_lock,
    })
}

fn inferred_project_config(root: &Path) -> ProjectConfig {
    let mut config = ProjectConfig::default();
    fill_inferred_defaults(root, &mut config);
    config
}

fn fill_inferred_defaults(root: &Path, config: &mut ProjectConfig) {
    if config.schema.is_none() {
        config.schema = Some(CONFIG_SCHEMA_URL.into());
    }
    if config.paths.components.as_os_str().is_empty() {
        config.paths.components = ProjectPaths::default().components;
    }
    if config.paths.assets.as_os_str().is_empty() {
        config.paths.assets = ProjectPaths::default().assets;
    }
    if config.registries.is_empty() {
        config.registries = default_registries();
    }
    if config.dev.command.is_empty() {
        config.dev.command = DevConfig::default().command;
    }
    if config.dev.host.is_empty() {
        config.dev.host = DevConfig::default().host;
    }
    if config.dev.port == 0 {
        config.dev.port = DevConfig::default().port;
    }
    if config.dev.watch.is_empty() {
        config.dev.watch = default_watch_paths();
    }
    if config.build.command.is_empty() {
        config.build.command = BuildConfig::default().command;
    }
    if config.build.assets.is_none() && root.join("styles/input.css").exists() {
        config.build.assets = Some(vec![tailwind_asset()]);
    }
}

fn default_registries() -> BTreeMap<String, String> {
    [
        ("@proa", "https://ui.proa.so/r/{name}.json"),
        ("@proa-pro", "https://console.proa.so/r/{name}.json"),
    ]
    .into_iter()
    .map(|(key, value)| (key.to_string(), value.to_string()))
    .collect()
}

// Cargo.lock is intentionally not watched: `cargo run` can rewrite it during
// the build the watcher just triggered, which restarts the dev loop forever.
fn default_watch_paths() -> Vec<PathBuf> {
    ["src", "styles", "Cargo.toml", "build.rs", CONFIG_FILE]
        .into_iter()
        .map(PathBuf::from)
        .collect()
}

fn tailwind_asset() -> AssetConfig {
    AssetConfig {
        kind: "tailwind".into(),
        command: Vec::new(),
        input: PathBuf::from("styles/input.css"),
        output: PathBuf::from("public/styles.css"),
        // Tailwind v4 discovers sources from the CSS entrypoint's `@source`
        // directives. The optional config field remains supported for older
        // and custom projects, but generated v4 sites do not need `-c`.
        config: None,
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn validate_reports_unknown_keys_and_bad_asset_kinds() {
        let temp = tempfile::tempdir().unwrap();
        fs::write(
            temp.path().join(CONFIG_FILE),
            r#"{
                "dev": { "comand": ["cargo", "run"] },
                "build": { "assets": [{ "kind": "webpack", "input": "a", "output": "b" }] }
            }"#,
        )
        .unwrap();

        let validation = validate_project_config(temp.path()).unwrap();
        assert!(
            validation
                .warnings
                .iter()
                .any(|warning| warning.contains("dev.comand")),
            "{validation:?}"
        );
        assert!(
            validation
                .errors
                .iter()
                .any(|error| error.contains("unknown kind `webpack`")),
            "{validation:?}"
        );
    }

    #[test]
    fn validate_passes_defaults_and_flags_missing_config() {
        let temp = tempfile::tempdir().unwrap();
        let validation = validate_project_config(temp.path()).unwrap();
        assert!(validation.errors.is_empty(), "{validation:?}");
        assert!(
            validation
                .warnings
                .iter()
                .any(|warning| warning.contains("not found")),
            "{validation:?}"
        );
    }

    #[test]
    fn validate_rejects_unsafe_paths_and_broken_registry_templates() {
        let temp = tempfile::tempdir().unwrap();
        fs::write(
            temp.path().join(CONFIG_FILE),
            r#"{
                "paths": { "components": "../outside", "assets": "/tmp/assets" },
                "registries": {
                    "@proa": "https://ui.proa.so/r/component.json",
                    "@proa-pro": "http://console.proa.so/r/{name}.json"
                }
            }"#,
        )
        .unwrap();

        let validation = validate_project_config(temp.path()).unwrap();
        assert!(
            validation
                .errors
                .iter()
                .any(|error| error.contains("paths.components")),
            "{validation:?}"
        );
        assert!(
            validation
                .errors
                .iter()
                .any(|error| error.contains("paths.assets")),
            "{validation:?}"
        );
        assert!(
            validation
                .errors
                .iter()
                .any(|error| error.contains("exactly one `{name}`")),
            "{validation:?}"
        );
        assert!(
            validation
                .errors
                .iter()
                .any(|error| error.contains("use HTTPS")),
            "{validation:?}"
        );
    }

    #[test]
    fn load_reports_unknown_keys() {
        let temp = tempfile::tempdir().unwrap();
        fs::write(temp.path().join(CONFIG_FILE), r#"{ "prot": 3001 }"#).unwrap();

        let (_, unknown) = load_project_config_with_unknown_keys(temp.path()).unwrap();
        assert_eq!(unknown, ["prot"]);
    }

    #[test]
    fn generated_config_includes_tailwind_asset_when_requested() {
        let json = generated_project_config(true).unwrap();

        assert!(json.contains("\"$schema\": \"https://proa.so/schema/proa.config.json\""));
        assert!(json.contains("\"components\": \"src/components\""));
        assert!(json.contains("\"@proa\""));
        assert!(json.contains("https://console.proa.so/r/{name}.json"));
        assert!(json.contains("\"command\": ["));
        assert!(json.contains("\"cargo\""));
        assert!(json.contains("\"kind\": \"tailwind\""));
        assert!(json.contains("\"styles/input.css\""));
        assert!(!json.contains("\"config\""));
        assert!(!json.contains("frontend"));
    }

    #[test]
    fn generated_config_can_omit_assets() {
        let json = generated_project_config(false).unwrap();

        assert!(json.contains("\"assets\": []"));
        assert!(!json.contains("\"kind\": \"tailwind\""));
    }

    #[test]
    fn generated_lock_starts_empty() {
        let json = generated_component_lock().unwrap();

        assert!(json.contains("\"$schema\": \"https://proa.so/schema/proa.lock.json\""));
        assert!(json.contains("\"components\": {}"));
    }

    #[test]
    fn init_project_files_writes_config_and_lock() {
        let temp = tempfile::tempdir().unwrap();
        let report = init_project_files(temp.path(), false).unwrap();

        assert!(report.wrote_config);
        assert!(report.wrote_lock);
        assert!(temp.path().join(CONFIG_FILE).exists());
        assert!(temp.path().join(LOCK_FILE).exists());

        let second = init_project_files(temp.path(), false).unwrap();
        assert!(!second.wrote_config);
        assert!(!second.wrote_lock);
    }
}