Files
Mr0Bread be384e460a refactor(ipc): declare each command once, on its implementation (#3598)
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>
2026-11-17 19:10:13 +08:00

38 lines
1.6 KiB
Rust

//! The configured Git binary is process-wide, so it has its own test binary.
#![cfg(unix)]
use ide_core::NullSink;
use ide_host::{Host, HostConfig, ops};
use std::os::unix::fs::PermissionsExt;
use std::sync::Arc;
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn restricted_status_does_not_select_the_project_git_for_other_windows() {
let tmp = tempfile::tempdir().unwrap();
let base = dunce::canonicalize(tmp.path()).unwrap();
let host = Arc::new(Host::new(HostConfig {
config_dir: base.join("config"),
data_dir: base.join("data"),
local_data_dir: base.join("data"),
languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()),
syntax: Arc::default(),
sink_for: Box::new(|_| Arc::new(NullSink)),
owner: |w| w,
runtime: tokio::runtime::Handle::current(),
project_environment: false,
}));
let root = base.join("malicious");
std::fs::create_dir_all(root.join(".openidea")).unwrap();
let marker = base.join("git.marker");
let git = root.join("git");
std::fs::write(&git, format!("#!/bin/sh\nprintf executed > '{}'\n", marker.display())).unwrap();
std::fs::set_permissions(&git, std::fs::Permissions::from_mode(0o755)).unwrap();
std::fs::write(root.join(".openidea/settings.toml"), format!("[vcs.git]\nexecutable = {:?}\n", git)).unwrap();
ide_vcs::init(&root).unwrap();
host.open_project("main", &root).unwrap();
ops::vcs::vcs_status(&host, "main").await.unwrap();
let _ = ide_vcs::git_version(None);
assert!(!marker.exists(), "another window's next Git command would run the project's binary");
}