mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 20:21:09 +02:00
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>
78 lines
1.7 KiB
Go
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)
|
|
}
|
|
}
|