fix(configuration): make bot_user required, defaulted, and named

bot_user names the agent that chat turns and the session curator attribute memory
to. The loader requires it of a single-identity deployment, but nothing covered
the two paths between that requirement and the consumers.

local-ollama-standalone.toml set no bot_user and defined no [[identities]], so a
profile AGENTS.md lists as supported could not load at all (archie-core-cx0d).
Give the profile the field, and make the regression guard enumerate
deployments/*.toml through the production loader instead of naming two files, so
a profile added later is covered the moment it is committed. dev.toml is
excluded because it is a development overlay layered over an installed config
rather than a standalone profile, and the exclusion is itself checked so a
renamed overlay is noticed instead of silently widening the rule.

The root BotUser was validated only when no [[identities]] block was present, so
a config with exactly one identity left it empty: the curator then skipped every
session with "no agent id" while the chat turn path ran with the same empty agent
(archie-core-4slp). applyIdentityDefaults now adopts a sole identity as the root
single-identity values -- which is what those fields mean -- and leaves the root
alone when two or more identities leave no single answer. The skip reason now
names bot_user, so the remaining case reads as configuration rather than as a
data problem.

Both regressions were red-first: the enumerated profile test failed on
local-ollama-standalone.toml before the profile was fixed, and the sole-identity
test failed before applyIdentityDefaults adopted it.
This commit is contained in:
sam committed 2026-10-03 01:48:28 +10:00
1 parent 7656311252
commit d5763a4e98
6 files changed
+119 -11

No files matched your search

+5
View File
@@ -5,6 +5,11 @@
# polling disabled (standalone execution mode).
# ==============================================================================
# Standalone still needs a bot identity: it names the agent that chat turns and
# the session curator attribute memory to, and it becomes the seeded identity's
# display name when there is no [[identities]] block.
bot_user = "archie"
work_dir = "~/.local/share/archie/work"
state_dir = "~/.local/share/archie" # NATS store, task logs
# The State Store's PostgreSQL connection (required; Postgres-only epic).
@@ -328,12 +328,26 @@ func applyDispatchDefaults(cfg *config.Config) {
}
// applyIdentityDefaults derives forge-appropriate commit emails wherever the
// operator omitted one, for both deployment shapes.
// operator omitted one, for both deployment shapes, and adopts a sole
// [[identities]] entry as the root single-identity values.
//
// The root fields are not merely the legacy single-identity shape: consumers
// that are inherently single-agent read them (the session curator is built with
// cfg.BotUser), so leaving the root empty beside exactly one identity is an
// empty address rather than an unused field, and every curated session is
// skipped for want of an agent. With two or more identities there is no single
// answer, so the root is left alone for the operator to name deliberately.
func applyIdentityDefaults(cfg *config.Config) {
if len(cfg.Identities) > 0 {
for i := range cfg.Identities {
cfg.Identities[i].BotEmail = defaultBotEmail(cfg.Identities[i].Forge.Type, cfg.Identities[i].BotUser, cfg.Identities[i].BotEmail)
}
if len(cfg.Identities) == 1 && cfg.BotUser == "" {
cfg.BotUser = cfg.Identities[0].BotUser
if cfg.BotEmail == "" {
cfg.BotEmail = cfg.Identities[0].BotEmail
}
}
}
cfg.BotEmail = defaultBotEmail(cfg.Forge.Type, cfg.BotUser, cfg.BotEmail)
}
@@ -79,6 +79,60 @@ func TestApplyIdentityDefaultsDerivesEmailPerIdentity(t *testing.T) {
}
}
// TestApplyIdentityDefaultsAdoptsASoleIdentityForTheRoot pins the single-identity
// case. When one [[identities]] entry defines the deployment, the root
// single-identity fields must not be left empty: consumers that are inherently
// single-agent read the root BotUser (the session curator is built with
// cfg.BotUser), so an empty root there is not "unused", it is "no agent" and
// every session is skipped.
func TestApplyIdentityDefaultsAdoptsASoleIdentityForTheRoot(t *testing.T) {
cfg := &config.Config{Identities: []config.IdentityConfig{
{BotUser: "solo-bot", Forge: config.Forge{Type: forgeTypeGitHub}},
}}
applyIdentityDefaults(cfg)
if want := "solo-bot"; cfg.BotUser != want {
t.Errorf("root BotUser = %q, want %q adopted from the sole identity", cfg.BotUser, want)
}
if want := "solo-bot@users.noreply.github.com"; cfg.BotEmail != want {
t.Errorf("root BotEmail = %q, want %q", cfg.BotEmail, want)
}
}
// TestApplyIdentityDefaultsLeavesAnExplicitRootAlone is the other direction: a
// default must never overwrite what the operator wrote.
func TestApplyIdentityDefaultsLeavesAnExplicitRootAlone(t *testing.T) {
cfg := &config.Config{
BotUser: "explicit-root",
Identities: []config.IdentityConfig{
{BotUser: "solo-bot", Forge: config.Forge{Type: forgeTypeGitHub}},
},
}
applyIdentityDefaults(cfg)
if want := "explicit-root"; cfg.BotUser != want {
t.Errorf("root BotUser = %q, want the explicit value %q preserved", cfg.BotUser, want)
}
}
// TestApplyIdentityDefaultsDoesNotGuessBetweenIdentities records the boundary:
// with more than one identity there is no single answer for the root, so it is
// left empty for the operator to set deliberately rather than guessed at.
func TestApplyIdentityDefaultsDoesNotGuessBetweenIdentities(t *testing.T) {
cfg := &config.Config{Identities: []config.IdentityConfig{
{BotUser: "one", Forge: config.Forge{Type: forgeTypeGitHub}},
{BotUser: "two", Forge: config.Forge{Type: forgeTypeGitHub}},
}}
applyIdentityDefaults(cfg)
if cfg.BotUser != "" {
t.Errorf("root BotUser = %q, want empty: two identities leave no single answer", cfg.BotUser)
}
}
func TestApplyCaptureDefaultsFillsZeroValues(t *testing.T) {
cfg := &config.Config{}
applyCaptureDefaults(cfg)
@@ -551,15 +551,47 @@ name = "my-repo"
requireValidateError(t, err, []string{`identities[0] ("personal").forge.intake "webhook"`, "not implemented"})
}
// TestShippedProfilesValidate guards the shipped deployments against a
// validation rule that would reject a profile the repository supports:
// multi-forge-github-gitea.toml is the only profile using [[identities]], and
// single-forge-github.toml the only documented webhook-capable shape, so an
// intake rule that fails either has broken a supported assembly.
// deploymentOverlays are the files in deployments/ that are not standalone
// profiles. dev.toml layers over an installed config (`task dev` passes it as
// -config-overlay) so it legitimately carries no bot_user; every other file
// here is a template an operator copies to config.toml and expects to start.
var deploymentOverlays = map[string]bool{"dev.toml": true}
// TestShippedProfilesValidate guards every standalone profile the repository
// ships against a validation rule that would reject it. AGENTS.md lists
// deployments/ as the supported profiles, so a profile that cannot load is a
// documented deployment path that cannot start at all. The directory is
// enumerated rather than a list of filenames repeated here, so a profile added
// later is covered the moment it is committed instead of the moment someone
// remembers this test.
func TestShippedProfilesValidate(t *testing.T) {
for _, name := range []string{"single-forge-github.toml", "multi-forge-github-gitea.toml"} {
t.Run(name, func(t *testing.T) {
path := filepath.Join("..", "..", "..", "deployments", name)
paths, err := filepath.Glob(filepath.Join("..", "..", "..", "deployments", "*.toml"))
if err != nil {
t.Fatalf("glob deployment profiles: %v", err)
}
if len(paths) == 0 {
t.Fatal("no deployment profiles matched; the glob is wrong, not the profiles")
}
seen := make(map[string]bool, len(paths))
for _, path := range paths {
seen[filepath.Base(path)] = true
}
// An exclusion that no longer names a real file would silently widen the
// rule, so it is checked as well.
for name := range deploymentOverlays {
if !seen[name] {
t.Errorf("deploymentOverlays names %q, which deployments/ does not contain", name)
}
}
var checked int
for _, path := range paths {
if deploymentOverlays[filepath.Base(path)] {
continue
}
checked++
t.Run(filepath.Base(path), func(t *testing.T) {
doc, err := New(nil).File(path)
if err != nil {
t.Fatalf("load %s: %v", path, err)
@@ -569,6 +601,9 @@ func TestShippedProfilesValidate(t *testing.T) {
}
})
}
if checked == 0 {
t.Fatal("every discovered profile was excluded, so this test asserts nothing")
}
}
// requireValidateError asserts err wraps ErrInvalidInput and carries every
@@ -166,7 +166,7 @@ func (c *Curator) reviewOne(ctx context.Context, engine domainmemory.MemoryEngin
At: c.host.Clock.Now(),
Type: ActionSkipped,
Detail: sess.ID,
Reason: "no agent id: agent-user memory needs an agent and a user",
Reason: "no agent id: bot_user is unset (agent-user memory needs an agent and a user)",
}, nil
}
@@ -582,7 +582,7 @@ func TestPassSkipsASessionWithNoAgentID(t *testing.T) {
if got.Detail != "s1" {
t.Errorf("Actions[0].Detail = %q, want the session id %q", got.Detail, "s1")
}
if want := "no agent id: agent-user memory needs an agent and a user"; got.Reason != want {
if want := "no agent id: bot_user is unset (agent-user memory needs an agent and a user)"; got.Reason != want {
t.Errorf("Actions[0].Reason = %q, want %q", got.Reason, want)
}
if dirs := engineScopeDirs(t, root); len(dirs) != 0 {