opi-coding-agent 0.5.0

Interactive coding agent CLI with file editing and shell execution
Documentation
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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
//! Coding-agent extension integration tests (task 4.4).
//!
//! Tests verify that extensions work through the full agent loop path:
//! - Extension tools are available and executable
//! - Extension hooks compose with base hooks during agent loop execution
//! - Extension events are observed during agent lifecycle
//! - Extension state persists across agent invocations

use std::future::Future;
use std::pin::Pin;
use std::sync::{Arc, Mutex};

use opi_agent::Agent;
use opi_agent::event::AgentEvent;
use opi_agent::extension::{Extension, ExtensionError, ExtensionHookResult, ExtensionRegistry};
use opi_agent::hooks::AgentHooks;
use opi_agent::loop_types::{AgentError, AgentLoopConfig};
use opi_agent::message::AgentMessage;
use opi_agent::tool::{ExecutionMode, Tool, ToolError, ToolResult};
use opi_ai::message::{OutputContent, ToolDef};
use opi_ai::provider::ModelInfo;
use opi_ai::test_support::{MockProvider, text_response, tool_call_response};
use opi_coding_agent::config::OpiConfig;
use opi_coding_agent::harness::CodingHarness;
use opi_coding_agent::policy::{RunMode, ToolRuntimeConfig, ToolSelection};
use tokio_util::sync::CancellationToken;

// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------

/// A simple extension tool that echoes its arguments.
struct EchoExtensionTool;

impl Tool for EchoExtensionTool {
    fn definition(&self) -> ToolDef {
        serde_json::from_value(serde_json::json!({
            "name": "ext_echo",
            "description": "extension echo tool",
            "input_schema": {
                "type": "object",
                "properties": { "text": { "type": "string" } },
                "required": ["text"]
            }
        }))
        .unwrap()
    }

    fn execute(
        &self,
        _call_id: &str,
        arguments: serde_json::Value,
        _signal: CancellationToken,
        _on_update: Option<opi_agent::tool::UpdateCallback>,
    ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send>> {
        let text = arguments["text"].as_str().unwrap_or("").to_string();
        Box::pin(async move {
            Ok(ToolResult {
                content: vec![OutputContent::Text {
                    text: format!("ext_echo: {text}"),
                }],
                details: None,
                is_error: false,
                terminate: false,
            })
        })
    }

    fn execution_mode(&self) -> ExecutionMode {
        ExecutionMode::Parallel
    }
}

/// Extension that provides a tool and records hook calls.
struct IntegrationExtension {
    before_calls: Arc<Mutex<Vec<String>>>,
    after_calls: Arc<Mutex<Vec<String>>>,
}

impl IntegrationExtension {
    fn new() -> Self {
        Self {
            before_calls: Arc::new(Mutex::new(Vec::new())),
            after_calls: Arc::new(Mutex::new(Vec::new())),
        }
    }
}

impl Extension for IntegrationExtension {
    fn name(&self) -> &str {
        "integration-ext"
    }

    fn tools(&self) -> Vec<Box<dyn Tool>> {
        vec![Box::new(EchoExtensionTool)]
    }

    fn on_before_tool_call(
        &self,
        tool_name: &str,
        _args: &serde_json::Value,
    ) -> Pin<Box<dyn Future<Output = ExtensionHookResult> + Send>> {
        let tool_name = tool_name.to_string();
        let calls = self.before_calls.clone();
        Box::pin(async move {
            calls.lock().unwrap().push(tool_name);
            ExtensionHookResult::Continue
        })
    }

    fn on_after_tool_call(
        &self,
        tool_name: &str,
        _result: &ToolResult,
    ) -> Pin<Box<dyn Future<Output = ()> + Send>> {
        let tool_name = tool_name.to_string();
        let calls = self.after_calls.clone();
        Box::pin(async move {
            calls.lock().unwrap().push(tool_name);
        })
    }
}

/// Minimal hooks for testing.
struct TestHooks;

impl AgentHooks for TestHooks {
    fn convert_to_llm(
        &self,
        messages: &[AgentMessage],
    ) -> Result<Vec<opi_ai::message::Message>, AgentError> {
        Ok(messages
            .iter()
            .filter_map(|m| match m {
                AgentMessage::Llm(msg) => Some(msg.clone()),
                _ => None,
            })
            .collect())
    }
}

// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------

#[tokio::test]
async fn extension_tool_executes_through_agent_loop() {
    let mut registry = ExtensionRegistry::new();
    let ext = IntegrationExtension::new();
    let before_calls = ext.before_calls.clone();
    let after_calls = ext.after_calls.clone();
    registry.register(Box::new(ext)).unwrap();

    let ext_tools = registry.collect_tools();

    let provider = MockProvider::new(
        "mock",
        vec![
            tool_call_response("tc_ext_1", "ext_echo", r#"{"text":"hello"}"#),
            text_response("Done"),
        ],
    );
    let hooks = registry.wrap_hooks(Box::new(TestHooks));
    let mut agent = Agent::new(
        Box::new(provider),
        ext_tools,
        "mock:model".into(),
        None,
        AgentLoopConfig {
            max_turns: 10,
            ..Default::default()
        },
        hooks,
    );

    let result = agent.prompt("test").await.unwrap();

    // Verify extension tool was executed: user + assistant(tool_call) + tool_result + assistant(text)
    assert!(result.len() >= 3);

    // Verify extension hooks were called.
    let before = before_calls.lock().unwrap();
    assert!(before.contains(&"ext_echo".to_string()));

    let after = after_calls.lock().unwrap();
    assert!(after.contains(&"ext_echo".to_string()));
}

#[tokio::test]
async fn extension_hooks_observe_builtin_tool_calls() {
    let observed_tools: Arc<Mutex<Vec<String>>> = Arc::new(Mutex::new(Vec::new()));

    struct ObserverExtension {
        observed: Arc<Mutex<Vec<String>>>,
    }

    impl Extension for ObserverExtension {
        fn name(&self) -> &str {
            "observer"
        }

        fn on_after_tool_call(
            &self,
            tool_name: &str,
            _result: &ToolResult,
        ) -> Pin<Box<dyn Future<Output = ()> + Send>> {
            let tool_name = tool_name.to_string();
            let observed = self.observed.clone();
            Box::pin(async move {
                observed.lock().unwrap().push(tool_name);
            })
        }
    }

    let mut registry = ExtensionRegistry::new();
    registry
        .register(Box::new(ObserverExtension {
            observed: observed_tools.clone(),
        }))
        .unwrap();

    // Dummy tool that's not an extension tool — extension should still observe it.
    struct DummyTool;

    impl Tool for DummyTool {
        fn definition(&self) -> ToolDef {
            serde_json::from_value(serde_json::json!({
                "name": "dummy",
                "description": "dummy tool",
                "input_schema": { "type": "object", "properties": {} }
            }))
            .unwrap()
        }

        fn execute(
            &self,
            _call_id: &str,
            _arguments: serde_json::Value,
            _signal: CancellationToken,
            _on_update: Option<opi_agent::tool::UpdateCallback>,
        ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send>> {
            Box::pin(async {
                Ok(ToolResult {
                    content: vec![OutputContent::Text { text: "ok".into() }],
                    details: None,
                    is_error: false,
                    terminate: false,
                })
            })
        }
    }

    let provider = MockProvider::new(
        "mock",
        vec![
            tool_call_response("tc_d1", "dummy", "{}"),
            text_response("Done"),
        ],
    );
    let hooks = registry.wrap_hooks(Box::new(TestHooks));
    let mut agent = Agent::new(
        Box::new(provider),
        vec![Box::new(DummyTool)],
        "mock:model".into(),
        None,
        AgentLoopConfig {
            max_turns: 10,
            ..Default::default()
        },
        hooks,
    );

    let result = agent.prompt("test").await.unwrap();
    assert!(result.len() >= 3);

    // Extension should have observed the "dummy" tool call.
    let observed = observed_tools.lock().unwrap();
    assert!(observed.contains(&"dummy".to_string()));
}

#[tokio::test]
async fn extension_can_block_tool_in_agent_loop() {
    struct BlockAllExtension;

    impl Extension for BlockAllExtension {
        fn name(&self) -> &str {
            "blocker"
        }

        fn on_before_tool_call(
            &self,
            _tool_name: &str,
            _args: &serde_json::Value,
        ) -> Pin<Box<dyn Future<Output = ExtensionHookResult> + Send>> {
            Box::pin(async {
                ExtensionHookResult::Block {
                    reason: "all tools blocked".into(),
                }
            })
        }
    }

    let mut registry = ExtensionRegistry::new();
    registry.register(Box::new(BlockAllExtension)).unwrap();

    struct AlwaysOkTool;

    impl Tool for AlwaysOkTool {
        fn definition(&self) -> ToolDef {
            serde_json::from_value(serde_json::json!({
                "name": "ok",
                "description": "ok tool",
                "input_schema": { "type": "object", "properties": {} }
            }))
            .unwrap()
        }

        fn execute(
            &self,
            _call_id: &str,
            _arguments: serde_json::Value,
            _signal: CancellationToken,
            _on_update: Option<opi_agent::tool::UpdateCallback>,
        ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send>> {
            Box::pin(async {
                Ok(ToolResult {
                    content: vec![OutputContent::Text {
                        text: "executed".into(),
                    }],
                    details: None,
                    is_error: false,
                    terminate: false,
                })
            })
        }
    }

    let provider = MockProvider::new(
        "mock",
        vec![
            tool_call_response("tc_b1", "ok", "{}"),
            text_response("Done"),
        ],
    );
    let hooks = registry.wrap_hooks(Box::new(TestHooks));
    let mut agent = Agent::new(
        Box::new(provider),
        vec![Box::new(AlwaysOkTool)],
        "mock:model".into(),
        None,
        AgentLoopConfig {
            max_turns: 10,
            ..Default::default()
        },
        hooks,
    );

    let result = agent.prompt("test").await.unwrap();

    // The tool result should contain the block reason (not "executed").
    let tool_text: String = result
        .iter()
        .filter_map(|m| {
            if let AgentMessage::Llm(opi_ai::message::Message::ToolResult(trm)) = m {
                Some(trm.content.clone())
            } else {
                None
            }
        })
        .flat_map(|c| {
            c.into_iter().filter_map(|c| match c {
                OutputContent::Text { text } => Some(text),
                _ => None,
            })
        })
        .collect();

    assert!(
        tool_text.contains("all tools blocked"),
        "tool result should contain block reason, got: {tool_text}"
    );
}

#[tokio::test]
async fn extension_state_round_trip_through_agent() {
    struct CountingExtension {
        count: Arc<Mutex<u64>>,
    }

    impl CountingExtension {
        fn new() -> Self {
            Self {
                count: Arc::new(Mutex::new(0)),
            }
        }
    }

    impl Extension for CountingExtension {
        fn name(&self) -> &str {
            "counter"
        }

        fn on_after_tool_call(
            &self,
            _tool_name: &str,
            _result: &ToolResult,
        ) -> Pin<Box<dyn Future<Output = ()> + Send>> {
            let count = self.count.clone();
            Box::pin(async move {
                *count.lock().unwrap() += 1;
            })
        }

        fn serialize_state(&self) -> Result<Option<serde_json::Value>, ExtensionError> {
            let count = *self.count.lock().unwrap();
            Ok(Some(serde_json::json!({ "count": count })))
        }

        fn restore_state(&self, state: serde_json::Value) -> Result<(), ExtensionError> {
            if let Some(c) = state["count"].as_u64() {
                *self.count.lock().unwrap() = c;
            }
            Ok(())
        }
    }

    let ext = CountingExtension::new();
    let count = ext.count.clone();
    let mut registry = ExtensionRegistry::new();
    registry.register(Box::new(ext)).unwrap();

    // Serialize (initial state).
    let states = registry.serialize_states().unwrap();
    assert_eq!(states["counter"]["count"], 0);

    // Simulate a tool call incrementing the counter.
    *count.lock().unwrap() = 5;

    // Serialize (after increment).
    let states = registry.serialize_states().unwrap();
    assert_eq!(states["counter"]["count"], 5);

    // Create a new extension and restore.
    let ext2 = CountingExtension::new();
    let count2 = ext2.count.clone();
    let mut registry2 = ExtensionRegistry::new();
    registry2.register(Box::new(ext2)).unwrap();
    registry2.restore_states(states).unwrap();

    assert_eq!(*count2.lock().unwrap(), 5);
}

#[tokio::test]
async fn harness_builder_wraps_extension_registry_hooks_and_tools() {
    struct BuilderTool;

    impl Tool for BuilderTool {
        fn definition(&self) -> ToolDef {
            serde_json::from_value(serde_json::json!({
                "name": "builder_echo",
                "description": "builder extension echo",
                "input_schema": { "type": "object", "properties": {} }
            }))
            .unwrap()
        }

        fn execute(
            &self,
            _call_id: &str,
            _arguments: serde_json::Value,
            _signal: CancellationToken,
            _on_update: Option<opi_agent::tool::UpdateCallback>,
        ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send>> {
            Box::pin(async {
                Ok(ToolResult {
                    content: vec![OutputContent::Text {
                        text: "builder tool executed".into(),
                    }],
                    details: None,
                    is_error: false,
                    terminate: false,
                })
            })
        }
    }

    struct BuilderExtension {
        before_calls: Arc<Mutex<Vec<String>>>,
    }

    impl Extension for BuilderExtension {
        fn name(&self) -> &str {
            "builder-extension"
        }

        fn tools(&self) -> Vec<Box<dyn Tool>> {
            vec![Box::new(BuilderTool)]
        }

        fn on_before_tool_call(
            &self,
            tool_name: &str,
            _args: &serde_json::Value,
        ) -> Pin<Box<dyn Future<Output = ExtensionHookResult> + Send>> {
            let tool_name = tool_name.to_string();
            let before_calls = self.before_calls.clone();
            Box::pin(async move {
                before_calls.lock().unwrap().push(tool_name);
                ExtensionHookResult::Continue
            })
        }
    }

    let before_calls = Arc::new(Mutex::new(Vec::new()));
    let mut registry = ExtensionRegistry::new();
    registry
        .register(Box::new(BuilderExtension {
            before_calls: before_calls.clone(),
        }))
        .unwrap();

    let provider = MockProvider::new(
        "mock",
        vec![
            tool_call_response("tc_builder", "builder_echo", "{}"),
            text_response("Done"),
        ],
    );
    let workspace = tempfile::tempdir().unwrap();
    let mut harness = CodingHarness::builder(
        Box::new(provider),
        "mock:mock-model".into(),
        OpiConfig::default(),
        workspace.path().to_path_buf(),
    )
    .extension_registry(registry)
    .tool_config(ToolRuntimeConfig {
        run_mode: RunMode::Interactive,
        active_tool_names: Vec::new(),
    })
    .build();

    assert!(harness.system_prompt().contains("builder_echo"));
    assert!(
        harness
            .resource_metadata()
            .extensions
            .iter()
            .any(|entry| entry.name == "builder-extension")
    );

    let messages = harness.prompt("use builder tool").await.unwrap();
    assert!(messages.len() >= 3);
    assert_eq!(
        before_calls.lock().unwrap().as_slice(),
        ["builder_echo".to_string()]
    );
}

#[tokio::test]
async fn harness_builder_extension_observes_agent_events() {
    struct EventRecorderExtension {
        events: Arc<Mutex<Vec<&'static str>>>,
    }

    impl Extension for EventRecorderExtension {
        fn name(&self) -> &str {
            "event-recorder"
        }

        fn on_event(&self, event: &AgentEvent) {
            let label = match event {
                AgentEvent::AgentStart => "AgentStart",
                AgentEvent::TurnStart => "TurnStart",
                AgentEvent::MessageStart { .. } => "MessageStart",
                AgentEvent::AgentEnd { .. } => "AgentEnd",
                _ => return,
            };
            self.events.lock().unwrap().push(label);
        }
    }

    let events = Arc::new(Mutex::new(Vec::new()));
    let mut registry = ExtensionRegistry::new();
    registry
        .register(Box::new(EventRecorderExtension {
            events: events.clone(),
        }))
        .unwrap();

    let provider = MockProvider::new("mock", vec![text_response("Done")]);
    let workspace = tempfile::tempdir().unwrap();
    let mut harness = CodingHarness::builder(
        Box::new(provider),
        "mock:mock-model".into(),
        OpiConfig::default(),
        workspace.path().to_path_buf(),
    )
    .extension_registry(registry)
    .tool_selection(ToolSelection::Disabled)
    .build();

    harness.prompt("hello").await.unwrap();

    let recorded = events.lock().unwrap().clone();
    assert!(
        recorded.contains(&"AgentStart"),
        "recorded events: {recorded:?}"
    );
    assert!(
        recorded.contains(&"TurnStart"),
        "recorded events: {recorded:?}"
    );
    assert!(
        recorded.contains(&"MessageStart"),
        "recorded events: {recorded:?}"
    );
    assert!(
        recorded.contains(&"AgentEnd"),
        "recorded events: {recorded:?}"
    );
}

#[tokio::test]
async fn harness_builder_tool_selection_disabled_filters_extension_tools() {
    let mut registry = ExtensionRegistry::new();
    registry
        .register(Box::new(IntegrationExtension::new()))
        .unwrap();
    let provider = MockProvider::new("mock", vec![text_response("Done")]);
    let workspace = tempfile::tempdir().unwrap();

    let harness = CodingHarness::builder(
        Box::new(provider),
        "mock:mock-model".into(),
        OpiConfig::default(),
        workspace.path().to_path_buf(),
    )
    .extension_registry(registry)
    .tool_selection(ToolSelection::Disabled)
    .build();

    assert!(!harness.system_prompt().contains("ext_echo"));
}

#[tokio::test]
async fn harness_builder_tool_selection_allowlist_filters_extension_tools_by_name() {
    let mut registry = ExtensionRegistry::new();
    registry
        .register(Box::new(IntegrationExtension::new()))
        .unwrap();
    let provider = MockProvider::new("mock", vec![text_response("Done")]);
    let workspace = tempfile::tempdir().unwrap();

    let harness = CodingHarness::builder(
        Box::new(provider),
        "mock:mock-model".into(),
        OpiConfig::default(),
        workspace.path().to_path_buf(),
    )
    .extension_registry(registry)
    .tool_selection(ToolSelection::Allowlist(vec!["ext_echo".to_owned()]))
    .build();

    assert!(harness.system_prompt().contains("ext_echo"));
    assert!(!harness.system_prompt().contains("read_file"));
}

#[tokio::test]
async fn harness_builder_tool_selection_allowlist_excludes_unlisted_extension_tools() {
    let mut registry = ExtensionRegistry::new();
    registry
        .register(Box::new(IntegrationExtension::new()))
        .unwrap();
    let provider = MockProvider::new("mock", vec![text_response("Done")]);
    let workspace = tempfile::tempdir().unwrap();

    let harness = CodingHarness::builder(
        Box::new(provider),
        "mock:mock-model".into(),
        OpiConfig::default(),
        workspace.path().to_path_buf(),
    )
    .extension_registry(registry)
    .tool_selection(ToolSelection::Allowlist(vec!["read".to_owned()]))
    .build();

    assert!(!harness.system_prompt().contains("ext_echo"));
}

#[test]
fn harness_builder_model_picker_includes_current_provider_extension_overrides() {
    struct ModelOverrideExtension;

    impl Extension for ModelOverrideExtension {
        fn name(&self) -> &str {
            "model-override-extension"
        }

        fn model_overrides(&self) -> Vec<(String, ModelInfo)> {
            vec![(
                "mock".into(),
                ModelInfo {
                    id: "custom-model".into(),
                    display_name: "Custom Model".into(),
                    context_window: 100_000,
                    max_output_tokens: 4_096,
                    supports_images: true,
                    supports_streaming: true,
                    supports_thinking: false,
                },
            )]
        }
    }

    let mut registry = ExtensionRegistry::new();
    registry.register(Box::new(ModelOverrideExtension)).unwrap();
    let workspace = tempfile::tempdir().unwrap();

    let harness = CodingHarness::builder(
        Box::new(MockProvider::new("mock", vec![text_response("Done")])),
        "mock:mock-model".into(),
        OpiConfig::default(),
        workspace.path().to_path_buf(),
    )
    .extension_registry(registry)
    .build();

    let items = harness.model_picker_items();

    assert!(
        items
            .iter()
            .any(|item| item.id == "mock:custom-model" && item.display == "Custom Model")
    );
}

#[test]
fn harness_builder_set_model_validated_accepts_current_provider_extension_overrides() {
    struct ModelOverrideExtension;

    impl Extension for ModelOverrideExtension {
        fn name(&self) -> &str {
            "model-override-extension"
        }

        fn model_overrides(&self) -> Vec<(String, ModelInfo)> {
            vec![(
                "mock".into(),
                ModelInfo {
                    id: "custom-model".into(),
                    display_name: "Custom Model".into(),
                    context_window: 100_000,
                    max_output_tokens: 4_096,
                    supports_images: true,
                    supports_streaming: true,
                    supports_thinking: false,
                },
            )]
        }
    }

    let mut registry = ExtensionRegistry::new();
    registry.register(Box::new(ModelOverrideExtension)).unwrap();
    let workspace = tempfile::tempdir().unwrap();

    let mut harness = CodingHarness::builder(
        Box::new(MockProvider::new("mock", vec![text_response("Done")])),
        "mock:mock-model".into(),
        OpiConfig::default(),
        workspace.path().to_path_buf(),
    )
    .extension_registry(registry)
    .build();

    let selected = harness
        .set_model_validated("mock:custom-model".into())
        .unwrap();

    assert_eq!(selected, "mock:custom-model");
}