agpm-cli 0.4.12

AGent Package Manager - A Git-based package manager for coding agents
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
813
814
815
816
817
818
819
820
821
822
823
824
825
826
//! Integration tests for tool inheritance in transitive dependencies
//!
//! Tests that transitive dependencies properly inherit the tool from their parent
//! resource when not explicitly specified.

use anyhow::Result;
use tokio::fs;

use crate::common::TestProject;

/// Test that transitive dependencies inherit tool from parent resource
///
/// This test verifies that when a resource with an explicit tool (e.g., opencode)
/// has transitive dependencies declared in its frontmatter, those dependencies
/// inherit the parent's tool if not explicitly specified.
///
/// Scenario:
/// - OpenCode command declares a snippet dependency in frontmatter
/// - Snippet does not specify a tool (should inherit opencode)
/// - Command template uses {{ agpm.deps.snippets.helper.content }}
/// - Should resolve to the opencode-specific snippet, not agpm default
///
/// This test verifies the fix for a bug where transitive dependencies
/// would get the default tool for their type instead of inheriting from parent.
///
/// The fix (commit 7e22f77) merged user tool configs with built-in defaults,
/// ensuring transitive dependencies can inherit the parent's tool correctly.
#[tokio::test]
async fn test_transitive_dependency_inherits_parent_tool() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;

    // Create directory structure
    fs::create_dir_all(project.project_path().join("commands")).await?;
    fs::create_dir_all(project.project_path().join("snippets")).await?;

    // Create a snippet file that will be referenced as a transitive dependency
    let snippet_content = r#"# Helper Snippet
This is a helper snippet for commands.

## Usage
Use this snippet to help with command tasks.
"#;
    fs::write(project.project_path().join("snippets/helper.md"), snippet_content).await?;

    // Create an OpenCode command that depends on the snippet
    // The snippet dependency does NOT specify tool - should inherit opencode from parent
    let command_content = r#"---
description: Test command with transitive snippet dependency
agpm:
  templating: true
dependencies:
  snippets:
    - name: helper
      path: ../snippets/helper.md
      install: false
---

# Test Command

This command uses a helper snippet:

{{ agpm.deps.snippets.helper.content }}
"#;
    fs::write(project.project_path().join("commands/test-command.md"), command_content).await?;

    // Create manifest with opencode tool enabled and command referencing the file
    // The command has tool=opencode, so its transitive snippet dep should inherit opencode
    let manifest_content = r#"
[tools.claude-code]
path = ".claude"
resources = { commands = { path = "commands/agpm", flatten = true } }

[tools.opencode]
enabled = true
path = ".opencode"
resources = { commands = { path = "command/agpm", flatten = true } }

[tools.agpm]
path = ".agpm"
resources = { snippets = { path = "snippets" } }

[commands]
test-command = { path = "commands/test-command.md", tool = "opencode" }
"#;

    fs::write(project.project_path().join("agpm.toml"), manifest_content).await?;

    // Run install - should succeed with snippet inheriting opencode tool
    let output = project.run_agpm(&["install"])?;

    if !output.success {
        eprintln!("STDOUT:\n{}", output.stdout);
        eprintln!("STDERR:\n{}", output.stderr);
    }

    assert!(
        output.success,
        "Install should succeed when transitive dependency inherits parent tool. stderr: {}",
        output.stderr
    );

    // Verify the command was installed to opencode directory
    let command_path = project
        .project_path()
        .join(".opencode")
        .join("command")
        .join("agpm")
        .join("test-command.md");

    assert!(command_path.exists(), "OpenCode command should be installed at: {:?}", command_path);

    // Read the installed command and verify template was rendered with snippet content
    let installed_content = fs::read_to_string(&command_path).await?;

    // The template should have been rendered with the snippet content
    assert!(
        installed_content.contains("Helper Snippet"),
        "Template should be rendered with snippet content. Got:\n{}",
        installed_content
    );

    assert!(
        !installed_content.contains("{{ agpm.deps.snippets.helper.content }}"),
        "Template variable should be replaced, not left as-is. Got:\n{}",
        installed_content
    );

    // Verify lockfile records correct tool for transitive dependency
    let lockfile = project.load_lockfile()?;
    let snippet_entry = lockfile
        .snippets
        .iter()
        .find(|s| s.name == "snippets/helper")
        .ok_or_else(|| anyhow::anyhow!("Snippet 'snippets/helper' not found in lockfile"))?;

    assert_eq!(
        snippet_entry.tool,
        Some("opencode".to_string()),
        "Transitive dependency should inherit parent tool in lockfile. Got: {:?}",
        snippet_entry.tool
    );

    Ok(())
}

/// Test that explicit tool specification overrides parent inheritance
///
/// This test verifies that when a transitive dependency explicitly specifies
/// a tool, it uses that tool instead of inheriting from the parent.
///
/// Scenario:
/// - Claude Code command declares a snippet dependency
/// - Snippet explicitly specifies tool=agpm
/// - Should use agpm tool, not inherit claude-code from parent
#[tokio::test]
async fn test_transitive_dependency_explicit_tool_overrides_parent() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;

    // Create directory structure
    fs::create_dir_all(project.project_path().join("commands")).await?;
    fs::create_dir_all(project.project_path().join("snippets")).await?;

    // Create a snippet file
    let snippet_content = r#"# Config Snippet
Configuration helper snippet.
"#;
    fs::write(project.project_path().join("snippets/config.md"), snippet_content).await?;

    // Create a Claude Code command that depends on the snippet with explicit tool=agpm
    let command_content = r#"---
description: Test command with explicit tool in transitive dependency
agpm:
  templating: true
dependencies:
  snippets:
    - name: config
      path: ../snippets/config.md
      tool: agpm
      install: false
---

# Test Command

Using config: {{ agpm.deps.snippets.config.content }}
"#;
    fs::write(project.project_path().join("commands/config-cmd.md"), command_content).await?;

    // Create manifest
    let manifest_content = r#"
[tools.claude-code]
path = ".claude"
resources = { commands = { path = "commands/agpm", flatten = true } }

[tools.agpm]
path = ".agpm"
resources = { snippets = { path = "snippets" } }

[commands]
config-cmd = { path = "commands/config-cmd.md", tool = "claude-code" }
"#;

    fs::write(project.project_path().join("agpm.toml"), manifest_content).await?;

    // Run install - should succeed with explicit tool override
    let output = project.run_agpm(&["install"])?;

    if !output.success {
        eprintln!("STDOUT:\n{}", output.stdout);
        eprintln!("STDERR:\n{}", output.stderr);
    }

    assert!(
        output.success,
        "Install should succeed when transitive dependency has explicit tool. stderr: {}",
        output.stderr
    );

    // Verify the command was installed and rendered
    let command_path =
        project.project_path().join(".claude").join("commands").join("agpm").join("config-cmd.md");

    assert!(command_path.exists(), "Command should be installed");

    let installed_content = fs::read_to_string(&command_path).await?;
    assert!(
        installed_content.contains("Config Snippet"),
        "Template should be rendered with snippet content"
    );

    // Verify lockfile records correct tool for transitive dependency
    let lockfile = project.load_lockfile()?;
    let snippet_entry = lockfile
        .snippets
        .iter()
        .find(|s| s.name == "snippets/config")
        .ok_or_else(|| anyhow::anyhow!("Snippet 'snippets/config' not found in lockfile"))?;

    assert_eq!(
        snippet_entry.tool,
        Some("agpm".to_string()),
        "Transitive dependency with explicit tool should record it in lockfile. Got: {:?}",
        snippet_entry.tool
    );

    Ok(())
}

/// Test that partial tool configs are merged with defaults
///
/// This test verifies the fix for the bug where old manifests (pre-v0.4)
/// that didn't specify all resource types would fail when transitive
/// dependencies needed those missing resource types.
///
/// Scenario:
/// - OpenCode config only specifies agents and commands (old manifest style)
/// - OpenCode command has a transitive snippet dependency
/// - Snippet resource type is NOT in user config
/// - Should succeed: snippets come from merged defaults
/// - Should inherit opencode tool, not fall back to agpm
#[tokio::test]
async fn test_partial_tool_config_merges_with_defaults() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;

    // Create directory structure
    fs::create_dir_all(project.project_path().join("commands")).await?;
    fs::create_dir_all(project.project_path().join("snippets")).await?;

    // Create a snippet file
    let snippet_content = r#"# Config Helper
This is a configuration helper snippet.
"#;
    fs::write(project.project_path().join("snippets/config.md"), snippet_content).await?;

    // Create an OpenCode command with transitive snippet dependency
    let command_content = r#"---
description: Command with transitive snippet dependency
agpm:
  templating: true
dependencies:
  snippets:
    - name: config
      path: ../snippets/config.md
      install: false
---

# Setup Command

Configuration: {{ agpm.deps.snippets.config.content }}
"#;
    fs::write(project.project_path().join("commands/setup.md"), command_content).await?;

    // CRITICAL: Manifest with partial opencode config (old style)
    // Only agents and commands specified - snippets missing!
    let manifest_content = r#"
[tools.claude-code]
path = ".claude"

[tools.opencode]
enabled = true
path = ".opencode"
resources = { agents = { path = "agent/agpm", flatten = true }, commands = { path = "command/agpm", flatten = true } }

[tools.agpm]
path = ".agpm"
resources = { snippets = { path = "snippets" } }

[commands]
setup = { path = "commands/setup.md", tool = "opencode" }
"#;

    fs::write(project.project_path().join("agpm.toml"), manifest_content).await?;

    // Run install - should succeed with snippet using merged default config
    let output = project.run_agpm(&["install"])?;

    if !output.success {
        eprintln!("STDOUT:\n{}", output.stdout);
        eprintln!("STDERR:\n{}", output.stderr);
    }

    assert!(
        output.success,
        "Install should succeed when tool config is partial and merges with defaults. stderr: {}",
        output.stderr
    );

    // Verify command was installed to opencode directory
    let command_path =
        project.project_path().join(".opencode").join("command").join("agpm").join("setup.md");

    assert!(command_path.exists(), "OpenCode command should be installed");

    // Verify template was rendered with snippet content
    let installed_content = fs::read_to_string(&command_path).await?;

    assert!(
        installed_content.contains("Config Helper"),
        "Template should be rendered with snippet content (tool inherited). Got:\n{}",
        installed_content
    );

    // Verify snippet was NOT installed to agpm directory (wrong tool)
    let wrong_path = project.project_path().join(".agpm").join("snippets").join("config.md");

    assert!(
        !wrong_path.exists(),
        "Snippet should NOT be installed to agpm directory (should inherit opencode)"
    );

    // Verify lockfile records correct tool for transitive dependency
    let lockfile = project.load_lockfile()?;
    let snippet_entry = lockfile
        .snippets
        .iter()
        .find(|s| s.name == "snippets/config")
        .ok_or_else(|| anyhow::anyhow!("Snippet 'snippets/config' not found in lockfile"))?;

    assert_eq!(
        snippet_entry.tool,
        Some("opencode".to_string()),
        "Transitive dependency should inherit opencode tool in lockfile from partial config. Got: {:?}",
        snippet_entry.tool
    );

    Ok(())
}

/// Test that custom tools work correctly with transitive dependencies
///
/// Custom tools don't have built-in defaults, so they should use
/// their explicit configuration without merging.
#[tokio::test]
async fn test_custom_tool_transitive_dependency() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;

    // Create directory structure
    fs::create_dir_all(project.project_path().join("commands")).await?;
    fs::create_dir_all(project.project_path().join("snippets")).await?;

    // Create snippet
    let snippet_content = r#"# Custom Snippet
Helper for custom tool.
"#;
    fs::write(project.project_path().join("snippets/helper.md"), snippet_content).await?;

    // Create command with transitive dependency
    let command_content = r#"---
description: Custom tool command
agpm:
  templating: true
dependencies:
  snippets:
    - name: helper
      path: ../snippets/helper.md
      install: false
---

# Custom Command

Using: {{ agpm.deps.snippets.helper.content }}
"#;
    fs::write(project.project_path().join("commands/cmd.md"), command_content).await?;

    // Manifest with custom tool (not well-known)
    let manifest_content = r#"
[tools.my_custom_tool]
enabled = true
path = ".my-custom"
resources = { commands = { path = "commands", flatten = true }, snippets = { path = "snippets", flatten = false } }

[commands]
cmd = { path = "commands/cmd.md", tool = "my_custom_tool" }
"#;

    fs::write(project.project_path().join("agpm.toml"), manifest_content).await?;

    // Run install - should succeed with custom tool
    let output = project.run_agpm(&["install"])?;

    assert!(
        output.success,
        "Install should succeed for custom tool with transitive deps. stderr: {}",
        output.stderr
    );

    // Verify command installed to custom tool directory
    let command_path = project.project_path().join(".my-custom").join("commands").join("cmd.md");

    assert!(command_path.exists(), "Custom tool command should be installed");

    let content = fs::read_to_string(&command_path).await?;
    assert!(content.contains("Custom Snippet"), "Template should be rendered with snippet content");

    Ok(())
}

/// Test that transitive dependency chains inherit tool correctly
///
/// Scenario: Agent → Command → Snippet (3-level chain)
/// All without explicit tool should inherit from root agent
#[tokio::test]
async fn test_transitive_chain_inherits_tool() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;

    // Create directory structure
    fs::create_dir_all(project.project_path().join("agents")).await?;
    fs::create_dir_all(project.project_path().join("commands")).await?;
    fs::create_dir_all(project.project_path().join("snippets")).await?;

    // Level 3: Snippet (leaf node)
    let snippet_content = r#"# Base Config
Configuration values.
"#;
    fs::write(project.project_path().join("snippets/config.md"), snippet_content).await?;

    // Level 2: Command that depends on snippet
    let command_content = r#"---
description: Middle command
agpm:
  templating: true
dependencies:
  snippets:
    - name: config
      path: ../snippets/config.md
      install: false
---

# Command

Config: {{ agpm.deps.snippets.config.content }}
"#;
    fs::write(project.project_path().join("commands/helper.md"), command_content).await?;

    // Level 1: Agent that depends on command
    let agent_content = r#"---
description: Root agent
agpm:
  templating: true
dependencies:
  commands:
    - name: helper
      path: ../commands/helper.md
      install: false
---

# Agent

Helper: {{ agpm.deps.commands.helper.content }}
"#;
    fs::write(project.project_path().join("agents/root.md"), agent_content).await?;

    // Manifest with opencode tool at root
    let manifest_content = r#"
[tools.opencode]
enabled = true
path = ".opencode"
resources = { agents = { path = "agent/agpm", flatten = true }, commands = { path = "command/agpm", flatten = true } }
# Note: snippets not specified - should merge from defaults

[agents]
root = { path = "agents/root.md", tool = "opencode" }
"#;

    fs::write(project.project_path().join("agpm.toml"), manifest_content).await?;

    // Run install - entire chain should inherit opencode
    let output = project.run_agpm(&["install"])?;

    assert!(
        output.success,
        "Install should succeed with transitive chain inheritance. stderr: {}",
        output.stderr
    );

    // Verify agent installed with fully rendered chain
    let agent_path =
        project.project_path().join(".opencode").join("agent").join("agpm").join("root.md");

    assert!(agent_path.exists(), "Agent should be installed");

    let content = fs::read_to_string(&agent_path).await?;

    // Should contain content from entire chain
    assert!(
        content.contains("Base Config"),
        "Agent should have rendered content from entire dependency chain"
    );

    Ok(())
}

/// Test that transitive dependency fails when tool doesn't support resource type
///
/// This test verifies that when a tool doesn't support a resource type
/// needed by a transitive dependency, installation fails with a clear error.
#[tokio::test]
async fn test_transitive_dependency_unsupported_resource_type() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;

    // Create directory structure
    fs::create_dir_all(project.project_path().join("agents")).await?;
    fs::create_dir_all(project.project_path().join("snippets")).await?;

    // Create a snippet file
    let snippet_content = r#"# Helper Snippet
This is a helper snippet.
"#;
    fs::write(project.project_path().join("snippets/helper.md"), snippet_content).await?;

    // Create an agent that depends on the snippet
    let agent_content = r#"---
description: Agent with transitive snippet dependency
agpm:
  templating: true
dependencies:
  snippets:
    - name: helper
      path: ../snippets/helper.md
      install: false
---

# Test Agent

This agent uses a snippet: {{ agpm.deps.snippets.helper.content }}
"#;
    fs::write(project.project_path().join("agents/test-agent.md"), agent_content).await?;

    // Create manifest with custom tool that only supports agents (not snippets)
    let manifest_content = r#"
[tools.claude-code]
path = ".claude"
resources = { agents = { path = "agents", flatten = true } }

[tools.my_custom_tool]
enabled = true
path = ".my-custom"
resources = { agents = { path = "agents", flatten = true } }
# IMPORTANT: No snippets configured for my_custom_tool

[agents]
test-agent = { path = "agents/test-agent.md", tool = "my_custom_tool" }
"#;

    fs::write(project.project_path().join("agpm.toml"), manifest_content).await?;

    // Run install - should fail because my_custom_tool doesn't support snippets
    let output = project.run_agpm(&["install"])?;

    assert!(
        !output.success,
        "Install should fail when tool doesn't support required resource type"
    );

    assert!(
        output.stderr.contains("does not support resource type")
            || output.stderr.contains("unsupported")
            || output.stderr.contains("snippets"),
        "Error should mention unsupported resource type. Got: {}",
        output.stderr
    );

    Ok(())
}

/// Test that circular dependencies in transitive chain are detected
///
/// This test verifies that circular dependencies are properly detected
/// even when they span multiple levels of transitive dependencies.
#[tokio::test]
async fn test_transitive_circular_dependency_detection() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;

    // Create directory structure
    fs::create_dir_all(project.project_path().join("agents")).await?;
    fs::create_dir_all(project.project_path().join("commands")).await?;
    fs::create_dir_all(project.project_path().join("snippets")).await?;

    // Level 3: Snippet that depends on Agent A (creates cycle)
    let snippet_content = r#"---
description: Snippet that depends on agent (creates cycle)
agpm:
  templating: true
dependencies:
  agents:
    - name: root-agent
      path: ../agents/root-agent.md
      install: false
---

# Cycle Snippet

This snippet creates a cycle back to agent.
"#;
    fs::write(project.project_path().join("snippets/cycle.md"), snippet_content).await?;

    // Level 2: Command that depends on snippet
    let command_content = r#"---
description: Command that depends on snippet
agpm:
  templating: true
dependencies:
  snippets:
    - name: cycle
      path: ../snippets/cycle.md
      install: false
---

# Middle Command

This command uses cycle snippet: {{ agpm.deps.snippets.cycle.content }}
"#;
    fs::write(project.project_path().join("commands/middle.md"), command_content).await?;

    // Level 1: Agent that depends on command
    let agent_content = r#"---
description: Root agent in cycle
agpm:
  templating: true
dependencies:
  commands:
    - name: middle
      path: ../commands/middle.md
      install: false
---

# Root Agent

This agent uses middle command: {{ agpm.deps.commands.middle.content }}
"#;
    fs::write(project.project_path().join("agents/root-agent.md"), agent_content).await?;

    // Manifest that creates the cycle: Agent -> Command -> Snippet -> Agent
    let manifest_content = r#"
[tools.claude-code]
path = ".claude"
resources = { agents = { path = "agents", flatten = true } }

[agents]
root-agent = { path = "agents/root-agent.md", tool = "claude-code" }
"#;

    fs::write(project.project_path().join("agpm.toml"), manifest_content).await?;

    // Run install - should detect circular dependency
    let output = project.run_agpm(&["install"])?;

    assert!(!output.success, "Install should fail when circular dependency is detected");

    assert!(
        output.stderr.contains("Circular dependency") || output.stderr.contains("circular"),
        "Error should mention circular dependency. Got: {}",
        output.stderr
    );

    Ok(())
}

/// Test that missing transitive dependency files are handled gracefully
///
/// This test verifies that when a transitive dependency references
/// a non-existent file, installation fails with a clear error.
#[tokio::test]
async fn test_transitive_dependency_file_not_found() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;

    // Create directory structure
    fs::create_dir_all(project.project_path().join("commands")).await?;
    // Note: NOT creating snippets directory - file should be missing

    // Create a command that depends on a non-existent snippet
    let command_content = r#"---
description: Command with missing transitive dependency
agpm:
  templating: true
dependencies:
  snippets:
    - name: missing
      path: ../snippets/missing.md
      install: false
---

# Test Command

This command tries to use a missing snippet: {{ agpm.deps.snippets.missing.content }}
"#;
    fs::write(project.project_path().join("commands/test.md"), command_content).await?;

    // Simple manifest
    let manifest_content = r#"
[tools.claude-code]
path = ".claude"
resources = { commands = { path = "commands", flatten = true } }

[commands]
test = { path = "commands/test.md", tool = "claude-code" }
"#;

    fs::write(project.project_path().join("agpm.toml"), manifest_content).await?;

    // Run install - should fail because snippet file doesn't exist
    let output = project.run_agpm(&["install"])?;

    assert!(!output.success, "Install should fail when transitive dependency file is not found");

    assert!(
        output.stderr.contains("not found")
            || output.stderr.contains("No such file")
            || output.stderr.contains("does not exist")
            || output.stderr.contains("missing.md")
            || output.stderr.contains("file access")
            || output.stderr.contains("Failed to file access"),
        "Error should mention missing file. Got: {}",
        output.stderr
    );

    Ok(())
}

/// Test that malformed tool configurations are detected
///
/// This test verifies that malformed tool configurations in manifest
/// result in clear error messages during installation.
#[tokio::test]
async fn test_malformed_tool_configuration() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;

    // Create directory structure
    fs::create_dir_all(project.project_path().join("agents")).await?;

    // Create a simple agent
    let agent_content = r#"# Simple Agent
This is a test agent.
"#;
    fs::write(project.project_path().join("agents/simple.md"), agent_content).await?;

    // Manifest with malformed tool configuration (missing required 'path' field)
    let manifest_content = r#"
[tools.claude-code]
# Missing 'path' field - this is malformed
resources = { agents = { path = "agents" }

[tools.malformed_tool]
enabled = true
# Missing both 'path' and 'resources' fields - completely invalid

[agents]
simple = { path = "agents/simple.md", tool = "claude-code" }
"#;

    fs::write(project.project_path().join("agpm.toml"), manifest_content).await?;

    // Run install - should fail due to malformed tool configuration
    let output = project.run_agpm(&["install"])?;

    assert!(!output.success, "Install should fail when tool configuration is malformed");

    assert!(
        output.stderr.contains("missing field")
            || output.stderr.contains("required")
            || output.stderr.contains("path")
            || output.stderr.contains("invalid")
            || output.stderr.contains("malformed"),
        "Error should mention configuration issue. Got: {}",
        output.stderr
    );

    Ok(())
}