cat / goq
clone

turns a linux box into a private steam streaming appliance: plug in, tap your key, play from another computer

fix/drop-hero-notarization-note
goq / portal / session-diagnostics.test.mjs
session-diagnostics.test.mjs 2.3K
1import test from 'node:test';2import assert from 'node:assert/strict';3import {4 normalizeSessionDiagnostics,5 sessionDiagnosticsPresentation,6} from './session-diagnostics.mjs';78test('normalizes bounded v2 session ownership without peer identity material', () => {9 const session = normalizeSessionDiagnostics({10 mode: 'moq_multi_viewer_v2',11 local_handle: 'viewer-0123456789abcdef',12 focus_generation: 7,13 roster_revision: 12,14 roster_age_ms: 25,15 subscription_expires_at_unix: 2_000_000_000,16 subscription_seconds_remaining: 42,17 stale_snapshot_total: 2,18 invalid_snapshot_total: 1,19 peer_id: 'must-not-cross-the-allowlist',20 });21 assert.equal(session.focusGeneration, 7);22 assert.equal(session.rosterRevision, 12);23 assert.doesNotMatch(JSON.stringify(session), /peer_id|must-not-cross/);24 assert.match(sessionDiagnosticsPresentation(session), /roster r12 age 25 ms/);25});2627test('labels legacy mode truthfully and forbids invented roster state', () => {28 const raw = {29 mode: 'legacy_exclusive_v1',30 local_handle: null,31 focus_generation: null,32 roster_revision: null,33 roster_age_ms: null,34 subscription_expires_at_unix: null,35 subscription_seconds_remaining: null,36 stale_snapshot_total: 0,37 invalid_snapshot_total: 0,38 };39 const legacy = normalizeSessionDiagnostics(raw);40 assert.match(sessionDiagnosticsPresentation(legacy), /legacy exclusive v1 ยท implicit focus/);41 assert.throws(() => normalizeSessionDiagnostics({42 ...raw,43 local_handle: 'invented-viewer',44 }), /require null local_handle/);45});4647test('rejects invalid handles, zero generations, and inexact counters', () => {48 const valid = {49 mode: 'moq_multi_viewer_v2',50 local_handle: 'viewer-one',51 focus_generation: null,52 roster_revision: 1,53 roster_age_ms: 0,54 subscription_expires_at_unix: 2_000_000_000,55 subscription_seconds_remaining: 30,56 stale_snapshot_total: 0,57 invalid_snapshot_total: 0,58 };59 assert.throws(() => normalizeSessionDiagnostics({ ...valid, local_handle: 'raw/key' }), /opaque/);60 assert.throws(() => normalizeSessionDiagnostics({ ...valid, roster_revision: 0 }), /positive/);61 assert.throws(() => normalizeSessionDiagnostics({62 ...valid,63 stale_snapshot_total: Number.MAX_SAFE_INTEGER + 1,64 }), /exact/);65});