feat(agentic): accept variables alias for flow preview
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
bc21029ac5
commit
2802aef6b4
2 changed files with 62 additions and 2 deletions
|
|
@ -94,12 +94,12 @@ func (s *PrepSubsystem) cmdFlowPreview(options core.Options) core.Result {
|
|||
func (s *PrepSubsystem) runFlowCommand(options core.Options, commandLabel string) core.Result {
|
||||
flowPath := optionStringValue(options, "_arg", "path", "slug")
|
||||
if flowPath == "" {
|
||||
core.Print(nil, "usage: core-agent %s <path-or-slug> [--dry-run] [--var=key=value] [--vars='{\"key\":\"value\"}']", commandLabel)
|
||||
core.Print(nil, "usage: core-agent %s <path-or-slug> [--dry-run] [--var=key=value] [--vars='{\"key\":\"value\"}'] [--variables='{\"key\":\"value\"}']", commandLabel)
|
||||
return core.Result{Value: core.E("agentic.cmdRunFlow", "flow path or slug is required", nil), OK: false}
|
||||
}
|
||||
|
||||
dryRun := optionBoolValue(options, "dry_run", "dry-run")
|
||||
variables := optionStringMapValue(options, "var", "vars")
|
||||
variables := optionStringMapValue(options, "var", "vars", "variables")
|
||||
|
||||
flowResult := readFlowDocument(flowPath, variables)
|
||||
if !flowResult.OK {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ package agentic
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
core "dappco.re/go/core"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -105,3 +106,62 @@ func TestCommandsFlow_CmdRunFlow_Ugly_InvalidYaml(t *testing.T) {
|
|||
require.True(t, ok)
|
||||
assert.Contains(t, err.Error(), "invalid flow definition")
|
||||
}
|
||||
|
||||
func TestCommandsFlow_CmdFlowPreview_Good_VariablesAlias(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
flowPath := core.JoinPath(root, "preview.yaml")
|
||||
fs.Write(flowPath, ""+
|
||||
"name: \"{{NAME}} deployment\"\n"+
|
||||
"description: \"Preview flow\"\n"+
|
||||
"steps:\n"+
|
||||
" - name: \"{{STEP}}\"\n"+
|
||||
" run: \"echo {{VALUE}}\"\n",
|
||||
)
|
||||
|
||||
s := &PrepSubsystem{
|
||||
ServiceRuntime: core.NewServiceRuntime(core.New(), AgentOptions{}),
|
||||
backoff: make(map[string]time.Time),
|
||||
failCount: make(map[string]int),
|
||||
}
|
||||
|
||||
output := captureStdout(t, func() {
|
||||
r := s.cmdFlowPreview(core.NewOptions(
|
||||
core.Option{Key: "_arg", Value: flowPath},
|
||||
core.Option{Key: "variables", Value: map[string]any{
|
||||
"NAME": "release",
|
||||
"STEP": "lint",
|
||||
"VALUE": "ok",
|
||||
}},
|
||||
))
|
||||
assert.True(t, r.OK)
|
||||
})
|
||||
|
||||
assert.Contains(t, output, "name: release deployment")
|
||||
assert.Contains(t, output, "1. lint")
|
||||
}
|
||||
|
||||
func TestCommandsFlow_CmdFlowPreview_Bad_MissingPath(t *testing.T) {
|
||||
s := &PrepSubsystem{
|
||||
ServiceRuntime: core.NewServiceRuntime(core.New(), AgentOptions{}),
|
||||
backoff: make(map[string]time.Time),
|
||||
failCount: make(map[string]int),
|
||||
}
|
||||
|
||||
r := s.cmdFlowPreview(core.NewOptions())
|
||||
assert.False(t, r.OK)
|
||||
}
|
||||
|
||||
func TestCommandsFlow_CmdFlowPreview_Ugly_InvalidYaml(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
flowPath := core.JoinPath(root, "broken.yaml")
|
||||
fs.Write(flowPath, "name: [broken\nsteps:\n - name: test\n")
|
||||
|
||||
s := &PrepSubsystem{
|
||||
ServiceRuntime: core.NewServiceRuntime(core.New(), AgentOptions{}),
|
||||
backoff: make(map[string]time.Time),
|
||||
failCount: make(map[string]int),
|
||||
}
|
||||
|
||||
r := s.cmdFlowPreview(core.NewOptions(core.Option{Key: "_arg", Value: flowPath}))
|
||||
assert.False(t, r.OK)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue