Documentation
¶
Index ¶
- Constants
- func ConversationWorkflow(args ...any) *workflow.Workflow
- func CreateTestWorkflow(t *testing.T, dir, name, content string)
- func LinearWorkflow(args ...any) *workflow.Workflow
- func LoopWorkflow(args ...any) *workflow.Workflow
- func ParallelWorkflow(args ...any) *workflow.Workflow
- func SetupTestDir(t *testing.T) string
- func SetupWorkflowsDir(t *testing.T, workflows map[string]string) string
- func SimpleWorkflow(args ...any) *workflow.Workflow
Constants ¶
const BadWorkflowYAML = `` /* 139-byte string literal not displayed */
BadWorkflowYAML is an invalid workflow with nonexistent state reference. Used for testing validation error handling.
const FullWorkflowYAML = `` /* 300-byte string literal not displayed */
FullWorkflowYAML is a complete workflow with version, description, inputs, and validation. Used for testing full workflow parsing and input handling.
const SimpleWorkflowYAML = `` /* 133-byte string literal not displayed */
SimpleWorkflowYAML is a minimal valid workflow with single command step and terminal. Used for basic CLI command testing.
Variables ¶
This section is empty.
Functions ¶
func ConversationWorkflow ¶
ConversationWorkflow creates a workflow with AI agent conversation step.
Parameters:
- args[0] (string): AI provider (default: "anthropic") Valid values: "anthropic", "openai", "google", "custom"
- args[1] (string): Model name (default: "claude-3-sonnet")
- args[2] (int): Number of conversation turns (default: 1, multi-turn if > 1)
Returns a workflow with:
- 1+ agent steps with AI configuration
- AgentConfig with Provider, Model, Prompt
- 1 terminal step after agent execution
Example:
wf := ConversationWorkflow() // anthropic claude-3-sonnet, single turn
wf := ConversationWorkflow("openai", "gpt-4") // openai gpt-4
wf := ConversationWorkflow("anthropic", "claude-3-opus", 3) // 3-turn conversation
func CreateTestWorkflow ¶
CreateTestWorkflow writes a YAML workflow file to the test directory. Helper for setting up test workflows in setupTestDir() environments.
The name parameter should be a workflow filename. If it contains path separators, they will be replaced with hyphens to create a flat file structure. This ensures consistent behavior across tests and avoids nested directory complexity.
Parameters:
- t: Testing context
- dir: Base directory (typically from SetupTestDir)
- name: Workflow name (path separators replaced with hyphens)
- content: YAML workflow content
Usage:
dir := SetupTestDir(t) CreateTestWorkflow(t, dir, "test.yaml", SimpleWorkflowYAML) CreateTestWorkflow(t, dir, "bad.yaml", BadWorkflowYAML) CreateTestWorkflow(t, dir, "sub/dir/wf.yaml", SimpleWorkflowYAML) // Creates "sub-dir-wf.yaml"
func LinearWorkflow ¶
LinearWorkflow creates a workflow with N sequential command steps followed by terminal.
Parameters:
- args[0] (int): Number of command steps (default: 3)
Returns a workflow with:
- N command steps in sequence (step1 -> step2 -> ... -> stepN)
- 1 terminal step at the end
- Each step has OnSuccess pointing to next step
Example:
wf := LinearWorkflow() // 3 command steps + terminal wf := LinearWorkflow(5) // 5 command steps + terminal
func LoopWorkflow ¶
LoopWorkflow creates a workflow with for_each or while loop step.
Parameters:
- args[0] (string): Loop type - "for_each" or "while" (default: "for_each")
- args[1] ([]string or string): For for_each: items array, for while: condition expression
Returns a workflow with:
- 1 loop step (for_each or while type)
- Loop body with command step(s)
- 1 terminal step after loop completion
Example:
wf := LoopWorkflow() // for_each with default items
wf := LoopWorkflow("for_each") // Explicit for_each
wf := LoopWorkflow("for_each", []string{"a", "b", "c"}) // Custom items
wf := LoopWorkflow("while") // While loop with default condition
func ParallelWorkflow ¶
ParallelWorkflow creates a workflow with parallel execution branches.
Parameters:
- args[0] (int): Number of parallel branches (default: 2)
- args[1] (string): Parallel strategy (default: "all_succeed") Valid values: "all_succeed", "any_succeed", "best_effort"
Returns a workflow with:
- 1 parallel step with N branches
- N branch command steps
- 1 terminal step after parallel completion
Example:
wf := ParallelWorkflow() // 2 branches, all_succeed wf := ParallelWorkflow(5) // 5 branches wf := ParallelWorkflow(3, "any_succeed") // 3 branches, any_succeed strategy
func SetupTestDir ¶
SetupTestDir creates an isolated test directory with .awf structure for CLI tests. Replaces the os.Chdir pattern with thread-safe t.TempDir() + directory structure creation.
Returns the path to the temporary directory.
The created directory structure:
- <tmpDir>/.awf/ # AWF project root marker
- <tmpDir>/.awf/workflows/ # Workflow storage directory
- <tmpDir>/.awf/storage/ # State storage directory
- <tmpDir>/.awf/prompts/ # Prompt storage directory
Usage:
dir := SetupTestDir(t) // dir now contains .awf structure // Use dir for --storage flag or file operations
Thread-safety: - Uses t.TempDir() for automatic cleanup - No os.Chdir (process-wide state) - Safe for parallel test execution
func SetupWorkflowsDir ¶
SetupWorkflowsDir creates test directory with multiple workflows from a map. Convenience wrapper around SetupTestDir + multiple CreateTestWorkflow calls.
Parameters:
- t: Testing context
- workflows: Map of workflow name -> YAML content
Returns the test directory path.
Usage:
dir := SetupWorkflowsDir(t, map[string]string{
"test": SimpleWorkflowYAML,
"full": FullWorkflowYAML,
})
// dir/.awf/workflows/test.yaml and full.yaml created
func SimpleWorkflow ¶
SimpleWorkflow creates a minimal valid workflow with a single command step and terminal.
Parameters:
- args[0] (string): Custom workflow name (default: "simple-workflow")
- args[1] (string): Custom command (default: "echo 'hello'")
Returns a workflow with:
- 1 command step (executes shell command)
- 1 terminal step (success)
Example:
wf := SimpleWorkflow() // Uses defaults
wf := SimpleWorkflow("my-workflow") // Custom name
wf := SimpleWorkflow("test", "echo 'test'") // Custom name and command
Types ¶
This section is empty.