rho-coding-agent 2.19.0

A fast Rust agent harness with a small footprint and opinionated defaults
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
use pretty_assertions::assert_eq;
use rho_providers::{
    credentials::{save_provider_api_key, MemoryCredentialStore},
    model::provider_models::ProviderModelHealth,
    provider::{self, ProviderAuthKind},
};

use super::*;
use crate::{
    antigravity_runtime::{
        executable::HarnessLocation,
        home::AntigravityAuthStatus,
        setup::{AntigravitySetup, ServerInstall},
    },
    claude_runtime::auth::ClaudeProbeSnapshot,
    cursor_runtime::auth::{
        CursorAuthError, CursorAuthStatus, CursorProbeSnapshot, CursorUserInfo,
    },
    plugins::{PluginOrigin, PluginReportEntry, PluginScope, PluginStatus},
    tools::mcp::{
        report::{ConnectedServerReport, McpLiveServerState},
        McpServerReport, McpTransportSummary,
    },
};

fn auth_check<'a>(checks: &'a [DoctorCheck], auth_mode: &str) -> &'a DoctorCheck {
    checks
        .iter()
        .find(|check| {
            check.id
                == DoctorCheckId::ProviderAuth {
                    auth_mode: auth_mode.into(),
                }
        })
        .unwrap_or_else(|| panic!("no authentication row for {auth_mode}"))
}

// Covers: authentication rows come from the injected store and env-override
// hook only: a stored key is ok, a missing key warns only for the active auth
// mode, and every other missing or optional key stays informational.
// Owner: pure unit (no process env)
#[test]
fn authentication_rows_reflect_the_injected_store() {
    let store = MemoryCredentialStore::default();
    save_provider_api_key(&store, "openai", "sk-test").unwrap();

    let checks = authentication_checks(&store, "anthropic-api-key", &|_| false);

    assert_eq!(
        auth_check(&checks, "api-key"),
        &DoctorCheck::new(
            DoctorCheckId::ProviderAuth {
                auth_mode: "api-key".into()
            },
            "OpenAI API key",
            DoctorStatus::Ok,
            "authenticated",
        )
    );
    assert_eq!(
        auth_check(&checks, "anthropic-api-key"),
        &DoctorCheck::new(
            DoctorCheckId::ProviderAuth {
                auth_mode: "anthropic-api-key".into()
            },
            "Anthropic API key",
            DoctorStatus::Warn,
            "missing",
        )
        .with_hint("run /login anthropic-api-key")
    );

    let inactive = authentication_checks(&store, "api-key", &|_| false);
    assert_eq!(
        auth_check(&inactive, "anthropic-api-key"),
        &DoctorCheck::new(
            DoctorCheckId::ProviderAuth {
                auth_mode: "anthropic-api-key".into()
            },
            "Anthropic API key",
            DoctorStatus::Info,
            "missing",
        )
    );

    let optional_host = provider::providers()
        .into_iter()
        .find(|descriptor| descriptor.has_none_auth() && !descriptor.is_keyless())
        .expect("a provider that runs with or without a key");
    let optional_mode = optional_host
        .auth_modes()
        .find(|mode| mode.auth_kind != ProviderAuthKind::None)
        .expect("keyed auth mode");
    assert_eq!(
        auth_check(&checks, optional_mode.id).status,
        DoctorStatus::Info
    );

    let from_env = authentication_checks(&store, "api-key", &|mode| mode == "api-key");
    assert_eq!(
        auth_check(&from_env, "api-key").summary,
        "authenticated via environment"
    );
}

// Covers: every Herdr socket state maps to one status.
// Owner: pure unit
#[test]
fn herdr_probe_maps_to_status() {
    for (probe, status) in [
        (HerdrProbe::NotConfigured, DoctorStatus::Info),
        (HerdrProbe::Reachable, DoctorStatus::Ok),
        (HerdrProbe::Unreachable, DoctorStatus::Fail),
        (HerdrProbe::Unknown, DoctorStatus::Warn),
    ] {
        assert_eq!(herdr_check(probe).status, status, "{probe:?}");
    }
}

// Covers: the active host fails or warns; unused configured hosts stay
// informational so a down custom endpoint cannot fail `rho doctor`.
// Owner: pure unit
#[test]
fn endpoint_health_maps_to_status() {
    let cases = [
        (
            ProviderModelHealth::ReachableWithModels { model_count: 3 },
            "ollama",
            DoctorStatus::Ok,
            "reachable, 3 models",
            None,
        ),
        (
            ProviderModelHealth::ReachableWithoutModels,
            "ollama",
            DoctorStatus::Warn,
            "no models",
            Some("the endpoint is reachable but has no installed models"),
        ),
        (
            ProviderModelHealth::Unreachable {
                error: "connection refused".into(),
            },
            "ollama",
            DoctorStatus::Fail,
            "unreachable",
            Some("connection refused"),
        ),
        (
            ProviderModelHealth::InvalidResponse {
                error: "HTTP 500".into(),
            },
            "ollama",
            DoctorStatus::Fail,
            "invalid response",
            Some("HTTP 500"),
        ),
        (
            ProviderModelHealth::Unreachable {
                error: "connection refused".into(),
            },
            "openai",
            DoctorStatus::Info,
            "unreachable",
            Some("connection refused"),
        ),
        (
            ProviderModelHealth::InvalidResponse {
                error: "HTTP 500".into(),
            },
            "openai",
            DoctorStatus::Info,
            "invalid response",
            Some("HTTP 500"),
        ),
        (
            ProviderModelHealth::ReachableWithoutModels,
            "openai",
            DoctorStatus::Info,
            "no models",
            Some("the endpoint is reachable but has no installed models"),
        ),
    ];
    for (health, active_provider, status, summary, hint) in cases {
        let check = endpoint_check("ollama", &health, active_provider);
        assert_eq!(check.label, "Ollama connection");
        assert_eq!(
            (check.status, check.summary.as_str(), check.hint.as_deref()),
            (status, summary, hint),
            "{health:?} active={active_provider}"
        );
    }
}

// Covers: Claude rows distinguish signed in, signed out, and a probe error.
// Owner: pure unit
#[test]
fn claude_rows_cover_signed_in_signed_out_and_error() {
    let signed_in = ClaudeProbeSnapshot {
        auth: Ok(serde_json::from_value(
            serde_json::json!({ "loggedIn": true, "email": "dev@example.com", "subscriptionType": "max" }),
        )
        .unwrap()),
        version: Ok("2.1.0 (Claude Code)".into()),
    };
    let rows = claude_checks(&signed_in);
    assert_eq!(
        rows,
        vec![
            DoctorCheck::new(
                DoctorCheckId::ClaudeAuth,
                CLAUDE_AUTH_LABEL,
                DoctorStatus::Ok,
                "signed in as dev@example.com (max)",
            ),
            DoctorCheck::new(
                DoctorCheckId::ClaudeBinary,
                CLAUDE_BINARY_LABEL,
                DoctorStatus::Ok,
                "2.1.0 (Claude Code)",
            ),
        ]
    );

    let signed_out = ClaudeProbeSnapshot {
        auth: Ok(serde_json::from_value(serde_json::json!({ "loggedIn": false })).unwrap()),
        version: Err("claude code: binary not found on PATH".into()),
    };
    let rows = claude_checks(&signed_out);
    assert_eq!(
        (
            rows[0].status,
            rows[0].summary.as_str(),
            rows[0].hint.as_deref()
        ),
        (
            DoctorStatus::Warn,
            "not signed in",
            Some("run /login claude-code")
        )
    );
    assert_eq!(
        (
            rows[1].status,
            rows[1].summary.as_str(),
            rows[1].hint.as_deref()
        ),
        (
            DoctorStatus::Warn,
            "unavailable",
            Some("claude code: binary not found on PATH")
        )
    );
}

// Covers: Cursor doctor row is informational for missing binary / signed-out
// Owner: pure unit
#[test]
fn cursor_row_covers_signed_in_signed_out_and_not_installed() {
    let signed_in = cursor_check(&CursorProbeSnapshot {
        auth: Ok(CursorAuthStatus {
            status: "authenticated".into(),
            is_authenticated: true,
            message: None,
            user_info: Some(CursorUserInfo {
                email: Some("dev@example.com".into()),
            }),
        }),
        version: Some("2026.08.25".into()),
        models_cached: 217,
    });
    let signed_out = cursor_check(&CursorProbeSnapshot {
        auth: Ok(CursorAuthStatus {
            status: "unauthenticated".into(),
            is_authenticated: false,
            message: Some("Not logged in".into()),
            user_info: None,
        }),
        version: Some("2026.08.25".into()),
        models_cached: 0,
    });
    let missing = cursor_check(&CursorProbeSnapshot {
        auth: Err(CursorAuthError::BinaryMissing),
        version: None,
        models_cached: 0,
    });

    let cases = [
        (
            signed_in,
            DoctorStatus::Ok,
            "2026.08.25 signed in as dev@example.com, 217 models cached",
        ),
        (
            signed_out,
            DoctorStatus::Info,
            "not signed in (run /login cursor)",
        ),
        (missing, DoctorStatus::Info, "not installed"),
    ];
    for (check, status, summary) in cases {
        assert_eq!(check.id, DoctorCheckId::Cursor);
        assert_eq!(check.label, CURSOR_LABEL);
        assert_eq!((check.status, check.summary.as_str()), (status, summary));
    }
}

// Covers: Antigravity is informational when absent or signed out, warns when
// an installed server cannot run, and an install problem outranks sign-in.
// Owner: pure unit
#[test]
fn antigravity_row_ranks_install_problems_above_sign_in() {
    let signed_in = || AntigravityAuthStatus::Configured {
        method: "oauth".into(),
    };
    let found = |harness| ServerInstall::Found {
        path: "/opt/agy/agy_acp_server.par".into(),
        harness,
    };
    let beside = || {
        found(HarnessLocation::Beside(
            "/opt/agy/localharness_external".into(),
        ))
    };
    let cases = [
        (
            ServerInstall::Missing,
            signed_in(),
            DoctorStatus::Info,
            "not installed",
        ),
        (
            found(HarnessLocation::Missing {
                expected: "/opt/agy/localharness_external".into(),
            }),
            signed_in(),
            DoctorStatus::Warn,
            "localharness_external missing",
        ),
        (beside(), signed_in(), DoctorStatus::Ok, "signed in (oauth)"),
        (
            found(HarnessLocation::Override(
                "/srv/agy/localharness_external".into(),
            )),
            signed_in(),
            DoctorStatus::Ok,
            "signed in (oauth)",
        ),
        (
            found(HarnessLocation::OverrideMissing(
                "/srv/agy/localharness_externa".into(),
            )),
            signed_in(),
            DoctorStatus::Warn,
            "localharness_external missing",
        ),
        (
            beside(),
            AntigravityAuthStatus::SignedOut {
                settings: "/home/rho/.gemini/antigravity-acp/settings.json".into(),
            },
            DoctorStatus::Info,
            "not signed in (run /login antigravity)",
        ),
        (
            beside(),
            AntigravityAuthStatus::MissingToken {
                method: "oauth".into(),
                token: "/home/rho/.gemini/antigravity-acp/acp_token.json".into(),
            },
            DoctorStatus::Info,
            "not signed in (run /login antigravity)",
        ),
        (
            beside(),
            AntigravityAuthStatus::Unreadable {
                settings: "/home/rho/.gemini/antigravity-acp/settings.json".into(),
                detail: "expected value at line 1 column 1".into(),
            },
            DoctorStatus::Warn,
            "settings unreadable",
        ),
    ];
    for (server, auth, status, summary) in cases {
        let check = antigravity_check(&AntigravitySetup { server, auth });
        assert_eq!(check.id, DoctorCheckId::Antigravity);
        assert_eq!((check.status, check.summary.as_str()), (status, summary));
    }
}

// Covers: the MCP row follows the session summary: unconfigured is neutral,
// connected servers are healthy, a failed server degrades the row.
// Owner: pure unit
#[test]
fn mcp_row_follows_session_summary() {
    let unconfigured = mcp_check(&McpSessionReport::default());
    assert_eq!(
        (unconfigured.status, unconfigured.summary.as_str()),
        (DoctorStatus::Info, "not configured")
    );

    let connected = McpSessionReport {
        mode: McpLoadMode::Native,
        servers: vec![McpServerReport::connected(ConnectedServerReport {
            identity: "filesystem".into(),
            transport: McpTransportSummary::StreamableHttp {
                url: "https://example.com/mcp".into(),
            },
            tools: Vec::new(),
            instructions: None,
            live: McpLiveServerState::default(),
            filtered_out_count: 0,
            collision_skipped_count: 0,
        })],
    };
    let check = mcp_check(&connected);
    assert_eq!(
        (check.status, check.summary.as_str(), check.hint.as_deref()),
        (
            DoctorStatus::Ok,
            "connected",
            Some("1 connected server, 0 exported tools")
        )
    );

    let degraded = McpSessionReport {
        mode: McpLoadMode::Native,
        servers: vec![McpServerReport::failed(
            "filesystem",
            McpTransportSummary::StreamableHttp {
                url: "https://example.com/mcp".into(),
            },
            "connection refused",
        )],
    };
    let check = mcp_check(&degraded);
    assert_eq!(
        (check.status, check.summary.as_str(), check.hint.as_deref()),
        (
            DoctorStatus::Warn,
            "degraded",
            Some("1 server problem, 0 connected, 0 tools; run /mcp for details")
        )
    );
}

fn plugin(name: &str, status: PluginStatus) -> PluginReportEntry {
    PluginReportEntry {
        name: name.into(),
        version: None,
        description: None,
        root: format!("/plugins/{name}"),
        scope: PluginScope::User,
        origin: PluginOrigin::Install,
        enabled: status != PluginStatus::Disabled,
        status,
        problems: Vec::new(),
        skill_count: 1,
        mcp_server_count: 0,
        skill_names: vec!["hello".into()],
        mcp_server_names: Vec::new(),
    }
}

// Covers: the plugin row is neutral with no packages, healthy when every
// package loaded cleanly, and warns on a rejected package.
// Owner: pure unit
#[test]
fn plugins_row_flags_rejected_packages() {
    let none = plugins_check(&PluginLoadReport::default());
    assert_eq!(
        (none.status, none.summary.as_str()),
        (DoctorStatus::Info, "none discovered")
    );

    let clean = plugins_check(&PluginLoadReport {
        plugins: vec![plugin("hello", PluginStatus::Loaded)],
    });
    assert_eq!(
        (clean.status, clean.summary.as_str()),
        (DoctorStatus::Ok, "1 loaded")
    );

    let rejected = plugins_check(&PluginLoadReport {
        plugins: vec![
            plugin("hello", PluginStatus::Loaded),
            plugin("broken", PluginStatus::Rejected),
        ],
    });
    assert_eq!(
        (rejected.status, rejected.summary.as_str()),
        (DoctorStatus::Warn, "1 loaded, 1 rejected")
    );
}

// Covers: path rows verify writability on disk and always carry the path.
// Owner: filesystem unit
#[test]
fn path_check_reports_writability() {
    let dir = tempfile::tempdir().unwrap();
    let config = dir.path().join("config.toml");
    let sessions = dir.path().join("sessions");

    let writable = path_check(
        DoctorCheckId::ConfigPath,
        "Configuration",
        &config,
        PathKind::File,
    );
    assert_eq!(
        (
            writable.status,
            writable.summary.as_str(),
            writable.hint.as_deref()
        ),
        (
            DoctorStatus::Ok,
            "writable",
            Some(config.display().to_string().as_str())
        )
    );

    // A file where a directory is expected is not writable as a directory.
    std::fs::write(&sessions, b"not a dir").unwrap();
    let not_dir = path_check(
        DoctorCheckId::SessionRoot,
        "Sessions",
        &sessions,
        PathKind::Directory,
    );
    assert_eq!(
        (not_dir.status, not_dir.summary.as_str()),
        (DoctorStatus::Fail, "not writable")
    );
}

// Covers: the permission screen row names the allow threshold a decision
// model allows at, its default included, and fails on one out of range,
// since every screen call would then fail; a text model's row has no
// threshold. Runs on an empty model cache so no discovered model warns.
// Owner: permission screen doctor row
#[test]
fn permission_screen_row_reports_the_allow_threshold() {
    let cases = [
        (
            "typesafe",
            "jev-latest",
            None,
            DoctorStatus::Ok,
            "typesafe/jev-latest, allows at P(allow) 95%",
        ),
        (
            "typesafe",
            "jev-latest",
            Some(80),
            DoctorStatus::Ok,
            "typesafe/jev-latest, allows at P(allow) 80%",
        ),
        (
            "typesafe",
            "jev-latest",
            Some(101),
            DoctorStatus::Fail,
            "[internal_agents.permission-classifier-screen] allow_threshold_percent must be 50 to 100, got 101",
        ),
        ("openai", "gpt-5", Some(101), DoctorStatus::Ok, "openai/gpt-5"),
    ];
    let cache = tempfile::tempdir().unwrap();
    rho_providers::model::provider_models::with_provider_models_cache_dir_for_tests(
        cache.path().into(),
        || {
            for (provider, model, allow_threshold_percent, status, summary) in cases {
                let mut entry =
                    InternalAgentModelConfig::new(provider.into(), model.into(), "keyless".into());
                entry.expect_rho_mut().allow_threshold_percent = allow_threshold_percent;

                let check = permission_screen_check(&entry);

                assert_eq!(
                    (check.status, check.summary.as_str()),
                    (status, summary),
                    "{provider}/{model} {allow_threshold_percent:?}"
                );
            }
        },
    );
}