beads_rust 0.2.14

Agent-first issue tracker (SQLite + JSONL)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
//! E2E tests for the `q` (quick capture) command.
//!
//! The `q` command is a shorthand for rapid issue creation that returns only the issue ID.
//! This enables scriptable workflows and fast capture.
//!
//! Test categories:
//! - Success paths: Basic functionality, flags, labels
//! - Error cases: Validation failures, uninitialized workspace
//! - Scripting integration: Pipeline usage, unique IDs, stderr behavior

mod common;

use common::cli::{BrWorkspace, extract_issues_array, extract_json_payload, run_br};
use serde_json::Value;
use std::collections::HashSet;

// =============================================================================
// Success Path Tests (8 tests)
// =============================================================================

#[test]
fn q_creates_issue_returns_id_only() {
    let _log = common::test_log("q_creates_issue_returns_id_only");
    // The q command should output only the issue ID (no "Created" prefix or other text)
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    let quick = run_br(&workspace, ["q", "Test quick capture"], "quick");
    assert!(quick.status.success(), "q failed: {}", quick.stderr);

    let output = quick.stdout.trim();
    // Should be just the ID, no other output
    assert_eq!(output.lines().count(), 1, "q should output only one line");
    assert!(
        output.contains('-'),
        "output should be an issue ID (prefix-hash format), got: {output}"
    );
    // Should not contain "Created" or other verbose text
    assert!(
        !output.to_lowercase().contains("created"),
        "q should not include 'Created' text"
    );
}

#[test]
fn q_with_type_flag() {
    let _log = common::test_log("q_with_type_flag");
    // --type bug should set the issue type correctly
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    let quick = run_br(
        &workspace,
        ["q", "Bug report", "--type", "bug"],
        "quick_type",
    );
    assert!(
        quick.status.success(),
        "q with --type failed: {}",
        quick.stderr
    );

    let id = quick.stdout.trim();

    // Verify the issue was created with the correct type
    let show = run_br(&workspace, ["show", id, "--json"], "show");
    assert!(show.status.success(), "show failed: {}", show.stderr);

    let payload = extract_json_payload(&show.stdout);
    let json: Vec<Value> = serde_json::from_str(&payload).expect("parse json");
    assert_eq!(json[0]["issue_type"], "bug", "issue type should be 'bug'");
}

#[test]
fn q_with_priority_flag() {
    let _log = common::test_log("q_with_priority_flag");
    // --priority 1 should set the priority correctly
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    let quick = run_br(
        &workspace,
        ["q", "High priority issue", "-p", "1"],
        "quick_priority",
    );
    assert!(quick.status.success(), "q with -p failed: {}", quick.stderr);

    let id = quick.stdout.trim();

    // Verify the issue was created with the correct priority
    let show = run_br(&workspace, ["show", id, "--json"], "show");
    assert!(show.status.success(), "show failed: {}", show.stderr);

    let payload = extract_json_payload(&show.stdout);
    let json: Vec<Value> = serde_json::from_str(&payload).expect("parse json");
    assert_eq!(json[0]["priority"], 1, "priority should be 1");
}

#[test]
fn q_with_all_flags() {
    let _log = common::test_log("q_with_all_flags");
    // Combine type + priority + labels
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    let quick = run_br(
        &workspace,
        [
            "q",
            "Critical bug",
            "-t",
            "bug",
            "-p",
            "0",
            "-l",
            "urgent",
            "-l",
            "regression",
        ],
        "quick_all",
    );
    assert!(
        quick.status.success(),
        "q with all flags failed: {}",
        quick.stderr
    );

    let id = quick.stdout.trim();

    // Verify all fields
    let show = run_br(&workspace, ["show", id, "--json"], "show");
    assert!(show.status.success(), "show failed: {}", show.stderr);

    let payload = extract_json_payload(&show.stdout);
    let json: Vec<Value> = serde_json::from_str(&payload).expect("parse json");
    assert_eq!(json[0]["issue_type"], "bug");
    assert_eq!(json[0]["priority"], 0);

    let labels = json[0]["labels"]
        .as_array()
        .expect("labels should be array");
    let label_names: Vec<&str> = labels.iter().filter_map(|l| l.as_str()).collect();
    assert!(
        label_names.contains(&"urgent"),
        "should have 'urgent' label"
    );
    assert!(
        label_names.contains(&"regression"),
        "should have 'regression' label"
    );
}

#[test]
fn q_with_labels() {
    let _log = common::test_log("q_with_labels");
    // Test label functionality including comma-separated values
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    // Test comma-separated labels
    let quick = run_br(
        &workspace,
        ["q", "Labeled issue", "-l", "frontend,backend,api"],
        "quick_labels",
    );
    assert!(
        quick.status.success(),
        "q with labels failed: {}",
        quick.stderr
    );

    let id = quick.stdout.trim();

    let show = run_br(&workspace, ["show", id, "--json"], "show");
    assert!(show.status.success(), "show failed: {}", show.stderr);

    let payload = extract_json_payload(&show.stdout);
    let json: Vec<Value> = serde_json::from_str(&payload).expect("parse json");

    let labels = json[0]["labels"]
        .as_array()
        .expect("labels should be array");
    assert_eq!(labels.len(), 3, "should have 3 labels");

    let label_names: Vec<&str> = labels.iter().filter_map(|l| l.as_str()).collect();
    assert!(label_names.contains(&"frontend"));
    assert!(label_names.contains(&"backend"));
    assert!(label_names.contains(&"api"));
}

#[test]
fn q_updates_last_touched_context() {
    let _log = common::test_log("q_updates_last_touched_context");
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init_q_last_touched");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    let quick = run_br(
        &workspace,
        ["q", "Quick capture updates last touched"],
        "quick_last_touched",
    );
    assert!(quick.status.success(), "q failed: {}", quick.stderr);
    let created_id = quick.stdout.trim().to_string();
    assert!(!created_id.is_empty(), "missing quick-capture id");

    let update = run_br(
        &workspace,
        ["update", "--status", "in_progress"],
        "update_last_touched_after_q",
    );
    assert!(update.status.success(), "update failed: {}", update.stderr);

    let show = run_br(
        &workspace,
        ["show", &created_id, "--json"],
        "show_last_touched_after_q",
    );
    assert!(show.status.success(), "show failed: {}", show.stderr);

    let payload = extract_json_payload(&show.stdout);
    let json: Vec<Value> = serde_json::from_str(&payload).expect("parse json");
    assert_eq!(json[0]["status"], "in_progress");
}

#[test]
fn q_multiple_words_title() {
    let _log = common::test_log("q_multiple_words_title");
    // Multiple words without quotes should be joined
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    let quick = run_br(
        &workspace,
        ["q", "This", "is", "a", "multi", "word", "title"],
        "quick_multiword",
    );
    assert!(
        quick.status.success(),
        "q with multiple words failed: {}",
        quick.stderr
    );

    let id = quick.stdout.trim();

    let show = run_br(&workspace, ["show", id, "--json"], "show");
    assert!(show.status.success(), "show failed: {}", show.stderr);

    let payload = extract_json_payload(&show.stdout);
    let json: Vec<Value> = serde_json::from_str(&payload).expect("parse json");

    // Words should be joined with spaces
    assert_eq!(
        json[0]["title"], "This is a multi word title",
        "title should be joined words"
    );
}

#[test]
fn q_output_is_valid_id() {
    let _log = common::test_log("q_output_is_valid_id");
    // Verify the output matches the expected ID format
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    let quick = run_br(&workspace, ["q", "ID format test"], "quick_id");
    assert!(quick.status.success(), "q failed: {}", quick.stderr);

    let id = quick.stdout.trim();

    // ID should match bd-XXXX format (prefix-hash)
    assert!(id.contains('-'), "ID should contain hyphen separator");
    let parts: Vec<&str> = id.split('-').collect();
    assert!(parts.len() >= 2, "ID should have prefix and hash parts");

    // The hash part should be alphanumeric (base36)
    let hash_part = parts[1..].join("-"); // In case of multiple hyphens
    assert!(
        hash_part.chars().all(|c| c.is_ascii_alphanumeric()),
        "hash part should be alphanumeric: {hash_part}"
    );
}

#[test]
fn q_issue_appears_in_list() {
    let _log = common::test_log("q_issue_appears_in_list");
    // Created issue should be visible in list output
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    let quick = run_br(&workspace, ["q", "Listable issue"], "quick_list");
    assert!(quick.status.success(), "q failed: {}", quick.stderr);

    let id = quick.stdout.trim();

    let list = run_br(&workspace, ["list", "--json"], "list");
    assert!(list.status.success(), "list failed: {}", list.stderr);

    let json = extract_issues_array(&list.stdout);

    let found = json.iter().any(|issue| issue["id"] == id);
    assert!(found, "issue {id} should appear in list output");
}

#[test]
fn q_parent_accepts_short_parent_id() {
    let _log = common::test_log("q_parent_accepts_short_parent_id");
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    let parent_create = run_br(&workspace, ["q", "Parent issue"], "q_parent");
    assert!(
        parent_create.status.success(),
        "parent q failed: {}",
        parent_create.stderr
    );
    let parent_id = parent_create.stdout.trim().to_string();
    let short_parent_id = parent_id
        .split_once('-')
        .map(|(_, hash)| hash)
        .expect("parent id should contain hash segment");

    let child_create = run_br(
        &workspace,
        ["q", "Child issue", "--parent", short_parent_id],
        "q_child_short_parent",
    );
    assert!(
        child_create.status.success(),
        "q with short parent id failed: {}",
        child_create.stderr
    );

    let child_id = child_create.stdout.trim();
    assert!(
        child_id.starts_with(&format!("{parent_id}.")),
        "child id should be generated under the resolved parent: {child_id}"
    );

    let show = run_br(&workspace, ["show", child_id, "--json"], "show_child");
    assert!(show.status.success(), "show failed: {}", show.stderr);
    let payload = extract_json_payload(&show.stdout);
    let json: Vec<Value> = serde_json::from_str(&payload).expect("parse json");
    let dependencies = json[0]["dependencies"]
        .as_array()
        .expect("dependencies should be an array");
    assert!(
        dependencies
            .iter()
            .any(|dep| { dep["id"] == parent_id && dep["dependency_type"] == "parent-child" }),
        "child should reference the resolved parent dependency: {dependencies:?}"
    );
}

// =============================================================================
// Error Cases (4 tests)
// =============================================================================

#[test]
fn q_without_init_fails() {
    let _log = common::test_log("q_without_init_fails");
    // q should fail if workspace is not initialized
    let workspace = BrWorkspace::new();

    // Do NOT run init

    let quick = run_br(&workspace, ["q", "No init"], "quick_no_init");
    assert!(
        !quick.status.success(),
        "q should fail without init, but succeeded"
    );

    // Should have error message about not being initialized
    assert!(
        quick.stderr.contains("not initialized")
            || quick.stderr.contains("Not initialized")
            || quick.stderr.contains(".beads")
            || quick.stderr.contains("init"),
        "error should mention initialization: {}",
        quick.stderr
    );
}

#[test]
fn q_empty_title_fails() {
    let _log = common::test_log("q_empty_title_fails");
    // Empty title should be rejected
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    // Try with empty string
    let quick = run_br(&workspace, ["q", ""], "quick_empty");
    assert!(
        !quick.status.success(),
        "q should fail with empty title, but succeeded"
    );

    assert!(
        quick.stderr.to_lowercase().contains("empty")
            || quick.stderr.to_lowercase().contains("title")
            || quick.stderr.to_lowercase().contains("cannot be empty"),
        "error should mention empty title: {}",
        quick.stderr
    );
}

#[test]
fn q_rejects_overlong_title_without_persisting() {
    let _log = common::test_log("q_rejects_overlong_title_without_persisting");
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    let title = "x".repeat(501);
    let quick = run_br(&workspace, ["q", title.as_str()], "quick_overlong_title");
    assert!(
        !quick.status.success(),
        "q should fail with an overlong title"
    );
    assert!(
        quick.stderr.contains("title") && quick.stderr.contains("exceeds 500"),
        "error should mention the title length limit: {}",
        quick.stderr
    );

    let list = run_br(&workspace, ["list", "--json"], "list_after_overlong_q");
    assert!(list.status.success(), "list failed: {}", list.stderr);
    let payload = extract_json_payload(&list.stdout);
    let issues = extract_issues_array(&payload);
    assert!(
        issues.is_empty(),
        "invalid quick-capture issue should not be persisted: {payload}"
    );
}

#[test]
fn q_with_custom_type_succeeds() {
    let _log = common::test_log("q_with_custom_type_succeeds");
    // br (unlike bd) allows custom issue types for flexibility
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    let quick = run_br(
        &workspace,
        ["q", "Custom type issue", "--type", "my_custom_type"],
        "quick_custom_type",
    );
    assert!(
        quick.status.success(),
        "q with custom type should succeed: {}",
        quick.stderr
    );

    // Verify the issue was created with the custom type
    let list = run_br(&workspace, ["list", "--json"], "list_check");
    assert!(list.status.success(), "list failed: {}", list.stderr);
    assert!(
        list.stdout.contains("my_custom_type"),
        "custom type should be preserved in the issue"
    );
}

#[test]
fn q_invalid_priority_fails() {
    let _log = common::test_log("q_invalid_priority_fails");
    // Out of range priority should be rejected
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    // Priority should be 0-4
    let quick = run_br(
        &workspace,
        ["q", "Bad priority", "-p", "99"],
        "quick_bad_priority",
    );
    assert!(
        !quick.status.success(),
        "q should fail with priority 99, but succeeded"
    );

    assert!(
        quick.stderr.to_lowercase().contains("priority")
            || quick.stderr.to_lowercase().contains("invalid")
            || quick.stderr.contains("99"),
        "error should mention invalid priority: {}",
        quick.stderr
    );
}

// =============================================================================
// Scripting Integration Tests (3 tests)
// =============================================================================

#[test]
fn q_output_usable_in_pipeline() {
    let _log = common::test_log("q_output_usable_in_pipeline");
    // ID can be piped to other commands (e.g., show)
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    let quick = run_br(&workspace, ["q", "Pipeline test"], "quick_pipeline");
    assert!(quick.status.success(), "q failed: {}", quick.stderr);

    let id = quick.stdout.trim();

    // The ID should work directly with show command
    let show = run_br(&workspace, ["show", id], "show_pipeline");
    assert!(
        show.status.success(),
        "show should succeed with q output: {}",
        show.stderr
    );
    assert!(
        show.stdout.contains("Pipeline test"),
        "show should display the issue title"
    );

    // Also verify it works with update
    let update = run_br(
        &workspace,
        ["update", id, "--status", "in_progress"],
        "update_pipeline",
    );
    assert!(
        update.status.success(),
        "update should succeed with q output: {}",
        update.stderr
    );
}

#[test]
fn q_multiple_creates_unique_ids() {
    let _log = common::test_log("q_multiple_creates_unique_ids");
    // Rapid creates should get unique IDs
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    let mut ids: HashSet<String> = HashSet::new();

    // Create 10 issues rapidly
    for i in 0..10 {
        let quick = run_br(
            &workspace,
            ["q", &format!("Rapid issue {i}")],
            &format!("quick_{i}"),
        );
        assert!(quick.status.success(), "q #{i} failed: {}", quick.stderr);

        let id = quick.stdout.trim().to_string();
        assert!(!id.is_empty(), "ID #{i} should not be empty");

        let is_new = ids.insert(id.clone());
        assert!(is_new, "ID {id} should be unique, but was duplicate");
    }

    assert_eq!(ids.len(), 10, "should have 10 unique IDs");

    // Verify all issues exist
    let list = run_br(&workspace, ["list", "--json"], "list_all");
    assert!(list.status.success(), "list failed: {}", list.stderr);

    let json = extract_issues_array(&list.stdout);
    assert_eq!(json.len(), 10, "should have 10 issues");
}

#[test]
fn q_silent_mode_stderr() {
    let _log = common::test_log("q_silent_mode_stderr");
    // No stderr output on success
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    let quick = run_br(&workspace, ["q", "Silent test"], "quick_silent");
    assert!(quick.status.success(), "q failed: {}", quick.stderr);

    // stderr should be empty on success (excluding debug logs if RUST_LOG is set)
    // Filter out tracing/debug output
    let stderr_lines: Vec<&str> = quick
        .stderr
        .lines()
        .filter(|line| {
            !line.contains("DEBUG")
                && !line.contains("INFO")
                && !line.contains("WARN")
                && !line.contains("TRACE")
                && !line.trim().is_empty()
        })
        .collect();

    assert!(
        stderr_lines.is_empty(),
        "stderr should be empty on success (excluding logs), got: {stderr_lines:?}"
    );
}

// =============================================================================
// Additional Edge Cases
// =============================================================================

#[test]
fn q_with_p_prefix_priority() {
    let _log = common::test_log("q_with_p_prefix_priority");
    // P0, P1, P2, P3, P4 format should work
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    let quick = run_br(
        &workspace,
        ["q", "P-format priority", "-p", "P0"],
        "quick_p_format",
    );
    assert!(
        quick.status.success(),
        "q with P0 format failed: {}",
        quick.stderr
    );

    let id = quick.stdout.trim();

    let show = run_br(&workspace, ["show", id, "--json"], "show");
    assert!(show.status.success(), "show failed: {}", show.stderr);

    let payload = extract_json_payload(&show.stdout);
    let json: Vec<Value> = serde_json::from_str(&payload).expect("parse json");
    assert_eq!(json[0]["priority"], 0, "P0 should map to priority 0");
}

#[test]
fn q_special_characters_in_title() {
    let _log = common::test_log("q_special_characters_in_title");
    // Special characters should be preserved in title
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    let title = "Fix bug: can't parse \"quotes\" & <special> chars!";
    let quick = run_br(&workspace, ["q", title], "quick_special");
    assert!(
        quick.status.success(),
        "q with special chars failed: {}",
        quick.stderr
    );

    let id = quick.stdout.trim();

    let show = run_br(&workspace, ["show", id, "--json"], "show");
    assert!(show.status.success(), "show failed: {}", show.stderr);

    let payload = extract_json_payload(&show.stdout);
    let json: Vec<Value> = serde_json::from_str(&payload).expect("parse json");
    assert_eq!(
        json[0]["title"], title,
        "special characters should be preserved"
    );
}

#[test]
fn q_default_values() {
    let _log = common::test_log("q_default_values");
    // Without flags, should use defaults (task type, medium priority)
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    let quick = run_br(&workspace, ["q", "Default values test"], "quick_defaults");
    assert!(quick.status.success(), "q failed: {}", quick.stderr);

    let id = quick.stdout.trim();

    let show = run_br(&workspace, ["show", id, "--json"], "show");
    assert!(show.status.success(), "show failed: {}", show.stderr);

    let payload = extract_json_payload(&show.stdout);
    let json: Vec<Value> = serde_json::from_str(&payload).expect("parse json");

    // Default type is task
    assert_eq!(json[0]["issue_type"], "task", "default type should be task");
    // Default priority is 2 (medium)
    assert_eq!(json[0]["priority"], 2, "default priority should be 2");
    // Status should be open
    assert_eq!(json[0]["status"], "open", "status should be open");
}

#[test]
fn q_status_is_always_open() {
    let _log = common::test_log("q_status_is_always_open");
    // q command always creates with status=open (no status flag)
    let workspace = BrWorkspace::new();

    let init = run_br(&workspace, ["init"], "init");
    assert!(init.status.success(), "init failed: {}", init.stderr);

    // Create multiple issues with different types/priorities
    let ids: Vec<String> = vec![
        run_br(&workspace, ["q", "Issue 1", "-t", "bug"], "q1"),
        run_br(&workspace, ["q", "Issue 2", "-p", "0"], "q2"),
        run_br(
            &workspace,
            ["q", "Issue 3", "-t", "feature", "-p", "1"],
            "q3",
        ),
    ]
    .into_iter()
    .filter(|r| r.status.success())
    .map(|r| r.stdout.trim().to_string())
    .collect();

    assert_eq!(ids.len(), 3, "all creates should succeed");

    // All should have status=open
    for id in ids {
        let show = run_br(&workspace, ["show", &id, "--json"], &format!("show_{id}"));
        assert!(show.status.success(), "show failed: {}", show.stderr);

        let payload = extract_json_payload(&show.stdout);
        let json: Vec<Value> = serde_json::from_str(&payload).expect("parse json");
        assert_eq!(
            json[0]["status"], "open",
            "issue {id} status should be open"
        );
    }
}