Files
archie/internal/infrastructure/workflowsteps/workflowsteps.go
T
sam b4aa56dcb3 fix(archied): register the step vocabulary only where a root resolves it
Review pass on the step-vocabulary shape. The gateway root shared
openStateStoreAdapter with the daemon, so it registered a step vocabulary and
built a workflow-definitions client it never read: the same dead vocabulary the
previous commit removed from internal/app/archiemessaging, reintroduced through
the shared adapter, and able to fail the gateway's boot the day a provider set
can fail to load. The vocabulary and the client now belong to the daemon root
alone (openDaemonWorkflowDefinitions, called by Run before buildDaemon captures
it), which is what Client's "a process that never reads or writes a workflow
definition needs no provider set and cannot be failed by one" already claimed.

The root guard was weaker than its own comment: it asserted that a root calls
stepVocabulary(), not that the manager returned is the one handed to
NewServer/NewWorkflowDefinitionsClient, so a root could call it and inject an
empty manager and keep every test green. The pin now asserts the data flow (both
halves mutation-checked), plus Run's ordering -- after openStateStoreAdapter,
before buildDaemon.

Three root guards asserted exact equality with workflow.BuiltinStepRegistry(),
which contradicted the extension path they guard: adding a provider to
workflowsteps.Providers() -- the documented way a step type arrives -- failed
all three, and the expectation could not be satisfied by editing it. They now
assert what their doc says (every shipped stage present) plus provenance (every
name resolved is declared by the shared provider set), and the workflowsteps
guard derives its expectation from Providers() so both sides move together.

New guard on the defect class the bead exists for: TestNoProductionSiteReaches-
ForTheBuiltinStepRegistry scans the module and fails if any non-test file outside
the domain declaration and the shipped provider names BuiltinStepRegistry, which
the agreement test cannot see for a sixth resolution site added later.

Claim-vs-code corrections: openStateStoreAdapter "reads and replaces" -> the
daemon only reads, and ReplaceWorkflowDefinitions has no production caller yet;
workflowsteps' package/Providers docs no longer claim every Archie binary
registers the set (archie-gateway, archie-messaging, archie-playbooks and
archie-ui do not); the shipped-provider test no longer says production does not
call BuiltinStepRegistry, which is false -- production calls it only there.
2026-09-21 20:22:44 +10:00

73 lines
3.3 KiB
Go

// Package workflowsteps is the compiled-in workflow step-type provider set:
// the one place a step type is bundled into the Archie binaries that resolve
// one, so no such binary can keep a provider set of its own.
//
// Two composition roots register it, both of them roots that resolve a step
// type: archied's RunStateStore (the State Store's validating side) and
// archied's daemon root (openDaemonWorkflowDefinitions, the executing side's
// workflow-definitions client, alongside agentworker's
// productionWorkerDependencies). Sharing one package is what keeps them
// registering the same vocabulary. Processes that resolve no step type do not
// import it and register nothing: archie-gateway, archie-messaging,
// archie-playbooks and archie-ui.
package workflowsteps
import (
"fmt"
"maps"
"slices"
"github.com/samcharles93/archie-core/internal/domain/workflow"
)
// shippedStages is the provider that contributes every stage of the shipped
// workflows (bootstrap, implement, tdd, feasibility, triage, remediate) as a
// workflow step type. It is what makes the shipped vocabulary arrive by
// registration rather than by the manager implying it, so the vocabulary a
// process resolves is always the vocabulary a provider set claimed.
type shippedStages struct{}
func (shippedStages) Name() string { return "shipped" }
func (shippedStages) StepTypes() []workflow.StepType {
registry := workflow.BuiltinStepRegistry()
stepTypes := make([]workflow.StepType, 0, len(registry))
for _, name := range slices.Sorted(maps.Keys(registry)) {
stepTypes = append(stepTypes, workflow.StepType{Name: name, Factory: registry[name]})
}
return stepTypes
}
// Providers returns the provider set the roots that resolve a workflow step
// type register at their composition root, before the first resolution: it is
// what NewManager registers, and what the roots' guards read to hold a
// registered vocabulary to the set it came from. A step type added here becomes
// reachable from the validating side and the executing side at once.
//
// The set is a compiled-in constant rather than a directory scan: a step type
// is a Go factory, and no bridge has been built from the Yaegi-interpreted
// plugins internal/plugin loads to workflow.StepFactory -- those plugins
// satisfy plugin.Plugin's metadata contract only. Such a bridge is possible:
// internal/secret/secretextract wraps an interpreted Engine into the typed
// contract secret.Registry.LoadDir registers (internal/app/archied/
// provider_secrets.go). Until one exists for step types, adding a step type
// means adding a provider here.
func Providers() []workflow.StepTypeProvider {
return []workflow.StepTypeProvider{shippedStages{}}
}
// NewManager builds this process's workflow step-type manager by registering
// the provider set. Every call constructs an independent manager: there is no
// package-level registry and nothing registers at init(), so building the
// vocabulary twice in one process — as `-count=2` does — cannot collide with
// the first build.
func NewManager() (*workflow.Manager, error) {
manager := workflow.NewManager()
for _, provider := range Providers() {
if err := manager.Register(provider); err != nil {
return nil, fmt.Errorf("register workflow step type provider %q: %w", provider.Name(), err)
}
}
return manager, nil
}