archie-core-fwmp. Every call site hardcoded workflow.BuiltinStepRegistry(), so the step vocabulary a workflow definition may name was closed to the six shipped workflows and archie-agent could compile only what the control plane happened to validate against the same literal. internal/domain/workflow.Manager is the family owner (ARCHITECTURE.md#plugin- engine-rule-strict invariant 2): a constructed, injected value with no package-level registry and no init()-time registration. Register validates at the producer and atomically -- nil or unnamed provider, malformed provider or step-type identifier, a step type with no factory, a duplicate claim, a provider declaring one type twice, and a contribution shadowing a shipped stage are each refused, and a refused contribution applies nothing. Registry() hands back a copy, so the closed set is a property of the manager rather than a convention. internal/infrastructure/workflowsteps is the one package both composition roots import: it holds the compiled-in provider set and builds the manager. archied registers it in RunStateStore (the validating side) and in openStateStoreAdapter (the daemon's client), archie-agent in productionWorkerDependencies (the executing side), and archie-messaging at its own root, each before the first resolution. The five hardcoded sites now resolve the injected manager instead: the State Store's workflow-definitions validate closure and encodeWorkflowDefinitions, the control-plane client's read and write paths, and CompilePinnedWorkflow's shipped -definition and pinned compiles (one resolution per package). step_vocabulary_agreement_test.go registers a provider through the production Manager and drives all three sides with it; breaking any one of the six resolution points back to the builtin registry fails that side's assertion.
46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
package controlplane
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
|
)
|
|
|
|
const WorkflowDefinitionsKind = "workflow-definitions"
|
|
|
|
// stepRegistry is this package's single resolution site for the workflow step
|
|
// vocabulary. The manager is built at the composition root
|
|
// (infrastructure/workflowsteps.NewManager) and injected, so the State Store
|
|
// server -- the validating side -- and the control-plane client both resolve
|
|
// the vocabulary that composition root registered, and neither can validate a
|
|
// definition against a vocabulary the other does not have.
|
|
func stepRegistry(steps *workflow.Manager) workflow.StepRegistry { return steps.Registry() }
|
|
|
|
func workflowDefinitionsDefinition(steps workflow.StepRegistry) Definition {
|
|
return Definition{
|
|
Kind: WorkflowDefinitionsKind,
|
|
Title: "Workflow definitions",
|
|
Schema: objectSchema,
|
|
ApplyMode: "live",
|
|
Seed: func(config.Config) any {
|
|
return workflow.ShippedDefinitions()
|
|
},
|
|
Defaults: func() any {
|
|
return workflow.ShippedDefinitions()
|
|
},
|
|
Validate: func(input []byte) error {
|
|
_, err := workflow.DecodeDefinitionCollection(input, steps)
|
|
return err
|
|
},
|
|
}
|
|
}
|
|
|
|
func encodeWorkflowDefinitions(collection workflow.WorkflowDefinitionCollection, steps workflow.StepRegistry) ([]byte, error) {
|
|
if err := workflow.ValidateDefinitionCollection(collection, steps); err != nil {
|
|
return nil, fmt.Errorf("%w: %w", ErrValidation, err)
|
|
}
|
|
return json.Marshal(collection)
|
|
}
|