Files
knox/internal/skillsrepo/health_test.go
T
david edf6c03a7c chore: checkpoint uncommitted work before session store fix
Pre-existing work-in-progress in the tree: karakeep, snippets,
skills-health and redaction ingesters, the opencode.db session sweep,
gossip and metrics changes. Checkpointed as-is so the adapter fix in the
next commit stays reviewable on its own.
2026-11-01 13:33:36 -08:00

59 lines
1.2 KiB
Go

package skillsrepo
import (
"os"
"os/exec"
"path/filepath"
"testing"
)
func gitInit(t *testing.T, dir string) {
t.Helper()
if _, err := exec.LookPath("git"); err != nil {
t.Skip("git not available")
}
run := func(args ...string) {
full := append([]string{"-c", "user.email=t@t", "-c", "user.name=t", "-C", dir}, args...)
if out, err := exec.Command("git", full...).CombinedOutput(); err != nil {
t.Fatalf("git %v: %v\n%s", args, err, out)
}
}
run("init", "-q")
if err := os.WriteFile(filepath.Join(dir, "a.txt"), []byte("x"), 0o644); err != nil {
t.Fatal(err)
}
run("add", ".")
run("commit", "-q", "-m", "init")
}
func TestCheckHealthyRepo(t *testing.T) {
dir := t.TempDir()
gitInit(t, dir)
h := Check(dir)
if !h.IsRepo {
t.Fatal("should be a repo")
}
if h.Head == "" {
t.Fatalf("HEAD should be readable: %+v", h)
}
if !h.FsckOK {
t.Fatalf("fsck should pass: %+v", h)
}
if h.FreeBytes == 0 {
t.Fatal("free bytes should be reported")
}
}
func TestCheckNotARepo(t *testing.T) {
h := Check(t.TempDir())
if h.IsRepo {
t.Fatal("should not be a repo")
}
if h.Healthy() {
t.Fatal("non-repo must not be healthy")
}
if len(h.Problems) == 0 {
t.Fatal("expected a problem note")
}
}