wyvern-cli 0.4.0

What You View, Engine Renders Natively — HTTP dialog CLI
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
//! Load/validation/run-stage errors and JSON emission helpers.

mod emit;

use wyvern_schema::{ErrorCode, FieldName, SerializeError};

#[doc(inline)]
pub use emit::{
    emit_extension_error, emit_fatal_internal, emit_host_error, emit_io_error, emit_parse_error,
    emit_stdout, emit_usage_error, emit_usage_message, emit_validation_error,
    emit_wizard_lint_stage_error, emit_workflow_error,
};

/// Built-in CLI family that owns subcommands (`browsers`, `extensions`, `examples`, `wizard`).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BuiltinDomain {
    /// `wyvern browsers …`
    Browsers,
    /// `wyvern extensions …`
    Extensions,
    /// `wyvern examples …`
    Examples,
    /// `wyvern wizard …`
    Wizard,
}

impl BuiltinDomain {
    /// Stable CLI family name.
    #[must_use]
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Browsers => "browsers",
            Self::Extensions => "extensions",
            Self::Examples => "examples",
            Self::Wizard => "wizard",
        }
    }
}

impl std::fmt::Display for BuiltinDomain {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

/// Host-flag / env usage failure kind for structured stderr recovery (RBP-F009).
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum UsageErrorKind {
    /// Generic argv/input usage (empty stdin, too many args, etc.).
    Generic,
    /// `--bind` value failed to parse as a socket address.
    InvalidBind {
        /// Raw `--bind` token from argv.
        value: String,
    },
    /// A host flag was given without a following value.
    MissingFlagValue {
        /// Flag name (e.g. `--bind`).
        flag: String,
    },
    /// `--viewer` value was not a known viewer mode.
    InvalidViewer {
        /// Raw `--viewer` token from argv.
        value: String,
    },
    /// `WYVERN_VIEWER` is set but not a valid viewer mode (RSH-010).
    InvalidWyvernViewerEnv {
        /// Raw env var value.
        value: String,
    },
    /// `WYVERN_VIEWER` is not valid Unicode.
    InvalidWyvernViewerUnicode,
    /// Unknown subcommand on a built-in family (`browsers`, `extensions`).
    UnknownSubcommand {
        /// Built-in family that rejected the token.
        domain: BuiltinDomain,
        /// Offending subcommand token.
        token: String,
    },
    /// `extensions show` was invoked without a usable extension id.
    MissingExtensionId,
}

/// Failure while loading command input from argv or stdin.
#[derive(Debug)]
pub enum LoadError {
    /// JSON text could not be parsed.
    Parse { message: String },
    /// A file or stdin read failed.
    Io {
        field: FieldName,
        message: String,
        /// Original I/O error if available.
        source: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
    },
    /// Invalid argv shape or host-flag value.
    Usage {
        kind: UsageErrorKind,
        message: String,
    },
}

impl std::fmt::Display for LoadError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Parse { message } => write!(f, "parse error: {message}"),
            Self::Io { field, message, .. } => write!(f, "io error ({field}): {message}"),
            Self::Usage { message, .. } => write!(f, "{message}"),
        }
    }
}

impl std::error::Error for LoadError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Self::Io { source, .. } => source.as_deref().map(|e| e as _),
            _ => None,
        }
    }
}

impl LoadError {
    /// Stable exit code for this load failure.
    pub fn exit_code(&self) -> i32 {
        match self {
            Self::Parse { .. } => ErrorCode::ParseError.exit_code(),
            Self::Io { .. } => ErrorCode::IoError.exit_code(),
            Self::Usage { .. } => ErrorCode::ParseError.exit_code(),
        }
    }
}

/// Failure serializing stdout or structured stderr JSON at the CLI emit boundary.
#[derive(Debug)]
pub enum EmitError {
    /// `serde_json` could not serialize the envelope or result.
    Serialize(SerializeError),
}

impl std::fmt::Display for EmitError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Serialize(e) => write!(f, "{e}"),
        }
    }
}

impl std::error::Error for EmitError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Self::Serialize(e) => Some(e),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use wyvern_schema::{ButtonLabel, ChromeResult, CommandResult, FieldName, MessageResult};

    #[test]
    fn emit_parse_error_with_quotes_is_valid_json() {
        let err = LoadError::Parse {
            message: r#"expected value at line 1: "bad""#.to_string(),
        };
        let out = emit_parse_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        assert_eq!(value["error"], "parse");
        assert_eq!(value["code"], "PARSE_ERROR");
        assert!(value["message"].as_str().unwrap().contains('"'));
        assert!(!value["recovery"].as_array().unwrap().is_empty());
        assert!(value.get("cause").is_some());
    }

    #[test]
    fn emit_io_error_with_quotes_is_valid_json() {
        let err = LoadError::Io {
            field: FieldName::new("file"),
            message: r#"could not read path 'say "hi".json'"#.to_string(),
            source: None,
        };
        let out = emit_io_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        assert_eq!(value["error"], "io");
        assert_eq!(value["code"], "IO_ERROR");
        assert_eq!(value["field"], "file");
        assert!(value["message"].as_str().unwrap().contains('"'));
        assert!(!value["recovery"].as_array().unwrap().is_empty());
    }

    #[test]
    fn emit_validation_error_message_with_quotes_is_valid_json() {
        let err = wyvern_schema::ValidationError::Validation {
            field: FieldName::new("title"),
            message: r#"field 'title' expected string, got "oops""#.to_string(),
        };
        let out = emit_validation_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        assert_eq!(value["error"], "validation");
        assert_eq!(value["code"], "VALIDATION_ERROR");
        assert_eq!(value["field"], "title");
        assert!(value["message"].as_str().unwrap().contains('"'));
        assert!(!value["recovery"].as_array().unwrap().is_empty());
    }

    #[test]
    fn emit_validation_error_missing_title_has_actionable_recovery() {
        let err = wyvern_schema::ValidationError::Validation {
            field: FieldName::new("title"),
            message: "missing required field 'title'".to_string(),
        };
        let out = emit_validation_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        let recovery = value["recovery"].as_array().unwrap();
        assert!(recovery
            .iter()
            .any(|s| s.as_str().unwrap().contains("title")));
    }

    #[test]
    fn emit_validation_error_state() {
        let err = wyvern_schema::ValidationError::State {
            field: FieldName::new("action"),
            message: "show is only valid in --interactive mode".to_string(),
        };
        let out = emit_validation_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        assert_eq!(value["error"], "state");
        assert_eq!(value["code"], "STATE_ERROR");
        assert_eq!(value["field"], "action");
        assert!(!value["recovery"].as_array().unwrap().is_empty());
    }

    #[test]
    fn emit_stdout_chrome_wire_shape() {
        let result = CommandResult::Chrome(ChromeResult {
            button: ButtonLabel::dismissed(),
        });
        assert_eq!(
            emit_stdout(&result).expect("emit"),
            r#"{"button":"dismissed"}"#
        );
    }

    #[test]
    fn emit_stdout_message_wire_shape() {
        let result = CommandResult::Message(MessageResult {
            button: ButtonLabel::new("ok"),
        });
        assert_eq!(emit_stdout(&result).expect("emit"), r#"{"button":"ok"}"#);
    }

    #[test]
    fn emit_stdout_forced_fail() {
        let _guard = emit::ForceEmitStdoutFailGuard::arm();
        let result = CommandResult::Message(MessageResult {
            button: ButtonLabel::new("ok"),
        });
        assert!(emit_stdout(&result).is_err());
    }

    #[test]
    fn load_error_io_preserves_source_chain() {
        let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "missing");
        let err = LoadError::Io {
            field: FieldName::new("file"),
            message: "could not read path".into(),
            source: Some(Box::new(io_err)),
        };
        assert_eq!(err.to_string(), "io error (file): could not read path");
        let source = std::error::Error::source(&err).expect("source chain");
        assert!(source.to_string().contains("missing"));
        assert!(std::error::Error::source(&LoadError::Parse {
            message: "x".into()
        })
        .is_none());
    }

    #[test]
    fn load_error_exit_codes() {
        assert_eq!(
            LoadError::Parse {
                message: "x".into()
            }
            .exit_code(),
            2
        );
        assert_eq!(
            LoadError::Io {
                field: FieldName::new("file"),
                message: "x".into(),
                source: None,
            }
            .exit_code(),
            3
        );
        assert_eq!(
            LoadError::Usage {
                kind: UsageErrorKind::Generic,
                message: "usage".into()
            }
            .exit_code(),
            2
        );
    }

    #[test]
    fn validation_error_exit_codes() {
        assert_eq!(
            wyvern_schema::ValidationError::Validation {
                field: FieldName::new("title"),
                message: "bad".into(),
            }
            .exit_code(),
            4
        );
        assert_eq!(
            wyvern_schema::ValidationError::State {
                field: FieldName::new("action"),
                message: "bad".into(),
            }
            .exit_code(),
            5
        );
    }

    #[test]
    fn emit_usage_error_is_structured_json() {
        let err = LoadError::Usage {
            kind: UsageErrorKind::Generic,
            message: "unknown subcommand".into(),
        };
        let out = emit_usage_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        assert_eq!(value["error"], "parse");
        assert_eq!(value["code"], "PARSE_ERROR");
        assert!(value["message"].as_str().unwrap().contains("unknown"));
        assert!(!value["recovery"].as_array().unwrap().is_empty());
    }

    #[test]
    fn emit_invalid_bind_has_flag_specific_recovery() {
        let err = LoadError::Usage {
            kind: UsageErrorKind::InvalidBind {
                value: "not-an-addr".into(),
            },
            message: "invalid --bind 'not-an-addr': invalid socket address".into(),
        };
        let out = emit_usage_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        let recovery = value["recovery"].as_array().unwrap();
        assert!(recovery
            .iter()
            .any(|s| s.as_str().unwrap().contains("--allow-non-loopback")));
        assert!(!value["message"].as_str().unwrap().contains("Recovery:"));
    }

    #[test]
    fn emit_invalid_wyvern_viewer_env_has_flag_specific_recovery() {
        let err = LoadError::Usage {
            kind: UsageErrorKind::InvalidWyvernViewerEnv {
                value: "not-a-viewer-mode".into(),
            },
            message: "invalid WYVERN_VIEWER=\"not-a-viewer-mode\"; expected embedded, none, system, or a named viewer path".into(),
        };
        let out = emit_usage_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        assert!(value["cause"].as_str().unwrap().contains("WYVERN_VIEWER"));
        let recovery = value["recovery"].as_array().unwrap();
        assert!(recovery
            .iter()
            .any(|s| s.as_str().unwrap().contains("Unset WYVERN_VIEWER")));
    }

    #[test]
    fn emit_unknown_subcommand_has_domain_specific_recovery() {
        let browsers = LoadError::Usage {
            kind: UsageErrorKind::UnknownSubcommand {
                domain: BuiltinDomain::Browsers,
                token: "nope".into(),
            },
            message: "unknown browsers subcommand 'nope'".into(),
        };
        let out = emit_usage_error(&browsers).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        assert!(value["cause"].as_str().unwrap().contains("nope"));
        let recovery = value["recovery"].as_array().unwrap();
        assert!(recovery
            .iter()
            .any(|s| s.as_str().unwrap().contains("browsers list")));

        let extensions = LoadError::Usage {
            kind: UsageErrorKind::UnknownSubcommand {
                domain: BuiltinDomain::Extensions,
                token: "show".into(),
            },
            message: "unknown extensions subcommand 'show'".into(),
        };
        let out = emit_usage_error(&extensions).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        let recovery = value["recovery"].as_array().unwrap();
        assert!(recovery
            .iter()
            .any(|s| s.as_str().unwrap().contains("extensions list")));
    }

    #[test]
    fn emit_missing_extension_id_has_show_recovery() {
        let err = LoadError::Usage {
            kind: UsageErrorKind::MissingExtensionId,
            message: "extensions show requires an extension id".into(),
        };
        let out = emit_usage_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        assert!(value["cause"].as_str().unwrap().contains("extension id"));
        let recovery = value["recovery"].as_array().unwrap();
        assert!(recovery
            .iter()
            .any(|s| s.as_str().unwrap().contains("extensions show <id>")));
        assert!(recovery
            .iter()
            .any(|s| s.as_str().unwrap().contains("extensions list")));
    }

    #[test]
    fn emit_missing_args_lists_flags() {
        use crate::extensions::{ExtensionError, ExtensionId};
        let err = ExtensionError::MissingArgs {
            missing: vec!["--root".into(), "--file".into()],
            declared: ["root".into(), "file".into()].into_iter().collect(),
            extension_id: ExtensionId::try_from(String::from("compose-render")).expect("id"),
            example: "wyvern compose render --root DIR --file FILE.j2".into(),
            help_command: "wyvern compose render --help".into(),
        };
        let out = emit_extension_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        let text = out.to_ascii_lowercase();
        assert!(value["message"].as_str().unwrap().contains("--root"));
        assert!(value["message"].as_str().unwrap().contains("--file"));
        assert!(value["recovery"]
            .as_array()
            .unwrap()
            .iter()
            .any(|s| s.as_str().unwrap().contains("--root")));
        assert!(value["recovery"]
            .as_array()
            .unwrap()
            .iter()
            .any(|s| s.as_str() == Some("Run wyvern compose render --help")));
        assert!(
            !out.contains("wyvern compose-render --help"),
            "recovery must use the invocation prefix, not the extension id: {out}"
        );
        assert!(!text.contains("declare them as {arg:"));
    }

    #[test]
    fn emit_unexpected_arg_is_caller_facing() {
        use crate::extensions::{ExtensionError, ExtensionId};
        let err = ExtensionError::UnexpectedArg {
            token: "--undeclared".into(),
            declared: ["root".into(), "file".into()].into_iter().collect(),
            extension_id: ExtensionId::try_from(String::from("compose-render")).expect("id"),
            help_command: "wyvern compose render --help".into(),
        };
        let out = emit_extension_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        assert!(value["cause"].as_str().unwrap().contains("--undeclared"));
        assert!(value["recovery"]
            .as_array()
            .unwrap()
            .iter()
            .any(|s| s.as_str().unwrap().contains("--root")));
        assert!(value["recovery"]
            .as_array()
            .unwrap()
            .iter()
            .any(|s| s.as_str() == Some("Run wyvern compose render --help")));
        assert!(!out.contains("wyvern compose-render --help"), "{out}");
        assert!(
            !out.contains("declare them as {arg:name}") && !out.contains("{arg:"),
            "{out}"
        );
    }

    #[test]
    fn emit_preexec_timeout_mentions_env_var() {
        use crate::extensions::{ExtensionError, PreexecFailureKind};
        let err = ExtensionError::Preexec {
            kind: Some(PreexecFailureKind::Timeout {
                cmd: "slow".into(),
                timeout_secs: 30,
            }),
            message: "slow timed out after 30s".into(),
            source: None,
        };
        let out = emit_extension_error(&err).expect("emit");
        assert!(
            out.contains("WYVERN_PREEXEC_TIMEOUT_SECS"),
            "timeout recovery must name the env var: {out}"
        );
        assert!(out.contains("30"), "{out}");
    }

    #[test]
    fn emit_wizard_lint_io_maps_to_io_error() {
        use crate::wizard_cmd::WizardLintStageError;
        let err = WizardLintStageError::Io {
            path: std::path::PathBuf::from("/missing/wizard.json"),
            message: "error: '/missing/wizard.json' not found".into(),
        };
        let out = emit_wizard_lint_stage_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        assert_eq!(value["error"], "io");
        assert_eq!(value["code"], "IO_ERROR");
        assert_eq!(value["subcode"], "wizard_lint_io");
        assert!(!value["recovery"].as_array().unwrap().is_empty());
    }

    #[test]
    fn emit_wizard_lint_parse_maps_to_parse_error() {
        use crate::wizard_cmd::WizardLintStageError;
        let err = WizardLintStageError::Parse {
            path: std::path::PathBuf::from("wizard.json"),
            message: "error: 'wizard.json': invalid JSON".into(),
        };
        let out = emit_wizard_lint_stage_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        assert_eq!(value["error"], "parse");
        assert_eq!(value["code"], "PARSE_ERROR");
        assert_eq!(value["subcode"], "wizard_lint_parse");
        assert!(value["recovery"]
            .as_array()
            .unwrap()
            .iter()
            .any(|s| s.as_str().unwrap().contains("valid JSON")));
    }

    #[test]
    fn emit_wizard_lint_validation_maps_to_validation_error() {
        use crate::wizard_cmd::WizardLintStageError;
        let err = WizardLintStageError::Validation {
            path: std::path::PathBuf::from("wizard.json"),
            field: FieldName::new("page.id"),
            message: "error: 'wizard.json': wizard.json page.id: wizard page field must be a non-empty string".into(),
        };
        let out = emit_wizard_lint_stage_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        assert_eq!(value["error"], "validation");
        assert_eq!(value["code"], "VALIDATION_ERROR");
        assert_eq!(value["subcode"], "wizard_lint_validation");
        assert_eq!(value["field"], "page.id");
        assert!(value["message"]
            .as_str()
            .unwrap()
            .contains("wizard page field must be a non-empty string"));
    }

    #[test]
    fn emit_validation_unknown_type_includes_report() {
        let err = wyvern_schema::ValidationError::Validation {
            field: FieldName::new("type"),
            message: "got 'unknown', expected one of: chrome, message, input, markdown, question, wizard, report"
                .to_string(),
        };
        let out = emit_validation_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        let recovery = value["recovery"].as_array().unwrap();
        assert!(recovery.iter().any(|s| {
            s.as_str()
                .is_some_and(|step| step.contains("wizard, report"))
        }));
        assert!(recovery.iter().any(|s| {
            s.as_str()
                .is_some_and(|step| step.contains("\"type\":\"report\""))
        }));
    }

    #[test]
    fn emit_validation_report_page_is_string_path_not_wizard_object() {
        let err = wyvern_schema::ValidationError::Validation {
            field: FieldName::new("page"),
            message: "field 'page' must end with .html or .xhtml (got 'pages/view.txt')"
                .to_string(),
        };
        let out = emit_validation_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        let recovery = value["recovery"].as_array().unwrap();
        assert!(recovery.iter().any(|s| {
            s.as_str()
                .is_some_and(|step| step.contains("pages/view.xhtml"))
        }));
        assert!(!recovery.iter().any(|s| {
            s.as_str()
                .is_some_and(|step| step.contains("\"id\":\"start\""))
        }));

        let missing = wyvern_schema::ValidationError::Validation {
            field: FieldName::new("page"),
            message: "missing required field 'page'".to_string(),
        };
        let missing_out = emit_validation_error(&missing).expect("emit");
        let missing_value: serde_json::Value =
            serde_json::from_str(&missing_out).expect("valid JSON");
        let missing_recovery = missing_value["recovery"].as_array().unwrap();
        assert!(missing_recovery
            .iter()
            .any(|s| { s.as_str().is_some_and(|step| step.contains("path string")) }));
    }

    #[test]
    fn emit_host_ui_not_found_mentions_report_page() {
        let err = wyvern_host::HostError::UiNotFound {
            path: std::path::PathBuf::from("pages/view.xhtml"),
            source: None,
        };
        let out = emit_host_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        assert!(value["cause"]
            .as_str()
            .is_some_and(|s| s.contains("report page")));
        let recovery = value["recovery"].as_array().unwrap();
        assert!(recovery
            .iter()
            .any(|s| { s.as_str().is_some_and(|step| step.contains("/report/**")) }));
    }

    #[test]
    fn emit_host_unsupported_type_includes_report() {
        let err = wyvern_host::HostError::UnsupportedType {
            type_name: wyvern_host::DialogTypeName::Chrome,
        };
        let out = emit_host_error(&err).expect("emit");
        let value: serde_json::Value = serde_json::from_str(&out).expect("valid JSON");
        assert!(value["cause"]
            .as_str()
            .is_some_and(|s| s.contains("report")));
        let recovery = value["recovery"].as_array().unwrap();
        assert!(recovery.iter().any(|s| {
            s.as_str()
                .is_some_and(|step| step.contains("wizard, report"))
        }));
    }
}