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.
Files changed (118) hide show
  1. package/README.md +160 -143
  2. package/cmd/relay-flow/commands_test.go +968 -0
  3. package/cmd/relay-flow/main.go +877 -175
  4. package/cmd/relay-flow/scenario_test.go +1310 -0
  5. package/cmd/relay-flow/serve.go +610 -0
  6. package/examples/default-story-workflow.yaml +88 -0
  7. package/go.mod +69 -2
  8. package/go.sum +185 -0
  9. package/internal/config/config.go +88 -0
  10. package/internal/config/machine.go +99 -48
  11. package/internal/config/machine_test.go +248 -0
  12. package/internal/config/merge_test.go +118 -0
  13. package/internal/config/writeatomic.go +36 -0
  14. package/internal/config/writeatomic_test.go +98 -0
  15. package/internal/execution/goworkflows/activities.go +490 -0
  16. package/internal/execution/goworkflows/engine.go +520 -0
  17. package/internal/execution/goworkflows/engine_test.go +660 -0
  18. package/internal/execution/goworkflows/fakes_test.go +509 -0
  19. package/internal/execution/goworkflows/interpreter.go +613 -0
  20. package/internal/execution/goworkflows/logging_test.go +154 -0
  21. package/internal/execution/goworkflows/mailbox_test.go +423 -0
  22. package/internal/execution/goworkflows/node_runtime_integration_test.go +133 -0
  23. package/internal/execution/goworkflows/node_runtime_test.go +510 -0
  24. package/internal/execution/goworkflows/projection.go +504 -0
  25. package/internal/execution/goworkflows/recovery_test.go +1092 -0
  26. package/internal/execution/goworkflows/retry_log_test.go +59 -0
  27. package/internal/execution/goworkflows/retry_projection_test.go +98 -0
  28. package/internal/harness/contract_test.go +174 -0
  29. package/internal/harness/factory.go +63 -0
  30. package/internal/harness/harness.go +41 -0
  31. package/internal/harness/opencode/opencode.go +166 -0
  32. package/internal/harness/opencode/opencode_test.go +50 -0
  33. package/internal/harness/plugin_selection_test.go +126 -0
  34. package/internal/identity/identity.go +37 -0
  35. package/internal/logging/logging.go +56 -0
  36. package/internal/logging/logging_test.go +116 -0
  37. package/internal/paths/paths.go +69 -0
  38. package/internal/recover/recover.go +115 -0
  39. package/internal/repo/poller.go +186 -0
  40. package/internal/repo/poller_test.go +327 -0
  41. package/internal/repo/repo.go +132 -0
  42. package/internal/repo/service.go +216 -0
  43. package/internal/repo/service_test.go +298 -0
  44. package/internal/retry/retry.go +118 -0
  45. package/internal/router/router.go +84 -0
  46. package/internal/router/router_test.go +231 -0
  47. package/internal/run/manager.go +121 -0
  48. package/internal/run/run.go +140 -0
  49. package/internal/run/run_identity_test.go +52 -0
  50. package/internal/run/run_manager_test.go +286 -0
  51. package/internal/runner/contract_test.go +259 -0
  52. package/internal/runner/factory.go +65 -0
  53. package/internal/runner/orca/orca.go +341 -172
  54. package/internal/runner/orca/orca_test.go +256 -143
  55. package/internal/runner/orca/orcacli/orcacli.go +220 -0
  56. package/internal/runner/orca/orcacli/orcacli_test.go +157 -0
  57. package/internal/runner/orca/orcacli/testdata/repo-list.json +18 -0
  58. package/internal/runner/orca/orcacli/testdata/strict-orca.sh +32 -0
  59. package/internal/runner/orca/orcacli/testdata/terminal-close.json +12 -0
  60. package/internal/runner/orca/orcacli/testdata/terminal-create.json +18 -0
  61. package/internal/runner/orca/orcacli/testdata/terminal-list.json +51 -0
  62. package/internal/runner/orca/orcacli/testdata/terminal-send.json +1 -0
  63. package/internal/runner/orca/orcacli/testdata/terminal-show.json +1 -0
  64. package/internal/runner/orca/orcacli/testdata/worktree-create.json +22 -0
  65. package/internal/runner/orca/orcacli/testdata/worktree-list.json +31 -0
  66. package/internal/runner/orca/orcacli/testdata/worktree-remove.json +6 -0
  67. package/internal/runner/runner.go +54 -64
  68. package/internal/server/api_test.go +300 -0
  69. package/internal/server/client.go +192 -74
  70. package/internal/server/fixture_test.go +248 -0
  71. package/internal/server/server.go +425 -248
  72. package/internal/server/shutdown_test.go +116 -0
  73. package/internal/task/auth_test.go +48 -0
  74. package/internal/task/contract_test.go +225 -0
  75. package/internal/task/factory.go +119 -0
  76. package/internal/task/jira/auth.go +183 -0
  77. package/internal/task/jira/auth_test.go +107 -0
  78. package/internal/task/jira/effects_test.go +39 -0
  79. package/internal/task/jira/filters_test.go +254 -0
  80. package/internal/task/jira/helpers_test.go +70 -0
  81. package/internal/task/jira/jira.go +538 -0
  82. package/internal/task/jira/normalize.go +119 -0
  83. package/internal/task/jira/rest/adf.go +128 -0
  84. package/internal/task/jira/rest/client.go +573 -0
  85. package/internal/task/jira/rest/client_test.go +381 -0
  86. package/internal/task/jira/testdata/jira_search_issues.json +120 -0
  87. package/internal/task/jira/transition_defaults_test.go +158 -0
  88. package/internal/task/jira/validation_test.go +94 -0
  89. package/internal/task/task.go +84 -0
  90. package/internal/workflow/report.go +85 -0
  91. package/internal/workflow/report_test.go +259 -0
  92. package/internal/workflow/service.go +142 -0
  93. package/internal/workflow/store.go +136 -0
  94. package/internal/workflow/store_test.go +282 -0
  95. package/internal/workflow/workflow.go +345 -0
  96. package/internal/workflow/workflow_test.go +412 -0
  97. package/package.json +7 -2
  98. package/internal/acli/acli.go +0 -229
  99. package/internal/config/demo_test.go +0 -17
  100. package/internal/config/schema.go +0 -193
  101. package/internal/config/schema_test.go +0 -162
  102. package/internal/daemon/daemon.go +0 -218
  103. package/internal/daemon/daemon_test.go +0 -204
  104. package/internal/discovery/discovery.go +0 -122
  105. package/internal/discovery/discovery_test.go +0 -62
  106. package/internal/opencode/opencode.go +0 -26
  107. package/internal/orcacli/orcacli.go +0 -264
  108. package/internal/runner/orca/README.md +0 -64
  109. package/internal/runner/runner_test.go +0 -64
  110. package/internal/server/server_test.go +0 -195
  111. package/internal/tasks/jira/README.md +0 -69
  112. package/internal/tasks/jira/component_test.go +0 -16
  113. package/internal/tasks/jira/decode.go +0 -24
  114. package/internal/tasks/jira/jira.go +0 -231
  115. package/internal/tasks/jira/jira_test.go +0 -259
  116. package/internal/tasks/jira/jql_test.go +0 -16
  117. package/internal/tasks/tasks.go +0 -90
  118. package/internal/tasks/tasks_test.go +0 -91
@@ -0,0 +1,107 @@
1
+ package jira
2
+
3
+ import (
4
+ "context"
5
+ "fmt"
6
+ "net/http"
7
+ "net/http/httptest"
8
+ "os"
9
+ "path/filepath"
10
+ "strings"
11
+ "testing"
12
+
13
+ "github.com/rajpopat27/relay-flow/internal/config"
14
+ "github.com/rajpopat27/relay-flow/internal/task"
15
+ )
16
+
17
+ func authServer(t *testing.T, valid bool) *httptest.Server {
18
+ t.Helper()
19
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
20
+ user, token, ok := r.BasicAuth()
21
+ if !ok || user != "bot@example.com" || token != "secret" || !valid {
22
+ http.Error(w, "invalid bot@example.com secret", http.StatusUnauthorized)
23
+ return
24
+ }
25
+ w.Header().Set("Content-Type", "application/json")
26
+ switch r.URL.Path {
27
+ case "/rest/api/3/myself":
28
+ fmt.Fprint(w, `{"accountId":"bot"}`)
29
+ case "/rest/api/3/project/PAY/statuses":
30
+ fmt.Fprint(w, `[{"id":"1","subtask":true,"statuses":[{"name":"To Do"},{"name":"In Progress"},{"name":"Done"}]}]`)
31
+ default:
32
+ http.NotFound(w, r)
33
+ }
34
+ }))
35
+ t.Cleanup(server.Close)
36
+ return server
37
+ }
38
+
39
+ func TestAuthWritesLoadsAndNewUsesJiraOwnedCredentials(t *testing.T) {
40
+ root := t.TempDir()
41
+ t.Setenv("RELAY_FLOW_HOME", root)
42
+ server := authServer(t, true)
43
+ if err := task.Auth(context.Background(), "jira", []string{
44
+ "--site", server.URL, "--email", "bot@example.com", "--token", "secret",
45
+ }, strings.NewReader("")); err != nil {
46
+ t.Fatal(err)
47
+ }
48
+ path := filepath.Join(root, "credentials.yaml")
49
+ info, err := os.Stat(path)
50
+ if err != nil {
51
+ t.Fatal(err)
52
+ }
53
+ if info.Mode().Perm() != 0o600 {
54
+ t.Fatalf("credentials mode = %o, want 600", info.Mode().Perm())
55
+ }
56
+ got, err := loadCredentials(path)
57
+ if err != nil {
58
+ t.Fatal(err)
59
+ }
60
+ if got.Site != server.URL || got.Email != "bot@example.com" || got.Token != "secret" {
61
+ t.Fatalf("credentials = %+v", got)
62
+ }
63
+ if _, err := task.New(context.Background(), "jira", task.RepoSpec{
64
+ Name: "payments", RepoConfig: config.RawValues{"project": "PAY", "component": "api"},
65
+ }); err != nil {
66
+ t.Fatalf("task.New did not load Jira-owned credentials: %v", err)
67
+ }
68
+ }
69
+
70
+ func TestAuthRejectsInvalidCredentialsWithoutWriting(t *testing.T) {
71
+ root := t.TempDir()
72
+ t.Setenv("RELAY_FLOW_HOME", root)
73
+ server := authServer(t, false)
74
+ err := auth(context.Background(), []string{
75
+ "--site", server.URL, "--email", "bot@example.com", "--token", "secret",
76
+ }, strings.NewReader(""))
77
+ if err == nil {
78
+ t.Fatal("invalid credentials accepted")
79
+ }
80
+ if strings.Contains(err.Error(), "secret") || strings.Contains(err.Error(), "bot@example.com") {
81
+ t.Fatalf("credential error exposed a secret: %v", err)
82
+ }
83
+ if _, statErr := os.Stat(filepath.Join(root, "credentials.yaml")); !os.IsNotExist(statErr) {
84
+ t.Fatalf("invalid auth wrote credentials: %v", statErr)
85
+ }
86
+ }
87
+
88
+ func TestLoadCredentialsRejectsPermissionsAndMalformedSecrets(t *testing.T) {
89
+ t.Run("permissions", func(t *testing.T) {
90
+ path := filepath.Join(t.TempDir(), "credentials.yaml")
91
+ if err := os.WriteFile(path, []byte("site: https://jira.example.com\nemail: bot@example.com\ntoken: secret\n"), 0o644); err != nil {
92
+ t.Fatal(err)
93
+ }
94
+ if _, err := loadCredentials(path); err == nil || !strings.Contains(err.Error(), "0600") {
95
+ t.Fatalf("permission error = %v", err)
96
+ }
97
+ })
98
+ t.Run("redaction", func(t *testing.T) {
99
+ path := filepath.Join(t.TempDir(), "credentials.yaml")
100
+ if err := os.WriteFile(path, []byte("token: [super-secret"), 0o600); err != nil {
101
+ t.Fatal(err)
102
+ }
103
+ if _, err := loadCredentials(path); err == nil || strings.Contains(err.Error(), "super-secret") {
104
+ t.Fatalf("malformed credential error = %v", err)
105
+ }
106
+ })
107
+ }
@@ -0,0 +1,39 @@
1
+ package jira
2
+
3
+ import (
4
+ "context"
5
+ "strings"
6
+ "testing"
7
+
8
+ "github.com/rajpopat27/relay-flow/internal/task"
9
+ )
10
+
11
+ func TestClaimUsesOneLabelAdd(t *testing.T) {
12
+ fake := &fakeJira{}
13
+ sys := newSystemWithFake(t, fake)
14
+ if err := sys.Claim(context.Background(), task.TicketRef{Key: "PAY-1"}, "flow"); err != nil {
15
+ t.Fatal(err)
16
+ }
17
+ if len(fake.labelCalls) != 1 || fake.labelCalls[0] != "PAY-1:wf:flow" {
18
+ t.Fatalf("label calls = %v, want one claim update", fake.labelCalls)
19
+ }
20
+ }
21
+
22
+ func TestCommentKeepsMarkerIdempotency(t *testing.T) {
23
+ fake := &fakeJira{comments: []string{"existing\n<!-- visit:summary -->"}}
24
+ sys := newSystemWithFake(t, fake)
25
+ target := task.Target{Parent: task.TicketRef{Key: "PAY-1"}}
26
+ if err := sys.Comment(context.Background(), target, "summary", "visit:summary"); err != nil {
27
+ t.Fatal(err)
28
+ }
29
+ if len(fake.addedComments) != 0 {
30
+ t.Fatal("duplicate marked comment was posted")
31
+ }
32
+ fake.comments = nil
33
+ if err := sys.Comment(context.Background(), target, "summary", "visit:summary"); err != nil {
34
+ t.Fatal(err)
35
+ }
36
+ if len(fake.addedComments) != 1 || !strings.Contains(fake.addedComments[0], "visit:summary") {
37
+ t.Fatalf("posted comments = %v", fake.addedComments)
38
+ }
39
+ }
@@ -0,0 +1,254 @@
1
+ package jira
2
+
3
+ import (
4
+ "context"
5
+ "os"
6
+ "strings"
7
+ "testing"
8
+
9
+ "github.com/rajpopat27/relay-flow/internal/config"
10
+ "github.com/rajpopat27/relay-flow/internal/task"
11
+ )
12
+
13
+ // 3.13: filter tests per specs/repo-workflow-routing "Workflow filters are
14
+ // structured and locally evaluable": the adapter compiles workflow
15
+ // taskConfig.filters into matchers over normalized ticket fields; matching
16
+ // is in-memory against one repo poll batch (no per-workflow re-query).
17
+ // Package-local so it can use the adapter's test seams without exporting
18
+ // production API.
19
+
20
+ // pollCountingSystem wraps the adapter's Poll to prove matchers never
21
+ // trigger another fetch.
22
+ type pollCountingSystem struct {
23
+ task.System
24
+ polls int
25
+ }
26
+
27
+ func (p *pollCountingSystem) Poll(ctx context.Context) ([]task.Ticket, error) {
28
+ p.polls++
29
+ return p.System.Poll(ctx)
30
+ }
31
+
32
+ func TestCompileFilterMatchesNormalizedFields(t *testing.T) {
33
+ sys := newSystemWithFake(t, &fakeJira{})
34
+
35
+ match, err := sys.CompileFilter(config.RawValues{
36
+ "filters": map[string]any{
37
+ "parentStatuses": []any{"To Do"},
38
+ "issueTypes": []any{"Task"},
39
+ "labels": []any{"coding"},
40
+ },
41
+ })
42
+ if err != nil {
43
+ t.Fatalf("CompileFilter failed: %v", err)
44
+ }
45
+
46
+ ticket := task.Ticket{
47
+ ID: "1", Key: "PAY-101",
48
+ Fields: map[string]any{
49
+ "status": "To Do",
50
+ "issueType": "Task",
51
+ "labels": []string{"coding", "backend"},
52
+ },
53
+ }
54
+ if !match(ticket) {
55
+ t.Fatal("matching ticket rejected by compiled filter")
56
+ }
57
+ }
58
+
59
+ func TestCompileFilterRejectsNonMatching(t *testing.T) {
60
+ sys := newSystemWithFake(t, &fakeJira{})
61
+ match, err := sys.CompileFilter(config.RawValues{
62
+ "filters": map[string]any{"parentStatuses": []any{"To Do"}},
63
+ })
64
+ if err != nil {
65
+ t.Fatalf("CompileFilter failed: %v", err)
66
+ }
67
+ for _, tc := range []struct {
68
+ name string
69
+ fields map[string]any
70
+ }{
71
+ {"wrong status", map[string]any{"status": "Done", "issueType": "Task"}},
72
+ {"missing status", map[string]any{"issueType": "Task"}},
73
+ } {
74
+ t.Run(tc.name, func(t *testing.T) {
75
+ if match(task.Ticket{Key: "PAY-1", Fields: tc.fields}) {
76
+ t.Fatal("non-matching ticket accepted")
77
+ }
78
+ })
79
+ }
80
+ }
81
+
82
+ func TestCompileFilterRejectsUnknownField(t *testing.T) {
83
+ sys := newSystemWithFake(t, &fakeJira{})
84
+ if _, err := sys.CompileFilter(config.RawValues{
85
+ "filters": map[string]any{"jql": "project = PAY"},
86
+ }); err == nil {
87
+ t.Fatal("arbitrary query/filter field accepted; workflow validation must reject it")
88
+ }
89
+ }
90
+
91
+ func TestMatchingIsInMemoryNoRequery(t *testing.T) {
92
+ // One repo poll fetches the batch; the compiled matcher then evaluates
93
+ // every ticket in memory with no per-workflow re-query.
94
+ fake := &fakeJira{searchJSON: []byte(`[{"id":"1","key":"PAY-1","fields":{"summary":"a","status":{"name":"To Do"},"issuetype":{"name":"Task"},"labels":[]}},{"id":"2","key":"PAY-2","fields":{"summary":"b","status":{"name":"Done"},"issuetype":{"name":"Task"},"labels":[]}},{"id":"3","key":"PAY-3","fields":{"summary":"c","status":{"name":"To Do"},"issuetype":{"name":"Task"},"labels":[]}}]`)}
95
+ base := newSystemWithFake(t, fake)
96
+ counting := &pollCountingSystem{System: base}
97
+
98
+ match, err := counting.CompileFilter(config.RawValues{
99
+ "filters": map[string]any{"parentStatuses": []any{"To Do"}},
100
+ })
101
+ if err != nil {
102
+ t.Fatal(err)
103
+ }
104
+
105
+ // The single repo poll.
106
+ batch, err := counting.Poll(context.Background())
107
+ if err != nil {
108
+ t.Fatal(err)
109
+ }
110
+ if counting.polls != 1 {
111
+ t.Fatalf("polls = %d, want exactly 1 repo poll", counting.polls)
112
+ }
113
+ if len(batch) == 0 {
114
+ t.Fatal("poll returned no batch to match against")
115
+ }
116
+
117
+ // Matching the batch must not trigger another poll.
118
+ var matched int
119
+ for _, tk := range batch {
120
+ if match(tk) {
121
+ matched++
122
+ }
123
+ }
124
+ if counting.polls != 1 {
125
+ t.Fatalf("matching triggered %d extra task-system polls; matching must be in-memory", counting.polls-1)
126
+ }
127
+ }
128
+
129
+ func TestJiraJSONNormalization(t *testing.T) {
130
+ // The adapter normalizes Jira search JSON (status, issue type, labels,
131
+ // assignee) into task.Ticket.Fields. Package-local so it can call the
132
+ // adapter's unexported normalization directly.
133
+ // The REST boundary supplies a normalized array of issue objects, and the
134
+ // normalized assignee is the user's email address — the stable identity
135
+ // workflow filters match on, not the human-readable display name.
136
+ raw := []byte(`[{"id":"1","key":"PAY-101","fields":{"summary":"parent","status":{"name":"To Do"},"issuetype":{"name":"Task"},"labels":["coding"],"assignee":{"displayName":"Relay Bot","emailAddress":"relay@bot"}}}]`)
137
+
138
+ tickets, err := normalizeSearchResponse(raw)
139
+ if err != nil {
140
+ t.Fatalf("normalization failed: %v", err)
141
+ }
142
+ if len(tickets) != 1 {
143
+ t.Fatalf("tickets = %d, want 1", len(tickets))
144
+ }
145
+ tk := tickets[0]
146
+ if tk.Fields["status"] != "To Do" {
147
+ t.Fatalf("status = %v", tk.Fields["status"])
148
+ }
149
+ if tk.Fields["issueType"] != "Task" {
150
+ t.Fatalf("issueType = %v", tk.Fields["issueType"])
151
+ }
152
+ labels, ok := tk.Fields["labels"].([]string)
153
+ if !ok || len(labels) != 1 || labels[0] != "coding" {
154
+ t.Fatalf("labels = %v", tk.Fields["labels"])
155
+ }
156
+ // Raw Jira assignee object is normalized to its email address.
157
+ if tk.Fields["assignee"] != "relay@bot" {
158
+ t.Fatalf("assignee = %v, want normalized email address", tk.Fields["assignee"])
159
+ }
160
+ }
161
+
162
+ func TestJiraJSONNormalizationFiltersOnlyOpenInwardBlockers(t *testing.T) {
163
+ raw := []byte(`[
164
+ {"id":"1","key":"PAY-1","fields":{"summary":"open blocker","status":{"name":"To Do"},"issuetype":{"name":"Task"},"labels":[],"issuelinks":[
165
+ {"type":{"name":"Blocks"},"inwardIssue":{"key":"OTHER-1","fields":{"status":{"statusCategory":{"key":"done"}}}}},
166
+ {"type":{"name":"Blocks"},"inwardIssue":{"key":"OTHER-2","fields":{"status":{"statusCategory":{"key":"new"}}}}}
167
+ ]}},
168
+ {"id":"2","key":"PAY-2","fields":{"summary":"closed blockers","status":{"name":"To Do"},"issuetype":{"name":"Task"},"labels":[],"issuelinks":[
169
+ {"type":{"name":"Blocks"},"inwardIssue":{"key":"OTHER-3","fields":{"status":{"statusCategory":{"key":"done"}}}}}
170
+ ]}},
171
+ {"id":"3","key":"PAY-3","fields":{"summary":"blocks another","status":{"name":"To Do"},"issuetype":{"name":"Task"},"labels":[],"issuelinks":[
172
+ {"type":{"name":"Blocks"},"outwardIssue":{"key":"OTHER-4","fields":{"status":{"statusCategory":{"key":"new"}}}}}
173
+ ]}}
174
+ ]`)
175
+ tickets, err := normalizeSearchResponse(raw)
176
+ if err != nil {
177
+ t.Fatal(err)
178
+ }
179
+ if len(tickets) != 2 || tickets[0].Key != "PAY-2" || tickets[1].Key != "PAY-3" {
180
+ t.Fatalf("eligible tickets = %+v, want PAY-2 and PAY-3", tickets)
181
+ }
182
+ }
183
+
184
+ func TestJiraJSONNormalizationParsesCapturedIssueShape(t *testing.T) {
185
+ // Preserve the captured issue-field fixture while the REST client contract
186
+ // itself is exercised through strict HTTP tests.
187
+ raw, err := os.ReadFile("testdata/jira_search_issues.json")
188
+ if err != nil {
189
+ t.Fatalf("read Jira fixture: %v", err)
190
+ }
191
+ tickets, err := normalizeSearchResponse(raw)
192
+ if err != nil {
193
+ t.Fatalf("normalization of captured Jira output failed: %v", err)
194
+ }
195
+ if len(tickets) == 0 {
196
+ t.Fatal("captured Jira fixture yielded no tickets")
197
+ }
198
+ for _, tk := range tickets {
199
+ if tk.Key == "" || tk.ID == "" {
200
+ t.Fatalf("ticket missing id/key: %+v", tk)
201
+ }
202
+ if tk.Fields["status"] == "" || tk.Fields["issueType"] == "" {
203
+ t.Fatalf("ticket %s missing status/issueType: %+v", tk.Key, tk.Fields)
204
+ }
205
+ if _, ok := tk.Fields["labels"].([]string); !ok {
206
+ t.Fatalf("ticket %s labels not normalized to []string: %+v", tk.Key, tk.Fields)
207
+ }
208
+ // The fixture is captured with assignee=currentUser(), so every
209
+ // entry carries an email-form normalized assignee.
210
+ a, _ := tk.Fields["assignee"].(string)
211
+ if a == "" || !strings.Contains(a, "@") {
212
+ t.Fatalf("ticket %s assignee = %q, want an email address", tk.Key, a)
213
+ }
214
+ }
215
+ }
216
+
217
+ func TestCompileFilterAssigneeMatchesEmail(t *testing.T) {
218
+ // 9.9: workflow assignee filters match the normalized EMAIL identity,
219
+ // not the display name. e2e workflow.yaml filters on the user's email.
220
+ sys := newSystemWithFake(t, &fakeJira{})
221
+ match, err := sys.CompileFilter(config.RawValues{
222
+ "filters": map[string]any{"assignees": []any{"raj.popat@example.com"}},
223
+ })
224
+ if err != nil {
225
+ t.Fatalf("CompileFilter failed: %v", err)
226
+ }
227
+ if !match(task.Ticket{Key: "PAY-1", Fields: map[string]any{"assignee": "raj.popat@example.com"}}) {
228
+ t.Fatal("email assignee rejected")
229
+ }
230
+ if match(task.Ticket{Key: "PAY-1", Fields: map[string]any{"assignee": "Raj Popat"}}) {
231
+ t.Fatal("display name accepted; filters must match the normalized email")
232
+ }
233
+ }
234
+
235
+ func TestCompileFilterAssigneeMatchAndMismatch(t *testing.T) {
236
+ // Assignee is a supported structured filter dimension
237
+ // (repo-workflow-routing: "parent statuses, issue types, labels, and
238
+ // assignee"); it matches the normalized ticket's assignee field.
239
+ // NOTE: the filter key `assignees` follows the same naming as
240
+ // parentStatuses/issueTypes/labels (plural); the docs do not pin the key.
241
+ sys := newSystemWithFake(t, &fakeJira{})
242
+ match, err := sys.CompileFilter(config.RawValues{
243
+ "filters": map[string]any{"assignees": []any{"relay-bot@example.com"}},
244
+ })
245
+ if err != nil {
246
+ t.Fatalf("CompileFilter failed: %v", err)
247
+ }
248
+ if !match(task.Ticket{Key: "PAY-1", Fields: map[string]any{"assignee": "relay-bot@example.com"}}) {
249
+ t.Fatal("matching assignee rejected")
250
+ }
251
+ if match(task.Ticket{Key: "PAY-1", Fields: map[string]any{"assignee": "someone-else@example.com"}}) {
252
+ t.Fatal("non-matching assignee accepted")
253
+ }
254
+ }
@@ -0,0 +1,70 @@
1
+ package jira
2
+
3
+ import (
4
+ "context"
5
+
6
+ "github.com/rajpopat27/relay-flow/internal/task"
7
+ "github.com/rajpopat27/relay-flow/internal/task/jira/rest"
8
+ )
9
+
10
+ // fakeClient adapts the test-local Jira fake to the production REST seam.
11
+ type fakeClient struct {
12
+ fake *fakeJira
13
+ }
14
+
15
+ func (f *fakeClient) Search(context.Context, string) ([]byte, error) {
16
+ return f.fake.searchJSON, nil
17
+ }
18
+
19
+ func (f *fakeClient) ValidateCredentials(context.Context) error { return nil }
20
+
21
+ func (f *fakeClient) ValidateAssignee(context.Context, string, string) error { return nil }
22
+
23
+ func (f *fakeClient) ValidateStatus(context.Context, string, string) error { return nil }
24
+
25
+ func (f *fakeClient) View(context.Context, string) ([]byte, error) {
26
+ return []byte(`{"fields":{"labels":[],"subtasks":[]}}`), nil
27
+ }
28
+
29
+ func (f *fakeClient) CreateSubtasks(context.Context, string, string, string, []rest.SubtaskSpec) ([]rest.CreatedSubtask, error) {
30
+ return nil, errNotFaked
31
+ }
32
+
33
+ func (f *fakeClient) Transition(_ context.Context, key, status, assignee string) error {
34
+ if assignee != "" {
35
+ f.fake.assignments = append(f.fake.assignments, key+":"+assignee)
36
+ if f.fake.assignErr != nil {
37
+ return f.fake.assignErr
38
+ }
39
+ }
40
+ f.fake.events = append(f.fake.events, "transition")
41
+ f.fake.transition(key, status)
42
+ return nil
43
+ }
44
+
45
+ func (f *fakeClient) EnsureLabel(_ context.Context, key, label string) error {
46
+ f.fake.labelCalls = append(f.fake.labelCalls, key+":"+label)
47
+ return nil
48
+ }
49
+
50
+ func (f *fakeClient) UpdateMailbox(context.Context, string, string, string) error { return nil }
51
+
52
+ func (f *fakeClient) ListComments(context.Context, string) ([]string, error) {
53
+ return append([]string(nil), f.fake.comments...), nil
54
+ }
55
+
56
+ func (f *fakeClient) AddComment(_ context.Context, _ string, body string) error {
57
+ f.fake.addedComments = append(f.fake.addedComments, body)
58
+ return nil
59
+ }
60
+
61
+ type notFakedError struct{}
62
+
63
+ func (notFakedError) Error() string { return "not faked" }
64
+
65
+ var errNotFaked = notFakedError{}
66
+
67
+ // newSystemForTest builds the adapter around the test-local REST seam.
68
+ func newSystemForTest(fake *fakeJira) (task.System, error) {
69
+ return newSystemForCLI(&fakeClient{fake: fake})
70
+ }