gunk-dev/the-valley

shared_git_test.go

sourcec14b0e68e9c3main's published tip history
2.4 KiB
1//go:build e2e
2
3package e2e
4
5import (
6 "fmt"
7 "strings"
8 "testing"
9 "time"
10
11 "the-valley/flow/internal/event"
12)
13
14// TestSharedGitConfigChange: every worktree of a clone shares its git
15// config. A worker that adds a setting there has its run flagged at
16// finalize: agent:shared-git-changed names the file, and klaus status shows
17// the run needs-attention with a line naming it. A worker whose only write
18// there is its branch's upstream, as git push -u makes, isn't flagged.
19func TestSharedGitConfigChange(t *testing.T) {
20 for _, tc := range []struct {
21 name, write string
22 flagged bool
23 }{
24 {"setting", `git config --local e2e.marker set`, true},
25 {"upstream", `b=$(git branch --show-current); git config "branch.$b.remote" origin; git config "branch.$b.merge" "refs/heads/$b"`, false},
26 } {
27 t.Run(tc.name, func(t *testing.T) {
28 t.Parallel()
29 h := NewHarness(t)
30 h.WriteStub("claude", strings.Replace(h.claudeStubScript(), `cat "$dir/claude.output.jsonl"`,
31 tc.write+"\ncat \"$dir/claude.output.jsonl\"", 1))
32 st := launchOne(t, h, "small task")
33 if st.SharedGit == nil || st.SharedGit.Files["config"] == "" {
34 t.Fatalf("launch recorded no snapshot of the clone's config: %+v", st.SharedGit)
35 }
36 h.WaitForClaudeStart(30 * time.Second)
37 releaseBackendWorkers(t, h)
38
39 final, err := h.ReadState(st.ID)
40 if err != nil {
41 t.Fatal(err)
42 }
43 if got := fmt.Sprint(final.SharedGit.Changed); tc.flagged != (got == "[config]") || !tc.flagged && got != "[]" {
44 t.Fatalf("changed shared files = %s, want flagged %v", got, tc.flagged)
45 }
46 var flagged bool
47 for _, e := range h.runEvents(st.ID) {
48 if e.Type == event.AgentSharedGitChanged {
49 flagged = true
50 if fmt.Sprint(e.Data["files"]) != "[config]" {
51 t.Errorf("event files = %v, want [config]", e.Data["files"])
52 }
53 }
54 }
55 if flagged != tc.flagged {
56 t.Errorf("agent:shared-git-changed emitted = %v, want %v", flagged, tc.flagged)
57 }
58
59 res := h.RunKlaus("status")
60 if res.ExitCode != 0 {
61 t.Fatalf("status: %s%s", res.Stdout, res.Stderr)
62 }
63 var row string
64 for _, l := range strings.Split(res.Stdout, "\n") {
65 if row == "" && strings.HasPrefix(l, st.ID+" ") {
66 row = l
67 }
68 }
69 line := st.ID + " changed its clone's shared git files while it ran: config"
70 if tc.flagged != strings.Contains(row, "needs-attention") || tc.flagged != strings.Contains(res.Stdout, line) {
71 t.Errorf("status (flagged %v):\n%s", tc.flagged, res.Stdout)
72 }
73 })
74 }
75}