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
57 changes: 56 additions & 1 deletion rust/crates/plugin-manifest/src/managed_runtimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use url::Url;

const MAX_DEPENDENCIES: usize = 16;
const MAX_ARTIFACTS: usize = 6;
const MAX_MIRRORS: usize = 8;
const DEFAULT_RESOLVE_TIMEOUT: u64 = 30_000;
const MAX_RESOLVE_TIMEOUT: u64 = 120_000;
const MAX_PATH_BYTES: usize = 4096;
Expand Down Expand Up @@ -55,6 +56,9 @@ struct RuntimeArtifact {
os: String,
arch: String,
url: String,
/// Optional fallback HTTPS URLs serving the exact same pinned SHA-256 archive.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
mirrors: Vec<String>,
sha256: String,
/// zip or tar.gz; the host never infers a format from a URL suffix.
archive: String,
Expand Down Expand Up @@ -159,6 +163,11 @@ impl DeclarativePluginManifest {
"A managed runtime set contains from 1 to 16 dependencies.",
));
}
let managed_runtimes_version = self
.requires
.get(capabilities::MANAGED_RUNTIMES)
.copied()
.unwrap_or(0);
let tool_ids: BTreeSet<&str> = self
.tool_definitions
.iter()
Expand Down Expand Up @@ -230,6 +239,49 @@ impl DeclarativePluginManifest {
"Runtime archive URLs use HTTPS without credentials or fragments.",
));
}
if !artifact.mirrors.is_empty() {
if managed_runtimes_version < 1 {
return Err(invalid(
"requires.managedRuntimes",
"Managed runtime mirror URLs require requires.managedRuntimes >= 1.",
));
}
if artifact.mirrors.len() > MAX_MIRRORS {
return Err(invalid(
format!("{field}.mirrors"),
"A runtime artifact declares at most 8 mirror URLs.",
));
}
let mut seen_urls = BTreeSet::new();
seen_urls.insert(artifact.url.as_str());
for (mirror_index, mirror) in artifact.mirrors.iter().enumerate() {
let mirror_field = format!("{field}.mirrors[{mirror_index}]");
let parsed = Url::parse(mirror).map_err(|_| {
invalid(
mirror_field.clone(),
"A runtime mirror needs an HTTPS URL.",
)
})?;
if !bounded_text(mirror, 4096)
|| parsed.scheme() != "https"
|| parsed.host_str().is_none()
|| !parsed.username().is_empty()
|| parsed.password().is_some()
|| parsed.fragment().is_some()
{
return Err(invalid(
mirror_field,
"Runtime mirror URLs use HTTPS without credentials or fragments.",
));
}
if !seen_urls.insert(mirror.as_str()) {
return Err(invalid(
mirror_field,
"Runtime mirror URLs must be unique and differ from the primary URL.",
));
}
}
}
if artifact.sha256.len() != 64
|| !artifact.sha256.bytes().all(|byte| byte.is_ascii_hexdigit())
{
Expand Down Expand Up @@ -319,9 +371,12 @@ impl ManagedRuntimes {
selected["tool"] = json!(tool);
}
// Serialize this explicitly constructed object, not input field order.
// Package versions are absent, so a plugin-only update reuses bytes.
// Package versions and mirrors are absent, so mirror additions reuse bytes.
let identity = Sha256::digest(selected.to_string().as_bytes());
selected["cacheKey"] = json!(format!("{identity:x}"));
if !artifact.mirrors.is_empty() {
selected["mirrors"] = json!(artifact.mirrors);
}
dependencies.push(selected);
}
Ok(json!({"resolve": self.resolve, "dependencies": dependencies}))
Expand Down
75 changes: 75 additions & 0 deletions rust/crates/plugin-manifest/src/managed_runtimes/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,78 @@ fn review_programs_include_every_origin_digest_and_resolver() {
programs
);
}

#[test]
fn mirrors_require_version_1_preserve_cache_key_and_reject_invalid_urls() {
let base_manifest = fixture()["manifest"].clone();
let base_plan = plan(base_manifest.clone());
assert_eq!(base_plan["status"], "ok", "{base_plan}");
let base_cache_key = base_plan["plan"]["dependencies"][0]["cacheKey"]
.as_str()
.unwrap()
.to_string();

// Declaring mirrors with managedRuntimes: 0 is rejected.
let mut v0_with_mirrors = base_manifest.clone();
v0_with_mirrors["managedRuntimes"]["dependencies"][0]["artifacts"][0]["mirrors"] =
json!(["https://mirror.example.org/engine.tar.gz"]);
assert_eq!(plan(v0_with_mirrors)["status"], "rejected");

// With managedRuntimes: 1, mirrors appear in the plan without changing cacheKey.
let mut v1 = base_manifest.clone();
v1["requires"]["managedRuntimes"] = json!(1);
let linux_index = v1["managedRuntimes"]["dependencies"][0]["artifacts"]
.as_array()
.unwrap()
.iter()
.position(|artifact| artifact["os"] == "linux")
.unwrap();
v1["managedRuntimes"]["dependencies"][0]["artifacts"][linux_index]["mirrors"] = json!([
"https://mirror1.example.org/engine.tar.gz",
"https://mirror2.example.org/engine.tar.gz"
]);
let v1_plan = plan(v1.clone());
assert_eq!(v1_plan["status"], "ok", "{v1_plan}");
assert_eq!(
v1_plan["plan"]["dependencies"][0]["cacheKey"].as_str(),
Some(base_cache_key.as_str())
);
assert_eq!(
v1_plan["plan"]["dependencies"][0]["mirrors"],
json!([
"https://mirror1.example.org/engine.tar.gz",
"https://mirror2.example.org/engine.tar.gz"
])
);

// Non-HTTPS, credentials, duplicates, or >8 mirrors are rejected.
let primary = v1["managedRuntimes"]["dependencies"][0]["artifacts"][linux_index]["url"]
.as_str()
.unwrap()
.to_string();
for bad in [
json!(["http://mirror.example.org/engine.tar.gz"]),
json!(["https://user:pass@mirror.example.org/engine.tar.gz"]),
json!(["https://mirror.example.org/engine.tar.gz#frag"]),
json!([primary]),
json!([
"https://mirror.example.org/engine.tar.gz",
"https://mirror.example.org/engine.tar.gz"
]),
json!([
"https://m1.example.org/e",
"https://m2.example.org/e",
"https://m3.example.org/e",
"https://m4.example.org/e",
"https://m5.example.org/e",
"https://m6.example.org/e",
"https://m7.example.org/e",
"https://m8.example.org/e",
"https://m9.example.org/e"
]),
] {
let mut invalid_manifest = v1.clone();
invalid_manifest["managedRuntimes"]["dependencies"][0]["artifacts"][linux_index]["mirrors"] = bad;
assert_eq!(plan(invalid_manifest)["status"], "rejected");
}
}
2 changes: 1 addition & 1 deletion rust/crates/plugin-model/src/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub const SUPPORTED_CAPABILITIES: &[(&str, &[u32])] = &[
(KEYMAP_IMPORT_PROVIDERS, &[0]),
(LANGUAGE_SERVERS, &[0]),
(LANGUAGES, &[0]),
(MANAGED_RUNTIMES, &[0]),
(MANAGED_RUNTIMES, &[0, 1]),
(OUTPUT_LINK_MATCHERS, &[0]),
(PACKAGE_TRUST, &[0]),
(PLUGIN_FUNCTIONS, &[0]),
Expand Down
9 changes: 8 additions & 1 deletion shared/plugins/contract/v1/plugin-manifest.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"executionProviders": { "enum": [0] },
"languageServers": { "description": "Required exactly when languageServers is non-empty. Covers languageServers[].workspaceConfiguration and the session fields requestMethods, commands, serializedCommands, forwardNotifications, state, and remote.", "enum": [0] },
"languages": { "description": "Required exactly when languages is non-empty. Covers languages[].grammar, a TextMate grammar, and languages[].configuration.", "enum": [0] },
"managedRuntimes": { "description": "Required exactly when managedRuntimes is present: approved pinned runtime archives, plugin-owned qualification and host-owned installation outside versioned packages.", "enum": [0] },
"managedRuntimes": { "description": "Required exactly when managedRuntimes is present: approved pinned runtime archives, plugin-owned qualification and host-owned installation outside versioned packages. Version 1 adds optional artifact mirror URLs.", "enum": [0, 1] },
"outputLinkMatchers": { "description": "Required exactly when outputLinkMatchers is non-empty.", "enum": [0] },
"packageTrust": { "description": "Required exactly when vendor.bundledSignatureRequirement is present.", "enum": [0] },
"projectGenerators": { "description": "Entries of the New Project window: fields, requirements, and steps, with tool fields that pick tool installations.", "enum": [0] },
Expand Down Expand Up @@ -1030,6 +1030,13 @@
"os": { "enum": ["macos", "windows", "linux"] },
"arch": { "enum": ["arm64", "x86_64"] },
"url": { "type": "string", "minLength": 1, "maxLength": 4096, "pattern": "^https://", "description": "HTTPS without credentials or fragments; semantic URL validation is performed by Core." },
"mirrors": {
"type": "array",
"maxItems": 8,
"uniqueItems": true,
"description": "Optional fallback HTTPS URLs serving the exact same pinned SHA-256 archive. Requires managedRuntimes 1.",
"items": { "type": "string", "minLength": 1, "maxLength": 4096, "pattern": "^https://" }
},
"sha256": { "type": "string", "pattern": "^[A-Fa-f0-9]{64}$" },
"archive": { "enum": ["zip", "tar.gz"] },
"stripPrefix": { "$ref": "#/$defs/managedRuntimePath", "default": "" },
Expand Down
6 changes: 4 additions & 2 deletions shared/plugins/reference/capabilities-and-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Core 列以本仓库 `main` 上的 Core 源码为准([`capabilities.rs`](https
| `beforeLaunchTasks` `0` | `buildSystems[].beforeLaunchTasks`:插件声明的启动前任务(如“运行 Go 命令”),列在运行配置“启动前”的“添加新任务”菜单里;宿主按声明的字段画任务表单,Core 用 `runConfig.checkBeforeLaunchTask` 校验值、`build.beforeLaunchTaskPlan` 在拥有这个步骤列表的配置的工作目录里展开命令行 | ✅ | ✅ | [Before-launch tasks](../contract/v1/README.md#before-launch-tasks) |
| `vcsProviders` `0` | [`vcsProviders[]`](../contract/v1/README.md#vcs-providers);说 `litheVcs` | ✅ | ✅¹ | [版本控制提供者](domains/vcs.md) |
| `debugAdapters` `0` | [`debugAdapters[]`](../contract/v1/README.md#debug-adapters):独立适配器、语言服务器内的适配器、[远程附加](../contract/v1/README.md#remote-attach)、参数和环境变量、[`features` 与 `defaults`](../contract/v1/README.md#adapter-features-and-defaults) | ✅ | ✅ | [调试适配器](domains/debug-adapters.md) |
| `managedRuntimes` `0` | 固定归档、插件后端资格检查、跨版本缓存与安装前准备;权限 `runtimes.install` | ✅ | 配套宿主接入后声明 | [Managed runtimes](../contract/v1/README.md#managed-runtimes) |
| `managedRuntimes` `0` | 固定归档、插件后端资格检查、跨版本缓存与安装前准备;权限 `runtimes.install` | ✅ | ✅ | [Managed runtimes](../contract/v1/README.md#managed-runtimes) |
| `managedRuntimes` `1` | 在 `0` 基础上允许每个平台归档声明最多 8 个 HTTPS `mirrors` 镜像地址,不改变 `cacheKey` | ✅ | 配套宿主接入后声明 | [Managed runtimes](../contract/v1/README.md#managed-runtimes) |
| `commandInstallers` `0` | [`commandInstallers[]`](../contract/v1/README.md#command-installers):用插件已依赖的工具安装 `systemCommand` 启动缺的裸命令,装到 Lithe 管理的目录(`managed`)或工具默认位置(`toolDefault`),用户确认后才运行 | ✅ | ✅ | [工具链](domains/toolchains.md#安装缺失的命令) |
| `outputLinkMatchers` `0` | [`outputLinkMatchers[]`](../contract/v1/README.md#output-link-matchers):插件声明的匹配规则让 Run 和测试控制台的输出出现链接;Core 负责匹配,`resolve` 函数在点击时才调用 | ✅ | ✅ | [语言](domains/languages.md) |
| `projectGenerators` `0` | [`projectGenerators[]`](../contract/v1/README.md#project-generators):新建项目窗口里的条目,含 [`tool` 字段](../contract/v1/README.md#tool-fields) | ✅ | ✅ | [项目生成器](domains/project-generators.md) |
Expand Down Expand Up @@ -169,7 +170,8 @@ Each row is one capability. `requires` lists **exactly** the capabilities a mani
| `beforeLaunchTasks` `0` | `buildSystems[].beforeLaunchTasks`: before-launch tasks a plugin declares (such as Run Go Command), listed in the Add New Task menu of a run configuration's Before Launch list; the host draws the task's form from the declared fields, Core checks the values with `runConfig.checkBeforeLaunchTask` and expands the command line with `build.beforeLaunchTaskPlan` in the working directory of the configuration whose list names the step | ✅ | ✅ | [Before-launch tasks](../contract/v1/README.md#before-launch-tasks) |
| `vcsProviders` `0` | [`vcsProviders[]`](../contract/v1/README.md#vcs-providers); they speak `litheVcs` | ✅ | ✅¹ | [VCS providers](domains/vcs.md) |
| `debugAdapters` `0` | [`debugAdapters[]`](../contract/v1/README.md#debug-adapters): standalone adapters, adapters inside a language server, [remote attach](../contract/v1/README.md#remote-attach), arguments and environment, [`features` and `defaults`](../contract/v1/README.md#adapter-features-and-defaults) | ✅ | ✅ | [Debug adapters](domains/debug-adapters.md) |
| `managedRuntimes` `0` | Pinned archives, plugin-owned qualification, version-independent cache and install preflight; permission `runtimes.install` | ✅ | Declared with companion host integration | [Managed runtimes](../contract/v1/README.md#managed-runtimes) |
| `managedRuntimes` `0` | Pinned archives, plugin-owned qualification, version-independent cache and install preflight; permission `runtimes.install` | ✅ | ✅ | [Managed runtimes](../contract/v1/README.md#managed-runtimes) |
| `managedRuntimes` `1` | Extends `0` with up to 8 optional HTTPS `mirrors` URLs per platform artifact without changing `cacheKey` | ✅ | Declared with companion host integration | [Managed runtimes](../contract/v1/README.md#managed-runtimes) |
| `commandInstallers` `0` | [`commandInstallers[]`](../contract/v1/README.md#command-installers): install a bare command a `systemCommand` launch lacks with a tool the plugin already requires, into a directory Lithe manages (`managed`) or the tool's default location (`toolDefault`), only after the user confirms | ✅ | ✅ | [Toolchains](domains/toolchains.md#installing-missing-commands) |
| `outputLinkMatchers` `0` | [`outputLinkMatchers[]`](../contract/v1/README.md#output-link-matchers): plugin-declared patterns that turn Run and Test console output into links; Core does the matching, and the `resolve` function is called only on click | ✅ | ✅ | [Languages](domains/languages.md) |
| `projectGenerators` `0` | [`projectGenerators[]`](../contract/v1/README.md#project-generators): entries of the New Project window, including [`tool` fields](../contract/v1/README.md#tool-fields) | ✅ | ✅ | [Project generators](domains/project-generators.md) |
Expand Down
Loading