augent 0.6.4

Lean package manager for various AI coding platforms
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
//! Tests for behavior specified in docs/implementation/specs/bundles.md
//!
//! Spec coverage:
//! - **Installing resources**: what to install from augent.lock; bundle's own resources last
//! - **Always when installing**: config files updated (unless same name already); lockfile then yaml then index; multiple bundles each get own entry; order retained
//! - **Dir bundle (type: dir)**: name is dir-name in yaml/lock/index; path relative to augent.lock dir; with/without augent.yaml in bundle
//! - **Git bundle (type: git)**: name format @owner/repo or @owner/repo:path; ref and sha (or hash) in lockfile for reproducibility
//! - **augent.yaml**: only direct dependencies; deps of deps only in lockfile
//! - **Reinstall same bundle**: idempotent, no duplicate entries

mod common;

// =============================================================================
// Dir bundle: name is dir-name, path relative to augent.lock directory (spec)
// =============================================================================

#[test]
fn test_dir_bundle_name_is_dir_name_in_config() {
    // Spec: "Dir bundle's name is always the following in augent.yaml,
    // augent.lock, augent.index.yaml: dir-name"
    let workspace = common::TestWorkspace::new();
    workspace.init_from_fixture("empty");
    workspace.create_agent_dir("cursor");
    workspace.copy_fixture_bundle("simple-bundle", "my-local-bundle");

    common::augent_cmd_for_workspace(&workspace.path)
        .args(["install", "./bundles/my-local-bundle"])
        .assert()
        .success();

    let yaml = workspace.read_file(".augent/augent.yaml");
    assert!(
        yaml.contains("name:")
            && (yaml.contains("my-local-bundle") || yaml.contains("my-local-bundle\n")),
        "augent.yaml should use dir-name as bundle name, got: {}",
        yaml
    );

    let lockfile = workspace.read_file(".augent/augent.lock");
    assert!(
        lockfile.contains("my-local-bundle"),
        "augent.lock should use dir-name, got: {}",
        lockfile
    );

    let index = workspace.read_file(".augent/augent.index.yaml");
    assert!(
        index.contains("my-local-bundle"),
        "augent.index.yaml should use dir-name, got: {}",
        index
    );
}

#[test]
fn test_dir_bundle_path_relative_to_augent_lock_dir() {
    // Spec: "for dir bundles, path is relative to the directory where augent.lock is"
    let workspace = common::TestWorkspace::new();
    workspace.init_from_fixture("empty");
    workspace.create_agent_dir("cursor");
    workspace.copy_fixture_bundle("simple-bundle", "local-bundle");

    common::augent_cmd_for_workspace(&workspace.path)
        .args(["install", "./bundles/local-bundle"])
        .assert()
        .success();

    let yaml = workspace.read_file(".augent/augent.yaml");
    assert!(
        yaml.contains("path:")
            && (yaml.contains("bundles/local-bundle") || yaml.contains("./bundles/local-bundle")),
        "path should be relative to workspace (where augent.lock lives), got: {}",
        yaml
    );
}

#[test]
fn test_dir_bundle_install_with_relative_path_saves_dir_name() {
    // Spec: "user gives augent install ./local-bundle" or "augent install local-bundle";
    // name is dir-name (e.g. local-bundle). Use ./path so CLI treats as dir, not GitHub.
    let workspace = common::TestWorkspace::new();
    workspace.init_from_fixture("empty");
    workspace.create_agent_dir("cursor");
    workspace.copy_fixture_bundle("simple-bundle", "local-bundle");

    common::augent_cmd_for_workspace(&workspace.path)
        .args(["install", "./bundles/local-bundle"])
        .assert()
        .success();

    let yaml = workspace.read_file(".augent/augent.yaml");
    assert!(
        yaml.contains("local-bundle"),
        "augent.yaml should use dir-name as bundle name, got: {}",
        yaml
    );
    assert!(workspace.file_exists(".cursor/commands/debug.md"));
}

#[test]
fn test_dir_bundle_without_augent_yaml_installs_resources_and_uses_dir_name() {
    // Spec § "without augent.lock": "installs all resources from path ./local-bundle";
    // "what is saved into augent.yaml: name: local-bundle, path: ./local-bundle"
    // Dir bundle name is always dir-name even when bundle has no augent.yaml.
    let workspace = common::TestWorkspace::new();
    workspace.init_from_fixture("empty");
    workspace.create_agent_dir("cursor");
    workspace.create_bundle("resource-only");
    std::fs::create_dir_all(workspace.path.join("bundles/resource-only/commands")).unwrap();
    std::fs::write(
        workspace
            .path
            .join("bundles/resource-only/commands/standalone.md"),
        "# Standalone command\n",
    )
    .expect("write");

    common::augent_cmd_for_workspace(&workspace.path)
        .args(["install", "./bundles/resource-only"])
        .assert()
        .success();

    assert!(
        workspace.file_exists(".cursor/commands/standalone.md"),
        "Resources from dir without augent.yaml should be installed"
    );

    let yaml = workspace.read_file(".augent/augent.yaml");
    assert!(
        yaml.contains("resource-only"),
        "augent.yaml should use dir-name for bundle without augent.yaml, got: {}",
        yaml
    );
    assert!(
        yaml.contains("path:"),
        "path should be saved (relative to augent.lock dir), got: {}",
        yaml
    );

    let lockfile = workspace.read_file(".augent/augent.lock");
    assert!(
        lockfile.contains("resource-only"),
        "augent.lock should record bundle by dir-name, got: {}",
        lockfile
    );
}

// =============================================================================
// Config files: lockfile, augent.yaml, augent.index.yaml all updated (spec)
// =============================================================================

#[test]
fn test_install_updates_lockfile_yaml_and_index() {
    // Spec: "The lockfile is updated first, then augent.yaml, then augent.index.yaml"
    // We verify all three exist and contain the installed bundle after install.
    let workspace = common::TestWorkspace::new();
    workspace.init_from_fixture("empty");
    workspace.create_agent_dir("cursor");
    workspace.copy_fixture_bundle("simple-bundle", "test-bundle");

    common::augent_cmd_for_workspace(&workspace.path)
        .args(["install", "./bundles/test-bundle"])
        .assert()
        .success();

    assert!(workspace.file_exists(".augent/augent.lock"));
    assert!(workspace.file_exists(".augent/augent.yaml"));
    assert!(workspace.file_exists(".augent/augent.index.yaml"));

    let lock = workspace.read_file(".augent/augent.lock");
    let yaml = workspace.read_file(".augent/augent.yaml");
    let index = workspace.read_file(".augent/augent.index.yaml");

    assert!(!lock.is_empty() && lock.contains("test-bundle"));
    assert!(!yaml.is_empty() && yaml.contains("test-bundle"));
    assert!(!index.is_empty() && index.contains("test-bundle"));
}

// =============================================================================
// Multiple bundles: each gets own entry; installation order retained (spec)
// =============================================================================

#[test]
fn test_multiple_bundles_each_get_own_entry_and_order_retained() {
    // Spec: "If user installs multiple bundles in the repo, each of those bundles
    // gets its own entry in augent.yaml, augent.lock, augent.index.yaml"
    // "All of augent files retain order in which things were installed."
    let workspace = common::TestWorkspace::new();
    workspace.init_from_fixture("empty");
    workspace.create_agent_dir("cursor");
    workspace.copy_fixture_bundle("simple-bundle", "bundle-a");
    workspace.copy_fixture_bundle("simple-bundle", "bundle-b");

    common::augent_cmd_for_workspace(&workspace.path)
        .args(["install", "./bundles/bundle-a"])
        .assert()
        .success();

    common::augent_cmd_for_workspace(&workspace.path)
        .args(["install", "./bundles/bundle-b"])
        .assert()
        .success();

    let yaml = workspace.read_file(".augent/augent.yaml");
    assert!(yaml.contains("bundle-a"));
    assert!(yaml.contains("bundle-b"));

    let lockfile = workspace.read_file(".augent/augent.lock");
    let pos_a = lockfile.find("bundle-a").expect("bundle-a not in lockfile");
    let pos_b = lockfile.find("bundle-b").expect("bundle-b not in lockfile");
    assert!(
        pos_a < pos_b,
        "Installation order should be retained: bundle-a before bundle-b in lockfile"
    );

    let index = workspace.read_file(".augent/augent.index.yaml");
    let pos_a_idx = index.find("bundle-a").expect("bundle-a not in index");
    let pos_b_idx = index.find("bundle-b").expect("bundle-b not in index");
    assert!(
        pos_a_idx < pos_b_idx,
        "Installation order should be retained in augent.index.yaml"
    );
}

// =============================================================================
// Dependencies of dependencies only in lockfile, not in augent.yaml (spec)
// =============================================================================

#[test]
fn test_deps_of_deps_only_in_lockfile_not_in_yaml() {
    // Spec: "dependencies of dependencies are not stored in augent.yaml,
    // they are stored in augent.lock"
    let workspace = common::TestWorkspace::new();
    workspace.init_from_fixture("empty");
    workspace.create_agent_dir("cursor");

    let bundle_a = workspace.create_bundle("bundle-a");
    let bundle_b = workspace.create_bundle("bundle-b");
    let bundle_c = workspace.create_bundle("bundle-c");

    workspace.write_file(
        "bundles/bundle-a/augent.yaml",
        r#"
name: "@test/bundle-a"
bundles:
  - name: "@test/bundle-b"
    path: ../bundle-b
"#,
    );
    std::fs::create_dir_all(bundle_a.join("commands")).unwrap();
    std::fs::write(bundle_a.join("commands/a.md"), "# A").expect("write");

    workspace.write_file(
        "bundles/bundle-b/augent.yaml",
        r#"
name: "@test/bundle-b"
bundles:
  - name: "@test/bundle-c"
    path: ../bundle-c
"#,
    );
    std::fs::create_dir_all(bundle_b.join("rules")).unwrap();
    std::fs::write(bundle_b.join("rules/b.md"), "# B").expect("write");

    workspace.write_file(
        "bundles/bundle-c/augent.yaml",
        r#"
name: "@test/bundle-c"
bundles: []
"#,
    );
    std::fs::create_dir_all(bundle_c.join("skills")).unwrap();
    std::fs::write(bundle_c.join("skills/c.md"), "# C").expect("write");

    common::augent_cmd_for_workspace(&workspace.path)
        .args(["install", "./bundles/bundle-a"])
        .assert()
        .success();

    let yaml = workspace.read_file(".augent/augent.yaml");
    assert!(yaml.contains("bundle-a"), "Root bundle must be in yaml");
    assert!(
        !yaml.contains("bundle-b") && !yaml.contains("bundle-c"),
        "Dependencies and transitive deps must not be in augent.yaml, got: {}",
        yaml
    );

    let lockfile = workspace.read_file(".augent/augent.lock");
    assert!(lockfile.contains("bundle-a"));
    assert!(lockfile.contains("@test/bundle-b"));
    assert!(lockfile.contains("@test/bundle-c"));
}

// =============================================================================
// Bundle with augent.lock: install order deps first, bundle's own resources last (spec)
// =============================================================================

#[test]
fn test_bundle_with_deps_installs_deps_first_then_bundle_in_lockfile() {
    // Spec: "If there are any resources in the bundle having augent.lock,
    // the last entry in augent.lock is the bundle itself" -> bundle's own resources last
    let workspace = common::TestWorkspace::new();
    workspace.init_from_fixture("empty");
    workspace.create_agent_dir("cursor");
    workspace.copy_fixture_bundle("simple-bundle", "simple-bundle");
    workspace.copy_fixture_bundle("with-deps", "with-deps");

    common::augent_cmd_for_workspace(&workspace.path)
        .args(["install", "./bundles/with-deps"])
        .assert()
        .success();

    let lockfile = workspace.read_file(".augent/augent.lock");
    let pos_simple = lockfile
        .find("@fixtures/simple-bundle")
        .or_else(|| lockfile.find("simple-bundle"));
    let pos_with_deps = lockfile.find("with-deps");

    assert!(pos_simple.is_some(), "Dependency should be in lockfile");
    assert!(pos_with_deps.is_some(), "Root bundle should be in lockfile");
    if let (Some(s), Some(w)) = (pos_simple, pos_with_deps) {
        assert!(
            s < w,
            "Dependencies should appear before the bundle (bundle's own resources last)"
        );
    }
}

// =============================================================================
// Git bundle: name format @owner/repo; ref and sha in lockfile (spec)
// =============================================================================

#[test]
fn test_git_bundle_name_format_and_reproducible_in_lockfile() {
    // Spec: "Git bundle's name is always in the following format in augent.yaml,
    // augent.lock, augent.index.yaml: @<owner>/repo[/bundle-name][:path/from/repo/root]"
    // "augent.lock always has ref and also THE EXACT sha" (or hash for cached dir)
    let workspace = common::TestWorkspace::new();
    workspace.init_from_fixture("empty");
    workspace.create_agent_dir("cursor");

    let repo_path = workspace.create_mock_git_repo("my-repo");
    let git_url = format!(
        "file://{}",
        repo_path.to_str().expect("Path is not valid UTF-8")
    );

    common::augent_cmd_for_workspace(&workspace.path)
        .args(["install", &git_url])
        .assert()
        .success();

    let yaml = workspace.read_file(".augent/augent.yaml");
    assert!(
        yaml.contains("my-repo") || yaml.contains("@test/my-repo"),
        "augent.yaml should contain bundle name (git repo name), got: {}",
        yaml
    );

    let lockfile = workspace.read_file(".augent/augent.lock");
    assert!(
        lockfile.contains("my-repo"),
        "augent.lock should contain bundle name, got: {}",
        lockfile
    );
    // Lockfile must pin for reproducibility: either ref+sha (git) or hash (cached dir)
    let has_ref_sha =
        lockfile.contains("ref") && (lockfile.contains("sha") || lockfile.contains("resolved_sha"));
    let has_hash = lockfile.contains("hash") || lockfile.contains("blake3:");
    assert!(
        has_ref_sha || has_hash,
        "augent.lock must pin bundle for reproducibility (ref+sha or hash), got: {}",
        lockfile
    );
}

#[test]
fn test_git_subdirectory_name_format_in_config() {
    // Spec: "where name is: @owner/repo:path/from/repo/root" for subdirectory install
    let workspace = common::TestWorkspace::new();
    workspace.init_from_fixture("empty");
    workspace.create_agent_dir("cursor");

    let repo_path = workspace.path.join("git-repo");
    std::fs::create_dir_all(&repo_path).expect("create repo");
    std::process::Command::new("git")
        .arg("init")
        .current_dir(&repo_path)
        .stdout(std::process::Stdio::null())
        .stderr(std::process::Stdio::null())
        .status()
        .expect("git init");
    std::process::Command::new("git")
        .args(["config", "user.email", "test@example.com"])
        .current_dir(&repo_path)
        .stdout(std::process::Stdio::null())
        .stderr(std::process::Stdio::null())
        .status()
        .expect("git config");
    std::process::Command::new("git")
        .args(["config", "user.name", "Test User"])
        .current_dir(&repo_path)
        .stdout(std::process::Stdio::null())
        .stderr(std::process::Stdio::null())
        .status()
        .expect("git config");

    let sub_path = repo_path.join("packages").join("my-bundle");
    std::fs::create_dir_all(&sub_path).expect("create sub");
    std::fs::write(
        sub_path.join("augent.yaml"),
        "name: \"@test/my-bundle\"\nbundles: []\n",
    )
    .expect("write yaml");
    std::fs::create_dir_all(sub_path.join("commands")).unwrap();
    std::fs::write(sub_path.join("commands/hello.md"), "# Hello").expect("write");

    std::process::Command::new("git")
        .args(["add", "."])
        .current_dir(&repo_path)
        .stdout(std::process::Stdio::null())
        .stderr(std::process::Stdio::null())
        .status()
        .expect("git add");
    std::process::Command::new("git")
        .args(["commit", "-m", "Initial"])
        .current_dir(&repo_path)
        .stdout(std::process::Stdio::null())
        .stderr(std::process::Stdio::null())
        .status()
        .expect("git commit");

    let git_url = format!(
        "file://{}:packages/my-bundle",
        repo_path.to_str().expect("Path is not valid UTF-8")
    );

    common::augent_cmd_for_workspace(&workspace.path)
        .args(["install", &git_url])
        .assert()
        .success();

    let yaml = workspace.read_file(".augent/augent.yaml");
    assert!(
        yaml.contains("packages/my-bundle") || yaml.contains("my-bundle"),
        "augent.yaml should record subdirectory path for git bundle, got: {}",
        yaml
    );
    assert!(workspace.file_exists(".cursor/commands/hello.md"));
}

// =============================================================================
// Same bundle already installed: config not duplicated (idempotent)
// =============================================================================

#[test]
fn test_reinstall_same_bundle_does_not_duplicate_entries() {
    // Spec: "Augent config files are updated (unless the bundle of the same name is installed already)"
    let workspace = common::TestWorkspace::new();
    workspace.init_from_fixture("empty");
    workspace.create_agent_dir("cursor");
    workspace.copy_fixture_bundle("simple-bundle", "same-bundle");

    common::augent_cmd_for_workspace(&workspace.path)
        .args(["install", "./bundles/same-bundle"])
        .assert()
        .success();

    let yaml_before = workspace.read_file(".augent/augent.yaml");
    let count_before = yaml_before.matches("same-bundle").count();

    common::augent_cmd_for_workspace(&workspace.path)
        .args(["install", "./bundles/same-bundle"])
        .assert()
        .success();

    let yaml_after = workspace.read_file(".augent/augent.yaml");
    let count_after = yaml_after.matches("same-bundle").count();
    assert!(
        count_after <= count_before + 1,
        "Re-installing same bundle should not duplicate entries (before: {}, after: {})",
        count_before,
        count_after
    );
}