feat(web): Go W-G12 rooms, Redis session, and API keys

Add mode=room with room_key hub APIs, optional redis:// session
backend, and web_api_key_check (sha256 pepper:key) for anlian primitives.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-09-10 20:10:43 +08:00
1 parent 26955f4f36
commit 12d2c7be69
15 files changed
+541 -13

No files matched your search

+36
View File
@@ -68,6 +68,8 @@ func TestParseModeVariants(t *testing.T) {
{"broadcast", ws.ModeBroadcast},
{"广播", ws.ModeBroadcast},
{"drain", ws.ModeDrain},
{"room", ws.ModeRoom},
{"房间", ws.ModeRoom},
{"nope", ws.ModeEcho},
}
for _, c := range cases {
@@ -77,6 +79,40 @@ func TestParseModeVariants(t *testing.T) {
}
}
func TestRouteWSRoomModeWithKey(t *testing.T) {
a := app.New(nil)
out, err := ws.RouteWS(a, "/chat", map[string]any{
"mode": "room",
"room_key": "chat.room.{id}",
})
if err != nil {
t.Fatal(err)
}
spec, err := ws.RouteSpecOf(out, "/chat")
if err != nil {
t.Fatal(err)
}
if spec.Mode != ws.ModeRoom {
t.Fatalf("mode=%q want room", spec.Mode)
}
if spec.RoomKey != "chat.room.{id}" {
t.Fatalf("room_key=%q", spec.RoomKey)
}
routes := out["ws_routes"].(map[string]any)
room := routes["/chat"].(map[string]any)
if room["mode"] != "room" || room["room_key"] != "chat.room.{id}" {
t.Fatalf("bag=%v", room)
}
}
func TestRouteWSRoomRequiresKey(t *testing.T) {
a := app.New(nil)
_, err := ws.RouteWS(a, "/chat", map[string]any{"mode": "room"})
if err == nil {
t.Fatal("expected error without room_key")
}
}
func TestConnectRefusesBadURL(t *testing.T) {
out := ws.Connect("http://127.0.0.1:1", "hi", nil, 1)
if out["ok"] == true {