From d2600b0bd9d4afca7cc04fa0eb13eeefe2947d42 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 15:39:40 -0800 Subject: [PATCH] Plug-ins: a JavaScript manifest opened by path is installed without reading it first Opening a JavaScript plug-in's .vcplugin by its path now goes straight to plugin.install {path}, which reads the manifest and its script with the plug-in loader's limits. The app's file reader no longer reads the whole file before the plug-in branch. The plugin.install params text is reworded so that every alternative starts with its parameter name. --- crates/engine/src/cmd/plugin.rs | 2 +- crates/ui-egui/src/io/open.rs | 6 ++++++ crates/ui-egui/src/tests/plugins.rs | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/plugin.rs b/crates/engine/src/cmd/plugin.rs index 6b7ce246d2..a048ac45de 100644 --- a/crates/engine/src/cmd/plugin.rs +++ b/crates/engine/src/cmd/plugin.rs @@ -1317,7 +1317,7 @@ pub fn specs() -> Vec { "Install Plug-in", [], None, - "{path: a .wasm file, or a JavaScript plug-in's .vcplugin manifest, read with the .js file its script names (desktop) | dataBase64: the module, or a JavaScript plug-in as one JSON object, its manifest with the script's text in source (+ name?: shown as its source), replace?: bool (true once the user agreed: a module with other bytes than the plug-in installed with its id, or with none installed, one whose id has settings or a cache in the plug-in store, installs only with it, takes that plug-in's place and gets its settings and cache; false: one whose id is installed is refused; left out, the same module installs again), name?: file name (with dataBase64), allowHeavy?: bool (a filter whose manifest asks for a heavy budget, budget \"heavy\" in plugin.inspect, installs only with it), grant?: [permission] (a plug-in whose manifest lists permissions, needsApproval in plugin.inspect, installs only when grant holds every one of them; the grant is recorded with the module's hash and covers only that module, so a module with other bytes needs a new grant even when it lists the same permissions; installing a module that lists no permissions forgets the grant held for its id; a refused install keeps the grant, a failed write of the module to the plug-in store leaves the grant in the store, and a stored module that is disabled or not read in Safe Mode keeps the grant for its id; with a plug-in store attached, only the grants kept there count; a request's allowHeavy and grant are refused unless the session was started with vectorcraft-cli --allow-plugin-grants: in the desktop app a person approves the install, see ui.installPlugin, and a module whose hash is already recorded, by a person's approval or by a grant accepted under that flag, needs no grant), hash?: string (the module's SHA-256 as plugin.inspect gave it: a module with other bytes is refused)} validate and install a plug-in for this session (with a plug-in store, the install waits while another window or process changes the store and writes the module and its grant before that window or process changes it again; when the store's disabled.lock can't be locked, nothing is installed) (a module whose commandAllowlist names a command no plug-in may call, such as one that reads or writes files, is refused) → its plugin.list entry, plus unknownCommands?: [id] (commandAllowlist ids no command has; a call of one fails)", + "{path: a .wasm file or a JavaScript plug-in's .vcplugin manifest (read with the .js file its script names) (desktop) | dataBase64: the module or a JavaScript plug-in as one JSON object (its manifest, with the script's text in source) (+ name?: shown as its source), replace?: bool (true once the user agreed: a module with other bytes than the plug-in installed with its id, or with none installed, one whose id has settings or a cache in the plug-in store, installs only with it, takes that plug-in's place and gets its settings and cache; false: one whose id is installed is refused; left out, the same module installs again), name?: file name (with dataBase64), allowHeavy?: bool (a filter whose manifest asks for a heavy budget, budget \"heavy\" in plugin.inspect, installs only with it), grant?: [permission] (a plug-in whose manifest lists permissions, needsApproval in plugin.inspect, installs only when grant holds every one of them; the grant is recorded with the module's hash and covers only that module, so a module with other bytes needs a new grant even when it lists the same permissions; installing a module that lists no permissions forgets the grant held for its id; a refused install keeps the grant, a failed write of the module to the plug-in store leaves the grant in the store, and a stored module that is disabled or not read in Safe Mode keeps the grant for its id; with a plug-in store attached, only the grants kept there count; a request's allowHeavy and grant are refused unless the session was started with vectorcraft-cli --allow-plugin-grants: in the desktop app a person approves the install, see ui.installPlugin, and a module whose hash is already recorded, by a person's approval or by a grant accepted under that flag, needs no grant), hash?: string (the module's SHA-256 as plugin.inspect gave it: a module with other bytes is refused)} validate and install a plug-in for this session (with a plug-in store, the install waits while another window or process changes the store and writes the module and its grant before that window or process changes it again; when the store's disabled.lock can't be locked, nothing is installed) (a module whose commandAllowlist names a command no plug-in may call, such as one that reads or writes files, is refused) → its plugin.list entry, plus unknownCommands?: [id] (commandAllowlist ids no command has; a call of one fails)", always, install ), diff --git a/crates/ui-egui/src/io/open.rs b/crates/ui-egui/src/io/open.rs index 70797c4a0a..18d1c7e598 100644 --- a/crates/ui-egui/src/io/open.rs +++ b/crates/ui-egui/src/io/open.rs @@ -575,6 +575,12 @@ fn open_file_with(app: &mut VectorcraftApp, path: &str, background: bool, p: &Va note_recent(app, path); return Ok(Value::Null); } + // A JavaScript plug-in's manifest is read by `plugin.install {path}`, with the script it names. + if opens_as(path) == Some(OpensAs::Plugin) && vectorcraft_plugins::registry::is_js_package(std::path::Path::new(path)) { + install_module(app, json!({ "path": path }))?; + note_recent(app, path); + return Ok(Value::Null); + } // A file only an importer plug-in reads is not read past the importer's input limit. check_import_size(path, false)?; let mut bytes = read(app, path)?; diff --git a/crates/ui-egui/src/tests/plugins.rs b/crates/ui-egui/src/tests/plugins.rs index 13484b098a..e2288b6bbc 100644 --- a/crates/ui-egui/src/tests/plugins.rs +++ b/crates/ui-egui/src/tests/plugins.rs @@ -743,3 +743,24 @@ fn opening_a_javascript_manifest_installs_it_with_its_script() { assert_eq!(vectorcraft_plugins::registry::get(id).and_then(|p| p.script().map(str::to_string)).as_deref(), Some("open.js")); app.run("plugin.remove", json!({"id": id})).unwrap(); } + +/// Opening a JavaScript plug-in's `.vcplugin` by its path installs it through `plugin.install +/// {path}` without the app's file reader reading the manifest first. +#[test] +fn opening_a_javascript_manifest_by_path_does_not_read_it_first() { + let mut app = app(); + app.services.read = Some(Box::new(|_: &str| Err("the whole file was read".to_string()))); + let id = "test.ui.js.open.path"; + let dir = std::env::temp_dir().join(format!("vc-ui-js-open-path-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + let manifest = json!({"id": id, "name": "Open JS by path", "kind": "filter", "runtime": "js", "script": "open.js"}).to_string(); + let path = dir.join("open.vcplugin"); + std::fs::write(&path, &manifest).unwrap(); + std::fs::write(dir.join("open.js"), "function run(input) { return input; }").unwrap(); + let r = io::open_path(&mut app, &path.display().to_string()); + std::fs::remove_dir_all(&dir).unwrap(); + assert_eq!(r, Ok(Value::Null)); + assert_eq!(vectorcraft_plugins::registry::get(id).and_then(|p| p.script().map(str::to_string)).as_deref(), Some("open.js")); + app.run("plugin.remove", json!({"id": id})).unwrap(); +}