Skip to content

Commit 98d82bd

Browse files
committed
chore(realtime): drop the test-only unguarded role-cache writer
Tests can express the same setup with commitRoomPermission + a read ticket, so the cache has exactly one write path and no export without a production caller.
1 parent 950d8a0 commit 98d82bd

4 files changed

Lines changed: 21 additions & 19 deletions

File tree

apps/realtime/src/handlers/file-doc.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
flushAllFileDocRooms,
4040
setupWorkspaceFileDocHandlers,
4141
} from '@/handlers/file-doc'
42-
import { recordRoomPermission } from '@/middleware/permissions'
42+
import { beginRoomPermissionRead, commitRoomPermission } from '@/middleware/permissions'
4343

4444
type Handler = (payload?: unknown) => Promise<void> | void
4545

@@ -255,7 +255,12 @@ describe('setupWorkspaceFileDocHandlers', () => {
255255
mockAuthorizeRoom.mockImplementation(async () => {
256256
// Simulate the revocation landing between this join's authorize and its commit,
257257
// exactly as the sweep would record it.
258-
recordRoomPermission('user-race', { type: ROOM_TYPES.WORKSPACE_FILE_DOC, id: 'file-1' }, null)
258+
commitRoomPermission(
259+
'user-race',
260+
{ type: ROOM_TYPES.WORKSPACE_FILE_DOC, id: 'file-1' },
261+
null,
262+
beginRoomPermissionRead()
263+
)
259264
return { allowed: true, status: 200, workspaceId: 'ws-1', workspacePermission: 'write' }
260265
})
261266

apps/realtime/src/handlers/tables.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ vi.mock('@sim/platform-authz/rooms', () => ({
2020
}))
2121

2222
import { setupTablesHandlers } from '@/handlers/tables'
23-
import { recordRoomPermission } from '@/middleware/permissions'
23+
import { beginRoomPermissionRead, commitRoomPermission } from '@/middleware/permissions'
2424

2525
const TABLE_ROOM = { type: ROOM_TYPES.TABLE, id: 'table-1' }
2626

@@ -183,7 +183,12 @@ describe('setupTablesHandlers', () => {
183183
setupTablesHandlers(socket as unknown as SetupArg, roomManager)
184184

185185
mockAuthorizeRoom.mockImplementation(async () => {
186-
recordRoomPermission('user-race', { type: ROOM_TYPES.TABLE, id: 'table-race' }, null)
186+
commitRoomPermission(
187+
'user-race',
188+
{ type: ROOM_TYPES.TABLE, id: 'table-race' },
189+
null,
190+
beginRoomPermissionRead()
191+
)
187192
return { allowed: true, status: 200, workspaceId: 'ws-1', workspacePermission: 'admin' }
188193
})
189194

apps/realtime/src/handlers/workspace-invalidation-room.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ vi.mock('@sim/platform-authz/rooms', () => ({
1919
}))
2020

2121
import { setupWorkspaceInvalidationRoom } from '@/handlers/workspace-invalidation-room'
22-
import { recordRoomPermission } from '@/middleware/permissions'
22+
import { beginRoomPermissionRead, commitRoomPermission } from '@/middleware/permissions'
2323

2424
type Payload = { workspaceId?: string }
2525

@@ -169,7 +169,12 @@ describe.each([ROOM_TYPES.WORKSPACE_FILES, ROOM_TYPES.WORKSPACE_TABLES] as const
169169
)
170170

171171
mockAuthorizeRoom.mockImplementation(async () => {
172-
recordRoomPermission('user-race', { type: roomType, id: 'ws-race' }, null)
172+
commitRoomPermission(
173+
'user-race',
174+
{ type: roomType, id: 'ws-race' },
175+
null,
176+
beginRoomPermissionRead()
177+
)
173178
return { allowed: true, status: 200, workspaceId: 'ws-race', workspacePermission: 'admin' }
174179
})
175180

apps/realtime/src/middleware/permissions.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -340,19 +340,6 @@ export function commitRoomPermission(
340340
commitRoleDecision(roleCacheKey(userId, room), permission, readSeq)
341341
}
342342

343-
/**
344-
* Records a decision as the newest word, taking its read ticket at write time.
345-
* For callers that have just observed the authoritative state with no query of
346-
* their own to order against.
347-
*/
348-
export function recordRoomPermission(
349-
userId: string,
350-
room: RoomRef,
351-
permission: PermissionType | null
352-
): void {
353-
recordRoleDecision(roleCacheKey(userId, room), permission, beginRoomPermissionRead())
354-
}
355-
356343
/**
357344
* Live permission gate for mutating socket operations. Re-validates the user's workspace
358345
* role against the database (cached per pod for {@link ROLE_REVALIDATION_TTL_MS}) so that

0 commit comments

Comments
 (0)