managarten/services/mana-matrix-bot/internal/plugin/keyword_test.go
Till JS 819568c3df feat(infra): consolidate 21 Matrix bots into Go binary + add Go API gateway
Replace 21 separate NestJS Matrix bot processes (~2.1 GB RAM, ~4.2 GB Docker images)
with a single Go binary using plugin architecture (8.6 MB binary, ~30 MB RAM).

New services:
- services/mana-matrix-bot/ — Go Matrix bot with 21 plugins (mautrix-go, Redis sessions)
- services/mana-api-gateway-go/ — Go API gateway (rate limiting, API keys, credit billing)

Deleted:
- 21 services/matrix-*-bot/ directories
- packages/bot-services/ and packages/matrix-bot-common/
- Legacy deploy scripts and CI build jobs

Updated:
- docker-compose.macmini.yml: new Go services, legacy bots removed
- CI/CD: change detection + build jobs for Go services
- Root package.json: new dev:matrix, build:matrix, test:matrix scripts

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 21:03:00 +01:00

78 lines
1.7 KiB
Go

package plugin
import "testing"
func TestKeywordDetector_Detect(t *testing.T) {
detector := NewKeywordDetector([]KeywordCommand{
{Keywords: []string{"hilfe", "help"}, Command: "help"},
{Keywords: []string{"zeige aufgaben", "show tasks"}, Command: "list"},
{Keywords: []string{"status"}, Command: "status"},
})
tests := []struct {
input string
want string
}{
{"hilfe", "help"},
{"Hilfe", "help"},
{"HILFE", "help"},
{"hilfe bitte", "help"},
{"help", "help"},
{"zeige aufgaben", "list"},
{"show tasks", "list"},
{"status", "status"},
{"status info", "status"},
{"was ist los", ""},
{"", ""},
// Long message should be skipped
{string(make([]byte, 100)), ""},
}
for _, tt := range tests {
got := detector.Detect(tt.input)
if got != tt.want {
t.Errorf("Detect(%q) = %q, want %q", tt.input, got, tt.want)
}
}
}
func TestKeywordDetector_PartialMatch(t *testing.T) {
detector := NewKeywordDetector(
[]KeywordCommand{
{Keywords: []string{"aufgabe"}, Command: "task"},
},
WithPartialMatch(true),
)
tests := []struct {
input string
want string
}{
{"neue aufgabe erstellen", "task"},
{"aufgabe", "task"},
{"nix", ""},
}
for _, tt := range tests {
got := detector.Detect(tt.input)
if got != tt.want {
t.Errorf("Detect(%q) = %q, want %q", tt.input, got, tt.want)
}
}
}
func TestKeywordDetector_MaxLength(t *testing.T) {
detector := NewKeywordDetector(
[]KeywordCommand{
{Keywords: []string{"help"}, Command: "help"},
},
WithMaxLength(10),
)
if got := detector.Detect("help"); got != "help" {
t.Errorf("short message should match, got %q", got)
}
if got := detector.Detect("help me please now"); got != "" {
t.Errorf("long message should be skipped, got %q", got)
}
}