wash-cli 0.39.0

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

use common::{init, init_path, init_provider, init_workspace, load_fixture};

use anyhow::{Context, Result};
use tokio::{fs::File, process::Command};
use wash_lib::build::PACKAGE_LOCK_FILE_NAME;

#[tokio::test]
#[cfg_attr(not(can_reach_ghcr_io), ignore = "ghcr.io is not reachable")]
async fn integration_build_rust_component_unsigned() -> Result<()> {
    let test_setup = init(
        /* component_name= */ "hello-unsigned",
        /* template_name= */ "hello-world-rust",
    )
    .await?;
    let project_dir = test_setup.project_dir.clone();

    let status = test_setup
        .base_command()
        .args(["build", "--build-only"])
        .status()
        .await
        .context("Failed to build project")?;

    assert!(status.success());
    let unsigned_file = project_dir.join("build/http_hello_world.wasm");
    assert!(
        tokio::fs::try_exists(unsigned_file).await.unwrap(),
        "unsigned file not found!"
    );
    let signed_file = project_dir.join("build/http_hello_world_s.wasm");
    assert!(
        !tokio::fs::try_exists(signed_file).await.unwrap(),
        "signed file should not exist when using --build-only!"
    );
    Ok(())
}

#[tokio::test]
#[cfg_attr(not(can_reach_ghcr_io), ignore = "ghcr.io is not reachable")]
async fn integration_build_rust_component_signed() -> Result<()> {
    // We test a dep from git above, so this tests with a local path so we can test local changes
    let test_setup = init_path(
        /* component_name= */ "hello",
        /* template_name= */ "crates/wash-cli/tests/fixtures/dog-fetcher",
    )
    .await?;
    let project_dir = test_setup.project_dir.clone();

    let status = test_setup
        .base_command()
        .args(["build"])
        .kill_on_drop(true)
        .status()
        .await
        .context("Failed to build project")?;

    assert!(status.success());
    let unsigned_file = project_dir.join("build/dog_fetcher.wasm");
    assert!(
        tokio::fs::try_exists(unsigned_file).await.unwrap(),
        "unsigned file not found!"
    );
    let signed_file = project_dir.join("build/dog_fetcher_s.wasm");
    assert!(
        tokio::fs::try_exists(signed_file).await.unwrap(),
        "signed file not found!"
    );
    let lock_file = project_dir.join(PACKAGE_LOCK_FILE_NAME);
    assert!(
        tokio::fs::try_exists(lock_file).await.unwrap(),
        "lock file not found!"
    );
    Ok(())
}

#[tokio::test]
#[cfg_attr(not(can_reach_ghcr_io), ignore = "ghcr.io is not reachable")]
async fn integration_build_uses_wkg_lock() -> Result<()> {
    let test_setup = init_path(
        /* component_name= */ "hello",
        /* template_name= */ "examples/rust/components/dog-fetcher",
    )
    .await?;
    let project_dir = test_setup.project_dir.clone();

    // Move the wasmcloud.lock to be wkg.lock
    tokio::fs::rename(
        project_dir.join("wasmcloud.lock"),
        project_dir.join("wkg.lock"),
    )
    .await
    .unwrap();

    let status = test_setup
        .base_command()
        .args(["build"])
        .kill_on_drop(true)
        .status()
        .await
        .context("Failed to build project")?;

    assert!(status.success());
    let unsigned_file = project_dir.join("build/dog_fetcher.wasm");
    assert!(
        tokio::fs::try_exists(unsigned_file).await.unwrap(),
        "unsigned file not found!"
    );
    let signed_file = project_dir.join("build/dog_fetcher_s.wasm");
    assert!(
        tokio::fs::try_exists(signed_file).await.unwrap(),
        "signed file not found!"
    );
    let lock_file = project_dir.join(wasm_pkg_core::lock::LOCK_FILE_NAME);
    assert!(
        tokio::fs::try_exists(lock_file).await.unwrap(),
        "lock file not found!"
    );
    // Make sure wasmcloud.lock is not present
    assert!(
        !tokio::fs::try_exists(project_dir.join("wasmcloud.lock"))
            .await
            .unwrap(),
        "wasmcloud.lock should not exist!"
    );
    Ok(())
}

#[ignore]
#[tokio::test]
// #[cfg_attr(not(can_reach_ghcr_io), ignore = "ghcr.io is not reachable")]
// TODO: This test should be re-enabled after the transitional period for dependencies manipulation
// (wit-deps -> wkg)
async fn integration_build_rust_component_with_existing_deps_signed() -> Result<()> {
    let test_setup = init_path(
        /* component_name= */ "hello",
        /* template_name= */
        "crates/wash-cli/tests/fixtures/old-examples/http-hello-world-rust",
    )
    .await?;
    let project_dir = test_setup.project_dir.clone();

    let status = test_setup
        .base_command()
        .args(["build"])
        .kill_on_drop(true)
        .status()
        .await
        .context("Failed to build project")?;

    assert!(status.success());
    let unsigned_file = project_dir.join("build/http_hello_world.wasm");
    assert!(
        tokio::fs::try_exists(unsigned_file).await.unwrap(),
        "unsigned file not found!"
    );
    let signed_file = project_dir.join("build/http_hello_world_s.wasm");
    assert!(
        tokio::fs::try_exists(signed_file).await.unwrap(),
        "signed file not found!"
    );
    let lock_file = project_dir.join(PACKAGE_LOCK_FILE_NAME);
    assert!(
        tokio::fs::try_exists(lock_file).await.unwrap(),
        "lock file not found!"
    );
    Ok(())
}

#[tokio::test]
#[cfg_attr(not(can_reach_ghcr_io), ignore = "ghcr.io is not reachable")]
async fn integration_build_with_wasmcloud_toml_overrides() -> Result<()> {
    // We test a dep from git above, so this tests with a local path so we can test local changes
    let test_setup = load_fixture("integrated-wkg").await?;
    let project_dir = test_setup.project_dir.clone();

    let status = test_setup
        .base_command()
        .args(["build"])
        .kill_on_drop(true)
        .status()
        .await
        .context("Failed to build project")?;

    assert!(status.success());
    let unsigned_file = project_dir.join("build/ponger_config_component.wasm");
    assert!(
        tokio::fs::try_exists(unsigned_file).await.unwrap(),
        "unsigned file not found!"
    );
    let signed_file = project_dir.join("build/ponger_config_component_s.wasm");
    assert!(
        tokio::fs::try_exists(signed_file).await.unwrap(),
        "signed file not found!"
    );
    Ok(())
}

#[tokio::test]
#[cfg_attr(not(can_reach_ghcr_io), ignore = "ghcr.io is not reachable")]
async fn integration_build_with_wkg_toml_overrides() -> Result<()> {
    // We test a dep from git above, so this tests with a local path so we can test local changes
    let test_setup = load_fixture("separate-wkg").await?;
    let project_dir = test_setup.project_dir.clone();

    let status = test_setup
        .base_command()
        .args(["build"])
        .kill_on_drop(true)
        .status()
        .await
        .context("Failed to build project")?;

    assert!(status.success());
    let unsigned_file = project_dir.join("build/ponger_config_component.wasm");
    assert!(
        tokio::fs::try_exists(unsigned_file).await.unwrap(),
        "unsigned file not found!"
    );
    let signed_file = project_dir.join("build/ponger_config_component_s.wasm");
    assert!(
        tokio::fs::try_exists(signed_file).await.unwrap(),
        "signed file not found!"
    );
    Ok(())
}

#[tokio::test]
#[cfg_attr(not(can_reach_ghcr_io), ignore = "ghcr.io is not reachable")]
async fn integration_build_with_logging_interface() -> Result<()> {
    // We test a dep from git above, so this tests with a local path so we can test local changes
    let test_setup = load_fixture("unversioned-logging").await?;
    let project_dir = test_setup.project_dir.clone();

    let status = test_setup
        .base_command()
        .args(["build"])
        .kill_on_drop(true)
        .status()
        .await
        .context("Failed to build project")?;

    assert!(status.success());
    let unsigned_file = project_dir.join("build/blobby.wasm");
    assert!(
        tokio::fs::try_exists(unsigned_file).await.unwrap(),
        "unsigned file not found!"
    );
    let signed_file = project_dir.join("build/blobby_s.wasm");
    assert!(
        tokio::fs::try_exists(signed_file).await.unwrap(),
        "signed file not found!"
    );
    let lock_file = project_dir.join(PACKAGE_LOCK_FILE_NAME);
    assert!(
        tokio::fs::try_exists(lock_file).await.unwrap(),
        "lock file not found!"
    );
    Ok(())
}

#[tokio::test]
async fn integration_build_rust_component_with_no_fetch() -> Result<()> {
    let test_setup = init_path(
        /* component_name= */ "hello",
        /* template_name= */
        "crates/wash-cli/tests/fixtures/old-examples/http-hello-world-rust",
    )
    .await?;
    let project_dir = test_setup.project_dir.clone();

    let status = test_setup
        .base_command()
        .args(["build", "--skip-fetch"])
        .kill_on_drop(true)
        .status()
        .await
        .context("Failed to build project")?;

    assert!(status.success());
    let unsigned_file = project_dir.join("build/http_hello_world.wasm");
    assert!(
        tokio::fs::try_exists(unsigned_file).await.unwrap(),
        "unsigned file not found!"
    );
    let signed_file = project_dir.join("build/http_hello_world_s.wasm");
    assert!(
        tokio::fs::try_exists(signed_file).await.unwrap(),
        "signed file not found!"
    );
    let lock_file = project_dir.join(PACKAGE_LOCK_FILE_NAME);
    assert!(
        !tokio::fs::try_exists(lock_file).await.unwrap(),
        "lock file should not have been generated!"
    );
    Ok(())
}

#[tokio::test]
#[cfg_attr(not(can_reach_ghcr_io), ignore = "ghcr.io is not reachable")]
async fn integration_build_rust_component_signed_with_signing_keys_directory_configuration(
) -> Result<()> {
    let test_setup = init(
        /* component_name= */ "hello",
        /* template_name= */ "hello-world-rust",
    )
    .await?;
    let project_dir = test_setup.project_dir.clone();

    // base case: no keys directory configured
    let mut expected_default_key_dir = etcetera::home_dir()?;
    expected_default_key_dir.push(".wash/keys");

    let cmd = test_setup
        .base_command()
        .args(["build"])
        .stderr(std::process::Stdio::piped())
        .env("RUST_LOG", "debug")
        .kill_on_drop(true)
        .spawn()
        .expect("Failed to build project");

    let output = cmd
        .wait_with_output()
        .await
        .context("test command failed to run and complete")?;

    assert!(output.status.success());

    // Ensure that the key was generated in the default directory
    let generated_key = expected_default_key_dir.join("http_hello_world_module.nk");
    assert!(
        std::fs::metadata(&generated_key).is_ok(),
        "Key should be present and accessible in ~/.wash/keys"
    );

    // assert ./keys directory is not created for generated keys
    assert!(std::fs::metadata(project_dir.join("keys")).is_err());

    // case: keys directory configured via cli arg --keys-directory
    let key_directory = project_dir.join("batmankeys").to_string_lossy().to_string();
    let cmd = test_setup
        .base_command()
        .args(["build", "--keys-directory", &key_directory])
        .stderr(std::process::Stdio::piped())
        .env("RUST_LOG", "debug")
        .kill_on_drop(true)
        .spawn()
        .expect("Failed to build project");

    let output = cmd
        .wait_with_output()
        .await
        .context("test command failed to run and complete")?;

    assert!(output.status.success());
    let output =
        String::from_utf8(output.stderr).context("Failed to convert output bytes to String")?;
    assert!(output.contains(format!("{key_directory}/http_hello_world_module.nk").as_str()));

    // case: keys directory configured via cli arg --keys-directory and --disable-keygen=true
    let key_directory = project_dir
        .join("spidermankeys")
        .to_string_lossy()
        .to_string();
    let cmd = test_setup
        .base_command()
        .args([
            "build",
            "--keys-directory",
            &key_directory,
            "--disable-keygen",
        ])
        .env("RUST_LOG", "debug")
        .stderr(std::process::Stdio::piped())
        .kill_on_drop(true)
        .spawn()
        .expect("Failed to build project");

    let output = cmd
        .wait_with_output()
        .await
        .context("test command failed to run and complete")?;

    assert!(!output.status.success());
    let output =
        String::from_utf8(output.stderr).context("Failed to convert output bytes to String")?;
    assert!(output.contains("No keypair found"));
    assert!(output.contains("hello/spidermankeys"));

    // case: keys directory configured via env var WASH_KEYS
    let key_directory = project_dir.join("flashkeys").to_string_lossy().to_string();
    let cmd = test_setup
        .base_command()
        .args(["build"])
        .env("WASH_KEYS", &key_directory)
        .env("RUST_LOG", "debug")
        .stderr(std::process::Stdio::piped())
        .kill_on_drop(true)
        .spawn()
        .expect("Failed to build project");

    let output = cmd
        .wait_with_output()
        .await
        .context("test command failed to run and complete")?;

    assert!(output.status.success());
    let output =
        String::from_utf8(output.stderr).context("Failed to convert output bytes to String")?;
    assert!(output.contains(format!("{key_directory}/http_hello_world_module.nk").as_str()));

    // case: keys directory configured via wasmcloud.toml. The config that is written to file does affect all the remaining test cases.
    let key_directory = project_dir
        .join("haljordankeys")
        .to_string_lossy()
        .to_string();

    tokio::fs::write(
        project_dir.join("wasmcloud.toml"),
        r#"
    name = "Hello World"
    language = "rust"
    type = "component"

    [component]
    claims = ["wasmcloud:httpserver"]
    key_directory = "./haljordankeys"
    "#,
    )
    .await
    .context("failed to update wasmcloud.toml file content for test case")?;

    let cmd = test_setup
        .base_command()
        .args(["build"])
        .stderr(std::process::Stdio::piped())
        .env("RUST_LOG", "debug")
        .kill_on_drop(true)
        .spawn()
        .expect("Failed to build project");

    let output = cmd
        .wait_with_output()
        .await
        .context("test command failed to run and complete")?;

    assert!(output.status.success());
    let output =
        String::from_utf8(output.stderr).context("Failed to convert output bytes to String")?;
    assert!(output.contains(format!("{key_directory}/http_hello_world_module.nk").as_str()));

    // case when keys directory is configured via cli arg --keys-directory and wasmcloud.toml. cli arg should take precedence
    let key_directory = project_dir
        .join("wonderwomankeys")
        .to_string_lossy()
        .to_string();

    let cmd = test_setup
        .base_command()
        .args(["build", "--keys-directory", &key_directory])
        .env("RUST_LOG", "debug")
        .stderr(std::process::Stdio::piped())
        .kill_on_drop(true)
        .spawn()
        .expect("Failed to build project");

    let output = cmd
        .wait_with_output()
        .await
        .context("test command failed to run and complete")?;

    assert!(output.status.success());
    let output =
        String::from_utf8(output.stderr).context("Failed to convert output bytes to String")?;
    assert!(output.contains(format!("{key_directory}/http_hello_world_module.nk").as_str()));

    // case when keys directory is configured via env var $WASH_KEYS, cli arg --keys-directory and wasmcloud.toml. cli arg should take precedence
    let env_key_directory = project_dir.join("flashkeys").to_string_lossy().to_string();

    let key_directory = project_dir
        .join("aquamankeys")
        .to_string_lossy()
        .to_string();

    let cmd = test_setup
        .base_command()
        .args(["build", "--keys-directory", &key_directory])
        .env("WASH_KEYS", &env_key_directory)
        .env("RUST_LOG", "debug")
        .stderr(std::process::Stdio::piped())
        .kill_on_drop(true)
        .spawn()
        .expect("Failed to build project");

    let output = cmd
        .wait_with_output()
        .await
        .context("test command failed to run and complete")?;

    assert!(output.status.success());
    let output =
        String::from_utf8(output.stderr).context("Failed to convert output bytes to String")?;
    assert!(output.contains(format!("{key_directory}/http_hello_world_module.nk").as_str()));

    // case when keys directory is configured via env var $WASH_KEYS and wasmcloud.toml. env var should take precedence
    let env_key_directory = project_dir.join("orionkeys").to_string_lossy().to_string();
    let cmd = test_setup
        .base_command()
        .args(["build"])
        .env("WASH_KEYS", &env_key_directory)
        .env("RUST_LOG", "debug")
        .stderr(std::process::Stdio::piped())
        .kill_on_drop(true)
        .spawn()
        .expect("Failed to build project");

    let output = cmd
        .wait_with_output()
        .await
        .context("test command failed to run and complete")?;

    assert!(output.status.success());
    let output =
        String::from_utf8(output.stderr).context("Failed to convert output bytes to String")?;
    assert!(output.contains(format!("{env_key_directory}/http_hello_world_module.nk").as_str()));

    Ok(())
}

#[tokio::test]
#[cfg_attr(not(can_reach_ghcr_io), ignore = "ghcr.io is not reachable")]
async fn integration_build_rust_component_in_workspace_unsigned() -> Result<()> {
    let test_setup = init_workspace(vec![/* component_names= */ "hello-1", "hello-2"]).await?;
    let project_dir = test_setup.project_dirs.first().unwrap();

    let status = Command::new(env!("CARGO_BIN_EXE_wash"))
        .args(["build", "--build-only"])
        .current_dir(project_dir)
        .kill_on_drop(true)
        .status()
        .await
        .context("Failed to build project")?;

    assert!(status.success());
    let unsigned_file = project_dir.join("build/http_hello_world.wasm");
    assert!(
        tokio::fs::try_exists(unsigned_file).await.unwrap(),
        "unsigned file not found!"
    );
    let signed_file = project_dir.join("build/http_hello_world_s.wasm");
    assert!(
        !tokio::fs::try_exists(signed_file).await.unwrap(),
        "signed file should not exist when using --build-only!"
    );
    Ok(())
}

#[tokio::test]
#[cfg_attr(not(can_reach_ghcr_io), ignore = "ghcr.io is not reachable")]
async fn integration_build_tinygo_component_unsigned() -> Result<()> {
    let test_setup = init(
        /* component_name= */ "hello-world-tinygo",
        /* template_name= */ "hello-world-tinygo",
    )
    .await?;
    let project_dir = test_setup.project_dir.clone();

    let status = test_setup
        .base_command()
        .args(["build", "--build-only"])
        .kill_on_drop(true)
        .status()
        .await
        .context("Failed to build project")?;

    assert!(status.success());
    let unsigned_file = project_dir.join("build/hello-world-tinygo.wasm");
    assert!(
        tokio::fs::try_exists(unsigned_file).await.unwrap(),
        "unsigned file not found!"
    );
    let signed_file = project_dir.join("build/hello_world_tinygo_s.wasm");
    assert!(
        !tokio::fs::try_exists(signed_file).await.unwrap(),
        "signed file should not exist when using --build-only!"
    );
    Ok(())
}

#[tokio::test]
#[cfg_attr(not(can_reach_ghcr_io), ignore = "ghcr.io is not reachable")]
async fn integration_build_tinygo_component_signed() -> Result<()> {
    let test_setup = init_path(
        /* component_name= */ "http-client-tinygo",
        /* template_name= */ "examples/golang/components/http-client-tinygo",
    )
    .await?;
    let project_dir = test_setup.project_dir.clone();

    let status = test_setup
        .base_command()
        .args(["build"])
        .kill_on_drop(true)
        .status()
        .await
        .context("Failed to build project")?;

    assert!(status.success());
    let unsigned_file = project_dir.join("build/http-client-tinygo.wasm");
    assert!(
        tokio::fs::try_exists(unsigned_file).await.unwrap(),
        "unsigned file not found!"
    );
    let signed_file = project_dir.join("build/http_client_tinygo_s.wasm");
    assert!(
        tokio::fs::try_exists(signed_file).await.unwrap(),
        "signed file not found!"
    );
    let lock_file = project_dir.join(PACKAGE_LOCK_FILE_NAME);
    assert!(
        tokio::fs::try_exists(lock_file).await.unwrap(),
        "lock file not found!"
    );
    Ok(())
}

#[ignore]
#[tokio::test]
// #[cfg_attr(not(can_reach_ghcr_io), ignore = "ghcr.io is not reachable")]
// TODO: This test should be re-enabled after the transitional period for dependencies manipulation
// (wit-deps -> wkg)
async fn integration_build_tinygo_component_with_existing_deps_signed() -> Result<()> {
    let test_setup = init_path(
        /* component_name= */ "hello-world-tinygo",
        /* template_name= */
        "crates/wash-cli/tests/fixtures/old-examples/http-hello-world-go",
    )
    .await?;
    let project_dir = test_setup.project_dir.clone();

    let status = test_setup
        .base_command()
        .args(["build"])
        .kill_on_drop(true)
        .status()
        .await
        .context("Failed to build project")?;

    assert!(status.success());
    let unsigned_file = project_dir.join("build/http-hello-world.wasm");
    assert!(
        tokio::fs::try_exists(unsigned_file).await.unwrap(),
        "unsigned file not found!"
    );
    let signed_file = project_dir.join("build/http_hello_world_s.wasm");
    assert!(
        tokio::fs::try_exists(signed_file).await.unwrap(),
        "signed file not found!"
    );
    let lock_file = project_dir.join(PACKAGE_LOCK_FILE_NAME);
    assert!(
        tokio::fs::try_exists(lock_file).await.unwrap(),
        "lock file not found!"
    );
    Ok(())
}

#[tokio::test]
#[cfg_attr(not(can_reach_ghcr_io), ignore = "ghcr.io is not reachable")]
async fn integration_build_handles_dashed_names() -> Result<()> {
    let component_name = "dashed-component";
    // This tests runs against a temp directory since cargo gets confused
    // about workspace projects if done from within wash
    let root_dir = tempfile::tempdir()?;
    let component_dir = root_dir.path().join(component_name);
    let stdout_path = root_dir
        .path()
        .join(format!("wash-test.{component_name}.stdout.log"));
    let stdout = File::create(stdout_path).await?.into_std().await;

    // Execute wash new to create an component with the given name
    let mut new_cmd = Command::new(env!("CARGO_BIN_EXE_wash"))
        .args([
            "new",
            "component",
            "dashed-component",
            "-t",
            "hello-world-rust",
        ])
        .kill_on_drop(true)
        .current_dir(&root_dir)
        .stdout(stdout.try_clone()?)
        .spawn()?;
    assert!(new_cmd.wait().await?.success());

    // Ensure that the component dir was created as expected
    assert!(tokio::fs::try_exists(&component_dir).await?);

    let mut build_cmd = Command::new(env!("CARGO_BIN_EXE_wash"))
        .args(["build"])
        .kill_on_drop(true)
        .stdout(stdout)
        .current_dir(&component_dir)
        .spawn()?;

    assert!(build_cmd.wait().await?.success());

    Ok(())
}

/// Ensure that wash build can handle absolute and relative paths changing for the
/// project directory, build directory, WIT directory, and wasmcloud.toml file.
#[tokio::test]
#[cfg_attr(not(can_reach_ghcr_io), ignore = "ghcr.io is not reachable")]
async fn integration_build_tinygo_component_separate_paths() -> Result<()> {
    let test_setup = init_path(
        /* component_name= */ "http-client-tinygo",
        /* template_name= */ "examples/golang/components/http-client-tinygo",
    )
    .await?;
    let project_dir = test_setup.project_dir.clone();

    // Rename the WIT directory
    tokio::fs::rename(project_dir.join("wit"), project_dir.join("wow"))
        .await
        .context("failed to rename wit directory")?;
    // Move the wasmcloud.toml to a different directory
    tokio::fs::remove_file(project_dir.join("wasmcloud.toml"))
        .await
        .context("failed to remove wasmcloud.toml")?;
    tokio::fs::create_dir(project_dir.join("config"))
        .await
        .context("failed to create config directory")?;
    tokio::fs::write(
        project_dir.join("config").join("wasmcloud.toml"),
        r#"
    name = "tinygo-moved"
    version = "0.1.0"
    language = "tinygo"
    type = "component"
    path = "../"
    wit = "../wow"
    build = "artifacts"

    [component]
    wit_world = "hello"
    wasm_target = "wasm32-wasip2"
    "#,
    )
    .await
    .context("failed to update wasmcloud.toml file content for test case")?;

    // Make sure the go generate command uses the `wow` WIT directory
    let tiny_go_main_dot_go = tokio::fs::read_to_string(project_dir.join("hello.go"))
        .await
        .context("failed to read tinygo hello.go")?;
    let new_main_dot_go = tiny_go_main_dot_go.replace(
        "generate --world hello --out gen ./wit",
        "generate --world hello --out gen ./wow",
    );
    tokio::fs::write(project_dir.join("hello.go"), new_main_dot_go)
        .await
        .context("failed to write new main.go")?;

    let status = test_setup
        .base_command()
        .args(["build", "-p", "config/wasmcloud.toml"])
        .kill_on_drop(true)
        .status()
        .await
        .context("Failed to build project")?;

    assert!(status.success());
    let unsigned_file = project_dir.join("config/artifacts/tinygo-moved.wasm");
    assert!(
        tokio::fs::try_exists(unsigned_file).await.unwrap(),
        "unsigned file not found!"
    );
    let signed_file = project_dir.join("config/artifacts/tinygo-moved_s.wasm");
    assert!(
        tokio::fs::try_exists(signed_file).await.unwrap(),
        "signed file not found!"
    );
    let lock_file = project_dir.join(PACKAGE_LOCK_FILE_NAME);
    assert!(
        tokio::fs::try_exists(lock_file).await.unwrap(),
        "lock file not found!"
    );
    Ok(())
}

#[tokio::test]
#[cfg_attr(not(can_reach_ghcr_io), ignore = "ghcr.io is not reachable")]
async fn integration_build_provider_debug_mode() -> Result<()> {
    let test_setup = init_provider(
        /* provider_name= */ "hello-world",
        /* template_name= */ "messaging-nats",
    )
    .await?;

    let project_dir = test_setup.project_dir.clone();

    tokio::fs::write(
        &project_dir.join("wasmcloud.toml"),
        r#"
    name = "Messaging NATS"
    language = "rust"
    type = "provider"

    [provider]
    vendor = "wasmcloud"

    [rust]
    debug = true
    "#,
    )
    .await
    .context("failed to update wasmcloud.toml file content for test case")?;

    let status = test_setup
        .base_command()
        .args(["build"])
        .kill_on_drop(true)
        .status()
        .await
        .context("Failed to build project")?;

    assert!(status.success());

    Ok(())
}