V0.7.0 shell contract (#54)
All checks were successful
CI/CD / detect-changes (push) Successful in 3s
CI/CD / test-frontend (push) Successful in 6s
CI/CD / test-sqlite (push) Successful in 2m54s
CI/CD / test-go-pg (push) Successful in 2m55s
CI/CD / build-and-deploy (push) Successful in 1m5s

This commit was merged in pull request #54.
This commit is contained in:
2026-04-01 20:19:45 +00:00
parent 1236220302
commit e916ed41ea
151 changed files with 3250 additions and 684 deletions

View File

@@ -236,3 +236,29 @@ func TestToolResultRouteBoth(t *testing.T) {
t.Error("tool.result.* should route DirBoth (filtered by WS subscriber, not routing table)")
}
}
func TestShellContractEventRoutes(t *testing.T) {
// package.changed — broadcast to all clients
if !ShouldSendToClient("package.changed") {
t.Error("package.changed should be sent to client")
}
if ShouldAcceptFromClient("package.changed") {
t.Error("package.changed should NOT be accepted from client")
}
// auth.changed — targeted to specific user
if !ShouldSendToClient("auth.changed") {
t.Error("auth.changed should be sent to client")
}
if ShouldAcceptFromClient("auth.changed") {
t.Error("auth.changed should NOT be accepted from client")
}
// notification.all_read — targeted to specific user
if !ShouldSendToClient("notification.all_read") {
t.Error("notification.all_read should be sent to client")
}
if ShouldAcceptFromClient("notification.all_read") {
t.Error("notification.all_read should NOT be accepted from client")
}
}

View File

@@ -51,8 +51,15 @@ var routeTable = map[string]Direction{
"role.fallback": DirToClient,
// Notifications
"notification.new": DirToClient, // targeted via Hub.PublishToUser, not room-based
"notification.read": DirToClient, // badge sync across tabs
"notification.new": DirToClient, // targeted via Hub.PublishToUser, not room-based
"notification.read": DirToClient, // badge sync across tabs
"notification.all_read": DirToClient, // mark-all-read badge sync
// Package lifecycle (broadcast to all clients)
"package.changed": DirToClient, // install/uninstall/enable/disable
// Auth changes (targeted to affected user)
"auth.changed": DirToClient, // role/membership change → menu refresh
// Workspace

View File

@@ -173,6 +173,12 @@ func (h *Hub) IsConnected(userID string) bool {
return false
}
// Broadcast sends an event to all connected clients via the bus.
// No TargetUserID — every WS subscriber receives it.
func (h *Hub) Broadcast(event Event) {
h.bus.Publish(event)
}
// PublishToUser sends an event to a specific user via the bus.
// All replicas receive the event; only the one with the user's connection delivers it.
func (h *Hub) PublishToUser(userID string, event Event) {