дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
Plugin API 1.21 adds ui.set-console-links: regex rules (validated like console highlight rules) that make matches in Run and Debug console output clickable and run one of the plugin's declared commands with { text, line, argument }; built-in file and URL links win where they overlap. It also adds the run.output capability: plugins subscribed to run-output receive the output of runs and debug sessions started in trusted projects, in chunks of at most 16 KiB, and nothing is wrapped while no plugin subscribes. Includes SDK types and MockHost support, a fixture plugin with a host integration test, regenerated bindings, rebuilt plugin components, the capability's description in the text catalog, and a README section.
Co-authored-by: RuyimgByCN <[email protected]>
108 рядки
4.5 KiB
Rust
108 рядки
4.5 KiB
Rust
//! API 1.21 `run.output` & `ui.set-console-links`: capability gating, declared-command
|
|
//! validation, console link snapshots/events, and live RunOutput event delivery.
|
|
mod common;
|
|
|
|
use ide_core::error::ErrorKind;
|
|
use ide_host::plugins::{Consent, HostWorkspace, PluginEvent, PluginHost};
|
|
use ide_host::{Host, HostConfig};
|
|
use ide_plugin::{Invocation, Limits, RunOutputEvent, WorkbenchEvent};
|
|
use std::{
|
|
path::{Path, PathBuf},
|
|
sync::{Arc, Mutex},
|
|
time::Duration,
|
|
};
|
|
|
|
/// An emitted plugin event and the window it went to.
|
|
type WindowEvent = (Option<String>, PluginEvent);
|
|
|
|
const ID: &str = "test.run-output";
|
|
|
|
fn fixture() -> PathBuf {
|
|
Path::new(env!("CARGO_MANIFEST_DIR")).join("../ide-plugin/tests/fixtures/run-output")
|
|
}
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
async fn run_output_and_console_links_enforce_grants_and_deliver_events() {
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
let root = dunce::canonicalize(tmp.path()).unwrap().join("project");
|
|
std::fs::create_dir(&root).unwrap();
|
|
|
|
let host =
|
|
Arc::new(Host::new(HostConfig { local_data_dir: tmp.path().join("local"), ..common::host_config(tmp.path()) }));
|
|
host.open_project("main", &root).unwrap();
|
|
|
|
let inv = || Invocation { client: Some("main".into()), workspace_root: Some(root.clone()), ..Default::default() };
|
|
|
|
// 1. Denied without `run.output`.
|
|
let denied = Arc::new(
|
|
PluginHost::new(
|
|
tmp.path().join("plugins-denied"),
|
|
Arc::new(|_: Option<&str>, _| {}),
|
|
Limits { timeout: Duration::from_secs(5), ..Default::default() },
|
|
)
|
|
.unwrap(),
|
|
);
|
|
denied.set_workspace(Some(Arc::new(HostWorkspace(Arc::downgrade(&host)))));
|
|
denied.install_from_dir(&fixture(), &Consent { optional: vec![], signer_change: true }).unwrap();
|
|
let (p, i) = (denied.clone(), inv());
|
|
let err = tokio::task::spawn_blocking(move || p.run_command(ID, "subscribe", None, i)).await.unwrap().unwrap_err();
|
|
assert_eq!(err.kind, ErrorKind::PermissionDenied);
|
|
|
|
// Undeclared command in `set_console_links` is rejected.
|
|
let (p, i) = (denied.clone(), inv());
|
|
let bad =
|
|
tokio::task::spawn_blocking(move || p.run_command(ID, "set-bad-link", None, i)).await.unwrap().unwrap_err();
|
|
assert_ne!(bad.kind, ErrorKind::PermissionDenied, "should fail validation, got {bad:?}");
|
|
|
|
// 2. Granted `run.output`: subscribe, set links, emit ConsoleLinksChanged, and receive RunOutput.
|
|
let events: Arc<Mutex<Vec<WindowEvent>>> = Arc::new(Mutex::new(Vec::new()));
|
|
let sink_events = events.clone();
|
|
let granted = Arc::new(
|
|
PluginHost::new(
|
|
tmp.path().join("plugins-granted"),
|
|
Arc::new(move |w: Option<&str>, ev| {
|
|
sink_events.lock().unwrap().push((w.map(str::to_owned), ev));
|
|
}),
|
|
Limits { timeout: Duration::from_secs(5), ..Default::default() },
|
|
)
|
|
.unwrap(),
|
|
);
|
|
granted.set_workspace(Some(Arc::new(HostWorkspace(Arc::downgrade(&host)))));
|
|
granted.install_from_dir(&fixture(), &Consent::all()).unwrap();
|
|
|
|
let (p, i) = (granted.clone(), inv());
|
|
tokio::task::spawn_blocking(move || p.run_command(ID, "subscribe", None, i)).await.unwrap().unwrap();
|
|
let (p, i) = (granted.clone(), inv());
|
|
tokio::task::spawn_blocking(move || p.run_command(ID, "set-links", None, i)).await.unwrap().unwrap();
|
|
|
|
let snapshot = granted.console_links();
|
|
let rules = snapshot.get(ID).expect("console link rules stored");
|
|
assert_eq!(rules.len(), 1);
|
|
assert_eq!(rules[0].command, "open");
|
|
assert!(events.lock().unwrap().iter().any(|(_, e)| matches!(
|
|
e,
|
|
PluginEvent::ConsoleLinksChanged { plugin_id, rules } if plugin_id == ID && rules.len() == 1
|
|
)));
|
|
|
|
granted.post_events(
|
|
Some("main"),
|
|
vec![WorkbenchEvent::RunOutput(RunOutputEvent {
|
|
run_id: "run-1".into(),
|
|
config_id: Some("app".into()),
|
|
stream: "stdout".into(),
|
|
text: "SQL: SELECT 1\n".into(),
|
|
})],
|
|
);
|
|
|
|
let (p, i) = (granted.clone(), inv());
|
|
let received = tokio::task::spawn_blocking(move || {
|
|
p.flush_events_at(std::time::Instant::now() + Duration::from_secs(3));
|
|
assert!(p.wait_events(Duration::from_secs(5)), "run-output event was not delivered");
|
|
p.run_command(ID, "drain", None, i).unwrap().unwrap_or_default()
|
|
})
|
|
.await
|
|
.unwrap();
|
|
assert!(received.contains("run-1"), "expected run-output payload, got {received:?}");
|
|
assert!(received.contains("SQL: SELECT 1"), "expected output text, got {received:?}");
|
|
}
|