argonauts-app 0.1.0

Argonauts Code's app controller and run host: the conversation, routing, choosing Captain or crew, and the run host each run has.
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
use std::path::PathBuf;

use argonauts_adapter_codex::CodexAdapter;
use argonauts_conductor::doctor::standing::oldest_supported;
use argonauts_conductor::{DoctorReport, GitCheck};
use argonauts_core::api::{RunState, RunSummary};
use argonauts_core::app::{AnswerTarget, AppChoice, UiCommand};
use argonauts_core::input::SlashCommand;
use argonauts_core::names::ModelRef;
use argonauts_testkit::TempRepo;

use super::super::test_support::{Call, CliOptions, TestCtx, TestDriver};
use super::*;

/// A version older than any Codex was recorded with.
const OLD: &str = "0.1.0";

/// A fake Codex outside any install Homebrew or npm made, so its own `update` is its updater.
/// Its version lives in a file that `update` runs `on_update` against.
struct FakeCodex {
    dir: tempfile::TempDir,
}

impl FakeCodex {
    fn new(on_update: &str) -> Self {
        let dir = tempfile::tempdir().unwrap();
        let fake = Self { dir };
        std::fs::write(fake.version_file(), format!("{OLD}\n")).unwrap();
        let version = fake.version_file().display().to_string();
        let on_update = on_update.replace("$VERSION", &version);
        let script = format!(
            "#!/bin/sh\ncase \"$1\" in\n  --version) echo \"codex-cli $(cat '{version}')\" ;;\n  \
             update) {on_update} ;;\nesac\n"
        );
        argonauts_testkit::write_script(&fake.binary(), &script).unwrap();
        fake
    }

    /// One whose update installs the oldest version supported.
    fn updating() -> Self {
        Self::new(&format!("echo {} > '$VERSION'", supported()))
    }

    fn binary(&self) -> PathBuf {
        self.dir.path().join("codex")
    }

    fn version_file(&self) -> PathBuf {
        self.dir.path().join("version")
    }

    /// Your settings with this Codex as a worker beside the main agent.
    fn options(&self) -> CliOptions {
        self.options_with("")
    }

    /// The same, with `crew` as more of the `[crew]` table.
    fn options_with(&self, crew: &str) -> CliOptions {
        let config = format!(
            "[crew]\nworker = [\"codex/gpt-5.6\"]\n{crew}\n[agents.codex]\nbinary = {:?}\n",
            self.binary().display().to_string()
        );
        CliOptions {
            prepare: Some(Box::new(move |repo: &TempRepo| {
                std::fs::write(repo.global_config(), config).unwrap();
            })),
            ..CliOptions::default()
        }
    }

    /// What Doctor finds of the CLIs as the app starts: this Codex alone.
    async fn report(&self) -> DoctorReport {
        let codex = check_agent_at(&CodexAdapter, Some(&self.binary()), VERSION_TIMEOUT).await;
        DoctorReport {
            agents: vec![codex],
            git: GitCheck {
                version: None,
                problem: None,
            },
        }
    }
}

fn supported() -> &'static str {
    oldest_supported(CodexAdapter.tested_versions()).expect("Codex was recorded with a version")
}

fn crew_run(task: &str) -> UiCommand {
    UiCommand::Slash {
        command: SlashCommand::Crew { task: task.into() },
    }
}

fn request(mode: RunMode) -> StartRun {
    StartRun {
        request: "tidy the date helpers".to_owned(),
        mode,
        forced: true,
        estimate: None,
        captain_or_crew: None,
        conversation_turn: None,
        continues: None,
        overrides: Vec::new(),
        include_uncommitted: false,
        main_agent: None,
        approval_mode: None,
        outside_agent: None,
        instructions: Vec::new(),
        request_settings: Vec::new(),
        required_steps: Vec::new(),
        starts_from: None,
    }
}

fn answer(id: &ChoiceId, value: &str) -> UiCommand {
    UiCommand::Answer {
        to: AnswerTarget::Choice { id: id.clone() },
        action: choices::choose(value),
        text: None,
        evidence_sha256: None,
        tasks: Vec::new(),
        remember: false,
    }
}

fn is_question(event: &AppEvent) -> bool {
    matches!(event, AppEvent::Choice { choice } if choice.kind == ChoiceKind::NeededUpdate)
}

fn is_started(event: &AppEvent) -> bool {
    matches!(event, AppEvent::Attached { .. })
}

async fn question(driver: &mut TestDriver) -> AppChoice {
    match driver.until(is_question).await {
        AppEvent::Choice { choice } => choice,
        other => unreachable!("{other:?}"),
    }
}

/// The notices among `events`, as text.
fn notices(events: &[AppEvent]) -> Vec<&str> {
    events
        .iter()
        .filter_map(|event| match event {
            AppEvent::Notice { text, .. } => Some(text.as_str()),
            _ => None,
        })
        .collect()
}

/// What each question among `events` closed with.
fn closed(events: &[AppEvent]) -> Vec<&str> {
    events
        .iter()
        .filter_map(|event| match event {
            AppEvent::ChoiceClosed { outcome, .. } => Some(outcome.as_str()),
            _ => None,
        })
        .collect()
}

/// The question as the versions picture has it: Codex 0.158.0 from Homebrew, where 0.160.0 is
/// the oldest version supported and another CLI holds the main role.
#[test]
fn the_question_reads_as_its_picture() {
    let cli = Outdated {
        id: "codex".to_owned(),
        name: "Codex".to_owned(),
        version: "0.158.0".to_owned(),
        check: CliVersionCheck {
            standing: VersionStanding::Older,
            oldest_supported: Some("0.160.0".to_owned()),
            update_command: Some("brew upgrade codex".to_owned()),
            ..CliVersionCheck::default()
        },
        can_leave_out: true,
        run_going: false,
    };
    let options = cli.options();
    let label_width = options
        .iter()
        .map(|option| option.label.chars().count())
        .max()
        .unwrap();
    let mut drawn = vec![
        format!("◆ {}", cli.title()),
        format!("  {WHAT_IT_MEANS}"),
        String::new(),
    ];
    for (index, option) in options.iter().enumerate() {
        let pointer = if index == 0 { "❯" } else { " " };
        let detail = option.detail.as_deref().unwrap();
        // Four cells after the longest answer, as the screen draws them.
        let label = format!("{:<width$}", option.label, width = label_width + 4);
        drawn.push(format!("  {pointer} {}. {label}{detail}", index + 1));
    }
    let picture = include_str!("../../../../tui/tests/golden/overview/versions.txt");
    let pictured: Vec<&str> = picture.lines().skip(13).take(6).collect();
    assert_eq!(drawn, pictured);
    let keys: Vec<(char, AnswerAction)> = options
        .into_iter()
        .map(|option| (option.key, option.action))
        .collect();
    assert_eq!(
        keys,
        [
            ('u', choices::choose(UPDATE)),
            ('l', choices::choose(LEAVE_OUT)),
            ('r', choices::choose(RUN_ANYWAY)),
        ]
    );
}

/// The main agent is the one you talk to, so its CLI can't be left out; a CLI nobody knows how
/// to update is never offered an update; and a version known not to work says that.
#[test]
fn only_the_answers_that_can_be_carried_out_are_offered() {
    let mut cli = Outdated {
        id: "codex".to_owned(),
        name: "Codex".to_owned(),
        version: "0.161.0".to_owned(),
        check: CliVersionCheck {
            standing: VersionStanding::Broken,
            ..CliVersionCheck::default()
        },
        can_leave_out: false,
        run_going: false,
    };
    assert_eq!(
        cli.title(),
        "Codex 0.161.0 is known not to work with Argonauts Code"
    );
    let labels = |cli: &Outdated| -> Vec<String> {
        cli.options()
            .into_iter()
            .map(|option| option.label)
            .collect()
    };
    assert_eq!(labels(&cli), ["Run with it anyway"]);
    cli.check.update_command = Some("codex update".to_owned());
    assert_eq!(labels(&cli), ["Update it now", "Run with it anyway"]);
    assert_eq!(
        cli.unasked_line(),
        "Codex 0.161.0 is known not to work with Argonauts Code · running with it anyway · \
         codex update updates it"
    );
}

/// A crew run that would use an outdated Codex waits on the question. Update it now runs
/// Codex's updater, says the version it is at, and the run starts. Nothing is asked twice.
#[tokio::test]
async fn update_it_now_updates_the_cli_then_the_run_starts() {
    let codex = FakeCodex::updating();
    let mut driver = TestDriver::start_with(codex.options()).await;
    driver.cli_facts.checked(codex.report().await);

    driver.send(crew_run("tidy the date helpers")).await;
    let asked = question(&mut driver).await;
    assert_eq!(
        asked.title,
        format!(
            "Codex {OLD} is older than Argonauts Code supports ({})",
            supported()
        )
    );
    assert_eq!(asked.body, [WHAT_IT_MEANS]);
    assert_eq!(
        asked.options[0].detail.as_deref(),
        Some("codex update, then the run starts")
    );
    assert!(driver.conductor.starts().is_empty(), "nothing has started");

    driver.send(answer(&asked.id, UPDATE)).await;
    driver.until(is_started).await;
    let started = driver.conductor.starts();
    assert_eq!(started.len(), 1);
    assert_eq!(started[0].request, "tidy the date helpers");
    assert!(started[0].request_settings.is_empty());
    let now = format!("Codex is now {}.", supported());
    assert!(notices(driver.seen()).contains(&now.as_str()));
    assert_eq!(closed(driver.seen()), ["Updating Codex · codex update"]);
    let installed = std::fs::read_to_string(codex.version_file()).unwrap();
    assert_eq!(installed.trim(), supported());

    let events = driver.exit().await;
    let questions = events.iter().filter(|event| is_question(event)).count();
    assert_eq!(questions, 1);
}

/// Esc starts nothing, and the next run is asked about again.
#[tokio::test]
async fn esc_leaves_the_run_unstarted() {
    let codex = FakeCodex::updating();
    let mut driver = TestDriver::start_with(codex.options()).await;
    driver.cli_facts.checked(codex.report().await);

    driver.send(crew_run("tidy the date helpers")).await;
    let asked = question(&mut driver).await;
    let to = AnswerTarget::Choice {
        id: asked.id.clone(),
    };
    driver.send(UiCommand::SetAside { to }).await;
    driver
        .until(|event| matches!(event, AppEvent::ChoiceClosed { .. }))
        .await;
    assert_eq!(
        closed(driver.seen()),
        [format!("Not started · Codex {OLD} still needs an update")]
    );

    driver.send(crew_run("tidy them after all")).await;
    let again = question(&mut driver).await;
    assert_ne!(again.id, asked.id);
    let started = driver.conductor.starts();
    driver.exit().await;
    assert!(started.is_empty(), "{started:?}");
    let installed = std::fs::read_to_string(codex.version_file()).unwrap();
    assert_eq!(installed.trim(), OLD, "nothing updated it");
}

/// A follow-up is a run like any other: it waits on the question, then continues the merged
/// run it builds on.
#[tokio::test]
async fn a_follow_up_run_waits_on_the_question_too() {
    let codex = FakeCodex::updating();
    let merged = RunSummary {
        run: argonauts_core::RunId::new("run-20261010-091503-3fa2").unwrap(),
        title: "Export the report".to_owned(),
        name: None,
        mode: RunMode::Captain,
        workflow: "captain".to_owned(),
        state: RunState::Merged,
        stopped_at: String::new(),
        updated: time::OffsetDateTime::UNIX_EPOCH,
        spent: argonauts_core::Spend::default(),
        sessions_to_resume: 0,
        waiting: Vec::new(),
        live: false,
        remind: false,
        shape_known: true,
    };
    let options = CliOptions {
        runs: vec![merged.clone()],
        ..codex.options()
    };
    let mut driver = TestDriver::start_with(options).await;
    driver.cli_facts.checked(codex.report().await);
    let conductor = driver.conductor.clone();
    let continued = || {
        conductor.calls().into_iter().find_map(|call| match call {
            Call::Continue { merged, request } => Some((merged, request)),
            _ => None,
        })
    };

    let command = SlashCommand::FollowUp {
        run: None,
        request: "Add a CSV export too".to_owned(),
    };
    driver.send(UiCommand::Slash { command }).await;
    let asked = question(&mut driver).await;
    // Captain's reviewer may run on Codex, so the run waits, and nothing has continued.
    assert!(continued().is_none());

    driver.send(answer(&asked.id, RUN_ANYWAY)).await;
    driver.exit().await;
    let (from, request) = continued().expect("the follow-up started");
    assert_eq!(from, merged.run);
    assert_eq!(request.request, "Add a CSV export too");
}

/// The state and the screen's events, for tests that call the handlers themselves.
struct Fixture {
    parts: TestCtx,
    state: NeededUpdateState,
}

impl Fixture {
    async fn new(codex: &FakeCodex) -> Self {
        Self::with(codex, codex.options()).await
    }

    async fn with(codex: &FakeCodex, options: CliOptions) -> Self {
        let (parts, _) = TestCtx::new(options);
        parts.ctx.cli_facts.checked(codex.report().await);
        Self {
            parts,
            state: NeededUpdateState::default(),
        }
    }

    async fn start(&mut self, request: StartRun, mode: ApprovalMode) -> Start {
        before_run(&mut self.parts.ctx, &mut self.state, request, mode).await
    }

    fn events(&mut self) -> Vec<AppEvent> {
        std::iter::from_fn(|| self.parts.events.try_recv().ok()).collect()
    }

    /// The question now on screen.
    fn asked(&mut self) -> AppChoice {
        let mut questions: Vec<AppChoice> = self
            .events()
            .into_iter()
            .filter_map(|event| match event {
                AppEvent::Choice { choice } => Some(choice),
                _ => None,
            })
            .collect();
        assert_eq!(questions.len(), 1, "{questions:?}");
        questions.remove(0)
    }

    /// The run an answer lets start.
    fn answered(&mut self, id: &ChoiceId, value: &str) -> StartRun {
        let ctx = &mut self.parts.ctx;
        let effects =
            answer_choice(ctx, &mut self.state, id.clone(), choices::choose(value)).unwrap();
        match effects.into_iter().next() {
            Some(Effect::StartRun(request)) => *request,
            other => panic!("{other:?}"),
        }
    }
}

fn starts_now(start: Start) -> StartRun {
    match start {
        Start::Now(request) => *request,
        Start::Waits => panic!("the run waits on a question"),
        Start::Refused(why) => panic!("refused: {why}"),
    }
}

fn waits(start: &Start) -> bool {
    matches!(start, Start::Waits)
}

/// Leave it out turns Codex off for this run alone, and Run with it anyway changes nothing.
/// Either way the run starts at once, and the next run is asked again.
#[tokio::test]
async fn leaving_it_out_or_running_anyway_holds_for_one_run() {
    let codex = FakeCodex::updating();
    let mut fixture = Fixture::new(&codex).await;

    assert!(waits(
        &fixture
            .start(request(RunMode::Crew), ApprovalMode::Supervised)
            .await
    ));
    let asked = fixture.asked();
    let labels: Vec<&str> = asked
        .options
        .iter()
        .map(|option| option.label.as_str())
        .collect();
    assert_eq!(
        labels,
        [
            "Update it now",
            "Leave Codex out of this run",
            "Run with it anyway"
        ]
    );
    let without = fixture.answered(&asked.id, LEAVE_OUT);
    assert_eq!(without.request_settings, ["agents.codex.enabled=false"]);
    assert_eq!(
        closed(&fixture.events()),
        ["Leaving Codex out of this run."]
    );
    // The run host reads that line as the request's own layer of settings, over every other.
    let sources = argonauts_registry::SettingsSources {
        interactive: true,
        request: without.request_settings.clone(),
        ..argonauts_registry::SettingsSources::default()
    };
    let resolved = argonauts_registry::resolve(&sources).unwrap();
    assert!(!resolved.settings.agents["codex"].enabled);
    // Started again with your answer, it goes ahead unasked, with Codex off in its settings.
    let going = starts_now(fixture.start(without, ApprovalMode::Supervised).await);
    let settings = run_settings(fixture.parts.ctx.settings(), &going);
    assert!(!settings.agents["codex"].enabled);
    assert!(fixture.parts.ctx.settings().agents["codex"].enabled);
    assert!(fixture.events().is_empty());

    assert!(waits(
        &fixture
            .start(request(RunMode::Crew), ApprovalMode::Supervised)
            .await
    ));
    let asked = fixture.asked();
    let anyway = fixture.answered(&asked.id, RUN_ANYWAY);
    assert!(anyway.request_settings.is_empty());
    assert_eq!(
        closed(&fixture.events()),
        [format!("Running with Codex {OLD}.")]
    );
    starts_now(fixture.start(anyway, ApprovalMode::Supervised).await);
    assert!(fixture.events().is_empty());

    // The answer was for that run. The next one is asked about again.
    assert!(waits(
        &fixture
            .start(request(RunMode::Crew), ApprovalMode::Supervised)
            .await
    ));
    // And a run that comes while one waits is turned away, saying what it waits on.
    let Start::Refused(why) = fixture
        .start(request(RunMode::Crew), ApprovalMode::Supervised)
        .await
    else {
        panic!("a second run started while the first waits");
    };
    assert_eq!(
        why,
        "another run waits on the question about Codex's update, so answer that first"
    );
}

/// An update that fails says why and asks again, with the run still waiting.
#[tokio::test]
async fn an_update_that_fails_says_why_and_asks_again() {
    let codex = FakeCodex::new("echo checking; echo 'no network' >&2; exit 1");
    let mut fixture = Fixture::new(&codex).await;
    assert!(waits(
        &fixture
            .start(request(RunMode::Crew), ApprovalMode::Supervised)
            .await
    ));
    let asked = fixture.asked();
    let ctx = &mut fixture.parts.ctx;
    let effects =
        answer_choice(ctx, &mut fixture.state, asked.id, choices::choose(UPDATE)).unwrap();
    assert!(effects.is_empty(), "the run waits for the update");
    let Some(Internal::CliUpdated(done)) = fixture.parts.internal.recv().await else {
        panic!("the update never reported back");
    };
    let effects = updated(&mut fixture.parts.ctx, &mut fixture.state, *done);
    assert!(effects.is_empty(), "the run still waits");
    let events = fixture.events();
    assert_eq!(notices(&events), ["Codex couldn't be updated: no network"]);
    assert_eq!(events.iter().filter(|event| is_question(event)).count(), 1);
}

/// While a run is going, in this folder or another, a CLI isn't updated: the question says
/// why and offers the rest, and an answer given as one starts is put off the same way.
#[tokio::test]
async fn a_cli_is_never_updated_while_a_run_is_going() {
    let codex = FakeCodex::updating();
    let mut fixture = Fixture::new(&codex).await;
    assert!(waits(
        &fixture
            .start(request(RunMode::Crew), ApprovalMode::Supervised)
            .await
    ));
    let asked = fixture.asked();
    assert_eq!(asked.options[0].label, "Update it now");

    // A run starts somewhere before you answer.
    let (pid, start_time) = crate::ancestry::own_process();
    let going = crate::live_registry::LiveRunHost {
        pid,
        start_time,
        repo_root: PathBuf::from("/another/folder"),
        run: argonauts_core::RunId::new("run-20261010-091503-3fa2").unwrap(),
        sessions: 1,
    };
    crate::live_registry::register(&fixture.parts.env.paths, &going).unwrap();
    let ctx = &mut fixture.parts.ctx;
    let effects =
        answer_choice(ctx, &mut fixture.state, asked.id, choices::choose(UPDATE)).unwrap();
    assert!(effects.is_empty());
    let events = fixture.events();
    assert_eq!(closed(&events), ["Codex wasn't updated."]);
    let again: Vec<&AppChoice> = events
        .iter()
        .filter_map(|event| match event {
            AppEvent::Choice { choice } => Some(choice),
            _ => None,
        })
        .collect();
    assert_eq!(
        again[0].body,
        [
            WHAT_IT_MEANS,
            "A run is going now, so it can't be updated until that ends: codex update"
        ]
    );
    let labels: Vec<&str> = again[0]
        .options
        .iter()
        .map(|option| option.label.as_str())
        .collect();
    assert_eq!(
        labels,
        ["Leave Codex out of this run", "Run with it anyway"]
    );
    let installed = std::fs::read_to_string(codex.version_file()).unwrap();
    assert_eq!(installed.trim(), OLD);
}

/// Autopilot is never asked: one line says the run goes on with the CLI as it is and what
/// updates it, and nothing updates it.
#[tokio::test]
async fn autopilot_is_told_in_one_line_and_runs_anyway() {
    let codex = FakeCodex::updating();
    let mut fixture = Fixture::new(&codex).await;
    let going = starts_now(
        fixture
            .start(request(RunMode::Crew), ApprovalMode::Autopilot)
            .await,
    );
    assert!(going.request_settings.is_empty());
    let events = fixture.events();
    assert_eq!(
        notices(&events),
        [format!(
            "Codex {OLD} is older than Argonauts Code supports ({}) · running with it anyway · \
             codex update updates it",
            supported()
        )]
    );
    assert!(!events.iter().any(is_question));
    let installed = std::fs::read_to_string(codex.version_file()).unwrap();
    assert_eq!(installed.trim(), OLD);
}

/// Only a run that would use the CLI is held: Captain works alone and is reviewed, so a CLI
/// that only workers run on isn't asked about, and one the run has off isn't either.
#[tokio::test]
async fn a_run_that_would_not_use_the_cli_is_not_asked() {
    let codex = FakeCodex::updating();
    let others_review = "reviewer = [\"antigravity-cli\"]\njudge = [\"antigravity-cli\"]\n";
    let mut fixture = Fixture::with(&codex, codex.options_with(others_review)).await;
    starts_now(
        fixture
            .start(request(RunMode::Captain), ApprovalMode::Supervised)
            .await,
    );
    // The crew's workers would run on it.
    assert!(waits(
        &fixture
            .start(request(RunMode::Crew), ApprovalMode::Supervised)
            .await
    ));
    let asked = fixture.asked();
    set_aside(&mut fixture.parts.ctx, &mut fixture.state, asked.id);
    fixture.events();
    let mut off = request(RunMode::Crew);
    off.request_settings
        .push("agents.codex.enabled=false".to_owned());
    starts_now(fixture.start(off, ApprovalMode::Supervised).await);
    assert!(fixture.events().is_empty());

    // With Codex as the main agent it can't be left out, in a Captain run or any other.
    let mut captain = request(RunMode::Captain);
    captain.main_agent = Some(ModelRef::new("codex", Some("gpt-5.6".to_owned())));
    assert!(waits(
        &fixture.start(captain, ApprovalMode::Supervised).await
    ));
    let labels: Vec<String> = fixture
        .asked()
        .options
        .into_iter()
        .map(|option| option.label)
        .collect();
    assert_eq!(labels, ["Update it now", "Run with it anyway"]);
}

/// A CLI you updated in another terminal since the app started is read again before anything
/// is said of it, so nothing is asked.
#[tokio::test]
async fn a_cli_updated_since_the_app_started_is_not_asked_about() {
    let codex = FakeCodex::updating();
    let mut fixture = Fixture::new(&codex).await;
    std::fs::write(codex.version_file(), supported()).unwrap();
    starts_now(
        fixture
            .start(request(RunMode::Crew), ApprovalMode::Supervised)
            .await,
    );
    assert!(fixture.events().is_empty());
    let report = fixture.parts.ctx.cli_facts.report().unwrap();
    assert_eq!(report.agents[0].version.as_deref(), Some(supported()));
}

/// A version that needs no update never holds a run.
#[tokio::test]
async fn a_supported_version_is_never_asked_about() {
    let codex = FakeCodex::updating();
    std::fs::write(codex.version_file(), supported()).unwrap();
    let mut fixture = Fixture::new(&codex).await;
    starts_now(
        fixture
            .start(request(RunMode::Crew), ApprovalMode::Supervised)
            .await,
    );
    assert!(fixture.events().is_empty());
}