Files
goclaw/internal/agent/loop_history_userpredefined_test.go
Bruno ClermontandBruno Clermont d3c04ab3e5 feat(bootstrap): skip built-in USER.md for predefined agents with USER_PREDEFINED.md (#1397)
When a predefined agent has an operator-authored USER_PREDEFINED.md, the
built-in per-user USER.md template is no longer seeded or injected into the
system prompt. This gives operators full control over user-context in the
prompt and stops the per-turn name/timezone profile nag. Open agents and
predefined agents without USER_PREDEFINED.md are unaffected.

Co-authored-by: Bruno Clermont <bruno.clermont@gmail.com>
2026-07-09 03:24:15 +07:00

55 lines
1.9 KiB
Go

package agent
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/nextlevelbuilder/goclaw/internal/bootstrap"
"github.com/nextlevelbuilder/goclaw/internal/store"
)
// TestDropBuiltinUserFileIfPredefined_WithUserPredefined verifies that USER.md
// is dropped from the merged context files for predefined agents when
// USER_PREDEFINED.md is present — the operator owns the user-context prompt.
func TestDropBuiltinUserFileIfPredefined_WithUserPredefined(t *testing.T) {
files := []bootstrap.ContextFile{
{Path: bootstrap.UserFile, Content: "built-in user template"},
{Path: bootstrap.UserPredefinedFile, Content: "operator authored"},
{Path: bootstrap.SoulFile, Content: "soul"},
}
got := dropBuiltinUserFileIfPredefined(store.AgentTypePredefined, files)
for _, f := range got {
assert.NotEqual(t, bootstrap.UserFile, f.Path, "USER.md must be dropped when USER_PREDEFINED.md is present")
}
assert.Len(t, got, 2)
}
// TestDropBuiltinUserFileIfPredefined_WithoutUserPredefined verifies USER.md is
// kept for predefined agents that do NOT have USER_PREDEFINED.md.
func TestDropBuiltinUserFileIfPredefined_WithoutUserPredefined(t *testing.T) {
files := []bootstrap.ContextFile{
{Path: bootstrap.UserFile, Content: "built-in user template"},
{Path: bootstrap.SoulFile, Content: "soul"},
}
got := dropBuiltinUserFileIfPredefined(store.AgentTypePredefined, files)
assert.Equal(t, files, got)
}
// TestDropBuiltinUserFileIfPredefined_OpenAgentUntouched verifies open agents
// are never affected, even if USER_PREDEFINED.md were somehow present.
func TestDropBuiltinUserFileIfPredefined_OpenAgentUntouched(t *testing.T) {
files := []bootstrap.ContextFile{
{Path: bootstrap.UserFile, Content: "built-in user template"},
{Path: bootstrap.UserPredefinedFile, Content: "operator authored"},
}
got := dropBuiltinUserFileIfPredefined(store.AgentTypeOpen, files)
assert.Equal(t, files, got)
}