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
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
//! CLI integration tests using the REAL augent binary

mod common;
use common::TestWorkspace;

use predicates::prelude::*;
use std::fs;

#[test]
fn test_help_output() {
    let temp = common::TestWorkspace::new();
    common::augent_cmd_for_workspace(&temp.path)
        .arg("--help")
        .assert()
        .success()
        .stdout(predicate::str::contains("AI coding platform resources"))
        .stdout(predicate::str::contains("install"))
        .stdout(predicate::str::contains("uninstall"))
        .stdout(predicate::str::contains("list"))
        .stdout(predicate::str::contains("show"));
}

#[test]
fn test_version_output() {
    let temp = common::TestWorkspace::new();
    common::augent_cmd_for_workspace(&temp.path)
        .arg("version")
        .assert()
        .success()
        .stdout(predicate::str::contains("augent"))
        .stdout(predicate::str::contains("Build info"));
}

#[test]
fn test_uninstall_stub() {
    let temp = common::TestWorkspace::new();
    let augent_dir = temp.create_augent_dir();

    // Create minimal workspace config
    let bundle_config_content = r#"name: "@test/workspace"
bundles: []
"#;
    fs::write(augent_dir.join("augent.yaml"), bundle_config_content)
        .expect("Failed to write bundle config");

    let lockfile_content = r#"{
  "name": "@test/workspace",
  "bundles": []
}"#;
    fs::write(augent_dir.join("augent.lock"), lockfile_content).expect("Failed to write lockfile");

    let workspace_config_content = r#"name: "@test/workspace"
bundles: []
"#;
    fs::write(
        augent_dir.join("augent.index.yaml"),
        workspace_config_content,
    )
    .expect("Failed to write workspace config");

    common::augent_cmd_for_workspace(&temp.path)
        .args(["uninstall", "my-bundle"])
        .assert()
        .failure()
        .stderr(predicate::str::contains(
            "Bundle 'my-bundle' not found in workspace",
        ));
}

#[test]
fn test_list_no_workspace() {
    let temp = common::TestWorkspace::new();
    common::augent_cmd_for_workspace(&temp.path)
        .arg("list")
        .assert()
        .failure()
        .stderr(
            predicate::str::contains("Workspace not found")
                .or(predicate::str::contains("WorkspaceNotFound")),
        );
}

#[test]
fn test_list_empty_workspace() {
    let temp = common::TestWorkspace::new();
    let augent_dir = temp.create_augent_dir();

    let bundle_config_content = r#"name: "@test/workspace"
bundles: []
"#;
    fs::write(augent_dir.join("augent.yaml"), bundle_config_content)
        .expect("Failed to write bundle config");

    let lockfile_content = r#"{
  "name": "@test/workspace",
  "bundles": []
}"#;
    fs::write(augent_dir.join("augent.lock"), lockfile_content).expect("Failed to write lockfile");

    let workspace_config_content = r#"name: "@test/workspace"
bundles: []
"#;
    fs::write(
        augent_dir.join("augent.index.yaml"),
        workspace_config_content,
    )
    .expect("Failed to write workspace config");

    common::augent_cmd_for_workspace(&temp.path)
        .arg("list")
        .assert()
        .success()
        .stdout(predicate::str::contains("No bundles installed"));
}

#[test]
fn test_list_with_bundles() {
    let temp = common::TestWorkspace::new();
    let augent_dir = temp.create_augent_dir();

    let bundle_config_content = r#"name: "@test/workspace"
bundles: []
"#;
    fs::write(augent_dir.join("augent.yaml"), bundle_config_content)
        .expect("Failed to write bundle config");

    let lockfile_content = r#"{
  "name": "@test/workspace",
  "bundles": [
    {
      "name": "test-bundle-1",
      "source": {
        "type": "dir",
        "path": "local-bundles/test-bundle-1",
        "hash": "blake3:abc123"
      },
      "files": ["commands/test.md", "agents/helper.md"]
    },
    {
      "name": "test-bundle-2",
      "source": {
        "type": "git",
        "url": "https://github.com/test/repo.git",
        "ref": "main",
        "sha": "def456789abc",
        "path": "subdir",
        "hash": "blake3:def456"
      },
      "files": ["rules/linting.md"]
    }
  ]
}"#;
    fs::write(augent_dir.join("augent.lock"), lockfile_content).expect("Failed to write lockfile");

    let workspace_config_content = r#"name: "@test/workspace"
bundles:
  - name: test-bundle-1
    enabled:
      commands/test.md:
        - .opencode/commands/test.md
        - .cursor/rules/test.mdc
      agents/helper.md:
        - .claude/agents/helper.md
  - name: test-bundle-2
    enabled:
      rules/linting.md:
        - .opencode/rules/linting.md
"#;
    fs::write(
        augent_dir.join("augent.index.yaml"),
        workspace_config_content,
    )
    .expect("Failed to write workspace config");

    common::augent_cmd_for_workspace(&temp.path)
        .arg("list")
        .assert()
        .success()
        .stdout(predicate::str::contains("Installed bundles (2)"))
        .stdout(predicate::str::contains("test-bundle-1"))
        .stdout(predicate::str::contains("test-bundle-2"))
        .stdout(predicate::str::contains("Type: Git"))
        .stdout(predicate::str::contains("Agents"))
        .stdout(predicate::str::contains("Commands"))
        .stdout(predicate::str::contains("Rules"));
}

#[test]
fn test_list_detailed() {
    let temp = common::TestWorkspace::new();
    let augent_dir = temp.create_augent_dir();

    let bundle_config_content = r#"name: "@test/workspace"
bundles: []
"#;
    fs::write(augent_dir.join("augent.yaml"), bundle_config_content)
        .expect("Failed to write bundle config");

    let lockfile_content = r#"{
  "name": "@test/workspace",
  "bundles": [
    {
      "name": "test-bundle",
      "source": {
        "type": "dir",
        "path": "local-bundles/test-bundle",
        "hash": "blake3:abc123"
      },
      "files": ["commands/test.md"]
    }
  ]
}"#;
    fs::write(augent_dir.join("augent.lock"), lockfile_content).expect("Failed to write lockfile");

    let workspace_config_content = r#"name: "@test/workspace"
bundles:
  - name: test-bundle
    enabled:
      commands/test.md:
        - .opencode/commands/test.md
"#;
    fs::write(
        augent_dir.join("augent.index.yaml"),
        workspace_config_content,
    )
    .expect("Failed to write workspace config");

    common::augent_cmd_for_workspace(&temp.path)
        .args(["list", "--detailed"])
        .assert()
        .success()
        .stdout(predicate::str::contains("test-bundle"))
        .stdout(predicate::str::contains("Type: Directory"))
        .stdout(predicate::str::contains("Path: local-bundles/test-bundle"))
        .stdout(predicate::str::contains("commands/test.md →"))
        .stdout(predicate::str::contains(".opencode/commands/test.md"));
}

#[test]
fn test_show_installed_bundle() {
    let workspace = common::TestWorkspace::new();

    workspace.create_augent_dir();

    workspace.write_file(
        "local-bundles/test-bundle/augent.yaml",
        r#"
name: "@user/test-bundle"
bundles: []
"#,
    );

    workspace.write_file(
        ".augent/augent.yaml",
        r#"
name: "@user/workspace"
bundles:
  - name: "@user/test-bundle"
    path: local-bundles/test-bundle
"#,
    );

    workspace.write_file(
        ".augent/augent.lock",
        r#"{
  "name": "@user/workspace",
  "bundles": [
    {
      "name": "@user/test-bundle",
      "source": {
        "type": "dir",
        "path": "local-bundles/test-bundle",
        "hash": "blake3:abc123"
      },
      "files": ["commands/test.md"]
    }
  ]
}"#,
    );

    workspace.write_file(
        ".augent/augent.index.yaml",
        r#"
name: "@user/workspace"
bundles:
  - name: "@user/test-bundle"
    enabled:
      commands/test.md:
        - .opencode/commands/test.md
"#,
    );

    // Create .opencode directory so platform is detected
    fs::create_dir_all(workspace.path.join(".opencode")).unwrap();

    common::augent_cmd_for_workspace(&workspace.path)
        .args(["show", "@user/test-bundle"])
        .assert()
        .success()
        .stdout(predicate::str::contains("@user/test-bundle"))
        .stdout(predicate::str::contains("Commands"))
        .stdout(predicate::str::contains("commands/test.md"));
}

#[test]
fn test_show_not_installed_bundle() {
    let workspace = common::TestWorkspace::new();

    workspace.create_augent_dir();

    workspace.write_file(
        "local-bundles/test-bundle/augent.yaml",
        r#"
name: "@user/test-bundle"
bundles: []
"#,
    );

    workspace.write_file(
        ".augent/augent.yaml",
        r#"
name: "@user/workspace"
bundles:
  - name: "@user/test-bundle"
    path: local-bundles/test-bundle
"#,
    );

    workspace.write_file(
        ".augent/augent.lock",
        r#"{
  "name": "@user/workspace",
  "bundles": [
    {
      "name": "@user/test-bundle",
      "source": {
        "type": "dir",
        "path": "local-bundles/test-bundle",
        "hash": "blake3:abc123"
      },
      "files": ["commands/test.md"]
    }
  ]
}"#,
    );

    common::augent_cmd_for_workspace(&workspace.path)
        .args(["show", "@user/test-bundle"])
        .assert()
        .success()
        .stdout(predicate::str::contains("@user/test-bundle"))
        .stdout(predicate::str::contains("Commands"))
        .stdout(predicate::str::contains("commands/test.md"))
        .stdout(predicate::str::contains("available"));
}

#[test]
fn test_show_nonexistent_bundle() {
    let workspace = common::TestWorkspace::new();

    workspace.create_augent_dir();

    workspace.write_file(
        ".augent/augent.yaml",
        r#"
name: "@user/workspace"
bundles: []
"#,
    );

    workspace.write_file(
        ".augent/augent.lock",
        r#"{
  "name": "@user/workspace",
  "bundles": []
}"#,
    );

    workspace.write_file(
        ".augent/augent.index.yaml",
        r#"
name: "@user/workspace"
bundles: []
"#,
    );

    common::augent_cmd_for_workspace(&workspace.path)
        .args(["show", "nonexistent-bundle"])
        .assert()
        .failure()
        .stderr(predicate::str::contains(
            "Bundle 'nonexistent-bundle' not found",
        ));
}

#[test]
fn test_unknown_command() {
    let temp = common::TestWorkspace::new();
    common::augent_cmd_for_workspace(&temp.path)
        .arg("unknown")
        .assert()
        .failure()
        .stderr(predicate::str::contains("error"));
}

#[test]
fn test_install_missing_source() {
    let temp = common::TestWorkspace::new();
    // Running install without source in a dir with no workspace should exit without creating .augent/
    common::augent_cmd_for_workspace(&temp.path)
        .arg("install")
        .assert()
        .success()
        .stdout(predicate::str::contains("Nothing to install"));
    assert!(
        !temp.path.join(".augent").exists(),
        ".augent/ must not be created when nothing to install"
    );
}

#[test]
fn test_install_git_subdirectory_creates_correct_name_and_type() {
    let workspace = TestWorkspace::new();
    workspace.create_augent_dir();
    workspace.create_all_agent_dirs();

    // Create a git repo with a subdirectory bundle
    let repo_path = workspace.create_mock_git_repo("test-repo");

    // Create a subdirectory with bundle content
    let sub_dir = repo_path.join("subdir-bundle");
    std::fs::create_dir_all(&sub_dir).expect("Failed to create subdirectory");

    std::fs::write(
        sub_dir.join("augent.yaml"),
        r#"name: "@custom/subdir-bundle"
bundles: []
"#,
    )
    .expect("Failed to write augent.yaml");

    std::fs::create_dir_all(sub_dir.join("commands")).expect("Failed to create commands dir");
    std::fs::write(sub_dir.join("commands/test.md"), "# Test Command")
        .expect("Failed to write command file");

    // Commit the changes
    std::process::Command::new("git")
        .args(["add", "."])
        .current_dir(&repo_path)
        .stdout(std::process::Stdio::null())
        .stderr(std::process::Stdio::null())
        .status()
        .expect("Failed to add files");

    std::process::Command::new("git")
        .args(["commit", "-m", "Add subdirectory bundle"])
        .current_dir(&repo_path)
        .stdout(std::process::Stdio::null())
        .stderr(std::process::Stdio::null())
        .status()
        .expect("Failed to commit");

    // Write initial workspace config
    workspace.write_file(
        ".augent/augent.yaml",
        r#"name: "@test/workspace"
bundles: []
"#,
    );

    // Run install with subdirectory selection (simulate menu selection by selecting first bundle)
    let repo_url = format!(
        "file://{}",
        repo_path.display().to_string().replace('\\', "/")
    );

    // For now, we'll test with the full source string including subdirectory
    // In real usage, users would select from an interactive menu
    common::augent_cmd_for_workspace(&workspace.path)
        .args([
            "install",
            &format!("{}:subdir-bundle", repo_url),
            "--to",
            "claude",
        ])
        .assert()
        .success();

    // Verify the lockfile has the correct source type (git) and path (subdirectory)
    let lockfile_content = workspace.read_file(".augent/augent.lock");
    assert!(
        lockfile_content.contains(r#""type": "git""#),
        "Lockfile should have git source type"
    );
    assert!(
        lockfile_content.contains(r#""path": "subdir-bundle""#),
        "Lockfile should have subdirectory in path field"
    );

    // Verify the bundle config has the correct name (not @local/ and uses author/repo format)
    let bundle_config_content = workspace.read_file(".augent/augent.yaml");
    // The name depends on what the bundle config specifies, which is @custom/subdir-bundle
    // or if not present, should be @test-repo/test-repo#subdir-bundle
    assert!(
        !bundle_config_content.contains("@local/"),
        "Bundle config should not contain @local/ prefix for git bundles"
    );
    // When bundle has augent.yaml with custom name, that takes precedence
    // But for bundles without augent.yaml, should extract author/repo from URL
    if !bundle_config_content.contains("@custom/subdir-bundle") {
        // Bundle doesn't have custom name in augent.yaml, should use URL-based name
        // For file:// URLs, the repo name is the directory name
        assert!(
            bundle_config_content.contains("test-repo")
                || bundle_config_content.contains("subdir-bundle"),
            "Bundle config should contain repository name or subdirectory"
        );
    }
}