Files
osmedeus/internal/template/precompiled_test.go
T
j3ssie 1403d20a4d feat: add LLM step executor with vision and tool support, event workflow system, and inheritance
- Add LLM executor supporting OpenAI vision, tool calling, embeddings, and structured outputs
- Introduce event emitter/receiver workflows with deduplication and filtering (generate_event functions)
- Add workflow extends/override system enabling inheritance chains and step merge modes
- Update function naming to snake_case across all testdata (fileExists→file_exists, etc.)
- Add comprehensive test fixtures for linter, events, CDN, step dependencies, and extends workflows
2026-01-20 18:23:57 +08:00

133 lines
3.8 KiB
Go

package template
import (
"testing"
)
func TestPrecompiledRegistry_PrecompileWorkflow(t *testing.T) {
registry := NewPrecompiledRegistry()
templates := map[string]string{
"step1:command": "nmap -sV {{target}}",
"step1:output": "{{output}}/nmap.txt",
"step2:command": "nuclei -t {{templates}} -u {{target}}",
"static": "No variables here",
}
err := registry.PrecompileWorkflow("test-workflow", templates)
if err != nil {
t.Fatalf("PrecompileWorkflow() error = %v", err)
}
// Verify templates were compiled
if registry.GetWorkflowCount() != 1 {
t.Errorf("GetWorkflowCount() = %d, want 1", registry.GetWorkflowCount())
}
// Should have 3 compiled templates (static one is skipped)
if registry.GetTemplateCount() != 3 {
t.Errorf("GetTemplateCount() = %d, want 3", registry.GetTemplateCount())
}
}
func TestPrecompiledRegistry_GetPrecompiled(t *testing.T) {
registry := NewPrecompiledRegistry()
templates := map[string]string{
"step1:command": "nmap -sV {{target}}",
}
_ = registry.PrecompileWorkflow("test-workflow", templates)
// Test existing template
tpl := registry.GetPrecompiled("test-workflow", "step1:command")
if tpl == nil {
t.Error("GetPrecompiled() returned nil for existing template")
}
// Test non-existing template
tpl = registry.GetPrecompiled("test-workflow", "nonexistent")
if tpl != nil {
t.Error("GetPrecompiled() returned non-nil for nonexistent template")
}
// Test non-existing workflow
tpl = registry.GetPrecompiled("nonexistent-workflow", "step1:command")
if tpl != nil {
t.Error("GetPrecompiled() returned non-nil for nonexistent workflow")
}
}
func TestPrecompiledRegistry_ClearPrecompiled(t *testing.T) {
registry := NewPrecompiledRegistry()
templates := map[string]string{
"step1:command": "nmap -sV {{target}}",
}
_ = registry.PrecompileWorkflow("test-workflow", templates)
if registry.GetWorkflowCount() != 1 {
t.Fatalf("Setup failed: GetWorkflowCount() = %d", registry.GetWorkflowCount())
}
registry.ClearPrecompiled("test-workflow")
if registry.GetWorkflowCount() != 0 {
t.Errorf("After ClearPrecompiled: GetWorkflowCount() = %d, want 0", registry.GetWorkflowCount())
}
}
func TestPrecompiledRegistry_ClearAll(t *testing.T) {
registry := NewPrecompiledRegistry()
_ = registry.PrecompileWorkflow("workflow1", map[string]string{"key": "{{value}}"})
_ = registry.PrecompileWorkflow("workflow2", map[string]string{"key": "{{value}}"})
if registry.GetWorkflowCount() != 2 {
t.Fatalf("Setup failed: GetWorkflowCount() = %d", registry.GetWorkflowCount())
}
registry.ClearAll()
if registry.GetWorkflowCount() != 0 {
t.Errorf("After ClearAll: GetWorkflowCount() = %d, want 0", registry.GetWorkflowCount())
}
}
func TestPrecompiledRegistry_InvalidTemplate(t *testing.T) {
registry := NewPrecompiledRegistry()
// Template with invalid syntax - should be skipped, not error
templates := map[string]string{
"valid": "{{target}}",
"invalid": "{{invalid syntax",
}
err := registry.PrecompileWorkflow("test-workflow", templates)
if err != nil {
t.Errorf("PrecompileWorkflow() should not error on invalid templates: %v", err)
}
// Only valid template should be compiled
if registry.GetTemplateCount() != 1 {
t.Errorf("GetTemplateCount() = %d, want 1 (invalid should be skipped)", registry.GetTemplateCount())
}
}
func TestPrecompiledRegistry_EmptyTemplates(t *testing.T) {
registry := NewPrecompiledRegistry()
err := registry.PrecompileWorkflow("empty-workflow", map[string]string{})
if err != nil {
t.Errorf("PrecompileWorkflow() with empty templates error = %v", err)
}
if registry.GetWorkflowCount() != 1 {
t.Errorf("GetWorkflowCount() = %d, want 1", registry.GetWorkflowCount())
}
if registry.GetTemplateCount() != 0 {
t.Errorf("GetTemplateCount() = %d, want 0", registry.GetTemplateCount())
}
}