Refactor VPN proxy components and update related behavior
Build and Deploy Gateway / build-and-push (push) Successful in 20s
Build and Deploy Gateway / deploy (push) Successful in 13s

This commit is contained in:
2026-08-11 01:27:46 +03:00
parent c89e56942a
commit aa9c959368
58 changed files with 4234 additions and 2755 deletions
+20 -11
View File
@@ -39,23 +39,29 @@ test('server health selection coerces IDs, deduplicates, ignores unknowns, and k
];
const checked = [];
const service = createServerHealthService({
readServers: () => servers,
readProfiles: () => [{ id: 'personal', servers }],
readDesiredProfileId: () => 'personal',
ping: async (host, port) => {
checked.push([host, port]);
return { ok: true };
},
});
assert.deepEqual((await service.check(['3', 1, '3', 'missing'])).map(({ id }) => id), ['1', '3']);
assert.deepEqual((await service.check('personal', ['3', 1, '3', 'missing'])).map(({ id }) => id), ['1', '3']);
assert.deepEqual(checked, [['one.example', 1], ['three.example', 3]]);
assert.deepEqual((await service.check(undefined)).map(({ id }) => id), ['1', '2', '3']);
assert.deepEqual((await service.check('2')).map(({ id }) => id), ['1', '2', '3']);
assert.deepEqual((await service.check([])).map(({ id }) => id), ['1', '2', '3']);
assert.deepEqual(await service.check(['missing']), []);
assert.deepEqual((await service.check('', undefined)).map(({ id }) => id), ['1', '2', '3']);
assert.deepEqual((await service.check('personal', '2')).map(({ id }) => id), ['1', '2', '3']);
assert.deepEqual((await service.check('personal', [])).map(({ id }) => id), ['1', '2', '3']);
assert.deepEqual(await service.check('personal', ['missing']), []);
assert.throws(() => service.check('missing', []), (error) => error.code === 'PROFILE_NOT_FOUND');
const failure = new Error('ping failed');
await assert.rejects(
createServerHealthService({ readServers: () => servers, ping: async () => { throw failure; } }).check([]),
createServerHealthService({
readProfiles: () => [{ id: 'personal', servers }],
readDesiredProfileId: () => 'personal',
ping: async () => { throw failure; },
}).check('personal', []),
(error) => error === failure,
);
});
@@ -63,15 +69,18 @@ test('server health selection coerces IDs, deduplicates, ignores unknowns, and k
test('server health route is the only endpoint adapter', async () => {
const sent = [];
const route = createServerHealthRoute({
serverHealth: { check: async (ids) => [{ ids }] },
serverHealth: { check: async (profileId, ids) => [{ profileId, ids }] },
readBody: async () => ({ serverIds: ['chosen'] }),
sendState: async (_res, extra) => { sent.push(extra); },
});
const response = {};
assert.equal(await route.handle({ method: 'GET', url: '/api/servers/ping-all' }, response), false);
assert.equal(await route.handle({ method: 'POST', url: '/api/servers/ping-all' }, response), true);
assert.deepEqual(sent, [{ results: [{ ids: ['chosen'] }] }]);
assert.equal(await route.handle({ method: 'GET', url: '/api/profiles/personal/servers/ping' }, response), false);
assert.equal(await route.handle({ method: 'POST', url: '/api/profiles/personal/servers/ping' }, response), true);
assert.deepEqual(sent, [{
profileId: 'personal',
results: [{ profileId: 'personal', ids: ['chosen'] }],
}]);
const source = readFileSync(new URL('../../src/server/index.ts', import.meta.url), 'utf8');
assert.match(source, /createServerHealthRoute\(\{/);