feat(controlplane): agent profiles as their own live control-plane resource

docs/prds/external-agent-harness.md ("Selection"): a Kit profile is an org
resource that applies without a restart. Profiles were bundled inside
container-runtime-policies (ApplyMode: restart-required), which is correct
for Image/MaxConcurrency/Network but not for Profiles, which nothing
startup-builds: daemon.configFor reads config.Holder fresh per dispatch
(pinTaskProfile -> Containers.Profile).

Split Profiles into its own resource, AgentProfileKind ("agent-profiles"),
ApplyMode: live, seeded from [containers.profiles] and validated with the
same rules the file document uses (config.ValidateAgentProfiles, factored
out of ContainerConfig.ValidateProfiles so the two cannot disagree).
config.ContainerConfig.Profiles is now json:"-" so container-runtime-policies
never carries it (one authoritative resource per field, not two), and
runtime_config.go layers the new resource in by wholesale map replacement
(matching ModelRoleAssignmentsKind's precedent) rather than merging into the
file's map. Added Profiles to reload.go's Containers reloadable-subfield set
to match this.

Deliberately NOT built here: true per-org multi-tenant storage for this
resource (docs/prds/orgs-and-access.md places agent profiles under org
ownership, granted to workspaces). No existing control-plane resource kind
in this registry does real per-org storage yet either -- schedules,
workflow settings, etc. are all single instance-wide documents -- so
agent-profiles follows that same established, tested pattern rather than
inventing org-scoped storage unilaterally for this one resource. Org/
workspace grants over agent-profiles are a follow-on, not a redo: nothing
about this resource's shape needs to change to add that scoping later.
This commit is contained in:
sam committed 2026-09-27 05:25:38 +10:00
1 parent 04dfa29dcb
commit adf44d827f
10 files changed
+217 -108

No files matched your search

@@ -175,6 +175,7 @@ looking at before reporting one:
| `volume_ttl` | Default `72h` only when enabled; negative rejected. |
| `pull_policy` | Default `missing` when enabled. Pool code recognises `missing` and `always`; other strings silently skip pre-pull. |
| `network` | Empty uses best-effort self-network detection. Repository overlay pins `archie-core_default`. |
| `profiles` | Named agent execution environments (image or Kit); resolved per task dispatch (`ContainerConfig.Profile`). Own control-plane resource `agent-profiles` (`json:"-"` on the field so `container-runtime-policies` never carries it), `ApplyMode: live` -- a profile change applies without a restart, unlike the rest of `[containers]`. |
### Channel settings
+13 -9
View File
@@ -148,16 +148,20 @@ var reloadableFields = map[string]bool{
// reloadableSubFields are sub-fields of structs that are otherwise
// startup-built. VolumeTTL is re-read per cycle in cleanupExpiredStorage;
// everything else in Containers (Image, MaxConcurrency,
// MaxUptime, PullPolicy, Network) is frozen in the startup-built
// container pool -- the dispatchers re-read MaxConcurrency but the pool
// captures it at construction (container/pool.go:94,163), so a change
// only partially applies and must warn requires-restart. Forge.Host is
// carried into TaskContext by ForTask (display/link building only); the
// forge client itself is startup-built, so Type/Token/TokenEnv stay
// requires-restart.
// Profiles is resolved fresh per dispatch (daemon.configFor ->
// Containers.Profile, called from pinTaskProfile) and is also its own
// live-applying control-plane resource (AgentProfileKind), never captured at
// container-pool construction -- docs/prds/external-agent-harness.md
// "Selection": a Kit profile applies without a restart. Everything else in
// Containers (Image, MaxConcurrency, MaxUptime, PullPolicy, Network) is
// frozen in the startup-built container pool -- the dispatchers re-read
// MaxConcurrency but the pool captures it at construction
// (container/pool.go:94,163), so a change only partially applies and must
// warn requires-restart. Forge.Host is carried into TaskContext by ForTask
// (display/link building only); the forge client itself is startup-built, so
// Type/Token/TokenEnv stay requires-restart.
var reloadableSubFields = map[string]map[string]bool{
"Containers": {"VolumeTTL": true},
"Containers": {"VolumeTTL": true, "Profiles": true},
"Forge": {"Host": true},
// Policy is carried into TaskConfig by ForTask (config.go); MCPServers,
// WebFetch and Minimax are not and stay requires-restart.
@@ -0,0 +1,67 @@
package controlplane
import "github.com/samcharles93/archie-core/internal/config"
// AgentProfileKind is the control-plane resource for Kit and image agent
// profiles. It exists so a Kit profile applies without a restart
// (docs/prds/external-agent-harness.md, "Selection"): [containers].profiles
// in config.toml is only its seed, ContainerRuntimePoliciesKind carries every
// other container setting and none of this one (config.ContainerConfig.
// Profiles is json:"-"), and this resource's own ApplyMode is "live".
//
// Its document is agentProfile (container_settings.go's snake_case wire
// type), not config.AgentProfile directly: that internal type carries no
// json tags, so encoding/json would fall back to its Go field names --
// "Tools", "Image" -- exactly the defect archie-core-1171 fixed for the rest
// of this document family.
const AgentProfileKind = "agent-profiles"
func agentProfileDefinition() Definition {
return Definition{
Kind: AgentProfileKind,
Title: "Agent profiles",
ApplyMode: "live",
Document: map[string]agentProfile{},
Seed: seedAgentProfiles,
Validate: validateAgentProfiles,
}
}
func seedAgentProfiles(cfg config.Config) any {
return agentProfilesDocument(cfg.Containers.Profiles)
}
// agentProfilesDocument maps the internal type to the document's wire type.
func agentProfilesDocument(profiles map[string]config.AgentProfile) map[string]agentProfile {
if profiles == nil {
return nil
}
out := make(map[string]agentProfile, len(profiles))
for name, p := range profiles {
out[name] = agentProfile{Image: p.Image, Kit: p.Kit, Adapter: p.Adapter, Tools: p.Tools}
}
return out
}
// agentProfilesSettings reverses agentProfilesDocument, for the layering in
// runtime_config.go and for validation against config.ValidateAgentProfiles.
func agentProfilesSettings(profiles map[string]agentProfile) map[string]config.AgentProfile {
if profiles == nil {
return nil
}
out := make(map[string]config.AgentProfile, len(profiles))
for name, p := range profiles {
out[name] = config.AgentProfile{Image: p.Image, Kit: p.Kit, Adapter: p.Adapter, Tools: p.Tools}
}
return out
}
func validateAgentProfiles(input []byte) error {
// The rules live in the config package and are shared with the file
// document's own validation (config.ContainerConfig.ValidateProfiles):
// which profiles are valid cannot differ between the file that seeds
// this resource and the resource that replaces it.
return validateAs(input, func(profiles map[string]agentProfile) error {
return config.ValidateAgentProfiles(agentProfilesSettings(profiles))
})
}
+24 -25
View File
@@ -17,14 +17,18 @@ import (
// "MaxConcurrency", "LegacyEnabled" -- the only Go-cased resource left in the
// registry (archie-core-1171). The two durations are config.Duration, which
// already writes the string the file accepts; the leak was the keys only.
//
// Profiles is deliberately not a field here: config.ContainerConfig.Profiles
// is json:"-" (its own resource, AgentProfileKind, applies live where the
// rest of this one is restart-required -- docs/prds/external-agent-harness.md
// "Selection"), so this document never carries it either.
type containerRuntimePolicies struct {
Image string `json:"image"`
MaxConcurrency int `json:"max_concurrency"`
MaxUptime config.Duration `json:"max_uptime"`
VolumeTTL config.Duration `json:"volume_ttl"`
PullPolicy string `json:"pull_policy"`
Network string `json:"network"`
Profiles map[string]agentProfile `json:"profiles,omitempty"`
Image string `json:"image"`
MaxConcurrency int `json:"max_concurrency"`
MaxUptime config.Duration `json:"max_uptime"`
VolumeTTL config.Duration `json:"volume_ttl"`
PullPolicy string `json:"pull_policy"`
Network string `json:"network"`
}
// agentProfile is one named execution environment as the document writes it.
@@ -43,7 +47,6 @@ type agentProfile struct {
var legacyContainerKeys = map[string]string{
"Image": "image", "MaxConcurrency": "max_concurrency", "MaxUptime": "max_uptime",
"VolumeTTL": "volume_ttl", "PullPolicy": "pull_policy", "Network": "network",
"Profiles": "profiles",
}
// legacyProfileKeys are the same fallback at the profile nesting level.
@@ -74,6 +77,11 @@ func (p *containerRuntimePolicies) UnmarshalJSON(data []byte) error {
// consumer -- so it is dropped rather than renamed: the strict decode would
// otherwise refuse a document every deployment of that window stores.
delete(raw, "LegacyEnabled")
// "profiles"/"Profiles" carried config.ContainerConfig.Profiles before it
// moved to its own resource, AgentProfileKind; a document stored under
// either name before that still decodes, with the key simply dropped.
delete(raw, "profiles")
delete(raw, "Profiles")
encoded, err := json.Marshal(raw)
if err != nil {
return err
@@ -87,33 +95,22 @@ func (p *containerRuntimePolicies) UnmarshalJSON(data []byte) error {
}
// settings maps the document onto the internal config struct the daemon runs.
// Profiles is never set here: config.ContainerConfig.Profiles is json:"-",
// and AgentProfileKind's own layering step in runtime_config.go is what sets
// it, after this one runs.
func (p containerRuntimePolicies) settings() config.ContainerConfig {
out := config.ContainerConfig{
return config.ContainerConfig{
Image: p.Image, MaxConcurrency: p.MaxConcurrency, MaxUptime: p.MaxUptime,
VolumeTTL: p.VolumeTTL, PullPolicy: p.PullPolicy, Network: p.Network,
}
if p.Profiles != nil {
out.Profiles = make(map[string]config.AgentProfile, len(p.Profiles))
for name, profile := range p.Profiles {
out.Profiles[name] = config.AgentProfile{Image: profile.Image, Kit: profile.Kit, Adapter: profile.Adapter, Tools: profile.Tools}
}
}
return out
}
func seedContainerPolicies(cfg config.Config) any {
containers := cfg.Containers
policies := containerRuntimePolicies{
return containerRuntimePolicies{
Image: containers.Image, MaxConcurrency: containers.MaxConcurrency, MaxUptime: containers.MaxUptime,
VolumeTTL: containers.VolumeTTL, PullPolicy: containers.PullPolicy, Network: containers.Network,
}
if containers.Profiles != nil {
policies.Profiles = make(map[string]agentProfile, len(containers.Profiles))
for name, profile := range containers.Profiles {
policies.Profiles[name] = agentProfile{Image: profile.Image, Kit: profile.Kit, Adapter: profile.Adapter, Tools: profile.Tools}
}
}
return policies
}
func validateContainers(input []byte) error {
@@ -130,7 +127,9 @@ func validateContainers(input []byte) error {
if strings.TrimSpace(settings.Image) == "" {
return fmt.Errorf("container image is required for autonomous workflow workers")
}
return settings.ValidateProfiles()
// Profiles is json:"-" on config.ContainerConfig: it is
// AgentProfileKind's document now, validated there.
return nil
})
}
@@ -33,7 +33,6 @@ func TestContainerRuntimePoliciesSeedIsTheDocumentShape(t *testing.T) {
Image: "archie-agent:test", MaxConcurrency: 4,
MaxUptime: config.Duration(2 * time.Hour), VolumeTTL: config.Duration(24 * time.Hour),
PullPolicy: "missing", Network: "bridge",
Profiles: map[string]config.AgentProfile{"net": {Tools: []string{"whois"}}},
}}
encoded, err := json.Marshal(containerPoliciesDefinition(t).Seed(cfg))
if err != nil {
@@ -53,33 +52,31 @@ func TestContainerRuntimePoliciesSeedIsTheDocumentShape(t *testing.T) {
t.Errorf("seed %s = %#v, want %#v", key, document[key], value)
}
}
profiles, ok := document["profiles"].(map[string]any)
if !ok {
t.Fatalf("profiles = %#v, want an object", document["profiles"])
}
net, ok := profiles["net"].(map[string]any)
if !ok || net["tools"] == nil {
t.Fatalf("profiles.net = %#v, want the snake_case tools", profiles["net"])
}
// The Go field names encoding/json fell back to when the document was the
// internal config struct -- at both nesting levels.
for _, legacy := range []string{"Image", "MaxConcurrency", "MaxUptime", "VolumeTTL", "PullPolicy", "Network", "Profiles"} {
// internal config struct.
for _, legacy := range []string{"Image", "MaxConcurrency", "MaxUptime", "VolumeTTL", "PullPolicy", "Network"} {
if _, present := document[legacy]; present {
t.Errorf("seed carries the Go-cased key %q", legacy)
}
}
for _, legacy := range []string{"Image", "Kit", "Adapter", "Tools"} {
if _, present := net[legacy]; present {
t.Errorf("profiles.net carries the Go-cased key %q", legacy)
}
// Profiles is its own resource (AgentProfileKind, applying live where the
// rest of this document is restart-required), so it never appears here at
// all, under either casing.
if _, present := document["profiles"]; present {
t.Error("seed carries profiles: it belongs to AgentProfileKind now")
}
if _, present := document["Profiles"]; present {
t.Error("seed carries Profiles: it belongs to AgentProfileKind now")
}
}
// legacyContainerDocument is a document as an earlier revision stored it: the
// Go field names encoding/json fell back to while the document was the internal
// config struct, and LegacyEnabled from the short window in which the removed
// containers.enabled switch still decoded. Every store written before the
// reshape holds a document like this one, so it has to keep working.
// config struct, LegacyEnabled from the short window in which the removed
// containers.enabled switch still decoded, and Profiles from before it moved to
// its own resource, AgentProfileKind. Every store written before either reshape
// holds a document like this one, so it has to keep working -- Profiles simply
// drops, the way LegacyEnabled already does.
const legacyContainerDocument = `{"Image":"archie-agent:test","MaxConcurrency":4,"MaxUptime":"2h0m0s","VolumeTTL":"24h0m0s","PullPolicy":"missing","Network":"bridge","LegacyEnabled":false,"Profiles":{"net":{"Image":"proxy:1","Tools":["whois"]}}}`
// TestContainerRuntimePoliciesReadsADocumentWrittenBeforeTheReshape covers the
@@ -99,7 +96,7 @@ func TestContainerRuntimePoliciesReadsADocumentWrittenBeforeTheReshape(t *testin
if err != nil {
t.Fatalf("Decode(legacy) = %v", err)
}
for _, legacy := range []string{`"Image"`, `"MaxConcurrency"`, `"LegacyEnabled"`, `"Profiles"`, `"Tools"`} {
for _, legacy := range []string{`"Image"`, `"MaxConcurrency"`, `"LegacyEnabled"`, `"Profiles"`, `"profiles"`} {
if strings.Contains(string(decoded), legacy) {
t.Fatalf("decoded document = %s, want the canonical keys without %q", decoded, legacy)
}
@@ -111,10 +108,6 @@ func TestContainerRuntimePoliciesReadsADocumentWrittenBeforeTheReshape(t *testin
VolumeTTL string `json:"volume_ttl"`
PullPolicy string `json:"pull_policy"`
Network string `json:"network"`
Profiles map[string]struct {
Image string `json:"image"`
Tools []string `json:"tools"`
} `json:"profiles"`
}
if err := json.Unmarshal(decoded, &document); err != nil {
t.Fatalf("unmarshal decoded document: %v", err)
@@ -124,23 +117,16 @@ func TestContainerRuntimePoliciesReadsADocumentWrittenBeforeTheReshape(t *testin
document.PullPolicy != "missing" || document.Network != "bridge" {
t.Errorf("document = %+v, want the legacy values preserved in the current shape", document)
}
if len(document.Profiles) != 1 || document.Profiles["net"].Image != "proxy:1" {
t.Errorf("profiles = %+v, want the legacy values preserved", document.Profiles)
}
}
// TestContainerRuntimePoliciesKeepsDisallowUnknownFields: the legacy tolerance
// renames the keys an existing store holds and nothing else, because swallowing
// an unknown key decodes as "unset" and an unset image is a broken worker. A
// misspelling is refused, at the top level and inside a profile.
// renames the keys an existing store holds and nothing else (plus dropping
// profiles/Profiles, which no longer belongs to this document at all), because
// swallowing any other unknown key decodes as "unset" and an unset image is a
// broken worker.
func TestContainerRuntimePoliciesKeepsDisallowUnknownFields(t *testing.T) {
for _, document := range []string{
`{"image":"archie-agent:test","maxconcurrency":4}`,
`{"image":"archie-agent:test","profiles":{"net":{"toolz":["whois"]}}}`,
} {
if err := containerPoliciesDefinition(t).Validate([]byte(document)); err == nil {
t.Errorf("Validate(%s) accepted a misspelled key", document)
}
if err := containerPoliciesDefinition(t).Validate([]byte(`{"image":"archie-agent:test","maxconcurrency":4}`)); err == nil {
t.Error("Validate accepted a misspelled key")
}
}
@@ -155,7 +141,7 @@ func TestContainerRuntimePoliciesLayersLegacyDocuments(t *testing.T) {
}{
{
name: "the current shape",
stored: `{"image":"archie-agent:test","max_concurrency":4,"max_uptime":"2h0m0s","volume_ttl":"24h0m0s","pull_policy":"missing","network":"bridge","profiles":{"net":{"image":"proxy:1","tools":["whois"]}}}`,
stored: `{"image":"archie-agent:test","max_concurrency":4,"max_uptime":"2h0m0s","volume_ttl":"24h0m0s","pull_policy":"missing","network":"bridge"}`,
},
{
name: "the Go-cased shape an existing store holds",
@@ -175,8 +161,11 @@ func TestContainerRuntimePoliciesLayersLegacyDocuments(t *testing.T) {
got.Containers.MaxUptime != config.Duration(2*time.Hour) || got.Containers.Network != "bridge" {
t.Fatalf("Containers = %+v, want the stored document applied", got.Containers)
}
if len(got.Containers.Profiles) != 1 || got.Containers.Profiles["net"].Image != "proxy:1" {
t.Fatalf("Profiles = %+v, want the stored profiles applied", got.Containers.Profiles)
// Profiles is AgentProfileKind's document now, not this one's; this
// resource carries none, under either casing, so it never reaches
// out.Containers.Profiles.
if len(got.Containers.Profiles) != 0 {
t.Fatalf("Profiles = %+v, want none: container-runtime-policies carries no profiles", got.Containers.Profiles)
}
})
}
+1 -1
View File
@@ -8,7 +8,7 @@ import (
// Schemas are not declared here: each Definition names its document type, and
// Definition.Descriptor derives the JSON Schema from it (internal/app/controlplane/schema.go).
func builtinDefinitions(steps workflow.StepRegistry) []Definition {
definitions := []Definition{workflowDefinition(), workflowDefinitionsDefinition(steps), personaDefinition(), scheduleDefinition()}
definitions := []Definition{workflowDefinition(), workflowDefinitionsDefinition(steps), personaDefinition(), scheduleDefinition(), agentProfileDefinition()}
definitions = append(definitions, modelDefinitions()...)
definitions = append(definitions, operationalDefinitions()...)
return definitions
+21 -17
View File
@@ -204,29 +204,33 @@ func runtimeToolConfigFrom(ctx context.Context, reader controlplanerpc.ResourceR
return config.Config{}, nil, err
}
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:
// the mapping below would otherwise merge into the file's map, so a
// profile deleted from the store would come back from the file. Both
// spellings are checked, because documents written before the document
// had its own shape carry the Go-cased key.
var keys map[string]json.RawMessage
if err := json.Unmarshal(value, &keys); err != nil {
return err
}
_, carriesProfiles := keys["profiles"]
if !carriesProfiles {
_, carriesProfiles = keys["Profiles"]
}
var policies containerRuntimePolicies
if err := json.Unmarshal(value, &policies); err != nil {
return err
}
inherited := out.Containers.Profiles
// Profiles survives this assignment untouched: containerRuntimePolicies
// carries no Profiles field at all (it is AgentProfileKind's document
// now), and settings() never sets it, so whatever the AgentProfileKind
// layering step below assigns is what's left standing regardless of
// which of the two runs first.
profiles := out.Containers.Profiles
out.Containers = policies.settings()
if !carriesProfiles {
out.Containers.Profiles = inherited
out.Containers.Profiles = profiles
return nil
}); err != nil {
return config.Config{}, nil, err
}
// AgentProfileKind is a separate resource from ContainerRuntimePoliciesKind
// (config.ContainerConfig.Profiles is json:"-") so a Kit profile applies
// without a restart: a stored value replaces the file's outright rather
// than merging into it, the same reason ModelRoleAssignmentsKind above
// reassigns out.Models wholesale instead of decoding into the existing map.
if err := layerResource(ctx, reader, versions, AgentProfileKind, func(value []byte) error {
var profiles map[string]agentProfile
if err := json.Unmarshal(value, &profiles); err != nil {
return err
}
out.Containers.Profiles = agentProfilesSettings(profiles)
return nil
}); err != nil {
return config.Config{}, nil, err
@@ -59,6 +59,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: map[string]any{"image": "archie:next", "pull_policy": "missing"},
AgentProfileKind: map[string]any{"net": map[string]any{"tools": []string{"whois"}}},
}})
got, versions, err := client.RuntimeConfig(t.Context(), base)
@@ -69,7 +70,7 @@ func TestRuntimeConfigUsesDatabaseResourcesAndPreservesBootstrapOnlySecrets(t *t
// publishes is the one it actually layered in (archie-core-pskb).
for _, kind := range []string{
ProviderSettingsKind, ModelRoleAssignmentsKind, RepositoryPoliciesKind, ChannelSettingsKind,
SchedulingPolicyKind, ToolSettingsKind, PluginSettingsKind, ContainerRuntimePoliciesKind,
SchedulingPolicyKind, ToolSettingsKind, PluginSettingsKind, ContainerRuntimePoliciesKind, AgentProfileKind,
} {
if versions[kind] != 2 {
t.Errorf("versions[%s] = %d, want the 2 the store answered with", kind, versions[kind])
@@ -551,7 +552,7 @@ func TestRuntimeResourceKindsApplyLive(t *testing.T) {
modes[definition.Kind] = definition.ApplyMode
}
for _, kind := range []string{
ProviderSettingsKind, ModelRoleAssignmentsKind, RepositoryPoliciesKind, SchedulingPolicyKind,
ProviderSettingsKind, ModelRoleAssignmentsKind, RepositoryPoliciesKind, SchedulingPolicyKind, AgentProfileKind,
} {
if modes[kind] != "live" {
t.Errorf("%s applies %q, want live: the daemon re-layers this kind on a watch", kind, modes[kind])
@@ -583,31 +584,47 @@ func TestSchedulingPolicySeedCarriesTheLabel(t *testing.T) {
}
}
// Stored container policies that carry profiles replace the file's outright;
// ones stored before profiles existed inherit the file's.
// absentReader answers every kind as not-found, so a test can exercise
// runtimeConfigFrom's leave-the-file-value-in-effect path (real ImportConfig
// never leaves a kind unseeded, but a store the migration has not reached yet
// -- or a resource kind added after this document was last stored -- does).
type absentReader struct{}
func (absentReader) Query(context.Context, string, func([]byte) error) (int64, bool, error) {
return 0, false, nil
}
// A stored AgentProfileKind value replaces the file's profiles outright; no
// stored value at all leaves the file's in effect (agent-profiles is its own
// resource, seeded from but independent of container-runtime-policies, so a
// Kit profile applies without a restart -- docs/prds/external-agent-harness.md
// "Selection").
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 stored value replaces the file's", stored: map[string]any{"net": map[string]any{"tools": []string{"whois"}}}, want: []string{"net"}},
{
// The Go-cased spelling documents written before the document had its
// own shape carry: the profile it names must still replace the file's.
name: "legacy Go-cased profiles replace the file's",
stored: map[string]any{"Image": "agent:2", "Profiles": map[string]any{"net": map[string]any{"Tools": []string{"whois"}}}},
// The Go-cased spelling documents written before agent-profiles had
// its own document shape carry, at the profile-nesting level
// (agentProfile.UnmarshalJSON): the profile it names must still
// replace the file's.
name: "a legacy Go-cased stored value replaces the file's",
stored: 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,
ContainerRuntimePoliciesKind: map[string]any{"image": "agent:2"},
AgentProfileKind: tt.stored,
}})
got, _, err := client.RuntimeConfig(t.Context(), base)
if err != nil {
@@ -622,6 +639,21 @@ func TestRuntimeConfigLayersStoredProfiles(t *testing.T) {
}
})
}
t.Run("no stored value inherits the file's", func(t *testing.T) {
got, _, err := runtimeConfigFrom(t.Context(), absentReader{}, base)
if err != nil {
t.Fatalf("runtimeConfigFrom: %v", err)
}
var names []string
for name := range got.Containers.Profiles {
names = append(names, name)
}
if want := []string{"file-only"}; !reflect.DeepEqual(names, want) {
t.Fatalf("profiles = %v, want %v", names, want)
}
})
if got := base.Containers.Profiles; len(got) != 1 {
t.Fatalf("layering mutated the file document's profiles: %v", got)
}
@@ -112,11 +112,11 @@ func TestResourceValidatorsRejectWhatEffectiveValidationRejects(t *testing.T) {
wantErr: false,
},
{
name: "container profile with an empty tool name",
kind: ContainerRuntimePoliciesKind,
value: containerRuntimePolicies{Image: "archie-agent:test", Profiles: map[string]agentProfile{
name: "agent profile with an empty tool name",
kind: AgentProfileKind,
value: map[string]agentProfile{
"net": {Tools: []string{""}},
}},
},
mutate: func(cfg *config.Config) {
cfg.Containers.Profiles = map[string]config.AgentProfile{"net": {Tools: []string{""}}}
},
+15 -2
View File
@@ -846,7 +846,11 @@ 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"`
// Profiles is excluded from the control-plane JSON document
// (container-runtime-policies): profiles are their own resource,
// AgentProfileKind, seeded from this field but validated and stored
// (and reloaded live) separately -- see internal/app/controlplane.
Profiles map[string]AgentProfile `toml:"profiles" yaml:"profiles" json:"-"`
}
// AgentProfile is a named execution environment for an agent. Secrets and
@@ -893,7 +897,16 @@ func (p AgentProfile) IsKit() bool { return len(p.Kit) > 0 }
// ValidateProfiles rejects a profile with an empty name, an empty tool
// name, or a Kit that is not pinned by digest or also names an image.
func (c ContainerConfig) ValidateProfiles() error {
for name, p := range c.Profiles {
return ValidateAgentProfiles(c.Profiles)
}
// ValidateAgentProfiles is ValidateProfiles's rule set, standalone so the
// control-plane AgentProfileKind resource (internal/app/controlplane) can
// apply the same rules to a stored value: the file document and the
// resource that replaces it must not be able to disagree about which
// profiles are valid.
func ValidateAgentProfiles(profiles map[string]AgentProfile) error {
for name, p := range profiles {
if strings.TrimSpace(name) == "" {
return fmt.Errorf("containers.profiles: a profile name must not be empty")
}