fix(workflow): pin the roots, drop the dead vocabulary, guard the nil manager
Third review pass on the step-vocabulary shape, one fix per finding. P1, roots unpinned. The agreement test built its own manager and injected it, so it pinned the resolution sites and not the roots that decide the provider set; a root regressed to workflow.NewManager() (no shipped stages) left go test green. archied now resolves through one unit, stepVocabulary (step_vocabulary.go), and agentworker's productionWorkerDependencies is exercised directly: internal/app/agentworker/step_vocabulary_test.go and internal/app/archied/step_vocabulary_test.go assert each root's manager resolves the shared provider set's shipped stages and accepts a provider registered through it. RunStateStore and openStateStoreAdapter own a SQLite file and a gRPC dial, so their calls are pinned by source position, the way composition_order_test.go pins the memory-engine ordering. P2-B, dead vocabulary. archie-messaging registered a step vocabulary it never resolved (its only control-plane call is RuntimeChatConfig) and could fail startup on it before the State Store target guard. The workflow-definitions surface is now its own type, controlplane.WorkflowDefinitionsClient, so the vocabulary is a constructor dependency of the one surface that resolves step types and of nothing else. The messaging root no longer imports workflowsteps. P2-C, nil manager. A nil *workflow.Manager dereferenced on every resolution path. stepRegistry and CompilePinnedWorkflow now refuse with an error naming the wiring mistake; TestNilStepVocabularyFailsClosedAtEveryResolutionSite pins the refusal. Claim-vs-code corrections: agreement is stated as within one build (vocabulary.go, stepRegistry, openStateStoreControlPlane, openStateStoreAdapter); the Yaegi claim now says no bridge to StepFactory has been built and cites internal/secret/secretextract; the provider set names its three roots; Manager.Register's ordering is documented as a constraint with its consequence, and the shape rule no longer claims to reserve shipped stage names; the shipped-stage test compares against the builtin factory's own stage.
This commit is contained in:
18 files changed
+398
-96
No files matched your search
@@ -0,0 +1,61 @@
|
||||
package agentworker
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
)
|
||||
|
||||
// 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")
|
||||
}
|
||||
want := make([]string, 0, len(workflow.BuiltinStepRegistry()))
|
||||
for name := range workflow.BuiltinStepRegistry() {
|
||||
want = append(want, name)
|
||||
}
|
||||
slices.Sort(want)
|
||||
if got := steps.StepTypes(); !slices.Equal(got, want) {
|
||||
t.Fatalf("the composition root resolves %v, want the shared provider set's shipped stages %v", got, want)
|
||||
}
|
||||
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")
|
||||
}
|
||||
}
|
||||
@@ -327,6 +327,12 @@ func runTask(ctx context.Context, req taskrun.Request, dependencies taskDependen
|
||||
// onto req and req.Task: the run's TaskContext carries that task record, so the
|
||||
// pin has to land on the request the caller handed in.
|
||||
func CompilePinnedWorkflow(req *taskrun.Request, steps *workflow.Manager) (workflow.Workflow, error) {
|
||||
// steps is this process's required step vocabulary, so a nil one is a wiring
|
||||
// mistake at the composition root (productionWorkerDependencies) rather than
|
||||
// a runtime condition: name it instead of dereferencing it.
|
||||
if steps == nil {
|
||||
return workflow.Workflow{}, errors.New("compile pinned workflow: no step vocabulary: the composition root must register the provider set (infrastructure/workflowsteps.NewManager) before the first compile")
|
||||
}
|
||||
// One resolution for the whole function: both compiles below read the
|
||||
// vocabulary the composition root registered, never the builtin registry.
|
||||
vocabulary := steps.Registry()
|
||||
|
||||
@@ -64,6 +64,12 @@ type workerDependencies struct {
|
||||
steps *workflow.Manager
|
||||
}
|
||||
|
||||
// productionWorkerDependencies builds the worker's process dependencies. The
|
||||
// workflow step vocabulary is registered here, at the executing side's
|
||||
// composition root, before the first task is served:
|
||||
// internal/app/agentworker's step_vocabulary_test.go calls this function and
|
||||
// fails if it stops using the shared provider set
|
||||
// (internal/infrastructure/workflowsteps).
|
||||
func productionWorkerDependencies() (workerDependencies, error) {
|
||||
steps, err := workflowsteps.NewManager()
|
||||
if err != nil {
|
||||
|
||||
@@ -54,7 +54,6 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/skillcurator"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/taskactions"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/workflowsteps"
|
||||
"github.com/samcharles93/archie-core/internal/logging"
|
||||
"github.com/samcharles93/archie-core/internal/plugin"
|
||||
"github.com/samcharles93/archie-core/internal/plugin/pluginextract"
|
||||
@@ -117,6 +116,10 @@ type boot struct {
|
||||
stateStoreGrants *staterpc.GrantIssuer
|
||||
stateStoreToken string
|
||||
controlPlane *controlplane.Client
|
||||
// workflowDefinitions is the one control-plane surface that resolves
|
||||
// workflow step types. It is separate from controlPlane because it is the
|
||||
// only surface that needs the process's step vocabulary.
|
||||
workflowDefinitions *controlplane.WorkflowDefinitionsClient
|
||||
// executionSettings is the last workflow execution settings the control
|
||||
// plane published. They arrive on a watch rather than in the file
|
||||
// document, so reloadConfig re-applies them from here.
|
||||
@@ -359,15 +362,23 @@ func (b *boot) openStateStoreAdapter() error {
|
||||
}
|
||||
b.stateStore = client
|
||||
// The daemon reads and replaces workflow definitions through the
|
||||
// control-plane client, so it resolves the same step vocabulary the State
|
||||
// Store server validates against: registered here, at the composition
|
||||
// root, before the first read.
|
||||
steps, err := workflowsteps.NewManager()
|
||||
// workflow-definitions client, so it resolves the same step vocabulary the
|
||||
// State Store server validates against: registered here, at the composition
|
||||
// root, before the first read, through stepVocabulary (see
|
||||
// step_vocabulary_test.go, which pins both archied roots to it). That
|
||||
// agreement holds within one build: the State Store is a separate binary,
|
||||
// and a skewed deploy is only fixed by a matching deploy.
|
||||
steps, err := stepVocabulary()
|
||||
if err != nil {
|
||||
b.log.Error("register workflow step vocabulary", "err", err)
|
||||
return err
|
||||
}
|
||||
b.controlPlane = controlplane.NewRPCClient(client.ControlPlane(), steps)
|
||||
b.controlPlane = controlplane.NewRPCClient(client.ControlPlane())
|
||||
b.workflowDefinitions, err = controlplane.NewWorkflowDefinitionsClient(client.ControlPlane(), steps)
|
||||
if err != nil {
|
||||
b.log.Error("workflow definitions client", "err", err)
|
||||
return err
|
||||
}
|
||||
b.applyStatus = applystatus.New(b.processName, client, b.log)
|
||||
b.stateStoreGrants = &staterpc.GrantIssuer{Client: client}
|
||||
b.stateStoreToken = b.cfg.Services.ResolvedToken(config.ServiceNameState, b.secrets.Getenv)
|
||||
@@ -1252,7 +1263,7 @@ func (b *boot) buildDaemon() {
|
||||
AgentStatus: b.agentStatus,
|
||||
KindWorkflows: b.kindWorkflows,
|
||||
LabelWorkflows: b.labelWorkflows,
|
||||
WorkflowDefinitions: b.controlPlane,
|
||||
WorkflowDefinitions: b.workflowDefinitions,
|
||||
}
|
||||
if identities, ok := b.stateStore.(identity.Repository); ok {
|
||||
b.d.IdentityRepository = identities
|
||||
|
||||
@@ -14,20 +14,8 @@ import (
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/workflowsteps"
|
||||
)
|
||||
|
||||
// reloadSteps builds the production workflow step vocabulary the reload tests'
|
||||
// control-plane client resolves definitions against.
|
||||
func reloadSteps(t *testing.T) *workflow.Manager {
|
||||
t.Helper()
|
||||
steps, err := workflowsteps.NewManager()
|
||||
if err != nil {
|
||||
t.Fatalf("build workflow step vocabulary: %v", err)
|
||||
}
|
||||
return steps
|
||||
}
|
||||
|
||||
// controlPlaneStub answers Query from a fixed resource map. queryErr, when
|
||||
// set, fails every Query so a test can drive the unreachable-State-Store
|
||||
// path.
|
||||
@@ -99,7 +87,7 @@ func newReloadBoot(t *testing.T, stub *controlPlaneStub) *boot {
|
||||
b := &boot{
|
||||
cfg: fileConfig(),
|
||||
log: slog.New(slog.DiscardHandler),
|
||||
controlPlane: controlplane.NewRPCClient(stub, reloadSteps(t)),
|
||||
controlPlane: controlplane.NewRPCClient(stub),
|
||||
}
|
||||
b.cfgHolder = config.NewHolder(b.cfg)
|
||||
return b
|
||||
|
||||
@@ -30,7 +30,6 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/cronstore"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/readiness"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/workflowsteps"
|
||||
"github.com/samcharles93/archie-core/internal/store"
|
||||
)
|
||||
|
||||
@@ -101,16 +100,12 @@ func RunStateStore(ctx context.Context, options StateStoreOptions) error {
|
||||
if !ok {
|
||||
return fmt.Errorf("state store does not support control-plane resources")
|
||||
}
|
||||
// The validating side's step vocabulary, registered here at the
|
||||
// composition root before the first definition is read or replaced. The
|
||||
// same provider set (internal/infrastructure/workflowsteps) is what
|
||||
// archie-agent registers before it compiles one, so a definition this
|
||||
// server admits is compilable there.
|
||||
steps, err := workflowsteps.NewManager()
|
||||
// The validating side's control plane, built here at the composition root
|
||||
// before the first definition is read or replaced.
|
||||
control, err := openStateStoreControlPlane(resources)
|
||||
if err != nil {
|
||||
return fmt.Errorf("register workflow step vocabulary: %w", err)
|
||||
return err
|
||||
}
|
||||
control := controlplane.NewServer(resources, steps)
|
||||
versions, err := control.ImportConfig(ctx, b.cfg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("import control-plane resources: %w", err)
|
||||
@@ -147,6 +142,29 @@ func RunStateStore(ctx context.Context, options StateStoreOptions) error {
|
||||
return serveStateStore(ctx, listener, deps, opts)
|
||||
}
|
||||
|
||||
// openStateStoreControlPlane builds the State Store's control plane server: the
|
||||
// validating side of the workflow step vocabulary, registered here at the
|
||||
// composition root before the first definition is read or replaced. The same
|
||||
// provider set (internal/infrastructure/workflowsteps) is what archie-agent
|
||||
// registers before it compiles one, so within one build a definition this
|
||||
// server admits is compilable there; a skewed deploy is only fixed by a
|
||||
// matching deploy.
|
||||
//
|
||||
// It is separate from RunStateStore so that function stays within its
|
||||
// complexity budget, and step_vocabulary_test.go pins both the call to
|
||||
// stepVocabulary below and RunStateStore's call to this function.
|
||||
func openStateStoreControlPlane(resources controlplane.ResourceStore) (*controlplane.Server, error) {
|
||||
steps, err := stepVocabulary()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("register workflow step vocabulary: %w", err)
|
||||
}
|
||||
server, err := controlplane.NewServer(resources, steps)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("build control plane server: %w", err)
|
||||
}
|
||||
return server, nil
|
||||
}
|
||||
|
||||
func migrateLegacySchedules(ctx context.Context, control *controlplane.Server, dbPath string, version int64) error {
|
||||
if version != 1 {
|
||||
return nil
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package archied
|
||||
|
||||
import (
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/workflowsteps"
|
||||
)
|
||||
|
||||
// stepVocabulary builds the workflow step vocabulary this archied process
|
||||
// resolves workflow definitions against: the shared provider set
|
||||
// (internal/infrastructure/workflowsteps), registered here at the composition
|
||||
// root, before the first resolution.
|
||||
//
|
||||
// Both archied roots call it -- RunStateStore (the State Store's validating
|
||||
// side) and openStateStoreAdapter (the daemon's control-plane client) -- so
|
||||
// neither can register a vocabulary of its own. It is a named function so that
|
||||
// step_vocabulary_test.go can fail if it stops using the shared provider set;
|
||||
// the roots themselves own a SQLite file and dial gRPC, so the test asserts
|
||||
// they call it by parsing their bodies.
|
||||
//
|
||||
// Agreement is within one build: the State Store and archie-agent are
|
||||
// separately deployed binaries, so a State Store built from newer source than
|
||||
// the agent it dispatches to can still disagree, and only a matching deploy
|
||||
// fixes that.
|
||||
func stepVocabulary() (*workflow.Manager, error) { return workflowsteps.NewManager() }
|
||||
@@ -0,0 +1,98 @@
|
||||
package archied
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
)
|
||||
|
||||
// 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
|
||||
}}}
|
||||
}
|
||||
|
||||
// TestStepVocabularyRegistersTheSharedProviderSet pins the unit both archied
|
||||
// roots resolve their vocabulary from. Handing this function an empty manager
|
||||
// (workflow.NewManager) would leave the State Store unable to admit any stored
|
||||
// definition and the daemon unable to decode one.
|
||||
func TestStepVocabularyRegistersTheSharedProviderSet(t *testing.T) {
|
||||
steps, err := stepVocabulary()
|
||||
if err != nil {
|
||||
t.Fatalf("stepVocabulary: %v", err)
|
||||
}
|
||||
if steps == nil {
|
||||
t.Fatal("stepVocabulary registered no workflow step vocabulary")
|
||||
}
|
||||
want := make([]string, 0, len(workflow.BuiltinStepRegistry()))
|
||||
for name := range workflow.BuiltinStepRegistry() {
|
||||
want = append(want, name)
|
||||
}
|
||||
slices.Sort(want)
|
||||
if got := steps.StepTypes(); !slices.Equal(got, want) {
|
||||
t.Fatalf("archied resolves %v, want the shared provider set's shipped stages %v", got, want)
|
||||
}
|
||||
if err := steps.Register(stepVocabularyProbe{}); err != nil {
|
||||
t.Fatalf("register a provider through archied's manager: %v", err)
|
||||
}
|
||||
if _, resolved := steps.Registry()["probe.registered"]; !resolved {
|
||||
t.Fatal("a provider registered through archied's manager did not reach its vocabulary")
|
||||
}
|
||||
}
|
||||
|
||||
// TestArchiedRootsResolveTheStepVocabularyFromThatFunction pins that reading
|
||||
// through stepVocabulary is how both roots reach the vocabulary. Neither root
|
||||
// can be executed in a unit test -- RunStateStore owns a SQLite file and
|
||||
// listen address, openStateStoreAdapter dials the State Store -- so the calls
|
||||
// are asserted by source position, the way composition_order_test.go pins the
|
||||
// memory-engine ordering for the same reason. A root that built its own manager
|
||||
// would resolve a vocabulary of its own and silently lose the shipped stages.
|
||||
func TestArchiedRootsResolveTheStepVocabularyFromThatFunction(t *testing.T) {
|
||||
for _, link := range []struct{ file, function, resolves string }{
|
||||
{"state_store.go", "RunStateStore", "openStateStoreControlPlane"},
|
||||
// RunStateStore delegates to this function, which is where the shipped
|
||||
// stages enter this process.
|
||||
{"state_store.go", "openStateStoreControlPlane", "stepVocabulary"},
|
||||
{"bootstrap.go", "openStateStoreAdapter", "stepVocabulary"},
|
||||
} {
|
||||
t.Run(link.function+"->"+link.resolves, func(t *testing.T) {
|
||||
file, err := parser.ParseFile(token.NewFileSet(), link.file, nil, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if identCallPosition(methodBody(t, file, link.function), link.resolves) == token.NoPos {
|
||||
t.Errorf("%s does not reach its step vocabulary through %s()", link.function, link.resolves)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// identCallPosition returns the position of the first call to a bare function
|
||||
// name in body, or token.NoPos when the body never calls it.
|
||||
func identCallPosition(body *ast.BlockStmt, name string) token.Pos {
|
||||
position := token.NoPos
|
||||
ast.Inspect(body, func(node ast.Node) bool {
|
||||
call, ok := node.(*ast.CallExpr)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
ident, ok := call.Fun.(*ast.Ident)
|
||||
if ok && ident.Name == name && position == token.NoPos {
|
||||
position = call.Pos()
|
||||
}
|
||||
return true
|
||||
})
|
||||
return position
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/workflowsteps"
|
||||
"github.com/samcharles93/archie-core/internal/secret"
|
||||
)
|
||||
|
||||
@@ -31,13 +30,6 @@ func Run(ctx context.Context, o Options) error {
|
||||
defer closeGateway()
|
||||
|
||||
health := newReadinessRegistry(cfg.Options, chat)
|
||||
// The messaging process reads control-plane resources through the client, so
|
||||
// it registers the workflow step vocabulary at its composition root, before
|
||||
// the first resolution, like every other process that resolves one.
|
||||
steps, err := workflowsteps.NewManager()
|
||||
if err != nil {
|
||||
return fmt.Errorf("register workflow step vocabulary: %w", err)
|
||||
}
|
||||
var settings *messaging.SettingsCommand
|
||||
var closeStateStore func()
|
||||
if cfg.Options.StateStore.Target != "" {
|
||||
@@ -47,7 +39,7 @@ func Run(ctx context.Context, o Options) error {
|
||||
}
|
||||
closeStateStore = closeClient
|
||||
defer closeStateStore()
|
||||
chatSettings, channelVersion, settingsErr := controlplane.NewRPCClient(stateStore.ControlPlane(), steps).RuntimeChatConfig(ctx, config.ChatConfig{
|
||||
chatSettings, channelVersion, settingsErr := controlplane.NewRPCClient(stateStore.ControlPlane()).RuntimeChatConfig(ctx, config.ChatConfig{
|
||||
Telegram: cfg.Telegram, Email: cfg.Email, Webhook: cfg.Webhook, WebhookAddr: cfg.WebhookAddr, ShowToolCalls: cfg.ShowToolCalls,
|
||||
})
|
||||
if settingsErr != nil {
|
||||
|
||||
@@ -17,19 +17,36 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/cronstore"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
rpc pb.ControlPlaneServiceClient
|
||||
// steps is the step vocabulary this client validates and decodes workflow
|
||||
// definitions against, resolved once by stepRegistry.
|
||||
// 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 --
|
||||
// needs no provider set and cannot be failed by one.
|
||||
type Client struct{ rpc pb.ControlPlaneServiceClient }
|
||||
|
||||
func NewClient(conn grpc.ClientConnInterface) *Client {
|
||||
return &Client{rpc: pb.NewControlPlaneServiceClient(conn)}
|
||||
}
|
||||
|
||||
func NewRPCClient(client pb.ControlPlaneServiceClient) *Client { return &Client{rpc: client} }
|
||||
|
||||
// WorkflowDefinitionsClient reads and replaces the workflow-definitions
|
||||
// resource, the one control-plane surface whose stored values name workflow
|
||||
// step types. Resolving those names needs the step vocabulary the process
|
||||
// registered at its composition root, so the vocabulary is a constructor
|
||||
// dependency of this surface and of no other: a caller that cannot reach
|
||||
// workflow definitions cannot ask for one.
|
||||
type WorkflowDefinitionsClient struct {
|
||||
rpc pb.ControlPlaneServiceClient
|
||||
steps workflow.StepRegistry
|
||||
}
|
||||
|
||||
func NewClient(conn grpc.ClientConnInterface, steps *workflow.Manager) *Client {
|
||||
return &Client{rpc: pb.NewControlPlaneServiceClient(conn), steps: stepRegistry(steps)}
|
||||
}
|
||||
|
||||
func NewRPCClient(client pb.ControlPlaneServiceClient, steps *workflow.Manager) *Client {
|
||||
return &Client{rpc: client, steps: stepRegistry(steps)}
|
||||
func NewWorkflowDefinitionsClient(client pb.ControlPlaneServiceClient, steps *workflow.Manager) (*WorkflowDefinitionsClient, error) {
|
||||
registry, err := stepRegistry(steps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &WorkflowDefinitionsClient{rpc: client, steps: registry}, nil
|
||||
}
|
||||
|
||||
func (c *Client) Catalog(ctx context.Context) ([]*pb.ResourceDescriptor, error) {
|
||||
@@ -40,7 +57,7 @@ func (c *Client) Catalog(ctx context.Context) ([]*pb.ResourceDescriptor, error)
|
||||
return response.Resources, nil
|
||||
}
|
||||
|
||||
func (c *Client) WorkflowDefinitions(ctx context.Context) (workflow.WorkflowDefinitionCollection, int64, error) {
|
||||
func (c *WorkflowDefinitionsClient) WorkflowDefinitions(ctx context.Context) (workflow.WorkflowDefinitionCollection, int64, error) {
|
||||
response, err := c.rpc.Query(ctx, &pb.QueryRequest{Kind: WorkflowDefinitionsKind})
|
||||
if err != nil {
|
||||
return workflow.WorkflowDefinitionCollection{}, 0, clientError(err)
|
||||
@@ -52,7 +69,7 @@ func (c *Client) WorkflowDefinitions(ctx context.Context) (workflow.WorkflowDefi
|
||||
// ReplaceWorkflowDefinitions replaces the collection. Passing
|
||||
// workflow.ShippedDefinitions() restores all shipped definitions while keeping
|
||||
// the previous override in resource history.
|
||||
func (c *Client) ReplaceWorkflowDefinitions(ctx context.Context, definitions workflow.WorkflowDefinitionCollection, expectedVersion int64, actor, source, requestID string) (int64, error) {
|
||||
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 {
|
||||
return 0, err
|
||||
|
||||
@@ -44,15 +44,19 @@ type Server struct {
|
||||
|
||||
// NewServer builds the control plane server the State Store serves. steps is
|
||||
// the workflow step vocabulary the composition root registered; this is the
|
||||
// validating side of the vocabulary archie-agent executes against.
|
||||
func NewServer(resources ResourceStore, steps *workflow.Manager) *Server {
|
||||
registry := stepRegistry(steps)
|
||||
// validating side of the vocabulary archie-agent executes against in a
|
||||
// matching build (see stepRegistry: a skewed deploy can still disagree).
|
||||
func NewServer(resources ResourceStore, steps *workflow.Manager) (*Server, error) {
|
||||
registry, err := stepRegistry(steps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
definitions := builtinDefinitions(registry)
|
||||
byKind := make(map[string]Definition, len(definitions))
|
||||
for _, definition := range definitions {
|
||||
byKind[definition.Kind] = definition
|
||||
}
|
||||
return &Server{store: resources, definitions: byKind, ordered: definitions}
|
||||
return &Server{store: resources, definitions: byKind, ordered: definitions}, nil
|
||||
}
|
||||
|
||||
func (s *Server) Catalog(context.Context, *pb.CatalogRequest) (*pb.CatalogResponse, error) {
|
||||
|
||||
@@ -29,12 +29,24 @@ func testSteps(t *testing.T) *workflow.Manager {
|
||||
return steps
|
||||
}
|
||||
|
||||
// testServer builds the State Store's control plane against the production
|
||||
// vocabulary, so a test that is not about the vocabulary still exercises the
|
||||
// constructor production uses.
|
||||
func testServer(t *testing.T, resources ResourceStore) *Server {
|
||||
t.Helper()
|
||||
server, err := NewServer(resources, testSteps(t))
|
||||
if err != nil {
|
||||
t.Fatalf("build control plane server: %v", err)
|
||||
}
|
||||
return server
|
||||
}
|
||||
|
||||
func TestCatalogCarriesShippedWorkflowDefinitionsForRestore(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
resources := store.OpenTest(t)
|
||||
defer resources.Close()
|
||||
catalog, err := NewServer(resources, testSteps(t)).Catalog(t.Context(), &pb.CatalogRequest{})
|
||||
catalog, err := testServer(t, resources).Catalog(t.Context(), &pb.CatalogRequest{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -61,7 +73,7 @@ func TestImportConfigSeedsWorkflowDefinitionsWithoutOverwritingOverride(t *testi
|
||||
|
||||
resources := store.OpenTest(t)
|
||||
defer resources.Close()
|
||||
server := NewServer(resources, testSteps(t))
|
||||
server := testServer(t, resources)
|
||||
if _, err := server.ImportConfig(t.Context(), config.Config{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -101,7 +113,7 @@ func TestImportConfigSeedsPersonasWithoutOverwritingEdits(t *testing.T) {
|
||||
|
||||
resources := store.OpenTest(t)
|
||||
defer resources.Close()
|
||||
server := NewServer(resources, testSteps(t))
|
||||
server := testServer(t, resources)
|
||||
if _, err := server.ImportConfig(t.Context(), config.Config{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -139,7 +151,7 @@ func TestImportWorkflowExecutionSettingsDoesNotOverwriteExistingValue(t *testing
|
||||
|
||||
resources := store.OpenTest(t)
|
||||
defer resources.Close()
|
||||
server := NewServer(resources, testSteps(t))
|
||||
server := testServer(t, resources)
|
||||
first := workflow.ExecutionSettings{MaxModelToolSteps: 10, MaxRuntime: time.Minute, MaxConsecutiveGateFailures: 2}
|
||||
if _, err := server.ImportWorkflowExecutionSettings(t.Context(), first); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -165,7 +177,7 @@ func TestRegistryRoutesAndValidatesDefinitions(t *testing.T) {
|
||||
|
||||
resources := store.OpenTest(t)
|
||||
defer resources.Close()
|
||||
server := NewServer(resources, testSteps(t))
|
||||
server := testServer(t, resources)
|
||||
if _, err := server.ImportConfig(t.Context(), config.Config{Containers: config.ContainerConfig{PullPolicy: "missing"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -195,7 +207,7 @@ func TestProviderSeedKeepsReferencesAndNeverResolvedSecrets(t *testing.T) {
|
||||
|
||||
resources := store.OpenTest(t)
|
||||
defer resources.Close()
|
||||
server := NewServer(resources, testSteps(t))
|
||||
server := testServer(t, resources)
|
||||
cfg := config.Config{Providers: map[string]config.Provider{"openai": {Class: "openai", APIKeyEnv: "OPENAI_API_KEY", APIKey: config.SecretRef{Engine: "env", Key: "OPENAI_API_KEY"}}}}
|
||||
if _, err := server.ImportConfig(context.Background(), cfg); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -222,7 +234,7 @@ func TestHistoryCarriesEveryRevisionWithItsAudit(t *testing.T) {
|
||||
|
||||
resources := store.OpenTest(t)
|
||||
defer resources.Close()
|
||||
server := NewServer(resources, testSteps(t))
|
||||
server := testServer(t, resources)
|
||||
if _, err := server.ImportConfig(t.Context(), config.Config{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestRuntimeConfigUsesDatabaseResourcesAndPreservesBootstrapOnlySecrets(t *t
|
||||
ToolSettingsKind: map[string]any{"mcp_servers": []map[string]any{{"name": "docs", "transport": "http", "url": "https://mcp.example.com", "headers_configured": true}}, "policy": map[string]any{}, "web_fetch": map[string]any{}, "minimax": map[string]any{"enabled": false, "credential_configured": false}},
|
||||
PluginSettingsKind: map[string]any{"plugin_dir": "/plugins", "module_dir": "/modules", "secret_engine_dir": "/secrets", "skills_dir": "/skills"},
|
||||
ContainerRuntimePoliciesKind: config.ContainerConfig{LegacyEnabled: true, Image: "archie:next", PullPolicy: "missing"},
|
||||
}}, testSteps(t))
|
||||
}})
|
||||
|
||||
got, versions, err := client.RuntimeConfig(t.Context(), base)
|
||||
if err != nil {
|
||||
|
||||
@@ -121,13 +121,16 @@ func TestEveryProductionResolutionSiteResolvesTheRegisteredStepType(t *testing.T
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("control-plane client", func(t *testing.T) {
|
||||
t.Run("workflow-definitions client", func(t *testing.T) {
|
||||
value, err := json.Marshal(probeCollection(test.stepType))
|
||||
if err != nil {
|
||||
t.Fatalf("encode definitions: %v", err)
|
||||
}
|
||||
rpc := &definitionsClient{value: value}
|
||||
client := NewRPCClient(rpc, steps)
|
||||
client, err := NewWorkflowDefinitionsClient(rpc, steps)
|
||||
if err != nil {
|
||||
t.Fatalf("build workflow-definitions client: %v", err)
|
||||
}
|
||||
|
||||
// Read path: the daemon decodes the stored collection here.
|
||||
collection, _, readErr := client.WorkflowDefinitions(t.Context())
|
||||
@@ -173,6 +176,30 @@ func TestEveryProductionResolutionSiteResolvesTheRegisteredStepType(t *testing.T
|
||||
}
|
||||
}
|
||||
|
||||
// TestNilStepVocabularyFailsClosedAtEveryResolutionSite pins the guard on the
|
||||
// manager every resolution site now requires. A nil manager is a wiring bug at
|
||||
// the composition root, so each site must name it and refuse to resolve, rather
|
||||
// than dereference it: a nil-pointer panic is the same failure with no clue in
|
||||
// it.
|
||||
func TestNilStepVocabularyFailsClosedAtEveryResolutionSite(t *testing.T) {
|
||||
resources := store.OpenTest(t)
|
||||
t.Cleanup(func() {
|
||||
if err := resources.Close(); err != nil {
|
||||
t.Errorf("close test store: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
if _, err := NewServer(resources, nil); err == nil || !strings.Contains(err.Error(), "no workflow step vocabulary") {
|
||||
t.Errorf("NewServer with no step vocabulary: error = %v, want the missing-vocabulary refusal", err)
|
||||
}
|
||||
if _, err := NewWorkflowDefinitionsClient(&definitionsClient{}, nil); err == nil || !strings.Contains(err.Error(), "no workflow step vocabulary") {
|
||||
t.Errorf("NewWorkflowDefinitionsClient with no step vocabulary: error = %v, want the missing-vocabulary refusal", err)
|
||||
}
|
||||
if _, err := agentworker.CompilePinnedWorkflow(probeRequest(probeStepType), nil); err == nil || !strings.Contains(err.Error(), "no step vocabulary") {
|
||||
t.Errorf("CompilePinnedWorkflow with no step vocabulary: error = %v, want the missing-vocabulary refusal", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestAgentWorkerCompilesShippedDefinitionsFromTheInjectedVocabulary pins the
|
||||
// shipped-definition route inside CompilePinnedWorkflow. That route compiles
|
||||
// definitions whose steps are all shipped stages, so no plugin assertion can
|
||||
@@ -226,7 +253,10 @@ func admitThroughStateStore(t *testing.T, steps *workflow.Manager, stepType stri
|
||||
t.Errorf("close test store: %v", closeErr)
|
||||
}
|
||||
})
|
||||
server := NewServer(resources, steps)
|
||||
server, err := NewServer(resources, steps)
|
||||
if err != nil {
|
||||
t.Fatalf("build control plane server: %v", err)
|
||||
}
|
||||
|
||||
if resource, resourceErr := resources.Resource(t.Context(), WorkflowDefinitionsKind); resourceErr == nil {
|
||||
before = resource.Version
|
||||
|
||||
@@ -2,6 +2,7 @@ package controlplane
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
@@ -11,12 +12,20 @@ import (
|
||||
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() }
|
||||
// vocabulary, and the guard on the manager it must be handed. The manager is
|
||||
// built at the composition root (infrastructure/workflowsteps.NewManager) and
|
||||
// injected, so the State Store server -- the validating side -- and the
|
||||
// workflow-definitions client both resolve the vocabulary that composition
|
||||
// root registered. Agreement is within one build: the State Store and
|
||||
// archie-agent are separately deployed binaries, so a State Store built from
|
||||
// newer source than the agent it dispatches to can still disagree, and only a
|
||||
// matching deploy fixes that.
|
||||
func stepRegistry(steps *workflow.Manager) (workflow.StepRegistry, error) {
|
||||
if steps == nil {
|
||||
return nil, errors.New("control plane: no workflow step vocabulary: the composition root must register the provider set (infrastructure/workflowsteps.NewManager) before the first resolution")
|
||||
}
|
||||
return steps.Registry(), nil
|
||||
}
|
||||
|
||||
func workflowDefinitionsDefinition(steps workflow.StepRegistry) Definition {
|
||||
return Definition{
|
||||
|
||||
Reference in new issue
Block a user