Skip to content

Commit

Permalink
fix: allow include loops while preventing task loops (#161)
Browse files Browse the repository at this point in the history
## Description

Marking this as a fix to #122 since it will fix the issue in most cases
and it allows loops since those can be valid constructs in some cases.
Long term we still need to refactor this code.

## Related Issue

Fixes #122

## Type of change

- [X] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [X] Test, docs, adr added or updated as needed
- [X] [Contributor Guide
Steps](https://github.com/defenseunicorns/maru-runner/blob/main/CONTRIBUTING.md)
followed
  • Loading branch information
Racer159 authored Oct 17, 2024
1 parent c29d41d commit 385a952
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 103 deletions.
3 changes: 3 additions & 0 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ var (
// VendorPrefix is the prefix for environment variables that an application vendoring Maru wants to use
VendorPrefix string

// MaxStack is the maximum stack size for task references
MaxStack = 2048

extraEnv = map[string]string{"MARU": "true", "MARU_ARCH": GetArch()}
)

Expand Down
86 changes: 43 additions & 43 deletions src/pkg/runner/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ func Test_validateActionableTaskCall(t *testing.T) {

func TestRunner_performAction(t *testing.T) {
type fields struct {
TasksFile types.TasksFile
TaskNameMap map[string]bool
envFilePath string
variableConfig *variables.VariableConfig[variables.ExtraVariableInfo]
TasksFile types.TasksFile
ExistingTaskIncludeNameLocation map[string]string
envFilePath string
variableConfig *variables.VariableConfig[variables.ExtraVariableInfo]
}
type args struct {
action types.Action
Expand All @@ -243,10 +243,10 @@ func TestRunner_performAction(t *testing.T) {
{
name: "failed action processing due to invalid command",
fields: fields{
TasksFile: types.TasksFile{},
TaskNameMap: make(map[string]bool),
envFilePath: "",
variableConfig: GetMaruVariableConfig(),
TasksFile: types.TasksFile{},
ExistingTaskIncludeNameLocation: make(map[string]string),
envFilePath: "",
variableConfig: GetMaruVariableConfig(),
},
args: args{
action: types.Action{
Expand All @@ -264,10 +264,10 @@ func TestRunner_performAction(t *testing.T) {
{
name: "Unable to open path",
fields: fields{
TasksFile: types.TasksFile{},
TaskNameMap: make(map[string]bool),
envFilePath: "test/path",
variableConfig: GetMaruVariableConfig(),
TasksFile: types.TasksFile{},
ExistingTaskIncludeNameLocation: make(map[string]string),
envFilePath: "test/path",
variableConfig: GetMaruVariableConfig(),
},
args: args{
action: types.Action{
Expand All @@ -293,10 +293,10 @@ func TestRunner_performAction(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := &Runner{
TasksFile: tt.fields.TasksFile,
TaskNameMap: tt.fields.TaskNameMap,
envFilePath: tt.fields.envFilePath,
variableConfig: tt.fields.variableConfig,
TasksFile: tt.fields.TasksFile,
ExistingTaskIncludeNameLocation: tt.fields.ExistingTaskIncludeNameLocation,
envFilePath: tt.fields.envFilePath,
variableConfig: tt.fields.variableConfig,
}
err := r.performAction(tt.args.action, tt.args.withs, tt.args.inputs)
if (err != nil) != tt.wantErr {
Expand All @@ -308,10 +308,10 @@ func TestRunner_performAction(t *testing.T) {

func TestRunner_processAction(t *testing.T) {
type fields struct {
TasksFile types.TasksFile
TaskNameMap map[string]bool
envFilePath string
variableConfig *variables.VariableConfig[variables.ExtraVariableInfo]
TasksFile types.TasksFile
ExistingTaskIncludeNameLocation map[string]string
envFilePath string
variableConfig *variables.VariableConfig[variables.ExtraVariableInfo]
}
type args struct {
task types.Task
Expand All @@ -326,10 +326,10 @@ func TestRunner_processAction(t *testing.T) {
{
name: "successful action processing",
fields: fields{
TasksFile: types.TasksFile{},
TaskNameMap: map[string]bool{},
envFilePath: "",
variableConfig: GetMaruVariableConfig(),
TasksFile: types.TasksFile{},
ExistingTaskIncludeNameLocation: map[string]string{},
envFilePath: "",
variableConfig: GetMaruVariableConfig(),
},
args: args{
task: types.Task{
Expand All @@ -344,10 +344,10 @@ func TestRunner_processAction(t *testing.T) {
{
name: "action processing with same task and action reference",
fields: fields{
TasksFile: types.TasksFile{},
TaskNameMap: map[string]bool{},
envFilePath: "",
variableConfig: GetMaruVariableConfig(),
TasksFile: types.TasksFile{},
ExistingTaskIncludeNameLocation: map[string]string{},
envFilePath: "",
variableConfig: GetMaruVariableConfig(),
},
args: args{
task: types.Task{
Expand All @@ -362,10 +362,10 @@ func TestRunner_processAction(t *testing.T) {
{
name: "action processing with empty task reference",
fields: fields{
TasksFile: types.TasksFile{},
TaskNameMap: map[string]bool{},
envFilePath: "",
variableConfig: GetMaruVariableConfig(),
TasksFile: types.TasksFile{},
ExistingTaskIncludeNameLocation: map[string]string{},
envFilePath: "",
variableConfig: GetMaruVariableConfig(),
},
args: args{
task: types.Task{
Expand All @@ -380,10 +380,10 @@ func TestRunner_processAction(t *testing.T) {
{
name: "action processing with non-empty task reference and different task and action reference names",
fields: fields{
TasksFile: types.TasksFile{},
TaskNameMap: map[string]bool{},
envFilePath: "",
variableConfig: GetMaruVariableConfig(),
TasksFile: types.TasksFile{},
ExistingTaskIncludeNameLocation: map[string]string{},
envFilePath: "",
variableConfig: GetMaruVariableConfig(),
},
args: args{
task: types.Task{
Expand All @@ -405,9 +405,9 @@ func TestRunner_processAction(t *testing.T) {
},
},
},
TaskNameMap: map[string]bool{},
envFilePath: "",
variableConfig: GetMaruVariableConfig(),
ExistingTaskIncludeNameLocation: map[string]string{},
envFilePath: "",
variableConfig: GetMaruVariableConfig(),
},
args: args{
task: types.Task{
Expand All @@ -423,10 +423,10 @@ func TestRunner_processAction(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := &Runner{
TasksFile: tt.fields.TasksFile,
TaskNameMap: tt.fields.TaskNameMap,
envFilePath: tt.fields.envFilePath,
variableConfig: tt.fields.variableConfig,
TasksFile: tt.fields.TasksFile,
ExistingTaskIncludeNameLocation: tt.fields.ExistingTaskIncludeNameLocation,
envFilePath: tt.fields.envFilePath,
variableConfig: tt.fields.variableConfig,
}
if got := r.processAction(tt.args.task, tt.args.action); got != tt.want {
t.Errorf("processAction() got = %v, want %v", got, tt.want)
Expand Down
Loading

0 comments on commit 385a952

Please sign in to comment.