Files
osmedeus/internal/core/workflow_help_test.go
T
j3ssie 4ac041fd73 feat: add workflow help metadata, artifact optional flag, and search/filter improvements
- Add WorkflowHelp struct with Usage and ExampleTargets for CLI documentation
- Add Optional field to Artifact model and database schema with migration support
- Implement workflow search functionality by name, description, and tags in CLI list command
- Add --usage and --search flags to workflow list command with multiple filtering options
- Display workflow usage info in show command when Help is defined
- Support help inheritance in workflow extends/inheritance resolver
- Update vulnerability counters from database after SARIF imports
- Add comprehensive Help unit tests covering parsing, cloning, and mutation isolation
- Improve test helpers with streaming output, diagnostics, and file validation utilities
- Add fourth general canary test for domain-list-recon flow with artifact validation
2026-02-12 01:04:03 +07:00

129 lines
3.1 KiB
Go

package core
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)
func TestWorkflowHelpYAMLParsing(t *testing.T) {
t.Run("both fields", func(t *testing.T) {
data := `
kind: module
name: test
help:
example_targets: ['example.com', 'httpbin.org']
usage: osmedeus run -m test -t <target>
steps:
- name: s1
type: bash
command: echo hi
`
var wf Workflow
err := yaml.Unmarshal([]byte(data), &wf)
require.NoError(t, err)
require.NotNil(t, wf.Help)
assert.Equal(t, "osmedeus run -m test -t <target>", wf.Help.Usage)
assert.Equal(t, []string{"example.com", "httpbin.org"}, wf.Help.ExampleTargets)
})
t.Run("usage only", func(t *testing.T) {
data := `
kind: module
name: test
help:
usage: osmedeus run -m test -t <target>
steps:
- name: s1
type: bash
command: echo hi
`
var wf Workflow
err := yaml.Unmarshal([]byte(data), &wf)
require.NoError(t, err)
require.NotNil(t, wf.Help)
assert.Equal(t, "osmedeus run -m test -t <target>", wf.Help.Usage)
assert.Empty(t, wf.Help.ExampleTargets)
})
t.Run("omitted", func(t *testing.T) {
data := `
kind: module
name: test
steps:
- name: s1
type: bash
command: echo hi
`
var wf Workflow
err := yaml.Unmarshal([]byte(data), &wf)
require.NoError(t, err)
assert.Nil(t, wf.Help)
})
}
func TestWorkflowGetUsage(t *testing.T) {
t.Run("nil help", func(t *testing.T) {
wf := &Workflow{}
assert.Equal(t, "", wf.GetUsage())
})
t.Run("non-nil help", func(t *testing.T) {
wf := &Workflow{
Help: &WorkflowHelp{Usage: "osmedeus run -m test -t example.com"},
}
assert.Equal(t, "osmedeus run -m test -t example.com", wf.GetUsage())
})
}
func TestWorkflowGetExampleTargets(t *testing.T) {
t.Run("nil help", func(t *testing.T) {
wf := &Workflow{}
assert.Nil(t, wf.GetExampleTargets())
})
t.Run("non-nil help", func(t *testing.T) {
wf := &Workflow{
Help: &WorkflowHelp{ExampleTargets: []string{"example.com", "httpbin.org"}},
}
assert.Equal(t, []string{"example.com", "httpbin.org"}, wf.GetExampleTargets())
})
}
func TestWorkflowHelpClone(t *testing.T) {
t.Run("nil help", func(t *testing.T) {
var h *WorkflowHelp
assert.Nil(t, h.Clone())
})
t.Run("deep copy and mutation isolation", func(t *testing.T) {
original := &WorkflowHelp{
ExampleTargets: []string{"example.com", "httpbin.org"},
Usage: "osmedeus run -m test -t <target>",
}
cloned := original.Clone()
require.NotNil(t, cloned)
assert.Equal(t, original.Usage, cloned.Usage)
assert.Equal(t, original.ExampleTargets, cloned.ExampleTargets)
// Mutate clone and verify original is unaffected
cloned.Usage = "changed"
cloned.ExampleTargets[0] = "changed.com"
assert.Equal(t, "osmedeus run -m test -t <target>", original.Usage)
assert.Equal(t, "example.com", original.ExampleTargets[0])
})
t.Run("empty example targets", func(t *testing.T) {
original := &WorkflowHelp{
Usage: "some usage",
}
cloned := original.Clone()
require.NotNil(t, cloned)
assert.Equal(t, "some usage", cloned.Usage)
assert.Nil(t, cloned.ExampleTargets)
})
}