Files
archie/internal/app/agentworker/step_vocabulary_test.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

90 lines
3.5 KiB
Go

package agentworker
import (
"slices"
"testing"
"gopkg.in/yaml.v3"
"github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/infrastructure/workflowsteps"
)
// stepVocabularyProbe is a provider set of one, used only to prove the
// manager a root builds is live: registering through it must reach its
// vocabulary.
type stepVocabularyProbe struct{}
func (stepVocabularyProbe) Name() string { return "probe" }
func (stepVocabularyProbe) StepTypes() []workflow.StepType {
return []workflow.StepType{{Name: "probe.registered", Factory: func(yaml.Node) (workflow.Stage, error) {
return workflow.Stage{Name: "probe.registered"}, nil
}}}
}
// TestProductionWorkerDependenciesRegisterTheSharedStepVocabulary pins the
// executing side's composition root. productionWorkerDependencies is reached
// only by Run, so nothing else fails if it stops registering the shared
// provider set (internal/infrastructure/workflowsteps) and hands the worker a
// manager with no shipped stage: every compile then fails at run time, in a
// container, per task.
func TestProductionWorkerDependenciesRegisterTheSharedStepVocabulary(t *testing.T) {
dependencies, err := productionWorkerDependencies()
if err != nil {
t.Fatalf("productionWorkerDependencies: %v", err)
}
requireSharedStepVocabulary(t, dependencies.steps)
}
// requireSharedStepVocabulary holds a composition root's manager to both halves
// of the contract: it resolves the shipped vocabulary, and it is live enough to
// take a provider registered through it.
func requireSharedStepVocabulary(t *testing.T, steps *workflow.Manager) {
t.Helper()
if steps == nil {
t.Fatal("the composition root registered no workflow step vocabulary")
}
got := steps.StepTypes()
// Containment, not equality: adding a provider to the shared set
// (workflowsteps.Providers) is the documented way a step type arrives, and
// that must not have to edit this guard. What it holds is that the shipped
// stages are all present, which is what a root regressing to
// workflow.NewManager() loses.
for name := range workflow.BuiltinStepRegistry() {
if !slices.Contains(got, name) {
t.Errorf("the composition root resolves %v, which is missing the shipped stage %q", got, name)
}
}
// The other half is provenance: every name the root resolves must be
// declared by the shared provider set, not by a near-identical provider of
// the root's own, because that set is what ties this process's vocabulary to
// the State Store that validates against it. It is content, not identity --
// the shipped provider rebuilds its factories on every call.
declared := sharedStepTypeNames()
for _, name := range got {
if !slices.Contains(declared, name) {
t.Errorf("the composition root resolves %q, which no provider in the shared set declares", name)
}
}
if err := steps.Register(stepVocabularyProbe{}); err != nil {
t.Fatalf("register a provider through the root's manager: %v", err)
}
if _, resolved := steps.Registry()["probe.registered"]; !resolved {
t.Fatal("a provider registered through the root's manager did not reach its vocabulary")
}
}
// sharedStepTypeNames returns the step types the shared provider set declares,
// read through the same Providers() seam the composition roots register.
func sharedStepTypeNames() []string {
names := make([]string, 0)
for _, provider := range workflowsteps.Providers() {
for _, stepType := range provider.StepTypes() {
names = append(names, stepType.Name)
}
}
slices.Sort(names)
return names
}