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
4 changes: 2 additions & 2 deletions docs/operating.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ runtime=directory presence=present compatibility=compatible action=configure tou
- `cortex doctor --target-dir <dir>` reports `presence`, `writability`, and `ownership`
(`unowned`, `owned`, `invalid`) for the directory. Only a missing
`.cortex/install-state.json` is `unowned`; a state file that exists but cannot be read or
decoded is `invalid`. An unwritable directory or an unreadable
prior state exits with the same conflict code install would hit.
decoded is `invalid`. An unwritable directory or an `invalid` prior state exits
with conflict code 3; unreadable state must not be treated as a clean first install.

## Running update

Expand Down
8 changes: 6 additions & 2 deletions internal/cli/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ func runDoctorDirectoryTarget(stdout io.Writer, targetDir string) int {
line += " writability=unwritable"
code = exitConflict
}
line += " ownership=" + doctorTargetOwnership(targetDir)
ownership := doctorTargetOwnership(targetDir)
line += " ownership=" + ownership
if ownership == "invalid" {
code = exitConflict
}
}
if _, err := io.WriteString(stdout, line+"\n"); err != nil {
return exitFailure
Expand Down Expand Up @@ -268,7 +272,7 @@ const (
"so frame directives stay rejected while the quoted diff passes validation (issue #305).\n"
rootHelp = "usage: cortex <command> [arguments]\ncommands: doctor, install, update, uninstall, qa\noptions: --version, --help\n" +
"install [--target-dir <dir>]: configure every compatible present runtime, or project the\ncatalog as plain SKILL.md files into an existing directory (Agent Skills layout)\n" +
"doctor [--target-dir <dir>]: probe runtimes, or report one directory target\n" +
"doctor [--target-dir <dir>]: probe host/target; conflicts exit 3\n" +
"uninstall [--target-dir <dir>]: remove owned files from every runtime root, or from <dir>\n\n" + qaHelp
// qaReportNote surfaces runtime prerequisites on non-catalog failures. It
// names no route: a refusal happens with a profile route resolved, with a
Expand Down
48 changes: 25 additions & 23 deletions internal/cli/doctor_directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,28 +104,30 @@ func TestDoctorDirectoryTargetUnreadableStateIsInvalid(t *testing.T) {
return target
}

// An undecodable state is the existing invalid classification.
garbage := writeState("garbage", []byte("not json"))
garbageCode, garbageOut, garbageErr := runDoctorOnTarget(t, garbage)
if garbageErr != "" || garbageOut != "target="+garbage+" presence=present writability=writable ownership=invalid\n" {
t.Fatalf("garbage: exit = %d stdout = %q stderr = %q", garbageCode, garbageOut, garbageErr)
}
t.Run("undecodable", func(t *testing.T) {
garbage := writeState("garbage", []byte("not json"))
code, stdout, stderr := runDoctorOnTarget(t, garbage)
if code != exitConflict || stderr != "" || stdout != "target="+garbage+" presence=present writability=writable ownership=invalid\n" {
t.Fatalf("garbage: exit = %d stdout = %q stderr = %q", code, stdout, stderr)
}
})

// An unreadable state exists, so it is invalid exactly like an undecodable one.
unreadable := writeState("unreadable", []byte("{}"))
statePath := filepath.Join(unreadable, ".cortex", "install-state.json")
if err := os.Chmod(statePath, 0o000); err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = os.Chmod(statePath, 0o600) })
if os.Getuid() == 0 {
t.Skip("root can read a mode 0000 file")
}
code, stdout, stderr := runDoctorOnTarget(t, unreadable)
if want := "target=" + unreadable + " presence=present writability=writable ownership=invalid\n"; stdout != want {
t.Fatalf("unreadable stdout = %q, want %q", stdout, want)
}
if stderr != "" || code != exitOK || garbageCode != exitOK {
t.Fatalf("unreadable: exit = %d (invalid exits %d) stderr = %q", code, garbageCode, stderr)
}
t.Run("unreadable", func(t *testing.T) {
unreadable := writeState("unreadable", []byte("{}"))
statePath := filepath.Join(unreadable, ".cortex", "install-state.json")
if err := os.Chmod(statePath, 0o000); err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = os.Chmod(statePath, 0o600) })
if os.Getuid() == 0 {
t.Skip("root can read a mode 0000 file")
}
code, stdout, stderr := runDoctorOnTarget(t, unreadable)
if want := "target=" + unreadable + " presence=present writability=writable ownership=invalid\n"; stdout != want {
t.Fatalf("unreadable stdout = %q, want %q", stdout, want)
}
if stderr != "" || code != exitConflict {
t.Fatalf("unreadable: exit = %d, want conflict; stderr = %q", code, stderr)
}
})
}
Loading