@@ -159,6 +159,116 @@ fn remote_build_detects_host_models_normalizes_diagnostics_and_invalidates_sync(
159159 assert_eq ! ( std:: fs:: read_dir( placeholder) . unwrap( ) . count( ) , 0 ) ;
160160}
161161
162+ /// Run configurations of a remote workspace are read from the host, checked
163+ /// against the host's files, and planned with host paths, so the client starts
164+ /// the process on the host without translating the plan.
165+ #[ test]
166+ fn remote_run_configurations_resolve_and_plan_against_the_host ( ) {
167+ let host = HostFixture :: new ( ) ;
168+ let root = host. root . join ( "host" ) ;
169+ let placeholder = host. root . join ( "placeholder" ) ;
170+ std:: fs:: create_dir_all ( root. join ( "scripts" ) ) . unwrap ( ) ;
171+ std:: fs:: create_dir_all ( root. join ( "web" ) ) . unwrap ( ) ;
172+ std:: fs:: write (
173+ root. join ( "scripts/build.sh" ) ,
174+ "#!/bin/bash -e\n echo built\n " ,
175+ )
176+ . unwrap ( ) ;
177+ super :: support:: write_run_document (
178+ & root,
179+ ".lithe/run/configurations.yaml" ,
180+ & json ! ( { "version" : 2 , "configurations" : [
181+ { "id" : "user:build" , "name" : "build" , "provider" : "process.shell" ,
182+ "confidence" : "declared" , "cwd" : "web" ,
183+ "extensions" : { "process" : { "script" : "scripts/build.sh" } } } ,
184+ { "id" : "user:inline" , "name" : "inline" , "provider" : "process.shell" ,
185+ "confidence" : "declared" , "extensions" : { "process" : { "text" : "echo hi\n " } } } ,
186+ { "id" : "user:missing" , "name" : "missing" , "provider" : "process.shell" ,
187+ "confidence" : "declared" , "extensions" : { "process" : { "script" : "scripts/gone.sh" } } } ,
188+ ] } ) ,
189+ ) ;
190+
191+ let resolved = host. request ( "runConfig.resolve" , json ! ( { "root" : placeholder} ) ) ;
192+ let availability = |id : & str | {
193+ resolved[ "configurations" ]
194+ . as_array ( )
195+ . unwrap ( )
196+ . iter ( )
197+ . find ( |entry| entry[ "id" ] == id)
198+ . unwrap_or_else ( || panic ! ( "{id} missing from {resolved}" ) ) [ "availability" ]
199+ . clone ( )
200+ } ;
201+ // The documents exist only on the host; a runnable entry carries no
202+ // availability.
203+ assert ! ( availability( "user:build" ) . is_null( ) , "{resolved}" ) ;
204+
205+ // The script and its `#!` line are read on the host; every path in the
206+ // plan is the host's.
207+ let plan = host. request (
208+ "runConfig.createLaunchPlan" ,
209+ json ! ( { "root" : placeholder, "configurationId" : "user:build" } ) ,
210+ ) ;
211+ let script = root. join ( "scripts/build.sh" ) ;
212+ assert_eq ! ( plan[ "executable" ] , json!( { "path" : "/bin/bash" } ) , "{plan}" ) ;
213+ assert_eq ! ( plan[ "arguments" ] , json!( [ "-e" , script] ) , "{plan}" ) ;
214+ assert_eq ! ( plan[ "workingDirectory" ] , "web" , "{plan}" ) ;
215+
216+ // An inline script goes where the client asked, on the host.
217+ let inline = host. request (
218+ "runConfig.createLaunchPlan" ,
219+ json ! ( { "root" : placeholder, "configurationId" : "user:inline" ,
220+ "inlineScriptBase" : "/tmp/lithe-run-x/script" } ) ,
221+ ) ;
222+ assert_eq ! (
223+ inline[ "inlineScript" ] [ "path" ] , "/tmp/lithe-run-x/script.sh" ,
224+ "{inline}"
225+ ) ;
226+ assert_eq ! ( inline[ "inlineScript" ] [ "content" ] , "echo hi\n " , "{inline}" ) ;
227+
228+ // A script missing on the host is refused before anything starts.
229+ let response: Value = serde_json:: from_str ( & crate :: execute_json (
230+ & json ! ( {
231+ "id" : test_support:: unique_id( ) , "command" : "runConfig.createLaunchPlan" ,
232+ "remoteWorkspace" : { "sessionId" : host. id, "localRoot" : placeholder, "remoteRoot" : root} ,
233+ "payload" : { "root" : placeholder, "configurationId" : "user:missing" } ,
234+ } )
235+ . to_string ( ) ,
236+ ) )
237+ . unwrap ( ) ;
238+ assert_eq ! ( response[ "ok" ] , false , "{response}" ) ;
239+ assert_eq ! (
240+ response[ "error" ] [ "message" ] , "Script file was not found" ,
241+ "{response}"
242+ ) ;
243+
244+ // The editor checks a working directory against the host's folders and
245+ // saves through changes the client applies on the host.
246+ let form = host. request (
247+ "runConfig.editorForm" ,
248+ json ! ( { "root" : placeholder, "configurationId" : "user:build" } ) ,
249+ ) ;
250+ let mut values = form[ "values" ] . as_object ( ) . unwrap ( ) . clone ( ) ;
251+ values. insert ( "workingDirectory" . into ( ) , json ! ( "nowhere" ) ) ;
252+ let refused = host. request (
253+ "runConfig.saveConfiguration" ,
254+ json ! ( { "root" : placeholder, "provider" : "process.shell" ,
255+ "configurationId" : "user:build" , "values" : values} ) ,
256+ ) ;
257+ assert_eq ! (
258+ refused[ "errors" ] ,
259+ json!( [ { "field" : "workingDirectory" , "code" : "notFound" } ] ) ,
260+ "{refused}"
261+ ) ;
262+ values. insert ( "workingDirectory" . into ( ) , json ! ( "scripts" ) ) ;
263+ let saved = host. request (
264+ "runConfig.saveConfiguration" ,
265+ json ! ( { "root" : placeholder, "provider" : "process.shell" ,
266+ "configurationId" : "user:build" , "values" : values} ) ,
267+ ) ;
268+ assert_eq ! ( saved[ "status" ] , "saved" , "{saved}" ) ;
269+ assert_eq ! ( std:: fs:: read_dir( placeholder) . unwrap( ) . count( ) , 0 ) ;
270+ }
271+
162272/// A remote root opened through a host symbolic link resolves outside the
163273/// local placeholder; the empty-root boundary must ask the host, not the
164274/// unmaterialized local projection, before scanning.
0 commit comments