terminal profile at runtime + canonical custom-file paths (v2.2.3)
TERMINAL PROFILE:
- GET /api/terminal-profile returns the profile in effect + the CLI default;
POST /api/terminal-profile validates ({profile}, hex, even, 1-255 bytes),
stores it in memory and re-sends it, resetting the STK session like
/api/rescue (the shared _resend_terminal_profile helper; rescue now
delegates to it). __main__ keeps server.cli_terminal_profile.
- Phone tab: a TERMINAL PROFILE block next to STATUS and Polling with the
current hex/byte count, Send (re-send) and Configure. The Configure
dialog has a device-model preset selector, a hex field and a per-bit
form generated from a 264-entry table for TS 102 223 V18.3.0 5.2 bytes
1-33 (pySim's table as scaffold, later bytes/3GPP bits added from the
spec; beyond the table generic RFU labels). Form <-> hex sync both
ways, hex authoritative, bits preserved. Apply posts the new value.
- Presets: Xiaomi Mi A1 (project default), Quectel GSM module example.
In-memory only, no persistence.
Custom files:
- Canonical paths rooted at MF / ADF.USIM / ADF.ISIM; entries are
{path, name, kind}. The editor now uses root + parent-DF selector +
4-hex FID + alias, requires the parent DF to be defined first, rejects
duplicates, rewrites descendants when a DF's path changes and cascades
deletes after a confirmation.
- Legacy forms are normalized on load/import (3F00/... -> MF/..., relative
a153/4954 resolved against the custom DFs); unresolvable entries are
dropped and reported in the list.
- Tree injection matches by exact parent path via the new pysimFsNodePath
(same-FID DFs under different parents no longer collide);
profilerCustomNameForPath uses the same normalization.
SW cache otaman-v167; help EN/RU + docs/api.md + AGENTS updated.
Tests: 236 Python + 371 frontend.
This commit is contained in:
@@ -21,22 +21,23 @@ function extractFunc(src, name) {
|
||||
return src.slice(m.index, i + 1);
|
||||
}
|
||||
|
||||
let code = 'var pysimCustomFiles = [];\nvar pysimCustomEditIndex = null;\n';
|
||||
for (const fn of ['pysimCustomSave', 'pysimCustomSubmit', 'pysimCustomEdit', 'pysimCustomEditCancel', 'pysimCustomRemove', 'pysimCustomRender']) {
|
||||
let code = 'var pysimCustomFiles = [];\nvar pysimCustomEditIndex = null;\nvar _pysimCustomDropped = 0;\n';
|
||||
for (const fn of ['pysimCustomNormPath', 'pysimCustomKindForName', 'pysimCustomFid',
|
||||
'pysimCustomParent', 'pysimCustomRoot', 'pysimCustomValidate',
|
||||
'pysimCustomRewriteDescendants', 'pysimCustomNormalizeEntries', 'pysimCustomSave',
|
||||
'pysimCustomRenderRoots', 'pysimCustomRenderParents', 'pysimCustomRootChanged',
|
||||
'pysimCustomSubmit', 'pysimCustomEdit', 'pysimCustomEditCancel',
|
||||
'pysimCustomRemove', 'pysimCustomRender']) {
|
||||
code += extractFunc(html, fn) + '\n';
|
||||
}
|
||||
code += html.match(/const CUSTOM_ROOTS = \[[^\]]*\];/)[0].replace('const ', 'var ') + '\n';
|
||||
code += 'globalThis.esc = s => s;\nglobalThis.t = s => s;\n';
|
||||
eval(code);
|
||||
|
||||
function fakeEl(id) {
|
||||
const classes = new Set();
|
||||
return {
|
||||
id,
|
||||
value: '',
|
||||
innerHTML: '',
|
||||
textContent: '',
|
||||
attrs: {},
|
||||
focused: 0,
|
||||
id, value: '', innerHTML: '', textContent: '', attrs: {}, focused: 0,
|
||||
classList: {
|
||||
add: (...cs) => cs.forEach(c => classes.add(c)),
|
||||
remove: (...cs) => cs.forEach(c => classes.delete(c)),
|
||||
@@ -44,12 +45,15 @@ function fakeEl(id) {
|
||||
},
|
||||
setAttribute(k, v) { this.attrs[k] = v; },
|
||||
focus() { this.focused++; },
|
||||
options() { return [...this.innerHTML.matchAll(/value="([^"]+)"/g)].map(m => m[1]); },
|
||||
};
|
||||
}
|
||||
|
||||
function setup(entries) {
|
||||
const els = {
|
||||
'pysim-cf-path': fakeEl('pysim-cf-path'),
|
||||
'pysim-cf-root': fakeEl('pysim-cf-root'),
|
||||
'pysim-cf-parent': fakeEl('pysim-cf-parent'),
|
||||
'pysim-cf-fid': fakeEl('pysim-cf-fid'),
|
||||
'pysim-cf-name': fakeEl('pysim-cf-name'),
|
||||
'pysim-cf-list': fakeEl('pysim-cf-list'),
|
||||
'pysim-cf-add-btn': fakeEl('pysim-cf-add-btn'),
|
||||
@@ -64,102 +68,172 @@ function setup(entries) {
|
||||
globalThis.document = { getElementById: id => els[id] || null };
|
||||
globalThis.alertCalls = [];
|
||||
globalThis.alert = m => { globalThis.alertCalls.push(m); };
|
||||
globalThis.confirmResult = true;
|
||||
globalThis.confirm = () => globalThis.confirmResult;
|
||||
pysimCustomFiles = (entries || []).map(e => Object.assign({}, e));
|
||||
pysimCustomEditIndex = null;
|
||||
_pysimCustomDropped = 0;
|
||||
pysimCustomRenderRoots();
|
||||
pysimCustomRenderParents();
|
||||
return els;
|
||||
}
|
||||
|
||||
const entry = (fid, name, parentFid) => ({ path: (parentFid || '3F00') + '/' + fid, name, fid, parentFid: parentFid || '3F00' });
|
||||
function fill(els, root, parent, fid, name) {
|
||||
els['pysim-cf-root'].value = root;
|
||||
pysimCustomRenderParents();
|
||||
els['pysim-cf-parent'].value = parent;
|
||||
els['pysim-cf-fid'].value = fid;
|
||||
els['pysim-cf-name'].value = name;
|
||||
}
|
||||
|
||||
test('rows render Edit and Delete buttons instead of the X glyph', () => {
|
||||
const els = setup([entry('6F46', 'EF.SPN')]);
|
||||
test('helpers derive canonical roots, parents, FIDs and kinds', () => {
|
||||
assert.strictEqual(pysimCustomNormPath('3f00/7f20/6f46'), 'MF/7F20/6F46');
|
||||
assert.strictEqual(pysimCustomNormPath(' mf / a153 '), 'MF/A153');
|
||||
assert.strictEqual(pysimCustomNormPath(''), '');
|
||||
assert.strictEqual(pysimCustomRoot({ path: 'ADF.USIM/6F07' }), 'ADF.USIM');
|
||||
assert.strictEqual(pysimCustomParent({ path: 'MF/A153/4954' }), 'MF/A153');
|
||||
assert.strictEqual(pysimCustomParent({ path: 'MF/6F46' }), 'MF');
|
||||
assert.strictEqual(pysimCustomFid({ path: 'MF/A153/4954' }), '4954');
|
||||
assert.strictEqual(pysimCustomKindForName('EF.SPN'), 'ef');
|
||||
assert.strictEqual(pysimCustomKindForName('DF.GSM'), 'df');
|
||||
assert.strictEqual(pysimCustomKindForName('XX.SPN'), null);
|
||||
});
|
||||
|
||||
test('migration resolves legacy relative paths and drops the unresolvable', () => {
|
||||
const res = pysimCustomNormalizeEntries([
|
||||
{ path: '3f00/a153', name: 'DF.A1' },
|
||||
{ path: 'a153/4954', name: 'EF.SPNS', fid: '4954', parentFid: 'a153' },
|
||||
{ path: 'a153/4955', name: 'EF.SMSCS' },
|
||||
{ path: 'ffff/1111', name: 'EF.ORPHAN' }, // no such custom DF -> dropped
|
||||
{ path: 'MF/6F46', name: 'BAD.NAME' }, // invalid alias -> dropped
|
||||
], []);
|
||||
assert.deepStrictEqual(res.files, [
|
||||
{ path: 'MF/A153', name: 'DF.A1', kind: 'df' },
|
||||
{ path: 'MF/A153/4954', name: 'EF.SPNS', kind: 'ef' },
|
||||
{ path: 'MF/A153/4955', name: 'EF.SMSCS', kind: 'ef' },
|
||||
]);
|
||||
assert.strictEqual(res.dropped, 2);
|
||||
});
|
||||
|
||||
test('validation requires a defined parent DF and a valid FID/alias', () => {
|
||||
const files = [{ path: 'MF/A153', name: 'DF.A1', kind: 'df' }];
|
||||
// parent not defined
|
||||
assert.match(pysimCustomValidate('MF', 'MF/A999', '6F46', 'EF.SPN', files, null).error, /not defined/);
|
||||
// parent defined -> ok
|
||||
assert.strictEqual(pysimCustomValidate('MF', 'MF/A153', '6F46', 'EF.SPN', files, null).path, 'MF/A153/6F46');
|
||||
// bad FID
|
||||
assert.match(pysimCustomValidate('MF', 'MF', '6F4', 'EF.SPN', files, null).error, /4 hex/);
|
||||
// bad alias
|
||||
assert.match(pysimCustomValidate('MF', 'MF', '6F46', 'SPN', files, null).error, /EF\.|DF\./);
|
||||
// duplicate
|
||||
assert.match(pysimCustomValidate('MF', 'MF/A153', '6F46', 'EF.SPN',
|
||||
files.concat([{ path: 'MF/A153/6F46', name: 'EF.OTHER', kind: 'ef' }]), null).error, /already defined/);
|
||||
// editing the same entry is not a duplicate
|
||||
assert.strictEqual(pysimCustomValidate('MF', 'MF/A153', '6F46', 'EF.SPN',
|
||||
files.concat([{ path: 'MF/A153/6F46', name: 'EF.OTHER', kind: 'ef' }]), 1).error, null);
|
||||
// root must be known
|
||||
assert.match(pysimCustomValidate('MFX', 'MFX', '6F46', 'EF.SPN', files, null).error, /Root/);
|
||||
});
|
||||
|
||||
test('root and parent selectors list roots and defined DFs', () => {
|
||||
const els = setup([
|
||||
{ path: 'MF/A153', name: 'DF.A1', kind: 'df' },
|
||||
{ path: 'MF/A153/4954', name: 'EF.SPNS', kind: 'ef' },
|
||||
{ path: 'ADF.USIM/6F07', name: 'EF.IMSI', kind: 'ef' },
|
||||
]);
|
||||
assert.deepStrictEqual(els['pysim-cf-root'].options(), ['MF', 'ADF.USIM', 'ADF.ISIM']);
|
||||
const parents = els['pysim-cf-parent'].options();
|
||||
assert.ok(parents.includes('MF'));
|
||||
assert.ok(parents.includes('MF/A153'));
|
||||
assert.ok(!parents.includes('MF/A153/4954'), 'EFs are not parent options');
|
||||
// the ADF root is always a valid parent
|
||||
els['pysim-cf-root'].value = 'ADF.USIM';
|
||||
pysimCustomRootChanged();
|
||||
assert.deepStrictEqual(els['pysim-cf-parent'].options(), ['ADF.USIM']);
|
||||
});
|
||||
|
||||
test('submit adds files under the root and under a defined DF', () => {
|
||||
const els = setup([]);
|
||||
fill(els, 'MF', 'MF', '6F46', 'EF.SPN');
|
||||
pysimCustomSubmit();
|
||||
assert.deepStrictEqual(pysimCustomFiles, [{ path: 'MF/6F46', name: 'EF.SPN', kind: 'ef' }]);
|
||||
assert.strictEqual(els['pysim-cf-fid'].value, '');
|
||||
// add a DF, then a file under it
|
||||
fill(els, 'MF', 'MF', 'A153', 'DF.A1');
|
||||
pysimCustomSubmit();
|
||||
fill(els, 'MF', 'MF/A153', '4954', 'EF.SPNS');
|
||||
pysimCustomSubmit();
|
||||
assert.deepStrictEqual(pysimCustomFiles.map(c => c.path),
|
||||
['MF/6F46', 'MF/A153', 'MF/A153/4954']);
|
||||
// adding under an undefined parent is rejected
|
||||
fill(els, 'MF', 'MF', '1111', 'EF.X');
|
||||
els['pysim-cf-parent'].value = 'MF/A153';
|
||||
els['pysim-cf-fid'].value = '2222';
|
||||
els['pysim-cf-name'].value = 'BAD';
|
||||
pysimCustomSubmit();
|
||||
assert.ok(globalThis.alertCalls.length === 1);
|
||||
});
|
||||
|
||||
test('editing a DF FID rewrites its descendants', () => {
|
||||
const els = setup([
|
||||
{ path: 'MF/A153', name: 'DF.A1', kind: 'df' },
|
||||
{ path: 'MF/A153/4954', name: 'EF.SPNS', kind: 'ef' },
|
||||
{ path: 'MF/A153/4955', name: 'EF.SMSCS', kind: 'ef' },
|
||||
]);
|
||||
pysimCustomEdit(0);
|
||||
assert.strictEqual(els['pysim-cf-fid'].value, 'A153');
|
||||
els['pysim-cf-fid'].value = 'A154';
|
||||
pysimCustomSubmit();
|
||||
assert.deepStrictEqual(pysimCustomFiles.map(c => c.path),
|
||||
['MF/A154', 'MF/A154/4954', 'MF/A154/4955']);
|
||||
assert.strictEqual(pysimCustomEditIndex, null);
|
||||
});
|
||||
|
||||
test('editing an entry to another defined path is rejected', () => {
|
||||
const els = setup([
|
||||
{ path: 'MF/6F46', name: 'EF.SPN', kind: 'ef' },
|
||||
{ path: 'MF/6F44', name: 'EF.SPN2', kind: 'ef' },
|
||||
]);
|
||||
pysimCustomEdit(0);
|
||||
els['pysim-cf-fid'].value = '6F44';
|
||||
pysimCustomSubmit();
|
||||
assert.deepStrictEqual(globalThis.alertCalls, ['File already defined: MF/6F44']);
|
||||
assert.deepStrictEqual(pysimCustomFiles.map(c => c.path), ['MF/6F46', 'MF/6F44']);
|
||||
assert.strictEqual(pysimCustomEditIndex, 0);
|
||||
});
|
||||
|
||||
test('deleting a DF cascades to its children only after confirmation', () => {
|
||||
setup([
|
||||
{ path: 'MF/A153', name: 'DF.A1', kind: 'df' },
|
||||
{ path: 'MF/A153/4954', name: 'EF.SPNS', kind: 'ef' },
|
||||
{ path: 'MF/6F46', name: 'EF.SPN', kind: 'ef' },
|
||||
]);
|
||||
globalThis.confirmResult = false;
|
||||
pysimCustomRemove(0);
|
||||
assert.strictEqual(pysimCustomFiles.length, 3, 'cancelled delete must keep everything');
|
||||
globalThis.confirmResult = true;
|
||||
pysimCustomRemove(0);
|
||||
assert.deepStrictEqual(pysimCustomFiles.map(c => c.path), ['MF/6F46']);
|
||||
});
|
||||
|
||||
test('render shows the canonical path, kind and row actions', () => {
|
||||
const els = setup([
|
||||
{ path: 'MF/A153', name: 'DF.A1', kind: 'df' },
|
||||
{ path: 'MF/A153/4954', name: 'EF.SPNS', kind: 'ef' },
|
||||
]);
|
||||
pysimCustomRender();
|
||||
const out = els['pysim-cf-list'].innerHTML;
|
||||
assert.match(out, /MF\/A153/);
|
||||
assert.match(out, /MF\/A153\/4954/);
|
||||
assert.match(out, /\(DF\)/);
|
||||
assert.match(out, /pysimCustomEdit\(0\)/);
|
||||
assert.match(out, /pysimCustomRemove\(0\)/);
|
||||
assert.match(out, />Edit</);
|
||||
assert.match(out, />Delete</);
|
||||
assert.ok(!out.includes('✕'), 'old X glyph must be gone');
|
||||
assert.match(out, /pysimCustomRemove\(1\)/);
|
||||
});
|
||||
|
||||
test('edit fills the top form and switches it to Save mode', () => {
|
||||
const els = setup([entry('6F46', 'EF.SPN')]);
|
||||
pysimCustomEdit(0);
|
||||
assert.strictEqual(pysimCustomEditIndex, 0);
|
||||
assert.strictEqual(els['pysim-cf-path'].value, '3F00/6F46');
|
||||
assert.strictEqual(els['pysim-cf-name'].value, 'EF.SPN');
|
||||
assert.strictEqual(els['pysim-cf-add-btn'].textContent, 'Save');
|
||||
assert.strictEqual(els['pysim-cf-add-btn'].attrs['data-l10n'], 'Save');
|
||||
assert.ok(!els['pysim-cf-cancel-btn'].classList.contains('hidden'));
|
||||
assert.strictEqual(els['pysim-cf-path'].focused, 1);
|
||||
});
|
||||
|
||||
test('submit in edit mode updates the entry in place', () => {
|
||||
const els = setup([entry('6F46', 'EF.SPN')]);
|
||||
pysimCustomEdit(0);
|
||||
els['pysim-cf-path'].value = '3F00/7F20/6F46';
|
||||
els['pysim-cf-name'].value = 'EF.SPNX';
|
||||
pysimCustomSubmit();
|
||||
assert.strictEqual(pysimCustomFiles.length, 1);
|
||||
assert.deepStrictEqual(pysimCustomFiles[0], { path: '3F00/7F20/6F46', name: 'EF.SPNX', fid: '6F46', parentFid: '7F20' });
|
||||
assert.strictEqual(pysimCustomEditIndex, null);
|
||||
assert.strictEqual(els['pysim-cf-add-btn'].textContent, 'Add');
|
||||
assert.ok(els['pysim-cf-cancel-btn'].classList.contains('hidden'));
|
||||
});
|
||||
|
||||
test('saving an edited entry with its own path is not a duplicate', () => {
|
||||
const els = setup([entry('6F46', 'EF.SPN')]);
|
||||
pysimCustomEdit(0);
|
||||
pysimCustomSubmit();
|
||||
assert.strictEqual(pysimCustomFiles.length, 1);
|
||||
assert.deepStrictEqual(globalThis.alertCalls, []);
|
||||
});
|
||||
|
||||
test('editing to another entry path is rejected as duplicate', () => {
|
||||
const els = setup([entry('6F46', 'EF.SPN'), entry('6F44', 'EF.SPN2')]);
|
||||
pysimCustomEdit(0);
|
||||
els['pysim-cf-path'].value = '3F00/6F44';
|
||||
pysimCustomSubmit();
|
||||
assert.deepStrictEqual(globalThis.alertCalls, ['Path already exists']);
|
||||
assert.deepStrictEqual(pysimCustomFiles.map(c => c.path), ['3F00/6F46', '3F00/6F44']);
|
||||
assert.strictEqual(pysimCustomEditIndex, 0);
|
||||
});
|
||||
|
||||
test('cancel restores the Add mode and clears the inputs', () => {
|
||||
const els = setup([entry('6F46', 'EF.SPN')]);
|
||||
pysimCustomEdit(0);
|
||||
pysimCustomEditCancel();
|
||||
assert.strictEqual(pysimCustomEditIndex, null);
|
||||
assert.strictEqual(els['pysim-cf-path'].value, '');
|
||||
assert.strictEqual(els['pysim-cf-name'].value, '');
|
||||
assert.strictEqual(els['pysim-cf-add-btn'].textContent, 'Add');
|
||||
assert.strictEqual(els['pysim-cf-add-btn'].attrs['data-l10n'], 'Add');
|
||||
assert.ok(els['pysim-cf-cancel-btn'].classList.contains('hidden'));
|
||||
});
|
||||
|
||||
test('deleting the entry being edited cancels the edit', () => {
|
||||
const els = setup([entry('6F46', 'EF.SPN')]);
|
||||
pysimCustomEdit(0);
|
||||
pysimCustomRemove(0);
|
||||
assert.deepStrictEqual(pysimCustomFiles, []);
|
||||
assert.strictEqual(pysimCustomEditIndex, null);
|
||||
assert.strictEqual(els['pysim-cf-add-btn'].textContent, 'Add');
|
||||
});
|
||||
|
||||
test('deleting before the edited row shifts the edit index', () => {
|
||||
setup([entry('6F46', 'EF.SPN'), entry('6F44', 'EF.SPN2'), entry('6F42', 'EF.SPN3')]);
|
||||
pysimCustomEdit(2);
|
||||
pysimCustomRemove(0);
|
||||
assert.strictEqual(pysimCustomEditIndex, 1);
|
||||
assert.strictEqual(pysimCustomFiles[1].name, 'EF.SPN3');
|
||||
});
|
||||
|
||||
test('submit adds a new entry when not editing', () => {
|
||||
test('render flags dropped legacy entries', () => {
|
||||
const els = setup([]);
|
||||
els['pysim-cf-path'].value = '3f00/6f46';
|
||||
els['pysim-cf-name'].value = 'EF.SPN';
|
||||
pysimCustomSubmit();
|
||||
assert.deepStrictEqual(pysimCustomFiles, [{ path: '3F00/6F46', name: 'EF.SPN', fid: '6F46', parentFid: '3F00' }]);
|
||||
assert.strictEqual(els['pysim-cf-path'].value, '');
|
||||
assert.strictEqual(els['pysim-cf-name'].value, '');
|
||||
_pysimCustomDropped = 3;
|
||||
pysimCustomRender();
|
||||
assert.match(els['pysim-cf-list'].innerHTML, /3/);
|
||||
_pysimCustomDropped = 0;
|
||||
});
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
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);
|
||||
}
|
||||
|
||||
let code = 'var pysimCustomFiles = [];\n';
|
||||
for (const fn of ['pysimFsNodePath', 'pysimCustomInject', 'pysimCustomParent', 'pysimCustomFid']) {
|
||||
code += extractFunc(html, fn) + '\n';
|
||||
}
|
||||
eval(code);
|
||||
|
||||
function node(name, fid, parent, children) {
|
||||
return { name, fid, parent: parent || null, children: children || null, isDir: true };
|
||||
}
|
||||
|
||||
function tree() {
|
||||
const mf = node('MF', '3F00', null, []);
|
||||
const dfA = node('DF.A', '5F01', mf);
|
||||
const dfB = node('DF.B', '5F02', mf);
|
||||
const dfC = node('DF.C', '5F03', mf, [node('EF.X', '6F46', null)]);
|
||||
dfC.children[0].parent = dfC;
|
||||
const adf = node('ADF.USIM', '7FFF', mf);
|
||||
const efImsi = node('EF.IMSI', '6F07', adf);
|
||||
adf.children = [efImsi];
|
||||
mf.children = [dfA, dfB, dfC, adf];
|
||||
return { mf, dfA, dfB, dfC, adf, efImsi };
|
||||
}
|
||||
|
||||
test('pysimFsNodePath builds canonical paths from MF and ADF roots', () => {
|
||||
const t = tree();
|
||||
assert.strictEqual(pysimFsNodePath(t.mf), 'MF');
|
||||
assert.strictEqual(pysimFsNodePath(t.dfA), 'MF/5F01');
|
||||
assert.strictEqual(pysimFsNodePath(t.dfC.children[0]), 'MF/5F03/6F46');
|
||||
assert.strictEqual(pysimFsNodePath(t.adf), 'ADF.USIM');
|
||||
assert.strictEqual(pysimFsNodePath(t.efImsi), 'ADF.USIM/6F07');
|
||||
});
|
||||
|
||||
test('injection matches full paths, so same-FID DFs stay apart', () => {
|
||||
const t = tree();
|
||||
pysimCustomFiles = [
|
||||
{ path: 'MF/5F01/6F46', name: 'EF.ONLY-A', kind: 'ef' },
|
||||
{ path: 'MF/5F02/6F46', name: 'EF.ONLY-B', kind: 'ef' },
|
||||
{ path: 'ADF.USIM/6F07', name: 'EF.MY-IMSI', kind: 'ef' },
|
||||
];
|
||||
pysimCustomInject(t.mf);
|
||||
assert.strictEqual(t.mf.children.length, 4, 'MF-level injection adds nothing');
|
||||
pysimCustomInject(t.dfA);
|
||||
assert.strictEqual(t.dfA.children.length, 1);
|
||||
assert.strictEqual(t.dfA.children[0].name, 'EF.ONLY-A');
|
||||
assert.strictEqual(t.dfA.children[0].customPath, 'MF/5F01/6F46');
|
||||
pysimCustomInject(t.dfB);
|
||||
assert.strictEqual(t.dfB.children[0].name, 'EF.ONLY-B');
|
||||
pysimCustomInject(t.dfC);
|
||||
assert.strictEqual(t.dfC.children.length, 1, 'unrelated DF is untouched');
|
||||
pysimCustomInject(t.adf);
|
||||
assert.strictEqual(t.adf.children.length, 1);
|
||||
assert.strictEqual(t.adf.children[0].name, 'EF.MY-IMSI');
|
||||
assert.strictEqual(t.adf.children[0].customPath, 'ADF.USIM/6F07');
|
||||
});
|
||||
|
||||
test('injection renames and marks an existing model node', () => {
|
||||
const t = tree();
|
||||
pysimCustomFiles = [{ path: 'MF/5F03/6F46', name: 'EF.RENAMED', kind: 'ef' }];
|
||||
pysimCustomInject(t.dfC);
|
||||
assert.strictEqual(t.dfC.children.length, 1);
|
||||
assert.strictEqual(t.dfC.children[0].name, 'EF.RENAMED');
|
||||
assert.strictEqual(t.dfC.children[0].custom, true);
|
||||
});
|
||||
|
||||
test('injected DFs are directories and can host their own children', () => {
|
||||
const t = tree();
|
||||
pysimCustomFiles = [
|
||||
{ path: 'MF/5F10', name: 'DF.NEW', kind: 'df' },
|
||||
{ path: 'MF/5F10/6F46', name: 'EF.UNDER-NEW', kind: 'ef' },
|
||||
];
|
||||
pysimCustomInject(t.mf);
|
||||
const df = t.mf.children.find(c => c.fid === '5F10');
|
||||
assert.ok(df, 'custom DF injected into MF');
|
||||
assert.strictEqual(df.isDir, true);
|
||||
assert.strictEqual(pysimFsNodePath(df), 'MF/5F10');
|
||||
pysimCustomInject(df);
|
||||
assert.strictEqual(df.children.length, 1);
|
||||
assert.strictEqual(df.children[0].name, 'EF.UNDER-NEW');
|
||||
});
|
||||
@@ -100,6 +100,11 @@ test('file manager keeps sort/probe controls above the scrolling tree', () => {
|
||||
test('custom files form has add/save and cancel controls', () => {
|
||||
assert.match(html, /id="pysim-cf-add-btn"[^>]*data-l10n="Add"/);
|
||||
assert.match(html, /id="pysim-cf-cancel-btn"[^>]*class="hidden[^"]*"[^>]*data-l10n="Cancel"/);
|
||||
// canonical path form: root + parent DF + 4-hex FID, no free-form path
|
||||
assert.ok(html.includes('id="pysim-cf-root"'));
|
||||
assert.ok(html.includes('id="pysim-cf-parent"'));
|
||||
assert.ok(html.includes('id="pysim-cf-fid"'));
|
||||
assert.ok(!html.includes('id="pysim-cf-path"'));
|
||||
assert.ok(html.includes("event.key==='Enter')pysimCustomSubmit()"));
|
||||
assert.ok(!html.includes('pysimCustomAdd'));
|
||||
});
|
||||
|
||||
@@ -27,7 +27,8 @@ const code = extractFunc(html, 'phoneSwitchSubtab') + '\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.pysimPliRender = () => { globalThis._pli = (globalThis._pli || 0) + 1; };\n' +
|
||||
'globalThis.tpRefresh = () => { globalThis._tp = (globalThis._tp || 0) + 1; };\n';
|
||||
eval(code);
|
||||
|
||||
function makeClassList() {
|
||||
@@ -52,7 +53,7 @@ function setup() {
|
||||
getElementById: id => panels[id] || null,
|
||||
};
|
||||
globalThis._anchor = null;
|
||||
globalThis._stk = globalThis._events = globalThis._log = globalThis._poll = globalThis._pli = 0;
|
||||
globalThis._stk = globalThis._events = globalThis._log = globalThis._poll = globalThis._pli = globalThis._tp = 0;
|
||||
return { buttons, panels };
|
||||
}
|
||||
|
||||
@@ -80,4 +81,5 @@ test('Phone pill shows the phone panel and renders CAT views', () => {
|
||||
assert.strictEqual(globalThis._log, 1);
|
||||
assert.strictEqual(globalThis._poll, 1);
|
||||
assert.strictEqual(globalThis._pli, 0);
|
||||
assert.strictEqual(globalThis._tp, 1);
|
||||
});
|
||||
|
||||
@@ -21,7 +21,7 @@ function extractFunc(src, name, asyncFn) {
|
||||
return (asyncFn ? 'async ' : '') + src.slice(m.index, i + 1);
|
||||
}
|
||||
|
||||
const FNS = ['profilerNormHex', 'profilerNormHexStrict', 'profilerMatch', 'profilerMatchMin', 'profilerMaskPrefix4', 'profilerFileFields', 'profilerContentKindForFileType', 'profilerEmptyRecordContent', 'profilerValidateProfile', 'profilerCustomNameForPath', 'profilerUpdateRulePath', 'profilerResultAspects', 'profilerAspectSummary', 'profilerNumRanges', 'profilerMatchedRecordsText', 'profilerCloneName', 'profilerClone', 'profilerNewId', 'esc', 'escHtml', 'profilerRawDataCheck', 'profilerRenderReport', 'parseBerLen', 'parseTlvList', 'fcpInt', 'fcpParseTlvs', 'fcpFileDescriptor', 'fcpLifeCycle', 'fcpSfi', 'fcpDo', 'fcpDecode', 'fcpDiffHtml', 'profilerFciPreviewItems', 'profilerUpdateFciPreview', 'profilerUpdateRule', 'profilerFciInput', 'profilerScanToggleAll', 'profilerScanIgnoreAllState', 'swapNibbles', 'decIccid', 'profilerSnapshotIccid', 'profilerValidateSnapshot', 'profilerListSwitch', 'profilerScanRefreshOptions', 'profilerLiveSource', 'profilerSnapshotSource', 'profilerVisibleResults', 'profilerRulesFromSnapshot', 'profilerExtraFileResults', 'profilerScanNameKeydown', 'profilerTimingStats', 'profilerTimingAccumulator', 'profilerFormatMs', 'profilerRenderSnapshotSummary', 'profilerSnapshotCountLabel', 'pysimFsInfoHtml', 'profilerLabelText', 'profilerResultsHeaderText', 'profilerRenderResultsView', 'profilerBuildFileRuleFromSnapshot', 'profilerSnapshotPickListHtml', 'profilerScanSetTarget'];
|
||||
const FNS = ['profilerNormHex', 'profilerNormHexStrict', 'profilerMatch', 'profilerMatchMin', 'profilerMaskPrefix4', 'profilerFileFields', 'profilerContentKindForFileType', 'profilerEmptyRecordContent', 'profilerValidateProfile', 'profilerCustomNameForPath', 'pysimCustomNormPath', 'profilerUpdateRulePath', 'profilerResultAspects', 'profilerAspectSummary', 'profilerNumRanges', 'profilerMatchedRecordsText', 'profilerCloneName', 'profilerClone', 'profilerNewId', 'esc', 'escHtml', 'profilerRawDataCheck', 'profilerRenderReport', 'parseBerLen', 'parseTlvList', 'fcpInt', 'fcpParseTlvs', 'fcpFileDescriptor', 'fcpLifeCycle', 'fcpSfi', 'fcpDo', 'fcpDecode', 'fcpDiffHtml', 'profilerFciPreviewItems', 'profilerUpdateFciPreview', 'profilerUpdateRule', 'profilerFciInput', 'profilerScanToggleAll', 'profilerScanIgnoreAllState', 'swapNibbles', 'decIccid', 'profilerSnapshotIccid', 'profilerValidateSnapshot', 'profilerListSwitch', 'profilerScanRefreshOptions', 'profilerLiveSource', 'profilerSnapshotSource', 'profilerVisibleResults', 'profilerRulesFromSnapshot', 'profilerExtraFileResults', 'profilerScanNameKeydown', 'profilerTimingStats', 'profilerTimingAccumulator', 'profilerFormatMs', 'profilerRenderSnapshotSummary', 'profilerSnapshotCountLabel', 'pysimFsInfoHtml', 'profilerLabelText', 'profilerResultsHeaderText', 'profilerRenderResultsView', 'profilerBuildFileRuleFromSnapshot', 'profilerSnapshotPickListHtml', 'profilerScanSetTarget'];
|
||||
let code = '';
|
||||
for (const f of FNS) code += extractFunc(html, f) + '\n';
|
||||
code += extractFunc(html, 'profilerBuildFileRule', true) + '\n';
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
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);
|
||||
}
|
||||
|
||||
let code = '';
|
||||
for (const f of ['tpNorm', 'tpValid', 'tpGetBit', 'tpSetBit', 'tpBitLabel']) {
|
||||
code += extractFunc(html, f) + '\n';
|
||||
}
|
||||
code += html.match(/const TP_BITS = \[[\s\S]*?\n\];/)[0].replace('const ', 'var ') + '\n';
|
||||
code += html.match(/const TP_PRESETS = \[[\s\S]*?\n\];/)[0].replace('const ', 'var ') + '\n';
|
||||
eval(code);
|
||||
|
||||
test('tpNorm / tpValid normalize and validate profile hex', () => {
|
||||
assert.strictEqual(tpNorm(' ff ee 00 '), 'FFEE00');
|
||||
assert.strictEqual(tpNorm('zz'), '');
|
||||
assert.ok(tpValid('FF'));
|
||||
assert.ok(tpValid('00FF'));
|
||||
assert.ok(!tpValid(''));
|
||||
assert.ok(!tpValid('F'));
|
||||
});
|
||||
|
||||
test('tpGetBit / tpSetBit address bits MSB-first per byte', () => {
|
||||
const hex = '80' + '01'; // byte 1 b8 set, byte 2 b1 set
|
||||
assert.strictEqual(tpGetBit(hex, 0), true); // byte 1 b8
|
||||
assert.strictEqual(tpGetBit(hex, 7), false); // byte 1 b1
|
||||
assert.strictEqual(tpGetBit(hex, 8), false); // byte 2 b8
|
||||
assert.strictEqual(tpGetBit(hex, 15), true); // byte 2 b1
|
||||
assert.strictEqual(tpGetBit(hex, 16), null); // beyond the profile
|
||||
// toggling keeps the other bits untouched
|
||||
assert.strictEqual(tpSetBit('00', 0, true), '80');
|
||||
assert.strictEqual(tpSetBit('80', 0, false), '00');
|
||||
assert.strictEqual(tpSetBit('FF', 7, false), 'FE');
|
||||
// a bit beyond the current length grows the profile with zero bytes
|
||||
assert.strictEqual(tpSetBit('FF', 24, true), 'FF000080');
|
||||
});
|
||||
|
||||
test('TERMINAL PROFILE bit table matches TS 102 223 5.2 spot checks', () => {
|
||||
assert.ok(TP_BITS.length >= 264, 'expected the full byte 1..33 table');
|
||||
assert.strictEqual(TP_BITS[0], 'Profile download'); // byte 1 b8
|
||||
assert.strictEqual(TP_BITS[16], 'Proactive UICC: DISPLAY TEXT'); // byte 3 b8
|
||||
assert.strictEqual(TP_BITS[32], 'Proactive UICC: SET UP EVENT LIST'); // byte 5 b8
|
||||
assert.strictEqual(TP_BITS[42], 'Event: Data available'); // byte 6 b3
|
||||
assert.strictEqual(TP_BITS[88], 'Proactive UICC: OPEN CHANNEL'); // byte 12 b8
|
||||
assert.strictEqual(TP_BITS[260], 'Proactive UICC: PROVIDE LOCAL INFORMATION (Supported Radio Access Technologies)');
|
||||
assert.strictEqual(tpBitLabel(0), 'Profile download');
|
||||
assert.match(tpBitLabel(400), /^RFU \(byte 51 b/); // beyond the table
|
||||
});
|
||||
|
||||
test('TERMINAL PROFILE presets are valid even-length hex', () => {
|
||||
assert.ok(TP_PRESETS.length >= 2);
|
||||
assert.match(TP_PRESETS[0].name, /Xiaomi/i);
|
||||
for (const p of TP_PRESETS) {
|
||||
assert.ok(p.name && p.profile, p.name);
|
||||
assert.ok(/^[0-9A-F]+$/.test(p.profile) && p.profile.length % 2 === 0, p.name);
|
||||
assert.ok(p.profile.length <= 510, p.name);
|
||||
}
|
||||
});
|
||||
|
||||
test('Phone tab exposes the TERMINAL PROFILE block and Configure dialog', () => {
|
||||
assert.ok(html.includes('id="tp-current"'));
|
||||
assert.match(html, /id="tp-send-btn"[^>]*data-needs="card"/);
|
||||
assert.match(html, /id="tp-configure-btn"[^>]*data-needs="server"/);
|
||||
assert.ok(html.includes('id="tp-modal"'));
|
||||
assert.ok(html.includes('id="tp-preset"'));
|
||||
assert.ok(html.includes('id="tp-hex"'));
|
||||
assert.ok(html.includes('id="tp-form"'));
|
||||
assert.ok(html.includes('id="tp-apply-btn"'));
|
||||
});
|
||||
Reference in New Issue
Block a user