agpm-cli 0.4.14

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
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
//! Tests for basic template rendering functionality.
//!
//! Covers:
//! - Simple variable substitution
//! - Template syntax validation
//! - Basic resource information injection
//! - Literal block handling

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

use crate::common::{ManifestBuilder, TestProject};

/// Test basic template variable substitution in markdown files.
#[tokio::test]
async fn test_basic_template_substitution() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;
    let test_repo = project.create_source_repo("test-repo").await?;

    // Create an agent with template variables
    test_repo
        .add_resource(
            "agents",
            "test-agent",
            r#"---
title: Test Agent
agpm:
  templating: true
---
# {{ agpm.resource.name }}

This agent is installed at: `{{ agpm.resource.install_path }}`
Version: {{ agpm.resource.version }}
"#,
        )
        .await?;

    test_repo.commit_all("Add test agent")?;
    test_repo.tag_version("v1.0.0")?;

    let repo_url = test_repo.bare_file_url(project.sources_path()).await?;

    // Create manifest
    let manifest = ManifestBuilder::new()
        .add_source("test-repo", &repo_url)
        .add_agent("test-agent", |d| {
            d.source("test-repo").path("agents/test-agent.md").version("v1.0.0")
        })
        .build();

    project.write_manifest(&manifest).await?;

    // Install - templating enabled via frontmatter
    let output = project.run_agpm(&["install"])?;
    assert!(output.success);

    // Read the installed file and verify template variables were replaced
    let installed_path = project.project_path().join(".claude/agents/agpm/test-agent.md");
    let content = fs::read_to_string(&installed_path).await?;

    // Verify variables were substituted - name includes resource type directory
    assert!(
        content.contains("# agents/test-agent"),
        "Resource name should be substituted with canonical format"
    );

    // Check for platform-native path separators
    #[cfg(windows)]
    let expected_path = "installed at: `.claude\\agents\\agpm\\test-agent.md`";
    #[cfg(not(windows))]
    let expected_path = "installed at: `.claude/agents/agpm/test-agent.md`";

    assert!(
        content.contains(expected_path),
        "Install path should be substituted with platform-native separators. Content:\n{}",
        content
    );
    assert!(content.contains("Version: v1.0.0"), "Version should be substituted");

    // Verify original template syntax is gone
    assert!(!content.contains("{{ agpm"), "Template syntax should be replaced");

    Ok(())
}

/// Test that files without templating enabled can contain template-like syntax.
///
/// This is critical for snippets containing JSDoc or other documentation that uses
/// curly braces (e.g., `@param {{id: number, name: string}} user`).
#[tokio::test]
async fn test_non_templated_files_with_curly_braces() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;
    let test_repo = project.create_source_repo("test-repo").await?;

    // Create a snippet with JSDoc-style syntax but NO templating enabled
    // This should install successfully without attempting to parse the {{ }} as templates
    test_repo
        .add_resource(
            "snippets",
            "javascript-snippet",
            r#"---
title: JavaScript Snippet
---
// JavaScript code with arrow functions
const calculateSum = (a, b) => {
    return a + b;
};

// Template literal syntax in JavaScript
const message = `Hello, ${name}!`;

// Object destructuring
const { firstName, lastName } = person;

// Array destructuring with rest
const [first, ...rest] = items;

console.log(calculateSum(5, 3));
console.log(message);
console.log(firstName, lastName);
console.log(first, rest);
"#,
        )
        .await?;

    test_repo.commit_all("Add JavaScript snippet")?;
    test_repo.tag_version("v1.0.0")?;

    let repo_url = test_repo.bare_file_url(project.sources_path()).await?;

    // Create manifest
    let manifest = ManifestBuilder::new()
        .add_source("test-repo", &repo_url)
        .add_snippet("javascript-snippet", |d| {
            d.source("test-repo")
                .path("snippets/javascript-snippet.md")
                .version("v1.0.0")
                .tool("agpm")
        })
        .build();

    project.write_manifest(&manifest).await?;

    // Install the snippet
    let output = project.run_agpm(&["install"])?;
    assert!(output.success, "Install should succeed");

    // Read the installed file and verify it wasn't processed as a template
    let installed_path = project.project_path().join(".agpm/snippets/javascript-snippet.md");
    let content = fs::read_to_string(&installed_path).await?;

    // Verify JavaScript syntax is preserved exactly
    assert!(content.contains("const calculateSum = (a, b) => {"));
    assert!(content.contains("const message = `Hello, ${name}!`;"));
    assert!(content.contains("const { firstName, lastName } = person;"));
    assert!(content.contains("const [first, ...rest] = items;"));
    assert!(content.contains("console.log(calculateSum(5, 3));"));

    Ok(())
}

/// Test that resources can reference each other via templates.
#[tokio::test]
async fn test_dependency_references() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;
    let test_repo = project.create_source_repo("test-repo").await?;

    // Create a helper snippet first
    test_repo
        .add_resource(
            "snippets",
            "helper",
            r#"---
title: Helper Functions
agpm:
  templating: true
---
# Helper Functions

This file contains helper functions.

## Function List
- sum
- multiply
- divide
"#,
        )
        .await?;

    // Create an agent that references the snippet via content filter
    test_repo
        .add_resource(
            "agents",
            "main-agent",
            r#"---
title: Main Agent
dependencies:
  snippets:
    - path: snippets/helper.md
      tool: agpm
      name: helper
agpm:
  templating: true
---
# Main Agent

This agent uses helper functions from snippets.

{{ agpm.deps.snippets.helper.content }}

## Usage

See helper functions above.
"#,
        )
        .await?;

    test_repo.commit_all("Add agent and snippet")?;
    test_repo.tag_version("v1.0.0")?;

    let repo_url = test_repo.bare_file_url(project.sources_path()).await?;

    // Create manifest with both dependencies
    let manifest = ManifestBuilder::new()
        .add_source("test-repo", &repo_url)
        .add_snippet("helper", |d| {
            d.source("test-repo").path("snippets/helper.md").version("v1.0.0").tool("agpm")
        })
        .add_agent("main-agent", |d| {
            d.source("test-repo").path("agents/main-agent.md").version("v1.0.0")
        })
        .build();

    project.write_manifest(&manifest).await?;

    // Install both resources
    let output = project.run_agpm(&["install"])?;
    assert!(output.success, "Install should succeed. stderr: {}", output.stderr);

    // Read the installed agent file
    let agent_path = project.project_path().join(".claude/agents/agpm/main-agent.md");
    let content = fs::read_to_string(&agent_path).await?;

    // Verify snippet content was embedded
    assert!(content.contains("# Helper Functions"));
    assert!(content.contains("## Function List"));
    assert!(content.contains("- sum"));
    assert!(content.contains("- multiply"));
    assert!(content.contains("- divide"));

    Ok(())
}

/// Test that templating is disabled by default and can be explicitly disabled.
///
/// Tests two scenarios in one:
/// 1. No frontmatter flag - template syntax preserved by default
/// 2. Explicit `templating: false` - template syntax preserved
#[tokio::test]
async fn test_templating_disabled_preserves_syntax() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;
    let test_repo = project.create_source_repo("test-repo").await?;

    // Agent with no templating flag (tests default behavior)
    test_repo
        .add_resource(
            "agents",
            "default-agent",
            r#"---
title: Default Agent
---
# {{ agpm.resource.name }}

Install path: {{ agpm.resource.install_path }}
"#,
        )
        .await?;

    // Agent with explicit templating: false
    test_repo
        .add_resource(
            "agents",
            "explicit-disabled",
            r#"---
title: Explicit Disabled Agent
agpm:
  templating: false
---
# Agent with Literal Syntax

This file contains literal template syntax: {{ agpm.resource.name }}
"#,
        )
        .await?;

    test_repo.commit_all("Add agents")?;
    test_repo.tag_version("v1.0.0")?;

    let repo_url = test_repo.bare_file_url(project.sources_path()).await?;

    let manifest = ManifestBuilder::new()
        .add_source("test-repo", &repo_url)
        .add_agent("default-agent", |d| {
            d.source("test-repo").path("agents/default-agent.md").version("v1.0.0")
        })
        .add_agent("explicit-disabled", |d| {
            d.source("test-repo").path("agents/explicit-disabled.md").version("v1.0.0")
        })
        .build();

    project.write_manifest(&manifest).await?;

    let output = project.run_agpm(&["install"])?;
    assert!(output.success);

    // Verify default behavior (no frontmatter flag)
    let default_path = project.project_path().join(".claude/agents/agpm/default-agent.md");
    let default_content = fs::read_to_string(&default_path).await?;
    assert!(
        default_content.contains("# {{ agpm.resource.name }}"),
        "Template syntax should remain literal by default"
    );
    assert!(
        default_content.contains("{{ agpm.resource.install_path }}"),
        "All template syntax should be preserved by default"
    );

    // Verify explicit disable (templating: false)
    let explicit_path = project.project_path().join(".claude/agents/agpm/explicit-disabled.md");
    let explicit_content = fs::read_to_string(&explicit_path).await?;
    assert!(
        explicit_content.contains("{{ agpm.resource.name }}"),
        "Template syntax should remain literal when templating is explicitly disabled"
    );

    Ok(())
}

/// Test that files without template syntax are unchanged.
#[tokio::test]
async fn test_no_template_syntax() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;
    let test_repo = project.create_source_repo("test-repo").await?;

    // Create a file without any template syntax but with templating enabled
    test_repo
        .add_resource(
            "agents",
            "plain-agent",
            r#"---
title: Plain Agent
agpm:
  templating: true
---
# Plain Agent

This agent has no template syntax.

## Features

- Feature 1
- Feature 2
- Feature 3

## Usage

Just use it normally.
"#,
        )
        .await?;

    test_repo.commit_all("Add plain agent")?;
    test_repo.tag_version("v1.0.0")?;

    let repo_url = test_repo.bare_file_url(project.sources_path()).await?;

    let manifest = ManifestBuilder::new()
        .add_source("test-repo", &repo_url)
        .add_agent("plain-agent", |d| {
            d.source("test-repo").path("agents/plain-agent.md").version("v1.0.0")
        })
        .build();

    project.write_manifest(&manifest).await?;

    let output = project.run_agpm(&["install"])?;
    assert!(output.success, "Install should succeed");

    // Read the installed file
    let installed_path = project.project_path().join(".claude/agents/agpm/plain-agent.md");
    let content = fs::read_to_string(&installed_path).await?;

    // Verify content is unchanged
    assert!(content.contains("# Plain Agent"));
    assert!(content.contains("This agent has no template syntax."));
    assert!(content.contains("- Feature 1"));
    assert!(content.contains("Just use it normally."));

    Ok(())
}

/// Test conditional rendering with {% if %} blocks.
#[tokio::test]
async fn test_conditional_rendering() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;
    let test_repo = project.create_source_repo("test-repo").await?;

    test_repo
        .add_resource(
            "agents",
            "conditional",
            r#"---
title: Conditional Agent
agpm:
  templating: true
---
# Conditional Content

{% if agpm.resource.source %}
This resource is from source: {{ agpm.resource.source }}
{% else %}
This is a local resource.
{% endif %}

{% if agpm.resource.version %}
Version: {{ agpm.resource.version }}
{% endif %}
"#,
        )
        .await?;

    test_repo.commit_all("Add agent")?;
    test_repo.tag_version("v1.0.0")?;

    let repo_url = test_repo.bare_file_url(project.sources_path()).await?;

    let manifest = ManifestBuilder::new()
        .add_source("test-repo", &repo_url)
        .add_agent("conditional", |d| {
            d.source("test-repo").path("agents/conditional.md").version("v1.0.0")
        })
        .build();

    project.write_manifest(&manifest).await?;

    let output = project.run_agpm(&["install"])?;
    assert!(output.success);

    let installed_path = project.project_path().join(".claude/agents/agpm/conditional.md");
    let content = fs::read_to_string(&installed_path).await?;

    // Verify conditional blocks were processed
    assert!(
        content.contains("This resource is from source: test-repo"),
        "Conditional block should render when condition is true"
    );
    assert!(!content.contains("This is a local resource"), "Alternative block should not render");
    assert!(
        content.contains("Version: v1.0.0"),
        "Optional block should render when variable exists"
    );

    Ok(())
}

/// Test loop over dependencies with {% for %} blocks.
#[tokio::test]
async fn test_loop_over_dependencies() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;
    let test_repo = project.create_source_repo("test-repo").await?;

    // Create multiple snippets
    test_repo
        .add_resource(
            "snippets",
            "helper1",
            r#"---
title: Helper 1
agpm:
  templating: true
---
# Helper 1

This is helper 1.
"#,
        )
        .await?;

    test_repo
        .add_resource(
            "snippets",
            "helper2",
            r#"---
title: Helper 2
agpm:
  templating: true
---
# Helper 2

This is helper 2.
"#,
        )
        .await?;

    test_repo
        .add_resource(
            "snippets",
            "helper3",
            r#"---
title: Helper 3
agpm:
  templating: true
---
# Helper 3

This is helper 3.
"#,
        )
        .await?;

    // Create an agent that loops over snippets
    test_repo
        .add_resource(
            "agents",
            "looping-agent",
            r#"---
title: Looping Agent
dependencies:
  snippets:
    - path: snippets/helper1.md
      tool: agpm
      name: helper1
    - path: snippets/helper2.md
      tool: agpm
      name: helper2
    - path: snippets/helper3.md
      tool: agpm
      name: helper3
agpm:
  templating: true
---
# Looping Agent

## Available Helpers

{% for name, snippet in agpm.deps.snippets %}
### {{ name }}
{{ snippet.content }}
{% endfor %}

## Count

There are {{ agpm.deps.snippets | length }} helpers available.
"#,
        )
        .await?;

    test_repo.commit_all("Add resources")?;
    test_repo.tag_version("v1.0.0")?;

    let repo_url = test_repo.bare_file_url(project.sources_path()).await?;

    let manifest = ManifestBuilder::new()
        .add_source("test-repo", &repo_url)
        .add_snippet("helper1", |d| {
            d.source("test-repo").path("snippets/helper1.md").version("v1.0.0").tool("agpm")
        })
        .add_snippet("helper2", |d| {
            d.source("test-repo").path("snippets/helper2.md").version("v1.0.0").tool("agpm")
        })
        .add_snippet("helper3", |d| {
            d.source("test-repo").path("snippets/helper3.md").version("v1.0.0").tool("agpm")
        })
        .add_agent("looping-agent", |d| {
            d.source("test-repo").path("agents/looping-agent.md").version("v1.0.0")
        })
        .build();

    project.write_manifest(&manifest).await?;

    // Install all resources
    let output = project.run_agpm(&["install"])?;
    assert!(output.success, "Install should succeed");

    // Read the installed agent file
    let agent_path = project.project_path().join(".claude/agents/agpm/looping-agent.md");
    let content = fs::read_to_string(&agent_path).await?;

    assert!(content.contains("### helper1"));
    assert!(content.contains("# Helper 1"));
    assert!(content.contains("### helper2"));
    assert!(content.contains("# Helper 2"));
    assert!(content.contains("### helper3"));
    assert!(content.contains("# Helper 3"));
    assert!(content.contains("There are 3 helpers available."));

    Ok(())
}

/// Test that non-templated content is protected when embedded via content filter.
///
/// This is a regression test for the bug where we removed literal guard wrapping,
/// which would cause template syntax in non-templated files to be rendered when
/// embedded via {{ agpm.deps.snippets.foo.content }}.
#[tokio::test]
async fn test_non_templated_content_embedding() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;
    let test_repo = project.create_source_repo("test-repo").await?;

    // Create a snippet with templating disabled that contains template syntax
    test_repo
        .add_resource(
            "snippets",
            "code-example",
            r#"---
title: Code Example Snippet
agpm:
  templating: false
---
# Example Code

This snippet contains literal template syntax that should NOT be rendered:

{{ agpm.resource.name }}
{{ project.language }}

These should remain as-is even when embedded.
"#,
        )
        .await?;

    // Create an agent that embeds the non-templated snippet
    test_repo
        .add_resource(
            "agents",
            "embedding-agent",
            r#"---
title: Embedding Agent
agpm:
  templating: true
dependencies:
  snippets:
    - path: snippets/code-example.md
      name: code_example
---
# Agent that Embeds Non-Templated Content

Here's the embedded snippet:

{{ agpm.deps.snippets.code_example.content }}

End of embedded content.
"#,
        )
        .await?;

    test_repo.commit_all("Add resources")?;
    test_repo.tag_version("v1.0.0")?;

    let repo_url = test_repo.bare_file_url(project.sources_path()).await?;

    let manifest = ManifestBuilder::new()
        .add_source("test-repo", &repo_url)
        .add_agent("embedding-agent", |d| {
            d.source("test-repo").path("agents/embedding-agent.md").version("v1.0.0")
        })
        .build();

    project.write_manifest(&manifest).await?;

    let output = project.run_agpm(&["install"])?;
    assert!(output.success, "Install should succeed");

    // Read the installed agent file
    let agent_path = project.project_path().join(".claude/agents/agpm/embedding-agent.md");
    let content = fs::read_to_string(&agent_path).await?;

    // Verify that the template syntax from the non-templated snippet was NOT rendered
    assert!(
        content.contains("{{ agpm.resource.name }}"),
        "Template syntax from non-templated snippet should remain literal, got:\n{}",
        content
    );
    assert!(
        content.contains("{{ project.language }}"),
        "Template syntax from non-templated snippet should remain literal, got:\n{}",
        content
    );

    // Verify the embedding worked (snippet content appears)
    assert!(content.contains("# Example Code"), "Snippet content should be embedded");
    assert!(content.contains("End of embedded content"), "Agent's own content should be present");

    Ok(())
}

/// Test that nested transitive dependencies work correctly with literal guard protection.
///
/// This is a regression test for the original bug where literal guards were
/// incorrectly stripped from non-templated content, causing template syntax
/// to be rendered prematurely in nested dependency chains.
///
/// Example failure chain that would occur before the fix:
/// frontend-engineer agent → frontend-engineer-base snippet → best-practices snippet
///
/// The agent tries to render {{ agpm.deps.snippets.frontend_engineer_base.content }},
/// which contains {{ agpm.deps.snippets.best_practices.content }}, but best_practices
/// is not available in the agent's rendering context.
#[tokio::test]
async fn test_nested_transitive_dependency_rendering() -> Result<()> {
    agpm_cli::test_utils::init_test_logging(None);

    let project = TestProject::new().await?;
    let test_repo = project.create_source_repo("test-repo").await?;

    // Create best-practices snippet (normal templated content)
    test_repo
        .add_resource(
            "snippets",
            "best-practices",
            r#"---
title: Best Practices
agpm:
  templating: true
---
# Best Practices

This is the best practices content that should be rendered normally.

Language: {{ agpm.resource.name }}
"#,
        )
        .await?;

    // Create frontend-engineer-base snippet with templating DISABLED
    // This is the key scenario from the original bug - non-templated content
    // that contains template syntax should remain protected when embedded
    test_repo
        .add_resource(
            "snippets",
            "frontend-engineer-base",
            r#"---
title: Frontend Engineer Base
agpm:
  templating: false
dependencies:
  snippets:
    - path: snippets/best-practices.md
      name: best_practices
---
# Frontend Engineer Base

Here's the best practices content:

{{ agpm.deps.snippets.best_practices.content }}

This template syntax should remain literal because templating: false.
Even though best_practices dependency should be resolved and available,
the template syntax itself should not be rendered when this snippet is embedded.
"#,
        )
        .await?;

    // Create frontend-engineer agent that embeds the non-templated snippet
    test_repo
        .add_resource(
            "agents",
            "frontend-engineer",
            r#"---
title: Frontend Engineer
agpm:
  templating: true
dependencies:
  snippets:
    - path: snippets/frontend-engineer-base.md
      name: frontend_engineer_base
---
# Frontend Engineer

Here's the embedded base content:

{{ agpm.deps.snippets.frontend_engineer_base.content }}

End of agent content.
"#,
        )
        .await?;

    test_repo.commit_all("Add nested dependency resources")?;
    test_repo.tag_version("v1.0.0")?;

    let repo_url = test_repo.bare_file_url(project.sources_path()).await?;

    let manifest = ManifestBuilder::new()
        .add_source("test-repo", &repo_url)
        .add_agent("frontend-engineer", |d| {
            d.source("test-repo").path("agents/frontend-engineer.md").version("v1.0.0")
        })
        .build();

    project.write_manifest(&manifest).await?;

    let output = project.run_agpm(&["install"])?;
    assert!(output.success, "Install should succeed");

    // Read the installed agent file
    let agent_path = project.project_path().join(".claude/agents/agpm/frontend-engineer.md");
    let content = fs::read_to_string(&agent_path).await?;

    // CRITICAL: The template syntax from frontend-engineer-base should remain LITERAL
    // This is what would have failed before the fix - literal guards were stripped
    // causing {{ agpm.deps.snippets.best_practices.content }} to be rendered prematurely
    // in the agent's context before best_practices was available
    assert!(
        content.contains("{{ agpm.deps.snippets.best_practices.content }}"),
        "Template syntax from non-templated snippet should remain literal, got:\n{}",
        content
    );

    // With templating: false, the snippet itself won't be rendered
    // So best-practices content won't be included, but template syntax should be protected
    assert!(
        !content.contains("Language: best-practices"),
        "With templating: false, snippet should not render its dependencies"
    );
    assert!(
        !content.contains("This is the best practices content that should be rendered normally."),
        "With templating: false, snippet content should not be rendered"
    );

    // Verify agent's own content is present
    assert!(content.contains("# Frontend Engineer"), "Agent title should be present");
    assert!(content.contains("End of agent content."), "Agent's own content should be present");

    Ok(())
}