Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,9 @@ or removing a command fails until the table changes in the same commit.
| `project.checkName` | Check that a name can be a new project's directory name |
| `project.extractArchive` | Extract a downloaded project archive into the staging directory, refusing unsafe entries |
| `plugins.marketplace.validateIndex` | Validate a marketplace index and report each plugin's availability for one platform |
| `plugins.marketplace.resolveSource` | Resolve a user-entered marketplace source to the index URL to fetch |
| `plugins.marketplace.resolveSource` | Resolve a user-entered marketplace source to the index and companion recommendations URLs to fetch |
| `plugins.marketplace.installReview` | List a package's permissions and programs, and those not yet approved |
| `plugins.marketplace.recommendForWorkspace` | Match sampled workspace files against marketplace recommendation catalogs and indexes |
| `workspace.snapshot` | Enumerate visible workspace nodes and relative file paths; `nestedWorktrees` lists linked worktrees checked out inside their own repository, which are left out of the tree, files, and search index; hidden folders, Core's own and the ones enabled plugins declare through `workspace.configureVisibility`, are skipped without being read; `includeTree: false` returns only `files` and a childless `root`; `files` (and the tree, when included) keep the lowercase traversal order that bounded consumers such as Windows Quick Open rely on, not the natural display order of `workspace.listDirectories` |
| `workspace.releaseIndexing` | Retire a policy and clear index/cache data at project close; accepts `root`, optional `ownerId`, and that owner's last observed `revision`, returns `released`; an old close must not retire a new generation |
| `workspace.configureIndexing` | Install a process-local, canonical-root indexing policy before workspace consumers run; returns a monotonic revision, effective directory reasons and Git failure state; see `rust/fixtures/workspace/indexing-policy-v1.json` |
Expand Down Expand Up @@ -5332,10 +5333,15 @@ archives and pass the parsed JSON. `validateIndex` accepts
and returns `{ status: "ok", index: { plugins, rejected } }` with per-entry
`availability`; a listed version is available only when its `pluginAPIVersion`
is one Core supports and every capability it requires is in `hostCapabilities`; `resolveSource` accepts `{ url }` and returns
`{ status: "ok", source: { indexURL, repository, displayName } }`;
`{ status: "ok", source: { indexURL, recommendationsURL, repository, displayName } }`;
`installReview` accepts `{ manifest, expectedID?, expectedVersion?,
approvedPrograms?, hostCapabilities? }` and returns `{ status: "ok", review: { id, version,
permissions, programs, newPrograms } }`. Content problems use the same
permissions, programs, newPrograms } }`;
`recommendForWorkspace` accepts `{ platform, workspaceFiles, catalogs: [{ index, sourceKind, indexURL?, recommendations }], hostCapabilities?, installedPluginIDs?, dismissedPluginIDs? }`
and returns `{ status: "ok", recommendation: { plugins: [{ plugin, matchedMarkers, matchedExtensions, marketplaceIndexURL? }], rejected } }`
after validating each catalog, filtering to available/uninstalled/undismissed
matches, excluding `coveredBy` alternatives, deduplicating across catalogs, and
sorting marker matches ahead of extension-only matches. Content problems use the same
`rejected` shape; see the Marketplace section of
[`plugins/v1`](../../shared/plugins/contract/v1/README.md) and `fixtures/marketplace/`.

Expand Down
5 changes: 5 additions & 0 deletions rust/crates/core/src/protocol/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ pub enum PluginsCommand {
MarketplaceResolveSource,
/// Lists a package's permissions and programs before installation (`plugins.marketplace.installReview`).
MarketplaceInstallReview,
/// Matches workspace file signals against marketplace recommendation catalogs (`plugins.marketplace.recommendForWorkspace`).
MarketplaceRecommendForWorkspace,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -1260,6 +1262,9 @@ impl CoreCommand {
"plugins.marketplace.installReview" => {
Some(Self::Plugins(PluginsCommand::MarketplaceInstallReview))
}
"plugins.marketplace.recommendForWorkspace" => Some(Self::Plugins(
PluginsCommand::MarketplaceRecommendForWorkspace,
)),
"workspace.snapshot" => Some(Self::Workspace(WorkspaceCommand::Snapshot)),
"workspace.releaseIndexing" => Some(Self::Workspace(WorkspaceCommand::ReleaseIndexing)),
"workspace.configureIndexing" => {
Expand Down
5 changes: 5 additions & 0 deletions rust/crates/core/src/runtime/dispatcher/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,10 @@ pub(super) fn dispatch(
payload,
lithe_plugin_marketplace::install_review_command,
),
PluginsCommand::MarketplaceRecommendForWorkspace => plugin_response(
id,
payload,
lithe_plugin_marketplace::recommend_for_workspace_command,
),
}
}
152 changes: 151 additions & 1 deletion rust/crates/core/src/tests/marketplace_plugins.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use lithe_plugin_marketplace::{
install_review_command, resolve_source_command, validate_index_command,
install_review_command, recommend_for_workspace_command, resolve_source_command,
validate_index_command,
};
use serde_json::{json, Value};

Expand All @@ -17,6 +18,9 @@ const INDEX: &str = contract_file!("fixtures/marketplace/index.json");
const INDEX_CASES: &str = contract_file!("fixtures/marketplace/index-cases.json");
const INVALID_ENTRIES: &str = contract_file!("fixtures/marketplace/invalid-index-entries.json");
const SOURCE_URLS: &str = contract_file!("fixtures/marketplace/source-urls.json");
const RECOMMENDATIONS: &str = contract_file!("fixtures/marketplace/recommendations.json");
const RECOMMENDATION_CASES: &str =
contract_file!("fixtures/marketplace/recommendations-cases.json");
const INSTALL_REVIEWS: &str = contract_file!("fixtures/marketplace/install-reviews.json");
const PHP_FIXTURE: &str = contract_file!("fixtures/languages/language-packaged-server.plugin.json");
const GO_FIXTURE: &str = contract_file!("fixtures/languages/language-system-command.plugin.json");
Expand Down Expand Up @@ -374,3 +378,149 @@ fn publisher_bundled_versions_require_host_trust_support_before_download() {
assert_eq!(plugin["availability"]["status"], expected, "{outcome}");
}
}

#[test]
fn recommendation_fixtures_match_expected_plugins() {
let cases = json_file(RECOMMENDATION_CASES);
for case in cases["cases"].as_array().unwrap() {
let name = case["name"].as_str().unwrap();
let outcome = recommend_for_workspace_command(json!({
"platform": case["platform"],
"workspaceFiles": case["workspaceFiles"],
"catalogs": [{
"index": json_file(INDEX),
"sourceKind": case["sourceKind"],
"indexURL": "https://example.com/lithe-plugin-index.json",
"recommendations": json_file(RECOMMENDATIONS),
}],
"hostCapabilities": case["hostCapabilities"],
"installedPluginIDs": case["installedPluginIDs"],
"dismissedPluginIDs": case["dismissedPluginIDs"],
}))
.expect("recommendation payload is well formed");
assert_eq!(outcome["status"], "ok", "{name}: {outcome}");
let plugins = outcome["recommendation"]["plugins"].as_array().unwrap();
let expected = case["expectedPlugins"].as_array().unwrap();
assert_eq!(plugins.len(), expected.len(), "{name}: {outcome}");
for (actual, want) in plugins.iter().zip(expected) {
assert_eq!(actual["plugin"]["id"], want["id"], "{name}");
assert_eq!(actual["matchedMarkers"], want["matchedMarkers"], "{name}");
assert_eq!(
actual["matchedExtensions"], want["matchedExtensions"],
"{name}"
);
assert_eq!(
actual["marketplaceIndexURL"], "https://example.com/lithe-plugin-index.json",
"{name}"
);
}
}
}

#[test]
fn recommendations_deduplicate_across_catalogs_and_reject_invalid_entries() {
let outcome = recommend_for_workspace_command(json!({
"platform": "darwin-arm64",
"workspaceFiles": ["build.zig", "lib/app.ex"],
"catalogs": [
{
"index": json_file(INDEX),
"sourceKind": "thirdParty",
"indexURL": "https://first.example.com/lithe-plugin-index.json",
"recommendations": {
"schemaVersion": 0,
"recommendations": [
{ "pluginID": "io.example.zig-support", "markers": ["build.zig"] },
{ "pluginID": "io.example.zig-support", "extensions": ["zig"] },
{ "pluginID": "io.example.bad", "markers": ["../bad"] },
{ "pluginID": "io.example.empty" },
{ "pluginID": "io.example.bad-ext", "extensions": [".zig"] },
{ "pluginID": "io.example.self-cover", "markers": ["m"], "coveredBy": ["io.example.self-cover"] }
]
}
},
{
"index": json_file(INDEX),
"sourceKind": "thirdParty",
"indexURL": "https://second.example.com/lithe-plugin-index.json",
"recommendations": {
"schemaVersion": 0,
"recommendations": [
{ "pluginID": "io.example.zig-support", "markers": ["build.zig"] },
{ "pluginID": "io.example.elixir-tools", "extensions": ["ex"] }
]
}
},
{
"index": json_file(INDEX),
"sourceKind": "thirdParty",
"recommendations": { "schemaVersion": 99, "recommendations": [] }
}
],
"hostCapabilities": { "languageServers": [0], "languages": [0] },
"installedPluginIDs": [],
"dismissedPluginIDs": []
}))
.expect("recommendation payload is well formed");

assert_eq!(outcome["status"], "ok", "{outcome}");
let plugins = outcome["recommendation"]["plugins"].as_array().unwrap();
assert_eq!(plugins.len(), 2, "{outcome}");
assert_eq!(plugins[0]["plugin"]["id"], "io.example.zig-support");
assert_eq!(
plugins[0]["marketplaceIndexURL"],
"https://first.example.com/lithe-plugin-index.json"
);
assert_eq!(plugins[1]["plugin"]["id"], "io.example.elixir-tools");
assert_eq!(
plugins[1]["marketplaceIndexURL"],
"https://second.example.com/lithe-plugin-index.json"
);

let rejected = outcome["recommendation"]["rejected"].as_array().unwrap();
let codes: Vec<&str> = rejected
.iter()
.map(|entry| entry["error"]["code"].as_str().unwrap())
.collect();
assert_eq!(
codes,
vec![
"plugin.recommendations.duplicate",
"plugin.recommendations.invalid",
"plugin.recommendations.invalid",
"plugin.recommendations.invalid",
"plugin.recommendations.invalid",
"plugin.recommendations.schemaUnsupported",
]
);
}

#[test]
fn recommend_for_workspace_dispatches_through_core_command() {
use crate::execute_json;
let request = json!({
"id": "marketplace-recommend-for-workspace",
"command": "plugins.marketplace.recommendForWorkspace",
"payload": {
"platform": "darwin-arm64",
"workspaceFiles": ["build.zig"],
"catalogs": [{
"index": json_file(INDEX),
"sourceKind": "thirdParty",
"recommendations": json_file(RECOMMENDATIONS),
}],
"hostCapabilities": { "languageServers": [0], "languages": [0] },
"installedPluginIDs": [],
"dismissedPluginIDs": []
}
})
.to_string();
let reply = execute_json(&request);
let value: Value = serde_json::from_str(&reply).unwrap();
assert_eq!(value["ok"], true, "{value}");
assert_eq!(value["data"]["status"], "ok", "{value}");
assert_eq!(
value["data"]["recommendation"]["plugins"][0]["plugin"]["id"], "io.example.zig-support",
"{value}"
);
}
Loading
Loading