relay-flow 0.1.0-alpha.0 → 0.2.1-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +160 -143
- package/cmd/relay-flow/commands_test.go +968 -0
- package/cmd/relay-flow/main.go +877 -175
- package/cmd/relay-flow/scenario_test.go +1310 -0
- package/cmd/relay-flow/serve.go +610 -0
- package/examples/default-story-workflow.yaml +88 -0
- package/go.mod +69 -2
- package/go.sum +185 -0
- package/internal/config/config.go +88 -0
- package/internal/config/machine.go +99 -48
- package/internal/config/machine_test.go +248 -0
- package/internal/config/merge_test.go +118 -0
- package/internal/config/writeatomic.go +36 -0
- package/internal/config/writeatomic_test.go +98 -0
- package/internal/execution/goworkflows/activities.go +490 -0
- package/internal/execution/goworkflows/engine.go +520 -0
- package/internal/execution/goworkflows/engine_test.go +660 -0
- package/internal/execution/goworkflows/fakes_test.go +509 -0
- package/internal/execution/goworkflows/interpreter.go +613 -0
- package/internal/execution/goworkflows/logging_test.go +154 -0
- package/internal/execution/goworkflows/mailbox_test.go +423 -0
- package/internal/execution/goworkflows/node_runtime_integration_test.go +133 -0
- package/internal/execution/goworkflows/node_runtime_test.go +510 -0
- package/internal/execution/goworkflows/projection.go +504 -0
- package/internal/execution/goworkflows/recovery_test.go +1092 -0
- package/internal/execution/goworkflows/retry_log_test.go +59 -0
- package/internal/execution/goworkflows/retry_projection_test.go +98 -0
- package/internal/harness/contract_test.go +174 -0
- package/internal/harness/factory.go +63 -0
- package/internal/harness/harness.go +41 -0
- package/internal/harness/opencode/opencode.go +166 -0
- package/internal/harness/opencode/opencode_test.go +50 -0
- package/internal/harness/plugin_selection_test.go +126 -0
- package/internal/identity/identity.go +37 -0
- package/internal/logging/logging.go +56 -0
- package/internal/logging/logging_test.go +116 -0
- package/internal/paths/paths.go +69 -0
- package/internal/recover/recover.go +115 -0
- package/internal/repo/poller.go +186 -0
- package/internal/repo/poller_test.go +327 -0
- package/internal/repo/repo.go +132 -0
- package/internal/repo/service.go +216 -0
- package/internal/repo/service_test.go +298 -0
- package/internal/retry/retry.go +118 -0
- package/internal/router/router.go +84 -0
- package/internal/router/router_test.go +231 -0
- package/internal/run/manager.go +121 -0
- package/internal/run/run.go +140 -0
- package/internal/run/run_identity_test.go +52 -0
- package/internal/run/run_manager_test.go +286 -0
- package/internal/runner/contract_test.go +259 -0
- package/internal/runner/factory.go +65 -0
- package/internal/runner/orca/orca.go +341 -172
- package/internal/runner/orca/orca_test.go +256 -143
- package/internal/runner/orca/orcacli/orcacli.go +220 -0
- package/internal/runner/orca/orcacli/orcacli_test.go +157 -0
- package/internal/runner/orca/orcacli/testdata/repo-list.json +18 -0
- package/internal/runner/orca/orcacli/testdata/strict-orca.sh +32 -0
- package/internal/runner/orca/orcacli/testdata/terminal-close.json +12 -0
- package/internal/runner/orca/orcacli/testdata/terminal-create.json +18 -0
- package/internal/runner/orca/orcacli/testdata/terminal-list.json +51 -0
- package/internal/runner/orca/orcacli/testdata/terminal-send.json +1 -0
- package/internal/runner/orca/orcacli/testdata/terminal-show.json +1 -0
- package/internal/runner/orca/orcacli/testdata/worktree-create.json +22 -0
- package/internal/runner/orca/orcacli/testdata/worktree-list.json +31 -0
- package/internal/runner/orca/orcacli/testdata/worktree-remove.json +6 -0
- package/internal/runner/runner.go +54 -64
- package/internal/server/api_test.go +300 -0
- package/internal/server/client.go +192 -74
- package/internal/server/fixture_test.go +248 -0
- package/internal/server/server.go +425 -248
- package/internal/server/shutdown_test.go +116 -0
- package/internal/task/auth_test.go +48 -0
- package/internal/task/contract_test.go +225 -0
- package/internal/task/factory.go +119 -0
- package/internal/task/jira/auth.go +183 -0
- package/internal/task/jira/auth_test.go +107 -0
- package/internal/task/jira/effects_test.go +39 -0
- package/internal/task/jira/filters_test.go +254 -0
- package/internal/task/jira/helpers_test.go +70 -0
- package/internal/task/jira/jira.go +538 -0
- package/internal/task/jira/normalize.go +119 -0
- package/internal/task/jira/rest/adf.go +128 -0
- package/internal/task/jira/rest/client.go +573 -0
- package/internal/task/jira/rest/client_test.go +381 -0
- package/internal/task/jira/testdata/jira_search_issues.json +120 -0
- package/internal/task/jira/transition_defaults_test.go +158 -0
- package/internal/task/jira/validation_test.go +94 -0
- package/internal/task/task.go +84 -0
- package/internal/workflow/report.go +85 -0
- package/internal/workflow/report_test.go +259 -0
- package/internal/workflow/service.go +142 -0
- package/internal/workflow/store.go +136 -0
- package/internal/workflow/store_test.go +282 -0
- package/internal/workflow/workflow.go +345 -0
- package/internal/workflow/workflow_test.go +412 -0
- package/package.json +7 -2
- package/internal/acli/acli.go +0 -229
- package/internal/config/demo_test.go +0 -17
- package/internal/config/schema.go +0 -193
- package/internal/config/schema_test.go +0 -162
- package/internal/daemon/daemon.go +0 -218
- package/internal/daemon/daemon_test.go +0 -204
- package/internal/discovery/discovery.go +0 -122
- package/internal/discovery/discovery_test.go +0 -62
- package/internal/opencode/opencode.go +0 -26
- package/internal/orcacli/orcacli.go +0 -264
- package/internal/runner/orca/README.md +0 -64
- package/internal/runner/runner_test.go +0 -64
- package/internal/server/server_test.go +0 -195
- package/internal/tasks/jira/README.md +0 -69
- package/internal/tasks/jira/component_test.go +0 -16
- package/internal/tasks/jira/decode.go +0 -24
- package/internal/tasks/jira/jira.go +0 -231
- package/internal/tasks/jira/jira_test.go +0 -259
- package/internal/tasks/jira/jql_test.go +0 -16
- package/internal/tasks/tasks.go +0 -90
- package/internal/tasks/tasks_test.go +0 -91
|
@@ -1,201 +1,314 @@
|
|
|
1
1
|
package orca
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
+
"context"
|
|
5
|
+
"errors"
|
|
6
|
+
"os/exec"
|
|
7
|
+
"strings"
|
|
4
8
|
"testing"
|
|
5
|
-
"time"
|
|
6
9
|
|
|
7
|
-
"github.com/rajpopat27/relay-flow/internal/
|
|
10
|
+
"github.com/rajpopat27/relay-flow/internal/config"
|
|
8
11
|
"github.com/rajpopat27/relay-flow/internal/runner"
|
|
9
|
-
"github.com/rajpopat27/relay-flow/internal/
|
|
12
|
+
"github.com/rajpopat27/relay-flow/internal/runner/orca/orcacli"
|
|
10
13
|
)
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
agentExists bool
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
func (f *fakeOrca) WorktreeList() ([]orcacli.Worktree, error) { return f.worktrees, nil }
|
|
26
|
-
func (f *fakeOrca) WorktreeCreate(ticketKey, repoID, parentWorktreeID, baseBranch string) error {
|
|
27
|
-
f.created = append(f.created, ticketKey)
|
|
28
|
-
f.worktrees = append(f.worktrees, orcacli.Worktree{ID: "wt-" + ticketKey, DisplayName: ticketKey, RepoID: repoID, Branch: baseBranch})
|
|
29
|
-
return nil
|
|
30
|
-
}
|
|
31
|
-
func (f *fakeOrca) FindWorktree(repoID, displayName string) (orcacli.Worktree, bool, error) {
|
|
32
|
-
for _, w := range f.worktrees {
|
|
33
|
-
if w.RepoID == repoID && w.DisplayName == displayName {
|
|
34
|
-
return w, true, nil
|
|
35
|
-
}
|
|
15
|
+
// 9.5: info-level outcome logs must never embed argv payloads. sanitizeErr
|
|
16
|
+
// strips the "[args...]" middle from orcacli errors so the agent prompt and
|
|
17
|
+
// RELAY_FLOW_* env carried by --command are never written to server.log.
|
|
18
|
+
func TestSanitizeErr(t *testing.T) {
|
|
19
|
+
// Shape from runJSON/run: "orca [terminal create ... --command 'PAYLOAD']: exit status 1: boom"
|
|
20
|
+
// wrapped by CreateTerminal as "orca terminal create: %w".
|
|
21
|
+
wrapped := errors.New("orca terminal create: orca [terminal create --worktree name:PAY-1 --title PAY-1:coding --command 'PAYLOAD']: exit status 1: boom")
|
|
22
|
+
got := sanitizeErr(wrapped)
|
|
23
|
+
if strings.Contains(got, "PAYLOAD") || strings.Contains(got, "--command") {
|
|
24
|
+
t.Fatalf("sanitizeErr leaked argv payload: %q", got)
|
|
36
25
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
func (f *fakeOrca) MainWorktree(repoID string) (orcacli.Worktree, bool, error) {
|
|
40
|
-
for _, w := range f.worktrees {
|
|
41
|
-
if w.RepoID == repoID && w.IsMainWorktree {
|
|
42
|
-
return w, true, nil
|
|
43
|
-
}
|
|
26
|
+
if !strings.Contains(got, "boom") {
|
|
27
|
+
t.Fatalf("sanitizeErr dropped failure reason: %q", got)
|
|
44
28
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if f.listErr != nil {
|
|
49
|
-
return nil, f.listErr
|
|
29
|
+
|
|
30
|
+
if got := sanitizeErr(nil); got != "" {
|
|
31
|
+
t.Fatalf("sanitizeErr(nil) = %q, want empty", got)
|
|
50
32
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return "", f.createErr
|
|
33
|
+
|
|
34
|
+
plain := errors.New("unwrapped failure")
|
|
35
|
+
if got := sanitizeErr(plain); got != "unwrapped failure" {
|
|
36
|
+
t.Fatalf("sanitizeErr(plain) = %q", got)
|
|
56
37
|
}
|
|
57
|
-
h := "h-" + title
|
|
58
|
-
f.terminals["name:"+ticketKey] = append(f.terminals["name:"+ticketKey], orcacli.Terminal{Handle: h, Title: title, Connected: true})
|
|
59
|
-
return h, nil
|
|
60
38
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
39
|
+
|
|
40
|
+
// fakeCLI is the orcacli.Client seam used by the Orca runner tests.
|
|
41
|
+
type fakeCLI struct {
|
|
42
|
+
repos []orcacli.Repo
|
|
43
|
+
worktrees []orcacli.Worktree
|
|
44
|
+
terminals map[string]orcacli.Terminal
|
|
45
|
+
|
|
46
|
+
createdBaseBranch string
|
|
47
|
+
createdParent string
|
|
48
|
+
status string
|
|
49
|
+
showHandles []string
|
|
50
|
+
createCommands []string
|
|
51
|
+
createN int
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
func (f *fakeCLI) ListRepos(context.Context) ([]orcacli.Repo, error) { return f.repos, nil }
|
|
55
|
+
func (f *fakeCLI) ListWorktrees(context.Context) ([]orcacli.Worktree, error) {
|
|
56
|
+
return f.worktrees, nil
|
|
57
|
+
}
|
|
58
|
+
func (f *fakeCLI) CreateWorktree(_ context.Context, ticketKey, repoID, parentWorktreeID, baseBranch string) error {
|
|
59
|
+
f.createdBaseBranch = baseBranch
|
|
60
|
+
f.createdParent = parentWorktreeID
|
|
61
|
+
f.worktrees = append(f.worktrees, orcacli.Worktree{
|
|
62
|
+
ID: "wt-new",
|
|
63
|
+
RepoID: repoID,
|
|
64
|
+
DisplayName: ticketKey,
|
|
65
|
+
Branch: "refs/heads/" + ticketKey,
|
|
66
|
+
Path: "/wt/" + ticketKey,
|
|
67
|
+
})
|
|
64
68
|
return nil
|
|
65
69
|
}
|
|
66
|
-
func (f *
|
|
67
|
-
f.
|
|
70
|
+
func (f *fakeCLI) SetWorktreeStatus(_ context.Context, _, status string) error {
|
|
71
|
+
f.status = status
|
|
68
72
|
return nil
|
|
69
73
|
}
|
|
74
|
+
func (f *fakeCLI) DeleteWorktree(context.Context, string) error { return nil }
|
|
75
|
+
func (f *fakeCLI) ShowTerminal(_ context.Context, handle string) (orcacli.Terminal, error) {
|
|
76
|
+
f.showHandles = append(f.showHandles, handle)
|
|
77
|
+
t, ok := f.terminals[handle]
|
|
78
|
+
if !ok {
|
|
79
|
+
return orcacli.Terminal{}, orcacli.ErrTerminalUnavailable
|
|
80
|
+
}
|
|
81
|
+
return t, nil
|
|
82
|
+
}
|
|
83
|
+
func (f *fakeCLI) SendTerminal(context.Context, string, string) error { return nil }
|
|
84
|
+
func (f *fakeCLI) ListTerminals(context.Context, string) ([]orcacli.Terminal, error) {
|
|
85
|
+
return nil, nil
|
|
86
|
+
}
|
|
87
|
+
func (f *fakeCLI) CreateTerminal(_ context.Context, _ string, title, command string) (string, error) {
|
|
88
|
+
f.createN++
|
|
89
|
+
f.createCommands = append(f.createCommands, command)
|
|
90
|
+
handle := "term-created-" + string(rune('0'+f.createN))
|
|
91
|
+
if f.terminals == nil {
|
|
92
|
+
f.terminals = map[string]orcacli.Terminal{}
|
|
93
|
+
}
|
|
94
|
+
f.terminals[handle] = orcacli.Terminal{Handle: handle, Title: title, Connected: true}
|
|
95
|
+
return handle, nil
|
|
96
|
+
}
|
|
97
|
+
func (f *fakeCLI) CloseTerminal(context.Context, string) error { return nil }
|
|
70
98
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return f.findBranchFn(repoPath, key)
|
|
80
|
-
}
|
|
81
|
-
return "", false, nil
|
|
99
|
+
// 9.16: when the repo's primary worktree is on master (refs/heads/master),
|
|
100
|
+
// EnsureEnvironment must pass --base-branch master (via CreateWorktree), not
|
|
101
|
+
// the hardcoded "main".
|
|
102
|
+
func TestEnsureEnvironment_PrimaryBranchMaster(t *testing.T) {
|
|
103
|
+
fx := &fakeCLI{
|
|
104
|
+
repos: []orcacli.Repo{{ID: "r1", DisplayName: "app", Path: "/srv/app"}},
|
|
105
|
+
worktrees: []orcacli.Worktree{
|
|
106
|
+
{ID: "wt-main", RepoID: "r1", DisplayName: "app-main", Branch: "refs/heads/master", Path: "/srv/app", IsMainWorktree: true},
|
|
82
107
|
},
|
|
83
108
|
}
|
|
109
|
+
a, err := New(fx, config.RawValues{})
|
|
110
|
+
if err != nil {
|
|
111
|
+
t.Fatal(err)
|
|
112
|
+
}
|
|
113
|
+
_, err = a.EnsureEnvironment(context.Background(), runner.RunSpec{TicketKey: "PAY-1", RepoName: "app", RepoPath: "/srv/app"})
|
|
114
|
+
if err != nil {
|
|
115
|
+
t.Fatal(err)
|
|
116
|
+
}
|
|
117
|
+
if fx.createdBaseBranch != "master" {
|
|
118
|
+
t.Fatalf("CreateWorktree baseBranch = %q, want %q", fx.createdBaseBranch, "master")
|
|
119
|
+
}
|
|
120
|
+
if fx.createdParent != "wt-main" {
|
|
121
|
+
t.Fatalf("CreateWorktree parent = %q, want %q", fx.createdParent, "wt-main")
|
|
122
|
+
}
|
|
84
123
|
}
|
|
85
124
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
125
|
+
// Explicit baseRef config overrides the primary worktree's branch.
|
|
126
|
+
func TestEnsureEnvironment_BaseRefOverride(t *testing.T) {
|
|
127
|
+
fx := &fakeCLI{
|
|
128
|
+
repos: []orcacli.Repo{{ID: "r1", DisplayName: "app", Path: "/srv/app"}},
|
|
129
|
+
worktrees: []orcacli.Worktree{
|
|
130
|
+
{ID: "wt-main", RepoID: "r1", DisplayName: "app-main", Branch: "refs/heads/master", Path: "/srv/app", IsMainWorktree: true},
|
|
131
|
+
},
|
|
89
132
|
}
|
|
90
|
-
|
|
91
|
-
|
|
133
|
+
a, err := New(fx, config.RawValues{"baseRef": "release/1.x"})
|
|
134
|
+
if err != nil {
|
|
135
|
+
t.Fatal(err)
|
|
136
|
+
}
|
|
137
|
+
_, err = a.EnsureEnvironment(context.Background(), runner.RunSpec{TicketKey: "PAY-1", RepoName: "app", RepoPath: "/srv/app"})
|
|
138
|
+
if err != nil {
|
|
139
|
+
t.Fatal(err)
|
|
92
140
|
}
|
|
93
|
-
if
|
|
94
|
-
t.
|
|
141
|
+
if fx.createdBaseBranch != "release/1.x" {
|
|
142
|
+
t.Fatalf("CreateWorktree baseBranch = %q, want %q", fx.createdBaseBranch, "release/1.x")
|
|
95
143
|
}
|
|
96
144
|
}
|
|
97
145
|
|
|
98
|
-
func
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
terminals: map[string][]orcacli.Terminal{},
|
|
102
|
-
agentExists: true,
|
|
103
|
-
}
|
|
104
|
-
r := newTestRunner(f)
|
|
105
|
-
tk := tasks.Ticket{Key: "XYZ-1"}
|
|
106
|
-
err := r.Spawn(tk, "coding", "build", "do the work", map[string]string{
|
|
107
|
-
"RELAY_FLOW_WORKFLOW": "wf", "RELAY_FLOW_TICKET": "XYZ-1", "RELAY_FLOW_NODE": "coding", "RELAY_FLOW_AGENT": "build",
|
|
108
|
-
})
|
|
146
|
+
func TestSetEnvironmentStatus(t *testing.T) {
|
|
147
|
+
fx := &fakeCLI{}
|
|
148
|
+
a, err := New(fx, config.RawValues{})
|
|
109
149
|
if err != nil {
|
|
110
|
-
t.
|
|
150
|
+
t.Fatal(err)
|
|
111
151
|
}
|
|
112
|
-
if
|
|
113
|
-
t.
|
|
152
|
+
if err := a.SetEnvironmentStatus(context.Background(), runner.Environment{ID: "wt-PAY-1"}, runner.WorkspaceStatusInReview); err != nil {
|
|
153
|
+
t.Fatal(err)
|
|
114
154
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
t.Errorf("terminals = %+v", terms)
|
|
155
|
+
if fx.status != runner.WorkspaceStatusInReview {
|
|
156
|
+
t.Fatalf("status = %q, want %q", fx.status, runner.WorkspaceStatusInReview)
|
|
118
157
|
}
|
|
119
158
|
}
|
|
120
159
|
|
|
121
|
-
func
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
160
|
+
func TestFindTerminalUsesPersistedID(t *testing.T) {
|
|
161
|
+
fx := &fakeCLI{terminals: map[string]orcacli.Terminal{
|
|
162
|
+
"term-stored": {Handle: "term-stored", Title: "PAY-1:implement", Connected: true},
|
|
163
|
+
}}
|
|
164
|
+
a, err := New(fx, config.RawValues{})
|
|
165
|
+
if err != nil {
|
|
166
|
+
t.Fatal(err)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
got, ok, err := a.FindTerminal(context.Background(), runner.Terminal{ID: "term-stored", Title: "PAY-1:implement"})
|
|
170
|
+
if err != nil || !ok || got.ID != "term-stored" {
|
|
171
|
+
t.Fatalf("FindTerminal = %+v, %v, %v", got, ok, err)
|
|
126
172
|
}
|
|
127
|
-
if len(
|
|
128
|
-
t.
|
|
173
|
+
if len(fx.showHandles) != 1 || fx.showHandles[0] != "term-stored" {
|
|
174
|
+
t.Fatalf("ShowTerminal handles = %v, want [term-stored]", fx.showHandles)
|
|
129
175
|
}
|
|
130
176
|
}
|
|
131
177
|
|
|
132
|
-
func
|
|
133
|
-
|
|
134
|
-
"
|
|
135
|
-
{Handle: "h1", Title: "XYZ-1:build:coding"},
|
|
136
|
-
{Handle: "h2", Title: "XYZ-1:build:reviewing"},
|
|
137
|
-
{Handle: "h3", Title: "Terminal 1"},
|
|
138
|
-
},
|
|
178
|
+
func TestFindTerminalReturnsOnlyLiveUsable(t *testing.T) {
|
|
179
|
+
fx := &fakeCLI{terminals: map[string]orcacli.Terminal{
|
|
180
|
+
"term-dead": {Handle: "term-dead", Title: "PAY-1:implement", Connected: false},
|
|
139
181
|
}}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
t.Errorf("Find coding = %+v ok=%v err=%v", s, ok, err)
|
|
182
|
+
a, err := New(fx, config.RawValues{})
|
|
183
|
+
if err != nil {
|
|
184
|
+
t.Fatal(err)
|
|
144
185
|
}
|
|
145
|
-
|
|
146
|
-
|
|
186
|
+
|
|
187
|
+
if _, ok, err := a.FindTerminal(context.Background(), runner.Terminal{}); err != nil || ok {
|
|
188
|
+
t.Fatalf("FindTerminal(empty) ok=%v err=%v, want absent", ok, err)
|
|
147
189
|
}
|
|
148
|
-
if _, ok,
|
|
149
|
-
t.
|
|
190
|
+
if _, ok, err := a.FindTerminal(context.Background(), runner.Terminal{ID: "term-dead"}); err != nil || ok {
|
|
191
|
+
t.Fatalf("FindTerminal(dead) ok=%v err=%v, want absent", ok, err)
|
|
192
|
+
}
|
|
193
|
+
if len(fx.showHandles) != 1 || fx.showHandles[0] != "term-dead" {
|
|
194
|
+
t.Fatalf("ShowTerminal handles = %v, want [term-dead]", fx.showHandles)
|
|
150
195
|
}
|
|
151
196
|
}
|
|
152
197
|
|
|
153
|
-
func
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if
|
|
159
|
-
t.
|
|
198
|
+
func TestEnsureTerminalFindsBeforeCreate(t *testing.T) {
|
|
199
|
+
fx := &fakeCLI{terminals: map[string]orcacli.Terminal{
|
|
200
|
+
"term-stored": {Handle: "term-stored", Title: "PAY-1:implement", Connected: true},
|
|
201
|
+
}}
|
|
202
|
+
a, err := New(fx, config.RawValues{})
|
|
203
|
+
if err != nil {
|
|
204
|
+
t.Fatal(err)
|
|
205
|
+
}
|
|
206
|
+
stored := runner.Terminal{ID: "term-stored", Title: "PAY-1:implement"}
|
|
207
|
+
|
|
208
|
+
got, err := a.EnsureTerminal(context.Background(), runner.Environment{ID: "wt-PAY-1"}, stored, "PAY-1:implement", runner.Command{Executable: "opencode"})
|
|
209
|
+
if err != nil {
|
|
210
|
+
t.Fatal(err)
|
|
160
211
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if _, _, err := r.Find(tasks.Ticket{Key: "XYZ-9"}, "coding"); err == nil {
|
|
164
|
-
t.Error("real list error must propagate")
|
|
212
|
+
if got.ID != stored.ID || fx.createN != 0 {
|
|
213
|
+
t.Fatalf("EnsureTerminal = %+v, creates=%d; want stored terminal and no create", got, fx.createN)
|
|
165
214
|
}
|
|
166
215
|
}
|
|
167
216
|
|
|
168
|
-
|
|
169
|
-
|
|
217
|
+
func TestEnsureTerminalCreatesWhenStoredTerminalUnavailable(t *testing.T) {
|
|
218
|
+
fx := &fakeCLI{}
|
|
219
|
+
a, err := New(fx, config.RawValues{})
|
|
220
|
+
if err != nil {
|
|
221
|
+
t.Fatal(err)
|
|
222
|
+
}
|
|
223
|
+
command := runner.Command{Executable: "custom-harness", Args: []string{"--session", "opaque", "--prompt", "work", "--agent", "review"}}
|
|
170
224
|
|
|
171
|
-
|
|
225
|
+
got, err := a.EnsureTerminal(context.Background(), runner.Environment{ID: "wt-PAY-1"}, runner.Terminal{ID: "term-stale"}, "PAY-1:implement", command)
|
|
226
|
+
if err != nil {
|
|
227
|
+
t.Fatal(err)
|
|
228
|
+
}
|
|
229
|
+
if got.ID != "term-created-1" || fx.createN != 1 {
|
|
230
|
+
t.Fatalf("EnsureTerminal = %+v, creates=%d", got, fx.createN)
|
|
231
|
+
}
|
|
232
|
+
if len(fx.showHandles) != 1 || fx.showHandles[0] != "term-stale" {
|
|
233
|
+
t.Fatalf("ShowTerminal handles = %v, want [term-stale]", fx.showHandles)
|
|
234
|
+
}
|
|
235
|
+
if len(fx.createCommands) != 1 || fx.createCommands[0] != shellCommand(command) {
|
|
236
|
+
t.Fatalf("CreateTerminal commands = %v, want opaque command unchanged", fx.createCommands)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
172
239
|
|
|
173
|
-
func (
|
|
240
|
+
func TestCreateTerminalAlwaysCreatesAndTreatsCommandAsOpaque(t *testing.T) {
|
|
241
|
+
fx := &fakeCLI{}
|
|
242
|
+
a, err := New(fx, config.RawValues{})
|
|
243
|
+
if err != nil {
|
|
244
|
+
t.Fatal(err)
|
|
245
|
+
}
|
|
246
|
+
command := runner.Command{Executable: "custom-harness", Args: []string{"--session", "opaque"}}
|
|
174
247
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
248
|
+
first, err := a.CreateTerminal(context.Background(), runner.Environment{ID: "wt-PAY-1"}, "PAY-1:implement", command)
|
|
249
|
+
if err != nil {
|
|
250
|
+
t.Fatal(err)
|
|
251
|
+
}
|
|
252
|
+
second, err := a.CreateTerminal(context.Background(), runner.Environment{ID: "wt-PAY-1"}, "PAY-1:implement", command)
|
|
253
|
+
if err != nil {
|
|
254
|
+
t.Fatal(err)
|
|
255
|
+
}
|
|
256
|
+
if first.ID == second.ID || fx.createN != 2 {
|
|
257
|
+
t.Fatalf("CreateTerminal IDs = %q, %q; creates=%d", first.ID, second.ID, fx.createN)
|
|
180
258
|
}
|
|
181
|
-
if len(
|
|
182
|
-
t.
|
|
259
|
+
if len(fx.showHandles) != 0 {
|
|
260
|
+
t.Fatalf("CreateTerminal parsed resume syntax and inspected terminals: %v", fx.showHandles)
|
|
183
261
|
}
|
|
184
262
|
}
|
|
185
263
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
264
|
+
// An existing ticket branch must win even over a configured baseRef. Passing
|
|
265
|
+
// any other base would make Orca hit its branch-name collision behavior.
|
|
266
|
+
func TestEnsureEnvironment_ExistingTicketBranchAvoidsCollision(t *testing.T) {
|
|
267
|
+
repo := t.TempDir()
|
|
268
|
+
runGit := func(args ...string) {
|
|
269
|
+
t.Helper()
|
|
270
|
+
cmdArgs := append([]string{"-C", repo}, args...)
|
|
271
|
+
if out, err := exec.Command("git", cmdArgs...).CombinedOutput(); err != nil {
|
|
272
|
+
t.Fatalf("git %s: %v: %s", strings.Join(args, " "), err, out)
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
runGit("init", "--quiet")
|
|
276
|
+
runGit("-c", "user.name=Relay Flow", "-c", "user.email=relay-flow@example.invalid", "commit", "--allow-empty", "--quiet", "-m", "initial")
|
|
277
|
+
runGit("branch", "alice/PAY-1")
|
|
278
|
+
|
|
279
|
+
fx := &fakeCLI{
|
|
280
|
+
repos: []orcacli.Repo{{ID: "r1", DisplayName: "app", Path: repo}},
|
|
281
|
+
worktrees: []orcacli.Worktree{
|
|
282
|
+
{ID: "wt-main", RepoID: "r1", DisplayName: "app-main", Branch: "refs/heads/master", Path: repo, IsMainWorktree: true},
|
|
192
283
|
},
|
|
193
|
-
}}
|
|
194
|
-
r := newTestRunner(f)
|
|
195
|
-
if err := r.Close(tasks.Ticket{Key: "XYZ-1"}); err != nil {
|
|
196
|
-
t.Fatalf("%v", err)
|
|
197
284
|
}
|
|
198
|
-
|
|
199
|
-
|
|
285
|
+
a, err := New(fx, config.RawValues{"baseRef": "release/1.x"})
|
|
286
|
+
if err != nil {
|
|
287
|
+
t.Fatal(err)
|
|
288
|
+
}
|
|
289
|
+
if _, err := a.EnsureEnvironment(context.Background(), runner.RunSpec{TicketKey: "PAY-1", RepoName: "app", RepoPath: repo}); err != nil {
|
|
290
|
+
t.Fatal(err)
|
|
291
|
+
}
|
|
292
|
+
if fx.createdBaseBranch != "alice/PAY-1" {
|
|
293
|
+
t.Fatalf("CreateWorktree baseBranch = %q, want existing ticket branch", fx.createdBaseBranch)
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
func TestPrimaryBranch(t *testing.T) {
|
|
298
|
+
cases := []struct {
|
|
299
|
+
in, want string
|
|
300
|
+
}{
|
|
301
|
+
{"refs/heads/master", "master"},
|
|
302
|
+
{"refs/heads/main", "main"},
|
|
303
|
+
{"refs/heads/release/1.x", "release/1.x"},
|
|
304
|
+
{"master", "master"}, // already bare
|
|
305
|
+
{"", "main"}, // empty → main fallback
|
|
306
|
+
{"refs/heads/", "main"}, // empty name → main fallback
|
|
307
|
+
}
|
|
308
|
+
for _, c := range cases {
|
|
309
|
+
got := primaryBranch(&orcacli.Worktree{Branch: c.in})
|
|
310
|
+
if got != c.want {
|
|
311
|
+
t.Errorf("primaryBranch(%q) = %q, want %q", c.in, got, c.want)
|
|
312
|
+
}
|
|
200
313
|
}
|
|
201
314
|
}
|