mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
A command is now declared once, on the fn that implements it. A project-host command is an ide-host fn with #[command(trust = …)] listed in its module's domain!; its Tauri adapter, bindings entry, JSON-RPC handler, trust class and remote routing are derived from that declaration. Desktop-only commands keep their Tauri fn and add #[desktop_command(trust = …)]. This removes the hand-written pass-through adapters, collect_commands!, the per-domain register fns and the trust tables in trust.rs. The invoke handler looks up each command's declared trust class; a name nothing declares is denied. A remote window routes the project-host commands of the desktop's own build. Duplicate names are a compile error. CI runs ide-command's compile_fail doctests. Part of #3344. Co-authored-by: Mr0Bread <55754540+Mr0Bread@users.noreply.github.com>
45 lines
1.8 KiB
Rust
45 lines
1.8 KiB
Rust
//! `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");
|
|
}
|
|
}
|