Visual Studio Code, rebuilt in Rust
Rust
fix(cli): locate and refuse built-ins, read verifySignature, install-source
rokartur26919b0f88db
diff --git a/native/crates/app/src/cli.rs b/native/crates/app/src/cli.rsindex c1267c349f6..3ffed58a09a 100644--- a/native/crates/app/src/cli.rs+++ b/native/crates/app/src/cli.rs@@ -14,7 +14,7 @@ use crate::argv::{self, OPTIONS};use crate::product;/// `main(argv)`: the process exit code. As cli.js the arguments start after the binary and code.sh's `$CLI`.-pub fn main(process_args: Vec<String>, user_data: &Path, working_dir: &Path) -> i32 {+pub fn main(process_args: Vec<String>, user_data: &Path, working_dir: &Path, app_root: &Path) -> i32 {let args = process_args.get(2..).unwrap_or_default();let (parsed, warnings) = match argv::parse_and_validate(args) {Ok(parsed) => parsed,@@ -42,7 +42,8 @@ pub fn main(process_args: Vec<String>, user_data: &Path, working_dir: &Path) ->return 0;}if crate::cli_process::handles(&parsed) {- return match crate::cli_process::run(&parsed, user_data, working_dir) {+ let run = crate::scan_system_extensions(app_root).and_then(|system| crate::cli_process::run(&parsed, user_data, working_dir, &system, &mut std::io::stdout()));+ return match run {Ok(()) => 0,Err(error) => {eprintln!("{error:#}");@@ -252,6 +253,8 @@ fn terminal_columns() -> usize {#[cfg(test)]mod tests {+ use std::path::Path;+#[test]fn terminal_encodings_map_to_iconv_lite_names() {assert_eq!(super::to_iconv_lite_encoding(""), "utf8");@@ -281,7 +284,7 @@ mod tests {std::fs::write(extensions.join("extensions.json"), entries.to_string()).unwrap();let args = ["vsrustium", "cli.js", "--uninstall-extension", "port.sample"].map(String::from).to_vec();- assert_eq!(super::main(args, &root, &root), 0);+ assert_eq!(super::main(args, &root, &root, Path::new(env!("VSCODE_SRC"))), 0);let profile = std::fs::read_to_string(extensions.join("extensions.json")).unwrap();std::fs::remove_dir_all(&root).unwrap();diff --git a/native/crates/app/src/cli_process.rs b/native/crates/app/src/cli_process.rsindex 93acd7d7178..04e998e6c6c 100644--- a/native/crates/app/src/cli_process.rs+++ b/native/crates/app/src/cli_process.rs@@ -1,6 +1,7 @@//! cliProcessMain.ts `doRun` with extensionManagementCLI.ts: the extension commands on the profile's user extensions,-//! in the CLI process, without a window.+//! in the CLI process, without a window. `out` is the CLI's `ConsoleLogger` info output; errors go to stderr.+use std::io::Write;use std::path::{Path, PathBuf};use anyhow::bail;@@ -15,12 +16,13 @@ use crate::user_data_profile::UserDataProfilesService;const USE_ID: &str = "Make sure you use the full extension ID, including the publisher, e.g.: ms-dotnettools.csharp";-/// cli.ts `shouldSpawnCliProcess`, for the commands the port runs.+/// cli.ts `shouldSpawnCliProcess`, without `--add-mcp` and `--telemetry` (AI and telemetry are removed).pub fn handles(args: &ParsedArgs) -> bool {- ["list-extensions", "install-extension", "uninstall-extension", "update-extensions", "locate-extension"].iter().any(|id| args.flag(id))+ ["install-source", "list-extensions", "install-extension", "uninstall-extension", "update-extensions", "locate-extension"].iter().any(|id| args.flag(id))}-pub fn run(args: &ParsedArgs, user_data: &Path, working_dir: &Path) -> anyhow::Result<()> {+/// `system` is what `getInstalled` adds to the user extensions: the built-ins.+pub fn run(args: &ParsedArgs, user_data: &Path, working_dir: &Path, system: &[ScannedExtension], out: &mut dyn Write) -> anyhow::Result<()> {let extensions_folder = args.string("extensions-dir").map_or_else(|| user_data.join("extensions"), PathBuf::from);let profiles = UserDataProfilesService::load(user_data, &extensions_folder).profiles;let profile = match args.string("profile") {@@ -35,40 +37,46 @@ pub fn run(args: &ParsedArgs, user_data: &Path, working_dir: &Path) -> anyhow::RSome(Value::List(values)) => values.clone(),_ => Vec::new(),};+ // cliProcessMain.ts reads the default profile's settings whatever `--profile` is.+ let installer = Installer { user: &user, downloads: user_data.join("CachedExtensionVSIXs"), verify_signature: verify_signature(&profiles.default_profile().settings_resource) };if args.flag("list-extensions") {- return list_extensions(&user, args.flag("show-versions"), args.string("category"));+ return list_extensions(&user, args.flag("show-versions"), args.string("category"), out);}if args.flag("install-extension") {- let downloads = user_data.join("CachedExtensionVSIXs");- return install_extensions(&user, &list("install-extension"), working_dir, &downloads, args.flag("pre-release"), args.flag("force"));+ return installer.install_extensions(&list("install-extension"), working_dir, args.flag("pre-release"), args.flag("force"), out);}if args.flag("uninstall-extension") {- return uninstall_extensions(&user, &list("uninstall-extension"), working_dir);+ return uninstall_extensions(&user, system, &list("uninstall-extension"), working_dir, args.flag("force"), out);}if args.flag("update-extensions") {- return update_extensions(&user, &user_data.join("CachedExtensionVSIXs"));+ return installer.update_extensions(out);}- // shortcut: user extensions only, upstream also finds built-ins; scan them here if a tool needs that.- for extension in user.scan()? {- if list("locate-extension").contains(&extension.id.to_lowercase()) {- println!("{}", extension.location.display());- }+ if args.flag("locate-extension") {+ return locate_extensions(&user, system, &list("locate-extension"), out);}+ // `--install-source` alone: the CLI process starts and does nothing.Ok(())}-fn list_extensions(user: &UserExtensions, show_versions: bool, category: Option<&str>) -> anyhow::Result<()> {+/// extensionManagementService.ts `downloadExtension`: `extensions.verifySignature` unless it is not a boolean.+fn verify_signature(settings_file: &Path) -> bool {+ let text = std::fs::read_to_string(settings_file).unwrap_or_default();+ let settings = config::json::parse(&text, &mut Vec::new(), Default::default());+ settings.and_then(|settings| settings.get("extensions.verifySignature").and_then(serde_json::Value::as_bool)).unwrap_or(true)+}++fn list_extensions(user: &UserExtensions, show_versions: bool, category: Option<&str>, out: &mut dyn Write) -> anyhow::Result<()> {let mut extensions = user.scan()?;match category {Some("") => {- println!("Possible Categories: ");+ writeln!(out, "Possible Categories: ")?;for category in CATEGORIES {- println!("{}", category.to_lowercase());+ writeln!(out, "{}", category.to_lowercase())?;}return Ok(());}Some(category) if !CATEGORIES.iter().any(|known| known.eq_ignore_ascii_case(category)) => {- println!("Invalid category please enter a valid category. To list valid categories run --category without a category specified");+ writeln!(out, "Invalid category please enter a valid category. To list valid categories run --category without a category specified")?;return Ok(());}Some(category) => extensions.retain(|extension| extension.description["categories"].as_array().is_some_and(|categories| categories.iter().any(|known| known.as_str().is_some_and(|known| known.eq_ignore_ascii_case(category))))),@@ -77,131 +85,160 @@ fn list_extensions(user: &UserExtensions, show_versions: bool, category: Option<let mut ids: Vec<(String, &str)> = extensions.iter().map(|extension| (extension.id.to_lowercase(), version(extension))).collect();ids.sort();for (id, version) in ids {- println!("{}", if show_versions { format!("{id}@{version}") } else { id });+ writeln!(out, "{}", if show_versions { format!("{id}@{version}") } else { id })?;}Ok(())}-/// `installExtensions`: VSIX files first, then gallery ids; a failure is logged and the rest still install.-fn install_extensions(user: &UserExtensions, inputs: &[String], working_dir: &Path, downloads: &Path, pre_release: bool, force: bool) -> anyhow::Result<()> {- println!("Installing extensions...");- let installed = user.scan()?;- let mut failed = Vec::new();- for vsix in inputs.iter().filter(|input| is_vsix(input)) {- if let Err(error) = install_vsix(user, &working_dir.join(vsix), force, &installed) {- eprintln!("{error:#}");- failed.push(working_dir.join(vsix).display().to_string());+struct Installer<'a> {+ user: &'a UserExtensions,+ downloads: PathBuf,+ verify_signature: bool,+}++impl Installer<'_> {+ /// `installExtensions`: VSIX files first, then gallery ids; a failure is logged and the rest still install.+ fn install_extensions(&self, inputs: &[String], working_dir: &Path, pre_release: bool, force: bool, out: &mut dyn Write) -> anyhow::Result<()> {+ writeln!(out, "Installing extensions...")?;+ let installed = self.user.scan()?;+ let mut failed = Vec::new();+ for vsix in inputs.iter().filter(|input| is_vsix(input)) {+ if let Err(error) = self.install_vsix(&working_dir.join(vsix), force, &installed, out) {+ eprintln!("{error:#}");+ failed.push(working_dir.join(vsix).display().to_string());+ }}- }- let gallery = Gallery::open_vsx(&crate::VERSION);- for input in inputs.iter().filter(|input| !is_vsix(input)) {- if let Err(error) = install_gallery(user, &gallery, input, downloads, pre_release, force, &installed) {- eprintln!("{error:#}");- failed.push(crate::workbench::extension_management::id_and_version(input).0);+ let gallery = Gallery::open_vsx(&crate::VERSION);+ for input in inputs.iter().filter(|input| !is_vsix(input)) {+ if let Err(error) = self.install_gallery(&gallery, input, pre_release, force, &installed, out) {+ eprintln!("{error:#}");+ failed.push(crate::workbench::extension_management::id_and_version(input).0);+ }}+ if !failed.is_empty() {+ bail!("Failed Installing Extensions: {}", failed.join(", "));+ }+ Ok(())}- if !failed.is_empty() {- bail!("Failed Installing Extensions: {}", failed.join(", "));- }- Ok(())-}-/// `installVSIX` with `validateVSIX`: a newer installed version stays unless `--force`.-fn install_vsix(user: &UserExtensions, vsix: &Path, force: bool, installed: &[ScannedExtension]) -> anyhow::Result<()> {- let manifest = exthost::extension_management::vsix_manifest(vsix)?;- let id = gallery_extension_id(&manifest);- let new_version = manifest["version"].as_str().unwrap_or_default();- if let Some(existing) = installed.iter().find(|extension| extension.id.eq_ignore_ascii_case(&id))- && !force- && semver_version(version(existing)) > semver_version(new_version)- {- println!("A newer version of extension '{}' v{} is already installed. Use '--force' option to downgrade to older version.", existing.id.to_lowercase(), version(existing));- return Ok(());+ /// `installVSIX` with `validateVSIX`: a newer installed version stays unless `--force`.+ fn install_vsix(&self, vsix: &Path, force: bool, installed: &[ScannedExtension], out: &mut dyn Write) -> anyhow::Result<()> {+ let manifest = exthost::extension_management::vsix_manifest(vsix)?;+ let id = gallery_extension_id(&manifest);+ let new_version = manifest["version"].as_str().unwrap_or_default();+ if let Some(existing) = installed.iter().find(|extension| extension.id.eq_ignore_ascii_case(&id))+ && !force+ && semver_version(version(existing)) > semver_version(new_version)+ {+ writeln!(out, "A newer version of extension '{}' v{} is already installed. Use '--force' option to downgrade to older version.", existing.id.to_lowercase(), version(existing))?;+ return Ok(());+ }+ self.user.install_vsix(vsix)?;+ writeln!(out, "Extension '{}' was successfully installed.", vsix.file_name().unwrap_or_default().to_string_lossy())?;+ Ok(())}- user.install_vsix(vsix)?;- println!("Extension '{}' was successfully installed.", vsix.file_name().unwrap_or_default().to_string_lossy());- Ok(())-}-/// `installGalleryExtensions` for one `id[@version]`.-fn install_gallery(user: &UserExtensions, gallery: &Gallery, input: &str, downloads: &Path, pre_release: bool, force: bool, installed: &[ScannedExtension]) -> anyhow::Result<()> {- let (id, version_arg) = crate::workbench::extension_management::id_and_version(input);- let pre_release = pre_release || version_arg.as_deref() == Some("prerelease");- let version_arg = version_arg.filter(|version| version != "prerelease");- let existing = installed.iter().find(|extension| extension.id.eq_ignore_ascii_case(&id));- if let Some(existing) = existing {- if !force && version_arg.is_none() {- println!("Extension '{id}' v{} is already installed. Use '--force' option to update to latest version or provide '@<version>' to install a specific version, for example: '{id}@1.2.3'.", version(existing));- return Ok(());+ /// `installGalleryExtensions` for one `id[@version]`.+ fn install_gallery(&self, gallery: &Gallery, input: &str, pre_release: bool, force: bool, installed: &[ScannedExtension], out: &mut dyn Write) -> anyhow::Result<()> {+ let (id, version_arg) = crate::workbench::extension_management::id_and_version(input);+ let pre_release = pre_release || version_arg.as_deref() == Some("prerelease");+ let version_arg = version_arg.filter(|version| version != "prerelease");+ let existing = installed.iter().find(|extension| extension.id.eq_ignore_ascii_case(&id));+ if let Some(existing) = existing {+ if !force && version_arg.is_none() {+ writeln!(out, "Extension '{id}' v{} is already installed. Use '--force' option to update to latest version or provide '@<version>' to install a specific version, for example: '{id}@1.2.3'.", version(existing))?;+ return Ok(());+ }+ if let Some(wanted) = version_arg.as_deref().filter(|wanted| *wanted == version(existing)) {+ writeln!(out, "Extension '{id}@{wanted}' is already installed.")?;+ return Ok(());+ }}- if let Some(wanted) = version_arg.as_deref().filter(|wanted| *wanted == version(existing)) {- println!("Extension '{id}@{wanted}' is already installed.");- return Ok(());+ let extension = gallery.installable_extension(&id, version_arg.as_deref(), pre_release).map_err(|error| anyhow::anyhow!("{error:#}\n{USE_ID}"))?;+ let named = version_arg.as_deref().map_or_else(|| id.clone(), |version| format!("{id}@{version}"));+ if let Some(existing) = existing {+ if extension.version == version(existing) {+ writeln!(out, "Extension '{named}' is already installed.")?;+ return Ok(());+ }+ writeln!(out, "Updating the extension '{id}' to the version {}", extension.version)?;}- }- let extension = gallery.installable_extension(&id, version_arg.as_deref(), pre_release).map_err(|error| anyhow::anyhow!("{error:#}\n{USE_ID}"))?;- let named = version_arg.as_deref().map_or_else(|| id.clone(), |version| format!("{id}@{version}"));- if let Some(existing) = existing {- if extension.version == version(existing) {- println!("Extension '{named}' is already installed.");- return Ok(());+ match &version_arg {+ Some(version) => writeln!(out, "Installing extension '{id}' v{version}...")?,+ None => writeln!(out, "Installing extension '{id}'...")?,}- println!("Updating the extension '{id}' to the version {}", extension.version);- }- match &version_arg {- Some(version) => println!("Installing extension '{id}' v{version}..."),- None => println!("Installing extension '{id}'..."),+ let operation = if existing.is_some() { Operation::Update } else { Operation::Install };+ let vsix = gallery.download(&extension, operation, &self.downloads, self.verify_signature)?;+ let local = self.user.install_gallery(&vsix, &extension).map_err(|error| anyhow::anyhow!("Error while installing extension {id}: {error:#}"))?;+ writeln!(out, "Extension '{id}' v{} was successfully installed.", version(&local))?;+ Ok(())}- let operation = if existing.is_some() { Operation::Update } else { Operation::Install };- let vsix = gallery.download(&extension, operation, downloads, true)?;- let local = user.install_gallery(&vsix, &extension).map_err(|error| anyhow::anyhow!("Error while installing extension {id}: {error:#}"))?;- println!("Extension '{id}' v{} was successfully installed.", version(&local));- Ok(())-}-/// `updateExtensions`: the gallery extensions with a newer compatible version; a failed update is logged.-fn update_extensions(user: &UserExtensions, downloads: &Path) -> anyhow::Result<()> {- let installed: Vec<ScannedExtension> = user.scan()?.into_iter().filter(|extension| extension.description["uuid"].is_string()).collect();- let infos: Vec<ExtensionInfo> = installed- .iter()- .map(|extension| ExtensionInfo { id: extension.id.clone(), uuid: extension.description["uuid"].as_str().map(Into::into), version: None, pre_release: extension.description["preRelease"] == true })- .collect();- let gallery = Gallery::open_vsx(&crate::VERSION);- let mut updates = Vec::new();- for latest in gallery.get_extensions(&infos, true)? {- let old = installed.iter().find(|extension| extension.id.eq_ignore_ascii_case(&latest.id));- if old.is_some_and(|old| semver_version(&latest.version) > semver_version(version(old))) {- updates.push(latest);+ /// `updateExtensions`: the gallery extensions with a newer compatible version; a failed update is logged.+ fn update_extensions(&self, out: &mut dyn Write) -> anyhow::Result<()> {+ let installed: Vec<ScannedExtension> = self.user.scan()?.into_iter().filter(|extension| extension.description["uuid"].is_string()).collect();+ let infos: Vec<ExtensionInfo> = installed+ .iter()+ .map(|extension| ExtensionInfo { id: extension.id.clone(), uuid: extension.description["uuid"].as_str().map(Into::into), version: None, pre_release: extension.description["preRelease"] == true })+ .collect();+ let gallery = Gallery::open_vsx(&crate::VERSION);+ let mut updates = Vec::new();+ for latest in gallery.get_extensions(&infos, true)? {+ let old = installed.iter().find(|extension| extension.id.eq_ignore_ascii_case(&latest.id));+ if old.is_some_and(|old| semver_version(&latest.version) > semver_version(version(old))) {+ updates.push(latest);+ }}- }- if updates.is_empty() {- println!("No extension to update");- return Ok(());- }- println!("Updating extensions: {}", updates.iter().map(|update| update.id.as_str()).collect::<Vec<_>>().join(", "));- for update in updates {- let updated = gallery.download(&update, Operation::Update, downloads, true).and_then(|vsix| user.install_gallery(&vsix, &update));- match updated {- Ok(local) => println!("Extension '{}' v{} was successfully updated.", update.id, version(&local)),- Err(error) => eprintln!("Error while updating extension {}: {error:#}", update.id),+ if updates.is_empty() {+ writeln!(out, "No extension to update")?;+ return Ok(());}+ writeln!(out, "Updating extensions: {}", updates.iter().map(|update| update.id.as_str()).collect::<Vec<_>>().join(", "))?;+ for update in updates {+ let updated = gallery.download(&update, Operation::Update, &self.downloads, self.verify_signature).and_then(|vsix| self.user.install_gallery(&vsix, &update));+ match updated {+ Ok(local) => writeln!(out, "Extension '{}' v{} was successfully updated.", update.id, version(&local))?,+ Err(error) => eprintln!("Error while updating extension {}: {error:#}", update.id),+ }+ }+ Ok(())}- Ok(())}-/// `uninstallExtensions`: a VSIX names the extension its manifest has; the first one not installed ends the command.-fn uninstall_extensions(user: &UserExtensions, inputs: &[String], working_dir: &Path) -> anyhow::Result<()> {+/// `uninstallExtensions`: a VSIX names the extension its manifest has. A built-in, or a missing id, ends the command.+fn uninstall_extensions(user: &UserExtensions, system: &[ScannedExtension], inputs: &[String], working_dir: &Path, force: bool, out: &mut dyn Write) -> anyhow::Result<()> {for input in inputs {let id = match is_vsix(input) {true => gallery_extension_id(&exthost::extension_management::vsix_manifest(&working_dir.join(input))?),false => input.clone(),};- if !user.scan()?.iter().any(|extension| extension.id.eq_ignore_ascii_case(&id)) {+ let user_matches: Vec<ScannedExtension> = user.scan()?.into_iter().filter(|extension| extension.id.eq_ignore_ascii_case(&id)).collect();+ let is_system = system.iter().any(|extension| extension.id.eq_ignore_ascii_case(&id));+ if user_matches.is_empty() && !is_system {bail!("Extension '{id}' is not installed.\n{USE_ID}");}- println!("Uninstalling {id}...");+ if is_system {+ writeln!(out, "Extension '{id}' is a Built-in extension and cannot be uninstalled")?;+ return Ok(());+ }+ if !force && user_matches.iter().any(|extension| extension.description["isBuiltin"] == true) {+ writeln!(out, "Extension '{id}' is marked as a Built-in extension by user. Please use '--force' option to uninstall it.")?;+ return Ok(());+ }+ writeln!(out, "Uninstalling {id}...")?;user.uninstall(&id)?;- println!("Extension '{id}' was successfully uninstalled!");+ writeln!(out, "Extension '{id}' was successfully uninstalled!")?;+ }+ Ok(())+}++/// `locateExtension`: the folder of each installed extension, built-in or not, whose id is one of `ids`.+fn locate_extensions(user: &UserExtensions, system: &[ScannedExtension], ids: &[String], out: &mut dyn Write) -> anyhow::Result<()> {+ let installed: Vec<ScannedExtension> = system.iter().cloned().chain(user.scan()?).collect();+ for id in ids {+ for extension in installed.iter().filter(|extension| extension.id.to_lowercase() == *id) {+ writeln!(out, "{}", extension.location.display())?;+ }}Ok(())}@@ -214,3 +251,6 @@ fn is_vsix(input: &str) -> bool {fn version(extension: &ScannedExtension) -> &str {extension.description["version"].as_str().unwrap_or_default()}++#[cfg(test)]+mod tests;diff --git a/native/crates/app/src/cli_process/tests.rs b/native/crates/app/src/cli_process/tests.rsnew file mode 100644index 00000000000..e252fd46a4a--- /dev/null+++ b/native/crates/app/src/cli_process/tests.rs@@ -0,0 +1,73 @@+use std::path::PathBuf;++use exthost::scan::{ScannedExtension, scan_extension};++struct Fixture {+ root: PathBuf,+}++impl Fixture {+ fn new(name: &str) -> Self {+ let root = std::env::temp_dir().join(format!("cli-process-{name}-{}", std::process::id()));+ let _ = std::fs::remove_dir_all(&root);+ std::fs::create_dir_all(&root).unwrap();+ Fixture { root }+ }++ fn built_in(&self, name: &str) -> ScannedExtension {+ let folder = self.root.join("builtin").join(name);+ std::fs::create_dir_all(&folder).unwrap();+ let manifest = serde_json::json!({ "name": name, "publisher": "vscode", "version": "1.0.0", "engines": { "vscode": "^1.0.0" } });+ std::fs::write(folder.join("package.json"), manifest.to_string()).unwrap();+ scan_extension(&folder, true).unwrap()+ }++ fn run(&self, args: &[&str], system: &[ScannedExtension]) -> anyhow::Result<String> {+ let args: Vec<String> = args.iter().map(|arg| arg.to_string()).collect();+ let (parsed, _) = crate::argv::parse_and_validate(&args).unwrap();+ let mut out = Vec::new();+ super::run(&parsed, &self.root, &self.root, system, &mut out)?;+ Ok(String::from_utf8(out).unwrap())+ }+}++impl Drop for Fixture {+ fn drop(&mut self) {+ let _ = std::fs::remove_dir_all(&self.root);+ }+}++#[test]+fn locate_extension_finds_a_built_in() {+ let fixture = Fixture::new("locate");+ let git = fixture.built_in("git");+ let located = fixture.run(&["--locate-extension", "vscode.git"], &[git]).unwrap();+ assert_eq!(located, format!("{}\n", fixture.root.join("builtin/git").display()));+}++#[test]+fn uninstall_extension_refuses_a_built_in() {+ let fixture = Fixture::new("uninstall-builtin");+ let git = fixture.built_in("git");+ let output = fixture.run(&["--uninstall-extension", "vscode.git"], &[git]).unwrap();+ assert_eq!(output, "Extension 'vscode.git' is a Built-in extension and cannot be uninstalled\n");+}++#[test]+fn install_source_alone_runs_in_the_cli_process() {+ let fixture = Fixture::new("install-source");+ let args = vec!["--install-source".to_string(), "setup".to_string()];+ assert!(super::handles(&crate::argv::parse_and_validate(&args).unwrap().0));+ assert_eq!(fixture.run(&["--install-source", "setup"], &[]).unwrap(), "");+}++#[test]+fn signature_verification_follows_the_user_setting() {+ let fixture = Fixture::new("verify-signature");+ let settings = fixture.root.join("settings.json");+ assert!(super::verify_signature(&settings), "on without a settings file");+ std::fs::write(&settings, "{\n // off for a private gallery\n \"extensions.verifySignature\": false,\n}").unwrap();+ assert!(!super::verify_signature(&settings));+ std::fs::write(&settings, "{ \"extensions.verifySignature\": \"no\" }").unwrap();+ assert!(super::verify_signature(&settings), "a value that is not a boolean keeps it on");+}diff --git a/native/crates/app/src/main.rs b/native/crates/app/src/main.rsindex 62a24dd4da3..09e9c1e6287 100644--- a/native/crates/app/src/main.rs+++ b/native/crates/app/src/main.rs@@ -196,7 +196,7 @@ fn main() -> anyhow::Result<()> {encoding_guess::set_app_root(&app_root);// code.sh runs the binary with `ELECTRON_RUN_AS_NODE=1` for cli.js.if std::env::var_os("ELECTRON_RUN_AS_NODE").is_some() {- std::process::exit(cli::main(args, &user_data, &working_dir));+ std::process::exit(cli::main(args, &user_data, &working_dir, &app_root));}if args.iter().any(|arg| arg == "--version" || arg == "-v") {println!("{}", argv::build_version_message(product::get("version").as_str(), product::get("commit").as_str()));@@ -243,11 +243,9 @@ fn main() -> anyhow::Result<()> {nls::init(&resolved);exthost::language_packs::set_nls(&user_data, resolved);perf::mark("code/didGenerateNls");- let extensions_dir = std::env::var_os("VSCODE_GPUI_EXTENSIONS").map(PathBuf::from).unwrap_or_else(|| app_root.join("extensions"));perf::mark("code/willLoadExtensions");- let mut builtins = scan_builtin_extensions(&extensions_dir)?;+ let builtins = scan_system_extensions(&app_root)?;perf::mark("code/didScanExtensions");- builtins.extend(exthost::scan::scan_dev_system_extensions(&app_root)?);// Artur: user extensions live in ~/.vsrustium/extensions, the default user data dir's extensions folder.let extensions_folder = flag_value("--extensions-dir").map_or_else(|| user_data.join("extensions"), PathBuf::from);UserExtensions::new(extensions_folder.clone(), &VERSION).clean_up()?;@@ -944,6 +942,15 @@ fn apply_shell_env(force_disable: bool, user_data: &Path) -> Option<String> {}}+/// The built-in extensions: `VSCODE_GPUI_EXTENSIONS` (a checkout's set) or `<app root>/extensions`, then the dev+/// system extensions.+pub(crate) fn scan_system_extensions(app_root: &Path) -> anyhow::Result<Vec<ScannedExtension>> {+ let extensions_dir = std::env::var_os("VSCODE_GPUI_EXTENSIONS").map(PathBuf::from).unwrap_or_else(|| app_root.join("extensions"));+ let mut extensions = scan_builtin_extensions(&extensions_dir)?;+ extensions.extend(exthost::scan::scan_dev_system_extensions(app_root)?);+ Ok(extensions)+}+fn default_user_data() -> anyhow::Result<PathBuf> {let home = std::env::var_os("HOME").ok_or_else(|| anyhow::anyhow!("HOME is not set"))?;// Artur: all user data lives in ~/.vsrustium, product.json `dataFolderName`.diff --git a/port/ledger.md b/port/ledger.mdindex d27ed8e0926..d68e779f85d 100644--- a/port/ledger.md+++ b/port/ledger.md@@ -206,7 +206,7 @@ One row per upstream unit, generated by `bun port/tools/gen-ledger.ts`; mileston| platform/encryption | src/vs/platform | M10 | removed | | the port keeps secrets as Keychain items (MainThreadSecretState row, port/notes.md), so there is no safeStorage key to encrypt with || platform/endpoint | src/vs/platform | | removed | | no remote or tunnels by decision (port/notes.md); one local extension host || platform/environment | src/vs/platform | M10 | verified | | port/tools/settings-check environment: the paths and values init data carries match the reference except appName, uriScheme, machineId format and isTelemetryEnabled (product and no-telemetry decisions); argv.ts and argvHelper.ts are ported in argv.rs (`OPTIONS`, minimist parsing, `parseArgs`, `--goto` validation, help and version text), which cli.rs and `start_open_window` parse with (cargo test -p app argv:: : parses_the_command_line_as_upstream_argv, help_matches_upstream_text, goto_mode_validates_its_arguments); stdin.ts piped input decoded from the terminal encoding (resolveTerminalEncoding: cargo test -p app cli::); userDataPath.ts and the Electron main environment are replaced by main.rs's flags (`--user-data-dir`, `--extensions-dir`, `--profile`, `--profile-temp`, `--extensionDevelopmentPath`, `--extensionTestsPath`); copilotHome removed (no AI by decision) |-| platform/extensionManagement | src/vs/platform | M18 | verified | | zip64 VSIX read as yauzl does (cargo test -p exthost zip::tests::reads_zip64_records_and_extended_information). VSIX and gallery install, update, uninstall and clean-up on disk (extensionsScannerService.ts, extensionsProfileScannerService.ts layout): cargo test -p exthost extension_management, zip; PORT_GALLERY=1 port/tools/extensions-check 5 ok (an ESM VSIX and redhat.vscode-yaml from Open VSX activate without restart); the extracted package.json is written as `JSON.stringify(manifest, null, '\t')`, strings untouched (cargo test -p exthost keeps_double_spaces_in_manifest_strings; port/tools/update-check pre-release installs the rust-analyzer pre-release, whose setting descriptions have two spaces in a row). The CLI (cliProcessMain.ts, extensionManagementCLI.ts): cli_process.rs runs `--list-extensions` (`--show-versions`, `--category`), `--install-extension` (ids, `id@version`, VSIX paths, `--force`, `--pre-release`), `--uninstall-extension`, `--update-extensions` and `--locate-extension` (user extensions only, a `shortcut:`) with `--profile`, and exits without a window (cargo test -p app cli::tests::uninstall_extension_runs_in_the_cli_without_the_app; the release binary as bin/code starts it installs, updates, lists, locates and uninstalls Open VSX extensions and a VSIX) |+| platform/extensionManagement | src/vs/platform | M18 | verified | | zip64 VSIX read as yauzl does (cargo test -p exthost zip::tests::reads_zip64_records_and_extended_information). VSIX and gallery install, update, uninstall and clean-up on disk (extensionsScannerService.ts, extensionsProfileScannerService.ts layout): cargo test -p exthost extension_management, zip; PORT_GALLERY=1 port/tools/extensions-check 5 ok (an ESM VSIX and redhat.vscode-yaml from Open VSX activate without restart); the extracted package.json is written as `JSON.stringify(manifest, null, '\t')`, strings untouched (cargo test -p exthost keeps_double_spaces_in_manifest_strings; port/tools/update-check pre-release installs the rust-analyzer pre-release, whose setting descriptions have two spaces in a row). The CLI (cliProcessMain.ts, extensionManagementCLI.ts): cli_process.rs runs `--list-extensions` (`--show-versions`, `--category`), `--install-extension` (ids, `id@version`, VSIX paths, `--force`, `--pre-release`), `--uninstall-extension`, `--update-extensions`, `--locate-extension` and `--install-source` with `--profile`, and exits without a window; a built-in is located and refused uninstalling, downloads follow `extensions.verifySignature` (cargo test -p app cli::tests::uninstall_extension_runs_in_the_cli_without_the_app cli_process::; the release binary as bin/code starts it installs, updates, lists, locates and uninstalls Open VSX extensions and a VSIX) || platform/extensionRecommendations | src/vs/platform | M18 | verified | | recommendation reasons and the workspace prompt text (extensionRecommendations.ts, extensionRecommendationNotificationService.ts): cargo test -p app recommendation; ui-pair port/fixtures/extensions/ui-recommendations.json (prompt, Recommended view) against the reference || platform/extensionResourceLoader | src/vs/platform | M18 | verified | | installed extensions' README, changelog and icon read from disk, gallery ones from their asset URIs (Open VSX has no `resourceUrlTemplate`): ui-pair port/fixtures/extensions/ui-view.json `details` shows the yaml README as the reference || platform/extensions | src/vs/platform | M18 | verified | | extensionValidator.ts with the cases of extensionValidator.test.ts: cargo test -p exthost extension_validator; installs validated in PORT_GALLERY=1 port/tools/extensions-check; built-in extensions are not validated yet |