diff --git a/deployments/local-ollama-standalone.toml b/deployments/local-ollama-standalone.toml index 4a705c18f..533fb9982 100644 --- a/deployments/local-ollama-standalone.toml +++ b/deployments/local-ollama-standalone.toml @@ -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). diff --git a/internal/infrastructure/configuration/defaults.go b/internal/infrastructure/configuration/defaults.go index c30198a36..8eb1468b6 100644 --- a/internal/infrastructure/configuration/defaults.go +++ b/internal/infrastructure/configuration/defaults.go @@ -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) } diff --git a/internal/infrastructure/configuration/defaults_test.go b/internal/infrastructure/configuration/defaults_test.go index ed0ae4d6f..3096c7772 100644 --- a/internal/infrastructure/configuration/defaults_test.go +++ b/internal/infrastructure/configuration/defaults_test.go @@ -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) diff --git a/internal/infrastructure/configuration/validate_test.go b/internal/infrastructure/configuration/validate_test.go index e29be3bc7..739ade25a 100644 --- a/internal/infrastructure/configuration/validate_test.go +++ b/internal/infrastructure/configuration/validate_test.go @@ -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 diff --git a/internal/infrastructure/sessioncurator/sessioncurator.go b/internal/infrastructure/sessioncurator/sessioncurator.go index e2a3b0fde..379c137b6 100644 --- a/internal/infrastructure/sessioncurator/sessioncurator.go +++ b/internal/infrastructure/sessioncurator/sessioncurator.go @@ -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 } diff --git a/internal/infrastructure/sessioncurator/sessioncurator_test.go b/internal/infrastructure/sessioncurator/sessioncurator_test.go index df30604f9..7b1868ad4 100644 --- a/internal/infrastructure/sessioncurator/sessioncurator_test.go +++ b/internal/infrastructure/sessioncurator/sessioncurator_test.go @@ -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 {