* fix: address the Greptile findings on the merged PRs Four valid review findings from PRs #892, #893, #898 and #899, which were merged without the comments being read. - Config.Clone left the new diff-cap pointers aliased (#899, mine). Clone deep-copies every reference field, including the *bool beside it, so a clone could write the cap through to the published snapshot. Both the top-level field and the identity overrides are copied, with the clone test extended to cover them. - providerOutcomeRecorder.record could report an older call as the latest (#892). The completion time is taken before the lock, so two concurrent calls can reach the lock in the opposite order to their completion and the unconditional store overwrote the newer outcome. It now keeps the newer, via a recordAt seam that makes the reordering testable. - Curator model calls bypassed the recorder (#892). curatorLLMRunner calls the runtime directly, so a daemon whose only recent model traffic was curator work reported "no calls attempted yet" while the provider was demonstrably reachable. It records at its own adapter, and sendChatTurn's "single choke point" comment is corrected to say there are two. - A provider error reached /status raw (#892), unlike channel details, so a multiline or oversized error broke the one-line-per-fact layout. Both now share one bounded formatter. Found while fixing the curator path: agentexec.NewRuntime returns nil when no provider is configured, and a nil *runtime.Runtime panics on its first method call, so a curator asking for a completion took the daemon down. It now returns an error, and records nothing -- a local misconfiguration is not a provider call. Not fixed, filed instead: the shared lastPollAt masking a stuck identity, the container max-uptime callback resurrecting teardown bookkeeping, the dashboard dropping a served-only status filter on cold load, and the route registry test's line-by-line parser. * fix(build): drop goimports from the gate's formatter set `task check` spent 136 of its 167 seconds in `task fmt`, and 134 of those 136 in one formatter: goimports alone over the tree. golangci-lint's goimports formatter calls imports.Process once per file, which builds a fresh x/tools ProcessEnv each time, so internal/imports.getFixesWithSource re-reads modindex.Read($GOMODCACHE) per file. On this machine that index is 62.7 MiB / 2,081,070 lines (an 11 GiB module cache), and modindex's in-process memo does not take effect: 3 files read 187.9 MiB back, 15 files open the payload 15 times. That is ~53 GiB of I/O and CSV parsing per run, and it is linear at ~155 ms per file (122 files -> 18.8s, 864 -> 133.8s). Pointing the index cache elsewhere drops the same command to 3.9s. The same analyzer runs under `golangci-lint run`, so a cold cache pays it again: 169s cold with goimports, 31s without -- which is what CI and archied's own PR gate see, since only `fmt` never caches locally. Removing it costs no enforcement. gofumpt and gci remain, `task lint` still reports formatter drift as an issue, and the whole-tree fmt is now 2.2s with the tree byte-identical. What is given up is goimports' convenience of adding and removing import lines, which compile errors already cover. The examples/secret-engines exclusion stays: gofumpt and gci leave those Yaegi programs alone today, but the exclusion is the stated invariant that a formatter must not rewrite the imports of files it cannot type-check, and TestFormattersExcludeInterpretedSecretEngines holds it. Its comment no longer pins the reason to the formatter that was dropped. * fix(gateway): stop /status promising and mis-reporting health it cannot see Two findings from the cloud review of #892. Title generation no longer records chat-model health. It runs detached after a first turn under its own 30s bound and its error is swallowed by the caller, but it shared the process-wide outcome recorder, so a title that merely timed out overwrote the health line with "failed" -- reporting a broken provider on the strength of a call no user was waiting for. The /status command description no longer claims "workers" and "channels". Neither can render: newStatusHealth reads the container pool and the poll loop from boot, but the only production router.Health assignment is in setupGatewayChat, which runs solely in the archie-gateway process, where neither exists; channels is nil since the Messaging Service took the front-ends. Only the broker and chat-model lines actually appear, so that is what the help text now says. The underlying split -- daemon owns the facts, Gateway owns the Router -- is filed rather than patched here: it needs either a cross-process health contract or a ratified two-section /status, not a quick wire-up.
111 lines
4.1 KiB
Go
111 lines
4.1 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// TestConfigCloneDeepCopiesReferenceFields pins that Clone returns a
|
|
// value sharing no memory with the original: mutating the clone's maps
|
|
// and slices must not touch the original. A shallow copy here would
|
|
// silently let a failed overlay decode mutate the published snapshot.
|
|
func TestConfigCloneDeepCopiesReferenceFields(t *testing.T) {
|
|
enabled := true
|
|
orig := Config{
|
|
Models: map[string]string{"builder": "m"},
|
|
ModelLimits: map[string]ModelLimits{"m": {ContextWindow: 128_000}},
|
|
Repos: []Repo{{Gate: [][]string{{"task", "check"}}, Protect: []string{"p"}}},
|
|
DiffCapLines: new(400),
|
|
Identities: []IdentityConfig{{
|
|
Models: map[string]string{"planner": "m2"},
|
|
DiffCapLines: new(50),
|
|
Repos: []Repo{{Gate: [][]string{{"go", "vet"}}}},
|
|
}},
|
|
Dispatch: Dispatch{Labels: map[string]string{"q": "archie:q"}},
|
|
Tools: ToolsConfig{
|
|
MCPServers: []MCPServer{{Headers: map[string]string{"A": "b"}, Args: []string{"x"}}},
|
|
WebFetch: WebFetchConfig{Enabled: &enabled},
|
|
},
|
|
Chat: ChatConfig{Telegram: TelegramConfig{AllowedUserIDs: []int64{1}}},
|
|
LegacyAgent: LegacyAgent{Env: []string{"HOME"}},
|
|
Extra: map[string]any{"custom": 1},
|
|
Bindings: BindingsConfig{PreviousEncryptionKeys: []SecretRef{{Engine: "env", Key: "K0"}}},
|
|
Image: ImageConfig{
|
|
Hosted: map[string]ImageHostedProvider{"openai": {Enabled: true}},
|
|
Local: map[string]ImageLocalProvider{"sdxl": {Enabled: true}},
|
|
},
|
|
Services: Services{
|
|
ServiceNameState: {Target: "127.0.0.1:9090", TargetToken: "secret"},
|
|
},
|
|
}
|
|
|
|
got := orig.Clone()
|
|
got.Models["builder"] = "changed"
|
|
got.ModelLimits["m"] = ModelLimits{ContextWindow: 1}
|
|
got.Repos[0].Gate[0][0] = "changed"
|
|
got.Repos[0].Protect[0] = "changed"
|
|
got.Identities[0].Models["planner"] = "changed"
|
|
got.Identities[0].Repos[0].Gate[0][0] = "changed"
|
|
got.Dispatch.Labels["q"] = "changed"
|
|
got.Tools.MCPServers[0].Headers["A"] = "changed"
|
|
got.Tools.MCPServers[0].Args[0] = "changed"
|
|
got.Chat.Telegram.AllowedUserIDs[0] = 99
|
|
got.LegacyAgent.Env[0] = "changed"
|
|
got.Extra["custom"] = 2
|
|
got.Bindings.PreviousEncryptionKeys[0] = SecretRef{Engine: "env", Key: "changed"}
|
|
*got.Tools.WebFetch.Enabled = false
|
|
*got.DiffCapLines = 1
|
|
*got.Identities[0].DiffCapLines = 2
|
|
got.Image.Hosted["openai"] = ImageHostedProvider{Enabled: false}
|
|
got.Image.Local["sdxl"] = ImageLocalProvider{Enabled: false}
|
|
got.Services[ServiceNameState] = ServiceConnection{Target: "changed"}
|
|
|
|
if orig.Models["builder"] != "m" {
|
|
t.Error("Models map is shared")
|
|
}
|
|
if orig.ModelLimits["m"].ContextWindow != 128_000 {
|
|
t.Error("ModelLimits map is shared")
|
|
}
|
|
if orig.Repos[0].Gate[0][0] != "task" || orig.Repos[0].Protect[0] != "p" {
|
|
t.Error("Repo nested slices are shared")
|
|
}
|
|
if orig.Identities[0].Models["planner"] != "m2" || orig.Identities[0].Repos[0].Gate[0][0] != "go" {
|
|
t.Error("Identity nested fields are shared")
|
|
}
|
|
if orig.Dispatch.Labels["q"] != "archie:q" {
|
|
t.Error("Dispatch.Labels map is shared")
|
|
}
|
|
if orig.Tools.MCPServers[0].Headers["A"] != "b" || orig.Tools.MCPServers[0].Args[0] != "x" {
|
|
t.Error("MCP server fields are shared")
|
|
}
|
|
if orig.Chat.Telegram.AllowedUserIDs[0] != 1 {
|
|
t.Error("Telegram.AllowedUserIDs is shared")
|
|
}
|
|
if orig.LegacyAgent.Env[0] != "HOME" {
|
|
t.Error("Agent.Env is shared")
|
|
}
|
|
if orig.Extra["custom"] != 1 {
|
|
t.Error("Extra map is shared")
|
|
}
|
|
if orig.Bindings.PreviousEncryptionKeys[0].Key != "K0" {
|
|
t.Error("Bindings.PreviousEncryptionKeys is shared")
|
|
}
|
|
if orig.DiffCap() != 400 {
|
|
t.Errorf("DiffCapLines pointer is shared: orig.DiffCap() = %d, want 400", orig.DiffCap())
|
|
}
|
|
if got := orig.Identities[0].DiffCapLines; got == nil || *got != 50 {
|
|
t.Errorf("Identities[0].DiffCapLines pointer is shared: got %v, want 50", got)
|
|
}
|
|
if !*orig.Tools.WebFetch.Enabled {
|
|
t.Error("WebFetch.Enabled pointer is shared")
|
|
}
|
|
if !orig.Image.Hosted["openai"].Enabled {
|
|
t.Error("Image.Hosted map is shared")
|
|
}
|
|
if !orig.Image.Local["sdxl"].Enabled {
|
|
t.Error("Image.Local map is shared")
|
|
}
|
|
if orig.Services[ServiceNameState].TargetToken != "secret" {
|
|
t.Error("Services map is shared")
|
|
}
|
|
}
|