18a36a8f27
BIP was only reachable through the SCP81 listener; cards that use TCP for
other purposes (an applet's OPEN CHANNEL, a push trigger without HTTP OTA)
now get a generic control surface, independent of SCP81.
Server:
- /api/bip/control starts a plain BIP session in three modes: sink
(default; a local TcpDumpServer that accepts the card's channels and only
logs conn/sink-rx/conn-close, never answering; port 0 = ephemeral, the
bound port is reported), passthru (dial the OPEN CHANNEL destination, TCP
client only) and redirect (fixed host:port).
- /api/bip/status returns {owner, bip, listener}; /api/bip/log and
/api/bip/log-clear share the BIP event log with /api/scp81/log.
- The session state is shared with the SCP81 listener and only one session
runs at a time: _bip_session_stop() stops whichever control started it
and the control responses report it as `replaced` (both directions,
SCP81 <-> BIP). State renamed _SCP81_MODE/_TARGET/_LISTENER/_LINK_EVENTS
-> _BIP_* plus _BIP_OWNER.
- TcpDumpServer logs conn-close and counts accepted connections; stop()
joins the accept thread so the port is really free on restart.
- The new control endpoints are blocked during test-script runs.
PWA:
- New Simulator pill BIP (after TR Config): mode select with notes,
Host/Port rules, Start/Stop with a "replaced" notice, status line (mode,
bound address, owner, channels), a Channels box and the shared BIP log
(reuses the SCP81 log renderer, now showing `peer`).
- The SCP81 status line marks a session owned by the BIP pill.
Help EN/RU 8.10, docs/api.md, AGENTS; CAT_TP/UDP recorded as not
implemented.
Tests: tests/test_bip.py (9) and frontend/tests/bip.test.js (6).
600 frontend / 482 Python green; version 3.6.0; sw simple-v273.
109 lines
4.3 KiB
JavaScript
109 lines
4.3 KiB
JavaScript
const { test } = require('node:test');
|
|
const assert = require('node:assert');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const html = fs.readFileSync(path.join(__dirname, '..', 'index.html'), 'utf8');
|
|
|
|
function extractFunc(src, name) {
|
|
const re = new RegExp('function\\s+' + name + '\\s*\\([^)]*\\)\\s*\\{');
|
|
const m = re.exec(src);
|
|
if (!m) throw new Error('function ' + name + ' not found');
|
|
let i = m.index + m[0].length - 1;
|
|
let depth = 0;
|
|
for (; i < src.length; i++) {
|
|
if (src[i] === '{') depth++;
|
|
else if (src[i] === '}') {
|
|
depth--;
|
|
if (depth === 0) break;
|
|
}
|
|
}
|
|
return src.slice(m.index, i + 1);
|
|
}
|
|
|
|
const code = extractFunc(html, 'phoneSwitchSubtab') + '\n' +
|
|
'globalThis.setHelpAnchor = a => { globalThis._anchor = a; };\n' +
|
|
'globalThis.stkCheckMenu = () => { globalThis._stk = (globalThis._stk || 0) + 1; };\n' +
|
|
'globalThis.pysimEventsRender = () => { globalThis._events = (globalThis._events || 0) + 1; };\n' +
|
|
'globalThis.pysimProactiveLogRender = () => { globalThis._log = (globalThis._log || 0) + 1; };\n' +
|
|
'globalThis.pysimPollStatusInit = () => { globalThis._poll = (globalThis._poll || 0) + 1; };\n' +
|
|
'globalThis.pysimPliRender = () => { globalThis._pli = (globalThis._pli || 0) + 1; };\n' +
|
|
'globalThis.tpRefresh = () => { globalThis._tp = (globalThis._tp || 0) + 1; };\n' +
|
|
'globalThis.esimFetchAll = () => { globalThis._esim = (globalThis._esim || 0) + 1; };\n' +
|
|
'globalThis.testInit = () => { globalThis._test = (globalThis._test || 0) + 1; };\n' +
|
|
'globalThis.bipEnter = () => { globalThis._bip = (globalThis._bip || 0) + 1; };\n' +
|
|
'globalThis.netStateFetch = () => { globalThis._netstate = (globalThis._netstate || 0) + 1; };\n';
|
|
eval(code);
|
|
|
|
function makeClassList() {
|
|
const set = new Set();
|
|
return {
|
|
toggle: (c, on) => { on ? set.add(c) : set.delete(c); },
|
|
has: c => set.has(c),
|
|
};
|
|
}
|
|
|
|
function setup() {
|
|
const buttons = [
|
|
{ dataset: { phoneSub: 'phone' }, classList: makeClassList() },
|
|
{ dataset: { phoneSub: 'tr' }, classList: makeClassList() },
|
|
{ dataset: { phoneSub: 'bip' }, classList: makeClassList() },
|
|
{ dataset: { phoneSub: 'esim' }, classList: makeClassList() },
|
|
{ dataset: { phoneSub: 'test' }, classList: makeClassList() },
|
|
];
|
|
const panels = {
|
|
'phone-sub-phone': { classList: makeClassList() },
|
|
'phone-sub-tr': { classList: makeClassList() },
|
|
'phone-sub-bip': { classList: makeClassList() },
|
|
'phone-sub-esim': { classList: makeClassList() },
|
|
'phone-sub-test': { classList: makeClassList() },
|
|
};
|
|
globalThis.document = {
|
|
querySelectorAll: sel => (sel === '.phone-subtab' ? buttons : []),
|
|
getElementById: id => panels[id] || null,
|
|
};
|
|
globalThis._anchor = null;
|
|
globalThis._stk = globalThis._events = globalThis._log = globalThis._poll = globalThis._pli = globalThis._tp = 0;
|
|
globalThis._esim = globalThis._netstate = 0;
|
|
globalThis._test = 0;
|
|
globalThis._bip = 0;
|
|
return { buttons, panels };
|
|
}
|
|
|
|
test('TR Config pill shows the TR panel and renders PLI data', () => {
|
|
const { buttons, panels } = setup();
|
|
phoneSwitchSubtab('tr');
|
|
assert.ok(!panels['phone-sub-tr'].classList.has('hidden'));
|
|
assert.ok(panels['phone-sub-phone'].classList.has('hidden'));
|
|
assert.ok(buttons[1].classList.has('bg-blue-600'));
|
|
assert.ok(!buttons[0].classList.has('bg-blue-600'));
|
|
assert.strictEqual(globalThis._anchor, 'pli-dict');
|
|
assert.strictEqual(globalThis._pli, 1);
|
|
assert.strictEqual(globalThis._stk, 0);
|
|
});
|
|
|
|
test('BIP pill shows the BIP panel', () => {
|
|
const { buttons, panels } = setup();
|
|
phoneSwitchSubtab('bip');
|
|
assert.ok(!panels['phone-sub-bip'].classList.has('hidden'));
|
|
assert.ok(panels['phone-sub-phone'].classList.has('hidden'));
|
|
assert.strictEqual(globalThis._anchor, 'bip');
|
|
assert.strictEqual(globalThis._bip, 1);
|
|
assert.strictEqual(globalThis._stk, 0);
|
|
});
|
|
|
|
test('Phone pill shows the phone panel and renders CAT views', () => {
|
|
const { buttons, panels } = setup();
|
|
phoneSwitchSubtab('phone');
|
|
assert.ok(!panels['phone-sub-phone'].classList.has('hidden'));
|
|
assert.ok(panels['phone-sub-tr'].classList.has('hidden'));
|
|
assert.ok(buttons[0].classList.has('bg-blue-600'));
|
|
assert.strictEqual(globalThis._anchor, 'stk-menu');
|
|
assert.strictEqual(globalThis._stk, 1);
|
|
assert.strictEqual(globalThis._events, 1);
|
|
assert.strictEqual(globalThis._log, 1);
|
|
assert.strictEqual(globalThis._poll, 1);
|
|
assert.strictEqual(globalThis._pli, 0);
|
|
assert.strictEqual(globalThis._tp, 1);
|
|
});
|