Skip to content

Commit ccf3ebf

Browse files
committed
test(cli): pin trailing separators, the empty runtime, and a valid target
Address the fleet review on #388: - A trailing separator (the form shell completion produces) is refused as invalid_target by every --target-dir command. On main, doctor accepted it and reported presence, update failed with the misleading invalid_catalog (exit 70), and install and uninstall already refused it; the change is pinned and named in docs/operating.md. - update --runtime "" stays a usage error, so the runtime mode never reaches the directory mode through an empty runtime ID. - A valid absolute target is still accepted (doctor control case), and TestValidTargetDir pins the check itself, including over-refusal. Refs #372
1 parent 12c5662 commit ccf3ebf

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

‎docs/operating.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ runtime=directory presence=present compatibility=compatible action=configure tou
7979
```
8080

8181
- `error=invalid_target` (exit 64) — the path is missing, relative, or not a directory.
82-
Doctor, update, and uninstall refuse an empty, relative, or unclean `--target-dir` with the
82+
Doctor, update, and uninstall refuse an empty, relative, or unclean `--target-dir` (a
83+
trailing separator counts as unclean: pass `/path/dir`, not `/path/dir/`) with the
8384
same error before reading or writing anything; an empty value never falls back to the
8485
runtime mode. A malformed command line is still refused first as `invalid_command` (for
8586
example `update --target-dir <dir>` without `--catalog`). A missing absolute target keeps each command's own answer (doctor reports

‎internal/cli/directory_lifecycle_test.go‎

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,11 @@ func TestDirectoryTargetCommandsRefuseRelativeTargets(t *testing.T) {
181181
t.Fatal(err)
182182
}
183183
// unclean is absolute and names the existing directory, so only the clean
184-
// check can refuse it. empty is what an unset shell variable passes.
184+
// check can refuse it. trailing-separator is the form shell completion
185+
// produces. empty is what an unset shell variable passes.
185186
unclean := cwd + string(filepath.Separator) + "." + string(filepath.Separator) + existing
186-
targets := map[string]string{"existing": existing, "missing": "relative/missing-target", "unclean": unclean, "empty": ""}
187+
trailing := filepath.Join(cwd, existing) + string(filepath.Separator)
188+
targets := map[string]string{"existing": existing, "missing": "relative/missing-target", "unclean": unclean, "trailing-separator": trailing, "empty": ""}
187189
if runtime.GOOS == "windows" {
188190
volume := filepath.VolumeName(cwd)
189191
targets["drive-relative"] = volume + existing
@@ -223,6 +225,46 @@ func TestDirectoryTargetCommandsRefuseRelativeTargets(t *testing.T) {
223225
t.Fatalf("exit = %d stdout = %q stderr = %q", code, stdout, stderr)
224226
}
225227
})
228+
// An explicit empty --runtime is a usage error, so the runtime mode never
229+
// reaches the directory mode through an empty runtime ID.
230+
t.Run("update/empty-runtime-is-a-usage-error", func(t *testing.T) {
231+
code, stdout, stderr := runRefusal(t, canonicalHome(t), []string{"update", "--runtime", "", "--catalog", "../../catalog"})
232+
if code != exitUsage || stdout != "" || stderr != "error=invalid_command\n" {
233+
t.Fatalf("exit = %d stdout = %q stderr = %q", code, stdout, stderr)
234+
}
235+
})
236+
// Control: the shared check must not over-refuse a valid absolute target.
237+
t.Run("doctor/accepts-valid-absolute", func(t *testing.T) {
238+
code, stdout, stderr := runRefusal(t, canonicalHome(t), []string{"doctor", "--target-dir", filepath.Join(cwd, existing)})
239+
if code != exitOK || stderr != "" || !strings.Contains(stdout, " presence=present ") {
240+
t.Fatalf("exit = %d stdout = %q stderr = %q", code, stdout, stderr)
241+
}
242+
})
243+
}
244+
245+
func TestValidTargetDir(t *testing.T) {
246+
cwd, err := os.Getwd()
247+
if err != nil {
248+
t.Fatal(err)
249+
}
250+
sep := string(filepath.Separator)
251+
for _, test := range []struct {
252+
name string
253+
target string
254+
want bool
255+
}{
256+
{"absolute clean", filepath.Join(cwd, "agent-skills"), true},
257+
{"relative", "agent-skills", false},
258+
{"dot relative", "." + sep + "agent-skills", false},
259+
{"unclean", cwd + sep + "." + sep + "agent-skills", false},
260+
{"parent element", filepath.Join(cwd, "a") + sep + ".." + sep + "agent-skills", false},
261+
{"trailing separator", filepath.Join(cwd, "agent-skills") + sep, false},
262+
{"empty", "", false},
263+
} {
264+
if got := validTargetDir(test.target); got != test.want {
265+
t.Errorf("%s: validTargetDir(%q) = %v, want %v", test.name, test.target, got, test.want)
266+
}
267+
}
226268
}
227269

228270
const invalidTargetRefusal = "error=invalid_target\n"

0 commit comments

Comments
 (0)