mirror of
https://github.com/djdevin/recflare.git
synced 2026-09-08 22:51:30 -07:00
support for 202507 endpoints (#37)
* [auth][api] accept the 20250424.01 client * [2025] unstable * 20250718.0 * correct one this time * stubs * more stubs * more stubs * [lists] add worker * [ai] route stubs * [api] player photo setting * [econ] add roomEconConfig route * [infra] update worker generators * [worker] add cards/moderation/platformnotification workers * [lists] updates to some endpoints * [clubs] stub out announcement endpoint, for now * [econ] stub out season endpoints for now * [chat] apps/chat stub out party endpoint not sure the shape yet * [api] stub out statsig and lockeditems * [doc] new services * [lists] stub the bulk endpoint * [datacollection] add placeholder service until we can kill it * [api] set gifting to lvl5 * update lock * [cdn] enable cache * [match] matchmake v2 * [lists] stub some lists * [ai] stubs * [rooms] new subroom save endpoint * [econ] add bulk purchase endpoint * [discovery] update featured creator to 1 for fun * [api] add photo settings flag * [chat] fixup chat permissions (sorta) * [auth] restrictions endpoint * [rooms] contributed endpoint * [api] fix outfit endpoint * [discovery] attempt to fix store * [chat] privacy endpoints * [api] cheered images * [rooms] add xp endpoint (disbaled) * [rooms] add xp endpoint (disabled) * update images-db for cheers * [rooms] add autocomplete endpoint * [cdn/img] increase cache ttl for statics * [api] bulk route for images * [accounts] add banner image * [api] add misc missing endpoints * [discovery] remove AI tab * [platformnotifications] stub some endpoints * [lists] add some more lists * [rooms] additional endpoints * [chat] stub a few privacy endpoints * [econ] stub some endpoints * misc db fixes * [api] tweak shape for images v6 * [rooms] dont show trending RROs
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import type { HonoApp } from '@repo/hono-helpers'
|
||||
import type { SharedHonoEnv, SharedHonoVariables } from '@repo/hono-helpers/src/types'
|
||||
|
||||
export type Env = SharedHonoEnv & {
|
||||
/**
|
||||
* Shared Secrets Store binding for the HS256 JWT signing key. Resolve the value with
|
||||
* `await env.JWT_SECRET.get()`; every worker binds the same store, so tokens signed by
|
||||
* `auth` verify here.
|
||||
*/
|
||||
JWT_SECRET: SecretsStoreSecret
|
||||
/**
|
||||
* Shared `recflare` DB (schema/migrations owned by the `rooms` worker), read-only here.
|
||||
* `GET /algorithmiclists/HotList` resolves the live hot-room ranking out of it, so a
|
||||
* discovery row shows the rooms people are actually in rather than a canned id list.
|
||||
*/
|
||||
DB: D1Database
|
||||
}
|
||||
|
||||
/** Variables can be extended */
|
||||
export type Variables = SharedHonoVariables
|
||||
|
||||
export interface App extends HonoApp {
|
||||
Bindings: Env
|
||||
Variables: Variables
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
import { Hono } from 'hono'
|
||||
import { useWorkersLogger } from 'workers-tagged-logger'
|
||||
|
||||
import { getHotRooms } from '@repo/domain'
|
||||
import { withNotFound, withOnError } from '@repo/hono-helpers'
|
||||
import { validateAndGetAccountId } from '@repo/jwt'
|
||||
|
||||
import type { Context } from 'hono'
|
||||
import type { App } from './context'
|
||||
|
||||
/**
|
||||
* Resolve the account id from a Bearer token. Returns `null` when the header is missing,
|
||||
* the token is invalid, or the `sub` claim isn't an integer.
|
||||
*/
|
||||
async function authedId(c: Context<App>): Promise<number | null> {
|
||||
return validateAndGetAccountId(c.req.raw, await c.env.JWT_SECRET.get())
|
||||
}
|
||||
|
||||
/** Results.Unauthorized() equivalent — 401 with empty body. */
|
||||
function unauthorized(c: Context<App>) {
|
||||
return c.body(null, 401)
|
||||
}
|
||||
|
||||
/**
|
||||
* What the ids in a list ARE. One enum shared by the curated lists' `Type` and the
|
||||
* algorithmic lists' — a BYTE on the client, so only 0–255 round-trips.
|
||||
*
|
||||
* It is what tells the client which service to resolve the ids against, which is why the
|
||||
* algorithmic route echoes back the type it was asked for rather than asserting one of its
|
||||
* own: a row asked for `Rooms` and handed `Accounts` would look up room ids in the account
|
||||
* service and render nothing.
|
||||
*/
|
||||
const ListEntityType = {
|
||||
Accounts: 0,
|
||||
Rooms: 1,
|
||||
Inventions: 2,
|
||||
CustomAvatarItems: 3,
|
||||
PurchasableItems: 4,
|
||||
Generic: 5,
|
||||
ChipAndPort: 6,
|
||||
DiscoverySection: 7,
|
||||
DiscoverySectionSubType: 8,
|
||||
} as const
|
||||
|
||||
/** The largest value the client's byte-wide `Type` can carry back. */
|
||||
const MAX_LIST_ENTITY_TYPE = 255
|
||||
|
||||
/**
|
||||
* The canned discovery pages served by `GET /curatedlists`, keyed by the `Name` the client
|
||||
* asks for. `ItemIds` are discovery row keys (strings), `Description` is null but
|
||||
* `ImageName` must be a string, and `CreatedAt` keeps its 7-digit fractional seconds — all
|
||||
* as the client's parser expects them.
|
||||
*
|
||||
* `ListId` is ours to choose and is deliberately SMALL. The reference's ids are 64-bit
|
||||
* (`624765592684307326`), past what a JS number holds exactly, so serving them verbatim
|
||||
* meant carrying them as bigints and hand-writing the JSON to keep the digits — machinery
|
||||
* for an id nothing on this server looks up. What the id has to be is stable and unique
|
||||
* per page: the client caches a list against it, so two pages sharing one id would serve
|
||||
* each other's rows from cache, and changing a page's id would drop its cache. Renumber
|
||||
* only when the page's contents are meant to be re-fetched.
|
||||
*/
|
||||
const CURATED_LISTS = [
|
||||
{
|
||||
ListId: 1,
|
||||
CreatorAccountId: 1,
|
||||
Name: 'Discovery.PageSource.PlayExplore',
|
||||
Description: null,
|
||||
ImageName: 'DefaultRoomImage.jpg',
|
||||
Type: ListEntityType.DiscoverySection,
|
||||
ItemIds: [
|
||||
'Rooms_New_PlayHighlight_TabsTest_Explore',
|
||||
'RoomCategories_MoodPlaylists_FeelingLucky',
|
||||
'Rooms_RecentlyUpdated_TabsTest_Explore',
|
||||
'Rooms_Battle_AlgoEndpoint_PlayHighlight_TabsTest_Explore',
|
||||
'Rooms_Quests_AlgoEndpoint_PlayHighlight_TabsTest_Explore',
|
||||
'Rooms_Roleplay_AlgoEndpoint_PlayHighlight_TabsTest_Explore',
|
||||
'Rooms_Horror_AlgoEndpoint_PlayHighlight_TabsTest_Explore',
|
||||
'Rooms_Hangout_AlgoEndpoint_PlayHighlight_TabsTest_Explore',
|
||||
'Rooms_Casual_AlgoEndpoint_PlayHighlight_TabsTest_Explore',
|
||||
'Rooms_Explore_AlgoEndpoint_PlayHighlight_TabsTest_Explore',
|
||||
],
|
||||
Accessibility: 1,
|
||||
CreatedAt: '2025-04-23T18:27:03.2643786Z',
|
||||
},
|
||||
{
|
||||
ListId: 2,
|
||||
CreatorAccountId: 1,
|
||||
Name: 'Discovery.PageSource.PlayLibrary',
|
||||
Description: null,
|
||||
ImageName: 'DefaultRoomImage.jpg',
|
||||
Type: ListEntityType.DiscoverySection,
|
||||
// The library page: what you were playing, saved, favorited and made. Note the
|
||||
// second row is a `PlayHighlight` key rather than a `PlayLibrary` one — that is the
|
||||
// reference's own naming, not a typo to tidy.
|
||||
ItemIds: [
|
||||
'Rooms_ContinuePlaying_PlayLibrary',
|
||||
'Rooms_SavedForLater_PlayHighlight',
|
||||
'Rooms_Favorites_PlayLibrary',
|
||||
'Rooms_MyRooms_Play',
|
||||
],
|
||||
Accessibility: 1,
|
||||
CreatedAt: '2025-04-23T18:25:31.5308539Z',
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* The entities an algorithmic list hands back (`GET /algorithmiclists/:list`) — ROOMS, which
|
||||
* is what a Play/Explore row is built from. Nothing ranks anything here yet, so one canned
|
||||
* set answers every row: rooms 2–6, the low ids this server's own rooms occupy, so a
|
||||
* discovery row resolves to something real instead of five dead ids.
|
||||
*
|
||||
* `Id` is a STRING even though a room id is a number, and `Context` is where the reference
|
||||
* server attributes the ranking/experiment that produced the entity. Nothing produced these,
|
||||
* so it is null on every one rather than a made-up context the client would carry into
|
||||
* telemetry.
|
||||
*/
|
||||
const ALGORITHMIC_LIST_ENTITIES: Array<{ Id: string; Context: string | null }> = [
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
'5',
|
||||
'6',
|
||||
].map((Id) => ({ Id, Context: null }))
|
||||
|
||||
/**
|
||||
* The row key that serves the LIVE hot-room ranking rather than the canned entities — the
|
||||
* same feed the rooms worker's `/rooms/hot` answers, which is what a "Hot" row on a
|
||||
* discovery page is supposed to show. Matched case-insensitively, since the key reaches us
|
||||
* from a curated page's `ItemIds` and its casing is the reference's, not ours.
|
||||
*/
|
||||
const HOT_LIST_KEY = 'hotlist'
|
||||
|
||||
/** How many rooms the hot row carries. A discovery carousel shows a page, not the world. */
|
||||
const HOT_LIST_SIZE = 20
|
||||
|
||||
/**
|
||||
* The feed the hot row is drawn from: `community`, which is the hot ranking with the rooms
|
||||
* the Coach account (id 1) created dropped. Those are this server's stock/seeded rooms, and
|
||||
* a "Hot" row that is mostly Rec Center is a row about the server rather than about what
|
||||
* players are doing. The pseudo-tag is the rooms worker's own — see `getHotRooms` — so the
|
||||
* definition of "community" stays in one place.
|
||||
*/
|
||||
const HOT_LIST_FEED = 'community'
|
||||
|
||||
/**
|
||||
* The entity type an algorithmic list reports when the query names none. The client always
|
||||
* sends `?type=`, and `Rooms` is what it asks for; falling back to `Accounts` (0, the enum's
|
||||
* zero value) would have the row resolve room ids against the account service.
|
||||
*/
|
||||
const DEFAULT_ALGORITHMIC_LIST_TYPE = ListEntityType.Rooms
|
||||
|
||||
/**
|
||||
* Each page keyed by its lowercased `Name` — the only thing a request decides is which one
|
||||
* it gets. Each entry is an ARRAY of one list: the endpoint answers a collection, and the
|
||||
* client reads it as such however many entries come back.
|
||||
*/
|
||||
const CURATED_LIST_PAGES = new Map(CURATED_LISTS.map((list) => [list.Name.toLowerCase(), [list]]))
|
||||
|
||||
/**
|
||||
* What a request that names no page — or names one nothing is captured for — gets: the
|
||||
* Explore page. A 404 or an empty array renders as an empty Play page, so answering with
|
||||
* SOMETHING is the better failure, and it is also what the reference was observed doing
|
||||
* for a `name` this server has no list under.
|
||||
*/
|
||||
const DEFAULT_CURATED_LIST_PAGE = CURATED_LIST_PAGES.get('discovery.pagesource.playexplore')!
|
||||
|
||||
const app = new Hono<App>()
|
||||
.use(
|
||||
'*',
|
||||
// middleware
|
||||
(c, next) =>
|
||||
useWorkersLogger(c.env.NAME, {
|
||||
environment: c.env.ENVIRONMENT,
|
||||
release: c.env.SENTRY_RELEASE,
|
||||
})(c, next)
|
||||
)
|
||||
|
||||
.onError(withOnError())
|
||||
.notFound(withNotFound())
|
||||
|
||||
.get('/', async (c) => {
|
||||
return c.text('hello, world!')
|
||||
})
|
||||
|
||||
// Bulk curated-list lookup — the client asks for a set of lists by repeating `?id=`.
|
||||
// Nothing curates lists here yet, so this serves one canned list: `ItemIds` are strings
|
||||
// (not numbers) and `Description` may be null, but `ImageName` has to be a string — the
|
||||
// client's parser reads it straight into a string field. A 404 shows as a failed load
|
||||
// instead, so an unknown id still answers 200.
|
||||
.get('/curatedlists/bulk', async (c) => {
|
||||
return c.json([
|
||||
{
|
||||
ListId: 17859340,
|
||||
CreatorAccountId: 1,
|
||||
Name: 'My List',
|
||||
Description: null,
|
||||
ImageName: '',
|
||||
Type: ListEntityType.Rooms,
|
||||
ItemIds: ['123', '456'],
|
||||
CreatedAt: '2025-07-18T00:00:00Z',
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
// The curated lists behind a discovery page (`GET /curatedlists`). The client asks with
|
||||
// `?creatorAccountId=&type=&name=`, and `name` is the page it wants
|
||||
// (`Discovery.PageSource.PlayExplore`, `…PlayLibrary`): it picks which canned page comes
|
||||
// back, matched case-insensitively. Nothing curates lists here, so the pages are static
|
||||
// captures — the same stand-in posture as `/curatedlists/bulk` above.
|
||||
//
|
||||
// `creatorAccountId` and `type` are accepted and IGNORED, deliberately: the reference was
|
||||
// observed answering a `type=5` request with a `Type` 7 list, so filtering on them would
|
||||
// answer nothing where it answers a page. An unknown `name` falls back to Explore rather
|
||||
// than an empty array, which renders as an empty Play page.
|
||||
//
|
||||
// `ItemIds` are the discovery ROWS the page is built from (algorithm/section keys), not
|
||||
// room ids — the client resolves each one itself.
|
||||
.get('/curatedlists', async (c) => {
|
||||
const name = c.req.query('name') ?? ''
|
||||
return c.json(CURATED_LIST_PAGES.get(name.toLowerCase()) ?? DEFAULT_CURATED_LIST_PAGE)
|
||||
})
|
||||
|
||||
// One discovery ROW's contents (`GET /algorithmiclists/:list?type=1`). `:list` is the row
|
||||
// key the curated page above lists in its `ItemIds` (e.g.
|
||||
// `Rooms_Battle_AlgoEndpoint_PlayHighlight_TabsTest_Explore`), and the answer is the
|
||||
// ranked entities that fill it, which the client then resolves by id itself.
|
||||
//
|
||||
// `HotList` is ranked for real — the same feed the rooms worker's `/rooms/hot` serves.
|
||||
// Every other row still serves the canned entities, and an unknown row key gets them too
|
||||
// rather than a 404, which the client renders as a row that failed to load. `Type` is
|
||||
// echoed back from the query: it tells the client what the `Id`s ARE (rooms, players, …),
|
||||
// so answering with a type the caller didn't ask for would have it resolve the ids
|
||||
// against the wrong service.
|
||||
.get('/algorithmiclists/:list', async (c) => {
|
||||
// Echoed, but only when it fits the byte the client reads it back into — anything
|
||||
// outside 0–255 can't round-trip, so a nonsense `?type=` gets the default instead of a
|
||||
// number that would break the response on the way in.
|
||||
const type = Number.parseInt(c.req.query('type') ?? '', 10)
|
||||
const echoed = type >= 0 && type <= MAX_LIST_ENTITY_TYPE ? type : DEFAULT_ALGORITHMIC_LIST_TYPE
|
||||
|
||||
// `HotList` is real: it serves the same ranking the rooms worker's `/rooms/hot` feed
|
||||
// does — live player count first, then engagement — so the Hot row on a discovery page
|
||||
// shows the rooms people are actually in, minus the Coach account's stock rooms (see
|
||||
// HOT_LIST_FEED). Only the ids travel; the client resolves each room itself, which is
|
||||
// why this reads the ranking and throws the room blobs away.
|
||||
if (c.req.param('list').toLowerCase() === HOT_LIST_KEY) {
|
||||
const { Results } = await getHotRooms(c.env.DB, HOT_LIST_FEED, 0, HOT_LIST_SIZE)
|
||||
return c.json({
|
||||
Type: echoed,
|
||||
Entities: Results.map((room) => ({ Id: String(room.RoomId), Context: null })),
|
||||
})
|
||||
}
|
||||
|
||||
return c.json({ Type: echoed, Entities: ALGORITHMIC_LIST_ENTITIES })
|
||||
})
|
||||
|
||||
// Contextual features — the client posts the context it's in and reads back whether the
|
||||
// call was accepted. Auth-gated, and the answer is a bare `{ success, error_id, error }`
|
||||
// with no payload: the reference server acknowledges the post and carries nothing back,
|
||||
// so there is nothing here to serve statically beyond the acknowledgement itself. The
|
||||
// body is read for the log only.
|
||||
.post('/contextualfeatures', async (c) => {
|
||||
const id = await authedId(c)
|
||||
if (id === null) return unauthorized(c)
|
||||
|
||||
return c.json({ success: true, error_id: null, error: null })
|
||||
})
|
||||
|
||||
export default app
|
||||
@@ -0,0 +1,302 @@
|
||||
import { adminSecretsStore, env, SELF } from 'cloudflare:test'
|
||||
import { beforeAll, expect, it } from 'vitest'
|
||||
|
||||
import {
|
||||
PRESENCE_SCHEMA_DDL,
|
||||
ROOM_SCHEMA_DDL,
|
||||
seedRoomWithSubRooms,
|
||||
SUBROOM_SCHEMA_DDL,
|
||||
} from '@repo/domain'
|
||||
|
||||
import type { Env } from '../../context'
|
||||
|
||||
declare module 'cloudflare:test' {
|
||||
interface ProvidedEnv extends Env {}
|
||||
}
|
||||
|
||||
const ORIGIN = 'https://example.com'
|
||||
|
||||
beforeAll(async () => {
|
||||
// Seed the shared JWT signing key into the local Secrets Store so .get() resolves.
|
||||
await adminSecretsStore(env.JWT_SECRET).create('test-signing-key')
|
||||
|
||||
// The shared room schema (owned by the `rooms` worker) plus a few public rooms — the
|
||||
// HotList row ranks these. Presence is what makes a room "hot", so its table is here too.
|
||||
for (const stmt of ROOM_SCHEMA_DDL) await env.DB.prepare(stmt).run()
|
||||
for (const stmt of SUBROOM_SCHEMA_DDL) await env.DB.prepare(stmt).run()
|
||||
for (const stmt of PRESENCE_SCHEMA_DDL) await env.DB.prepare(stmt).run()
|
||||
for (const room of [
|
||||
// Account 1 is the Coach — its rooms are this server's stock ones, which the hot row
|
||||
// leaves out.
|
||||
{ RoomId: 2, Name: 'RecCenter', CreatorAccountId: 1, Accessibility: 1, IsDorm: false },
|
||||
{ RoomId: 3, Name: 'DodgeBall', CreatorAccountId: 500, Accessibility: 1, IsDorm: false },
|
||||
{ RoomId: 4, Name: 'Quietly', CreatorAccountId: 501, Accessibility: 1, IsDorm: false },
|
||||
// Non-public and a dorm: neither belongs in a discovery row.
|
||||
{ RoomId: 5, Name: 'SecretRoom', CreatorAccountId: 500, Accessibility: 0, IsDorm: false },
|
||||
{ RoomId: 6, Name: '@Dorm', CreatorAccountId: 502, Accessibility: 1, IsDorm: true },
|
||||
]) {
|
||||
await seedRoomWithSubRooms(env.DB, { ...room, SubRooms: [] } as Record<string, unknown>)
|
||||
}
|
||||
})
|
||||
|
||||
/** Put a player in a room, the way the `match` heartbeat would — this is what ranks it. */
|
||||
async function putInRoom(accountId: number, roomId: number): Promise<void> {
|
||||
const now = Math.floor(Date.now() / 1000)
|
||||
await env.DB.prepare('INSERT OR REPLACE INTO presence (data) VALUES (?1)')
|
||||
.bind(
|
||||
JSON.stringify({
|
||||
accountId,
|
||||
roomInstance: { roomInstanceId: 1000000 + roomId, roomId, subRoomId: roomId },
|
||||
expiresAt: now + 900,
|
||||
})
|
||||
)
|
||||
.run()
|
||||
}
|
||||
|
||||
// Mint a token the way the `auth` worker does, signing with the shared test key seeded
|
||||
// into the JWT_SECRET store.
|
||||
const TEST_SECRET = 'test-signing-key'
|
||||
|
||||
function b64url(input: ArrayBuffer | string): string {
|
||||
const bytes = typeof input === 'string' ? new TextEncoder().encode(input) : new Uint8Array(input)
|
||||
let binary = ''
|
||||
for (const byte of bytes) binary += String.fromCharCode(byte)
|
||||
return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
|
||||
}
|
||||
|
||||
async function bearer(sub = '42'): Promise<Record<string, string>> {
|
||||
const now = Math.floor(Date.now() / 1000)
|
||||
const signingInput = `${b64url(JSON.stringify({ alg: 'HS256', typ: 'JWT' }))}.${b64url(
|
||||
JSON.stringify({ sub, exp: now + 3600 })
|
||||
)}`
|
||||
const key = await crypto.subtle.importKey(
|
||||
'raw',
|
||||
new TextEncoder().encode(TEST_SECRET),
|
||||
{ name: 'HMAC', hash: 'SHA-256' },
|
||||
false,
|
||||
['sign']
|
||||
)
|
||||
const sig = await crypto.subtle.sign('HMAC', key, new TextEncoder().encode(signingInput))
|
||||
return { Authorization: `Bearer ${signingInput}.${b64url(sig)}` }
|
||||
}
|
||||
|
||||
it('response with hello world', async () => {
|
||||
const res = await SELF.fetch(ORIGIN)
|
||||
expect(res.status).toBe(200)
|
||||
expect(await res.text()).toMatchInlineSnapshot(`"hello, world!"`)
|
||||
})
|
||||
|
||||
it('serves the canned curated-list bulk lookup', async () => {
|
||||
const res = await SELF.fetch(`${ORIGIN}/curatedlists/bulk?id=17859340`)
|
||||
expect(res.status).toBe(200)
|
||||
expect(await res.json()).toEqual([
|
||||
{
|
||||
ListId: 17859340,
|
||||
CreatorAccountId: 1,
|
||||
Name: 'My List',
|
||||
Description: null,
|
||||
ImageName: '',
|
||||
Type: 1,
|
||||
ItemIds: ['123', '456'],
|
||||
CreatedAt: '2025-07-18T00:00:00Z',
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it('serves the canned discovery page from /curatedlists', async () => {
|
||||
const res = await SELF.fetch(
|
||||
`${ORIGIN}/curatedlists?creatorAccountId=1&type=5&name=RoomGenreTags`
|
||||
)
|
||||
expect(res.status).toBe(200)
|
||||
expect(res.headers.get('content-type')).toContain('application/json')
|
||||
|
||||
const text = await res.text()
|
||||
expect(JSON.parse(text)).toMatchObject([
|
||||
{
|
||||
ListId: 1,
|
||||
CreatorAccountId: 1,
|
||||
Name: 'Discovery.PageSource.PlayExplore',
|
||||
Description: null,
|
||||
ImageName: 'DefaultRoomImage.jpg',
|
||||
Type: 7,
|
||||
Accessibility: 1,
|
||||
CreatedAt: '2025-04-23T18:27:03.2643786Z',
|
||||
ItemIds: [
|
||||
'Rooms_New_PlayHighlight_TabsTest_Explore',
|
||||
'RoomCategories_MoodPlaylists_FeelingLucky',
|
||||
'Rooms_RecentlyUpdated_TabsTest_Explore',
|
||||
'Rooms_Battle_AlgoEndpoint_PlayHighlight_TabsTest_Explore',
|
||||
'Rooms_Quests_AlgoEndpoint_PlayHighlight_TabsTest_Explore',
|
||||
'Rooms_Roleplay_AlgoEndpoint_PlayHighlight_TabsTest_Explore',
|
||||
'Rooms_Horror_AlgoEndpoint_PlayHighlight_TabsTest_Explore',
|
||||
'Rooms_Hangout_AlgoEndpoint_PlayHighlight_TabsTest_Explore',
|
||||
'Rooms_Casual_AlgoEndpoint_PlayHighlight_TabsTest_Explore',
|
||||
'Rooms_Explore_AlgoEndpoint_PlayHighlight_TabsTest_Explore',
|
||||
],
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it('serves the PlayLibrary page when the query names it', async () => {
|
||||
const res = await SELF.fetch(
|
||||
`${ORIGIN}/curatedlists?creatorAccountId=1&type=5&name=Discovery.PageSource.PlayLibrary`
|
||||
)
|
||||
expect(res.status).toBe(200)
|
||||
|
||||
const text = await res.text()
|
||||
expect(JSON.parse(text)).toMatchObject([
|
||||
{
|
||||
ListId: 2,
|
||||
CreatorAccountId: 1,
|
||||
Name: 'Discovery.PageSource.PlayLibrary',
|
||||
Description: null,
|
||||
ImageName: 'DefaultRoomImage.jpg',
|
||||
Type: 7,
|
||||
Accessibility: 1,
|
||||
CreatedAt: '2025-04-23T18:25:31.5308539Z',
|
||||
ItemIds: [
|
||||
'Rooms_ContinuePlaying_PlayLibrary',
|
||||
'Rooms_SavedForLater_PlayHighlight',
|
||||
'Rooms_Favorites_PlayLibrary',
|
||||
'Rooms_MyRooms_Play',
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
// The name is matched case-insensitively, and `type` is not filtered on — the request
|
||||
// above asks for type 5 and gets the type 7 list, as the reference does.
|
||||
const lower = await SELF.fetch(`${ORIGIN}/curatedlists?name=discovery.pagesource.playlibrary`)
|
||||
expect(await lower.text()).toBe(text)
|
||||
})
|
||||
|
||||
it('gives each curated page a distinct, JS-safe ListId', async () => {
|
||||
// The client caches a list against its ListId, so two pages must never share one — and
|
||||
// an id past Number.MAX_SAFE_INTEGER would round on the way through JSON, which is why
|
||||
// these are small numbers of our own rather than the reference's 64-bit ones.
|
||||
const pages = ['Discovery.PageSource.PlayExplore', 'Discovery.PageSource.PlayLibrary']
|
||||
const ids: number[] = []
|
||||
for (const name of pages) {
|
||||
const [list] = (await (
|
||||
await SELF.fetch(`${ORIGIN}/curatedlists?name=${name}`)
|
||||
).json()) as Array<{ ListId: number }>
|
||||
expect(Number.isSafeInteger(list.ListId)).toBe(true)
|
||||
ids.push(list.ListId)
|
||||
}
|
||||
expect(new Set(ids).size).toBe(ids.length)
|
||||
})
|
||||
|
||||
it('falls back to the Explore page for a name it has nothing for', async () => {
|
||||
// An empty array renders as an empty Play page, so an unknown page source answers
|
||||
// SOMETHING — which is also what the reference was observed doing for RoomGenreTags.
|
||||
const explore = await (
|
||||
await SELF.fetch(`${ORIGIN}/curatedlists?name=Discovery.PageSource.PlayExplore`)
|
||||
).text()
|
||||
|
||||
for (const query of ['?type=99&name=Nope', '?creatorAccountId=1&type=5&name=RoomGenreTags', '']) {
|
||||
const res = await SELF.fetch(`${ORIGIN}/curatedlists${query}`)
|
||||
expect(res.status).toBe(200)
|
||||
expect(await res.text()).toBe(explore)
|
||||
}
|
||||
})
|
||||
|
||||
it('serves a discovery row from /algorithmiclists', async () => {
|
||||
const res = await SELF.fetch(
|
||||
`${ORIGIN}/algorithmiclists/Rooms_Battle_AlgoEndpoint_PlayHighlight_TabsTest_Explore?type=1`
|
||||
)
|
||||
expect(res.status).toBe(200)
|
||||
// `Type` is echoed from the query — it says what the ids ARE (1 = rooms), so the client
|
||||
// resolves them against the right service. Ids are STRINGS even though a room id is a
|
||||
// number, and `Context` (the ranking attribution) is null: nothing ranks anything here
|
||||
// yet, so every row serves rooms 2–6.
|
||||
expect(await res.json()).toEqual({
|
||||
Type: 1,
|
||||
Entities: [
|
||||
{ Id: '2', Context: null },
|
||||
{ Id: '3', Context: null },
|
||||
{ Id: '4', Context: null },
|
||||
{ Id: '5', Context: null },
|
||||
{ Id: '6', Context: null },
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
it('serves the live hot-room ranking for /algorithmiclists/HotList', async () => {
|
||||
// Two players in room 3, one in room 4 — live player count is what ranks the hot feed,
|
||||
// so 3 comes first. Room 2 is busiest of all and still must not appear: the Coach
|
||||
// account made it.
|
||||
await putInRoom(901, 3)
|
||||
await putInRoom(902, 3)
|
||||
await putInRoom(903, 4)
|
||||
await putInRoom(904, 2)
|
||||
await putInRoom(905, 2)
|
||||
await putInRoom(906, 2)
|
||||
|
||||
const res = await SELF.fetch(`${ORIGIN}/algorithmiclists/HotList?type=1`)
|
||||
expect(res.status).toBe(200)
|
||||
const body = (await res.json()) as {
|
||||
Type: number
|
||||
Entities: Array<{ Id: string; Context: null }>
|
||||
}
|
||||
expect(body.Type).toBe(1)
|
||||
|
||||
// Same entity shape as any other row: ids as STRINGS, `Context` null (nothing attributes
|
||||
// a ranking here). Only ids travel — the client resolves each room itself.
|
||||
const ids = body.Entities.map((e) => e.Id)
|
||||
expect(ids.slice(0, 2)).toEqual(['3', '4'])
|
||||
expect(body.Entities.every((e) => e.Context === null)).toBe(true)
|
||||
|
||||
// Room 2 has the most players in it and is still absent: it was created by account 1,
|
||||
// the Coach, whose stock rooms the hot row leaves out — a "Hot" row full of Rec Center
|
||||
// is a row about the server rather than about what players are doing.
|
||||
expect(ids).not.toContain('2')
|
||||
// The private room and the dorm are not in it either.
|
||||
expect(ids).not.toContain('5')
|
||||
expect(ids).not.toContain('6')
|
||||
|
||||
// The row key is matched case-insensitively — it reaches us from a curated page's
|
||||
// ItemIds, whose casing is the reference's.
|
||||
const lower = await SELF.fetch(`${ORIGIN}/algorithmiclists/hotlist?type=1`)
|
||||
expect(((await lower.json()) as { Entities: unknown[] }).Entities).toEqual(body.Entities)
|
||||
})
|
||||
|
||||
it('echoes the requested type and answers an unknown row', async () => {
|
||||
const other = await SELF.fetch(`${ORIGIN}/algorithmiclists/Nothing_Ranks_This_Row?type=4`)
|
||||
expect(other.status).toBe(200)
|
||||
const body = (await other.json()) as { Type: number; Entities: unknown[] }
|
||||
// An unknown row key still gets the canned entities: a 404 renders as a row that failed
|
||||
// to load rather than an empty one.
|
||||
expect(body.Type).toBe(4)
|
||||
expect(body.Entities).toHaveLength(5)
|
||||
|
||||
// No `type` at all falls back to Rooms (1), the only one the client asks for — falling
|
||||
// back to the enum's zero value would have the row resolve room ids as ACCOUNTS.
|
||||
const untyped = await SELF.fetch(`${ORIGIN}/algorithmiclists/Rooms_New_TabsTest_Explore`)
|
||||
expect(((await untyped.json()) as { Type: number }).Type).toBe(1)
|
||||
|
||||
// `Type` is a byte on the client, so a value that can't round-trip is not echoed back.
|
||||
for (const bad of ['256', '-1', 'rooms']) {
|
||||
const res = await SELF.fetch(
|
||||
`${ORIGIN}/algorithmiclists/Rooms_New_TabsTest_Explore?type=${bad}`
|
||||
)
|
||||
expect(((await res.json()) as { Type: number }).Type).toBe(1)
|
||||
}
|
||||
// 0 (Accounts) is a real member, so it IS echoed — it is not treated as "unset".
|
||||
const accounts = await SELF.fetch(`${ORIGIN}/algorithmiclists/Accounts_Row?type=0`)
|
||||
expect(((await accounts.json()) as { Type: number }).Type).toBe(0)
|
||||
})
|
||||
|
||||
it('acknowledges a contextual-features post', async () => {
|
||||
const res = await SELF.fetch(`${ORIGIN}/contextualfeatures`, {
|
||||
method: 'POST',
|
||||
headers: { ...(await bearer()), 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({}),
|
||||
})
|
||||
expect(res.status).toBe(200)
|
||||
expect(await res.json()).toEqual({ success: true, error_id: null, error: null })
|
||||
})
|
||||
|
||||
it('401s the contextual-features post without a bearer token', async () => {
|
||||
const res = await SELF.fetch(`${ORIGIN}/contextualfeatures`, { method: 'POST' })
|
||||
expect(res.status).toBe(401)
|
||||
expect(await res.text()).toBe('')
|
||||
})
|
||||
Reference in New Issue
Block a user