auth: room notice version is bounded at 4294967295 (Heimdall's one version rule)
Some checks failed
Build pull request / Build pull request (pull_request) Has been cancelled
Check PR title / lint (pull_request_target) Has been cancelled
CLA Assistant / CLAssistant (pull_request_target) Failing after 1s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Void 2026-11-07 00:31:31 +00:00
commit b9c5e3d1a5
2 changed files with 16 additions and 2 deletions

View file

@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest';
import {
MAX_NOTICE_VERSION,
ROOM_NOTICE_EVENT_TYPE,
TRAINING_NOTICE_TEXT,
parseRoomNotice,
@ -49,6 +50,16 @@ describe('training notice', () => {
expect(lineFor({ version: '007', scope: 'train' })).toBeUndefined();
});
it('bounds the version at 4294967295', () => {
expect(MAX_NOTICE_VERSION).toBe(4294967295);
expect(lineFor({ version: 4294967295, scope: 'train' })).toBe(TRAINING_NOTICE_TEXT);
expect(parseRoomNotice({ version: 4294967295, scope: 'train' })?.version).toBe(4294967295);
expect(lineFor({ version: 4294967296, scope: 'train' })).toBeUndefined();
expect(lineFor({ version: Number.MAX_SAFE_INTEGER, scope: 'train' })).toBeUndefined();
expect(lineFor({ version: 4294967295.5, scope: 'train' })).toBeUndefined();
expect(lineFor({ version: '4294967295', scope: 'train' })).toBeUndefined();
});
it('rejects an unknown or wrongly cased scope', () => {
expect(lineFor({ version: 1, scope: 'everything' })).toBeUndefined();
expect(lineFor({ version: 1, scope: 'Train' })).toBeUndefined();

View file

@ -5,9 +5,11 @@ export const TRAINING_NOTICE_TEXT =
/**
* Heimdall's ruling: a room's notice is a room state event, not a pinned message. Type below,
* state_key '', content `{version, scope}`; version a positive integer, scope exactly one of
* show, study or train. Absent or malformed in any way means no train line.
* state_key '', content `{version, scope}`; scope exactly one of show, study or train. Heimdall's
* one version rule: a positive integer, no leading zeros, no greater than 4294967295; anything
* else is malformed. Absent or malformed in any way means no train line.
*/
export const MAX_NOTICE_VERSION = 4294967295;
export const ROOM_NOTICE_EVENT_TYPE = StateEvent.GameCultNotice;
export type RoomNotice = { version: number; scope: 'show' | 'study' | 'train' };
@ -20,6 +22,7 @@ export const parseRoomNotice = (content: unknown): RoomNotice | undefined => {
typeof version === 'number' &&
Number.isSafeInteger(version) &&
version > 0 &&
version <= MAX_NOTICE_VERSION &&
(scope === 'show' || scope === 'study' || scope === 'train')
) {
return { version, scope };