Skip to content

Commit 9dea6aa

Browse files
authored
feat(plugins): add managedRuntimes 1 mirror URLs for runtime artifacts (#108)
1 parent 555eb95 commit 9dea6aa

5 files changed

Lines changed: 144 additions & 5 deletions

File tree

‎rust/crates/plugin-manifest/src/managed_runtimes.rs‎

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use url::Url;
1010

1111
const MAX_DEPENDENCIES: usize = 16;
1212
const MAX_ARTIFACTS: usize = 6;
13+
const MAX_MIRRORS: usize = 8;
1314
const DEFAULT_RESOLVE_TIMEOUT: u64 = 30_000;
1415
const MAX_RESOLVE_TIMEOUT: u64 = 120_000;
1516
const MAX_PATH_BYTES: usize = 4096;
@@ -55,6 +56,9 @@ struct RuntimeArtifact {
5556
os: String,
5657
arch: String,
5758
url: String,
59+
/// Optional fallback HTTPS URLs serving the exact same pinned SHA-256 archive.
60+
#[serde(default, skip_serializing_if = "Vec::is_empty")]
61+
mirrors: Vec<String>,
5862
sha256: String,
5963
/// zip or tar.gz; the host never infers a format from a URL suffix.
6064
archive: String,
@@ -159,6 +163,11 @@ impl DeclarativePluginManifest {
159163
"A managed runtime set contains from 1 to 16 dependencies.",
160164
));
161165
}
166+
let managed_runtimes_version = self
167+
.requires
168+
.get(capabilities::MANAGED_RUNTIMES)
169+
.copied()
170+
.unwrap_or(0);
162171
let tool_ids: BTreeSet<&str> = self
163172
.tool_definitions
164173
.iter()
@@ -230,6 +239,49 @@ impl DeclarativePluginManifest {
230239
"Runtime archive URLs use HTTPS without credentials or fragments.",
231240
));
232241
}
242+
if !artifact.mirrors.is_empty() {
243+
if managed_runtimes_version < 1 {
244+
return Err(invalid(
245+
"requires.managedRuntimes",
246+
"Managed runtime mirror URLs require requires.managedRuntimes >= 1.",
247+
));
248+
}
249+
if artifact.mirrors.len() > MAX_MIRRORS {
250+
return Err(invalid(
251+
format!("{field}.mirrors"),
252+
"A runtime artifact declares at most 8 mirror URLs.",
253+
));
254+
}
255+
let mut seen_urls = BTreeSet::new();
256+
seen_urls.insert(artifact.url.as_str());
257+
for (mirror_index, mirror) in artifact.mirrors.iter().enumerate() {
258+
let mirror_field = format!("{field}.mirrors[{mirror_index}]");
259+
let parsed = Url::parse(mirror).map_err(|_| {
260+
invalid(
261+
mirror_field.clone(),
262+
"A runtime mirror needs an HTTPS URL.",
263+
)
264+
})?;
265+
if !bounded_text(mirror, 4096)
266+
|| parsed.scheme() != "https"
267+
|| parsed.host_str().is_none()
268+
|| !parsed.username().is_empty()
269+
|| parsed.password().is_some()
270+
|| parsed.fragment().is_some()
271+
{
272+
return Err(invalid(
273+
mirror_field,
274+
"Runtime mirror URLs use HTTPS without credentials or fragments.",
275+
));
276+
}
277+
if !seen_urls.insert(mirror.as_str()) {
278+
return Err(invalid(
279+
mirror_field,
280+
"Runtime mirror URLs must be unique and differ from the primary URL.",
281+
));
282+
}
283+
}
284+
}
233285
if artifact.sha256.len() != 64
234286
|| !artifact.sha256.bytes().all(|byte| byte.is_ascii_hexdigit())
235287
{
@@ -319,9 +371,12 @@ impl ManagedRuntimes {
319371
selected["tool"] = json!(tool);
320372
}
321373
// Serialize this explicitly constructed object, not input field order.
322-
// Package versions are absent, so a plugin-only update reuses bytes.
374+
// Package versions and mirrors are absent, so mirror additions reuse bytes.
323375
let identity = Sha256::digest(selected.to_string().as_bytes());
324376
selected["cacheKey"] = json!(format!("{identity:x}"));
377+
if !artifact.mirrors.is_empty() {
378+
selected["mirrors"] = json!(artifact.mirrors);
379+
}
325380
dependencies.push(selected);
326381
}
327382
Ok(json!({"resolve": self.resolve, "dependencies": dependencies}))

‎rust/crates/plugin-manifest/src/managed_runtimes/tests.rs‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,78 @@ fn review_programs_include_every_origin_digest_and_resolver() {
249249
programs
250250
);
251251
}
252+
253+
#[test]
254+
fn mirrors_require_version_1_preserve_cache_key_and_reject_invalid_urls() {
255+
let base_manifest = fixture()["manifest"].clone();
256+
let base_plan = plan(base_manifest.clone());
257+
assert_eq!(base_plan["status"], "ok", "{base_plan}");
258+
let base_cache_key = base_plan["plan"]["dependencies"][0]["cacheKey"]
259+
.as_str()
260+
.unwrap()
261+
.to_string();
262+
263+
// Declaring mirrors with managedRuntimes: 0 is rejected.
264+
let mut v0_with_mirrors = base_manifest.clone();
265+
v0_with_mirrors["managedRuntimes"]["dependencies"][0]["artifacts"][0]["mirrors"] =
266+
json!(["https://mirror.example.org/engine.tar.gz"]);
267+
assert_eq!(plan(v0_with_mirrors)["status"], "rejected");
268+
269+
// With managedRuntimes: 1, mirrors appear in the plan without changing cacheKey.
270+
let mut v1 = base_manifest.clone();
271+
v1["requires"]["managedRuntimes"] = json!(1);
272+
let linux_index = v1["managedRuntimes"]["dependencies"][0]["artifacts"]
273+
.as_array()
274+
.unwrap()
275+
.iter()
276+
.position(|artifact| artifact["os"] == "linux")
277+
.unwrap();
278+
v1["managedRuntimes"]["dependencies"][0]["artifacts"][linux_index]["mirrors"] = json!([
279+
"https://mirror1.example.org/engine.tar.gz",
280+
"https://mirror2.example.org/engine.tar.gz"
281+
]);
282+
let v1_plan = plan(v1.clone());
283+
assert_eq!(v1_plan["status"], "ok", "{v1_plan}");
284+
assert_eq!(
285+
v1_plan["plan"]["dependencies"][0]["cacheKey"].as_str(),
286+
Some(base_cache_key.as_str())
287+
);
288+
assert_eq!(
289+
v1_plan["plan"]["dependencies"][0]["mirrors"],
290+
json!([
291+
"https://mirror1.example.org/engine.tar.gz",
292+
"https://mirror2.example.org/engine.tar.gz"
293+
])
294+
);
295+
296+
// Non-HTTPS, credentials, duplicates, or >8 mirrors are rejected.
297+
let primary = v1["managedRuntimes"]["dependencies"][0]["artifacts"][linux_index]["url"]
298+
.as_str()
299+
.unwrap()
300+
.to_string();
301+
for bad in [
302+
json!(["http://mirror.example.org/engine.tar.gz"]),
303+
json!(["https://user:pass@mirror.example.org/engine.tar.gz"]),
304+
json!(["https://mirror.example.org/engine.tar.gz#frag"]),
305+
json!([primary]),
306+
json!([
307+
"https://mirror.example.org/engine.tar.gz",
308+
"https://mirror.example.org/engine.tar.gz"
309+
]),
310+
json!([
311+
"https://m1.example.org/e",
312+
"https://m2.example.org/e",
313+
"https://m3.example.org/e",
314+
"https://m4.example.org/e",
315+
"https://m5.example.org/e",
316+
"https://m6.example.org/e",
317+
"https://m7.example.org/e",
318+
"https://m8.example.org/e",
319+
"https://m9.example.org/e"
320+
]),
321+
] {
322+
let mut invalid_manifest = v1.clone();
323+
invalid_manifest["managedRuntimes"]["dependencies"][0]["artifacts"][linux_index]["mirrors"] = bad;
324+
assert_eq!(plan(invalid_manifest)["status"], "rejected");
325+
}
326+
}

‎rust/crates/plugin-model/src/capabilities.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub const SUPPORTED_CAPABILITIES: &[(&str, &[u32])] = &[
135135
(KEYMAP_IMPORT_PROVIDERS, &[0]),
136136
(LANGUAGE_SERVERS, &[0]),
137137
(LANGUAGES, &[0]),
138-
(MANAGED_RUNTIMES, &[0]),
138+
(MANAGED_RUNTIMES, &[0, 1]),
139139
(OUTPUT_LINK_MATCHERS, &[0]),
140140
(PACKAGE_TRUST, &[0]),
141141
(PLUGIN_FUNCTIONS, &[0]),

‎shared/plugins/contract/v1/plugin-manifest.schema.json‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"executionProviders": { "enum": [0] },
4242
"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] },
4343
"languages": { "description": "Required exactly when languages is non-empty. Covers languages[].grammar, a TextMate grammar, and languages[].configuration.", "enum": [0] },
44-
"managedRuntimes": { "description": "Required exactly when managedRuntimes is present: approved pinned runtime archives, plugin-owned qualification and host-owned installation outside versioned packages.", "enum": [0] },
44+
"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] },
4545
"outputLinkMatchers": { "description": "Required exactly when outputLinkMatchers is non-empty.", "enum": [0] },
4646
"packageTrust": { "description": "Required exactly when vendor.bundledSignatureRequirement is present.", "enum": [0] },
4747
"projectGenerators": { "description": "Entries of the New Project window: fields, requirements, and steps, with tool fields that pick tool installations.", "enum": [0] },
@@ -1030,6 +1030,13 @@
10301030
"os": { "enum": ["macos", "windows", "linux"] },
10311031
"arch": { "enum": ["arm64", "x86_64"] },
10321032
"url": { "type": "string", "minLength": 1, "maxLength": 4096, "pattern": "^https://", "description": "HTTPS without credentials or fragments; semantic URL validation is performed by Core." },
1033+
"mirrors": {
1034+
"type": "array",
1035+
"maxItems": 8,
1036+
"uniqueItems": true,
1037+
"description": "Optional fallback HTTPS URLs serving the exact same pinned SHA-256 archive. Requires managedRuntimes 1.",
1038+
"items": { "type": "string", "minLength": 1, "maxLength": 4096, "pattern": "^https://" }
1039+
},
10331040
"sha256": { "type": "string", "pattern": "^[A-Fa-f0-9]{64}$" },
10341041
"archive": { "enum": ["zip", "tar.gz"] },
10351042
"stripPrefix": { "$ref": "#/$defs/managedRuntimePath", "default": "" },

‎shared/plugins/reference/capabilities-and-versions.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ Core 列以本仓库 `main` 上的 Core 源码为准([`capabilities.rs`](https
5656
| `beforeLaunchTasks` `0` | `buildSystems[].beforeLaunchTasks`:插件声明的启动前任务(如“运行 Go 命令”),列在运行配置“启动前”的“添加新任务”菜单里;宿主按声明的字段画任务表单,Core 用 `runConfig.checkBeforeLaunchTask` 校验值、`build.beforeLaunchTaskPlan` 在拥有这个步骤列表的配置的工作目录里展开命令行 | ✅ | ✅ | [Before-launch tasks](../contract/v1/README.md#before-launch-tasks) |
5757
| `vcsProviders` `0` | [`vcsProviders[]`](../contract/v1/README.md#vcs-providers);说 `litheVcs` | ✅ | ✅¹ | [版本控制提供者](domains/vcs.md) |
5858
| `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) |
59-
| `managedRuntimes` `0` | 固定归档、插件后端资格检查、跨版本缓存与安装前准备;权限 `runtimes.install` | ✅ | 配套宿主接入后声明 | [Managed runtimes](../contract/v1/README.md#managed-runtimes) |
59+
| `managedRuntimes` `0` | 固定归档、插件后端资格检查、跨版本缓存与安装前准备;权限 `runtimes.install` | ✅ | ✅ | [Managed runtimes](../contract/v1/README.md#managed-runtimes) |
60+
| `managedRuntimes` `1` | 在 `0` 基础上允许每个平台归档声明最多 8 个 HTTPS `mirrors` 镜像地址,不改变 `cacheKey` | ✅ | 配套宿主接入后声明 | [Managed runtimes](../contract/v1/README.md#managed-runtimes) |
6061
| `commandInstallers` `0` | [`commandInstallers[]`](../contract/v1/README.md#command-installers):用插件已依赖的工具安装 `systemCommand` 启动缺的裸命令,装到 Lithe 管理的目录(`managed`)或工具默认位置(`toolDefault`),用户确认后才运行 | ✅ | ✅ | [工具链](domains/toolchains.md#安装缺失的命令) |
6162
| `outputLinkMatchers` `0` | [`outputLinkMatchers[]`](../contract/v1/README.md#output-link-matchers):插件声明的匹配规则让 Run 和测试控制台的输出出现链接;Core 负责匹配,`resolve` 函数在点击时才调用 | ✅ | ✅ | [语言](domains/languages.md) |
6263
| `projectGenerators` `0` | [`projectGenerators[]`](../contract/v1/README.md#project-generators):新建项目窗口里的条目,含 [`tool` 字段](../contract/v1/README.md#tool-fields) | ✅ | ✅ | [项目生成器](domains/project-generators.md) |
@@ -169,7 +170,8 @@ Each row is one capability. `requires` lists **exactly** the capabilities a mani
169170
| `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) |
170171
| `vcsProviders` `0` | [`vcsProviders[]`](../contract/v1/README.md#vcs-providers); they speak `litheVcs` | ✅ | ✅¹ | [VCS providers](domains/vcs.md) |
171172
| `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) |
172-
| `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) |
173+
| `managedRuntimes` `0` | Pinned archives, plugin-owned qualification, version-independent cache and install preflight; permission `runtimes.install` | ✅ | ✅ | [Managed runtimes](../contract/v1/README.md#managed-runtimes) |
174+
| `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) |
173175
| `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) |
174176
| `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) |
175177
| `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) |

0 commit comments

Comments
 (0)