package thin import ( "context" "os" "path/filepath" "runtime" "strings" "testing" ) // The index says what each repository's default branch holds now: its // newest commit, the checks gate in Amadan's order, and whether this // runner could run the checks (a Linux runner cannot check Swift). func TestIndexDescribesFacts(t *testing.T) { root := t.TempDir() c := &Clones{Root: filepath.Join(root, "work"), Git: "git"} x := &Index{Clones: c} for _, tc := range []struct { repo string files map[string]string gate string reason string }{ {"amadan.net/a/ios", map[string]string{".amadan/ci.d/10-test": "#!/bin/sh\nmake test\n", "App/View.swift": "import SwiftUI\n", "Makefile": "ci:\n\tgo test\n"}, ".amadan/ci.d", "needs_macos"}, {"amadan.net/a/go", map[string]string{"Makefile": "build:\n\tgo build\nci: build\n\tgo test ./...\n", "go.mod": "module x\n"}, "make ci", ""}, {"amadan.net/a/ci", map[string]string{".amadan/ci": "#!/bin/sh\nxcodebuild test\n"}, ".amadan/ci", "needs_macos"}, {"amadan.net/a/none", map[string]string{"README.md": "# None\n\nNothing to check.\n"}, "", ""}, } { seed := filepath.Join(root, "seed", filepath.Base(tc.repo)) for name, body := range tc.files { os.MkdirAll(filepath.Dir(filepath.Join(seed, name)), 0700) if err := os.WriteFile(filepath.Join(seed, name), []byte(body), 0600); err != nil { t.Fatal(err) } } hostileGit(t, seed, "init", "-q", "-b", "main") hostileGit(t, seed, "add", "-A") hostileGit(t, seed, "commit", "-q", "-m", "First line of "+tc.repo+"\n\nThe body.") dir := c.Path(tc.repo) os.MkdirAll(filepath.Dir(dir), 0700) hostileGit(t, root, "clone", "-q", "--bare", seed, dir) e := x.describe(context.Background(), tc.repo, "main", dir) if len(e.HeadSHA) != 40 || e.HeadSubject != "First line of "+tc.repo || e.UpdatedAt.IsZero() { t.Fatalf("%s head: %q %q %v", tc.repo, e.HeadSHA, e.HeadSubject, e.UpdatedAt) } want := tc.reason if runtime.GOOS == "darwin" { want = "" } if e.Gate != tc.gate || e.ChecksReason != want { t.Fatalf("%s: gate %q reason %q, want %q %q", tc.repo, e.Gate, e.ChecksReason, tc.gate, want) } if strings.Contains(e.HeadSubject, "\x00") { t.Fatalf("subject %q", e.HeadSubject) } } } // A step's activity names each tool its specialist starts: reading, // searching, editing or running, with the file, pattern or the command's // first line, never the workspace's own path. func TestToolActivity(t *testing.T) { raw := `{"type":"assistant","message":{"content":[{"type":"text","text":"Looking."},{"type":"tool_use","name":"Read","input":{"file_path":"/workspace/panes/swipe.go"}},{"type":"tool_use","name":"Grep","input":{"pattern":"EdgeSwipe"}},{"type":"tool_use","name":"Edit","input":{"file_path":"/workspace/panes/swipe.go","old_string":"a","new_string":"b"}},{"type":"tool_use","name":"Bash","input":{"command":"go test ./panes\nrm -rf /"}},{"type":"tool_use","name":"mcp__equipo__submit_candidate","input":{}}]}}` got := toolActivity([]byte(raw)) want := [][2]string{{"read", "panes/swipe.go"}, {"search", "EdgeSwipe"}, {"edit", "panes/swipe.go"}, {"run", "go test ./panes"}, {"other", ""}} if len(got) != len(want) { t.Fatalf("got %v", got) } for i := range want { if got[i] != want[i] { t.Fatalf("line %d: %v, want %v", i, got[i], want[i]) } } }