Refactor VPN proxy components and update related behavior
This commit is contained in:
@@ -63,9 +63,12 @@ test('schema v2 state migrates built-in .ru into a normal enabled rule', (t) =>
|
||||
assert.deepEqual(migrated.routeRules, [
|
||||
{ type: 'domain_suffix', value: 'ru', enabled: true },
|
||||
]);
|
||||
assert.equal(migrated.appliedTag, 'nl');
|
||||
assert.equal(migrated.selectedServerId, createServerId(legacy.servers[0]));
|
||||
assert.equal(migrated.appliedServerId, migrated.selectedServerId);
|
||||
const primary = migrated.profiles[0];
|
||||
assert.equal(primary.label, 'Основной');
|
||||
assert.equal(primary.desiredServerId, createServerId(legacy.servers[0]));
|
||||
assert.equal(migrated.appliedProfileId, primary.id);
|
||||
assert.equal(migrated.appliedServerId, primary.desiredServerId);
|
||||
assert.equal(Object.hasOwn(migrated, 'selectedServerId'), false);
|
||||
assert.equal(store.migration.fromVersion, 2);
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(store.migration.backupPath, 'utf8')), legacy);
|
||||
assert.equal(JSON.parse(fs.readFileSync(filePath, 'utf8')).schemaVersion, STATE_SCHEMA_VERSION);
|
||||
@@ -84,9 +87,54 @@ test('ambiguous legacy selectedTag explicitly requires a new choice', (t) => {
|
||||
|
||||
const migrated = createStateStore(filePath).read();
|
||||
|
||||
assert.equal(migrated.selectedServerId, '');
|
||||
assert.equal(migrated.profiles[0].desiredServerId, '');
|
||||
assert.equal(migrated.appliedServerId, '');
|
||||
assert.equal(migrated.servers.length, 2);
|
||||
assert.equal(migrated.profiles[0].servers.length, 2);
|
||||
});
|
||||
|
||||
test('schema v4 migration never combines canonical state with a different cache owner', (t) => {
|
||||
const filePath = fixture(t);
|
||||
const stateServer = {
|
||||
tag: 'State server',
|
||||
type: 'vless',
|
||||
server: 'state.example',
|
||||
server_port: 443,
|
||||
};
|
||||
const cacheServer = {
|
||||
tag: 'Cache server',
|
||||
type: 'vless',
|
||||
server: 'cache.example',
|
||||
server_port: 8443,
|
||||
};
|
||||
const stateServerId = createServerId(stateServer);
|
||||
fs.writeFileSync(filePath, JSON.stringify({
|
||||
schemaVersion: 4,
|
||||
revision: 9,
|
||||
subscriptionUrl: 'https://state.example/subscription-a',
|
||||
servers: [stateServer],
|
||||
selectedServerId: stateServerId,
|
||||
appliedServerId: stateServerId,
|
||||
connectionDesired: 'running',
|
||||
}));
|
||||
|
||||
const migrated = createStateStore(filePath, {
|
||||
legacySubscriptionCache: {
|
||||
url: 'https://cache.example/subscription-b',
|
||||
config: { outbounds: [cacheServer] },
|
||||
servers: [cacheServer],
|
||||
userInfo: { total: 123 },
|
||||
fetchedAt: '2026-08-11T12:00:00.000Z',
|
||||
},
|
||||
}).read();
|
||||
|
||||
assert.equal(migrated.profiles.length, 1);
|
||||
assert.equal(migrated.profiles[0].subscriptionUrl, 'https://state.example/subscription-a');
|
||||
assert.equal(migrated.profiles[0].subscriptionConfig, null);
|
||||
assert.deepEqual(migrated.profiles[0].servers.map(({ id }) => id), [stateServerId]);
|
||||
assert.equal(migrated.profiles[0].desiredServerId, stateServerId);
|
||||
assert.equal(migrated.appliedServerId, stateServerId);
|
||||
assert.equal(migrated.appliedServerSnapshot.id, stateServerId);
|
||||
assert.equal(JSON.stringify(migrated).includes('cache.example'), false);
|
||||
});
|
||||
|
||||
test('data invariant: corrupt JSON preserves original bytes and returns explicit recovery state', (t) => {
|
||||
|
||||
Reference in New Issue
Block a user