bamboo-server 2026.4.27

HTTP server and API layer for the Bamboo agent framework
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
use super::{AppState, DEFAULT_BASE_PROMPT};
use crate::tools::ToolSurface;
use bamboo_agent_core::tools::{FunctionCall, ToolCall, ToolError};
use bamboo_tools::permission::config::{PermissionConfig, PermissionRule, PermissionType};
use bamboo_tools::permission::storage::PermissionStorage;
use serde_json::json;

fn make_tool_call(name: &str, args: serde_json::Value) -> ToolCall {
    ToolCall {
        id: format!("call_{name}"),
        tool_type: "function".to_string(),
        function: FunctionCall {
            name: name.to_string(),
            arguments: args.to_string(),
        },
    }
}

#[test]
fn default_base_prompt_does_not_unconditionally_require_conclusion_with_options() {
    let normalized = DEFAULT_BASE_PROMPT.to_ascii_lowercase();
    assert!(!normalized.contains("before ending a task, always call conclusion_with_options"));
    assert!(!normalized.contains("do not ask final confirmation in plain assistant text"));
}
#[test]
fn default_base_prompt_prefers_using_injected_context_before_reasking() {
    assert!(DEFAULT_BASE_PROMPT.contains("treat it as available working context"));
    assert!(DEFAULT_BASE_PROMPT.contains("Prefer a minimal verifiable attempt first"));
    assert!(DEFAULT_BASE_PROMPT
        .contains("only ask follow-up questions for information that is still genuinely missing"));
}

#[tokio::test]
async fn test_app_state_creation() {
    let temp_dir = tempfile::tempdir().unwrap();
    let state = AppState::new(temp_dir.path().to_path_buf())
        .await
        .expect("app state should initialize");

    // Verify basic fields
    assert!(state.sessions.read().await.is_empty());
}

#[tokio::test]
async fn root_tools_include_server_overlays_and_session_note() {
    let temp_dir = tempfile::tempdir().unwrap();
    let state = AppState::new(temp_dir.path().to_path_buf())
        .await
        .expect("app state should initialize");
    let names: std::collections::HashSet<String> = state
        .get_all_tool_schemas()
        .into_iter()
        .map(|schema| schema.function.name)
        .collect();

    assert!(names.contains("Task"));
    assert!(names.contains("SubSession"));
    assert!(names.contains("scheduler"));
    assert!(names.contains("sub_session_manager"));
    assert!(names.contains("recall"));
    assert!(names.contains("memory"));
    assert!(names.contains("load_skill"));
    assert!(names.contains("read_skill_resource"));
    assert!(names.contains("session_note"));
}

#[tokio::test]
async fn default_first_round_tool_surface_is_smaller_than_full_root_tool_catalog() {
    let temp_dir = tempfile::tempdir().unwrap();
    let state = AppState::new(temp_dir.path().to_path_buf())
        .await
        .expect("app state should initialize");

    let full = state.get_all_tool_schemas();
    let visible: Vec<_> = full
        .iter()
        .filter(|schema| bamboo_tools::exposure::is_core_tool(&schema.function.name))
        .collect();
    let visible_names: std::collections::HashSet<&str> = visible
        .iter()
        .map(|schema| schema.function.name.as_str())
        .collect();
    eprintln!(
        "tool_surface_metrics: full={}, visible={}, hidden={}",
        full.len(),
        visible.len(),
        full.len().saturating_sub(visible.len())
    );

    assert!(
        visible.len() < full.len(),
        "expected reduced first-round surface: visible={}, full={}",
        visible.len(),
        full.len()
    );
    assert!(!visible_names.contains("scheduler"));
    assert!(!visible_names.contains("sub_session_manager"));
    assert!(!visible_names.contains("recall"));
}

#[tokio::test]
async fn child_tools_exclude_scheduler_and_recall() {
    let temp_dir = tempfile::tempdir().unwrap();
    let state = AppState::new(temp_dir.path().to_path_buf())
        .await
        .expect("app state should initialize");
    let names: std::collections::HashSet<String> = state
        .tools_for(ToolSurface::Child)
        .list_tools()
        .into_iter()
        .map(|schema| schema.function.name)
        .collect();

    assert!(!names.contains("scheduler"));
    assert!(!names.contains("sub_session_manager"));
    assert!(!names.contains("recall"));
    assert!(names.contains("memory"));
    assert!(names.contains("load_skill"));
    assert!(names.contains("read_skill_resource"));
    assert!(names.contains("session_note"));
}

#[tokio::test]
async fn overlay_tools_require_session_context() {
    let temp_dir = tempfile::tempdir().unwrap();
    let state = AppState::new(temp_dir.path().to_path_buf())
        .await
        .expect("app state should initialize");

    let schedule_result = state
        .tools_for(ToolSurface::Root)
        .execute(&make_tool_call("scheduler", json!({ "action": "list" })))
        .await;
    assert!(matches!(
        schedule_result,
        Err(ToolError::Execution(msg)) if msg.contains("session_id")
    ));

    let inspector_result = state
        .tools_for(ToolSurface::Root)
        .execute(&make_tool_call("recall", json!({ "action": "list" })))
        .await;
    assert!(matches!(
        inspector_result,
        Err(ToolError::Execution(msg)) if msg.contains("session_id")
    ));

    let memory_result = state
        .tools_for(ToolSurface::Root)
        .execute(&make_tool_call(
            "memory",
            json!({ "action": "inspect", "scope": "global" }),
        ))
        .await;
    assert!(matches!(
        memory_result,
        Err(ToolError::Execution(msg)) if msg.contains("session_id")
    ));

    let sub_session_manager_result = state
        .tools_for(ToolSurface::Root)
        .execute(&make_tool_call(
            "sub_session_manager",
            json!({ "action": "list" }),
        ))
        .await;
    assert!(matches!(
        sub_session_manager_result,
        Err(ToolError::Execution(msg)) if msg.contains("session_id")
    ));
}

#[tokio::test]
async fn memory_tool_merge_action_updates_existing_project_memory() {
    let temp_dir = tempfile::tempdir().unwrap();
    bamboo_infrastructure::paths::init_bamboo_dir(temp_dir.path().to_path_buf());
    let state = AppState::new(temp_dir.path().to_path_buf())
        .await
        .expect("app state should initialize");

    bamboo_tools::tools::workspace_state::ensure_session_workspace(
        "session-merge",
        Some(temp_dir.path().to_path_buf()),
    );

    let write_target = make_tool_call(
        "memory",
        json!({
            "action": "write",
            "scope": "project",
            "type": "project",
            "title": "Release freeze begins next week",
            "content": "Merge freeze begins on Tuesday.",
            "tags": ["release"]
        }),
    );
    let target_result = state
        .tools_for(ToolSurface::Root)
        .execute_with_context(
            &write_target,
            bamboo_agent_core::tools::ToolExecutionContext {
                session_id: Some("session-merge"),
                tool_call_id: "tool-call-write-target",
                event_tx: None,
                available_tool_schemas: None,
            },
        )
        .await
        .expect("write target should succeed");
    let target_json: serde_json::Value = serde_json::from_str(&target_result.result).unwrap();
    let target_id = target_json["memory"]["id"].as_str().unwrap().to_string();

    let write_source = make_tool_call(
        "memory",
        json!({
            "action": "write",
            "scope": "project",
            "type": "project",
            "title": "Mobile release note",
            "content": "Stakeholders confirmed freeze applies to mobile release cut.",
            "tags": ["mobile"]
        }),
    );
    let source_result = state
        .tools_for(ToolSurface::Root)
        .execute_with_context(
            &write_source,
            bamboo_agent_core::tools::ToolExecutionContext {
                session_id: Some("session-merge"),
                tool_call_id: "tool-call-write-source",
                event_tx: None,
                available_tool_schemas: None,
            },
        )
        .await
        .expect("write source should succeed");
    let source_json: serde_json::Value = serde_json::from_str(&source_result.result).unwrap();
    let source_id = source_json["memory"]["id"].as_str().unwrap().to_string();

    let merge_call = make_tool_call(
        "memory",
        json!({
            "action": "merge",
            "id": target_id,
            "content": "Additional confirmation from a later session.",
            "tags": ["confirmed"],
            "source_memory_ids": [source_id]
        }),
    );
    let merge_result = state
        .tools_for(ToolSurface::Root)
        .execute_with_context(
            &merge_call,
            bamboo_agent_core::tools::ToolExecutionContext {
                session_id: Some("session-merge"),
                tool_call_id: "tool-call-merge",
                event_tx: None,
                available_tool_schemas: None,
            },
        )
        .await
        .expect("merge should succeed");
    let merge_json: serde_json::Value = serde_json::from_str(&merge_result.result).unwrap();
    assert_eq!(merge_json["action"], "merge");
    assert_eq!(merge_json["data"]["appended"], true);
    assert_eq!(
        merge_json["data"]["superseded_ids"][0],
        source_json["memory"]["id"]
    );
}

#[tokio::test]
async fn memory_tool_write_merges_heuristically_similar_memory_when_enabled() {
    let temp_dir = tempfile::tempdir().unwrap();
    bamboo_infrastructure::paths::init_bamboo_dir(temp_dir.path().to_path_buf());
    let state = AppState::new(temp_dir.path().to_path_buf())
        .await
        .expect("app state should initialize");

    bamboo_tools::tools::workspace_state::ensure_session_workspace(
        "session-heuristic-merge",
        Some(temp_dir.path().to_path_buf()),
    );

    let original = state
        .tools_for(ToolSurface::Root)
        .execute_with_context(
            &make_tool_call(
                "memory",
                json!({
                    "action": "write",
                    "scope": "project",
                    "type": "project",
                    "title": "Release freeze begins next week",
                    "content": "Merge freeze begins on Tuesday for mobile release cut.",
                    "tags": ["release", "freeze"],
                    "options": { "allow_merge_if_similar": false }
                }),
            ),
            bamboo_agent_core::tools::ToolExecutionContext {
                session_id: Some("session-heuristic-merge"),
                tool_call_id: "tool-call-write-heuristic-original",
                event_tx: None,
                available_tool_schemas: None,
            },
        )
        .await
        .expect("original write should succeed");
    let original_json: serde_json::Value = serde_json::from_str(&original.result).unwrap();
    let original_id = original_json["memory"]["id"].as_str().unwrap().to_string();

    let merged = state
        .tools_for(ToolSurface::Root)
        .execute_with_context(
            &make_tool_call(
                "memory",
                json!({
                    "action": "write",
                    "scope": "project",
                    "type": "project",
                    "title": "Mobile release freeze starts Tuesday",
                    "content": "Stakeholders confirmed the mobile release freeze starts Tuesday.",
                    "tags": ["mobile", "release"],
                    "options": { "allow_merge_if_similar": true }
                }),
            ),
            bamboo_agent_core::tools::ToolExecutionContext {
                session_id: Some("session-heuristic-merge"),
                tool_call_id: "tool-call-write-heuristic-merge",
                event_tx: None,
                available_tool_schemas: None,
            },
        )
        .await
        .expect("heuristic merge write should succeed");
    let merged_json: serde_json::Value = serde_json::from_str(&merged.result).unwrap();
    let merged_id = merged_json["memory"]["id"].as_str().unwrap().to_string();
    assert_eq!(merged_id, original_id);

    let inspect = state
        .tools_for(ToolSurface::Root)
        .execute_with_context(
            &make_tool_call(
                "memory",
                json!({
                    "action": "inspect",
                    "scope": "project"
                }),
            ),
            bamboo_agent_core::tools::ToolExecutionContext {
                session_id: Some("session-heuristic-merge"),
                tool_call_id: "tool-call-inspect-heuristic-merge",
                event_tx: None,
                available_tool_schemas: None,
            },
        )
        .await
        .expect("inspect should succeed");
    let inspect_json: serde_json::Value = serde_json::from_str(&inspect.result).unwrap();
    assert_eq!(inspect_json["data"]["total_memories"], 1);
}

#[tokio::test]
async fn memory_tool_merge_mode_contradict_marks_memory_contradicted() {
    let temp_dir = tempfile::tempdir().unwrap();
    bamboo_infrastructure::paths::init_bamboo_dir(temp_dir.path().to_path_buf());
    let state = AppState::new(temp_dir.path().to_path_buf())
        .await
        .expect("app state should initialize");

    bamboo_tools::tools::workspace_state::ensure_session_workspace(
        "session-contradict",
        Some(temp_dir.path().to_path_buf()),
    );

    let target = state
        .tools_for(ToolSurface::Root)
        .execute_with_context(
            &make_tool_call(
                "memory",
                json!({
                    "action": "write",
                    "scope": "project",
                    "type": "project",
                    "title": "Release freeze begins next week",
                    "content": "Freeze begins on Tuesday."
                }),
            ),
            bamboo_agent_core::tools::ToolExecutionContext {
                session_id: Some("session-contradict"),
                tool_call_id: "tool-call-write-contradict-target",
                event_tx: None,
                available_tool_schemas: None,
            },
        )
        .await
        .expect("write target should succeed");
    let target_json: serde_json::Value = serde_json::from_str(&target.result).unwrap();
    let target_id = target_json["memory"]["id"].as_str().unwrap().to_string();

    let source = state
        .tools_for(ToolSurface::Root)
        .execute_with_context(
            &make_tool_call(
                "memory",
                json!({
                    "action": "write",
                    "scope": "project",
                    "type": "project",
                    "title": "Updated release note",
                    "content": "Freeze is postponed."
                }),
            ),
            bamboo_agent_core::tools::ToolExecutionContext {
                session_id: Some("session-contradict"),
                tool_call_id: "tool-call-write-contradict-source",
                event_tx: None,
                available_tool_schemas: None,
            },
        )
        .await
        .expect("write source should succeed");
    let source_json: serde_json::Value = serde_json::from_str(&source.result).unwrap();
    let source_id = source_json["memory"]["id"].as_str().unwrap().to_string();

    let contradict_result = state
        .tools_for(ToolSurface::Root)
        .execute_with_context(
            &make_tool_call(
                "memory",
                json!({
                    "action": "merge",
                    "mode": "contradict",
                    "id": target_id,
                    "content": "newer info conflicts",
                    "reason": "newer release update conflicts",
                    "source_memory_ids": [source_id]
                }),
            ),
            bamboo_agent_core::tools::ToolExecutionContext {
                session_id: Some("session-contradict"),
                tool_call_id: "tool-call-contradict",
                event_tx: None,
                available_tool_schemas: None,
            },
        )
        .await
        .expect("contradict should succeed");
    let contradict_json: serde_json::Value =
        serde_json::from_str(&contradict_result.result).unwrap();
    assert_eq!(contradict_json["action"], "merge");
    assert_eq!(contradict_json["mode"], "contradict");
    assert_eq!(contradict_json["data"]["changed"], true);
    assert_eq!(
        contradict_json["data"]["contradicted_ids"][0],
        source_json["memory"]["id"]
    );
}

#[tokio::test]
async fn memory_tool_batch_purge_archives_filtered_items() {
    let temp_dir = tempfile::tempdir().unwrap();
    bamboo_infrastructure::paths::init_bamboo_dir(temp_dir.path().to_path_buf());
    let state = AppState::new(temp_dir.path().to_path_buf())
        .await
        .expect("app state should initialize");

    bamboo_tools::tools::workspace_state::ensure_session_workspace(
        "session-batch-purge",
        Some(temp_dir.path().to_path_buf()),
    );

    let stale_write = state
        .tools_for(ToolSurface::Root)
        .execute_with_context(
            &make_tool_call(
                "memory",
                json!({
                    "action": "write",
                    "scope": "project",
                    "type": "reference",
                    "title": "Old dashboard link",
                    "content": "Legacy dashboard."
                }),
            ),
            bamboo_agent_core::tools::ToolExecutionContext {
                session_id: Some("session-batch-purge"),
                tool_call_id: "tool-call-write-stale",
                event_tx: None,
                available_tool_schemas: None,
            },
        )
        .await
        .expect("write stale memory should succeed");
    let stale_json: serde_json::Value = serde_json::from_str(&stale_write.result).unwrap();
    let stale_id = stale_json["memory"]["id"].as_str().unwrap().to_string();

    state
        .tools_for(ToolSurface::Root)
        .execute_with_context(
            &make_tool_call(
                "memory",
                json!({
                    "action": "purge",
                    "id": stale_id,
                    "mode": "stale",
                    "reason": "mark stale first"
                }),
            ),
            bamboo_agent_core::tools::ToolExecutionContext {
                session_id: Some("session-batch-purge"),
                tool_call_id: "tool-call-mark-stale",
                event_tx: None,
                available_tool_schemas: None,
            },
        )
        .await
        .expect("mark stale should succeed");

    state
        .tools_for(ToolSurface::Root)
        .execute_with_context(
            &make_tool_call(
                "memory",
                json!({
                    "action": "write",
                    "scope": "project",
                    "type": "reference",
                    "title": "Current dashboard link",
                    "content": "Current dashboard."
                }),
            ),
            bamboo_agent_core::tools::ToolExecutionContext {
                session_id: Some("session-batch-purge"),
                tool_call_id: "tool-call-write-active",
                event_tx: None,
                available_tool_schemas: None,
            },
        )
        .await
        .expect("write active memory should succeed");

    let batch_result = state
        .tools_for(ToolSurface::Root)
        .execute_with_context(
            &make_tool_call(
                "memory",
                json!({
                    "action": "purge",
                    "scope": "project",
                    "mode": "archived",
                    "reason": "archive stale references",
                    "filters": {
                        "type": ["reference"],
                        "status": ["stale"]
                    }
                }),
            ),
            bamboo_agent_core::tools::ToolExecutionContext {
                session_id: Some("session-batch-purge"),
                tool_call_id: "tool-call-batch-purge",
                event_tx: None,
                available_tool_schemas: None,
            },
        )
        .await
        .expect("batch purge should succeed");
    let batch_json: serde_json::Value = serde_json::from_str(&batch_result.result).unwrap();
    assert_eq!(batch_json["action"], "purge");
    assert_eq!(batch_json["data"]["matched_count"], 1);
}

#[tokio::test]
async fn memory_tool_inspect_and_rebuild_expose_observability_fields() {
    let temp_dir = tempfile::tempdir().unwrap();
    bamboo_infrastructure::paths::init_bamboo_dir(temp_dir.path().to_path_buf());
    let state = AppState::new(temp_dir.path().to_path_buf())
        .await
        .expect("app state should initialize");

    bamboo_tools::tools::workspace_state::ensure_session_workspace(
        "session-inspect",
        Some(temp_dir.path().to_path_buf()),
    );

    state
        .tools_for(ToolSurface::Root)
        .execute_with_context(
            &make_tool_call(
                "memory",
                json!({
                    "action": "write",
                    "scope": "project",
                    "type": "reference",
                    "title": "Old dashboard link",
                    "content": "Legacy dashboard."
                }),
            ),
            bamboo_agent_core::tools::ToolExecutionContext {
                session_id: Some("session-inspect"),
                tool_call_id: "tool-call-write-inspect",
                event_tx: None,
                available_tool_schemas: None,
            },
        )
        .await
        .expect("write memory should succeed");

    let inspect_result = state
        .tools_for(ToolSurface::Root)
        .execute_with_context(
            &make_tool_call(
                "memory",
                json!({
                    "action": "inspect",
                    "scope": "project"
                }),
            ),
            bamboo_agent_core::tools::ToolExecutionContext {
                session_id: Some("session-inspect"),
                tool_call_id: "tool-call-inspect",
                event_tx: None,
                available_tool_schemas: None,
            },
        )
        .await
        .expect("inspect should succeed");
    let inspect_json: serde_json::Value = serde_json::from_str(&inspect_result.result).unwrap();
    assert_eq!(inspect_json["action"], "inspect");
    assert!(inspect_json["data"]["index_files"].is_array());
    assert!(inspect_json["data"]["state_files"].is_array());
    assert!(inspect_json["data"]["stale_candidate_count"].is_number());
    assert!(inspect_json["data"]["last_reindex_at"].is_string());
    assert!(inspect_json["data"]["last_dream_at"].is_string());

    let rebuild_result = state
        .tools_for(ToolSurface::Root)
        .execute_with_context(
            &make_tool_call(
                "memory",
                json!({
                    "action": "rebuild",
                    "scope": "project"
                }),
            ),
            bamboo_agent_core::tools::ToolExecutionContext {
                session_id: Some("session-inspect"),
                tool_call_id: "tool-call-rebuild",
                event_tx: None,
                available_tool_schemas: None,
            },
        )
        .await
        .expect("rebuild should succeed");
    let rebuild_json: serde_json::Value = serde_json::from_str(&rebuild_result.result).unwrap();
    assert_eq!(rebuild_json["action"], "rebuild");
    assert!(rebuild_json["data"]["index_files"].is_array());
    assert!(rebuild_json["data"]["state_files"].is_array());
    assert!(rebuild_json["data"]["stale_candidate_count"].is_number());
    assert!(rebuild_json["data"]["last_reindex_at"].is_string());
    assert!(rebuild_json["data"]["last_dream_at"].is_string());
}

#[tokio::test]
async fn app_state_uses_persisted_permission_config_in_data_dir() {
    let temp_dir = tempfile::tempdir().unwrap();
    let storage = PermissionStorage::new(temp_dir.path());
    let config = PermissionConfig::new();
    config.set_enabled(true);
    config.add_rule(PermissionRule::new(PermissionType::WriteFile, "*", false));
    storage.save(&config).await.unwrap();

    let state = AppState::new(temp_dir.path().to_path_buf())
        .await
        .expect("app state should initialize");
    let target = temp_dir.path().join("blocked.txt");
    let call = make_tool_call(
        "Write",
        json!({
            "file_path": target,
            "content": "blocked"
        }),
    );

    let result = state.tools_for(ToolSurface::Root).execute(&call).await;
    assert!(matches!(result, Err(ToolError::Execution(_))));
    assert!(!target.exists());
}