Skip to content

Commit d630938

Browse files
authored
feat(marketplace): add workspace plugin recommendation contract and command (#130)
* feat(marketplace): add workspace plugin recommendation contract and command * docs(plugins): link #130 in protocol changelog
1 parent 41432d4 commit d630938

11 files changed

Lines changed: 772 additions & 13 deletions

File tree

‎rust/contracts/rust-core-api.md‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,9 @@ or removing a command fails until the table changes in the same commit.
596596
| `project.checkName` | Check that a name can be a new project's directory name |
597597
| `project.extractArchive` | Extract a downloaded project archive into the staging directory, refusing unsafe entries |
598598
| `plugins.marketplace.validateIndex` | Validate a marketplace index and report each plugin's availability for one platform |
599-
| `plugins.marketplace.resolveSource` | Resolve a user-entered marketplace source to the index URL to fetch |
599+
| `plugins.marketplace.resolveSource` | Resolve a user-entered marketplace source to the index and companion recommendations URLs to fetch |
600600
| `plugins.marketplace.installReview` | List a package's permissions and programs, and those not yet approved |
601+
| `plugins.marketplace.recommendForWorkspace` | Match sampled workspace files against marketplace recommendation catalogs and indexes |
601602
| `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` |
602603
| `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 |
603604
| `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` |
@@ -5333,10 +5334,15 @@ archives and pass the parsed JSON. `validateIndex` accepts
53335334
and returns `{ status: "ok", index: { plugins, rejected } }` with per-entry
53345335
`availability`; a listed version is available only when its `pluginAPIVersion`
53355336
is one Core supports and every capability it requires is in `hostCapabilities`; `resolveSource` accepts `{ url }` and returns
5336-
`{ status: "ok", source: { indexURL, repository, displayName } }`;
5337+
`{ status: "ok", source: { indexURL, recommendationsURL, repository, displayName } }`;
53375338
`installReview` accepts `{ manifest, expectedID?, expectedVersion?,
53385339
approvedPrograms?, hostCapabilities? }` and returns `{ status: "ok", review: { id, version,
5339-
permissions, programs, newPrograms } }`. Content problems use the same
5340+
permissions, programs, newPrograms } }`;
5341+
`recommendForWorkspace` accepts `{ platform, workspaceFiles, catalogs: [{ index, sourceKind, indexURL?, recommendations }], hostCapabilities?, installedPluginIDs?, dismissedPluginIDs? }`
5342+
and returns `{ status: "ok", recommendation: { plugins: [{ plugin, matchedMarkers, matchedExtensions, marketplaceIndexURL? }], rejected } }`
5343+
after validating each catalog, filtering to available/uninstalled/undismissed
5344+
matches, excluding `coveredBy` alternatives, deduplicating across catalogs, and
5345+
sorting marker matches ahead of extension-only matches. Content problems use the same
53405346
`rejected` shape; see the Marketplace section of
53415347
[`plugins/v1`](../../shared/plugins/contract/v1/README.md) and `fixtures/marketplace/`.
53425348

‎rust/crates/core/src/protocol/command.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ pub enum PluginsCommand {
300300
MarketplaceResolveSource,
301301
/// Lists a package's permissions and programs before installation (`plugins.marketplace.installReview`).
302302
MarketplaceInstallReview,
303+
/// Matches workspace file signals against marketplace recommendation catalogs (`plugins.marketplace.recommendForWorkspace`).
304+
MarketplaceRecommendForWorkspace,
303305
}
304306

305307
#[derive(Debug, Clone)]
@@ -1263,6 +1265,9 @@ impl CoreCommand {
12631265
"plugins.marketplace.installReview" => {
12641266
Some(Self::Plugins(PluginsCommand::MarketplaceInstallReview))
12651267
}
1268+
"plugins.marketplace.recommendForWorkspace" => Some(Self::Plugins(
1269+
PluginsCommand::MarketplaceRecommendForWorkspace,
1270+
)),
12661271
"workspace.snapshot" => Some(Self::Workspace(WorkspaceCommand::Snapshot)),
12671272
"workspace.releaseIndexing" => Some(Self::Workspace(WorkspaceCommand::ReleaseIndexing)),
12681273
"workspace.configureIndexing" => {

‎rust/crates/core/src/runtime/dispatcher/plugins.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,10 @@ pub(super) fn dispatch(
176176
payload,
177177
lithe_plugin_marketplace::install_review_command,
178178
),
179+
PluginsCommand::MarketplaceRecommendForWorkspace => plugin_response(
180+
id,
181+
payload,
182+
lithe_plugin_marketplace::recommend_for_workspace_command,
183+
),
179184
}
180185
}

‎rust/crates/core/src/tests/marketplace_plugins.rs‎

Lines changed: 151 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use lithe_plugin_marketplace::{
2-
install_review_command, resolve_source_command, validate_index_command,
2+
install_review_command, recommend_for_workspace_command, resolve_source_command,
3+
validate_index_command,
34
};
45
use serde_json::{json, Value};
56

@@ -17,6 +18,9 @@ const INDEX: &str = contract_file!("fixtures/marketplace/index.json");
1718
const INDEX_CASES: &str = contract_file!("fixtures/marketplace/index-cases.json");
1819
const INVALID_ENTRIES: &str = contract_file!("fixtures/marketplace/invalid-index-entries.json");
1920
const SOURCE_URLS: &str = contract_file!("fixtures/marketplace/source-urls.json");
21+
const RECOMMENDATIONS: &str = contract_file!("fixtures/marketplace/recommendations.json");
22+
const RECOMMENDATION_CASES: &str =
23+
contract_file!("fixtures/marketplace/recommendations-cases.json");
2024
const INSTALL_REVIEWS: &str = contract_file!("fixtures/marketplace/install-reviews.json");
2125
const PHP_FIXTURE: &str = contract_file!("fixtures/languages/language-packaged-server.plugin.json");
2226
const GO_FIXTURE: &str = contract_file!("fixtures/languages/language-system-command.plugin.json");
@@ -374,3 +378,149 @@ fn publisher_bundled_versions_require_host_trust_support_before_download() {
374378
assert_eq!(plugin["availability"]["status"], expected, "{outcome}");
375379
}
376380
}
381+
382+
#[test]
383+
fn recommendation_fixtures_match_expected_plugins() {
384+
let cases = json_file(RECOMMENDATION_CASES);
385+
for case in cases["cases"].as_array().unwrap() {
386+
let name = case["name"].as_str().unwrap();
387+
let outcome = recommend_for_workspace_command(json!({
388+
"platform": case["platform"],
389+
"workspaceFiles": case["workspaceFiles"],
390+
"catalogs": [{
391+
"index": json_file(INDEX),
392+
"sourceKind": case["sourceKind"],
393+
"indexURL": "https://example.com/lithe-plugin-index.json",
394+
"recommendations": json_file(RECOMMENDATIONS),
395+
}],
396+
"hostCapabilities": case["hostCapabilities"],
397+
"installedPluginIDs": case["installedPluginIDs"],
398+
"dismissedPluginIDs": case["dismissedPluginIDs"],
399+
}))
400+
.expect("recommendation payload is well formed");
401+
assert_eq!(outcome["status"], "ok", "{name}: {outcome}");
402+
let plugins = outcome["recommendation"]["plugins"].as_array().unwrap();
403+
let expected = case["expectedPlugins"].as_array().unwrap();
404+
assert_eq!(plugins.len(), expected.len(), "{name}: {outcome}");
405+
for (actual, want) in plugins.iter().zip(expected) {
406+
assert_eq!(actual["plugin"]["id"], want["id"], "{name}");
407+
assert_eq!(actual["matchedMarkers"], want["matchedMarkers"], "{name}");
408+
assert_eq!(
409+
actual["matchedExtensions"], want["matchedExtensions"],
410+
"{name}"
411+
);
412+
assert_eq!(
413+
actual["marketplaceIndexURL"], "https://example.com/lithe-plugin-index.json",
414+
"{name}"
415+
);
416+
}
417+
}
418+
}
419+
420+
#[test]
421+
fn recommendations_deduplicate_across_catalogs_and_reject_invalid_entries() {
422+
let outcome = recommend_for_workspace_command(json!({
423+
"platform": "darwin-arm64",
424+
"workspaceFiles": ["build.zig", "lib/app.ex"],
425+
"catalogs": [
426+
{
427+
"index": json_file(INDEX),
428+
"sourceKind": "thirdParty",
429+
"indexURL": "https://first.example.com/lithe-plugin-index.json",
430+
"recommendations": {
431+
"schemaVersion": 0,
432+
"recommendations": [
433+
{ "pluginID": "io.example.zig-support", "markers": ["build.zig"] },
434+
{ "pluginID": "io.example.zig-support", "extensions": ["zig"] },
435+
{ "pluginID": "io.example.bad", "markers": ["../bad"] },
436+
{ "pluginID": "io.example.empty" },
437+
{ "pluginID": "io.example.bad-ext", "extensions": [".zig"] },
438+
{ "pluginID": "io.example.self-cover", "markers": ["m"], "coveredBy": ["io.example.self-cover"] }
439+
]
440+
}
441+
},
442+
{
443+
"index": json_file(INDEX),
444+
"sourceKind": "thirdParty",
445+
"indexURL": "https://second.example.com/lithe-plugin-index.json",
446+
"recommendations": {
447+
"schemaVersion": 0,
448+
"recommendations": [
449+
{ "pluginID": "io.example.zig-support", "markers": ["build.zig"] },
450+
{ "pluginID": "io.example.elixir-tools", "extensions": ["ex"] }
451+
]
452+
}
453+
},
454+
{
455+
"index": json_file(INDEX),
456+
"sourceKind": "thirdParty",
457+
"recommendations": { "schemaVersion": 99, "recommendations": [] }
458+
}
459+
],
460+
"hostCapabilities": { "languageServers": [0], "languages": [0] },
461+
"installedPluginIDs": [],
462+
"dismissedPluginIDs": []
463+
}))
464+
.expect("recommendation payload is well formed");
465+
466+
assert_eq!(outcome["status"], "ok", "{outcome}");
467+
let plugins = outcome["recommendation"]["plugins"].as_array().unwrap();
468+
assert_eq!(plugins.len(), 2, "{outcome}");
469+
assert_eq!(plugins[0]["plugin"]["id"], "io.example.zig-support");
470+
assert_eq!(
471+
plugins[0]["marketplaceIndexURL"],
472+
"https://first.example.com/lithe-plugin-index.json"
473+
);
474+
assert_eq!(plugins[1]["plugin"]["id"], "io.example.elixir-tools");
475+
assert_eq!(
476+
plugins[1]["marketplaceIndexURL"],
477+
"https://second.example.com/lithe-plugin-index.json"
478+
);
479+
480+
let rejected = outcome["recommendation"]["rejected"].as_array().unwrap();
481+
let codes: Vec<&str> = rejected
482+
.iter()
483+
.map(|entry| entry["error"]["code"].as_str().unwrap())
484+
.collect();
485+
assert_eq!(
486+
codes,
487+
vec![
488+
"plugin.recommendations.duplicate",
489+
"plugin.recommendations.invalid",
490+
"plugin.recommendations.invalid",
491+
"plugin.recommendations.invalid",
492+
"plugin.recommendations.invalid",
493+
"plugin.recommendations.schemaUnsupported",
494+
]
495+
);
496+
}
497+
498+
#[test]
499+
fn recommend_for_workspace_dispatches_through_core_command() {
500+
use crate::execute_json;
501+
let request = json!({
502+
"id": "marketplace-recommend-for-workspace",
503+
"command": "plugins.marketplace.recommendForWorkspace",
504+
"payload": {
505+
"platform": "darwin-arm64",
506+
"workspaceFiles": ["build.zig"],
507+
"catalogs": [{
508+
"index": json_file(INDEX),
509+
"sourceKind": "thirdParty",
510+
"recommendations": json_file(RECOMMENDATIONS),
511+
}],
512+
"hostCapabilities": { "languageServers": [0], "languages": [0] },
513+
"installedPluginIDs": [],
514+
"dismissedPluginIDs": []
515+
}
516+
})
517+
.to_string();
518+
let reply = execute_json(&request);
519+
let value: Value = serde_json::from_str(&reply).unwrap();
520+
assert_eq!(value["ok"], true, "{value}");
521+
assert_eq!(value["data"]["status"], "ok", "{value}");
522+
assert_eq!(
523+
value["data"]["recommendation"]["plugins"][0]["plugin"]["id"], "io.example.zig-support",
524+
"{value}"
525+
);
526+
}

0 commit comments

Comments
 (0)