Add EngineBuilder fluent API for reusable engine initialization#197
Add EngineBuilder fluent API for reusable engine initialization#197
Conversation
…integration Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
…ate tests and CLI Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR introduces a fluent EngineBuilder API to eliminate ~20 lines of boilerplate code needed to initialize the workflow engine across multiple consumers (CLI tools, MCP server, tests, scaffold templates). The implementation successfully centralizes engine initialization logic while maintaining backward compatibility.
Changes:
- Introduces
EngineBuilderwith fluent API methods (WithAllDefaults(),WithDefaultHandlers(),WithDefaultTriggers(), etc.) for simplified engine configuration - Creates
setup/package to break import cycles between the root workflow package and handlers package using factory function pattern - Integrates optional engine support into MCP server via
EngineProviderinterface andWithEngine()option - Refactors all CLI commands and scaffold templates to use the new builder API, reducing code from 107→89 lines in
cmd/wfctl/run.go
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
engine_builder.go |
New fluent builder API with 13 configuration methods and 4 terminal methods for engine construction |
engine_builder_test.go |
Comprehensive test coverage with 17 test cases covering builder patterns, chaining, defaults, and lifecycle |
setup/setup.go |
Factory provider package that breaks import cycles by registering default handlers/triggers via init() |
setup/setup_test.go |
Tests verifying 8 handlers and 5 triggers are registered by default factories |
mcp/server.go |
Adds optional EngineProvider interface and WithEngine() option, conditionally registers run_workflow tool |
mcp/server_test.go |
6 new tests for engine integration including success, error, missing params, and no-engine scenarios |
cmd/wfctl/run.go |
Refactored from manual 20-line setup to 5-line builder call with WithAllDefaults() |
cmd/wfctl/pipeline.go |
Simplified to use builder with selective components (pipeline handler + plugin only) |
cmd/wfctl/templates/*/*.tmpl |
All 3 scaffold templates updated to use builder API, removing 10+ lines of boilerplate each |
|
@copilot apply changes based on the comments in this thread make sure tests exist to validate our logic. replace the cli and mcp services with this functionality if you didn't already, then ensure they still compile and can execute correctly. |
Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
All review comments addressed in fb1e5a0:
CLI ( |
EngineBuilderfluent API inengine_builder.gowith:NewEngineBuilder()constructorWithApplication(app)/WithLogger(logger)- custom dependenciesWithDefaultHandlers()- register all 8 built-in workflow handlersWithDefaultTriggers()- register all 5 built-in triggersWithDynamicComponents()- set up dynamic interpreter/registry/loaderWithAllDefaults()- convenience for all of the aboveWithHandler(h)/WithTrigger(t)- custom componentsWithPlugin(p)/WithPlugins(p...)- load pluginsWithPluginLoader(l)- custom plugin loaderWithConfigPath(path)- for BuildAndConfigureBuild()/BuildFromConfig(cfg)/BuildAndConfigure()- create engineRunUntilSignal(cfg)- CLI convenience for start/signal/stopsetuppackage for default handler/trigger registration (avoids import cycles)cmd/wfctl/run.goto use the builder (with_ setupimport)cmd/wfctl/pipeline.goto use the builder_ setupimportEngineProviderinterface in mcp packageWithEngine(engine)server optionrun_workflowtool for AI-driven workflow executiongo vet ./...clean)golangci-lint run ./...- 0 issues)setup/setup.gopackage doc (removed non-existent function references, added correct blank-import usage example)_ "github.com/GoCodeAlone/workflow/setup"to all 3 scaffold templatesEngineBuildertype doc with setup import exampleWithDefaultHandlers(),WithDefaultTriggers(),WithAllDefaults()🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.