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.
82 lines
4.5 KiB
Go
82 lines
4.5 KiB
Go
package controlplane
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
pb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
|
|
)
|
|
|
|
type runtimeConfigClient struct{ values map[string]any }
|
|
|
|
func (*runtimeConfigClient) Catalog(context.Context, *pb.CatalogRequest, ...grpc.CallOption) (*pb.CatalogResponse, error) {
|
|
return &pb.CatalogResponse{}, nil
|
|
}
|
|
|
|
func (c *runtimeConfigClient) Query(_ context.Context, request *pb.QueryRequest, _ ...grpc.CallOption) (*pb.QueryResponse, error) {
|
|
value, err := json.Marshal(c.values[request.Kind])
|
|
return &pb.QueryResponse{Resource: &pb.Resource{Kind: request.Kind, Version: 2, ValueJson: value}}, err
|
|
}
|
|
|
|
func (*runtimeConfigClient) History(context.Context, *pb.HistoryRequest, ...grpc.CallOption) (*pb.HistoryResponse, error) {
|
|
panic("unexpected History")
|
|
}
|
|
|
|
func (*runtimeConfigClient) Command(context.Context, *pb.CommandRequest, ...grpc.CallOption) (*pb.CommandResponse, error) {
|
|
panic("unexpected Command")
|
|
}
|
|
|
|
func (*runtimeConfigClient) Watch(context.Context, *pb.WatchRequest, ...grpc.CallOption) (grpc.ServerStreamingClient[pb.WatchResponse], error) {
|
|
panic("unexpected Watch")
|
|
}
|
|
|
|
func TestRuntimeConfigUsesDatabaseResourcesAndPreservesBootstrapOnlySecrets(t *testing.T) {
|
|
base := config.Config{
|
|
Providers: map[string]config.Provider{"old": {Class: "openai"}},
|
|
Models: map[string]string{"builder": "old/model"},
|
|
Repos: []config.Repo{{Owner: "old", Name: "repo"}},
|
|
Chat: config.ChatConfig{Telegram: config.TelegramConfig{
|
|
UpdateCheckCommand: []string{"check"}, UpdateInstallCommand: []string{"install"},
|
|
}},
|
|
Tools: config.ToolsConfig{MCPServers: []config.MCPServer{{Name: "docs", Headers: map[string]string{"Authorization": "secret"}}}},
|
|
}
|
|
client := NewRPCClient(&runtimeConfigClient{values: map[string]any{
|
|
ProviderSettingsKind: map[string]any{"main": map[string]any{"class": "openai", "base_url": "https://api.example.com", "api_key_ref": map[string]any{"engine": "env", "key": "API_KEY"}, "has_credential": true}},
|
|
ModelRoleAssignmentsKind: map[string]string{"builder": "main/model"},
|
|
RepositoryPoliciesKind: []config.Repo{{Owner: "acme", Name: "widget"}},
|
|
ChannelSettingsKind: map[string]any{"operator": "Sam", "show_tool_calls": true, "max_steps": 20, "models": []string{"main/model"}, "email": map[string]any{}, "webhook_addr": "", "webhook": map[string]any{}, "telegram": map[string]any{"allowed_user_ids": []int64{42}, "credential_configured": false}, "rate_limit": map[string]any{}, "unrestricted_filesystem": false, "workspace": "/workspace"},
|
|
SchedulingPolicyKind: map[string]any{"poll_interval": "2m", "max_retries": 7, "dispatch": map[string]any{"trigger": "assignee"}},
|
|
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 {
|
|
t.Fatalf("RuntimeConfig: %v", err)
|
|
}
|
|
// Every kind it read is reported as applied, so the version a process
|
|
// publishes is the one it actually layered in (archie-core-pskb).
|
|
for _, kind := range []string{
|
|
ProviderSettingsKind, ModelRoleAssignmentsKind, RepositoryPoliciesKind, ChannelSettingsKind,
|
|
SchedulingPolicyKind, ToolSettingsKind, PluginSettingsKind, ContainerRuntimePoliciesKind,
|
|
} {
|
|
if versions[kind] != 2 {
|
|
t.Errorf("versions[%s] = %d, want the 2 the store answered with", kind, versions[kind])
|
|
}
|
|
}
|
|
if got.Models["builder"] != "main/model" || got.Repos[0].FullName() != "acme/widget" || got.MaxRetries != 7 || got.PluginDir != "/plugins" || got.Containers.Image != "archie:next" {
|
|
t.Fatalf("database settings not applied: %+v", got)
|
|
}
|
|
if got.Chat.Operator != "Sam" || got.Chat.Telegram.AllowedUserIDs[0] != 42 {
|
|
t.Fatalf("channel settings not applied: %+v", got.Chat)
|
|
}
|
|
if got.Chat.Telegram.UpdateCheckCommand[0] != "check" || got.Tools.MCPServers[0].Headers["Authorization"] != "secret" {
|
|
t.Fatalf("bootstrap-only secret-backed settings were dropped: chat=%+v tools=%+v", got.Chat, got.Tools)
|
|
}
|
|
}
|