sunox 0.0.10

Generate AI music from your terminal via direct Suno web workflows
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
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
use assert_cmd::Command;
use predicates::prelude::*;
use std::path::{Path, PathBuf};

fn isolated_test_home(prefix: &str) -> PathBuf {
    let test_home = std::env::temp_dir().join(format!("{prefix}-{}", uuid::Uuid::new_v4()));
    let _ = std::fs::remove_dir_all(&test_home);
    std::fs::create_dir_all(&test_home).expect("test home");
    test_home
}

fn with_isolated_home<'a>(cmd: &'a mut Command, test_home: &Path) -> &'a mut Command {
    cmd.env("HOME", test_home)
        .env("XDG_CONFIG_HOME", test_home.join(".config"))
        .env("XDG_DATA_HOME", test_home.join(".local").join("share"))
        .env_remove("SUNO_DEFAULT_MODEL")
        .env_remove("SUNO_POLL_INTERVAL_SECS")
        .env_remove("SUNO_POLL_TIMEOUT_SECS")
        .env_remove("SUNO_OUTPUT_DIR")
        .env_remove("SUNO_SERIAL_MUTATIONS")
}

#[test]
fn help_lists_codex_style_commands() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.arg("--help")
        .assert()
        .success()
        .stdout(predicate::str::contains("Usage: sunox [OPTIONS] [PROMPT]"))
        .stdout(predicate::str::contains("create"))
        .stdout(predicate::str::contains("download"))
        .stdout(predicate::str::contains("add"))
        .stdout(predicate::str::contains("clip"))
        .stdout(predicate::str::contains("login"))
        .stdout(predicate::str::contains("logout"))
        .stdout(predicate::str::contains("doctor"))
        .stdout(predicate::str::contains("-c, --config <key=value>"))
        .stdout(predicate::str::contains("--parallel"))
        .stdout(predicate::str::contains("generate").not());
}

#[test]
fn create_help_accepts_prompt_argument() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["create", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains(
            "Usage: sunox create [OPTIONS] [PROMPT]",
        ))
        .stdout(predicate::str::contains("--title"))
        .stdout(predicate::str::contains("--tags"))
        .stdout(predicate::str::contains("--captcha"));
}

#[test]
fn clip_help_groups_clip_subcommands() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["clip", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("Manage clips"))
        .stdout(predicate::str::contains("list"))
        .stdout(predicate::str::contains("status"))
        .stdout(predicate::str::contains("download"))
        .stdout(predicate::str::contains("upload"))
        .stdout(predicate::str::contains("timed-lyrics"));
}

#[test]
fn clip_status_reuses_existing_validation() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["clip", "status", "--json"])
        .assert()
        .failure()
        .stderr(predicate::str::contains("\"code\": \"config_error\""))
        .stderr(predicate::str::contains("no clip IDs provided"));
}

#[test]
fn login_logout_and_doctor_help_are_available() {
    for command in ["login", "logout", "doctor"] {
        let mut cmd = Command::cargo_bin("sunox").expect("binary");

        cmd.args([command, "--help"])
            .assert()
            .success()
            .stdout(predicate::str::contains("Usage:"));
    }
}

#[test]
fn help_lists_playlist_command() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.arg("--help")
        .assert()
        .success()
        .stdout(predicate::str::contains("playlist"))
        .stdout(predicate::str::contains("Manage playlists"));
}

#[test]
fn help_lists_clip_management_commands() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["clip", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("restore"))
        .stdout(predicate::str::contains("like"))
        .stdout(predicate::str::contains("dislike"));
}

#[test]
fn help_lists_upload_command() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["clip", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("upload"))
        .stdout(predicate::str::contains("Upload a local audio file"));
}

#[test]
fn upload_help_lists_workflow_flags() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["clip", "upload", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("<FILE>"))
        .stdout(predicate::str::contains("--upload-type"))
        .stdout(predicate::str::contains("--stem-mix"))
        .stdout(predicate::str::contains("--title"))
        .stdout(predicate::str::contains("--lyrics-file"))
        .stdout(predicate::str::contains("--timeout"));
}

#[test]
fn playlist_help_lists_management_subcommands() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["playlist", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("list"))
        .stdout(predicate::str::contains("info"))
        .stdout(predicate::str::contains("create"))
        .stdout(predicate::str::contains("set"))
        .stdout(predicate::str::contains("add"))
        .stdout(predicate::str::contains("remove"))
        .stdout(predicate::str::contains("publish"))
        .stdout(predicate::str::contains("reorder"))
        .stdout(predicate::str::contains("restore"))
        .stdout(predicate::str::contains("save"))
        .stdout(predicate::str::contains("unsave"))
        .stdout(predicate::str::contains("like"))
        .stdout(predicate::str::contains("dislike"))
        .stdout(predicate::str::contains("delete"));
}

#[test]
fn playlist_set_help_lists_image_url() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["playlist", "set", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("--image-url"))
        .stdout(predicate::str::contains("--image-file"));
}

#[test]
fn clip_set_help_lists_cover_options() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["clip", "set", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("--image-url"))
        .stdout(predicate::str::contains("--image-file"))
        .stdout(predicate::str::contains("--remove-video-cover"));
}

#[test]
fn clip_set_rejects_multiple_cover_sources() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args([
        "clip",
        "set",
        "clip-a",
        "--image-url",
        "https://cdn2.suno.ai/image_a.jpeg",
        "--image-file",
        "cover.png",
    ])
    .assert()
    .failure()
    .stderr(predicate::str::contains("cannot be used with"));
}

#[test]
fn persona_help_lists_management_subcommands() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["persona", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("list"))
        .stdout(predicate::str::contains("info"))
        .stdout(predicate::str::contains("clips"))
        .stdout(predicate::str::contains("create"))
        .stdout(predicate::str::contains("set"))
        .stdout(predicate::str::contains("processed-clip"))
        .stdout(predicate::str::contains("publish"))
        .stdout(predicate::str::contains("unpublish"))
        .stdout(predicate::str::contains("love"))
        .stdout(predicate::str::contains("unlove"))
        .stdout(predicate::str::contains("toggle-love"))
        .stdout(predicate::str::contains("delete"))
        .stdout(predicate::str::contains("restore"))
        .stdout(predicate::str::contains("purge"));
}

#[test]
fn create_rejects_removed_wait_flag() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args([
        "create",
        "--title",
        "Test",
        "--tags",
        "pop",
        "--lyrics",
        "[Verse]\nHello",
        "--wait",
        "--no-captcha",
    ])
    .assert()
    .failure()
    .stderr(predicate::str::contains("unexpected argument '--wait'"));
}

#[test]
fn create_rejects_removed_download_flag() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args([
        "create",
        "--title",
        "Test",
        "--tags",
        "pop",
        "--lyrics",
        "[Verse]\nHello",
        "--download",
        "./out",
        "--no-captcha",
    ])
    .assert()
    .failure()
    .stderr(predicate::str::contains("unexpected argument '--download'"));
}

#[test]
fn create_help_lists_optional_captcha_flag() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["create", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("--captcha"))
        .stdout(predicate::str::contains("[default: v5.5]").not())
        .stdout(predicate::str::contains("--variation").not());
}

#[test]
fn top_level_help_omits_removed_generate_command() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["--help"]).assert().success().stdout(
        predicate::str::contains("Generate music with custom lyrics, tags, and controls").not(),
    );
}

#[test]
fn cover_help_does_not_hardcode_generation_model_default() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["clip", "cover", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("--model"))
        .stdout(predicate::str::contains("[default: v5.5]").not());
}

#[test]
fn speed_help_exposes_live_adjust_speed_contract() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["clip", "speed", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("--multiplier"))
        .stdout(predicate::str::contains("--no-keep-pitch"))
        .stdout(predicate::str::contains("--title"));
}

#[test]
fn generate_backed_clip_commands_expose_challenge_controls() {
    for args in [
        ["clip", "cover", "--help"],
        ["clip", "extend", "--help"],
        ["clip", "stems", "--help"],
    ] {
        let mut cmd = Command::cargo_bin("sunox").expect("binary");
        cmd.args(args)
            .assert()
            .success()
            .stdout(predicate::str::contains("--token"))
            .stdout(predicate::str::contains("--captcha"))
            .stdout(predicate::str::contains("--no-captcha"));
    }
}

#[test]
fn extend_help_exposes_source_defaults_and_instrumental_overrides() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["clip", "extend", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("--title"))
        .stdout(predicate::str::contains("--exclude"))
        .stdout(predicate::str::contains("--instrumental"))
        .stdout(predicate::str::contains("--no-instrumental"));
}

#[test]
fn install_skill_prints_current_generation_guidance() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["install-skill", "--print"])
        .assert()
        .success()
        .stdout(predicate::str::contains("token=null"))
        .stdout(predicate::str::contains("--captcha"))
        .stdout(predicate::str::contains("sunox create --title"))
        .stdout(predicate::str::contains("returned clip ID"))
        .stdout(predicate::str::contains("do not pass --parallel"))
        .stdout(predicate::str::contains("simple audio analysis"))
        .stdout(predicate::str::contains(
            "current CLI download supports MP3",
        ))
        .stdout(predicate::str::contains("do not publish"))
        .stdout(predicate::str::contains("destructive commands require"))
        .stdout(predicate::str::contains("WAV"))
        .stdout(predicate::str::contains(
            "not the same as Suno Web Pro Get Stems export",
        ))
        .stdout(predicate::str::contains("error.details"))
        .stdout(predicate::str::contains("sunox clip upload <file>"))
        .stdout(predicate::str::contains("sunox clip speed <clip_id>"));
}

#[test]
fn install_skill_defaults_to_codex_skill_directory() {
    let test_home = isolated_test_home("sunox-cli-install-skill-codex-default-test");

    let mut cmd = Command::cargo_bin("sunox").expect("binary");
    with_isolated_home(&mut cmd, &test_home)
        .args(["install-skill", "--json"])
        .assert()
        .success()
        .stdout(predicate::str::contains("\"target\": \"codex\""))
        .stdout(predicate::str::contains(".codex/skills/sunox/SKILL.md"));

    let installed = test_home.join(".codex/skills/sunox/SKILL.md");
    let skill = std::fs::read_to_string(installed).expect("installed skill");
    assert!(skill.contains("sunox agent-info"));
    assert!(skill.contains("sunox clip wait"));
}

#[test]
fn install_skill_accepts_explicit_codex_target() {
    let test_home = isolated_test_home("sunox-cli-install-skill-codex-explicit-test");

    let mut cmd = Command::cargo_bin("sunox").expect("binary");
    with_isolated_home(&mut cmd, &test_home)
        .args(["install-skill", "--target", "codex", "--json"])
        .assert()
        .success()
        .stdout(predicate::str::contains("\"target\": \"codex\""))
        .stdout(predicate::str::contains(".codex/skills/sunox/SKILL.md"));
}

#[test]
fn set_rejects_empty_update_before_auth() {
    let test_home = isolated_test_home("sunox-cli-set-before-auth-test");

    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    with_isolated_home(&mut cmd, &test_home)
        .args(["clip", "set", "clip-a", "--json"])
        .assert()
        .failure()
        .stderr(predicate::str::contains("\"code\": \"config_error\""))
        .stderr(predicate::str::contains(
            "provide at least one metadata field",
        ));
}

#[test]
fn status_rejects_empty_ids_before_auth() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["clip", "status", "--json"])
        .assert()
        .failure()
        .stderr(predicate::str::contains("\"code\": \"config_error\""))
        .stderr(predicate::str::contains("no clip IDs provided"));
}

#[test]
fn download_rejects_empty_ids_before_auth() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["clip", "download", "--json"])
        .assert()
        .failure()
        .stderr(predicate::str::contains("\"code\": \"config_error\""))
        .stderr(predicate::str::contains("no clip IDs provided"));
}

#[test]
fn top_level_download_reuses_clip_download_validation() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["download", "--json"])
        .assert()
        .failure()
        .stderr(predicate::str::contains("\"code\": \"config_error\""))
        .stderr(predicate::str::contains("no clip IDs provided"));
}

#[test]
fn top_level_download_help_is_user_facing() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["download", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains(
            "Usage: sunox download [OPTIONS] [IDS]...",
        ))
        .stdout(predicate::str::contains("--output"))
        .stdout(predicate::str::contains("--video"));
}

#[test]
fn top_level_add_requires_clip_ids_before_auth() {
    let test_home = isolated_test_home("sunox-cli-add-before-auth-test");

    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    with_isolated_home(&mut cmd, &test_home)
        .args(["add", "--to", "playlist-a", "--json"])
        .assert()
        .failure()
        .stderr(predicate::str::contains("\"code\": \"config_error\""))
        .stderr(predicate::str::contains("no clip IDs provided"));
}

#[test]
fn playlist_remove_rejects_empty_ids_before_auth() {
    let test_home = isolated_test_home("sunox-cli-playlist-remove-before-auth-test");

    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    with_isolated_home(&mut cmd, &test_home)
        .args(["playlist", "remove", "playlist-a", "--json"])
        .assert()
        .failure()
        .stderr(predicate::str::contains("\"code\": \"config_error\""))
        .stderr(predicate::str::contains("no clip IDs provided"));
}

#[test]
fn clip_delete_requires_yes_before_auth() {
    let test_home = isolated_test_home("sunox-cli-clip-delete-yes-test");

    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    with_isolated_home(&mut cmd, &test_home)
        .args(["clip", "delete", "clip-a", "--json"])
        .assert()
        .failure()
        .stderr(predicate::str::contains("\"code\": \"config_error\""))
        .stderr(predicate::str::contains("requires -y/--yes"));
}

#[test]
fn playlist_delete_requires_yes_before_auth() {
    let test_home = isolated_test_home("sunox-cli-playlist-delete-yes-test");

    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    with_isolated_home(&mut cmd, &test_home)
        .args(["playlist", "delete", "playlist-a", "--json"])
        .assert()
        .failure()
        .stderr(predicate::str::contains("\"code\": \"config_error\""))
        .stderr(predicate::str::contains("requires -y/--yes"));
}

#[test]
fn persona_purge_requires_yes_before_auth() {
    let test_home = isolated_test_home("sunox-cli-persona-purge-yes-test");

    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    with_isolated_home(&mut cmd, &test_home)
        .args(["persona", "purge", "persona-a", "--json"])
        .assert()
        .failure()
        .stderr(predicate::str::contains("\"code\": \"config_error\""))
        .stderr(predicate::str::contains("requires -y/--yes"));
}

#[test]
fn playlist_set_rejects_empty_update_before_auth() {
    let test_home = isolated_test_home("sunox-cli-playlist-set-before-auth-test");

    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    with_isolated_home(&mut cmd, &test_home)
        .args(["playlist", "set", "playlist-a", "--json"])
        .assert()
        .failure()
        .stderr(predicate::str::contains("\"code\": \"config_error\""))
        .stderr(predicate::str::contains("provide at least one"));
}

#[test]
fn top_level_add_help_uses_playlist_language() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["add", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains(
            "Usage: sunox add [OPTIONS] --to <PLAYLIST_ID> [CLIP_IDS]...",
        ))
        .stdout(predicate::str::contains("--to <PLAYLIST_ID>"));
}

#[test]
fn config_set_persists_in_isolated_home() {
    let test_home = isolated_test_home("sunox-cli-config-test");

    let mut cmd = Command::cargo_bin("sunox").expect("binary");
    with_isolated_home(&mut cmd, &test_home)
        .args(["config", "set", "output_dir", "./songs", "--json"])
        .assert()
        .success()
        .stdout(predicate::str::contains("\"output_dir\": \"./songs\""));

    let mut show = Command::cargo_bin("sunox").expect("binary");
    with_isolated_home(&mut show, &test_home)
        .args(["config", "show", "--json"])
        .assert()
        .success()
        .stdout(predicate::str::contains("\"status\": \"success\""))
        .stdout(predicate::str::contains("\"data\""))
        .stdout(predicate::str::contains("\"output_dir\": \"./songs\""));
}

#[test]
fn config_show_json_uses_success_envelope() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["config", "show", "--json"])
        .assert()
        .success()
        .stdout(predicate::str::contains("\"status\": \"success\""))
        .stdout(predicate::str::contains("\"data\""))
        .stdout(predicate::str::contains("\"default_model\""))
        .stdout(predicate::str::contains("\"serial_mutations\": true"));
}

#[test]
fn config_show_applies_suno_env_overrides() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.env("SUNO_OUTPUT_DIR", "/tmp/suno-output")
        .env("SUNO_POLL_TIMEOUT_SECS", "777")
        .args(["config", "show", "--json"])
        .assert()
        .success()
        .stdout(predicate::str::contains(
            "\"output_dir\": \"/tmp/suno-output\"",
        ))
        .stdout(predicate::str::contains("\"poll_timeout_secs\": 777"));
}

#[test]
fn config_set_normalizes_default_model_version() {
    let test_home = isolated_test_home("sunox-cli-model-config-test");

    let mut cmd = Command::cargo_bin("sunox").expect("binary");
    with_isolated_home(&mut cmd, &test_home)
        .args(["config", "set", "default_model", "v5.5", "--json"])
        .assert()
        .success()
        .stdout(predicate::str::contains(
            "\"default_model\": \"chirp-fenix\"",
        ));
}

#[test]
fn global_config_override_applies_without_persisting() {
    let test_home = isolated_test_home("sunox-cli-global-config-test");

    let mut cmd = Command::cargo_bin("sunox").expect("binary");
    with_isolated_home(&mut cmd, &test_home)
        .args([
            "-c",
            "default_model=v5",
            "-c",
            "serial_mutations=false",
            "config",
            "show",
            "--json",
        ])
        .assert()
        .success()
        .stdout(predicate::str::contains(
            "\"default_model\": \"chirp-crow\"",
        ))
        .stdout(predicate::str::contains("\"serial_mutations\": false"));

    let mut show = Command::cargo_bin("sunox").expect("binary");
    with_isolated_home(&mut show, &test_home)
        .args(["config", "show", "--json"])
        .assert()
        .success()
        .stdout(predicate::str::contains(
            "\"default_model\": \"chirp-fenix\"",
        ))
        .stdout(predicate::str::contains("\"serial_mutations\": true"));
}

#[test]
fn config_check_json_reports_missing_auth_structurally() {
    let test_home = isolated_test_home("sunox-cli-config-check-test");

    let mut cmd = Command::cargo_bin("sunox").expect("binary");
    with_isolated_home(&mut cmd, &test_home)
        .args(["config", "check", "--json"])
        .assert()
        .success()
        .stdout(predicate::str::contains("\"status\": \"success\""))
        .stdout(predicate::str::contains("\"auth\""))
        .stdout(predicate::str::contains("\"ok\": false"))
        .stdout(predicate::str::contains("\"code\": \"auth_missing\""));
}

#[test]
fn agent_info_reports_submit_wait_download_workflow() {
    let mut cmd = Command::cargo_bin("sunox").expect("binary");

    cmd.args(["agent-info", "--json"])
        .assert()
        .success()
        .stdout(predicate::str::contains("\"clip wait\""))
        .stdout(predicate::str::contains("\"workflow\""))
        .stdout(predicate::str::contains("\"human_commands\""))
        .stdout(predicate::str::contains("\"machine_commands\""))
        .stdout(predicate::str::contains("\"execution_policy\""))
        .stdout(predicate::str::contains("\"agent_safety\""))
        .stdout(predicate::str::contains("\"post_submit_workflow\""))
        .stdout(predicate::str::contains("account-scoped"))
        .stdout(predicate::str::contains("do not pass --parallel"))
        .stdout(predicate::str::contains("\"audio_analysis\""))
        .stdout(predicate::str::contains("\"download_formats\""))
        .stdout(predicate::str::contains(
            "current CLI download supports MP3",
        ))
        .stdout(predicate::str::contains(
            "Suno Web exposes Pro download choices",
        ))
        .stdout(predicate::str::contains("WAV"))
        .stdout(predicate::str::contains("do not publish"))
        .stdout(predicate::str::contains("destructive commands require"))
        .stdout(predicate::str::contains("returned clip IDs"))
        .stdout(predicate::str::contains("--parallel"))
        .stdout(predicate::str::contains("partial_mutation"))
        .stdout(predicate::str::contains(
            "not the same as Suno Web Pro Get Stems export",
        ))
        .stdout(predicate::str::contains("sunox download <clip_id>"))
        .stdout(predicate::str::contains(
            "sunox add <clip_id> --to <playlist_id>",
        ))
        .stdout(predicate::str::contains(
            "submit generation or description and return clip payload",
        ))
        .stdout(predicate::str::contains(
            "poll clip ids until complete or error",
        ))
        .stdout(predicate::str::contains("download completed media"))
        .stdout(predicate::str::contains("\"v3.5\""))
        .stdout(predicate::str::contains("chirp-v3-5"))
        .stdout(predicate::str::contains("\"playlist\""))
        .stdout(predicate::str::contains("\"playlist_create\""))
        .stdout(predicate::str::contains("\"playlist_set_visibility\""))
        .stdout(predicate::str::contains("\"playlist_reorder_tracks\""))
        .stdout(predicate::str::contains("\"playlist_save\""))
        .stdout(predicate::str::contains("\"playlist_unsave\""))
        .stdout(predicate::str::contains("\"playlist_like\""))
        .stdout(predicate::str::contains("\"playlist_dislike\""))
        .stdout(predicate::str::contains("\"persona_create\""))
        .stdout(predicate::str::contains("\"persona_clips\""))
        .stdout(predicate::str::contains("\"persona_set_visibility\""))
        .stdout(predicate::str::contains("\"persona_set_metadata\""))
        .stdout(predicate::str::contains("\"persona_processed_clip\""))
        .stdout(predicate::str::contains("\"persona_love\""))
        .stdout(predicate::str::contains("\"persona_unlove\""))
        .stdout(predicate::str::contains("\"persona_toggle_love\""))
        .stdout(predicate::str::contains("\"clip_restore\""))
        .stdout(predicate::str::contains("\"clip_like\""))
        .stdout(predicate::str::contains("\"clip_dislike\""))
        .stdout(predicate::str::contains("\"clip_speed\""))
        .stdout(predicate::str::contains("\"persona_list\""))
        .stdout(predicate::str::contains("token=null"))
        .stdout(predicate::str::contains("--captcha"))
        .stdout(predicate::str::contains("\"audio_upload\""))
        .stdout(predicate::str::contains("\"persona_delete\""))
        .stdout(predicate::str::contains("\"persona_restore\""))
        .stdout(predicate::str::contains("\"persona_purge\""))
        .stdout(predicate::str::contains("\"unsupported_surfaces\""))
        .stdout(predicate::str::contains("\"image_upload\""))
        .stdout(predicate::str::contains("\"update_feedback_state\""))
        .stdout(predicate::str::contains("\"not_implemented\"").not())
        .stdout(predicate::str::contains("deprecated").not())
        .stdout(predicate::str::contains("\"config\""))
        .stdout(predicate::str::contains("\"serial_mutations\""))
        .stdout(predicate::str::contains("\"agent_targets\""))
        .stdout(predicate::str::contains("\"codex\""))
        .stdout(predicate::str::contains("~/.codex/skills/sunox/SKILL.md"))
        .stdout(predicate::str::contains(
            "sunox install-skill --target codex",
        ))
        .stdout(predicate::str::contains("clip speed"))
        .stdout(predicate::str::contains("config.toml"));
}

#[test]
fn agent_info_separates_challenge_capable_commands_from_async_edits() {
    let output = Command::cargo_bin("sunox")
        .expect("binary")
        .args(["agent-info", "--json"])
        .output()
        .expect("agent info output");
    assert!(output.status.success());
    let stdout = String::from_utf8(output.stdout).expect("utf8 stdout");
    let agent_info: serde_json::Value = serde_json::from_str(&stdout).expect("agent info json");
    let command_notes = agent_info["command_notes"]
        .as_object()
        .expect("command_notes object");

    let challenge_commands = command_notes["challenge_capable_generation_commands"]["commands"]
        .as_array()
        .expect("challenge commands");
    let challenge_commands = challenge_commands
        .iter()
        .map(|value| value.as_str().expect("command string"))
        .collect::<Vec<_>>();

    assert_eq!(
        challenge_commands,
        vec![
            "create",
            "describe",
            "clip cover",
            "clip extend",
            "clip stems"
        ]
    );
    for command in ["clip concat", "clip remaster", "clip speed"] {
        assert!(!challenge_commands.contains(&command));
    }

    let async_edits = command_notes["async_clip_edits"]["commands"]
        .as_array()
        .expect("async edit commands");
    let async_edits = async_edits
        .iter()
        .map(|value| value.as_str().expect("command string"))
        .collect::<Vec<_>>();

    for command in [
        "clip cover",
        "clip extend",
        "clip concat",
        "clip stems",
        "clip remaster",
        "clip speed",
    ] {
        assert!(async_edits.contains(&command));
    }
    let extend_notes = command_notes["clip extend"]
        .as_object()
        .expect("extend notes");
    assert_eq!(
        extend_notes["route"],
        "GET /api/feed/?ids=<clip_id>, optional POST /api/feed/v3 metadata fallback, then POST /api/generate/v2-web/"
    );
    assert!(
        extend_notes["defaults"]
            .as_str()
            .expect("extend defaults")
            .contains("source.metadata.make_instrumental")
    );
    assert!(
        extend_notes["defaults"]
            .as_str()
            .expect("extend defaults")
            .contains("source.metadata.negative_tags")
    );
    assert!(command_notes.get("generate_backed_clip_edits").is_none());
}