rho-coding-agent 2.30.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
use super::*;

#[test]
fn config_normalizes_provider_profiles_for_top_level_and_internal_models() {
    let dir = tempfile::tempdir().unwrap();
    let path = dir.path().join("config.toml");
    std::fs::write(
        &path,
        "provider = \"openrouter-oauth\"\nmodel = \"anthropic/claude-sonnet-4\"\nauth = \"openrouter-api-key\"\n[internal_agents.session-title]\nprovider = \"openrouter\"\nmodel = \"anthropic/claude-sonnet-4\"\nauth = \"openrouter-oauth\"\n",
    )
    .unwrap();

    let config = Config::load_with_store(
        path,
        &rho_providers::credentials::MemoryCredentialStore::default(),
    )
    .unwrap();

    assert_eq!(
        (config.provider.as_str(), config.auth.as_str()),
        ("openrouter", "openrouter-oauth")
    );
    let title = config.internal_agent_model("session-title").unwrap();
    assert_eq!(
        (
            title.expect_rho().provider.as_str(),
            title.expect_rho().auth.as_str()
        ),
        ("openrouter", "openrouter-oauth")
    );
}

#[test]
fn config_canonicalizes_legacy_poolside_wire_model_ids() {
    let dir = tempfile::tempdir().unwrap();
    let path = dir.path().join("config.toml");
    std::fs::write(
        &path,
        "provider = \"poolside\"\nmodel = \"poolside/laguna-m.1\"\nauth = \"poolside-api-key\"\n[internal_agents.session-title]\nprovider = \"poolside\"\nmodel = \"poolside/poolside/laguna-m.1\"\nauth = \"poolside-api-key\"\n",
    )
    .unwrap();

    let config = Config::load_with_store(
        path,
        &rho_providers::credentials::MemoryCredentialStore::default(),
    )
    .unwrap();

    assert_eq!(config.provider, "poolside");
    assert_eq!(config.model, "laguna-m.1");
    let title = config.internal_agent_model("session-title").unwrap();
    assert_eq!(title.expect_rho().provider, "poolside");
    assert_eq!(title.expect_rho().model, "laguna-m.1");
}

// Covers: first-run config must not invent a default Ollama endpoint
// Owner: provider config
#[test]
fn default_config_omits_ollama_endpoint_until_login_or_explicit_table() {
    let dir = tempfile::tempdir().unwrap();
    let path = dir.path().join("config.toml");
    Config::default().write_settings(path.clone()).unwrap();
    let saved = std::fs::read_to_string(&path).unwrap();
    assert!(
        !saved.contains("[providers.ollama]"),
        "first-run config must not write a default Ollama endpoint: {saved}"
    );

    let mut config = Config::default();
    config
        .providers
        .set_endpoint("ollama", rho_providers::provider::OLLAMA_API_BASE)
        .unwrap();
    config.write_settings(path.clone()).unwrap();
    let saved = std::fs::read_to_string(&path).unwrap();
    assert!(
        saved.contains("[providers.ollama]"),
        "explicit Ollama login must persist the endpoint: {saved}"
    );
    assert!(
        saved.contains(&format!(
            "base_url = \"{}\"",
            rho_providers::provider::OLLAMA_API_BASE
        )),
        "saved Ollama endpoint must keep the submitted URL: {saved}"
    );
}

// Covers: config load must use one validated endpoint write path
// Owner: provider config
#[test]
fn set_endpoint_updates_supported_providers_and_rejects_others() {
    let mut providers = ProviderConfigs::default();

    providers
        .set_endpoint("ollama", "http://10.0.0.5:11434/v1")
        .unwrap();
    assert_eq!(
        providers
            .ollama
            .as_ref()
            .expect("ollama endpoint")
            .base_url
            .as_str(),
        "http://10.0.0.5:11434/v1"
    );

    providers
        .set_endpoint("composer", "http://127.0.0.1:8787/v1")
        .unwrap();
    assert_eq!(
        providers.custom["composer"].base_url.as_str(),
        "http://127.0.0.1:8787/v1"
    );

    let unsupported = providers
        .set_endpoint("openai", "https://api.openai.com/v1")
        .unwrap_err();
    assert!(
        format!("{unsupported:#}").contains("conflicts with a built-in provider"),
        "{unsupported:#}"
    );

    let invalid = providers
        .set_endpoint("ollama", "file:///tmp/ollama")
        .unwrap_err();
    assert!(
        format!("{invalid:#}").contains("providers.ollama.base_url"),
        "{invalid:#}"
    );
}

// Covers: built-in hosts resolve their default API base with no config override
// Owner: provider config
#[test]
fn built_in_providers_resolve_default_endpoint_without_config() {
    let config = Config::default();

    for (provider, expected) in [
        (
            "qwen-token-plan",
            rho_providers::provider::QWEN_TOKEN_PLAN_API_BASE,
        ),
        ("meta", rho_providers::provider::META_API_BASE),
        ("minimax", rho_providers::provider::MINIMAX_API_BASE),
    ] {
        assert_eq!(
            config
                .resolved_provider_endpoint(provider)
                .unwrap()
                .as_str(),
            expected,
            "{provider}"
        );
    }
}

// Covers: user-defined OpenAI-compatible hosts keep their configured base URL
// Owner: provider config
#[test]
fn custom_openai_compatible_resolves_configured_endpoint() {
    let dir = tempfile::tempdir().unwrap();
    let path = dir.path().join("config.toml");
    std::fs::write(
        &path,
        "provider = \"composer\"\nmodel = \"composer-2.5\"\n[providers.custom.composer]\nbase_url = \"http://127.0.0.1:8787/v1\"\n",
    )
    .unwrap();

    let config = Config::load_with_store(
        path,
        &rho_providers::credentials::MemoryCredentialStore::default(),
    )
    .unwrap();

    assert_eq!(config.provider, "composer");
    assert_eq!(config.auth, "none");
    assert_eq!(
        config
            .resolved_provider_endpoint("composer")
            .unwrap()
            .as_str(),
        "http://127.0.0.1:8787/v1"
    );
}

// Covers: a stored custom key must promote `auth = "none"` so restart sends it
// Owner: provider config
#[test]
fn custom_openai_compatible_promotes_stored_key_over_keyless() {
    use rho_providers::credentials::{CredentialStore, MemoryCredentialStore};

    let _lock = rho_providers::provider::custom_provider_registry_test_lock();
    rho_providers::provider::reset_custom_openai_compatible_providers_for_tests();
    let dir = tempfile::tempdir().unwrap();
    let path = dir.path().join("config.toml");
    std::fs::write(
        &path,
        "provider = \"composer\"\nmodel = \"composer-2.5\"\nauth = \"none\"\n[providers.custom.composer]\nbase_url = \"http://127.0.0.1:8787/v1\"\n",
    )
    .unwrap();

    let store = MemoryCredentialStore::default();
    store
        .set_secret("provider:composer:api-key", "composer-secret")
        .unwrap();
    let mut config = Config::load_with_store(path, &store).unwrap();
    assert_eq!(config.auth, "none");
    assert!(config.promote_stored_custom_auth(&store));
    assert_eq!(config.auth, "composer-api-key");
}

// Covers: startup must not write keyed custom auth back to `none`
// Owner: provider config
#[test]
fn custom_openai_compatible_keeps_keyed_auth_when_store_is_empty() {
    use rho_providers::credentials::MemoryCredentialStore;

    let _lock = rho_providers::provider::custom_provider_registry_test_lock();
    rho_providers::provider::reset_custom_openai_compatible_providers_for_tests();
    let dir = tempfile::tempdir().unwrap();
    let path = dir.path().join("config.toml");
    std::fs::write(
        &path,
        "provider = \"composer\"\nmodel = \"composer-2.5\"\nauth = \"composer-api-key\"\n[providers.custom.composer]\nbase_url = \"http://127.0.0.1:8787/v1\"\n",
    )
    .unwrap();

    let store = MemoryCredentialStore::default();
    let mut config = Config::load_with_store(path, &store).unwrap();
    assert_eq!(config.auth, "composer-api-key");
    assert!(!config.promote_stored_custom_auth(&store));
    assert_eq!(config.auth, "composer-api-key");
}

// Covers: endpoint updates change only their declared fields, so current and
// future provider options cannot be erased by an incomplete copy list.
// Owner: provider config
#[test]
fn endpoint_updates_preserve_unrelated_custom_options() {
    let mut providers = ProviderConfigs::default();
    let original = ProviderEndpointConfig {
        base_url: Url::parse("http://127.0.0.1:8317/v1").unwrap(),
        catalog: Some("llmgateway".into()),
        catalog_lookup: rho_providers::provider::CatalogLookupMode::Slug,
        api: rho_providers::provider::OpenAiCompatibleApi::Responses,
        edit_tool: Some(rho_tools::EditFormat::ApplyPatch),
        prompt_cache_ttl: Some(std::time::Duration::from_secs(3600)),
        request_compression: Some(rho_providers::providers::RequestCompression::Zstd),
    };
    providers
        .custom
        .insert("cliproxyapi".into(), original.clone());

    providers
        .set_endpoint("cliproxyapi", "http://127.0.0.1:8318/v1")
        .unwrap();
    let mut expected = original;
    expected.base_url = Url::parse("http://127.0.0.1:8318/v1").unwrap();
    assert_eq!(providers.custom["cliproxyapi"], expected);

    providers
        .set_custom_endpoint(
            "cliproxyapi",
            "http://127.0.0.1:8319/v1",
            rho_providers::provider::OpenAiCompatibleApi::ChatCompletions,
        )
        .unwrap();
    expected.base_url = Url::parse("http://127.0.0.1:8319/v1").unwrap();
    expected.api = rho_providers::provider::OpenAiCompatibleApi::ChatCompletions;
    assert_eq!(providers.custom["cliproxyapi"], expected);
}

// Covers: a custom provider can choose Auto's edit format without overriding a
// globally pinned edit preference, and the choice survives config persistence.
// Owner: provider config
#[test]
fn custom_provider_edit_tool_configures_auto_resolution() {
    let _lock = rho_providers::provider::custom_provider_registry_test_lock();
    rho_providers::provider::reset_custom_openai_compatible_providers_for_tests();
    let dir = tempfile::tempdir().unwrap();
    let path = dir.path().join("config.toml");
    std::fs::write(
        &path,
        "provider = \"vllm\"\nmodel = \"qwen2.5-coder\"\n[providers.custom.vllm]\nbase_url = \"http://127.0.0.1:8000/v1\"\nedit_tool = \"apply_patch\"\n[behavior]\nedit_tool = \"auto\"\n",
    )
    .unwrap();

    let mut config = Config::load_with_store(
        path.clone(),
        &rho_providers::credentials::MemoryCredentialStore::default(),
    )
    .unwrap();

    assert_eq!(
        config.resolved_edit_tool(),
        rho_tools::EditFormat::ApplyPatch
    );
    config.edit_tool = crate::config::EditTool::Pinned(rho_tools::EditFormat::StrReplace);
    assert_eq!(
        config.resolved_edit_tool(),
        rho_tools::EditFormat::StrReplace
    );

    config.write_settings(path.clone()).unwrap();
    let saved = std::fs::read_to_string(path).unwrap();
    assert!(
        saved.contains("edit_tool = \"apply_patch\""),
        "saved config must keep the custom provider edit tool: {saved}"
    );
    rho_providers::provider::reset_custom_openai_compatible_providers_for_tests();
}

// Covers: every custom endpoint option loads, interns into provider
// construction, and survives a settings write and reload, while an omitted
// api stays Chat Completions.
// Owner: provider config
#[test]
fn custom_endpoint_options_load_intern_and_persist() {
    use rho_providers::provider::{
        interned_custom_provider, CatalogLookupMode, OpenAiCompatibleApi,
    };

    let _lock = rho_providers::provider::custom_provider_registry_test_lock();
    rho_providers::provider::reset_custom_openai_compatible_providers_for_tests();
    let dir = tempfile::tempdir().unwrap();
    let path = dir.path().join("config.toml");
    std::fs::write(
        &path,
        "provider = \"litellm\"\nmodel = \"gpt-5.6\"\n[providers.custom.composer]\nbase_url = \"http://127.0.0.1:8787/v1\"\ncatalog_mode = \"model-id\"\n[providers.custom.litellm]\nbase_url = \"http://127.0.0.1:4000/v1\"\napi = \"responses\"\ncatalog = \"llmgateway\"\nprompt_cache_ttl = \"1h\"\nrequest_compression = \"zstd\"\n",
    )
    .unwrap();
    let store = rho_providers::credentials::MemoryCredentialStore::default();

    let config = Config::load_with_store(path.clone(), &store).unwrap();

    let litellm = &config.providers.custom["litellm"];
    assert_eq!(
        (
            litellm.api,
            litellm.catalog.as_deref(),
            litellm.prompt_cache_ttl,
            litellm.request_compression,
        ),
        (
            OpenAiCompatibleApi::Responses,
            Some("llmgateway"),
            Some(std::time::Duration::from_secs(3600)),
            Some(rho_providers::providers::RequestCompression::Zstd),
        )
    );
    let composer = &config.providers.custom["composer"];
    assert_eq!(
        (composer.api, composer.catalog_lookup),
        (
            OpenAiCompatibleApi::ChatCompletions,
            CatalogLookupMode::ModelId
        )
    );
    let litellm = interned_custom_provider("litellm").unwrap();
    let composer = interned_custom_provider("composer").unwrap();
    assert_eq!(
        (
            litellm.openai_compatible_api(),
            composer.openai_compatible_api(),
            composer.catalog_lookup(),
        ),
        (
            OpenAiCompatibleApi::Responses,
            OpenAiCompatibleApi::ChatCompletions,
            CatalogLookupMode::ModelId,
        )
    );

    config.write_settings(path.clone()).unwrap();
    let reloaded = Config::load_with_store(path, &store).unwrap();
    assert_eq!(reloaded.providers, config.providers);
    rho_providers::provider::reset_custom_openai_compatible_providers_for_tests();
}

// Covers: invalid endpoint options fail config load naming the offending
// field, and Ollama refuses the custom-only options.
// Owner: provider config
#[test]
fn invalid_endpoint_options_name_the_offending_field() {
    let custom = "[providers.custom.cliproxy]\nbase_url = \"http://127.0.0.1:8317/v1\"\n";
    let ollama = "[providers.ollama]\nbase_url = \"http://127.0.0.1:11434/v1\"\n";
    let cases = [
        (
            "model-qualified catalog",
            format!("{custom}catalog = \"anthropic/claude-sonnet-4-5\"\n"),
            "providers.custom.cliproxy.catalog",
        ),
        (
            "comma catalog",
            format!("{custom}catalog = \"a,b\"\n"),
            "must not contain ','",
        ),
        (
            "unknown catalog_mode",
            format!("{custom}catalog_mode = \"owner-model\"\n"),
            "providers.custom.cliproxy.catalog_mode",
        ),
        (
            "catalog_mode with catalog",
            format!("{custom}catalog = \"llmgateway\"\ncatalog_mode = \"model-id\"\n"),
            "cannot be combined with catalog",
        ),
        (
            "unknown api",
            format!("{custom}api = \"websocket\"\n"),
            "providers.custom.cliproxy.api",
        ),
        (
            "zero prompt_cache_ttl",
            format!("{custom}prompt_cache_ttl = \"0s\"\n"),
            "providers.custom.cliproxy.prompt_cache_ttl",
        ),
        (
            "unknown request_compression",
            format!("{custom}request_compression = \"br\"\n"),
            "providers.custom.cliproxy.request_compression",
        ),
        (
            "ollama catalog",
            format!("{ollama}catalog = \"llmgateway\"\n"),
            "providers.ollama does not accept catalog",
        ),
        (
            "ollama catalog_mode",
            format!("{ollama}catalog_mode = \"model-id\"\n"),
            "providers.ollama does not accept catalog_mode",
        ),
        (
            "ollama api",
            format!("{ollama}api = \"responses\"\n"),
            "providers.ollama does not accept api",
        ),
        (
            "ollama request_compression",
            format!("{ollama}request_compression = \"zstd\"\n"),
            "providers.ollama does not accept request_compression",
        ),
    ];
    let dir = tempfile::tempdir().unwrap();
    let store = rho_providers::credentials::MemoryCredentialStore::default();
    for (case, table, field) in cases {
        let path = dir.path().join("config.toml");
        std::fs::write(&path, table).unwrap();

        let error = Config::load_with_store(path, &store).unwrap_err();

        assert!(format!("{error:#}").contains(field), "{case}: {error:#}");
    }
}