cueloop 0.5.0

A Rust CLI for managing AI agent loops with a structured JSON task queue
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
//! Parse-regression tests for the top-level CLI surface.
//!
//! Purpose:
//! - Parse-regression tests for the top-level CLI surface.
//!
//! Responsibilities:
//! - Verify key top-level command routes and rejected legacy flags.
//! - Keep root CLI parsing coverage out of the root facade file.
//! - Assert version/help behaviors exposed by Clap.
//!
//! Not handled here:
//! - Exhaustive per-subcommand argument validation owned by submodules.
//! - Runtime execution behavior after parsing succeeds.
//!
//!
//! Usage:
//! - Used through the crate module tree or integration test harness.
//!
//! Invariants/assumptions:
//! - Tests exercise the public `Cli` parser exactly as end users invoke it.
//! - Removed flags/subcommands must remain rejected.

use super::{Cli, Command};
use crate::cli::app_parity::{
    APP_PARITY_SCENARIO_REGISTRY, app_parity_scenario_coverage_issues, app_parity_scenario_report,
    unclassified_human_cli_commands,
};
use crate::cli::{machine, queue, run, task};
use clap::Parser;
use clap::error::ErrorKind;
use std::path::{Path, PathBuf};

fn assert_proof_anchor_exists(anchor: &str) {
    let (relative_path, symbol) = anchor
        .rsplit_once("::")
        .unwrap_or_else(|| panic!("proof anchor must include a path and symbol: {anchor}"));
    let repo_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
    let source_path: PathBuf = repo_root.join(relative_path);
    assert!(
        source_path.is_file(),
        "proof anchor path does not exist: {anchor}"
    );
    let source = std::fs::read_to_string(&source_path)
        .unwrap_or_else(|err| panic!("failed to read proof anchor source {anchor}: {err}"));
    assert!(
        source.contains(symbol),
        "proof anchor symbol does not exist in source: {anchor}"
    );
}

#[test]
fn app_parity_registry_classifies_every_human_cli_root_command() {
    let missing = unclassified_human_cli_commands();
    assert!(
        missing.is_empty(),
        "new human-facing CLI commands need CueLoopMac parity registry entries: {missing:?}"
    );
}

#[test]
fn app_parity_registry_tracks_required_scenarios_with_proof() {
    let required = [
        "run_loop_empty_queue_summary",
        "run_loop_blocked_queue_summary",
        "run_loop_failure_after_run_started",
        "run_stop_after_current_machine_contract",
        "workspace_custom_queue_path_resolution",
        "execution_controls_plugin_runner_visibility",
        "execution_controls_parallel_workers_above_menu_default",
        "continuation_next_steps_native_actions",
    ];

    for scenario in required {
        assert!(
            APP_PARITY_SCENARIO_REGISTRY
                .iter()
                .any(|entry| entry.scenario == scenario),
            "required app parity scenario is missing: {scenario}"
        );
    }
}

#[test]
fn app_parity_registry_requires_contract_and_test_anchors() {
    let issues = app_parity_scenario_coverage_issues();
    assert!(issues.is_empty(), "{}", app_parity_scenario_report());
}

#[test]
fn app_parity_registry_proof_anchors_point_to_real_tests() {
    for entry in APP_PARITY_SCENARIO_REGISTRY {
        for anchor in entry.rust_tests {
            assert_proof_anchor_exists(anchor);
        }
        for anchor in entry.app_tests {
            assert_proof_anchor_exists(anchor);
        }
    }
}

#[test]
fn cli_parses_queue_list_smoke() {
    let cli = Cli::try_parse_from(["cueloop", "queue", "list"]).expect("parse");
    match cli.command {
        Command::Queue(_) => {}
        other => panic!(
            "expected queue command, got {:?}",
            std::mem::discriminant(&other)
        ),
    }
}

#[test]
fn cli_parses_queue_archive_subcommand() {
    let cli = Cli::try_parse_from(["cueloop", "queue", "archive"]).expect("parse");
    match cli.command {
        Command::Queue(queue::QueueArgs { command }) => match command {
            queue::QueueCommand::Archive(_) => {}
            _ => panic!("expected queue archive command"),
        },
        _ => panic!("expected queue command"),
    }
}

#[test]
fn cli_rejects_invalid_prompt_phase() {
    let err = Cli::try_parse_from(["cueloop", "prompt", "worker", "--phase", "4"])
        .err()
        .expect("parse failure");
    let msg = err.to_string();
    assert!(msg.contains("invalid phase"), "unexpected error: {msg}");
}

#[test]
fn cli_parses_run_git_revert_mode() {
    let cli = Cli::try_parse_from(["cueloop", "run", "one", "--git-revert-mode", "disabled"])
        .expect("parse");
    match cli.command {
        Command::Run(args) => match args.command {
            run::RunCommand::One(args) => {
                assert_eq!(args.agent.git_revert_mode.as_deref(), Some("disabled"));
            }
            _ => panic!("expected run one command"),
        },
        _ => panic!("expected run command"),
    }
}

#[test]
fn cli_parses_run_git_publish_mode() {
    let cli =
        Cli::try_parse_from(["cueloop", "run", "one", "--git-publish-mode", "off"]).expect("parse");
    match cli.command {
        Command::Run(args) => match args.command {
            run::RunCommand::One(args) => {
                assert_eq!(args.agent.git_publish_mode.as_deref(), Some("off"));
            }
            _ => panic!("expected run one command"),
        },
        _ => panic!("expected run command"),
    }
}

#[test]
fn cli_parses_run_include_draft() {
    let cli = Cli::try_parse_from(["cueloop", "run", "one", "--include-draft"]).expect("parse");
    match cli.command {
        Command::Run(args) => match args.command {
            run::RunCommand::One(args) => {
                assert!(args.agent.include_draft);
            }
            _ => panic!("expected run one command"),
        },
        _ => panic!("expected run command"),
    }
}

#[test]
fn cli_parses_run_one_debug() {
    let cli = Cli::try_parse_from(["cueloop", "run", "one", "--debug"]).expect("parse");
    match cli.command {
        Command::Run(args) => match args.command {
            run::RunCommand::One(args) => {
                assert!(args.debug);
            }
            _ => panic!("expected run one command"),
        },
        _ => panic!("expected run command"),
    }
}

#[test]
fn cli_parses_run_loop_debug() {
    let cli = Cli::try_parse_from(["cueloop", "run", "loop", "--debug"]).expect("parse");
    match cli.command {
        Command::Run(args) => match args.command {
            run::RunCommand::Loop(args) => {
                assert!(args.debug);
            }
            _ => panic!("expected run loop command"),
        },
        _ => panic!("expected run command"),
    }
}

#[test]
fn cli_parses_machine_run_loop_parallel_override() {
    let cli = Cli::try_parse_from(["cueloop", "machine", "run", "loop", "--parallel", "3"])
        .expect("parse");
    match cli.command {
        Command::Machine(args) => match args.command {
            machine::MachineCommand::Run(args) => match args.command {
                machine::MachineRunCommand::Loop(args) => {
                    assert_eq!(args.parallel, Some(3));
                }
                _ => panic!("expected machine run loop command"),
            },
            _ => panic!("expected machine run command"),
        },
        _ => panic!("expected machine command"),
    }
}

#[test]
fn cli_parses_machine_run_loop_parallel_default_missing_value() {
    let cli =
        Cli::try_parse_from(["cueloop", "machine", "run", "loop", "--parallel"]).expect("parse");
    match cli.command {
        Command::Machine(args) => match args.command {
            machine::MachineCommand::Run(args) => match args.command {
                machine::MachineRunCommand::Loop(args) => {
                    assert_eq!(args.parallel, Some(2));
                }
                _ => panic!("expected machine run loop command"),
            },
            _ => panic!("expected machine run command"),
        },
        _ => panic!("expected machine command"),
    }
}

#[test]
fn cli_parses_machine_run_stop_dry_run() {
    let cli =
        Cli::try_parse_from(["cueloop", "machine", "run", "stop", "--dry-run"]).expect("parse");
    match cli.command {
        Command::Machine(args) => match args.command {
            machine::MachineCommand::Run(args) => match args.command {
                machine::MachineRunCommand::Stop(args) => {
                    assert!(args.dry_run);
                }
                _ => panic!("expected machine run stop command"),
            },
            _ => panic!("expected machine run command"),
        },
        _ => panic!("expected machine command"),
    }
}

#[test]
fn cli_parses_machine_task_build_input() {
    let cli = Cli::try_parse_from([
        "cueloop",
        "machine",
        "task",
        "build",
        "--input",
        "request.json",
    ])
    .expect("parse");
    match cli.command {
        Command::Machine(args) => match args.command {
            machine::MachineCommand::Task(args) => match args.command {
                machine::MachineTaskCommand::Build(args) => {
                    assert_eq!(args.input.as_deref(), Some("request.json"));
                }
                _ => panic!("expected machine task build command"),
            },
            _ => panic!("expected machine task command"),
        },
        _ => panic!("expected machine command"),
    }
}

#[test]
fn cli_parses_machine_task_insert_input() {
    let cli = Cli::try_parse_from([
        "cueloop",
        "machine",
        "task",
        "insert",
        "--input",
        "request.json",
        "--dry-run",
    ])
    .expect("parse");
    match cli.command {
        Command::Machine(args) => match args.command {
            machine::MachineCommand::Task(args) => match args.command {
                machine::MachineTaskCommand::Insert(args) => {
                    assert_eq!(args.input.as_deref(), Some("request.json"));
                    assert!(args.dry_run);
                }
                _ => panic!("expected machine task insert command"),
            },
            _ => panic!("expected machine task command"),
        },
        _ => panic!("expected machine command"),
    }
}

#[test]
fn cli_parses_run_one_id() {
    let cli = Cli::try_parse_from(["cueloop", "run", "one", "--id", "RQ-0001"]).expect("parse");
    match cli.command {
        Command::Run(args) => match args.command {
            run::RunCommand::One(args) => {
                assert_eq!(args.id.as_deref(), Some("RQ-0001"));
            }
            _ => panic!("expected run one command"),
        },
        _ => panic!("expected run command"),
    }
}

#[test]
fn cli_parses_task_update_without_id() {
    let cli = Cli::try_parse_from(["cueloop", "task", "update"]).expect("parse");
    match cli.command {
        Command::Task(args) => match args.command {
            Some(task::TaskCommand::Update(args)) => {
                assert!(args.task_id.is_none());
            }
            _ => panic!("expected task update command"),
        },
        _ => panic!("expected task command"),
    }
}

#[test]
fn cli_parses_task_update_with_id() {
    let cli = Cli::try_parse_from(["cueloop", "task", "update", "RQ-0001"]).expect("parse");
    match cli.command {
        Command::Task(args) => match args.command {
            Some(task::TaskCommand::Update(args)) => {
                assert_eq!(args.task_id.as_deref(), Some("RQ-0001"));
            }
            _ => panic!("expected task update command"),
        },
        _ => panic!("expected task command"),
    }
}

#[test]
fn cli_rejects_removed_run_one_interactive_flag_short() {
    let err = Cli::try_parse_from(["cueloop", "run", "one", "-i"])
        .err()
        .expect("parse failure");
    let msg = err.to_string().to_lowercase();
    assert!(
        msg.contains("unexpected") || msg.contains("unrecognized") || msg.contains("unknown"),
        "unexpected error: {msg}"
    );
}

#[test]
fn cli_rejects_removed_run_one_interactive_flag_long() {
    let err = Cli::try_parse_from(["cueloop", "run", "one", "--interactive"])
        .err()
        .expect("parse failure");
    let msg = err.to_string().to_lowercase();
    assert!(
        msg.contains("unexpected") || msg.contains("unrecognized") || msg.contains("unknown"),
        "unexpected error: {msg}"
    );
}

#[test]
fn cli_parses_task_default_subcommand() {
    let cli = Cli::try_parse_from(["cueloop", "task", "Add", "tests"]).expect("parse");
    match cli.command {
        Command::Task(args) => {
            assert!(args.command.is_none(), "expected implicit build subcommand");
            assert_eq!(
                args.build.request,
                vec!["Add".to_string(), "tests".to_string()]
            );
        }
        _ => panic!("expected task command"),
    }
}

#[test]
fn cli_parses_task_ready_subcommand() {
    let cli = Cli::try_parse_from(["cueloop", "task", "ready", "RQ-0005"]).expect("parse");
    match cli.command {
        Command::Task(args) => match args.command {
            Some(task::TaskCommand::Ready(args)) => {
                assert_eq!(args.task_id, "RQ-0005");
            }
            _ => panic!("expected task ready command"),
        },
        _ => panic!("expected task command"),
    }
}

#[test]
fn cli_parses_task_done_subcommand() {
    let cli = Cli::try_parse_from(["cueloop", "task", "done", "RQ-0001"]).expect("parse");
    match cli.command {
        Command::Task(args) => match args.command {
            Some(task::TaskCommand::Done(args)) => {
                assert_eq!(args.task_id, "RQ-0001");
            }
            _ => panic!("expected task done command"),
        },
        _ => panic!("expected task command"),
    }
}

#[test]
fn cli_parses_task_reject_subcommand() {
    let cli = Cli::try_parse_from(["cueloop", "task", "reject", "RQ-0002"]).expect("parse");
    match cli.command {
        Command::Task(args) => match args.command {
            Some(task::TaskCommand::Reject(args)) => {
                assert_eq!(args.task_id, "RQ-0002");
            }
            _ => panic!("expected task reject command"),
        },
        _ => panic!("expected task command"),
    }
}

#[test]
fn cli_rejects_queue_set_status_subcommand() {
    let result = Cli::try_parse_from(["cueloop", "queue", "set-status", "RQ-0001", "doing"]);
    assert!(result.is_err(), "expected queue set-status to be rejected");
    let msg = result
        .err()
        .expect("queue set-status error")
        .to_string()
        .to_lowercase();
    assert!(
        msg.contains("unrecognized") || msg.contains("unexpected") || msg.contains("unknown"),
        "unexpected error: {msg}"
    );
}

#[test]
fn cli_rejects_removed_run_loop_interactive_flag_short() {
    let err = Cli::try_parse_from(["cueloop", "run", "loop", "-i"])
        .err()
        .expect("parse failure");
    let msg = err.to_string().to_lowercase();
    assert!(
        msg.contains("unexpected") || msg.contains("unrecognized") || msg.contains("unknown"),
        "unexpected error: {msg}"
    );
}

#[test]
fn cli_rejects_removed_run_loop_interactive_flag_long() {
    let err = Cli::try_parse_from(["cueloop", "run", "loop", "--interactive"])
        .err()
        .expect("parse failure");
    let msg = err.to_string().to_lowercase();
    assert!(
        msg.contains("unexpected") || msg.contains("unrecognized") || msg.contains("unknown"),
        "unexpected error: {msg}"
    );
}

#[test]
fn cli_rejects_removed_tui_command() {
    let err = Cli::try_parse_from(["cueloop", "tui"])
        .err()
        .expect("parse failure");
    let msg = err.to_string().to_lowercase();
    assert!(
        msg.contains("unexpected") || msg.contains("unrecognized") || msg.contains("unknown"),
        "unexpected error: {msg}"
    );
}

#[test]
fn cli_rejects_run_loop_with_id_flag() {
    let err = Cli::try_parse_from(["cueloop", "run", "loop", "--id", "RQ-0001"])
        .err()
        .expect("parse failure");
    let msg = err.to_string();
    assert!(
        msg.contains("unexpected") || msg.contains("unrecognized") || msg.contains("unknown"),
        "unexpected error: {msg}"
    );
}

#[test]
fn cli_supports_top_level_version_flag_long() {
    let err = Cli::try_parse_from(["cueloop", "--version"])
        .err()
        .expect("expected clap to render version and exit");
    assert_eq!(err.kind(), ErrorKind::DisplayVersion);
    let rendered = err.to_string();
    assert!(rendered.contains("cueloop"));
    assert!(rendered.contains(env!("CARGO_PKG_VERSION")));
}

#[test]
fn cli_supports_top_level_version_flag_short() {
    let err = Cli::try_parse_from(["cueloop", "-V"])
        .err()
        .expect("expected clap to render version and exit");
    assert_eq!(err.kind(), ErrorKind::DisplayVersion);
    let rendered = err.to_string();
    assert!(rendered.contains("cueloop"));
    assert!(rendered.contains(env!("CARGO_PKG_VERSION")));
}