Skip to content

Commit 23920e8

Browse files
AbirAbbasclaude
andcommitted
test(cli,packages): cover requirements CLI branches and subdir error paths
Closes the patch-coverage gap: no-configuration and unlabeled require_one_of rendering plus inspect-error propagation in af show-requirements, and the root-resolution / manifest-missing error branches of ResolvePackageSubdir. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent efa425b commit 23920e8

4 files changed

Lines changed: 71 additions & 0 deletions

File tree

control-plane/internal/cli/show_requirements_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,36 @@ func TestShowRequirements_RejectsUnknownOutputFormat(t *testing.T) {
8484
cmd.SilenceErrors = true
8585
require.Error(t, cmd.Execute())
8686
}
87+
88+
func TestShowRequirements_TextNoConfigurationNeeded(t *testing.T) {
89+
cmd := NewShowRequirementsCommand()
90+
cmd.SetArgs([]string{"testdata/show-requirements-bare"})
91+
92+
out := captureOutput(t, func() {
93+
require.NoError(t, cmd.Execute())
94+
})
95+
96+
require.Contains(t, out, "This node needs no user configuration.")
97+
require.Contains(t, out, "Install: af install testdata/show-requirements-bare")
98+
}
99+
100+
func TestShowRequirements_TextUnlabeledRequireOneOfGroup(t *testing.T) {
101+
cmd := NewShowRequirementsCommand()
102+
cmd.SetArgs([]string{"testdata/show-requirements-unlabeled"})
103+
104+
out := captureOutput(t, func() {
105+
require.NoError(t, cmd.Execute())
106+
})
107+
108+
require.Contains(t, out, "At least one of")
109+
require.Contains(t, out, "one of these")
110+
}
111+
112+
func TestShowRequirements_InspectErrorPropagates(t *testing.T) {
113+
cmd := NewShowRequirementsCommand()
114+
cmd.SetArgs([]string{"testdata/does-not-exist"})
115+
cmd.SilenceUsage = true
116+
cmd.SilenceErrors = true
117+
118+
require.Error(t, cmd.Execute())
119+
}

control-plane/internal/cli/testdata/show-requirements-bare/agentfield-package.yaml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

control-plane/internal/cli/testdata/show-requirements-unlabeled/agentfield-package.yaml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

control-plane/internal/packages/install_path_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,23 @@ func TestInstallPathGoSubdirBuildsRelativeToSubdir(t *testing.T) {
231231
t.Fatalf("build must be rooted at the subdir, not the repo root")
232232
}
233233
}
234+
235+
func TestResolvePackageSubdir_ErrorBranches(t *testing.T) {
236+
t.Run("nonexistent root fails resolution", func(t *testing.T) {
237+
_, err := ResolvePackageSubdir(filepath.Join(t.TempDir(), "gone"), "sub")
238+
if err == nil || !strings.Contains(err.Error(), "failed to resolve package root") {
239+
t.Fatalf("expected root resolution error, got %v", err)
240+
}
241+
})
242+
243+
t.Run("existing subdir without manifest names the expected path", func(t *testing.T) {
244+
root := t.TempDir()
245+
if err := os.MkdirAll(filepath.Join(root, "empty"), 0o755); err != nil {
246+
t.Fatal(err)
247+
}
248+
_, err := ResolvePackageSubdir(root, "empty")
249+
if err == nil || !strings.Contains(err.Error(), "agentfield-package.yaml") {
250+
t.Fatalf("expected missing-manifest error, got %v", err)
251+
}
252+
})
253+
}

0 commit comments

Comments
 (0)