oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package thin
2
3import (
4 "context"
5 "os"
6 "path/filepath"
7 "runtime"
8 "strings"
9 "testing"
10)
11
12// The index says what each repository's default branch holds now: its
13// newest commit, the checks gate in Amadan's order, and whether this
14// runner could run the checks (a Linux runner cannot check Swift).
15func TestIndexDescribesFacts(t *testing.T) {
16 root := t.TempDir()
17 c := &Clones{Root: filepath.Join(root, "work"), Git: "git"}
18 x := &Index{Clones: c}
19 for _, tc := range []struct {
20 repo string
21 files map[string]string
22 gate string
23 reason string
24 }{
25 {"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"},
26 {"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", ""},
27 {"amadan.net/a/ci", map[string]string{".amadan/ci": "#!/bin/sh\nxcodebuild test\n"}, ".amadan/ci", "needs_macos"},
28 {"amadan.net/a/none", map[string]string{"README.md": "# None\n\nNothing to check.\n"}, "", ""},
29 } {
30 seed := filepath.Join(root, "seed", filepath.Base(tc.repo))
31 for name, body := range tc.files {
32 os.MkdirAll(filepath.Dir(filepath.Join(seed, name)), 0700)
33 if err := os.WriteFile(filepath.Join(seed, name), []byte(body), 0600); err != nil {
34 t.Fatal(err)
35 }
36 }
37 hostileGit(t, seed, "init", "-q", "-b", "main")
38 hostileGit(t, seed, "add", "-A")
39 hostileGit(t, seed, "commit", "-q", "-m", "First line of "+tc.repo+"\n\nThe body.")
40 dir := c.Path(tc.repo)
41 os.MkdirAll(filepath.Dir(dir), 0700)
42 hostileGit(t, root, "clone", "-q", "--bare", seed, dir)
43 e := x.describe(context.Background(), tc.repo, "main", dir)
44 if len(e.HeadSHA) != 40 || e.HeadSubject != "First line of "+tc.repo || e.UpdatedAt.IsZero() {
45 t.Fatalf("%s head: %q %q %v", tc.repo, e.HeadSHA, e.HeadSubject, e.UpdatedAt)
46 }
47 want := tc.reason
48 if runtime.GOOS == "darwin" {
49 want = ""
50 }
51 if e.Gate != tc.gate || e.ChecksReason != want {
52 t.Fatalf("%s: gate %q reason %q, want %q %q", tc.repo, e.Gate, e.ChecksReason, tc.gate, want)
53 }
54 if strings.Contains(e.HeadSubject, "\x00") {
55 t.Fatalf("subject %q", e.HeadSubject)
56 }
57 }
58}
59
60// A step's activity names each tool its specialist starts: reading,
61// searching, editing or running, with the file, pattern or the command's
62// first line, never the workspace's own path.
63func TestToolActivity(t *testing.T) {
64 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":{}}]}}`
65 got := toolActivity([]byte(raw))
66 want := [][2]string{{"read", "panes/swipe.go"}, {"search", "EdgeSwipe"}, {"edit", "panes/swipe.go"}, {"run", "go test ./panes"}, {"other", ""}}
67 if len(got) != len(want) {
68 t.Fatalf("got %v", got)
69 }
70 for i := range want {
71 if got[i] != want[i] {
72 t.Fatalf("line %d: %v, want %v", i, got[i], want[i])
73 }
74 }
75}
76