MosswartOverlord/go-services/discord-go/classify_test.go
Erik 8d4c6ff68f feat(go-services): discord-go — Go port of discord-rare-monitor
Consumes the Python tracker's /ws/live firehose (subscribed to rare+chat),
classifies rares common/great, posts embeds + relays allegiance chat.

- classify.go: the 74-name common-rares set, extracted verbatim from the Python
  COMMON_RARES_PATTERN (not hand-transcribed). go test runs at build time; a
  server-side dump-rares vs the Python regex confirms the sets are IDENTICAL.
- poster.go: a `poster` interface with a real discordgo impl (REST sends by
  channel id; gold/blue embeds, location/time fields, icon attachment) and a
  dry-run log impl.
- ws.go: coder/websocket client to /ws/live with subscribe, ping keepalive,
  exponential-backoff reconnect; rare/chat dispatch incl. vortex-warning + the
  MONITOR_CHARACTER filter.
- SAFE BY DEFAULT: dry-run unless a token AND DRY_RUN=0 are set, so it can never
  double-post to production. Deployed via the compose override
  (discord-rare-monitor-go), running dry-run against the same live firehose.

Validated on the server: connects, subscribes, relays a real chat in dry-run;
classifier parity 74/74 vs the Python regex.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 10:06:59 +02:00

38 lines
1.1 KiB
Go

package main
import "testing"
// Every name in the common-rares set must classify as "common".
func TestClassifyCommon(t *testing.T) {
if len(commonRares) != 74 {
t.Fatalf("expected 74 common rares, got %d", len(commonRares))
}
for name := range commonRares {
if got := classify(name); got != "common" {
t.Errorf("classify(%q) = %q, want common", name, got)
}
}
}
// Names not in the set (including near-misses) must classify as "great".
func TestClassifyGreat(t *testing.T) {
greats := []string{
"Shimmering Skeleton Key",
"Star of Tukal",
"Hieroglyph of the Bludgeoner",
"Infinite Phial of Pyreal Flux",
"Foolproof Hooks",
"Staff of All Aphus",
"Count Renari's Equctioneer",
"Gelidite Long Sword",
"Pearl of Blade Baning ", // trailing space — not an exact match
"alchemist's crystal", // wrong case — not an exact match
"Alchemist's Crystals", // plural — not an exact match
"",
}
for _, name := range greats {
if got := classify(name); got != "great" {
t.Errorf("classify(%q) = %q, want great", name, got)
}
}
}