@@ -67,6 +67,8 @@ const PROJECT_GENERATOR_TOOL_FIXTURE: &str =
6767 contract_file ! ( "fixtures/project-generators/project-generator-tool-field.plugin.json" ) ;
6868const COMMAND_INSTALLER_FIXTURE : & str =
6969 contract_file ! ( "fixtures/command-installers/command-installer.plugin.json" ) ;
70+ const COMMAND_INSTALLER_DOWNLOAD_FIXTURE : & str =
71+ contract_file ! ( "fixtures/command-installers/command-installer-download.plugin.json" ) ;
7072const COMMAND_INSTALLER_PLANS : & str =
7173 contract_file ! ( "fixtures/command-installers/command-installer-plans.json" ) ;
7274const RUN_CONFIGURATION_TYPES_FIXTURE : & str =
@@ -106,6 +108,7 @@ fn fixture(name: &str) -> Value {
106108 "project-generator.plugin.json" => PROJECT_GENERATOR_FIXTURE ,
107109 "project-generator-tool-field.plugin.json" => PROJECT_GENERATOR_TOOL_FIXTURE ,
108110 "command-installer.plugin.json" => COMMAND_INSTALLER_FIXTURE ,
111+ "command-installer-download.plugin.json" => COMMAND_INSTALLER_DOWNLOAD_FIXTURE ,
109112 "run-configuration-types.plugin.json" => RUN_CONFIGURATION_TYPES_FIXTURE ,
110113 "before-launch-tasks.plugin.json" => BEFORE_LAUNCH_TASKS_FIXTURE ,
111114 other => panic ! ( "unknown fixture {other}" ) ,
@@ -140,6 +143,7 @@ fn contract_fixtures_and_official_plugins_validate() {
140143 EDITOR_PROVIDERS_FIXTURE ,
141144 PROJECT_GENERATOR_TOOL_FIXTURE ,
142145 COMMAND_INSTALLER_FIXTURE ,
146+ COMMAND_INSTALLER_DOWNLOAD_FIXTURE ,
143147 RUN_CONFIGURATION_TYPES_FIXTURE ,
144148 BEFORE_LAUNCH_TASKS_FIXTURE ,
145149 ] {
@@ -279,7 +283,8 @@ fn command_installer_fixtures_match_on_this_host() {
279283 for case in plans[ "cases" ] . as_array ( ) . unwrap ( ) {
280284 let name = case[ "name" ] . as_str ( ) . unwrap ( ) ;
281285 let specific = & case[ "platforms" ] [ platform] ;
282- let mut payload = json ! ( { "manifest" : fixture( "command-installer.plugin.json" ) } ) ;
286+ let plugin = case. get ( "plugin" ) . unwrap_or ( & plans[ "plugin" ] ) ;
287+ let mut payload = json ! ( { "manifest" : fixture( plugin. as_str( ) . unwrap( ) ) } ) ;
283288 for source in [ & case[ "payload" ] , & specific[ "payload" ] ] {
284289 for ( field, value) in source. as_object ( ) . into_iter ( ) . flatten ( ) {
285290 payload[ field] = value. clone ( ) ;
@@ -342,6 +347,78 @@ fn command_installers_are_reviewed_programs() {
342347 assert_ne ! ( programs( changed) , before) ;
343348}
344349
350+ /// A download installer's review entry shows every archive it may fetch, so
351+ /// a new URL or digest is a new program the user approves again; it runs no
352+ /// tool, so the entry has no tool or arguments.
353+ #[ test]
354+ fn download_installers_are_reviewed_programs ( ) {
355+ let programs = |manifest : Value | {
356+ let outcome = lithe_plugin_marketplace:: install_review_command ( json ! ( {
357+ "manifest" : manifest,
358+ } ) )
359+ . expect ( "payload is well formed" ) ;
360+ outcome[ "review" ] [ "programs" ]
361+ . as_array ( )
362+ . unwrap ( )
363+ . iter ( )
364+ . filter ( |program| program[ "kind" ] == "commandInstaller" )
365+ . cloned ( )
366+ . collect :: < Vec < _ > > ( )
367+ } ;
368+ let manifest = fixture ( "command-installer-download.plugin.json" ) ;
369+ let before = programs ( manifest. clone ( ) ) ;
370+ assert_eq ! ( before. len( ) , 1 ) ;
371+ let program = & before[ 0 ] ;
372+ assert_eq ! ( program[ "installer" ] , "sample-lldb" ) ;
373+ assert_eq ! ( program[ "timeoutSeconds" ] , 900 ) ;
374+ assert ! ( program. get( "tool" ) . is_none( ) && program. get( "arguments" ) . is_none( ) ) ;
375+ let artifacts = program[ "download" ] [ "artifacts" ] . as_array ( ) . unwrap ( ) ;
376+ assert_eq ! ( artifacts. len( ) , 3 ) ;
377+ // The review lists the digest Core checks, in lowercase.
378+ let macos = artifacts
379+ . iter ( )
380+ . find ( |artifact| artifact[ "os" ] == "macos" )
381+ . unwrap ( ) ;
382+ assert_eq ! (
383+ macos[ "sha256" ] ,
384+ "2f114a990e1b368dd1dbd33c80c0e719767af2d228391ec0df0571c957f9ac91"
385+ ) ;
386+ for ( pointer, value) in [
387+ (
388+ "/commandInstallers/0/download/artifacts/0/url" ,
389+ json ! ( "https://downloads.example.org/other.zip" ) ,
390+ ) ,
391+ (
392+ "/commandInstallers/0/download/artifacts/1/sha256" ,
393+ json ! ( "0" . repeat( 64 ) ) ,
394+ ) ,
395+ ( "/commandInstallers/0/download/version" , json ! ( "1.2.4" ) ) ,
396+ ] {
397+ let mut changed = manifest. clone ( ) ;
398+ * changed. pointer_mut ( pointer) . unwrap ( ) = value;
399+ assert_ne ! ( programs( changed) , before, "{pointer}" ) ;
400+ }
401+ }
402+
403+ /// A host that declares `commandInstallers` 0 does not know download
404+ /// installers, so it refuses a plugin that needs them before installing it.
405+ #[ test]
406+ fn download_installers_need_a_host_with_version_1 ( ) {
407+ let manifest = fixture ( "command-installer-download.plugin.json" ) ;
408+ let host = json ! ( { "commandInstallers" : [ 0 ] , "debugAdapters" : [ 0 ] , "languages" : [ 0 ] } ) ;
409+ let refused = validate_command ( json ! ( { "manifest" : manifest, "hostCapabilities" : host } ) )
410+ . expect ( "payload is well formed" ) ;
411+ assert_eq ! (
412+ refused[ "error" ] [ "code" ] , "plugin.api.unsupported" ,
413+ "{refused}"
414+ ) ;
415+ assert_eq ! ( refused[ "error" ] [ "field" ] , "requires.commandInstallers" ) ;
416+ let host = json ! ( { "commandInstallers" : [ 0 , 1 ] , "debugAdapters" : [ 0 ] , "languages" : [ 0 ] } ) ;
417+ let accepted = validate_command ( json ! ( { "manifest" : manifest, "hostCapabilities" : host } ) )
418+ . expect ( "payload is well formed" ) ;
419+ assert_eq ! ( accepted[ "status" ] , "ok" , "{accepted}" ) ;
420+ }
421+
345422/// A malformed request is a Core failure, not a rejection.
346423#[ test]
347424fn command_installer_requests_decode_strictly ( ) {
@@ -354,6 +431,20 @@ fn command_installer_requests_decode_strictly() {
354431 json!( { "manifest" : manifest, "installerID" : "sample-ls" } )
355432 )
356433 . is_err( ) ) ;
434+ // A platform names a supported pair by its two fields and nothing else.
435+ let manifest = fixture ( "command-installer-download.plugin.json" ) ;
436+ assert ! ( command_installer_plan_command( json!( {
437+ "manifest" : manifest,
438+ "installerID" : "sample-lldb" ,
439+ "target" : "managed" ,
440+ "platform" : { "os" : "macos" }
441+ } ) )
442+ . is_err( ) ) ;
443+ assert ! ( command_installer_requirements_command( json!( {
444+ "manifest" : manifest,
445+ "platform" : { "os" : "macos" , "arch" : "arm64" , "libc" : "musl" }
446+ } ) )
447+ . is_err( ) ) ;
357448}
358449
359450#[ test]
0 commit comments