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.
This commit is contained in:
sam committed 2026-09-21 20:22:44 +10:00
1 parent 9fb65d0519
commit b4aa56dcb3
9 files changed
+418 -91

No files matched your search

+6 -1
View File
@@ -20,7 +20,8 @@ import (
// Client is the control-plane client for every resource that does not resolve
// a workflow step type: catalog, history, settings, personas, schedules. It
// carries no step vocabulary, so a process that never reads or writes a
// workflow definition -- archie-messaging, which only loads channel settings --
// workflow definition -- archie-messaging, which only loads channel settings,
// and archie-gateway, which reads catalog, runtime settings and personas --
// needs no provider set and cannot be failed by one.
type Client struct{ rpc pb.ControlPlaneServiceClient }
@@ -69,6 +70,10 @@ func (c *WorkflowDefinitionsClient) WorkflowDefinitions(ctx context.Context) (wo
// ReplaceWorkflowDefinitions replaces the collection. Passing
// workflow.ShippedDefinitions() restores all shipped definitions while keeping
// the previous override in resource history.
//
// No production process calls it today: the daemon's only consumer of this
// surface reads (internal/daemon's WorkflowDefinitions interface), so this half
// is reached by tests until a writer exists.
func (c *WorkflowDefinitionsClient) ReplaceWorkflowDefinitions(ctx context.Context, definitions workflow.WorkflowDefinitionCollection, expectedVersion int64, actor, source, requestID string) (int64, error) {
value, err := encodeWorkflowDefinitions(definitions, c.steps)
if err != nil {
@@ -3,7 +3,11 @@
// side (archie-agent) compiles it. Two packages that each pass their own tests
// and disagree with each other is the failure archie-core-fwmp exists to
// prevent, so this is the one test that registers a provider through the
// production Manager and drives every production resolution site with it.
// production Manager and drives the production entry points that resolve a step
// type with it: the State Store server, the daemon's workflow-definitions
// client (its read path, and its write path, which no production caller reaches
// yet) and agentworker.CompilePinnedWorkflow. A site these do not enumerate is
// caught by TestNoProductionSiteReachesForTheBuiltinStepRegistry below.
//
// "Agreement" here means within one build: archie-state-store and archie-agent
// are separately deployed binaries, so a State Store built from newer source
@@ -15,6 +19,11 @@ package controlplane
import (
"context"
"encoding/json"
"go/ast"
"go/parser"
"go/token"
"io/fs"
"path/filepath"
"strings"
"testing"
@@ -319,3 +328,70 @@ func (c *definitionsClient) Command(_ context.Context, request *pb.CommandReques
func (c *definitionsClient) Watch(context.Context, *pb.WatchRequest, ...grpc.CallOption) (grpc.ServerStreamingClient[pb.WatchResponse], error) {
panic("Watch is not part of the workflow-definitions path")
}
// TestNoProductionSiteReachesForTheBuiltinStepRegistry guards the class of
// defect archie-core-fwmp exists to remove: a call site that resolves workflow
// step types out of workflow.BuiltinStepRegistry() instead of the manager its
// composition root registered. The agreement test above can only drive the
// entry points it enumerates, so a sixth one added later would validate, or
// fail to compile, against a vocabulary no other process has. Exactly two
// non-test files may name it: the domain file that declares it, and the shipped
// provider that bundles the shipped stages through it.
func TestNoProductionSiteReachesForTheBuiltinStepRegistry(t *testing.T) {
allowed := map[string]string{
filepath.Join("internal", "domain", "workflow", "definition.go"): "declares BuiltinStepRegistry",
filepath.Join("internal", "infrastructure", "workflowsteps", "workflowsteps.go"): "bundles the shipped stages as a provider",
}
// The module root, three levels up from this package.
root := filepath.Join("..", "..", "..")
scanned := 0
walkErr := filepath.WalkDir(root, func(path string, entry fs.DirEntry, err error) error {
if err != nil {
return err
}
name := entry.Name()
if entry.IsDir() {
// The root is "../../..", whose own name starts with a dot: only
// directories below it are filtered.
if path == root {
return nil
}
// tools is a separate module, and the rest carry no Archie source.
if name == "tools" || name == "node_modules" || name == "testdata" || name == "vendor" || strings.HasPrefix(name, ".") {
return fs.SkipDir
}
return nil
}
if !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") {
return nil
}
relative, relErr := filepath.Rel(root, path)
if relErr != nil {
return relErr
}
if _, permitted := allowed[relative]; permitted {
return nil
}
file, parseErr := parser.ParseFile(token.NewFileSet(), path, nil, 0)
if parseErr != nil {
return parseErr
}
scanned++
ast.Inspect(file, func(node ast.Node) bool {
if ident, ok := node.(*ast.Ident); ok && ident.Name == "BuiltinStepRegistry" {
t.Errorf("%s names BuiltinStepRegistry; only %s (%s) and %s (%s) may, or that resolution site keeps a step vocabulary of its own",
relative,
filepath.Join("internal", "domain", "workflow", "definition.go"), allowed[filepath.Join("internal", "domain", "workflow", "definition.go")],
filepath.Join("internal", "infrastructure", "workflowsteps", "workflowsteps.go"), allowed[filepath.Join("internal", "infrastructure", "workflowsteps", "workflowsteps.go")])
}
return true
})
return nil
})
if walkErr != nil {
t.Fatalf("scan the module for BuiltinStepRegistry: %v", walkErr)
}
if scanned == 0 {
t.Fatal("the scan read no non-test Go file; it is not looking at the module")
}
}