diff --git a/lib/crates/fabro-cli/src/commands/run/attach.rs b/lib/crates/fabro-cli/src/commands/run/attach.rs index 417cf80b6..3b3a74ddf 100644 --- a/lib/crates/fabro-cli/src/commands/run/attach.rs +++ b/lib/crates/fabro-cli/src/commands/run/attach.rs @@ -91,17 +91,26 @@ pub(crate) async fn attach_run_with_client( attach_live_run_with_client( client, run_id, - auto_approve, - verbose, replay_events, stream, - kill_on_detach, styles, - json_output, + AttachOptions { + auto_approve, + verbose, + kill_on_detach, + json_output, + }, ) .await } +struct AttachOptions { + auto_approve: bool, + verbose: bool, + kill_on_detach: bool, + json_output: bool, +} + fn replay_run_with_client( verbose: bool, events: Vec, @@ -124,31 +133,28 @@ fn replay_run_with_client( async fn attach_live_run_with_client( client: &server_client::ServerStoreClient, run_id: &RunId, - auto_approve: bool, - verbose: bool, existing_events: Vec, mut stream: server_client::RunAttachEventStream, - kill_on_detach: bool, styles: &'static Styles, - json_output: bool, + opts: AttachOptions, ) -> Result { let is_tty = std::io::stderr().is_terminal(); - let mut progress_ui = run_progress::ProgressUI::new(is_tty, verbose); + let mut progress_ui = run_progress::ProgressUI::new(is_tty, opts.verbose); let ctrl_c_signal = ctrl_c(); tokio::pin!(ctrl_c_signal); for event in existing_events { let line = event_payload_line(&event)?; - emit_progress_line(&mut progress_ui, &line, json_output)?; + emit_progress_line(&mut progress_ui, &line, opts.json_output)?; } if let Some(exit_code) = handle_pending_server_interview( client, run_id, - auto_approve, + opts.auto_approve, &mut progress_ui, styles, - json_output, + opts.json_output, ) .await? { @@ -158,23 +164,23 @@ async fn attach_live_run_with_client( loop { let next_event = tokio::select! { _ = &mut ctrl_c_signal => { - handle_detach_signal(client, run_id, kill_on_detach).await; - finish_progress(&mut progress_ui, json_output); + handle_detach_signal(client, run_id, opts.kill_on_detach).await; + finish_progress(&mut progress_ui, opts.json_output); return Ok(ExitCode::from(1)); } result = stream.next_event() => result?, }; let Some(event) = next_event else { - finish_progress(&mut progress_ui, json_output); + finish_progress(&mut progress_ui, opts.json_output); return Err(anyhow::anyhow!(ATTACH_PREMATURE_EOF_MESSAGE)); }; let line = event_payload_line(&event)?; - emit_progress_line(&mut progress_ui, &line, json_output)?; + emit_progress_line(&mut progress_ui, &line, opts.json_output)?; if let Some(exit_code) = event_exit_code(&event) { - finish_progress(&mut progress_ui, json_output); + finish_progress(&mut progress_ui, opts.json_output); return Ok(exit_code); } @@ -182,10 +188,10 @@ async fn attach_live_run_with_client( if let Some(exit_code) = handle_pending_server_interview( client, run_id, - auto_approve, + opts.auto_approve, &mut progress_ui, styles, - json_output, + opts.json_output, ) .await? { diff --git a/lib/crates/fabro-cli/src/commands/run/runner.rs b/lib/crates/fabro-cli/src/commands/run/runner.rs index a4718e8bb..c5b711439 100644 --- a/lib/crates/fabro-cli/src/commands/run/runner.rs +++ b/lib/crates/fabro-cli/src/commands/run/runner.rs @@ -63,8 +63,11 @@ pub(crate) async fn execute( .run .as_ref() .ok_or_else(|| anyhow!("Run {run_id} has no run record in store"))?; - let artifact_uploader = - build_artifact_uploader(run_id, client.clone_for_reuse(), artifact_upload_token); + let artifact_uploader = Some(build_artifact_uploader( + run_id, + client.clone_for_reuse(), + artifact_upload_token, + )); let interviewer = Arc::new(ControlInterviewer::new()); let cancel_token = Arc::new(AtomicBool::new(false)); tokio::spawn(read_worker_control_stream( @@ -115,17 +118,10 @@ async fn read_worker_control_stream( R: AsyncRead + Unpin, { let mut lines = BufReader::new(reader).lines(); - loop { - match lines.next_line().await { - Ok(Some(line)) => { - apply_worker_control_line(&interviewer, &cancel_token, &line).await; - } - Ok(None) | Err(_) => { - interviewer.abort_all().await; - break; - } - } + while let Ok(Some(line)) = lines.next_line().await { + apply_worker_control_line(&interviewer, &cancel_token, &line).await; } + interviewer.abort_all().await; } async fn apply_worker_control_line( @@ -156,17 +152,15 @@ fn build_artifact_uploader( run_id: RunId, client: server_client::ServerStoreClient, artifact_upload_token: Option, -) -> Option> { - let uploader: Arc = match artifact_upload_token { +) -> Arc { + match artifact_upload_token { Some(token) => Arc::new(HttpArtifactUploader { run_id, client, bearer_token: token, }), None => Arc::new(MissingArtifactUploadTokenUploader { run_id }), - }; - - Some(uploader) + } } struct HttpArtifactUploader { diff --git a/lib/crates/fabro-server/src/server.rs b/lib/crates/fabro-server/src/server.rs index 3d22c4a01..6cbf171e2 100644 --- a/lib/crates/fabro-server/src/server.rs +++ b/lib/crates/fabro-server/src/server.rs @@ -502,16 +502,11 @@ impl SlackService { return; }; - let pending = match load_pending_interview(state.as_ref(), run_id, &submission.qid).await { - Ok(pending) => pending, - Err(_) => return, - }; - if submit_pending_interview_answer(state.as_ref(), &pending, submission.answer) - .await - .is_err() - { + let Ok(pending) = load_pending_interview(state.as_ref(), run_id, &submission.qid).await + else { return; - } + }; + let _ = submit_pending_interview_answer(state.as_ref(), &pending, submission.answer).await; } } diff --git a/lib/crates/fabro-test/src/lib.rs b/lib/crates/fabro-test/src/lib.rs index 44efc1c0b..b058cc5bf 100644 --- a/lib/crates/fabro-test/src/lib.rs +++ b/lib/crates/fabro-test/src/lib.rs @@ -272,9 +272,8 @@ fn with_session_lock(root: &Path, f: impl FnOnce() -> T) -> T { ensure_parent_dir(&lock_path); match File::create(&lock_path) { Ok(f) => break f, - Err(err) if std::time::Instant::now() < deadline => { + Err(_) if std::time::Instant::now() < deadline => { std::thread::sleep(Duration::from_millis(10)); - continue; } Err(err) => panic!("failed to create {}: {err}", lock_path.display()), } diff --git a/lib/crates/fabro-types/src/interview.rs b/lib/crates/fabro-types/src/interview.rs index a32e62d3a..d3d42ddfd 100644 --- a/lib/crates/fabro-types/src/interview.rs +++ b/lib/crates/fabro-types/src/interview.rs @@ -22,7 +22,6 @@ impl InterviewQuestionType { "yes_no" => Self::YesNo, "multiple_choice" => Self::MultipleChoice, "multi_select" => Self::MultiSelect, - "freeform" => Self::Freeform, "confirmation" => Self::Confirmation, _ => Self::Freeform, }