Files
archie/internal/infrastructure/workflowsteps/workflowsteps_test.go
T
sam 56f7295a3c feat(workflow): own the step vocabulary in a family manager registered at each composition root
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.
2026-09-21 19:42:24 +10:00

61 lines
2.0 KiB
Go

package workflowsteps
import (
"slices"
"testing"
"github.com/samcharles93/archie-core/internal/domain/workflow"
)
// TestShippedVocabularyCoversEveryShippedStage is the guard that the bundled
// provider set really carries the shipped stages: a process that registers it
// can compile every shipped workflow, and one that does not has no vocabulary
// at all.
func TestShippedVocabularyCoversEveryShippedStage(t *testing.T) {
t.Parallel()
manager, err := NewManager()
if err != nil {
t.Fatalf("NewManager: %v", err)
}
want := make([]string, 0, len(workflow.BuiltinStepRegistry()))
for name := range workflow.BuiltinStepRegistry() {
want = append(want, name)
}
slices.Sort(want)
if got := manager.StepTypes(); !slices.Equal(got, want) {
t.Fatalf("registered vocabulary = %v, want the shipped stages %v", got, want)
}
// The vocabulary arrives by registration, not by implication: a manager
// that was handed no provider set resolves nothing, which is what makes
// every resolution site's use of the injected manager observable.
if got := workflow.NewManager().StepTypes(); len(got) != 0 {
t.Fatalf("an unregistered manager resolves %v, want nothing", got)
}
}
// TestNewManagerIsRepeatableWithinOneProcess is the regression guard for
// registering the provider set into shared state: every construction is
// independent, so building the vocabulary twice in one process — as `-count=2`
// does — must succeed and produce the same vocabulary.
func TestNewManagerIsRepeatableWithinOneProcess(t *testing.T) {
t.Parallel()
first, err := NewManager()
if err != nil {
t.Fatalf("first NewManager: %v", err)
}
second, err := NewManager()
if err != nil {
t.Fatalf("second NewManager: %v", err)
}
if !slices.Equal(first.StepTypes(), second.StepTypes()) {
t.Fatalf("two managers resolved different vocabularies: %v and %v", first.StepTypes(), second.StepTypes())
}
if !slices.Equal(first.Providers(), second.Providers()) {
t.Fatalf("two managers registered different providers: %v and %v", first.Providers(), second.Providers())
}
}