//! `cargo test -p openidea --test export_bindings` regenerates `src/bindings.ts` and //! `src-tauri/tests/commands.snap` without launching the app (used by `pnpm gen:bindings` //! and CI drift checks). use ide_host::catalogue::{Mode, Placement, TrustClass}; use std::path::Path; #[test] fn export_bindings() { openidea_lib::export_bindings(&openidea_lib::specta_builder()); } /// Every command, one line each, as declared: its trust class, where a remote window runs it, /// whether it is in `bindings.ts`, and how Tauri runs it. A change to any of these shows up in /// this file's diff. #[test] fn export_command_snapshot() { let target = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/commands.snap"); let mut out = String::from( "# Generated by `pnpm gen:bindings`; do not edit. One line per command:\n\ # name, trust class, placement in a remote window, in bindings.ts, how Tauri runs it.\n", ); for c in openidea_lib::declarations() { let trust = match c.trust { TrustClass::Always => "always", TrustClass::OutsideRestricted => "outside_restricted", TrustClass::Trusted => "trusted", }; let placement = match c.placement { Placement::Desktop => "desktop", Placement::ProjectHost => "project_host", }; let bindings = if c.bindings { "bindings" } else { "-" }; let mode = match c.mode { Mode::Sync => "sync", Mode::Async => "async", Mode::Spawn => "spawn", }; out.push_str(&format!("{:<44} {trust:<18} {placement:<12} {bindings:<8} {mode}\n", c.name)); } if std::fs::read_to_string(&target).ok().as_deref() != Some(out.as_str()) { std::fs::write(&target, out).expect("failed to write the command snapshot"); } }