Files
stack/packages/bus/tests/p5-identity.test.mjs

25 lines
1.1 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { telemetryFixture } from './p5-telemetry-fixture.mjs';
for (const foreign of [true, false]) test(`configured usage remains undrained with ${foreign ? 'foreign' : 'matching'} proxy identity`, async t => {
t.mock.timers.enable({ apis: ['Date', 'setInterval'], now: Date.now() });
const f = await telemetryFixture(t, { foreign });
await f.start();
t.mock.timers.tick(3000);
await new Promise(setImmediate);
assert.equal(f.queueCalls(), 0);
assert.equal(f.state.queued.length, 1);
assert.equal(f.bus.broker.request(f.human(), { verb: 'usage' }).proxy.state, 'unavailable');
if (foreign) await assert.rejects(f.bus.modelPreflight({ business: 'demo', role: 'coder' }), { code: 'proxy-open' });
});
test('a later identity change still refuses launch while usage stays undrained', async t => {
const f = await telemetryFixture(t);
await f.start();
f.state.keys = [f.other];
await assert.rejects(f.bus.modelPreflight({ business: 'demo', role: 'coder' }), { code: 'proxy-open' });
assert.equal(f.queueCalls(), 0);
assert.equal(f.state.queued.length, 1);
});