Refactor VPN proxy client implementation
This commit is contained in:
@@ -3,17 +3,32 @@ import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
|
||||
import { readStyleSource } from './style-source.js';
|
||||
|
||||
import {
|
||||
autoServer,
|
||||
filterServers,
|
||||
groupServers,
|
||||
parseServerPingResults,
|
||||
SERVER_RESULT_WINDOW,
|
||||
} from '../../src/web/utils/serverPicker.js';
|
||||
} from '../../.test-dist/src/web/features/servers/serverPickerModel.js';
|
||||
|
||||
const root = path.resolve(import.meta.dirname, '../..');
|
||||
const picker = fs.readFileSync(path.join(root, 'src/web/components/ServerPicker.jsx'), 'utf8');
|
||||
const overview = fs.readFileSync(path.join(root, 'src/web/components/ClientOverviewPage.jsx'), 'utf8');
|
||||
const styles = fs.readFileSync(path.join(root, 'src/web/styles.css'), 'utf8');
|
||||
const picker = fs.readFileSync(path.join(root, 'src/web/features/servers/ServerPicker.tsx'), 'utf8');
|
||||
const boundary = fs.readFileSync(path.join(root, 'src/web/features/servers/index.ts'), 'utf8');
|
||||
const overview = fs.readFileSync(path.join(root, 'src/web/components/ClientOverviewPage.tsx'), 'utf8');
|
||||
const styles = readStyleSource(root);
|
||||
|
||||
test('server picker has one public feature owner without legacy shims', () => {
|
||||
assert.equal(boundary.trim(), "export { ServerPicker } from './ServerPicker.js';");
|
||||
assert.equal(fs.existsSync(path.join(root, 'src/web/components/ServerPicker.jsx')), false);
|
||||
assert.equal(fs.existsSync(path.join(root, 'src/web/utils/serverPicker.js')), false);
|
||||
assert.match(overview, /import \{ ServerPicker \} from '\.\.\/features\/servers\/index\.js'/);
|
||||
assert.equal((overview.match(/<ServerPicker/g) || []).length, 1);
|
||||
assert.doesNotMatch(picker, /from ['"][^'"]*\/api\/|\bapi\./);
|
||||
assert.match(overview, /const selectedServerId = pendingServerId \|\| state\?\.selection\?\.desiredServerId \|\| ''/);
|
||||
assert.match(overview, /setPendingServerId\(serverId\);[\s\S]*if \(connected && serverId\) onApply\(serverId\)/);
|
||||
});
|
||||
|
||||
const fixtures = (count) => Array.from({ length: count }, (_, index) => ({
|
||||
id: `srv-${String(count - index).padStart(3, '0')}`,
|
||||
@@ -37,6 +52,27 @@ test('server picker handles 1, 30 and 300 stable-ID servers with duplicate label
|
||||
assert.equal(SERVER_RESULT_WINDOW, 60);
|
||||
});
|
||||
|
||||
test('server picker validates unknown ping payloads before publishing results', () => {
|
||||
const result = { id: 'srv-1', ok: true, latency: 12, checkedAt: '2026-08-08T12:00:00.000Z', extra: 'kept' };
|
||||
const failed = { id: 'srv-2', ok: false, latency: null, error: 'timeout', checkedAt: '2026-08-08T12:00:01.000Z', extra: 'kept' };
|
||||
assert.deepEqual(parseServerPingResults({}), []);
|
||||
assert.equal(parseServerPingResults({ results: [result] })[0], result);
|
||||
assert.equal(parseServerPingResults({ results: [failed] })[0], failed);
|
||||
for (const payload of [
|
||||
null,
|
||||
[],
|
||||
{ results: null },
|
||||
{ results: [{}] },
|
||||
{ results: [{ id: '', ok: true }] },
|
||||
{ results: [{ id: 'srv-1', ok: 'yes' }] },
|
||||
{ results: [{ id: 'srv-1', latency: -1 }] },
|
||||
{ results: [{ id: 'srv-1', checkedAt: 123 }] },
|
||||
]) {
|
||||
assert.throws(() => parseServerPingResults(payload), TypeError);
|
||||
}
|
||||
assert.match(picker, /parseServerPingResults\(await pingServers\(ids\)\)/);
|
||||
});
|
||||
|
||||
test('server picker checks health only on manual refresh and bounds the result window', () => {
|
||||
assert.doesNotMatch(overview, /pingAll|servers\.ping/);
|
||||
assert.doesNotMatch(picker, /checkVisible\(\);/);
|
||||
|
||||
Reference in New Issue
Block a user