/* * The name a live feed takes its lease under. * * This is worth a test because the failure it prevents is silent: two feeds * sharing one name means one of them stops, and it stops looking like * "someone else holds it" — the ordinary case on every instance but one, so * nothing gets logged and nothing looks wrong. */ import test from 'node:test' import assert from 'node:assert/strict' import { liveFeedLeaseName } from '../server/service/reference/live-feed-lease.js' test('the domain is part of the name, so two tenants do not block each other', () => { /* * This is the whole reason the reference layer composes the name instead of * the adapter: an adapter is handed cfg and site, and neither carries a * domain, so a name built there would collide across tenants. */ const a = liveFeedLeaseName('domain-a', 'mes-line-a', 'mes') const b = liveFeedLeaseName('domain-b', 'mes-line-a', 'mes') assert.notEqual(a, b) assert.ok(a.includes('domain-a')) }) test('the instance is part of the name, so two twins on one source do not block each other', () => { const a = liveFeedLeaseName('d', 'mes-line-a', 'mes') const b = liveFeedLeaseName('d', 'mes-miratek', 'mes') assert.notEqual(a, b) }) test('the same feed always gets the same name, so a second instance sees it as taken', () => { assert.equal(liveFeedLeaseName('d', 'i', 's'), liveFeedLeaseName('d', 'i', 's')) }) test('the name says it is a live feed, so a lease table read tells you the kind of task', () => { assert.ok(liveFeedLeaseName('d', 'i', 's').startsWith('twin-live::')) }) test('a missing source still names the feed — an instance has one feed', () => { const named = liveFeedLeaseName('d', 'i') assert.equal(named, 'twin-live::d::i') assert.notEqual(named, liveFeedLeaseName('d', 'other')) }) test('a blank source is the same as none rather than an empty segment', () => { assert.equal(liveFeedLeaseName('d', 'i', ' '), liveFeedLeaseName('d', 'i')) }) test('a missing domain or instance is refused, not filled in', () => { /* * Composing a name from a blank would put two feeds on one row. Throwing * here surfaces it at startup; filling it in would surface it as a channel * that quietly stopped weeks later. */ assert.throws(() => liveFeedLeaseName('', 'i', 's'), /domainId/) assert.throws(() => liveFeedLeaseName(' ', 'i', 's'), /domainId/) assert.throws(() => liveFeedLeaseName('d', '', 's'), /instanceId/) assert.throws(() => liveFeedLeaseName('d', undefined as any, 's'), /instanceId/) })