Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,6 @@ func statusCommand(opts *options) *cobra.Command {
}
plan, err := opts.plan()
if err != nil {
if isMissingConfigError(home, opts.configPath, err) {
return nil
}
return err
}
fmt.Fprint(cmd.OutOrStdout(), core.DriftSummary(plan))
Expand Down Expand Up @@ -580,17 +577,6 @@ func validationError(errs []error) error {
return errors.Join(errs...)
}

func isMissingConfigError(home, configPath string, err error) bool {
var pathErr *os.PathError
if !errors.As(err, &pathErr) || !errors.Is(pathErr.Err, os.ErrNotExist) {
return false
}
if configPath == "" {
configPath = filepath.Join(home, "kanon.yaml")
}
return filepath.Clean(pathErr.Path) == filepath.Clean(configPath)
}

func confirm(in io.Reader, out io.Writer) (bool, error) {
fmt.Fprint(out, "Apply these changes? [y/N] ")
line, err := bufio.NewReader(in).ReadString('\n')
Expand Down
27 changes: 27 additions & 0 deletions internal/cli/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,33 @@ func TestStatusReportsRemoteSkillMaterializationErrors(t *testing.T) {
}
}

func TestStatusFailsWhenConfigMissing(t *testing.T) {
userHome := t.TempDir()
t.Setenv("HOME", userHome)

home := t.TempDir()
if err := core.InitHome(core.InitOptions{Home: home}); err != nil {
t.Fatal(err)
}
configPath := filepath.Join(home, "kanon.yaml")
if err := os.Remove(configPath); err != nil {
t.Fatal(err)
}

cmd := NewRootCommand()
var out bytes.Buffer
cmd.SetOut(&out)
cmd.SetErr(&out)
cmd.SetArgs([]string{"--home", home, "status"})
err := cmd.Execute()
if err == nil {
t.Fatalf("expected status to fail when %s is missing\n%s", configPath, out.String())
}
if !strings.Contains(err.Error(), configPath) {
t.Fatalf("expected status error to name %s, got %v\n%s", configPath, err, out.String())
}
}

func TestLockCommandWritesLockfile(t *testing.T) {
repo, ref := newRemoteSkillRepo(t, "version one\n")
home := t.TempDir()
Expand Down
Loading