package headless import ( "context" "encoding/json" "os" "os/exec" "path/filepath" "slices" "strings" "sync" "testing" "time" "amadan.net/oficina/equipo/internal/runner/forge" "amadan.net/oficina/equipo/internal/runner/forge/forgetest" "amadan.net/oficina/equipo/internal/runner/thin" "amadan.net/oficina/equipo/internal/runner/workspace" "amadan.net/oficina/equipo/internal/stagingtest" "amadan.net/oficina/equipo/internal/thintest" "amadan.net/oficina/equipo/internal/wire" ) // localForge stands in for Amadan: bare repositories on disk, reached with // the file protocol and no password, and creation in one namespace. type localForge struct { root string mu sync.Mutex repos []string hidden []string createIn []string // hubUpdated: the hub makes the first merge into an empty repository // (amadan#139); before it, such a merge is refused unborn_default. hubUpdated bool } func gitRun(t *testing.T, dir string, args ...string) { t.Helper() cmd := exec.Command("git", args...) cmd.Dir = dir cmd.Env = append(os.Environ(), "GIT_AUTHOR_NAME=t", "GIT_AUTHOR_EMAIL=t@example.com", "GIT_COMMITTER_NAME=t", "GIT_COMMITTER_EMAIL=t@example.com", "GIT_CONFIG_GLOBAL=/dev/null") if out, err := cmd.CombinedOutput(); err != nil { t.Fatalf("git %v: %v %s", args, err, out) } } // newLocalForge makes oficina/sample (Woodstar, a Go app) and oficina/equipo. // oficina/notes is reachable through the namespace grant but not in the // credential file, like a repository the agent was granted later. func newLocalForge(t *testing.T, root string) *localForge { t.Helper() f := &localForge{root: private(t, filepath.Join(root, "forge")), createIn: []string{"oficina"}} files := map[string]map[string]string{ "sample": {"README.md": "# Woodstar\n\nWoodstar is a reading app with sliding panes. Woodstar keeps your place.\n\nIt has a typo: teh panes.\n", "go.mod": "module amadan.net/oficina/sample\n\ngo 1.26\n", "panes/swipe.go": "package panes\n\n// EdgeSwipe goes back when a finger slides from the edge.\nfunc EdgeSwipe() bool { return false }\n", // The repository's own gate: fails while the README has the typo, // printing the edit that fixes it; and an iOS file. ".equipo/gates.json": "{\"version\":1,\"files\":[]}\n", "Makefile": "ci:\n\t@if grep -q 'teh panes' README.md; then echo 'README.md still says teh panes. edit:README.md|teh panes|the panes'; exit 1; fi\n\t@test -d .git && git rev-parse HEAD\n\t@echo README ok\n", "ios/App.swift": "import SwiftUI\n\nlet edgeSwipe = false\n"}, "equipo": {"README.md": "# Equipo\n\nEquipo runs a team's coordinator and specialists.\n", "go.mod": "module amadan.net/oficina/equipo\n\ngo 1.26\n"}, "notes": {"README.md": "# Notes\n\nShared notes.\n"}, } for name, tree := range files { work := filepath.Join(root, "seed-"+name) for p, body := range tree { if err := os.MkdirAll(filepath.Dir(filepath.Join(work, p)), 0700); err != nil { t.Fatal(err) } if err := os.WriteFile(filepath.Join(work, p), []byte(body), 0600); err != nil { t.Fatal(err) } } gitRun(t, work, "init", "-q", "-b", "main") gitRun(t, work, "add", "-A") gitRun(t, work, "commit", "-q", "-m", "seed") // A second commit in sample, so the index's depth-1 fetch leaves // its clone shallow, as a real repository with history does. if name != "sample" { gitRun(t, root, "clone", "-q", "--bare", work, f.path("amadan.net/oficina/"+name)) continue } if err := os.WriteFile(filepath.Join(work, "CHANGES"), []byte("second\n"), 0600); err != nil { t.Fatal(err) } gitRun(t, work, "add", "-A") gitRun(t, work, "commit", "-q", "-m", "second") gitRun(t, root, "clone", "-q", "--bare", work, f.path("amadan.net/oficina/"+name)) } f.repos = []string{"amadan.net/oficina/equipo", "amadan.net/oficina/sample"} f.hidden = []string{"amadan.net/oficina/notes"} return f } // localForgeState is a local forge as a runner subprocess reads it. type localForgeState struct { Root string Repos []string Hidden []string CreateIn []string HubUpdated bool } func (f *localForge) state() *localForgeState { f.mu.Lock() defer f.mu.Unlock() return &localForgeState{Root: f.root, Repos: slices.Clone(f.repos), Hidden: slices.Clone(f.hidden), CreateIn: slices.Clone(f.createIn), HubUpdated: f.hubUpdated} } func (s *localForgeState) forge() *localForge { return &localForge{root: s.Root, repos: s.Repos, hidden: s.Hidden, createIn: s.CreateIn, hubUpdated: s.HubUpdated} } // grant makes a new repository reachable, like a namespace granted to // the agent: hidden from the credential file, reachable for the index. func (f *localForge) grant(t *testing.T, root, repo string) { t.Helper() work := filepath.Join(root, "seed-"+strings.ReplaceAll(strings.TrimPrefix(repo, "amadan.net/"), "/", "__")) if err := os.MkdirAll(work, 0700); err != nil { t.Fatal(err) } name := filepath.Base(repo) if err := os.WriteFile(filepath.Join(work, "README.md"), []byte("# "+name+"\n\n"+name+" keeps the kitchen's recipes.\n"), 0600); err != nil { t.Fatal(err) } gitRun(t, work, "init", "-q", "-b", "main") gitRun(t, work, "add", "-A") gitRun(t, work, "commit", "-q", "-m", "seed") gitRun(t, root, "clone", "-q", "--bare", work, f.path(repo)) f.mu.Lock() f.hidden = append(f.hidden, repo) f.mu.Unlock() } // grantEmpty makes a new repository with no commits reachable, like a // repository created on the hub and not pushed to yet. func (f *localForge) grantEmpty(t *testing.T, repo string) { t.Helper() if err := os.MkdirAll(f.root, 0700); err != nil { t.Fatal(err) } gitRun(t, f.root, "init", "-q", "--bare", "-b", "main", f.path(repo)) f.mu.Lock() f.hidden = append(f.hidden, repo) f.mu.Unlock() } // revoke makes a repository unreachable again. func (f *localForge) revoke(repo string) { f.mu.Lock() defer f.mu.Unlock() f.hidden = slices.DeleteFunc(f.hidden, func(r string) bool { return r == repo }) f.repos = slices.DeleteFunc(f.repos, func(r string) bool { return r == repo }) } func (f *localForge) path(repo string) string { return filepath.Join(f.root, strings.ReplaceAll(strings.TrimPrefix(repo, "amadan.net/"), "/", "__")+".git") } // Repos is everything the agent reaches: the agent-wide credential // covers granted repositories too (the file forge's Repos does the same). func (f *localForge) Repos() []string { f.mu.Lock() defer f.mu.Unlock() out := append(slices.Clone(f.repos), f.hidden...) slices.Sort(out) return out } func (f *localForge) Reachable(context.Context) []string { f.mu.Lock() out := append(slices.Clone(f.repos), f.hidden...) f.mu.Unlock() slices.Sort(out) return slices.Compact(out) } func (f *localForge) Remote(ctx context.Context, repo string, use thin.Use) (workspace.Remote, error) { if !slices.Contains(f.Reachable(ctx), repo) { return workspace.Remote{}, workspace.ErrGitPassword } return workspace.Remote{URL: f.path(repo)}, nil } func (f *localForge) CreateIn(context.Context) []string { return slices.Clone(f.createIn) } func (f *localForge) Agent() string { return "equipo-test" } // Recheck: the local forge is always current. func (f *localForge) Recheck() {} // Merge is the hub's merge API on the local forge: the same refusals // (moved, conflicts, already merged) and a merge commit, branch deleted. func (f *localForge) Merge(ctx context.Context, repo, branch string, req forge.MergeRequest) (forge.MergeResult, error) { if !slices.Contains(f.Reachable(ctx), repo) { return forge.MergeResult{Status: 404, Reason: "not_found"}, nil } f.mu.Lock() hub := forgetest.Hub{CreatesUnbornDefault: f.hubUpdated} f.mu.Unlock() return hub.Merge(ctx, "git", f.path(repo), branch, req) } func (f *localForge) Exists(ctx context.Context, repo string) (bool, error) { return slices.Contains(f.Reachable(ctx), repo), nil } func (f *localForge) Create(ctx context.Context, repo string) error { if !thin.ValidNewRepo(repo) || !slices.Contains(f.createIn, strings.Split(strings.TrimPrefix(repo, "amadan.net/"), "/")[0]) { return thin.ErrNoCreate } if out, err := exec.CommandContext(ctx, "git", "init", "-q", "--bare", f.path(repo)).CombinedOutput(); err != nil { return &os.PathError{Op: "init", Path: string(out), Err: err} } f.mu.Lock() f.repos = append(f.repos, repo) f.mu.Unlock() return nil } // keep follows the stream like a client that loses its connection: it // reopens at the conversation's cursor whenever the stream ends. func (s *session) keep() { s.close() go func() { for s.ctx.Err() == nil { var cursor int64 s.conv.Locked(func(c *thintest.Conversation) { cursor = c.Cursor }) st, err := s.env.Client.Open(s.ctx, cursor) if err != nil { time.Sleep(time.Second) continue } s.conv.Follow(st) st.Close() } }() } // cards returns the conversation's cards of a kind, for one turn. func cards(c *thintest.Conversation, turn, kind string) []wire.Card { var out []wire.Card for _, k := range c.Cards { if k.TurnID == turn && k.Kind == kind { out = append(out, k) } } return out } func (s *session) project(name string) (wire.Project, bool) { var out wire.Project found := false s.conv.Locked(func(c *thintest.Conversation) { for _, p := range c.Projects { if p.Name == name && p.State == wire.ProjectActive { out, found = p, true } } }) return out, found } // noRepoQuestion fails if the coordinator asked the person to choose a // repository or mentioned a set-up step. func noRepoQuestion(t *testing.T, s *session, turn string) { t.Helper() // Only a question about WHERE the work goes fails: a live coordinator // may fairly ask about the change itself (the live README may hold no // typo any more). bad := []string{"set up", "which repository", "which repo", "which project", "which framework", "which one should"} var questions []wire.Card s.conv.Locked(func(c *thintest.Conversation) { questions = cards(c, turn, wire.CardQuestion) }) for _, q := range questions { text := strings.ToLower(q.Question) for _, b := range bad { if strings.Contains(text, b) { t.Fatalf("coordinator asked which repository (%q): %+v", b, q) } } } reply := strings.ToLower(s.reply(t, turn).Text) for _, b := range bad { if strings.Contains(reply, b) { t.Fatalf("reply asks the person to choose (%q): %s", b, reply) } } } // Scenario 2 (to the project): "fix the README typo in sample" puts the // project in the conversation with an Added card, clones it, and never // asks which repository. func scenarioProject(t *testing.T, env *Env) { s := open(t, env) s.keep() s.wait(t, "runner online", 30*time.Second, func(c *thintest.Conversation) bool { return c.Runner.Online }) target := "oficina/sample" if env.Live { target = env.Project } // The allowlist arrives with the runner's hello. deadline := time.Now().Add(90 * time.Second) for { list, err := env.Client.Projects(s.ctx) if err == nil && slices.Contains(list.Allowed, "amadan.net/"+target) { break } if time.Now().After(deadline) { t.Fatalf("allowlist never listed %s: %+v %v", target, list, err) } time.Sleep(time.Second) } text := "think Fix the README typo in sample. tool:status\ntool:add_project:oficina/sample" if env.Live { text = "In " + target + ", add a README note saying: Staging suite check " + env.RunID + ". This is a new request for this run." } sent, timing := s.timed(t, "project", text) if err := s.placement(sent.Turn.ID, []string{target}, true); err != nil { t.Fatal(err) } if _, ok := s.project(target); !ok { t.Fatalf("no %s project event", target) } if env.Live { return } noRepoQuestion(t, s, sent.Turn.ID) if timing.Timing == nil || timing.Timing.ResultMs == 0 || timing.Timing.FirstToolMs == 0 || timing.Timing.FirstThinkingMs == 0 { t.Fatalf("turn timing %+v", timing.Timing) } var acts []wire.Activity s.conv.Locked(func(c *thintest.Conversation) { acts = c.Activity[sent.Turn.ID] }) kinds := []string{} for _, a := range acts { kinds = append(kinds, a.Kind+":"+a.Tool+":"+a.Label) } want := []string{"thinking::Thinking", "tool:status:Checking your projects…", "tool:add_project:Adding a project…", "tool:add_project:Adding oficina/sample…"} if !slices.Equal(kinds, want) { t.Fatalf("activity %q, want %q", kinds, want) } if r := s.reply(t, sent.Turn.ID).Text; !strings.Contains(r, "[add_project: Added oficina/sample.") || strings.Contains(r, "not cloned") || !strings.Contains(r, `"can_add":["oficina/equipo","oficina/notes","oficina/sample"]`) { t.Fatalf("reply %q", r) } // A second turn in the same project reports "Working in", not Added. again := s.send(t, "tool:add_project:oficina/sample") s.waitTurn(t, again.Turn.ID, wire.TurnReplied) s.wait(t, "working card", 10*time.Second, func(c *thintest.Conversation) bool { k := cards(c, again.Turn.ID, wire.CardProject) return len(k) == 1 && k[0].State == wire.CardWorking }) } // Scenario 2b: discovery finds quoted repository references through the // index and reads code without asking for placement. A repository outside // the allowlist gets one access card. func scenarioFindAndRead(t *testing.T, env *Env) { s := open(t, env) s.keep() s.wait(t, "runner online", 30*time.Second, func(c *thintest.Conversation) bool { return c.Runner.Online }) if env.Live { sent := s.send(t, "Investigate the swipe-back gesture in Woodstar for this suite run. Do not create a repository. Ask me if the project is unclear.") s.waitTurn(t, sent.Turn.ID, wire.TurnReplied) list, err := env.Client.Projects(s.ctx) if err != nil { t.Fatal(err) } var allowed []string for _, repo := range list.Allowed { allowed = append(allowed, strings.TrimPrefix(repo, "amadan.net/")) } if err := s.placement(sent.Turn.ID, allowed, false); err != nil { t.Fatal(err) } return } sent := s.send(t, "In Woodstar, the panes aren't slideable from the edge. tool:find:Woodstar\ntool:search_code:oficina/sample|EdgeSwipe\ntool:read_file:oficina/sample|panes/swipe.go") s.waitTurn(t, sent.Turn.ID, wire.TurnReplied) r := s.reply(t, sent.Turn.ID).Text for _, want := range []string{"oficina/sample", "calls itself Woodstar", "repository", "panes/swipe.go:3:// EdgeSwipe goes back", "4\tfunc EdgeSwipe() bool { return false }"} { if !strings.Contains(r, want) { t.Fatalf("reply lacks %q: %s", want, r) } } noRepoQuestion(t, s, sent.Turn.ID) // A repository reachable only through the namespace grant is readable. notes := s.send(t, "tool:read_file:oficina/notes|README.md") s.waitTurn(t, notes.Turn.ID, wire.TurnReplied) if r := s.reply(t, notes.Turn.ID).Text; !strings.Contains(r, "1\t# Notes") { t.Fatalf("granted repository not readable: %s", r) } // Path tricks are refused. trick := s.send(t, "tool:read_file:oficina/sample|../../etc/passwd") s.waitTurn(t, trick.Turn.ID, wire.TurnReplied) if r := s.reply(t, trick.Turn.ID).Text; !strings.Contains(r, "Could not read that") { t.Fatalf("path trick: %s", r) } // A repository the person never named, in a namespace Equipo knows // nothing of: it cannot tell whether it exists, so no access card // (#48, review R1); the model is told so. missing := s.send(t, "In Moonbeam, the panes stick. tool:find:moonbeam/app") s.waitTurn(t, missing.Turn.ID, wire.TurnReplied) if r := s.reply(t, missing.Turn.ID).Text; !strings.Contains(r, "moonbeam/app exists") { t.Fatalf("reply %s", r) } snap, err := env.Client.Snapshot(s.ctx) if err != nil { t.Fatal(err) } for _, k := range snap.Cards { if k.TurnID == missing.Turn.ID && k.Kind == wire.CardAccess { t.Fatalf("access card for an unknown namespace: %+v", k) } } // The person names it: the grant card, as before #48. named := s.send(t, "The panes stick in moonbeam/app. tool:find:moonbeam/app") s.waitTurn(t, named.Turn.ID, wire.TurnReplied) s.wait(t, "access card", 10*time.Second, func(c *thintest.Conversation) bool { k := cards(c, named.Turn.ID, wire.CardAccess) return len(k) == 1 && k[0].Question == "moonbeam/app" && k[0].Choice == "equipo-test" && slices.Equal(k[0].Options, []string{"oficina"}) }) if r := s.reply(t, named.Turn.ID).Text; !strings.Contains(r, `Nothing Equipo's agent can reach matches \"moonbeam/app\"`) && !strings.Contains(r, `matches "moonbeam/app"`) { t.Fatalf("reply %s", r) } } // Scenario 2c: an explicit new-project request creates its repository. // Without creation access, the coordinator asks instead of silently choosing // an existing project. func scenarioNewWork(t *testing.T, env *Env) { s := open(t, env) s.keep() s.wait(t, "runner online", 30*time.Second, func(c *thintest.Conversation) bool { return c.Runner.Online }) text := "Create a new project called oficina/suite-site" if env.Live { text = "Plan a small website introducing the Oficina suite. Use the existing project " + env.Project + " if it fits, otherwise ask me where it should go. Do not create a repository." } sent := s.send(t, text) s.waitTurn(t, sent.Turn.ID, wire.TurnReplied) if env.Live { if err := s.placement(sent.Turn.ID, []string{env.Project}, false); err != nil { t.Fatal(err) } return } noRepoQuestion(t, s, sent.Turn.ID) s.wait(t, "created card", 10*time.Second, func(c *thintest.Conversation) bool { k := cards(c, sent.Turn.ID, wire.CardProject) return len(k) == 1 && k[0].State == wire.CardCreated && k[0].Name == "oficina/suite-site" }) if r := s.reply(t, sent.Turn.ID).Text; !strings.Contains(r, "Created oficina/suite-site.") || strings.Contains(r, "not cloned") { t.Fatalf("reply %s", r) } // Outside the namespaces the agent may create in, it is refused. other := s.send(t, "tool:create_project:carlos/site") s.waitTurn(t, other.Turn.ID, wire.TurnReplied) if r := s.reply(t, other.Turn.ID).Text; !strings.Contains(r, "You cannot create a repository in that namespace") { t.Fatalf("reply %s", r) } // Change points the work at another repository: the answer is the // person's next message, and the card shows what changed. var card wire.Card s.conv.Locked(func(c *thintest.Conversation) { card = cards(c, sent.Turn.ID, wire.CardProject)[0] }) ans, err := env.Client.Answer(s.ctx, card.ID, "oficina/equipo", card.Revision) if err != nil || ans.Card.State != wire.CardChanged || ans.Message.Text != "oficina/equipo" { t.Fatalf("change: %+v %v", ans, err) } s.env.Turn(t) s.waitTurn(t, ans.Turn.ID, wire.TurnReplied) // Remove takes the project out; its card says so. p, ok := s.project("oficina/suite-site") if !ok { t.Fatal("no created project") } if _, err := env.Client.RemoveProject(s.ctx, p.ID); err != nil { t.Fatal(err) } s.wait(t, "removed", 10*time.Second, func(c *thintest.Conversation) bool { return c.Projects[p.ID].State == wire.ProjectRemoved && c.Cards[card.ID].State == wire.CardChanged }) } // Scenario 2e: with no home for new projects set, status says so (the // coordinator then takes the best-fitting repository with Change); the // person can ask for a home, only in a namespace the agent creates in. func scenarioProjectHome(t *testing.T, env *Env) { if env.Live { t.Skip("driven by the fake CLI") } s := open(t, env) s.wait(t, "runner online", 30*time.Second, func(c *thintest.Conversation) bool { return c.Runner.Online }) step := func(text, want string) { t.Helper() sent := s.send(t, text) s.waitTurn(t, sent.Turn.ID, wire.TurnReplied) if r := s.reply(t, sent.Turn.ID).Text; !strings.Contains(r, want) { t.Fatalf("%s: reply %s, want %s", text, r, want) } } step("tool:status", `"home":""`) list, err := env.Client.Projects(s.ctx) if err != nil || list.Home != "" { t.Fatalf("unset home: %+v %v", list, err) } // With no home there is nothing to clear; a namespace the agent cannot // create in is refused; anything else is the person's tap. step("tool:set_project_home:", "nothing to clear") step("Put new projects in carlos.\ntool:set_project_home:carlos", "You cannot create a repository in that namespace") sent := s.send(t, "New projects go to oficina.\ntool:set_project_home:oficina") s.waitTurn(t, sent.Turn.ID, wire.TurnReplied) if r := s.reply(t, sent.Turn.ID).Text; !strings.Contains(r, "Nothing changed yet") { t.Fatalf("set home: %s", r) } var ask wire.Card s.wait(t, "home card", 10*time.Second, func(c *thintest.Conversation) bool { k := cards(c, sent.Turn.ID, wire.CardHome) if len(k) == 1 { ask = k[0] } return len(k) == 1 && k[0].Name == "oficina" && k[0].State == wire.CardHomeAsk }) step("tool:status", `"home":""`) if _, err := env.Client.Answer(s.ctx, ask.ID, wire.ChoiceConfirm, ask.Revision); err != nil { t.Fatal(err) } step("tool:status", `"home":"oficina"`) if list, err = env.Client.Projects(s.ctx); err != nil || list.Home != "oficina" { t.Fatalf("home: %+v %v", list, err) } } // Scenario 2d: ask_person shows a question card; a stale answer is a 409 // carrying the current card; the answer becomes the next message. func scenarioQuestion(t *testing.T, env *Env) { if env.Live { t.Skip("the question card is driven by the fake CLI; live runs never steer the model") } s := open(t, env) s.wait(t, "runner online", 30*time.Second, func(c *thintest.Conversation) bool { return c.Runner.Online }) sent := s.send(t, "tool:ask_person:Should the panes slide on iPad too?|Yes|No") s.waitTurn(t, sent.Turn.ID, wire.TurnReplied) var q wire.Card s.wait(t, "question", 10*time.Second, func(c *thintest.Conversation) bool { k := cards(c, sent.Turn.ID, wire.CardQuestion) if len(k) == 1 { q = k[0] } return len(k) == 1 && slices.Equal(k[0].Options, []string{"Yes", "No"}) && k[0].State == wire.CardOpen }) if _, err := env.Client.Answer(s.ctx, q.ID, "Maybe", q.Revision); thintest.Status(err) != 422 { t.Fatalf("choice outside the options: %v", err) } if _, err := env.Client.Answer(s.ctx, q.ID, "Yes", q.Revision+1); thintest.Status(err) != 409 { t.Fatalf("stale revision: %v", err) } ans, err := env.Client.Answer(s.ctx, q.ID, "Yes", q.Revision) if err != nil || ans.Card.State != wire.CardAnswered || ans.Card.Choice != "Yes" { t.Fatalf("answer %+v %v", ans, err) } s.env.Turn(t) _, err = env.Client.Answer(s.ctx, q.ID, "No", ans.Card.Revision) var conflict wire.CardConflict if st, ok := err.(*thintest.ErrStatus); !ok || st.Status != 409 || json.Unmarshal(st.Body, &conflict) != nil || conflict.Code != "card_answered" || conflict.Card.Choice != "Yes" { t.Fatalf("second answer: %v", err) } s.waitTurn(t, ans.Turn.ID, wire.TurnReplied) } // turnClock is where one turn's time went, as the client and both ends // saw it. type turnClock struct { Commit, FirstActivity, FirstDelta, Message time.Duration Timing *wire.TurnTiming } // TurnClocks collects per-turn timing for the report. var TurnClocks = map[string]turnClock{} // timed sends text and records the turn's clock. func (s *session) timed(t *testing.T, name, text string) (wire.Sent, turnClock) { t.Helper() start := time.Now() sent := s.send(t, text) clock := turnClock{Commit: time.Since(start)} s.waitTurn(t, sent.Turn.ID, wire.TurnReplied) var reply wire.Message s.wait(t, "reply", 30*time.Second, func(c *thintest.Conversation) bool { for _, m := range c.Replies() { if m.TurnID == sent.Turn.ID { reply = m } } if at, ok := c.FirstActivity[sent.Turn.ID]; ok { clock.FirstActivity = at.Sub(start) } if at, ok := c.FirstDelta[sent.Turn.ID]; ok { clock.FirstDelta = at.Sub(start) } return reply.ID != "" }) clock.Message = time.Since(start) turn, err := s.env.Client.Turn(s.ctx, sent.Turn.ID) if err != nil { t.Fatal(err) } clock.Timing = turn.Timing TurnClocks[t.Name()+"/"+name] = clock raw, _ := json.Marshal(clock) t.Logf("turn clock %s: %s", name, raw) return sent, clock } func (s *session) placement(turn string, named []string, required bool) error { var found []wire.Card var tasks []wire.Task s.conv.Locked(func(c *thintest.Conversation) { for _, card := range c.Cards { if card.TurnID == turn { found = append(found, card) } } for _, task := range c.Tasks { if task.TurnID == turn { tasks = append(tasks, task) } } }) return stagingtest.Placement(found, tasks, named, required) }