agentty 0.14.3

Agentty is an ADE (Agentic Development Environment) for structured, controllable AI-assisted software development.
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
//! Confirmation dialog E2E tests: quit-confirm-yes exits, quit-confirm
//! dismiss via `n` and `Esc` returns to the app.

use std::time::Duration;

use agentty::test_support;
use testty::assertion;
use testty::region::Region;
use testty::scenario::Scenario;

use crate::common;
use crate::common::{BuilderEnv, FeatureTest, SessionSeed};

type E2eResult = Result<(), Box<dyn std::error::Error>>;

/// Seeds one unstarted draft session for list-mode cancel confirmation.
fn seed_cancelable_draft_session(env: &BuilderEnv) -> E2eResult {
    common::seed_session(
        env,
        SessionSeed::draft("draft-cancel-0001", "gpt-5.6-sol", "main", "Draft")
            .with_title("Cancel staged draft from list"),
    )
}

/// Seeds one draft orchestrator with its materialized controller worktree.
fn seed_cancelable_draft_orchestrator(env: &BuilderEnv) -> E2eResult {
    let session_id = "orchdraft-0001";

    common::seed_session(
        env,
        SessionSeed::regular(session_id, "gpt-5.6-sol", "main", "Draft")
            .with_title("Cancel draft orchestrator"),
    )?;

    let runtime = common::seed_runtime()?;
    runtime.block_on(async {
        let database = common::open_database(env).await?;
        sqlx::query!(
            "UPDATE session SET role = 'Orchestrator' WHERE id = ?",
            session_id
        )
        .execute(database.pool())
        .await?;

        Ok::<(), Box<dyn std::error::Error>>(())
    })?;

    std::fs::create_dir_all(test_support::session_folder(
        &env.agentty_root.join("wt"),
        session_id,
    ))?;

    Ok(())
}

/// Seeds one running session for list-mode cancel confirmation.
fn seed_cancelable_running_session(env: &BuilderEnv) -> E2eResult {
    let session_id = "running-cancel-0001";

    common::seed_session(
        env,
        SessionSeed::regular(session_id, "gpt-5.6-sol", "main", "InProgress")
            .with_title("Cancel running session"),
    )?;

    let worktree_name = &session_id[..8];
    // Match `session_folder()` so the seeded in-progress row remains visible
    // in the list and can participate in cancel flow assertions.
    std::fs::create_dir_all(env.agentty_root.join("wt").join(worktree_name))?;

    Ok(())
}

/// Seeds a review-ready parent with one cancelable stacked draft child.
fn seed_cancelable_stacked_child_session(env: &BuilderEnv) -> E2eResult {
    let parent_session_id = "parentca-0001";
    let child_session_id = "childcan-0001";

    common::seed_session(
        env,
        SessionSeed::regular(parent_session_id, "gpt-5.6-sol", "main", "Review")
            .with_title("Parent for child cancel"),
    )?;
    common::seed_session(
        env,
        SessionSeed::stacked_draft(
            child_session_id,
            "gpt-5.6-sol",
            "wt/parentca",
            "Draft",
            parent_session_id,
        )
        .with_title("Stacked child cancel archive"),
    )?;

    std::fs::create_dir_all(env.agentty_root.join("wt").join("parentca"))?;

    Ok(())
}

/// Verify that confirming quit with `y` causes the process to exit with
/// code 0.
///
/// Opens the quit dialog, presses `y`, and asserts that the PTY child
/// process terminates successfully. The exit wait is intentionally longer
/// than a regular PTY assertion because coverage builds and CI hosts can
/// take extra time to unwind terminal cleanup on shutdown.
#[test]
fn quit_confirm_yes_exits() {
    // Arrange
    let _test_guard = common::acquire_e2e_test_lock();
    let temp = tempfile::TempDir::new().expect("failed to create temp dir");
    let env = BuilderEnv::new(temp.path()).expect("failed to create builder env");
    let mut session = env.builder().spawn().expect("failed to spawn session");

    let scenario = Scenario::new("quit_yes")
        .compose(&common::wait_for_agentty_startup())
        .compose(&common::open_quit_dialog())
        .press_key("y")
        .sleep(Duration::from_millis(500));

    // Act
    scenario
        .execute_in_pty(&mut session)
        .expect("scenario execution failed");

    // Assert — process should exit with code 0.
    let exited_successfully = session
        .wait_for_exit(Duration::from_secs(15))
        .expect("process did not exit within timeout");

    assert!(exited_successfully, "Process should exit with code 0");
}

/// Verify that dismissing the quit dialog with `n` and `Esc` returns to
/// the normal app view.
///
/// Opens the quit dialog twice: first dismisses with `n`, then with `Esc`.
/// After each dismissal, asserts that the app is back on the Projects tab.
#[test]
fn quit_confirm_dismiss_returns() {
    // Arrange, Act, Assert
    FeatureTest::new("quit_dismiss")
        .with_git()
        .zola(
            "Quit dismiss",
            "Dismiss the quit dialog to stay in the session.",
            140,
        )
        .run(
            |scenario| {
                scenario
                    .compose(&common::wait_for_agentty_startup())
                    .viewing_pause_ms(2000)
                    .compose(&common::open_quit_dialog())
                    .viewing_pause_ms(2500)
                    .capture_labeled("dialog_n", "Quit dialog before n")
                    .press_key("n")
                    .wait_for_stable_frame(300, 3000)
                    .viewing_pause_ms(2000)
                    .capture_labeled("after_n", "App restored after n")
                    .compose(&common::open_quit_dialog())
                    .viewing_pause_ms(2500)
                    .capture_labeled("dialog_esc", "Quit dialog before Esc")
                    .press_key("Escape")
                    .wait_for_stable_frame(300, 3000)
                    .viewing_pause_ms(2000)
                    .capture_labeled("after_esc", "App restored after Esc")
            },
            |frame, report| {
                let dialog_n_frame = common::frame_from_capture(&report.captures[0]);
                let full = Region::full(dialog_n_frame.cols(), dialog_n_frame.rows());
                assertion::assert_text_in_region(&dialog_n_frame, "Confirm Quit", &full);

                let dialog_esc_frame = common::frame_from_capture(&report.captures[2]);
                let full_esc = Region::full(dialog_esc_frame.cols(), dialog_esc_frame.rows());
                assertion::assert_text_in_region(&dialog_esc_frame, "Confirm Quit", &full_esc);

                let after_n_frame = common::frame_from_capture(&report.captures[1]);
                let restored_full = Region::full(after_n_frame.cols(), after_n_frame.rows());
                assertion::assert_text_in_region(&after_n_frame, "test-project", &restored_full);

                let after_n_text = after_n_frame.text_in_region(&restored_full);
                assert!(
                    !after_n_text.contains("Confirm Quit"),
                    "Quit dialog should be dismissed after 'n'"
                );

                let final_full = Region::full(frame.cols(), frame.rows());
                assertion::assert_text_in_region(frame, "test-project", &final_full);

                let final_text = frame.text_in_region(&final_full);
                assert!(
                    !final_text.contains("Confirm Quit"),
                    "Quit dialog should be dismissed after Esc"
                );
            },
        )
        .expect("feature test failed");
}

/// Verify that an unstarted draft session can be canceled directly from the
/// session list.
#[test]
fn draft_session_cancel_confirmation() -> E2eResult {
    // Arrange, Act, Assert
    FeatureTest::new("draft_session_cancel")
        .with_git()
        .setup(seed_cancelable_draft_session)
        .run(
            |scenario| {
                scenario
                    .compose(&common::wait_for_agentty_startup())
                    .compose(&common::switch_to_tab("Sessions"))
                    .wait_for_text("Cancel staged draft from list", 5000)
                    .viewing_pause_ms(1500)
                    .capture_labeled(
                        "draft_row",
                        "Draft session visible in the session list with cancel available",
                    )
                    .press_key("c")
                    .wait_for_text("Confirm Cancel", 3000)
                    .viewing_pause_ms(1500)
                    .capture_labeled(
                        "confirm_cancel",
                        "Cancel confirmation for the selected draft session",
                    )
                    .press_key("y")
                    .wait_for_text("Canceled", 5000)
                    .viewing_pause_ms(1500)
                    .capture_labeled(
                        "canceled_draft",
                        "Canceled draft session moved into the archive group",
                    )
            },
            |frame, report| {
                let list_frame = common::frame_from_capture(&report.captures[0]);
                let list_full = Region::full(list_frame.cols(), list_frame.rows());
                assertion::assert_text_in_region(
                    &list_frame,
                    "Cancel staged draft from list",
                    &list_full,
                );
                assertion::assert_text_in_region(&list_frame, "Draft", &list_full);
                assertion::assert_text_in_region(&list_frame, "c: cancel", &list_full);

                let confirmation_frame = common::frame_from_capture(&report.captures[1]);
                let confirmation_full =
                    Region::full(confirmation_frame.cols(), confirmation_frame.rows());
                assertion::assert_text_in_region(
                    &confirmation_frame,
                    "Confirm Cancel",
                    &confirmation_full,
                );

                let final_full = Region::full(frame.cols(), frame.rows());
                assertion::assert_text_in_region(frame, "Archive", &final_full);
                assertion::assert_text_in_region(frame, "Canceled", &final_full);
            },
        )?;

    Ok(())
}

/// Verify that a draft orchestrator can be canceled directly from the session
/// list before its first goal is submitted.
#[test]
fn test_draft_orchestrator_cancel() -> E2eResult {
    // Arrange, Act, Assert
    FeatureTest::new("draft_orchestrator_cancel")
        .with_git()
        .setup(seed_cancelable_draft_orchestrator)
        .run(
            |scenario| {
                scenario
                    .compose(&common::wait_for_agentty_startup())
                    .compose(&common::switch_to_tab("Sessions"))
                    .wait_for_text("Cancel draft orchestrator", 5000)
                    .capture_labeled(
                        "draft_orchestrator",
                        "Draft orchestrator visible with cancel available",
                    )
                    .press_key("c")
                    .wait_for_text("Confirm Cancel", 3000)
                    .capture_labeled(
                        "confirm_cancel",
                        "Cancel confirmation for the draft orchestrator",
                    )
                    .press_key("y")
                    .wait_for_text("Canceled", 5000)
                    .capture_labeled(
                        "canceled_orchestrator",
                        "Canceled draft orchestrator moved into the archive group",
                    )
            },
            |frame, report| {
                let list_frame = common::frame_from_capture(&report.captures[0]);
                let list_full = Region::full(list_frame.cols(), list_frame.rows());
                assertion::assert_text_in_region(
                    &list_frame,
                    "Cancel draft orchestrator",
                    &list_full,
                );
                assertion::assert_text_in_region(&list_frame, "Draft", &list_full);
                assertion::assert_text_in_region(&list_frame, "c: cancel", &list_full);

                let confirmation_frame = common::frame_from_capture(&report.captures[1]);
                let confirmation_full =
                    Region::full(confirmation_frame.cols(), confirmation_frame.rows());
                assertion::assert_text_in_region(
                    &confirmation_frame,
                    "Confirm Cancel",
                    &confirmation_full,
                );

                let final_full = Region::full(frame.cols(), frame.rows());
                assertion::assert_text_in_region(frame, "Archive", &final_full);
                assertion::assert_text_in_region(frame, "Canceled", &final_full);
            },
        )?;

    Ok(())
}

/// Verify that a running session can be canceled directly from the session
/// list.
#[test]
fn running_session_cancel_confirmation() -> E2eResult {
    // Arrange, Act, Assert
    FeatureTest::new("running_session_cancel")
        .with_git()
        .setup(seed_cancelable_running_session)
        .run(
            |scenario| {
                scenario
                    .compose(&common::wait_for_agentty_startup())
                    .compose(&common::switch_to_tab("Sessions"))
                    .wait_for_text("Cancel running session", 5000)
                    .viewing_pause_ms(1500)
                    .capture_labeled(
                        "running_row",
                        "Running session visible in the session list with cancel available",
                    )
                    .press_key("c")
                    .wait_for_text("Confirm Cancel", 3000)
                    .viewing_pause_ms(1500)
                    .capture_labeled(
                        "confirm_cancel",
                        "Cancel confirmation for the selected running session",
                    )
                    .press_key("y")
                    .wait_for_text("Canceled", 5000)
                    .viewing_pause_ms(1500)
                    .capture_labeled(
                        "canceled_running",
                        "Canceled running session moved into the archive group",
                    )
            },
            |frame, report| {
                let list_frame = common::frame_from_capture(&report.captures[0]);
                let list_full = Region::full(list_frame.cols(), list_frame.rows());
                assertion::assert_text_in_region(&list_frame, "Cancel running session", &list_full);
                assertion::assert_text_in_region(&list_frame, "c: cancel", &list_full);

                let confirmation_frame = common::frame_from_capture(&report.captures[1]);
                let confirmation_full =
                    Region::full(confirmation_frame.cols(), confirmation_frame.rows());
                assertion::assert_text_in_region(
                    &confirmation_frame,
                    "Confirm Cancel",
                    &confirmation_full,
                );

                let final_full = Region::full(frame.cols(), frame.rows());
                assertion::assert_text_in_region(frame, "Archive", &final_full);
                assertion::assert_text_in_region(frame, "Canceled", &final_full);
            },
        )?;

    Ok(())
}

/// Verify that canceling a stacked child moves it into the archive group when
/// its parent remains active.
#[test]
fn stacked_child_cancel_confirmation_archives_child() -> E2eResult {
    // Arrange, Act, Assert
    FeatureTest::new("stacked_child_cancel_archive")
        .with_git()
        .setup(seed_cancelable_stacked_child_session)
        .run(
            |scenario| {
                scenario
                    .compose(&common::wait_for_agentty_startup())
                    .compose(&common::switch_to_tab("Sessions"))
                    .wait_for_text("Stacked child cancel archive", 5000)
                    .viewing_pause_ms(1500)
                    .capture_labeled(
                        "stacked_child_row",
                        "Stacked child visible beneath its active parent",
                    )
                    .press_key("c")
                    .wait_for_text("Confirm Cancel", 3000)
                    .viewing_pause_ms(1500)
                    .capture_labeled(
                        "confirm_cancel",
                        "Cancel confirmation for the selected stacked child",
                    )
                    .press_key("y")
                    .wait_for_text("Canceled", 5000)
                    .viewing_pause_ms(1500)
                    .capture_labeled(
                        "archived_child",
                        "Canceled stacked child rendered as an archive row",
                    )
            },
            |frame, report| {
                let list_frame = common::frame_from_capture(&report.captures[0]);
                let list_full = Region::full(list_frame.cols(), list_frame.rows());
                assertion::assert_text_in_region(
                    &list_frame,
                    "Parent for child cancel",
                    &list_full,
                );
                assertion::assert_text_in_region(&list_frame, "└ [XS] Stacked child", &list_full);

                let confirmation_frame = common::frame_from_capture(&report.captures[1]);
                let confirmation_full =
                    Region::full(confirmation_frame.cols(), confirmation_frame.rows());
                assertion::assert_text_in_region(
                    &confirmation_frame,
                    "Confirm Cancel",
                    &confirmation_full,
                );

                let final_full = Region::full(frame.cols(), frame.rows());
                assertion::assert_text_in_region(frame, "Archive", &final_full);
                assertion::assert_text_in_region(frame, "Canceled", &final_full);
                assertion::assert_text_in_region(
                    frame,
                    "Stacked child cancel archive",
                    &final_full,
                );
                assertion::assert_not_visible(frame, "└ [XS] Stacked child");
            },
        )?;

    Ok(())
}