Файли
openidea/sdk/rust/openidea-plugin/tests/api21_git_actions.rs
T
astesiaтаkirito1105 05a88394fb feat(plugins): Project view panes and Git branch menu commands (API 1.21) (#7980)
Plugins can add panes to the Project tool window and commands to the Git branch menus:

- `[[contributes.projectViewPanes]]` with the `project-view-provider` export regroups a directory's native children under virtual folders. Existing nodes keep their icons, Git status and actions. `project-view.refresh` / `select-in` and `projectViewContext` menu items work against these panes. Requires `project.read`.
- `git.branches.popup` and `git.branch.context` menus. `invocation.git-action-context` gives the command the repository roots and the full ref of the clicked branch. Requires `vcs.read`.
- `views.open-revision-comparison` opens the IDE's comparison of two full commit IDs as a Compare tool window tab, the same one Compare Versions opens. The repository must be a mapped Git root of the invoking trusted project. Requires `vcs.read`.

All of this is part of plugin API 1.21. A project-view test fixture and host tests cover the provider, the branch menu context and the comparison call. The plugin components and bindings are rebuilt.

Co-authored-by: kirito1105 <[email protected]>
2026-12-05 12:24:10 +08:00

42 рядки
1.6 KiB
Rust

use openidea_plugin::{Error, GitActionBranch, GitActionContext, RevisionComparison, host, mock::MockHost};
#[test]
fn opens_a_native_comparison_with_immutable_revisions() {
let mut comparison = RevisionComparison {
repository: "/repo".into(),
left: "a".repeat(40),
right: "b".repeat(40),
left_label: Some("Merge base".into()),
right_label: None,
};
{
let _mock = MockHost::install().with_capabilities(&[]);
assert_eq!(host::open_revision_comparison(&comparison), Err(Error::Denied("vcs.read".into())));
}
let mock = MockHost::install().with_capabilities(&["vcs.read"]);
host::open_revision_comparison(&comparison).unwrap();
assert_eq!(mock.revision_comparisons(), [comparison.clone()]);
comparison.left = "HEAD~1".into();
assert!(matches!(host::open_revision_comparison(&comparison), Err(Error::Invalid(_))));
assert_eq!(mock.revision_comparisons().len(), 1);
}
#[test]
fn exposes_a_git_branch_snapshot_only_with_vcs_read() {
let context = GitActionContext {
repositories: vec!["/repo".into(), "/repo-two".into()],
branch: Some(GitActionBranch {
name: "origin/release".into(),
full_ref: "refs/remotes/origin/release".into(),
remote: true,
}),
};
{
let mock = MockHost::install().with_capabilities(&[]).with_git_action_context(context.clone());
assert_eq!(mock.invocation().git_action_context(), None);
}
let mock = MockHost::install().with_capabilities(&["vcs.read"]).with_git_action_context(context.clone());
assert_eq!(mock.invocation().git_action_context(), Some(context));
}