Something went wrong. Try again.
A Kubernetes operator that runs Claude Code sessions on long-horizon work
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236package console_test
import ( "encoding/json" "io" "os" "os/exec" "path/filepath" "testing"
"tangled.org/guid.foo/simmer/api/v1alpha1" "tangled.org/guid.foo/simmer/console")
// origin makes a repository with one commit, which a test clones by// its path.func origin(t *testing.T) string { t.Helper() dir := t.TempDir() for _, args := range [][]string{ {"init", "--quiet", "--initial-branch=main"}, {"-c", "user.name=t", "-c", "user.email=t@example", "commit", "--quiet", "--allow-empty", "-m", "first"}, } { if out, err := exec.Command("git", append([]string{"-C", dir}, args...)...).CombinedOutput(); err != nil { t.Fatalf("git %v: %v: %s", args, err, out) } } return dir}
// home is a Console's home with a ~/.claude.json that a person and an// earlier start wrote.func home(t *testing.T) console.Config { t.Helper() h := t.TempDir() write(t, filepath.Join(h, ".claude.json"), `{ "theme": "dark", "mcpServers": {"mine": {"type": "http", "url": "http://mine"}, "gone": {"type": "http", "url": "http://gone"}} }`) write(t, filepath.Join(h, ".config", "simmer", "console.json"), `{"mcpServers": ["gone"]}`) return console.Config{ Name: "personal", Namespace: "consoles", Home: h, Directory: filepath.Join(h, "src"), PermissionMode: "auto", McpServers: map[string]v1alpha1.McpServerSpec{ "prometheus": {URL: "http://prometheus-mcp/mcp", OAuth: &v1alpha1.McpOAuth{TokenURL: "http://idp/token", ClientID: "prometheus-mcp"}}, "public": {URL: "http://public-mcp/mcp"}, }, DisabledConnectors: []string{"claude.ai Gmail"}, }}
func write(t *testing.T, path, content string) { t.Helper() if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { t.Fatal(err) } if err := os.WriteFile(path, []byte(content), 0o600); err != nil { t.Fatal(err) }}
func readJSON(t *testing.T, path string) map[string]any { t.Helper() data, err := os.ReadFile(path) if err != nil { t.Fatal(err) } var out map[string]any if err := json.Unmarshal(data, &out); err != nil { t.Fatal(err) } return out}
func setup(t *testing.T, c console.Config) { t.Helper() if err := console.Setup(t.Context(), c, io.Discard); err != nil { t.Fatal(err) }}
func TestSetupClonesEachRepositoryThatIsMissing(t *testing.T) { c := home(t) c.Repositories = []console.Repository{{URL: origin(t), Path: "forge.example/personal"}}
setup(t, c)
if _, err := os.Stat(filepath.Join(c.Directory, "forge.example", "personal", ".git")); err != nil { t.Errorf("the repository is not cloned: %v", err) }}
func TestSetupLeavesACheckoutAsItIs(t *testing.T) { c := home(t) c.Repositories = []console.Repository{{URL: origin(t), Path: "personal"}} setup(t, c) work := filepath.Join(c.Directory, "personal", "work-in-progress") write(t, work, "draft")
setup(t, c)
if _, err := os.Stat(work); err != nil { t.Errorf("the second start lost the work in progress: %v", err) }}
func TestAFailedCloneDoesNotStopTheOthers(t *testing.T) { c := home(t) c.Repositories = []console.Repository{ {URL: filepath.Join(t.TempDir(), "missing"), Path: "missing"}, {URL: origin(t), Path: "personal"}, }
setup(t, c)
if _, err := os.Stat(filepath.Join(c.Directory, "personal", ".git")); err != nil { t.Errorf("the second repository is not cloned: %v", err) }}
// pluginOrigin makes a repository named name that holds a Claude Code// plugin with the skill first. The clone's filter applies only over a// transport, so a test clones it by its file:// URL.func pluginOrigin(t *testing.T, name string) string { t.Helper() dir := filepath.Join(t.TempDir(), name) write(t, filepath.Join(dir, ".claude-plugin", "plugin.json"), `{"name": "`+name+`"}`) for _, args := range [][]string{ {"init", "--quiet", "--initial-branch=main"}, {"config", "uploadpack.allowFilter", "true"}, } { if out, err := exec.Command("git", append([]string{"-C", dir}, args...)...).CombinedOutput(); err != nil { t.Fatalf("git %v: %v: %s", args, err, out) } } commitSkill(t, dir, "first") return dir}
// commitSkill commits a skill to a plugin's repository.func commitSkill(t *testing.T, dir, skill string) { t.Helper() write(t, filepath.Join(dir, "skills", skill, "SKILL.md"), "---\nname: "+skill+"\n---\n") for _, args := range [][]string{ {"add", "."}, {"-c", "user.name=t", "-c", "user.email=t@example", "commit", "--quiet", "-m", skill}, } { if out, err := exec.Command("git", append([]string{"-C", dir}, args...)...).CombinedOutput(); err != nil { t.Fatalf("git %v: %v: %s", args, err, out) } }}
func skillPath(c console.Config, plugin, skill string) string { return filepath.Join(console.PluginsDir(c.Home), plugin, "skills", skill, "SKILL.md")}
func TestSetupClonesEachPlugin(t *testing.T) { c := home(t) c.Plugins = []string{"file://" + pluginOrigin(t, "personal"), "file://" + pluginOrigin(t, "docs")}
setup(t, c)
for _, name := range []string{"personal", "docs"} { if _, err := os.Stat(skillPath(c, name, "first")); err != nil { t.Errorf("the plugin %s is not cloned: %v", name, err) } }}
func TestEachStartClonesThePluginsAfresh(t *testing.T) { c := home(t) origin := pluginOrigin(t, "personal") c.Plugins = []string{"file://" + origin} setup(t, c) commitSkill(t, origin, "second")
setup(t, c)
if _, err := os.Stat(skillPath(c, "personal", "second")); err != nil { t.Errorf("the second start kept the old clone: %v", err) }}
func TestAFailedPluginCloneDoesNotStopTheOthers(t *testing.T) { c := home(t) c.Plugins = []string{"file://" + filepath.Join(t.TempDir(), "missing"), "file://" + pluginOrigin(t, "personal")}
setup(t, c)
if _, err := os.Stat(skillPath(c, "personal", "first")); err != nil { t.Errorf("the second plugin is not cloned: %v", err) }}
func TestSetupRegistersTheConsolesMcpServers(t *testing.T) { c := home(t)
setup(t, c)
servers := readJSON(t, filepath.Join(c.Home, ".claude.json"))["mcpServers"] want := map[string]any{ "mine": map[string]any{"type": "http", "url": "http://mine"}, "prometheus": map[string]any{"type": "http", "url": "http://prometheus-mcp/mcp", "headersHelper": "/simmer/simmer mcp-token"}, "public": map[string]any{"type": "http", "url": "http://public-mcp/mcp"}, } got, _ := json.Marshal(servers) wanted, _ := json.Marshal(want) if string(got) != string(wanted) { t.Errorf("mcpServers = %s, want %s", got, wanted) }}
func TestSetupHandsTheHeadersHelperItsOAuthApplications(t *testing.T) { c := home(t)
setup(t, c)
got := readJSON(t, console.McpConfigPath(c.Home)) if _, ok := got["prometheus"]; !ok || len(got) != 1 { t.Errorf("mcp.json = %v, want prometheus alone", got) }}
func TestSetupAnswersRemoteControlsQuestionsAndHidesTheConnectors(t *testing.T) { c := home(t)
setup(t, c)
config := readJSON(t, filepath.Join(c.Home, ".claude.json")) project, _ := config["projects"].(map[string]any)[c.Directory].(map[string]any) disabled, _ := json.Marshal(project["disabledMcpServers"]) if config["remoteDialogSeen"] != true || project["hasTrustDialogAccepted"] != true || string(disabled) != `["claude.ai Gmail"]` || config["theme"] != "dark" { t.Errorf("~/.claude.json = %v", config) }}