Something went wrong. Try again.
A Kubernetes operator that runs Claude Code sessions on long-horizon work
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129package turn_test
import ( "os" "os/exec" "path/filepath" "strings" "testing")
// pluginRepository makes a repository that holds a Claude Code plugin// and other files that must not reach a Session, served over file:// so// the clone's filter applies as it does against a forge.func pluginRepository(t *testing.T, name string) string { t.Helper() dir := filepath.Join(t.TempDir(), name) files := map[string]string{ ".claude-plugin/plugin.json": `{"name": "` + name + `"}`, "skills/upkeep/SKILL.md": "---\nname: upkeep\n---\n", "README.md": "private notes\n", "src/secret.txt": "private code\n", "docs/skills/elsewhere.md": "not the plugin's skills\n", "docs/.claude-plugin/fake.txt": "not the plugin's manifest\n", } for path, body := range files { full := filepath.Join(dir, path) if err := os.MkdirAll(filepath.Dir(full), 0o755); err != nil { t.Fatal(err) } if err := os.WriteFile(full, []byte(body), 0o644); err != nil { t.Fatal(err) } } for _, args := range [][]string{ {"init", "--quiet"}, {"config", "uploadpack.allowFilter", "true"}, {"add", "."}, {"-c", "user.name=t", "-c", "user.email=t@example.com", "commit", "--quiet", "-m", "plugin"}, } { cmd := exec.Command("git", args...) cmd.Dir = dir if output, err := cmd.CombinedOutput(); err != nil { t.Fatalf("git %v: %v: %s", args, err, output) } } return "file://" + dir}
// checkedOut lists every file under dir, outside .git, by its path in// dir.func checkedOut(t *testing.T, dir string) []string { t.Helper() var files []string err := filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error { if err != nil { return err } if d.IsDir() && d.Name() == ".git" { return filepath.SkipDir } if !d.IsDir() { rel, _ := filepath.Rel(dir, path) files = append(files, rel) } return nil }) if err != nil { t.Fatal(err) } return files}
func TestAPluginClonesOnlyItsManifestAndSkills(t *testing.T) { f := newFixture(t) f.control.turn.Plugins = []string{pluginRepository(t, "shop")} if err := f.run(t); err != nil { t.Fatal(err) }
got := strings.Join(checkedOut(t, filepath.Join(f.options.WorkDir, ".plugins", "shop")), " ") if got != ".claude-plugin/plugin.json skills/upkeep/SKILL.md" { t.Errorf("the plugin's clone holds %s", got) }}
// The filter keeps the other files' contents out of the clone's// objects, not only out of its working tree.func TestAPluginsOtherFilesNeverReachTheSession(t *testing.T) { f := newFixture(t) f.control.turn.Plugins = []string{pluginRepository(t, "shop")} if err := f.run(t); err != nil { t.Fatal(err) }
cmd := exec.Command("git", "rev-list", "--objects", "--missing=print", "HEAD") cmd.Dir = filepath.Join(f.options.WorkDir, ".plugins", "shop") cmd.Env = append(os.Environ(), "GIT_NO_LAZY_FETCH=1") output, err := cmd.Output() missing := strings.Count(string(output), "\n?") if err != nil || missing != 4 { t.Errorf("%d objects are missing from the clone, want the 4 other files: %v\n%s", missing, err, output) }}
func TestEachPluginIsAPluginDir(t *testing.T) { f := newFixture(t) f.control.turn.Plugins = []string{pluginRepository(t, "shop"), pluginRepository(t, "garden")} if err := f.run(t); err != nil { t.Fatal(err) }
args := f.logged(t, "args") for _, name := range []string{"shop", "garden"} { want := "--plugin-dir\n" + filepath.Join(f.options.WorkDir, ".plugins", name) + "\n" if !strings.Contains(args, want) { t.Errorf("claude ran without %q: %q", want, args) } }}
func TestTwoPluginsWithOneNameFailTheTurn(t *testing.T) { f := newFixture(t) f.control.turn.Plugins = []string{pluginRepository(t, "shop"), pluginRepository(t, "shop")}
if err := f.run(t); err == nil || !strings.Contains(err.Error(), "shop") { t.Errorf("the turn answered %v, want an error that names shop", err) }}