Files
archie/internal/infrastructure/configuration/apply_test.go
T
sam cc53e5258d fix(telegram): compact tool output and drop turn caps
Render completed ToolCallEvents as Telegram-safe streaming blocks
with compact name/status and a short cleaned preview. Summarize
file contents and listings instead of dumping source or quoted
JSON. Collapse repeated legacy turn-budget failures.

Remove max_tokens turn gating and the 200000 turn_budget_chars
default so absent or commented config cannot restore an aggregate
cap. Keep per-result max_result_chars and spill.

Confine find/grep discovery to the active workspace/worktree.

Refs #604
2026-08-23 16:40:16 +00:00

84 lines
2.4 KiB
Go

package configuration
import (
"log/slog"
"os"
"path/filepath"
"testing"
"time"
"github.com/samcharles93/archie-core/internal/config"
)
func TestApplyOverlayValuesFieldLevelMerge(t *testing.T) {
cfg := config.Config{
BotUser: "a",
Budgets: config.Budgets{MaxSteps: 10},
}
overrides := map[string]any{
"budgets": map[string]any{"max_steps": float64(20)},
}
if err := ApplyOverlayValues(&cfg, overrides); err != nil {
t.Fatal(err)
}
if cfg.Budgets.MaxSteps != 20 {
t.Errorf("MaxSteps = %d, want 20", cfg.Budgets.MaxSteps)
}
// Fields the overlay omits keep their value.
if cfg.BotUser != "a" {
t.Errorf("BotUser = %q, want a (unchanged)", cfg.BotUser)
}
}
func TestLoaderApplyOverlayLayersDefaultsValidatesAndRecordsProvenance(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.toml")
if err := os.WriteFile(path, []byte("bot_user = \"widget\"\n[[repos]]\nowner = \"acme\"\nname = \"app\"\n"), 0o600); err != nil {
t.Fatal(err)
}
l := New(slog.New(slog.DiscardHandler))
doc, err := l.Resolve(path, "")
if err != nil {
t.Fatal(err)
}
applied, err := l.ApplyOverlay(doc, map[string]any{"poll_interval": "90s"})
if err != nil {
t.Fatal(err)
}
if applied.Config.PollInterval != config.Duration(90*time.Second) {
t.Errorf("PollInterval = %v, want 90s", applied.Config.PollInterval)
}
if len(applied.Provenance.Origins) != 2 {
t.Errorf("Origins = %+v, want 2 (file + runtime overlay)", applied.Provenance.Origins)
}
// An overlay that fails validation aborts; ApplyOverlay never mutates
// its input, so the base document is untouched even without a copy.
if _, err := l.ApplyOverlay(doc, map[string]any{"agent": map[string]any{"mode": "bogus"}}); err == nil {
t.Fatal("invalid overlay accepted")
}
if doc.Config.Agent.Mode != "inprocess" {
t.Errorf("base Agent.Mode = %q, want inprocess (defaulted, untouched)", doc.Config.Agent.Mode)
}
}
func TestLoaderApplyOverlayEmptyIsNoOp(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.toml")
if err := os.WriteFile(path, []byte("bot_user = \"widget\"\n[[repos]]\nowner = \"acme\"\nname = \"app\"\n"), 0o600); err != nil {
t.Fatal(err)
}
l := New(slog.New(slog.DiscardHandler))
doc, err := l.Resolve(path, "")
if err != nil {
t.Fatal(err)
}
applied, err := l.ApplyOverlay(doc, nil)
if err != nil {
t.Fatal(err)
}
if len(applied.Provenance.Origins) != 1 {
t.Errorf("Origins = %+v, want 1 (no overlay origin for an empty overlay)", applied.Provenance.Origins)
}
}