All checks were successful
PR build (required check) / build-frontend (pull_request) Has been skipped
PR build (required check) / validate-observability (pull_request) Has been skipped
secrets-guard / encrypted (pull_request) Successful in 6s
PR build (required check) / changes (pull_request) Successful in 9s
shell-lint / shellcheck (pull_request) Successful in 6s
PR build (required check) / build-backend (pull_request) Successful in 1m10s
PR build (required check) / gate (pull_request) Successful in 2s
THERMOGRAPH_DISCORD_BOT_MENTIONS=0 makes the gateway bot silent on guild mentions. Default on, and unset counts as on, so every env file that predates the knob behaves exactly as before. The reason is a second responder. The operator's desktop now runs a conversational agent that replies as this same bot account (discord-voice-bot, AGENTS.md) and grades through the same API we do, so with both live a single "@Thermograph Phoenix" gets answered twice — once as a card, once as a reply. Only one of us can own that surface, and the agent is the one that can also hold a conversation. Scoped to guild mentions on purpose. DMs stay here: the agent polls guild channels only, so staying silent in a DM would just drop the message. And /grade is a signed HTTP interaction that never touched this path, so it keeps answering from prod while the desktop is asleep — which is what stops this from trading an always-on surface for a sometimes-on one. Claude-Session: https://claude.ai/code/session_015Z1ebLbhUxeZ9ozpNrVTCP
124 lines
3.7 KiB
Go
124 lines
3.7 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// env builds a getenv func over a map, defaulting the two required vars so
|
|
// each test only states what it cares about.
|
|
func env(overrides map[string]string) func(string) string {
|
|
base := map[string]string{
|
|
"THERMOGRAPH_INTERNAL_TOKEN": "sekrit",
|
|
"THERMOGRAPH_API_BASE_INTERNAL": "http://web:8137",
|
|
}
|
|
for k, v := range overrides {
|
|
base[k] = v
|
|
}
|
|
return func(k string) string { return base[k] }
|
|
}
|
|
|
|
func TestRequiredVarsRefuseToStart(t *testing.T) {
|
|
for _, missing := range []string{"THERMOGRAPH_INTERNAL_TOKEN", "THERMOGRAPH_API_BASE_INTERNAL"} {
|
|
if _, err := load(env(map[string]string{missing: ""})); err == nil {
|
|
t.Errorf("expected error when %s is unset, got nil", missing)
|
|
}
|
|
}
|
|
if cfg, err := load(env(nil)); err != nil || cfg == nil {
|
|
t.Fatalf("both required vars set: unexpected error %v", err)
|
|
}
|
|
}
|
|
|
|
func TestTruthyParsing(t *testing.T) {
|
|
cases := []struct {
|
|
flag, token string
|
|
want bool
|
|
}{
|
|
// Must match the Python _TRUTHY set exactly.
|
|
{"1", "tok", true},
|
|
{"true", "tok", true},
|
|
{"TRUE", "tok", true},
|
|
{"yes", "tok", true},
|
|
{"on", "tok", true},
|
|
{" on ", "tok", true}, // whitespace tolerated, like .strip() in Python
|
|
{"0", "tok", false},
|
|
{"false", "tok", false},
|
|
{"", "tok", false},
|
|
{"enabled", "tok", false}, // not in the truthy set
|
|
// Flag alone is not enough: no token means no gateway.
|
|
{"1", "", false},
|
|
}
|
|
for _, c := range cases {
|
|
cfg, err := load(env(map[string]string{
|
|
"THERMOGRAPH_DISCORD_BOT": c.flag,
|
|
"THERMOGRAPH_DISCORD_BOT_TOKEN": c.token,
|
|
}))
|
|
if err != nil {
|
|
t.Fatalf("flag=%q token=%q: unexpected error %v", c.flag, c.token, err)
|
|
}
|
|
if cfg.DiscordEnabled != c.want {
|
|
t.Errorf("flag=%q token=%q: DiscordEnabled=%v, want %v", c.flag, c.token, cfg.DiscordEnabled, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGuildMentionsDefaultsOn(t *testing.T) {
|
|
// This knob turns existing behaviour off, so every env file that predates
|
|
// it — which is all of them — must keep answering mentions.
|
|
cases := []struct {
|
|
raw string
|
|
want bool
|
|
}{
|
|
{"", true}, // unset means the default, not "off"
|
|
{" ", true}, // whitespace is still unset
|
|
{"1", true},
|
|
{"true", true},
|
|
{"on", true},
|
|
{"0", false},
|
|
{"false", false},
|
|
{"no", false},
|
|
{"off", false},
|
|
}
|
|
for _, c := range cases {
|
|
cfg, err := load(env(map[string]string{"THERMOGRAPH_DISCORD_BOT_MENTIONS": c.raw}))
|
|
if err != nil {
|
|
t.Fatalf("raw=%q: unexpected error %v", c.raw, err)
|
|
}
|
|
if cfg.DiscordGuildMentions != c.want {
|
|
t.Errorf("raw=%q: DiscordGuildMentions=%v, want %v", c.raw, cfg.DiscordGuildMentions, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIntervalDefaultsAndFallbacks(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
warm, indexnow string
|
|
wantWarm time.Duration
|
|
wantIndexNow time.Duration
|
|
}{
|
|
{"unset uses defaults", "", "", 24 * time.Hour, 6 * time.Hour},
|
|
{"explicit values win", "12", "3", 12 * time.Hour, 3 * time.Hour},
|
|
// Malformed values degrade to the default instead of erroring, like
|
|
// the Python int(... or 24) they replace.
|
|
{"garbage falls back", "soon", "1.5", 24 * time.Hour, 6 * time.Hour},
|
|
{"non-positive falls back", "0", "-2", 24 * time.Hour, 6 * time.Hour},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
cfg, err := load(env(map[string]string{
|
|
"THERMOGRAPH_WARM_CITIES_INTERVAL_HOURS": c.warm,
|
|
"THERMOGRAPH_INDEXNOW_INTERVAL_HOURS": c.indexnow,
|
|
}))
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if cfg.WarmCitiesInterval != c.wantWarm {
|
|
t.Errorf("WarmCitiesInterval=%v, want %v", cfg.WarmCitiesInterval, c.wantWarm)
|
|
}
|
|
if cfg.IndexNowInterval != c.wantIndexNow {
|
|
t.Errorf("IndexNowInterval=%v, want %v", cfg.IndexNowInterval, c.wantIndexNow)
|
|
}
|
|
})
|
|
}
|
|
}
|