Files
Reims-Go/internal/archtest/events_test.go
NwflowerandClaude Opus 5.5 b203bde650 refactor: merge duplicated helpers and the window event contract
Events to the frontend go through App.emit, and a test keeps their names
in step with wails.ts. QEMU argument splitting, hidden console processes,
the macOS release record, the running check and a few smaller helpers
now exist once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 21:09:19 -07:00

57 lines
1.5 KiB
Go

package archtest
import (
"go/ast"
"os"
"regexp"
"strings"
"testing"
)
// TestFrontendEventsMatch keeps both ends of the window event contract in step:
// Go emits only through App.emit, and every event name used in Go is also used
// in the frontend's wails.ts, and the other way round.
func TestFrontendEventsMatch(t *testing.T) {
raw, err := os.ReadFile("../../frontend/src/wails.ts")
if err != nil {
t.Fatal(err)
}
frontend := map[string]bool{}
for _, m := range regexp.MustCompile(`'(reims:[a-z-]+)'`).FindAllStringSubmatch(string(raw), -1) {
frontend[m[1]] = true
}
if len(frontend) < 10 {
t.Fatalf("found only %d event names in wails.ts", len(frontend))
}
backend := map[string]bool{}
for _, s := range sources(t) {
if s.isTest() || !strings.HasPrefix(s.rel, "internal/") {
continue
}
ast.Inspect(s.file, func(n ast.Node) bool {
switch n := n.(type) {
case *ast.SelectorExpr:
if n.Sel.Name == "EventsEmit" && s.rel != "internal/app/events.go" {
t.Errorf("%s calls EventsEmit: use App.emit", s.rel)
}
case *ast.BasicLit:
if name := strings.Trim(n.Value, `"`); strings.HasPrefix(name, "reims:") {
backend[name] = true
}
}
return true
})
}
for name := range backend {
if !frontend[name] {
t.Errorf("event %q exists in Go but not in frontend/src/wails.ts", name)
}
}
for name := range frontend {
if !backend[name] {
t.Errorf("event %q exists in frontend/src/wails.ts but not in Go", name)
}
}
}