@@ -6,19 +6,21 @@ use rspm_daemon::api::DaemonApi;
66use rspm_daemon:: runtime:: TaskRuntime ;
77use tempfile:: TempDir ;
88
9+ mod common;
10+
911#[ tokio:: test]
1012async fn daemon_api_handles_start_describe_list_and_stop ( ) {
1113 let temp = TempDir :: new ( ) . expect ( "temp dir" ) ;
12- let config = ProjectConfig :: from_toml_str (
14+ let config = ProjectConfig :: from_toml_str ( & format ! (
1315 r#"
1416 [project]
1517 name = "api-test"
1618
1719 [tasks.sleeper]
18- cmd = "sh"
19- args = ["-c", "sleep 30"]
20+ {}
2021 "# ,
21- )
22+ common:: sleep_task_command( )
23+ ) )
2224 . expect ( "valid config" ) ;
2325 let runtime = TaskRuntime :: new ( config, temp. path ( ) ) . expect ( "runtime" ) ;
2426 let mut api = DaemonApi :: new ( runtime) ;
@@ -62,15 +64,16 @@ async fn daemon_api_handles_start_describe_list_and_stop() {
6264#[ tokio:: test]
6365async fn daemon_api_rejects_requests_with_missing_or_wrong_token ( ) {
6466 let temp = TempDir :: new ( ) . expect ( "temp dir" ) ;
65- let config = ProjectConfig :: from_toml_str (
67+ let config = ProjectConfig :: from_toml_str ( & format ! (
6668 r#"
6769 [project]
6870 name = "api-auth-test"
6971
7072 [tasks.echo]
71- cmd = "true"
73+ {}
7274 "# ,
73- )
75+ common:: success_task_command( )
76+ ) )
7477 . expect ( "valid config" ) ;
7578 let runtime = TaskRuntime :: new ( config, temp. path ( ) ) . expect ( "runtime" ) ;
7679 let mut api = DaemonApi :: new ( runtime) . with_auth_token ( "secret-token" ) ;
@@ -104,21 +107,21 @@ async fn daemon_api_rejects_requests_with_missing_or_wrong_token() {
104107#[ tokio:: test]
105108async fn daemon_api_starts_and_stops_all_tasks_in_dag_order ( ) {
106109 let temp = TempDir :: new ( ) . expect ( "temp dir" ) ;
107- let config = ProjectConfig :: from_toml_str (
110+ let config = ProjectConfig :: from_toml_str ( & format ! (
108111 r#"
109112 [project]
110113 name = "api-all-test"
111114
112115 [tasks.master]
113- cmd = "sh"
114- args = ["-c", "sleep 30"]
116+ {}
115117
116118 [tasks.worker]
117- cmd = "sh"
118- args = ["-c", "sleep 30"]
119+ {}
119120 depends_on = ["master"]
120121 "# ,
121- )
122+ common:: sleep_task_command( ) ,
123+ common:: sleep_task_command( )
124+ ) )
122125 . expect ( "valid config" ) ;
123126 let runtime = TaskRuntime :: new ( config, temp. path ( ) ) . expect ( "runtime" ) ;
124127 let mut api = DaemonApi :: new ( runtime) ;
@@ -147,15 +150,16 @@ async fn daemon_api_starts_and_stops_all_tasks_in_dag_order() {
147150#[ tokio:: test]
148151async fn daemon_api_returns_error_response_for_unknown_task ( ) {
149152 let temp = TempDir :: new ( ) . expect ( "temp dir" ) ;
150- let config = ProjectConfig :: from_toml_str (
153+ let config = ProjectConfig :: from_toml_str ( & format ! (
151154 r#"
152155 [project]
153156 name = "api-error-test"
154157
155158 [tasks.master]
156- cmd = "true"
159+ {}
157160 "# ,
158- )
161+ common:: success_task_command( )
162+ ) )
159163 . expect ( "valid config" ) ;
160164 let runtime = TaskRuntime :: new ( config, temp. path ( ) ) . expect ( "runtime" ) ;
161165 let mut api = DaemonApi :: new ( runtime) ;
@@ -176,15 +180,16 @@ async fn daemon_api_returns_error_response_for_unknown_task() {
176180#[ tokio:: test]
177181async fn daemon_api_reload_returns_explicit_not_configured_error ( ) {
178182 let temp = TempDir :: new ( ) . expect ( "temp dir" ) ;
179- let config = ProjectConfig :: from_toml_str (
183+ let config = ProjectConfig :: from_toml_str ( & format ! (
180184 r#"
181185 [project]
182186 name = "api-reload-test"
183187
184188 [tasks.master]
185- cmd = "true"
189+ {}
186190 "# ,
187- )
191+ common:: success_task_command( )
192+ ) )
188193 . expect ( "valid config" ) ;
189194 let runtime = TaskRuntime :: new ( config, temp. path ( ) ) . expect ( "runtime" ) ;
190195 let mut api = DaemonApi :: new ( runtime) ;
@@ -216,14 +221,14 @@ async fn daemon_api_reload_runs_configured_command() {
216221 name = "api-reload-command-test"
217222
218223 [tasks.master]
219- cmd = "sh"
220- args = ["-c", "sleep 30"]
224+ {}
221225
222226 [tasks.master.reload]
223227 mode = "command"
224- command = "touch {}"
228+ command = "{}"
225229 "# ,
226- marker. display( )
230+ common:: sleep_task_command( ) ,
231+ common:: toml_string( & common:: touch_command( & marker) )
227232 ) )
228233 . expect ( "valid config" ) ;
229234 let runtime = TaskRuntime :: new ( config, temp. path ( ) ) . expect ( "runtime" ) ;
@@ -314,35 +319,39 @@ async fn daemon_api_reload_sends_configured_signal() {
314319#[ tokio:: test]
315320async fn daemon_api_applies_new_config_and_stops_removed_tasks ( ) {
316321 let temp = TempDir :: new ( ) . expect ( "temp dir" ) ;
317- let initial = ProjectConfig :: from_toml_str (
322+ let initial = ProjectConfig :: from_toml_str ( & format ! (
318323 r#"
319324 [project]
320325 name = "apply-test"
321326
322327 [tasks.old]
323- cmd = "sh"
324- args = ["-c", "sleep 30"]
328+ {}
325329 "# ,
326- )
330+ common:: sleep_task_command( )
331+ ) )
327332 . expect ( "valid config" ) ;
328333 let runtime = TaskRuntime :: new ( initial, temp. path ( ) ) . expect ( "runtime" ) ;
329334 let mut api = DaemonApi :: new ( runtime) ;
330335
331336 api. handle ( RpcRequest :: start ( "old" ) )
332337 . await
333338 . expect ( "start old" ) ;
339+ let replacement_toml = format ! (
340+ r#"
341+ [project]
342+ name = "apply-test"
343+
344+ [tasks.new]
345+ {}
346+ "# ,
347+ common:: success_task_command( )
348+ ) ;
334349 let response = api
335350 . handle ( RpcRequest :: new (
336351 2 ,
337352 "config.apply" ,
338353 serde_json:: json!( {
339- "toml" : r#"
340- [project]
341- name = "apply-test"
342-
343- [tasks.new]
344- cmd = "true"
345- "#
354+ "toml" : replacement_toml
346355 } ) ,
347356 ) )
348357 . await
@@ -368,15 +377,16 @@ async fn daemon_api_applies_new_config_and_stops_removed_tasks() {
368377#[ tokio:: test]
369378async fn daemon_api_persists_applied_config_when_store_is_configured ( ) {
370379 let temp = TempDir :: new ( ) . expect ( "temp dir" ) ;
371- let initial = ProjectConfig :: from_toml_str (
380+ let initial = ProjectConfig :: from_toml_str ( & format ! (
372381 r#"
373382 [project]
374383 name = "persist-apply-test"
375384
376385 [tasks.old]
377- cmd = "true"
386+ {}
378387 "# ,
379- )
388+ common:: success_task_command( )
389+ ) )
380390 . expect ( "valid config" ) ;
381391 let applied_path = temp. path ( ) . join ( "state" ) . join ( "applied.toml" ) ;
382392 let runtime = TaskRuntime :: new ( initial, temp. path ( ) ) . expect ( "runtime" ) ;
@@ -408,15 +418,16 @@ async fn daemon_api_persists_applied_config_when_store_is_configured() {
408418async fn daemon_api_writes_lifecycle_events_to_jsonl_log ( ) {
409419 let temp = TempDir :: new ( ) . expect ( "temp dir" ) ;
410420 let event_path = temp. path ( ) . join ( "events" ) . join ( "project.jsonl" ) ;
411- let config = ProjectConfig :: from_toml_str (
421+ let config = ProjectConfig :: from_toml_str ( & format ! (
412422 r#"
413423 [project]
414424 name = "event-jsonl-test"
415425
416426 [tasks.echo]
417- cmd = "true"
427+ {}
418428 "# ,
419- )
429+ common:: success_task_command( )
430+ ) )
420431 . expect ( "valid config" ) ;
421432 let runtime = TaskRuntime :: new ( config, temp. path ( ) )
422433 . expect ( "runtime" )
@@ -441,16 +452,16 @@ async fn daemon_api_writes_lifecycle_events_to_jsonl_log() {
441452async fn runtime_restores_lifecycle_state_from_event_log ( ) {
442453 let temp = TempDir :: new ( ) . expect ( "temp dir" ) ;
443454 let event_path = temp. path ( ) . join ( "events" ) . join ( "project.jsonl" ) ;
444- let config = ProjectConfig :: from_toml_str (
455+ let config = ProjectConfig :: from_toml_str ( & format ! (
445456 r#"
446457 [project]
447458 name = "event-restore-test"
448459
449460 [tasks.echo]
450- cmd = "sh"
451- args = ["-c", "printf restore"]
461+ {}
452462 "# ,
453- )
463+ common:: print_task_command( "restore" )
464+ ) )
454465 . expect ( "valid config" ) ;
455466 let mut runtime = TaskRuntime :: new ( config. clone ( ) , temp. path ( ) )
456467 . expect ( "runtime" )
@@ -476,16 +487,16 @@ async fn runtime_restores_lifecycle_state_from_event_log() {
476487async fn runtime_reattaches_running_task_pid_from_event_log ( ) {
477488 let temp = TempDir :: new ( ) . expect ( "temp dir" ) ;
478489 let event_path = temp. path ( ) . join ( "events" ) . join ( "project.jsonl" ) ;
479- let config = ProjectConfig :: from_toml_str (
490+ let config = ProjectConfig :: from_toml_str ( & format ! (
480491 r#"
481492 [project]
482493 name = "reattach-test"
483494
484495 [tasks.sleeper]
485- cmd = "sh"
486- args = ["-c", "sleep 30"]
496+ {}
487497 "# ,
488- )
498+ common:: sleep_task_command( )
499+ ) )
489500 . expect ( "valid config" ) ;
490501 let mut runtime = TaskRuntime :: new ( config. clone ( ) , temp. path ( ) )
491502 . expect ( "runtime" )
@@ -508,16 +519,16 @@ async fn runtime_reattaches_running_task_pid_from_event_log() {
508519#[ tokio:: test]
509520async fn daemon_api_lists_task_lifecycle_events ( ) {
510521 let temp = TempDir :: new ( ) . expect ( "temp dir" ) ;
511- let config = ProjectConfig :: from_toml_str (
522+ let config = ProjectConfig :: from_toml_str ( & format ! (
512523 r#"
513524 [project]
514525 name = "api-event-test"
515526
516527 [tasks.echo]
517- cmd = "sh"
518- args = ["-c", "printf event"]
528+ {}
519529 "# ,
520- )
530+ common:: print_task_command( "event" )
531+ ) )
521532 . expect ( "valid config" ) ;
522533 let runtime = TaskRuntime :: new ( config, temp. path ( ) ) . expect ( "runtime" ) ;
523534 let mut api = DaemonApi :: new ( runtime) ;
@@ -548,16 +559,16 @@ async fn daemon_api_lists_task_lifecycle_events() {
548559#[ tokio:: test]
549560async fn daemon_api_returns_task_logs ( ) {
550561 let temp = TempDir :: new ( ) . expect ( "temp dir" ) ;
551- let config = ProjectConfig :: from_toml_str (
562+ let config = ProjectConfig :: from_toml_str ( & format ! (
552563 r#"
553564 [project]
554565 name = "api-log-test"
555566
556567 [tasks.echo]
557- cmd = "sh"
558- args = ["-c", "printf hello-from-log"]
568+ {}
559569 "# ,
560- )
570+ common:: print_task_command( "hello-from-log" )
571+ ) )
561572 . expect ( "valid config" ) ;
562573 let runtime = TaskRuntime :: new ( config, temp. path ( ) ) . expect ( "runtime" ) ;
563574 let mut api = DaemonApi :: new ( runtime) ;
0 commit comments