fix(controlplane): stored container policies replace file profiles; add profile image and workflow examples
A stored container-runtime-policies document that carries Profiles now replaces the file's profiles instead of merging into them, so a profile deleted in the dashboard stays deleted; one stored before profiles existed still inherits the file's. Profiles drop their json tags so the stored document keys them like its other fields. Adds examples/profiles/Dockerfile.agent-net (agent image plus network lookup tools) with a build-only agent-net compose service, examples/workflows/firewall-investigate.yaml with a test that parses every example against the registered step vocabulary, and names the postgres service in the compose header.
This commit is contained in:
1 parent
7b7aa62c28
commit
4046766abe
8 files changed
+128
-7
No files matched your search
@@ -187,7 +187,20 @@ func runtimeToolConfigFrom(ctx context.Context, reader controlplanerpc.ResourceR
|
||||
}); err != nil {
|
||||
return config.Config{}, nil, err
|
||||
}
|
||||
if err := layerResourceJSON(ctx, reader, versions, ContainerRuntimePoliciesKind, &out.Containers); err != nil {
|
||||
if err := layerResource(ctx, reader, versions, ContainerRuntimePoliciesKind, func(value []byte) error {
|
||||
// A document that omits Profiles (one stored before they existed)
|
||||
// inherits the file's. One that carries them replaces the file's:
|
||||
// json.Unmarshal merges into an existing map, so without clearing it a
|
||||
// profile deleted from the store would come back from the file.
|
||||
var keys map[string]json.RawMessage
|
||||
if err := json.Unmarshal(value, &keys); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, stored := keys["Profiles"]; stored {
|
||||
out.Containers.Profiles = nil
|
||||
}
|
||||
return json.Unmarshal(value, &out.Containers)
|
||||
}); err != nil {
|
||||
return config.Config{}, nil, err
|
||||
}
|
||||
return out, versions, nil
|
||||
|
||||
@@ -333,3 +333,40 @@ func TestSchedulingPolicySeedCarriesTheLabel(t *testing.T) {
|
||||
t.Fatalf("seed label = %q, want the file document's label", label)
|
||||
}
|
||||
}
|
||||
|
||||
// Stored container policies that carry profiles replace the file's outright;
|
||||
// ones stored before profiles existed inherit the file's.
|
||||
func TestRuntimeConfigLayersStoredProfiles(t *testing.T) {
|
||||
base := config.Config{Containers: config.ContainerConfig{Image: "agent:1", Profiles: map[string]config.AgentProfile{
|
||||
"file-only": {Image: "file:1"},
|
||||
}}}
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
stored map[string]any
|
||||
want []string
|
||||
}{
|
||||
{name: "stored profiles replace the file's", stored: map[string]any{"Image": "agent:2", "Profiles": map[string]any{"net": map[string]any{"Tools": []string{"whois"}}}}, want: []string{"net"}},
|
||||
{name: "a document without profiles inherits the file's", stored: map[string]any{"Image": "agent:2"}, want: []string{"file-only"}},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
client := NewRPCClient(&runtimeConfigClient{values: map[string]any{
|
||||
SchedulingPolicyKind: map[string]any{"poll_interval": "2m", "dispatch": map[string]any{"trigger": "assignee"}},
|
||||
ContainerRuntimePoliciesKind: tt.stored,
|
||||
}})
|
||||
got, _, err := client.RuntimeConfig(t.Context(), base)
|
||||
if err != nil {
|
||||
t.Fatalf("RuntimeConfig: %v", err)
|
||||
}
|
||||
var names []string
|
||||
for name := range got.Containers.Profiles {
|
||||
names = append(names, name)
|
||||
}
|
||||
if !reflect.DeepEqual(names, tt.want) {
|
||||
t.Fatalf("profiles = %v, want %v", names, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
if got := base.Containers.Profiles; len(got) != 1 {
|
||||
t.Fatalf("layering mutated the file document's profiles: %v", got)
|
||||
}
|
||||
}
|
||||
@@ -909,7 +909,7 @@ type ContainerConfig struct {
|
||||
// Profiles are the named agent profiles a workflow selects with
|
||||
// `profile:`. A workflow that names none runs under the default profile:
|
||||
// Image and every tool.
|
||||
Profiles map[string]AgentProfile `toml:"profiles" yaml:"profiles" json:"profiles,omitempty"`
|
||||
Profiles map[string]AgentProfile `toml:"profiles" yaml:"profiles"`
|
||||
}
|
||||
|
||||
// AgentProfile is a named execution environment for an agent. Secrets and
|
||||
@@ -919,12 +919,12 @@ type ContainerConfig struct {
|
||||
// an operator when it is dispatched (daemon pinTaskProfile).
|
||||
type AgentProfile struct {
|
||||
// Image is the container image; empty means [containers].image.
|
||||
Image string `toml:"image" yaml:"image" json:"image,omitempty"`
|
||||
Image string `toml:"image" yaml:"image"`
|
||||
// Tools allowlists the tools archie adds to the agent (MCP servers,
|
||||
// repository scripts and skill plugins) by name. Empty allows them all.
|
||||
// The agent loop's own file tools are always present, read-only when a
|
||||
// step asks for that.
|
||||
Tools []string `toml:"tools" yaml:"tools" json:"tools,omitempty"`
|
||||
Tools []string `toml:"tools" yaml:"tools"`
|
||||
}
|
||||
|
||||
// Profile resolves the profile a workflow names: "" is the default profile,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package workflowsteps
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -189,3 +191,26 @@ func TestRepoHookStepsCompileThroughTheManager(t *testing.T) {
|
||||
t.Fatalf("ParseAndCompile(%q) error = %v, want the unusable rule refused by name", broken, err)
|
||||
}
|
||||
}
|
||||
|
||||
// The shipped example workflows parse against the vocabulary the roots
|
||||
// register, so an example cannot drift from the steps that exist.
|
||||
func TestExampleWorkflowsParse(t *testing.T) {
|
||||
paths, err := filepath.Glob("../../../examples/workflows/*.yaml")
|
||||
if err != nil || len(paths) == 0 {
|
||||
t.Fatalf("no example workflows found: %v", err)
|
||||
}
|
||||
manager, err := NewManager()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
registry := manager.Registry()
|
||||
for _, path := range paths {
|
||||
src, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := workflow.ParseDefinition(string(src), registry); err != nil {
|
||||
t.Errorf("%s: %v", path, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user