#![allow( unused_imports, unused_variables, clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::indexing_slicing, clippy::redundant_closure, clippy::useless_conversion, clippy::bool_assert_comparison, clippy::collapsible_if, clippy::len_zero, clippy::needless_borrow, clippy::redundant_locals, suspicious_double_ref_op )] //! 10,000-scenario deep sweep of vak-delivery across all surfaces. //! //! Red Team — 5,000 adversarial scenarios (×6 surfaces = 30,000 checks): //! XSS injection, malformed tables, code-fence abuse, spoiler edge cases, //! unicode abuse, extreme inputs, link injection, nested markdown abuse, //! worker-protocol fuzz, empty/null inputs. //! //! Blue Team — 5,000 defensive scenarios: //! error-path non-panic, HTML sanitization, determinism, coverage //! accounting, capability validation, template revision security, outbox //! state machine, signal accuracy, skill validation, worker round-trip, //! structured-output parsing. //! //! Each scenario closure tests ALL six surfaces (telegram, discord, slack, //! desktop, terminal, admin) so a single failure is caught at the right //! surface. use serde_json::json; use std::collections::BTreeMap; use vak_delivery::Block; use vak_delivery::DeliveryPacket; use vak_delivery::Markup; use vak_delivery::ProgressPayload; use vak_delivery::ToolResultPayload; use vak_delivery::discord; use vak_delivery::outbox::{Outbox, OutboxError, OutboxState}; use vak_delivery::skills::{ PRESENTATION_SKILL_API, PresentationSkillManifest, SignalContext, StructuredOutput, built_in_recipes, built_in_skill_registry, link_previews_from_text, parse_fragment, project_structured_fences, signals_from_context, signals_from_text, structured_outputs_from_text, }; use vak_delivery::slack; use vak_delivery::telegram; use vak_delivery::worker::{WORKER_PROTOCOL_VERSION, WorkerRequest, WorkerResponse, process_line}; use vak_delivery::{ AnswerDraft, AnswerResult, ApprovalPayload, Cadence, DeliveryAction, DeliveryContent, DeliveryError, DeliveryJob, DeliveryKind, DeliveryPayload, DeliveryPosture, DeliveryProfile, Disposition, OutputContent, OutputStatus, Urgency, }; use vak_delivery::{compile_markdown, render}; type Scenario = (String, Box); fn tc(name: &str, f: F) -> Scenario { (name.to_string(), Box::new(f)) } fn run(label: &str, scenarios: Vec) { let total = scenarios.len(); let mut passed = 0usize; let mut failures: Vec = Vec::new(); for (name, test) in scenarios { match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| test())) { Ok(()) => passed += 1, Err(_) => failures.push(name), } } assert_eq!( passed, total, "{label}: {passed}/{total} passed — failures: {failures:?}" ); println!(" ✓ {label}: {total} scenarios passed"); } fn answer_draft(source: &str) -> AnswerDraft { AnswerDraft::from_markdown(source) } fn answer_job(source: &str, markup: Markup, surface: &str) -> DeliveryJob { DeliveryJob { job_id: "sweep".into(), target: format!("{surface}:one"), kind: DeliveryKind::Assistant, content: DeliveryContent::Answer(answer_draft(source)), profile: DeliveryProfile { surface: surface.into(), markup, max_chars: None, supports_tables: true, supports_code_blocks: true, supports_links: true, supports_actions: false, template: None, posture: DeliveryPosture::default(), }, skill_registry: None, } } fn make_root() -> std::path::PathBuf { std::env::temp_dir().join(format!( "vak-sweep-{}-{}", std::process::id(), std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .unwrap() .as_nanos() )) } const SURFACES: &[(&str, Markup)] = &[ ("telegram", Markup::TelegramHtml), ("discord", Markup::DiscordMarkdown), ("slack", Markup::SlackMrkdwn), ("desktop", Markup::Markdown), ("terminal", Markup::Plain), ("admin", Markup::Plain), ]; const MARKUPS: &[(Markup, &str)] = &[ (Markup::Plain, "plain"), (Markup::Markdown, "markdown"), (Markup::TelegramHtml, "telegram"), (Markup::SlackMrkdwn, "slack"), (Markup::DiscordMarkdown, "discord"), (Markup::Json, "json"), ]; fn all_surfaces_render(source: &str) { for (surface, markup) in SURFACES { let job = answer_job(source, *markup, surface); let _ = render(&job); } } // ═══════════════════════ RED TEAM ═══════════════════════════════════ #[test] fn red_team_xss_injection() { let mut scenarios: Vec = vec![]; let payloads: Vec = (0..500) .map(|i| { let templates: &[&str] = &[ "", "", "", "", "