Feat v0.3.2 workflow engine + handlers
Some checks failed
CI/CD / detect-changes (pull_request) Successful in 4s
CI/CD / test-frontend (pull_request) Has been skipped
CI/CD / test-go-pg (pull_request) Failing after 2m43s
CI/CD / test-sqlite (pull_request) Successful in 2m57s
CI/CD / build-and-deploy (pull_request) Has been skipped

Workflow execution engine with Start/Advance/Cancel lifecycle, automated
stage processor with Starlark hook firing and cycle guard (max 10),
instance and assignment HTTP handlers, store round-trip tests for all
v0.3.1 methods, and Starlark module expansion (get_instance, list_instances).

New routes:
- POST/GET /workflows/:id/instances (start, list)
- GET /workflows/:id/instances/:iid (get)
- POST /workflows/:id/instances/:iid/advance (advance)
- POST /workflows/:id/instances/:iid/cancel (cancel)
- POST /assignments/:id/claim|unclaim|complete|cancel
- GET /assignments/mine
- Team-scoped mirrors under /teams/:teamId/...

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-27 21:36:40 +00:00
parent 01ee9e668b
commit 438143318f
13 changed files with 1652 additions and 24 deletions

View File

@@ -30,6 +30,7 @@ import (
"switchboard-core/storage"
"switchboard-core/store"
"switchboard-core/triggers"
"switchboard-core/workflow"
postgres "switchboard-core/store/postgres"
sqliteStore "switchboard-core/store/sqlite"
)
@@ -399,6 +400,21 @@ func main() {
protected.POST("/workflows/:id/publish", middleware.RequirePermission(auth.PermWorkflowCreate, stores), wfH.Publish)
protected.GET("/workflows/:id/versions/:version", wfH.GetVersion)
// Workflow instances + assignments (v0.3.2)
wfEngine := workflow.NewEngine(stores, bus, starlarkRunner)
wfInstH := handlers.NewWorkflowInstanceHandler(wfEngine, stores)
protected.POST("/workflows/:id/instances", middleware.RequirePermission(auth.PermWorkflowSubmit, stores), wfInstH.Start)
protected.GET("/workflows/:id/instances", wfInstH.ListInstances)
protected.GET("/workflows/:id/instances/:iid", wfInstH.GetInstance)
protected.POST("/workflows/:id/instances/:iid/advance", middleware.RequirePermission(auth.PermWorkflowSubmit, stores), wfInstH.Advance)
protected.POST("/workflows/:id/instances/:iid/cancel", middleware.RequirePermission(auth.PermWorkflowCreate, stores), wfInstH.Cancel)
wfAssignH := handlers.NewWorkflowAssignmentHandler(wfEngine, stores)
protected.POST("/assignments/:id/claim", wfAssignH.Claim)
protected.POST("/assignments/:id/unclaim", wfAssignH.Unclaim)
protected.POST("/assignments/:id/complete", wfAssignH.Complete)
protected.POST("/assignments/:id/cancel", middleware.RequirePermission(auth.PermWorkflowCreate, stores), wfAssignH.Cancel)
protected.GET("/assignments/mine", wfAssignH.ListMine)
// Surface discovery (v0.25.0, v0.28.7: unified packages)
pkgH := handlers.NewPackageHandler(stores)
@@ -522,6 +538,17 @@ func main() {
teamScoped.POST("/workflows/:id/publish", teamWfH.PublishTeamWorkflow)
teamScoped.GET("/workflows/:id/versions/:version", teamWfH.GetTeamWorkflowVersion)
// Team workflow instances + assignments (v0.3.2)
teamWfInstH := handlers.NewWorkflowInstanceHandler(wfEngine, stores)
teamScoped.POST("/workflows/:id/instances", teamWfInstH.Start)
teamScoped.GET("/workflows/:id/instances", teamWfInstH.ListInstances)
teamScoped.GET("/workflows/:id/instances/:iid", teamWfInstH.GetInstance)
teamScoped.POST("/workflows/:id/instances/:iid/advance", teamWfInstH.Advance)
teamScoped.POST("/workflows/:id/instances/:iid/cancel", teamWfInstH.Cancel)
teamWfAssignH := handlers.NewWorkflowAssignmentHandler(wfEngine, stores)
teamScoped.GET("/assignments", teamWfAssignH.ListByTeam)
}
// Public global settings (non-admin users can read safe subset)