vesper-player-cli 0.5.0

The vesper command-line tool for authoring, validating, and installing plugins.
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
use std::collections::HashSet;
use std::fs::{self, File};
#[cfg(any(unix, test))]
use std::io::BufReader;
#[cfg(unix)]
use std::io::Read;
use std::io::{self, BufRead, Write};
use std::path::{Path, PathBuf};
#[cfg(unix)]
use std::process::{Command, Stdio};
#[cfg(unix)]
use std::sync::Arc;
#[cfg(unix)]
use std::sync::atomic::{AtomicBool, Ordering};
#[cfg(unix)]
use std::sync::mpsc::{self, Receiver};
#[cfg(unix)]
use std::thread;
use std::time::Duration;
#[cfg(unix)]
use std::time::Instant;

use clap::ValueEnum;
use player_cli::{
    PluginArtifactFormat, PluginArtifactSource, PluginArtifactTransport, PluginProjectManifest,
};
#[cfg(unix)]
use player_platform_process::configure_background_process_group;
use serde::{Deserialize, Serialize};

const MAX_CARGO_JSON_LINE_BYTES: usize = 4 * 1024 * 1024;
const MAX_CARGO_ARTIFACT_CANDIDATES: usize = 128;
#[cfg(unix)]
const BUILD_POLL_INTERVAL: Duration = Duration::from_millis(10);
#[cfg(unix)]
const BUILD_TERMINATION_GRACE: Duration = Duration::from_millis(500);
#[cfg(unix)]
const BUILD_REAP_TIMEOUT: Duration = Duration::from_secs(2);
#[cfg(unix)]
const BUILD_OUTPUT_DRAIN_GRACE: Duration = Duration::from_secs(2);

#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum PluginBuildProfile {
    Dev,
    Release,
}

impl PluginBuildProfile {
    #[cfg(unix)]
    const fn as_str(self) -> &'static str {
        match self {
            Self::Dev => "dev",
            Self::Release => "release",
        }
    }
}

#[derive(Debug)]
pub struct PluginArtifactSelector {
    pub transport: Option<PluginArtifactTransport>,
    pub target: Option<String>,
    pub architecture: Option<String>,
}

#[derive(Debug)]
pub struct PluginBuildRequest {
    pub plugin_id: String,
    #[cfg_attr(not(unix), allow(dead_code))]
    pub cargo_manifest: PathBuf,
    #[cfg_attr(not(unix), allow(dead_code))]
    pub working_directory: PathBuf,
    pub artifact: PluginArtifactSource,
    pub destination: PathBuf,
    pub profile: PluginBuildProfile,
    #[cfg_attr(not(unix), allow(dead_code))]
    pub package: Option<String>,
    #[cfg_attr(not(unix), allow(dead_code))]
    pub timeout: Duration,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PluginBuildReport {
    pub schema_version: u32,
    pub plugin_id: String,
    pub transport: PluginArtifactTransport,
    pub target: String,
    pub architecture: String,
    pub profile: PluginBuildProfile,
    pub package_id: String,
    pub cargo_target_name: String,
    pub cargo_artifact: PathBuf,
    pub output: PathBuf,
    pub bytes: u64,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PluginBuildError {
    Storage(String),
    Compatibility(String),
    Conformance(String),
    Worker(String),
}

impl std::fmt::Display for PluginBuildError {
    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Storage(message)
            | Self::Compatibility(message)
            | Self::Conformance(message)
            | Self::Worker(message) => formatter.write_str(message),
        }
    }
}

impl std::error::Error for PluginBuildError {}

pub fn select_plugin_artifact(
    project: &PluginProjectManifest,
    selector: &PluginArtifactSelector,
) -> Result<PluginArtifactSource, PluginBuildError> {
    let matches = project
        .artifacts()
        .iter()
        .filter(|artifact| {
            selector
                .transport
                .is_none_or(|transport| artifact.transport == transport)
                && selector
                    .target
                    .as_deref()
                    .is_none_or(|target| artifact.target == target)
                && selector
                    .architecture
                    .as_deref()
                    .is_none_or(|architecture| artifact.architecture == architecture)
        })
        .cloned()
        .collect::<Vec<_>>();
    match matches.as_slice() {
        [artifact] => match (artifact.transport, artifact.format) {
            (PluginArtifactTransport::Native, PluginArtifactFormat::Dylib)
            | (PluginArtifactTransport::Wasm, PluginArtifactFormat::WasmComponent) => {
                Ok(artifact.clone())
            }
            _ => Err(PluginBuildError::Compatibility(format!(
                "vesper plugin build supports Cargo dylib and wasm-component artifacts; selected '{}:{}' uses format '{}'",
                artifact.transport.as_str(),
                artifact.target,
                artifact.format.as_str()
            ))),
        },
        [] => Err(PluginBuildError::Compatibility(
            "no manifest artifact matches the requested transport, target, and architecture"
                .to_owned(),
        )),
        _ => Err(PluginBuildError::Compatibility(format!(
            "artifact selector is ambiguous and matches {} manifest entries; specify --transport, --target, and --architecture",
            matches.len()
        ))),
    }
}

pub fn build_plugin_artifact(
    request: PluginBuildRequest,
) -> Result<PluginBuildReport, PluginBuildError> {
    let candidates = run_cargo_build(&request)?;
    let expected_extension = expected_artifact_extension(&request.artifact)?;
    let mut matches = candidates
        .into_iter()
        .filter(|candidate| {
            candidate
                .path
                .extension()
                .and_then(|extension| extension.to_str())
                .is_some_and(|extension| extension.eq_ignore_ascii_case(expected_extension))
        })
        .collect::<Vec<_>>();
    matches.sort_by(|left, right| left.path.cmp(&right.path));
    let candidate = match matches.as_slice() {
        [candidate] => candidate,
        [] => {
            return Err(PluginBuildError::Conformance(format!(
                "Cargo completed successfully but did not emit one '{}' cdylib artifact for target '{}'",
                expected_extension, request.artifact.target
            )));
        }
        _ => {
            return Err(PluginBuildError::Compatibility(format!(
                "Cargo emitted {} matching cdylib artifacts for target '{}'; use --package to select one package",
                matches.len(),
                request.artifact.target
            )));
        }
    };
    let bytes = atomic_copy_artifact(&candidate.path, &request.destination)?;
    Ok(PluginBuildReport {
        schema_version: 1,
        plugin_id: request.plugin_id,
        transport: request.artifact.transport,
        target: request.artifact.target,
        architecture: request.artifact.architecture,
        profile: request.profile,
        package_id: candidate.package_id.clone(),
        cargo_target_name: candidate.target_name.clone(),
        cargo_artifact: candidate.path.clone(),
        output: request.destination,
        bytes,
    })
}

fn expected_artifact_extension(
    artifact: &PluginArtifactSource,
) -> Result<&'static str, PluginBuildError> {
    match (artifact.transport, artifact.format) {
        (PluginArtifactTransport::Wasm, PluginArtifactFormat::WasmComponent) => Ok("wasm"),
        (PluginArtifactTransport::Native, PluginArtifactFormat::Dylib) => {
            if artifact.target.contains("windows") {
                Ok("dll")
            } else if artifact.target.contains("apple")
                || artifact.target.contains("darwin")
                || artifact.target.contains("ios")
            {
                Ok("dylib")
            } else {
                Ok("so")
            }
        }
        _ => Err(PluginBuildError::Compatibility(format!(
            "artifact format '{}' cannot be built by Cargo",
            artifact.format.as_str()
        ))),
    }
}

#[derive(Debug)]
struct CargoArtifactCandidate {
    package_id: String,
    target_name: String,
    path: PathBuf,
}

#[derive(Debug, Deserialize)]
struct CargoMessage {
    reason: String,
    #[serde(default)]
    package_id: Option<String>,
    #[serde(default)]
    target: Option<CargoTarget>,
    #[serde(default)]
    filenames: Vec<PathBuf>,
    #[serde(default)]
    message: Option<CargoDiagnostic>,
}

#[derive(Debug, Deserialize)]
struct CargoTarget {
    name: String,
    #[serde(default)]
    kind: Vec<String>,
    #[serde(default)]
    crate_types: Vec<String>,
}

#[derive(Debug, Deserialize)]
struct CargoDiagnostic {
    #[serde(default)]
    rendered: Option<String>,
}

#[cfg(unix)]
fn run_cargo_build(
    request: &PluginBuildRequest,
) -> Result<Vec<CargoArtifactCandidate>, PluginBuildError> {
    let cargo = std::env::var_os("CARGO").unwrap_or_else(|| "cargo".into());
    let mut command = Command::new(cargo);
    command
        .arg("build")
        .arg("--manifest-path")
        .arg(&request.cargo_manifest)
        .arg("--target")
        .arg(&request.artifact.target)
        .arg("--profile")
        .arg(request.profile.as_str())
        .arg("--message-format=json-render-diagnostics")
        .current_dir(&request.working_directory)
        .stdin(Stdio::null())
        .stdout(Stdio::piped())
        .stderr(Stdio::inherit());
    configure_background_process_group(&mut command);
    if let Some(package) = request.package.as_deref() {
        command.arg("--package").arg(package);
    }
    let mut child = command.spawn().map_err(|error| {
        PluginBuildError::Worker(format!("failed to spawn Cargo build: {error}"))
    })?;
    let process_group = i32::try_from(child.id()).map_err(|_| {
        let _ = child.kill();
        let _ = child.wait();
        PluginBuildError::Worker(
            "Cargo build process id cannot be represented as a process group".to_owned(),
        )
    })?;
    let stdout = child.stdout.take().ok_or_else(|| {
        abort_build_setup(&mut child, process_group);
        PluginBuildError::Worker("Cargo build stdout pipe is missing".to_owned())
    })?;
    let output = start_cargo_output_parser(stdout);
    let cancelled = Arc::new(AtomicBool::new(false));
    let signal_id =
        signal_hook::flag::register(signal_hook::consts::SIGINT, Arc::clone(&cancelled)).map_err(
            |error| {
                abort_build_setup(&mut child, process_group);
                PluginBuildError::Worker(format!(
                    "failed to install Cargo build cancellation handler: {error}"
                ))
            },
        )?;
    let signal_guard = SignalRegistration(signal_id);
    let started = Instant::now();
    let status = loop {
        match child.try_wait() {
            Ok(Some(status)) => break status,
            Ok(None) => {}
            Err(error) => {
                let _ = terminate_and_reap(&mut child, process_group, false);
                return Err(PluginBuildError::Worker(format!(
                    "failed to poll Cargo build: {error}"
                )));
            }
        }
        if cancelled.load(Ordering::Acquire) {
            terminate_and_reap(&mut child, process_group, true)?;
            drop(signal_guard);
            return Err(PluginBuildError::Worker(
                "Cargo build was cancelled".to_owned(),
            ));
        }
        if started.elapsed() >= request.timeout {
            terminate_and_reap(&mut child, process_group, false)?;
            drop(signal_guard);
            return Err(PluginBuildError::Worker(format!(
                "Cargo build exceeded its {} ms deadline",
                request.timeout.as_millis()
            )));
        }
        thread::sleep(BUILD_POLL_INTERVAL);
    };
    drop(signal_guard);
    cleanup_descendants(process_group);
    let candidates = receive_cargo_output(output)?;
    if !status.success() {
        return Err(PluginBuildError::Conformance(format!(
            "Cargo build exited unsuccessfully ({status})"
        )));
    }
    Ok(candidates)
}

#[cfg(not(unix))]
fn run_cargo_build(
    _request: &PluginBuildRequest,
) -> Result<Vec<CargoArtifactCandidate>, PluginBuildError> {
    Err(PluginBuildError::Worker(
        "Cargo build process containment is not implemented for this platform".to_owned(),
    ))
}

#[cfg(unix)]
fn start_cargo_output_parser<R>(reader: R) -> Receiver<Result<Vec<CargoArtifactCandidate>, String>>
where
    R: Read + Send + 'static,
{
    let (sender, receiver) = mpsc::sync_channel(1);
    thread::spawn(move || {
        let result = parse_cargo_output(BufReader::new(reader));
        let _ = sender.send(result);
    });
    receiver
}

fn parse_cargo_output<R>(mut reader: R) -> Result<Vec<CargoArtifactCandidate>, String>
where
    R: BufRead,
{
    let mut candidates = Vec::new();
    let mut seen = HashSet::new();
    while let Some(line) = read_bounded_line(&mut reader, MAX_CARGO_JSON_LINE_BYTES)? {
        if line.iter().all(u8::is_ascii_whitespace) {
            continue;
        }
        let message: CargoMessage = serde_json::from_slice(&line)
            .map_err(|error| format!("Cargo emitted invalid JSON output: {error}"))?;
        if message.reason == "compiler-message"
            && let Some(rendered) = message.message.and_then(|message| message.rendered)
        {
            let mut stderr = io::stderr().lock();
            stderr
                .write_all(rendered.as_bytes())
                .map_err(|error| format!("failed to relay Cargo diagnostic: {error}"))?;
            if !rendered.ends_with('\n') {
                stderr
                    .write_all(b"\n")
                    .map_err(|error| format!("failed to terminate Cargo diagnostic: {error}"))?;
            }
        }
        if message.reason != "compiler-artifact" {
            continue;
        }
        let Some(target) = message.target else {
            return Err("Cargo compiler-artifact message is missing its target".to_owned());
        };
        if !target
            .crate_types
            .iter()
            .chain(target.kind.iter())
            .any(|kind| kind == "cdylib")
        {
            continue;
        }
        let package_id = message.package_id.ok_or_else(|| {
            "Cargo compiler-artifact message is missing its package_id".to_owned()
        })?;
        for path in message.filenames {
            if seen.insert(path.clone()) {
                if candidates.len() >= MAX_CARGO_ARTIFACT_CANDIDATES {
                    return Err(format!(
                        "Cargo emitted more than {MAX_CARGO_ARTIFACT_CANDIDATES} cdylib artifact candidates"
                    ));
                }
                candidates.push(CargoArtifactCandidate {
                    package_id: package_id.clone(),
                    target_name: target.name.clone(),
                    path,
                });
            }
        }
    }
    Ok(candidates)
}

fn read_bounded_line<R>(reader: &mut R, maximum_bytes: usize) -> Result<Option<Vec<u8>>, String>
where
    R: BufRead,
{
    let mut line = Vec::new();
    loop {
        let available = reader
            .fill_buf()
            .map_err(|error| format!("failed to read Cargo JSON output: {error}"))?;
        if available.is_empty() {
            return if line.is_empty() {
                Ok(None)
            } else {
                Ok(Some(line))
            };
        }
        let consumed = available
            .iter()
            .position(|byte| *byte == b'\n')
            .map_or(available.len(), |index| index + 1);
        if line.len().saturating_add(consumed) > maximum_bytes {
            return Err(format!(
                "Cargo JSON output line exceeds {maximum_bytes} bytes"
            ));
        }
        line.extend_from_slice(&available[..consumed]);
        let ended = available[consumed - 1] == b'\n';
        reader.consume(consumed);
        if ended {
            return Ok(Some(line));
        }
    }
}

#[cfg(unix)]
fn receive_cargo_output(
    receiver: Receiver<Result<Vec<CargoArtifactCandidate>, String>>,
) -> Result<Vec<CargoArtifactCandidate>, PluginBuildError> {
    receiver
        .recv_timeout(BUILD_OUTPUT_DRAIN_GRACE)
        .map_err(|error| {
            PluginBuildError::Worker(format!(
                "Cargo JSON output did not finish draining within {} ms: {error}",
                BUILD_OUTPUT_DRAIN_GRACE.as_millis()
            ))
        })?
        .map_err(PluginBuildError::Worker)
}

fn atomic_copy_artifact(source: &Path, destination: &Path) -> Result<u64, PluginBuildError> {
    let metadata = fs::symlink_metadata(source).map_err(|error| {
        PluginBuildError::Conformance(format!(
            "failed to inspect Cargo artifact '{}': {error}",
            source.display()
        ))
    })?;
    if !metadata.file_type().is_file() {
        return Err(PluginBuildError::Conformance(format!(
            "Cargo artifact '{}' is not a regular non-symlink file",
            source.display()
        )));
    }
    if source == destination {
        return Ok(metadata.len());
    }
    let parent = destination
        .parent()
        .filter(|parent| !parent.as_os_str().is_empty())
        .unwrap_or_else(|| Path::new("."));
    fs::create_dir_all(parent).map_err(|error| {
        PluginBuildError::Storage(format!(
            "failed to create artifact output directory '{}': {error}",
            parent.display()
        ))
    })?;
    let mut input = File::open(source).map_err(|error| {
        PluginBuildError::Conformance(format!(
            "failed to open Cargo artifact '{}': {error}",
            source.display()
        ))
    })?;
    let mut temporary = tempfile::NamedTempFile::new_in(parent).map_err(|error| {
        PluginBuildError::Storage(format!(
            "failed to create artifact staging file in '{}': {error}",
            parent.display()
        ))
    })?;
    let bytes = io::copy(&mut input, &mut temporary).map_err(|error| {
        PluginBuildError::Storage(format!(
            "failed to stage Cargo artifact for '{}': {error}",
            destination.display()
        ))
    })?;
    temporary.as_file().sync_all().map_err(|error| {
        PluginBuildError::Storage(format!(
            "failed to sync staged Cargo artifact for '{}': {error}",
            destination.display()
        ))
    })?;
    temporary.persist(destination).map_err(|error| {
        PluginBuildError::Storage(format!(
            "failed to atomically replace artifact '{}': {}",
            destination.display(),
            error.error
        ))
    })?;
    Ok(bytes)
}

#[cfg(unix)]
fn abort_build_setup(child: &mut std::process::Child, process_group: i32) {
    let _ = terminate_and_reap(child, process_group, false);
}

#[cfg(unix)]
fn terminate_and_reap(
    child: &mut std::process::Child,
    process_group: i32,
    cancelled: bool,
) -> Result<(), PluginBuildError> {
    use nix::sys::signal::Signal;

    let initial_signal = if cancelled {
        Signal::SIGINT
    } else {
        Signal::SIGTERM
    };
    let initial_error = signal_process_group(process_group, initial_signal).err();
    if initial_error.is_some() {
        let _ = child.kill();
    }
    let grace_deadline = Instant::now() + BUILD_TERMINATION_GRACE;
    while Instant::now() < grace_deadline {
        if child
            .try_wait()
            .map_err(|error| {
                PluginBuildError::Worker(format!("failed to reap Cargo build: {error}"))
            })?
            .is_some()
        {
            cleanup_descendants(process_group);
            return initial_error.map_or(Ok(()), Err);
        }
        thread::sleep(BUILD_POLL_INTERVAL);
    }
    let kill_error = signal_process_group(process_group, Signal::SIGKILL).err();
    let _ = child.kill();
    let reap_deadline = Instant::now() + BUILD_REAP_TIMEOUT;
    while Instant::now() < reap_deadline {
        if child
            .try_wait()
            .map_err(|error| {
                PluginBuildError::Worker(format!("failed to reap Cargo build: {error}"))
            })?
            .is_some()
        {
            return initial_error.or(kill_error).map_or(Ok(()), Err);
        }
        thread::sleep(BUILD_POLL_INTERVAL);
    }
    Err(PluginBuildError::Worker(
        "Cargo build could not be reaped after termination".to_owned(),
    ))
}

#[cfg(unix)]
fn signal_process_group(
    process_group: i32,
    signal: nix::sys::signal::Signal,
) -> Result<(), PluginBuildError> {
    use nix::errno::Errno;
    use nix::sys::signal::killpg;
    use nix::unistd::Pid;

    match killpg(Pid::from_raw(process_group), signal) {
        Ok(()) | Err(Errno::ESRCH) => Ok(()),
        Err(error) => Err(PluginBuildError::Worker(format!(
            "failed to signal Cargo build process group: {error}"
        ))),
    }
}

#[cfg(unix)]
fn cleanup_descendants(process_group: i32) {
    use nix::sys::signal::{Signal, killpg};
    use nix::unistd::Pid;

    let process_group = Pid::from_raw(process_group);
    let _ = killpg(process_group, Signal::SIGTERM);
    thread::sleep(Duration::from_millis(20));
    let _ = killpg(process_group, Signal::SIGKILL);
}

#[cfg(unix)]
struct SignalRegistration(signal_hook::SigId);

#[cfg(unix)]
impl Drop for SignalRegistration {
    fn drop(&mut self) {
        signal_hook::low_level::unregister(self.0);
    }
}

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

    #[test]
    fn bounded_line_reader_rejects_an_unterminated_oversized_line() {
        let mut reader = BufReader::new(&b"12345"[..]);
        let error = read_bounded_line(&mut reader, 4).expect_err("oversized line");
        assert!(error.contains("exceeds 4 bytes"));
    }

    #[test]
    fn cargo_parser_keeps_only_unique_cdylib_filenames() {
        let source = br#"{"reason":"compiler-artifact","package_id":"fixture 0.1.0","target":{"name":"fixture","kind":["cdylib"],"crate_types":["cdylib"]},"filenames":["/tmp/fixture.wasm","/tmp/fixture.wasm"]}
{"reason":"build-finished","success":true}
"#;
        let candidates = parse_cargo_output(BufReader::new(&source[..])).expect("Cargo JSON");
        assert_eq!(candidates.len(), 1);
        assert_eq!(candidates[0].path, Path::new("/tmp/fixture.wasm"));
    }
}