mahbot 0.1.1

An autonomous agentic engineering system that manages software development through role separation, subagents, and deterministic diagnostics.
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
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
//! Ticket management tools for the Manager role.
//!
//! These tools allow the Manager to create tickets on the board,
//! update their status, list them, and inspect individual tickets.

use crate::Role;
use crate::Workspace;
use crate::board::TicketPhase;
use crate::tools::Tool;
use anyhow::Result;
use async_trait::async_trait;
use serde_json::json;
use std::fmt::Write;

// ── CreateTicketTool ─────────────────────────────────────────────

/// Tool for creating tickets. The `reporter` field is set at construction
/// time based on which role is using the tool — invisible to the agent,
/// no parameter to pass.
pub struct CreateTicketTool {
    reporter: String,
}

impl CreateTicketTool {
    pub fn new(reporter: impl Into<String>) -> Self {
        Self {
            reporter: reporter.into(),
        }
    }
}

#[async_trait]
impl Tool for CreateTicketTool {
    fn name(&self) -> &'static str {
        "create_ticket"
    }

    fn parameters_schema(&self) -> serde_json::Value {
        super::tool_params_schema(
            &json!({
                "title": {
                    "type": "string",
                    "description": "Short title/summary of the task"
                },
                "description": {
                    "type": "string",
                    "description": "Detailed description of the task"
                },
                "prerequisites": {
                    "type": "array",
                    "description": "Optional list of ticket IDs that must be completed (done, archived, or cancelled) before this ticket can be claimed",
                    "items": {
                        "type": "string"
                    }
                },
                "supersede": {
                    "type": "string",
                    "description": "Optional ticket ID to supersede — atomically cancels the old ticket, creates this one as its replacement, and rewires any dependents to point to the new ID"
                },
            }),
            &["title", "description"],
        )
    }

    async fn execute(&self, ws: &Workspace, args: serde_json::Value) -> Result<String> {
        let title = super::get_str(&args, "title")?;
        let description = super::get_str(&args, "description")?;

        let prerequisites: Vec<String> = match args.get("prerequisites") {
            Some(serde_json::Value::Array(arr)) => arr
                .iter()
                .filter_map(|v| v.as_str().map(String::from))
                .collect(),
            Some(_) => {
                anyhow::bail!("prerequisites must be an array of ticket ID strings");
            }
            None => Vec::new(),
        };

        let supersede_id: Option<String> = match args.get("supersede") {
            Some(serde_json::Value::String(s)) => Some(s.clone()),
            Some(_) => anyhow::bail!("supersede must be a ticket ID string"),
            None => None,
        };

        let store = crate::board::store();
        let embedding_bytes: Option<Vec<u8>> =
            crate::embedder::embed(title, false).map(|v| crate::vector::vec_to_bytes(&v));

        let prereq_note = if prerequisites.is_empty() {
            String::new()
        } else {
            format!(" with prerequisites: {}", prerequisites.join(", "))
        };

        if let Some(supersede_id) = supersede_id {
            guard_not_pipeline_blocking(store, &supersede_id).await?;

            let id = store
                .supersede_and_create(
                    &supersede_id,
                    title,
                    description,
                    ws,
                    &prerequisites,
                    &self.reporter,
                    embedding_bytes.as_deref(),
                )
                .await?;
            Ok(format!(
                "Superseded {supersede_id} → created ticket {id}: {title}{prereq_note}"
            ))
        } else {
            let id = store
                .create_ticket(
                    title,
                    description,
                    ws,
                    TicketPhase::Backlog,
                    &prerequisites,
                    &self.reporter,
                    embedding_bytes.as_deref(),
                )
                .await?;
            Ok(format!("Created ticket {id}: {title}{prereq_note}"))
        }
    }
}

// ── UpdateTicketTool ─────────────────────────────────────────────

pub struct UpdateTicketTool;

#[async_trait]
impl Tool for UpdateTicketTool {
    fn name(&self) -> &'static str {
        "update_ticket"
    }

    fn parameters_schema(&self) -> serde_json::Value {
        super::tool_params_schema(
            &json!({
                "ticket_id": {
                    "type": "string",
                    "description": "The ticket id"
                },
                "status": {
                    "type": "string",
                    "description": "New status for the ticket. Valid manual transitions: backlog (return to queue), ready_for_development (send to engineer), paused (temporarily hold), cancelled (abandon), failed (mark unsuccessful), done (mark complete). Do NOT manually set pipeline-managed phases (analysis, planning, in_development, in_diagnostics, diagnostics_done, in_review, reviewed, in_qa, qa_passed) — the board poller handles these automatically and manual transitions will interfere with running agents."
                }
            }),
            &["ticket_id", "status"],
        )
    }

    async fn execute(&self, _ws: &Workspace, args: serde_json::Value) -> Result<String> {
        let ticket_id = super::get_str(&args, "ticket_id")?;
        let new_status = super::get_str(&args, "status")?;

        let parsed_status = parse_ticket_phase(new_status)?;

        let store = crate::board::store();

        // Guard: refuse to update a ticket that is in a pipeline-blocking phase.
        guard_not_pipeline_blocking(store, ticket_id).await?;

        store.transition_to(ticket_id, None, parsed_status).await?;

        Ok(format!(
            "Ticket {ticket_id} status updated to '{new_status}'"
        ))
    }
}

// ── ListTicketsTool ─────────────────────────────────────────────

pub struct ListTicketsTool;

#[async_trait]
impl Tool for ListTicketsTool {
    fn name(&self) -> &'static str {
        "list_tickets"
    }

    fn parameters_schema(&self) -> serde_json::Value {
        super::tool_params_schema(
            &json!({
                "status": {
                    "type": "string",
                    "description": "Optional status filter (e.g. 'ready_for_development', 'in_development', 'done', 'cancelled'). When omitted, 'done' and 'cancelled' tickets are excluded — use an explicit status filter to include them. Use 'search_archived_tickets' to find archived tickets."
                }
            }),
            &[],
        )
    }

    fn side_effects(&self, _args: &serde_json::Value) -> bool {
        false // read-only board query
    }

    async fn execute(&self, ws: &Workspace, args: serde_json::Value) -> Result<String> {
        let raw_status = super::get_opt_str(&args, "status");

        // "archived" is no longer a status — redirect to search_archived_tickets
        if let Some(s) = raw_status
            && s.eq_ignore_ascii_case("archived")
        {
            anyhow::bail!(
                "Archived tickets are not accessible via 'list_tickets'. \
                     Use 'search_archived_tickets' to search the archive."
            );
        }

        let status_filter = match raw_status {
            Some(s) => {
                let parsed = parse_ticket_phase(s)?;
                Some(parsed)
            }
            None => None,
        };

        let store = crate::board::store();

        let mut tickets = store
            .list_all_tickets(Some(&ws.name), status_filter)
            .await?;

        // Default: exclude unblocking phases. When an explicit status filter
        // is provided, respect it as-is.
        if status_filter.is_none() {
            tickets.retain(|t| !t.status.is_unblocking());
        }

        if tickets.is_empty() {
            return Ok("No tickets found.".to_string());
        }

        let mut output = String::from("Tickets:\n");
        for t in &tickets {
            let _ = writeln!(output, "{}", t.short_display());
        }

        Ok(output)
    }
}

// ── GetTicketTool ───────────────────────────────────────────────

pub struct GetTicketTool;

#[async_trait]
impl Tool for GetTicketTool {
    fn name(&self) -> &'static str {
        "get_ticket"
    }

    fn parameters_schema(&self) -> serde_json::Value {
        super::tool_params_schema(
            &json!({
                "ticket_id": {
                    "type": "string",
                    "description": "The ticket id"
                }
            }),
            &["ticket_id"],
        )
    }

    fn side_effects(&self, _args: &serde_json::Value) -> bool {
        false // read-only board query
    }

    /// Override format_output to preserve full ticket content.
    /// The default truncation at 5K chars would lose long comments/descriptions
    /// that LLMs need to read in their entirety.
    fn format_output(&self, output: &str) -> String {
        output.to_string()
    }

    async fn execute(&self, _ws: &Workspace, args: serde_json::Value) -> Result<String> {
        let ticket_id = super::get_str(&args, "ticket_id")?;

        let store = crate::board::store();

        match store.get_ticket(ticket_id).await? {
            Some(ticket) => Ok(ticket.detailed_display()),
            None => anyhow::bail!("Ticket {ticket_id} not found"),
        }
    }
}

// ── AddCommentTool ──────────────────────────────────────────────

pub struct AddCommentTool;

#[async_trait]
impl Tool for AddCommentTool {
    fn name(&self) -> &'static str {
        "add_comment"
    }

    fn parameters_schema(&self) -> serde_json::Value {
        super::tool_params_schema(
            &json!({
                "ticket_id": {
                    "type": "string",
                    "description": "The ID of the ticket to comment on"
                },
                "content": {
                    "type": "string",
                    "description": "The comment content"
                }
            }),
            &["ticket_id", "content"],
        )
    }

    async fn execute(&self, _ws: &Workspace, args: serde_json::Value) -> Result<String> {
        let ticket_id = super::get_str(&args, "ticket_id")?;
        let content = super::get_str(&args, "content")?;

        let store = crate::board::store();

        // Guard: refuse to comment on a ticket that is in a pipeline-blocking phase.
        guard_not_pipeline_blocking(store, ticket_id).await?;

        store
            .add_comment(ticket_id, Role::Manager.as_str(), content)
            .await?;

        Ok(format!("Comment added to ticket {ticket_id}"))
    }
}

/// Returns a comma-separated string of all valid [`TicketPhase`] variant names.
///
/// Used in parse-error messages across ticket tools to give agents an
/// actionable list of accepted status strings.
fn valid_phases_string() -> String {
    <TicketPhase as strum::IntoEnumIterator>::iter()
        .map(|p| p.to_string())
        .collect::<Vec<_>>()
        .join(", ")
}

/// Parse a status string into a [`TicketPhase`], returning a user-friendly
/// error message listing all valid phases on failure.
fn parse_ticket_phase(s: &str) -> Result<TicketPhase> {
    s.parse::<TicketPhase>().map_err(|_| {
        anyhow::anyhow!(
            "Invalid status '{s}'. Valid statuses: {}",
            valid_phases_string()
        )
    })
}

/// Guard: refuse to proceed if the ticket is in a pipeline-blocking phase.
/// All three user-facing ticket tools use this to prevent modifications
/// to in-flight tickets during automated pipeline processing.
async fn guard_not_pipeline_blocking(
    store: &crate::board::BoardStore,
    ticket_id: &str,
) -> Result<()> {
    if let Some(current_phase) = store.get_ticket_status(ticket_id).await?
        && current_phase.is_pipeline_blocking()
    {
        anyhow::bail!(
            "Ticket {ticket_id} is currently in phase '{status}' — \
                 in-flight tickets cannot be modified through automated tools. \
                 Use the GUI to cancel or manage this ticket manually.",
            status = current_phase.as_ref(),
        );
    }
    Ok(())
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::workspace::test_ws;
    use serde_json::json;

    // ── Unit test for parse_ticket_phase error formatting ──────────

    #[test]
    fn test_parse_ticket_phase_error_message() {
        let err = parse_ticket_phase("bogus_status").unwrap_err();
        let msg = format!("{err}");

        assert!(
            msg.contains("Invalid status"),
            "error should mention 'Invalid status'"
        );
        assert!(
            msg.contains("bogus_status"),
            "error should contain the invalid input value"
        );
        assert!(
            msg.contains("backlog"),
            "error should list valid phases (e.g. backlog)"
        );
        assert!(
            msg.contains("done"),
            "error should list valid phases (e.g. done)"
        );
    }

    #[tokio::test]
    async fn test_create_ticket_tool() {
        crate::util::test::init_test_stores().await;

        let tool = CreateTicketTool::new("test");
        let ws = test_ws("/tmp/test_ws");
        let args = json!({
            "title": "Test ticket",
            "description": "A test description",
        });
        let result = tool.execute(&ws, args).await.expect("execute");
        assert!(
            result.contains("Test ticket"),
            "Output should contain title"
        );
    }

    #[tokio::test]
    async fn test_update_ticket_tool() {
        crate::util::test::init_test_stores().await;

        let store = crate::board::store();
        let id = store
            .create_ticket(
                "Test",
                "desc",
                &test_ws("/ws"),
                crate::board::DEFAULT_TICKET_PHASE,
                &[],
                "test",
                None,
            )
            .await
            .expect("create");

        let tool = UpdateTicketTool;
        let ws = test_ws("/tmp");
        let args = json!({
            "ticket_id": id,
            "status": "in_qa"
        });
        tool.execute(&ws, args).await.expect("execute");
        let ticket = store
            .get_ticket(&id)
            .await
            .expect("get_ticket")
            .expect("ticket exists");
        assert_eq!(ticket.status, TicketPhase::InQa);
    }

    #[tokio::test]
    async fn test_list_tickets_tool() {
        crate::util::test::init_test_stores().await;

        let store = crate::board::store();
        let ws = test_ws("/tmp_ws");

        let _id_a = store
            .create_ticket(
                "A",
                "desc",
                &ws,
                crate::board::DEFAULT_TICKET_PHASE,
                &[],
                "test",
                None,
            )
            .await
            .expect("create");
        let id_b = store
            .create_ticket(
                "B",
                "desc",
                &ws,
                crate::board::DEFAULT_TICKET_PHASE,
                &[],
                "test",
                None,
            )
            .await
            .expect("create");
        let id_c = store
            .create_ticket(
                "C",
                "desc",
                &ws,
                crate::board::DEFAULT_TICKET_PHASE,
                &[],
                "test",
                None,
            )
            .await
            .expect("create");
        // Transition C to 'done' and B to 'cancelled'
        store
            .transition_to(&id_c, Some(TicketPhase::Backlog), TicketPhase::Done)
            .await
            .expect("transition to done");
        store
            .transition_to(&id_b, Some(TicketPhase::Backlog), TicketPhase::Cancelled)
            .await
            .expect("transition to cancelled");

        let tool = ListTicketsTool;

        // Default (no filter): excludes done and cancelled — only A should appear
        let args = json!({});
        let result = tool.execute(&ws, args).await.expect("execute");
        assert!(
            result.contains('A'),
            "Default listing should include active ticket A"
        );
        assert!(
            !result.contains('B'),
            "Default listing should exclude cancelled ticket B"
        );
        assert!(
            !result.contains('C'),
            "Default listing should exclude done ticket C"
        );

        // Explicit filter for 'done': includes done tickets
        let args = json!({"status": "done"});
        let result = tool.execute(&ws, args).await.expect("execute");
        assert!(
            result.contains('C'),
            "Explicit 'done' filter should include done ticket C"
        );
        assert!(
            !result.contains('A'),
            "Explicit 'done' filter should exclude active ticket A"
        );

        // Explicit filter for 'cancelled': includes cancelled tickets
        let args = json!({"status": "cancelled"});
        let result = tool.execute(&ws, args).await.expect("execute");
        assert!(
            result.contains('B'),
            "Explicit 'cancelled' filter should include cancelled ticket B"
        );

        // Filter for an active phase that ticket A is actually in
        let args = json!({"status": "backlog"});
        let result = tool.execute(&ws, args).await.expect("execute");
        assert!(
            result.contains('A'),
            "Explicit 'backlog' filter should include ticket A"
        );
    }

    #[tokio::test]
    async fn test_list_tickets_invalid_status() {
        crate::util::test::init_test_stores().await;

        let ws = crate::workspace::test_ws("/tmp");
        let tool = ListTicketsTool;
        let args = json!({"status": "bogus_status"});
        let result = tool.execute(&ws, args).await;
        assert!(result.is_err(), "Invalid status should fail");
    }

    #[tokio::test]
    async fn test_get_ticket_tool() {
        crate::util::test::init_test_stores().await;

        let store = crate::board::store();
        let id = store
            .create_ticket(
                "GetTest",
                "get me",
                &test_ws("/ws"),
                crate::board::DEFAULT_TICKET_PHASE,
                &[],
                "test",
                None,
            )
            .await
            .expect("create");

        // Fetch the ticket to compare against detailed_display()
        let ticket = crate::util::test::expect_ticket(store, &id).await;
        let expected = ticket.detailed_display();

        let tool = GetTicketTool;
        let ws = test_ws("/tmp");
        let args = json!({"ticket_id": id});
        let result = tool.execute(&ws, args).await.expect("execute");
        assert_eq!(
            result, expected,
            "GetTicketTool output must match Ticket::detailed_display()"
        );
    }

    #[tokio::test]
    async fn test_add_comment_tool() {
        crate::util::test::init_test_stores().await;

        let store = crate::board::store();
        let id = store
            .create_ticket(
                "CommentTest",
                "add a comment",
                &test_ws("/ws"),
                crate::board::DEFAULT_TICKET_PHASE,
                &[],
                "test",
                None,
            )
            .await
            .expect("create");

        let tool = AddCommentTool;
        let ws = test_ws("/tmp");
        let args = json!({
            "ticket_id": id,
            "content": "This is a test comment",
        });
        let result = tool.execute(&ws, args).await.expect("execute");
        assert!(result.contains(&id), "Output should contain ticket id");

        // Verify comment was stored
        let ticket = crate::util::test::expect_ticket(store, &id).await;
        let comment = ticket.comments.last().expect("at least one comment");
        assert_eq!(comment.role, Role::Manager.as_str());
        assert_eq!(comment.content, "This is a test comment");
    }

    #[tokio::test]
    async fn test_invalid_status() {
        crate::util::test::init_test_stores().await;

        let store = crate::board::store();
        let id = store
            .create_ticket(
                "Test",
                "desc",
                &test_ws("/ws"),
                crate::board::DEFAULT_TICKET_PHASE,
                &[],
                "test",
                None,
            )
            .await
            .expect("create");

        let tool = UpdateTicketTool;
        let ws = test_ws("/tmp");
        let args = json!({
            "ticket_id": id,
            "status": "invalid_status"
        });
        let result = tool.execute(&ws, args).await;
        assert!(result.is_err(), "Invalid status should fail");
    }

    // ── Pipeline-blocking guard tests ────────────────────────────

    #[tokio::test]
    async fn test_guard_not_pipeline_blocking_cases() {
        crate::util::test::init_test_stores().await;

        let store = crate::board::store();
        let ws = test_ws("/ws");

        let blocking_id = store
            .create_ticket(
                "BlockingGuard",
                "in development",
                &ws,
                TicketPhase::InDevelopment,
                &[],
                "test",
                None,
            )
            .await
            .expect("create");

        let nonblocking_id = store
            .create_ticket(
                "NonBlockingGuard",
                "backlog",
                &ws,
                TicketPhase::Backlog,
                &[],
                "test",
                None,
            )
            .await
            .expect("create");

        let result = guard_not_pipeline_blocking(store, &blocking_id).await;
        assert!(result.is_err(), "Blocking-phase ticket should be rejected");
        let err = format!("{}", result.unwrap_err());
        assert!(
            err.contains("in-flight"),
            "Error should mention in-flight restriction"
        );

        let result = guard_not_pipeline_blocking(store, &nonblocking_id).await;
        assert!(result.is_ok(), "Non-blocking ticket should pass the guard");

        // Non-existent ticket silently passes (nothing to block)
        let result = guard_not_pipeline_blocking(store, "nonexistent_id").await;
        assert!(
            result.is_ok(),
            "Non-existent ticket should silently pass the guard"
        );
    }

    /// Create a ticket in a pipeline-blocking phase (InDevelopment).
    /// Used by wiring tests below to verify tools call `guard_not_pipeline_blocking`.
    async fn create_blocking_ticket() -> String {
        crate::util::test::init_test_stores().await;
        let store = crate::board::store();
        store
            .create_ticket(
                "BlockMe",
                "in flight",
                &test_ws("/ws"),
                TicketPhase::InDevelopment,
                &[],
                "test",
                None,
            )
            .await
            .expect("create")
    }

    #[tokio::test]
    async fn test_update_ticket_blocked_by_pipeline() {
        let id = create_blocking_ticket().await;
        let result = UpdateTicketTool
            .execute(
                &test_ws("/tmp"),
                json!({"ticket_id": id, "status": "backlog"}),
            )
            .await;
        assert!(
            result.is_err(),
            "Pipeline-blocking ticket should reject update"
        );
    }

    #[tokio::test]
    async fn test_create_ticket_supersede_blocked_by_pipeline() {
        let id = create_blocking_ticket().await;
        let result = CreateTicketTool::new("test")
            .execute(
                &test_ws("/ws"),
                json!({"title": "Replacement", "description": "trying to supersede", "supersede": id}),
            )
            .await;
        assert!(
            result.is_err(),
            "Supersede should be rejected for pipeline-blocking tickets"
        );
    }

    #[tokio::test]
    async fn test_add_comment_blocked_by_pipeline() {
        let id = create_blocking_ticket().await;
        let result = AddCommentTool
            .execute(
                &test_ws("/tmp"),
                json!({"ticket_id": id, "content": "This should be blocked"}),
            )
            .await;
        assert!(
            result.is_err(),
            "Pipeline-blocking ticket should reject comments"
        );
    }

    #[tokio::test]
    async fn test_update_ticket_allowed_when_not_blocked() {
        crate::util::test::init_test_stores().await;

        let store = crate::board::store();
        let id = store
            .create_ticket(
                "NotBlocked",
                "backlog ticket",
                &test_ws("/ws"),
                TicketPhase::Backlog,
                &[],
                "test",
                None,
            )
            .await
            .expect("create");

        let tool = UpdateTicketTool;
        let ws = test_ws("/tmp");
        let args = json!({
            "ticket_id": id,
            "status": "done"
        });
        let result = tool.execute(&ws, args).await;
        assert!(
            result.is_ok(),
            "Non-pipeline ticket should update freely: {:?}",
            result.err()
        );
    }
}