Skip to content

Commit d0bee2b

Browse files
committed
fix(staged): use shell env snapshots for doctor
Signed-off-by: Matt Toohey <contact@matttoohey.com>
1 parent 4366c70 commit d0bee2b

3 files changed

Lines changed: 355 additions & 25 deletions

File tree

apps/staged/src-tauri/src/doctor.rs

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,41 @@
22
33
pub use doctor::types::{AuthStatus, InstallSource};
44
pub use doctor::{
5-
AgentVersionInfo, CheckStatus, DoctorCheck, DoctorReport, FixType, RunChecksOptions,
5+
AgentVersionInfo, CheckStatus, DoctorCheck, DoctorReport, ExecuteFixOptions, FixType,
6+
RunChecksOptions,
67
};
78

9+
async fn doctor_env_vars() -> Vec<(String, String)> {
10+
crate::shell_env::home_env_vars_with_extended_path(
11+
crate::session_runner::shell_env_cache().as_ref(),
12+
)
13+
.await
14+
}
15+
16+
fn run_checks_options(check_freshness: bool, env_vars: Vec<(String, String)>) -> RunChecksOptions {
17+
RunChecksOptions {
18+
check_freshness,
19+
offline: false,
20+
// Use the default public registries — Staged installs these agents
21+
// from public npm/brew/crates.io, not an internal mirror.
22+
npm_registry: None,
23+
env: None,
24+
}
25+
.with_env_snapshot(env_vars)
26+
}
27+
28+
fn execute_fix_options(
29+
command_override: Option<String>,
30+
env_vars: Vec<(String, String)>,
31+
) -> ExecuteFixOptions {
32+
ExecuteFixOptions {
33+
command_override,
34+
npm_registry: None,
35+
env: None,
36+
}
37+
.with_env_snapshot(env_vars)
38+
}
39+
840
/// Run all health checks and return the report.
941
///
1042
/// This is the cheap, no-network path: it resolves binaries and reports
@@ -13,7 +45,8 @@ pub use doctor::{
1345
/// [`run_doctor_freshness`] to fill in version/update information.
1446
#[tauri::command]
1547
pub async fn run_doctor() -> DoctorReport {
16-
doctor::run_checks().await
48+
let env_vars = doctor_env_vars().await;
49+
doctor::run_checks_with_options(run_checks_options(false, env_vars)).await
1750
}
1851

1952
/// Run all health checks with version freshness enabled.
@@ -25,15 +58,8 @@ pub async fn run_doctor() -> DoctorReport {
2558
/// each readout. Hits the network, so it must never block first paint.
2659
#[tauri::command]
2760
pub async fn run_doctor_freshness() -> DoctorReport {
28-
doctor::run_checks_with_options(RunChecksOptions {
29-
check_freshness: true,
30-
offline: false,
31-
// Use the default public registries — Staged installs these agents
32-
// from public npm/brew/crates.io, not an internal mirror.
33-
npm_registry: None,
34-
env: None,
35-
})
36-
.await
61+
let env_vars = doctor_env_vars().await;
62+
doctor::run_checks_with_options(run_checks_options(true, env_vars)).await
3763
}
3864

3965
/// Run a fix for a doctor check, identified by check ID and fix type.
@@ -42,7 +68,9 @@ pub async fn run_doctor_freshness() -> DoctorReport {
4268
/// the caller never sends a raw command string.
4369
#[tauri::command]
4470
pub async fn run_doctor_fix(check_id: String, fix_type: FixType) -> Result<(), String> {
45-
doctor::execute_fix(check_id, fix_type).await
71+
let env_vars = doctor_env_vars().await;
72+
doctor::execute_fix_with_env_options(check_id, fix_type, execute_fix_options(None, env_vars))
73+
.await
4674
}
4775

4876
/// Run a source-aware update for a single readout (main CLI or ACP bridge).
@@ -63,7 +91,8 @@ pub async fn run_doctor_update(
6391
fix_type: FixType,
6492
command: String,
6593
) -> Result<(), String> {
66-
let expected = expected_update_command(&check_id, &fix_type).await?;
94+
let env_vars = doctor_env_vars().await;
95+
let expected = expected_update_command(&check_id, &fix_type, env_vars.clone()).await?;
6796
if expected != command {
6897
return Err(format!(
6998
"Update command mismatch for {check_id}: refusing to run a command \
@@ -74,19 +103,22 @@ pub async fn run_doctor_update(
74103
// They are equal past the guard above, but executing `expected` makes the
75104
// command that runs provably the one the backend derived — no dependence on
76105
// the equality check surviving future edits.
77-
doctor::execute_fix_with_options(check_id, fix_type, Some(expected), None).await
106+
doctor::execute_fix_with_env_options(
107+
check_id,
108+
fix_type,
109+
execute_fix_options(Some(expected), env_vars),
110+
)
111+
.await
78112
}
79113

80114
/// Re-run freshness and return the authoritative update command for the given
81115
/// check + slot, or an error if no actionable update is derivable.
82-
async fn expected_update_command(check_id: &str, fix_type: &FixType) -> Result<String, String> {
83-
let report = doctor::run_checks_with_options(RunChecksOptions {
84-
check_freshness: true,
85-
offline: false,
86-
npm_registry: None,
87-
env: None,
88-
})
89-
.await;
116+
async fn expected_update_command(
117+
check_id: &str,
118+
fix_type: &FixType,
119+
env_vars: Vec<(String, String)>,
120+
) -> Result<String, String> {
121+
let report = doctor::run_checks_with_options(run_checks_options(true, env_vars)).await;
90122

91123
let check = report
92124
.checks

0 commit comments

Comments
 (0)