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
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
package workflow
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"fmt"
|
|
5
|
+
"os"
|
|
6
|
+
"path/filepath"
|
|
7
|
+
"sort"
|
|
8
|
+
"strings"
|
|
9
|
+
"sync"
|
|
10
|
+
|
|
11
|
+
"github.com/rajpopat27/relay-flow/internal/config"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
// Store persists workflow definitions as YAML files under Dir. The workflow
|
|
15
|
+
// file is the durable definition.
|
|
16
|
+
type Store struct {
|
|
17
|
+
Dir string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
func (s *Store) path(name string) string {
|
|
21
|
+
return filepath.Join(s.Dir, name+".yaml")
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// LoadAll reads and parses every stored workflow file.
|
|
25
|
+
func (s *Store) LoadAll() ([]*Workflow, error) {
|
|
26
|
+
entries, err := os.ReadDir(s.Dir)
|
|
27
|
+
if err != nil {
|
|
28
|
+
if os.IsNotExist(err) {
|
|
29
|
+
return nil, nil
|
|
30
|
+
}
|
|
31
|
+
return nil, fmt.Errorf("read workflow dir %s: %w", s.Dir, err)
|
|
32
|
+
}
|
|
33
|
+
var out []*Workflow
|
|
34
|
+
for _, e := range entries {
|
|
35
|
+
if e.IsDir() || !strings.HasSuffix(e.Name(), ".yaml") {
|
|
36
|
+
continue
|
|
37
|
+
}
|
|
38
|
+
name := strings.TrimSuffix(e.Name(), ".yaml")
|
|
39
|
+
wf, err := s.Get(name)
|
|
40
|
+
if err != nil {
|
|
41
|
+
return nil, err
|
|
42
|
+
}
|
|
43
|
+
out = append(out, wf)
|
|
44
|
+
}
|
|
45
|
+
return out, nil
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Get reads and parses one stored workflow by name.
|
|
49
|
+
func (s *Store) Get(name string) (*Workflow, error) {
|
|
50
|
+
raw, err := os.ReadFile(s.path(name))
|
|
51
|
+
if err != nil {
|
|
52
|
+
return nil, fmt.Errorf("read workflow %q: %w", name, err)
|
|
53
|
+
}
|
|
54
|
+
return Parse(name, raw)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Put atomically writes the workflow file with mode 0644.
|
|
58
|
+
func (s *Store) Put(name string, yamlBytes []byte) error {
|
|
59
|
+
if err := os.MkdirAll(s.Dir, 0o755); err != nil {
|
|
60
|
+
return fmt.Errorf("create workflow dir %s: %w", s.Dir, err)
|
|
61
|
+
}
|
|
62
|
+
if err := config.WriteAtomic(s.path(name), yamlBytes, 0o644); err != nil {
|
|
63
|
+
return fmt.Errorf("store workflow %q: %w", name, err)
|
|
64
|
+
}
|
|
65
|
+
return nil
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Remove deletes the workflow file.
|
|
69
|
+
func (s *Store) Remove(name string) error {
|
|
70
|
+
if err := os.Remove(s.path(name)); err != nil {
|
|
71
|
+
return fmt.Errorf("remove workflow %q: %w", name, err)
|
|
72
|
+
}
|
|
73
|
+
return nil
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Registry is the in-memory workflow set. The registry has no repo index;
|
|
77
|
+
// repo bindings are the only derived repo-to-workflow index.
|
|
78
|
+
type Registry struct {
|
|
79
|
+
mu sync.RWMutex
|
|
80
|
+
byID map[string]*Workflow
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
func (r *Registry) get(name string) (*Workflow, bool) {
|
|
84
|
+
r.mu.RLock()
|
|
85
|
+
defer r.mu.RUnlock()
|
|
86
|
+
wf, ok := r.byID[name]
|
|
87
|
+
return wf, ok
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Get returns the workflow by name.
|
|
91
|
+
func (r *Registry) Get(name string) (*Workflow, bool) {
|
|
92
|
+
return r.get(name)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// List returns all registered workflows sorted by name.
|
|
96
|
+
func (r *Registry) List() []*Workflow {
|
|
97
|
+
r.mu.RLock()
|
|
98
|
+
defer r.mu.RUnlock()
|
|
99
|
+
out := make([]*Workflow, 0, len(r.byID))
|
|
100
|
+
for _, wf := range r.byID {
|
|
101
|
+
out = append(out, wf)
|
|
102
|
+
}
|
|
103
|
+
sort.Slice(out, func(i, j int) bool { return out[i].Name < out[j].Name })
|
|
104
|
+
return out
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ReferencesRepo reports whether any registered workflow lists the repo.
|
|
108
|
+
func (r *Registry) ReferencesRepo(repo string) bool {
|
|
109
|
+
r.mu.RLock()
|
|
110
|
+
defer r.mu.RUnlock()
|
|
111
|
+
for _, wf := range r.byID {
|
|
112
|
+
for _, rr := range wf.Repos {
|
|
113
|
+
if rr == repo {
|
|
114
|
+
return true
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return false
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Replace creates or replaces the workflow in the registry.
|
|
122
|
+
func (r *Registry) Replace(wf *Workflow) {
|
|
123
|
+
r.mu.Lock()
|
|
124
|
+
defer r.mu.Unlock()
|
|
125
|
+
if r.byID == nil {
|
|
126
|
+
r.byID = map[string]*Workflow{}
|
|
127
|
+
}
|
|
128
|
+
r.byID[wf.Name] = wf
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Remove deletes the workflow from the registry.
|
|
132
|
+
func (r *Registry) Remove(name string) {
|
|
133
|
+
r.mu.Lock()
|
|
134
|
+
defer r.mu.Unlock()
|
|
135
|
+
delete(r.byID, name)
|
|
136
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
package workflow_test
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"errors"
|
|
6
|
+
"os"
|
|
7
|
+
"path/filepath"
|
|
8
|
+
"strings"
|
|
9
|
+
"testing"
|
|
10
|
+
|
|
11
|
+
"github.com/rajpopat27/relay-flow/internal/workflow"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
// 3.34: workflow storage/service per specs/workflow-repo-management
|
|
15
|
+
// "Workflow definitions are persisted atomically" and "Workflow replacement
|
|
16
|
+
// has no concurrent versions" / "Workflow removal protects active runs".
|
|
17
|
+
|
|
18
|
+
const storeValid = `
|
|
19
|
+
name: basicFlow
|
|
20
|
+
repos: [payments]
|
|
21
|
+
nodes:
|
|
22
|
+
start:
|
|
23
|
+
onSuccess:
|
|
24
|
+
- target: coding
|
|
25
|
+
coding:
|
|
26
|
+
type: agent
|
|
27
|
+
agent: build
|
|
28
|
+
description: work
|
|
29
|
+
onSuccess:
|
|
30
|
+
- target: end
|
|
31
|
+
onFailure:
|
|
32
|
+
- target: coding
|
|
33
|
+
end: {}
|
|
34
|
+
`
|
|
35
|
+
|
|
36
|
+
type fakeActiveRuns struct{ active map[string]bool }
|
|
37
|
+
|
|
38
|
+
func (f *fakeActiveRuns) HasActiveWorkflow(_ context.Context, name string) (bool, error) {
|
|
39
|
+
return f.active[name], nil
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func (f *fakeActiveRuns) set(name string, on bool) { f.active[name] = on }
|
|
43
|
+
|
|
44
|
+
type fakeRepoLookup struct{ repos map[string]bool }
|
|
45
|
+
|
|
46
|
+
func (f fakeRepoLookup) Exists(name string) bool { return f.repos[name] }
|
|
47
|
+
|
|
48
|
+
func newStore(t *testing.T) *workflow.Store {
|
|
49
|
+
t.Helper()
|
|
50
|
+
return &workflow.Store{Dir: t.TempDir()}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// newService builds a Service via its constructor over a temp store and the
|
|
54
|
+
// fake ActiveRuns/RepoLookup consumer interfaces.
|
|
55
|
+
func newService(t *testing.T, active *fakeActiveRuns, repos map[string]bool) (*workflow.Service, *workflow.Store) {
|
|
56
|
+
t.Helper()
|
|
57
|
+
store := newStore(t)
|
|
58
|
+
svc := workflow.NewService(store, active, fakeRepoLookup{repos: repos})
|
|
59
|
+
return svc, store
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
func TestStorePutGetLoadAll(t *testing.T) {
|
|
63
|
+
s := newStore(t)
|
|
64
|
+
if err := s.Put("basicFlow", []byte(storeValid)); err != nil {
|
|
65
|
+
t.Fatalf("Put failed: %v", err)
|
|
66
|
+
}
|
|
67
|
+
// File lands at <dir>/<name>.yaml with 0644.
|
|
68
|
+
fi, err := os.Stat(filepath.Join(s.Dir, "basicFlow.yaml"))
|
|
69
|
+
if err != nil {
|
|
70
|
+
t.Fatalf("workflow file not stored: %v", err)
|
|
71
|
+
}
|
|
72
|
+
if fi.Mode().Perm() != 0644 {
|
|
73
|
+
t.Fatalf("workflow file mode = %o, want 0644", fi.Mode().Perm())
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
wf, err := s.Get("basicFlow")
|
|
77
|
+
if err != nil {
|
|
78
|
+
t.Fatalf("Get failed: %v", err)
|
|
79
|
+
}
|
|
80
|
+
if wf.Name != "basicFlow" {
|
|
81
|
+
t.Fatalf("Get name = %q", wf.Name)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
all, err := s.LoadAll()
|
|
85
|
+
if err != nil || len(all) != 1 {
|
|
86
|
+
t.Fatalf("LoadAll = %d, %v", len(all), err)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if err := s.Remove("basicFlow"); err != nil {
|
|
90
|
+
t.Fatalf("Remove failed: %v", err)
|
|
91
|
+
}
|
|
92
|
+
if _, err := s.Get("basicFlow"); err == nil {
|
|
93
|
+
t.Fatal("Get after Remove succeeded")
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
func TestServiceSubmitValidatesBeforeStoring(t *testing.T) {
|
|
98
|
+
active := &fakeActiveRuns{active: map[string]bool{}}
|
|
99
|
+
svc, store := newService(t, active, map[string]bool{"payments": true})
|
|
100
|
+
|
|
101
|
+
// Invalid YAML must fail before any file is written.
|
|
102
|
+
if _, err := svc.Submit(context.Background(), []byte("name: bad name!!")); err == nil {
|
|
103
|
+
t.Fatal("invalid workflow submitted")
|
|
104
|
+
}
|
|
105
|
+
if _, err := store.Get("bad name!!"); err == nil {
|
|
106
|
+
t.Fatal("invalid workflow was stored")
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
wf, err := svc.Submit(context.Background(), []byte(storeValid))
|
|
110
|
+
if err != nil {
|
|
111
|
+
t.Fatalf("valid Submit failed: %v", err)
|
|
112
|
+
}
|
|
113
|
+
if wf.Name != "basicFlow" {
|
|
114
|
+
t.Fatalf("submitted name = %q", wf.Name)
|
|
115
|
+
}
|
|
116
|
+
// Submission updates the in-memory registry: the workflow is retrievable.
|
|
117
|
+
if _, err := svc.Get("basicFlow"); err != nil {
|
|
118
|
+
t.Fatal("submitted workflow not in registry after submit")
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
func TestServiceSubmitValidatesReferencedRepoConfigBeforeStoring(t *testing.T) {
|
|
123
|
+
active := &fakeActiveRuns{active: map[string]bool{}}
|
|
124
|
+
svc, store := newService(t, active, map[string]bool{"payments": true})
|
|
125
|
+
svc.ValidateTaskConfig = func(_ context.Context, wf *workflow.Workflow) error {
|
|
126
|
+
if wf.Nodes["coding"].TaskConfig["invalid"] == true {
|
|
127
|
+
return errors.New("repo payments node coding: invalid task config")
|
|
128
|
+
}
|
|
129
|
+
return nil
|
|
130
|
+
}
|
|
131
|
+
invalid := []byte(strings.Replace(storeValid, "description: work", "description: work\n taskConfig:\n invalid: true", 1))
|
|
132
|
+
|
|
133
|
+
if _, err := svc.Submit(context.Background(), invalid); err == nil || !strings.Contains(err.Error(), "invalid task config") {
|
|
134
|
+
t.Fatalf("Submit error = %v", err)
|
|
135
|
+
}
|
|
136
|
+
if _, err := store.Get("basicFlow"); err == nil {
|
|
137
|
+
t.Fatal("workflow was stored despite task validation failure")
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
func TestServiceSubmitRejectsUnknownRepo(t *testing.T) {
|
|
142
|
+
active := &fakeActiveRuns{active: map[string]bool{}}
|
|
143
|
+
svc, store := newService(t, active, map[string]bool{}) // no repos registered
|
|
144
|
+
if _, err := svc.Submit(context.Background(), []byte(storeValid)); err == nil {
|
|
145
|
+
t.Fatal("workflow referencing unregistered repo accepted")
|
|
146
|
+
}
|
|
147
|
+
if _, err := store.Get("basicFlow"); err == nil {
|
|
148
|
+
t.Fatal("unknown-repo workflow stored")
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
func TestServiceReplaceRejectedWhileActive(t *testing.T) {
|
|
153
|
+
active := &fakeActiveRuns{active: map[string]bool{}}
|
|
154
|
+
svc, store := newService(t, active, map[string]bool{"payments": true})
|
|
155
|
+
if _, err := svc.Submit(context.Background(), []byte(storeValid)); err != nil {
|
|
156
|
+
t.Fatal(err)
|
|
157
|
+
}
|
|
158
|
+
before, err := store.Get("basicFlow")
|
|
159
|
+
if err != nil {
|
|
160
|
+
t.Fatal(err)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Now a run is active; replacement must be rejected and the stored file
|
|
164
|
+
// and in-memory definition must remain unchanged. Change a REAL field
|
|
165
|
+
// (the coding node description), not just a comment.
|
|
166
|
+
active.set("basicFlow", true)
|
|
167
|
+
replacement := []byte(strings.Replace(storeValid, "description: work", "description: changed work", 1))
|
|
168
|
+
if _, err := svc.Submit(context.Background(), replacement); err == nil {
|
|
169
|
+
t.Fatal("replacement during active run accepted")
|
|
170
|
+
}
|
|
171
|
+
after, err := store.Get("basicFlow")
|
|
172
|
+
if err != nil {
|
|
173
|
+
t.Fatal(err)
|
|
174
|
+
}
|
|
175
|
+
if after.Name != before.Name {
|
|
176
|
+
t.Fatal("stored definition changed during rejected replacement")
|
|
177
|
+
}
|
|
178
|
+
if after.Nodes["coding"].Description != before.Nodes["coding"].Description {
|
|
179
|
+
t.Fatalf("in-memory definition changed during rejected replacement: %q -> %q",
|
|
180
|
+
before.Nodes["coding"].Description, after.Nodes["coding"].Description)
|
|
181
|
+
}
|
|
182
|
+
rawOnDisk, rerr := os.ReadFile(filepath.Join(store.Dir, "basicFlow.yaml"))
|
|
183
|
+
if rerr == nil && strings.Contains(string(rawOnDisk), "changed work") {
|
|
184
|
+
t.Fatal("stored workflow file changed during rejected replacement")
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// After completion, replacement succeeds and becomes the definition.
|
|
188
|
+
active.set("basicFlow", false)
|
|
189
|
+
if _, err := svc.Submit(context.Background(), replacement); err != nil {
|
|
190
|
+
t.Fatalf("replacement after completion rejected: %v", err)
|
|
191
|
+
}
|
|
192
|
+
installed, err := store.Get("basicFlow")
|
|
193
|
+
if err != nil {
|
|
194
|
+
t.Fatal(err)
|
|
195
|
+
}
|
|
196
|
+
if installed.Nodes["coding"].Description != "changed work" {
|
|
197
|
+
t.Fatalf("changed definition not installed after completion: %q", installed.Nodes["coding"].Description)
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
func TestServiceFailedWritePreservesExisting(t *testing.T) {
|
|
202
|
+
active := &fakeActiveRuns{active: map[string]bool{}}
|
|
203
|
+
svc, store := newService(t, active, map[string]bool{"payments": true})
|
|
204
|
+
if _, err := svc.Submit(context.Background(), []byte(storeValid)); err != nil {
|
|
205
|
+
t.Fatal(err)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Make the store directory read-only so the atomic replacement fails.
|
|
209
|
+
if err := os.Chmod(store.Dir, 0500); err != nil {
|
|
210
|
+
t.Fatal(err)
|
|
211
|
+
}
|
|
212
|
+
defer os.Chmod(store.Dir, 0700)
|
|
213
|
+
|
|
214
|
+
replacement := []byte(storeValid + "\n# changed\n")
|
|
215
|
+
if _, err := svc.Submit(context.Background(), replacement); err == nil {
|
|
216
|
+
t.Fatal("submission with failing write succeeded")
|
|
217
|
+
}
|
|
218
|
+
// Prior file and in-memory definition remain usable/active.
|
|
219
|
+
os.Chmod(store.Dir, 0700)
|
|
220
|
+
got, err := store.Get("basicFlow")
|
|
221
|
+
if err != nil {
|
|
222
|
+
t.Fatalf("prior workflow unusable after failed write: %v", err)
|
|
223
|
+
}
|
|
224
|
+
if got.Name != "basicFlow" {
|
|
225
|
+
t.Fatal("in-memory definition lost after failed write")
|
|
226
|
+
}
|
|
227
|
+
if _, err := svc.Get("basicFlow"); err != nil {
|
|
228
|
+
t.Fatal("in-memory definition lost after failed write")
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
func TestServiceRemoveProtectsActiveRuns(t *testing.T) {
|
|
233
|
+
active := &fakeActiveRuns{active: map[string]bool{}}
|
|
234
|
+
svc, _ := newService(t, active, map[string]bool{"payments": true})
|
|
235
|
+
if _, err := svc.Submit(context.Background(), []byte(storeValid)); err != nil {
|
|
236
|
+
t.Fatal(err)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
active.set("basicFlow", true)
|
|
240
|
+
if err := svc.Remove(context.Background(), "basicFlow"); err == nil {
|
|
241
|
+
t.Fatal("removal with active run accepted")
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
active.set("basicFlow", false)
|
|
245
|
+
if err := svc.Remove(context.Background(), "basicFlow"); err != nil {
|
|
246
|
+
t.Fatalf("removal without active runs rejected: %v", err)
|
|
247
|
+
}
|
|
248
|
+
if _, err := svc.Get("basicFlow"); err == nil {
|
|
249
|
+
t.Fatal("removed workflow still returned by Get")
|
|
250
|
+
}
|
|
251
|
+
// Registry updated on removal: List no longer returns it.
|
|
252
|
+
for _, w := range svc.List() {
|
|
253
|
+
if w.Name == "basicFlow" {
|
|
254
|
+
t.Fatal("removed workflow still listed")
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
func TestRegistryReferencesRepoAndReplace(t *testing.T) {
|
|
260
|
+
reg := &workflow.Registry{}
|
|
261
|
+
wf, err := workflow.Parse("basicFlow", []byte(storeValid))
|
|
262
|
+
if err != nil {
|
|
263
|
+
t.Fatal(err)
|
|
264
|
+
}
|
|
265
|
+
reg.Replace(wf)
|
|
266
|
+
if !reg.ReferencesRepo("payments") {
|
|
267
|
+
t.Fatal("ReferencesRepo(payments) = false")
|
|
268
|
+
}
|
|
269
|
+
if reg.ReferencesRepo("other") {
|
|
270
|
+
t.Fatal("ReferencesRepo(other) = true")
|
|
271
|
+
}
|
|
272
|
+
if got, ok := reg.Get("basicFlow"); !ok || got.Name != "basicFlow" {
|
|
273
|
+
t.Fatalf("Registry.Get = %v, %v", got, ok)
|
|
274
|
+
}
|
|
275
|
+
reg.Remove("basicFlow")
|
|
276
|
+
if _, ok := reg.Get("basicFlow"); ok {
|
|
277
|
+
t.Fatal("Registry.Get after Remove found workflow")
|
|
278
|
+
}
|
|
279
|
+
if reg.ReferencesRepo("payments") {
|
|
280
|
+
t.Fatal("ReferencesRepo still true after removal")
|
|
281
|
+
}
|
|
282
|
+
}
|