Add runtime version reporting and display
This commit is contained in:
@@ -6,11 +6,19 @@ test('control uses the dataplane socket protocol', async () => {
|
||||
const requests = [];
|
||||
const send = async (socketPath, pathname, method) => {
|
||||
requests.push(`${method} ${pathname} ${socketPath}`);
|
||||
return { running: pathname !== '/stop', startedAt: 'now' };
|
||||
return {
|
||||
running: pathname !== '/stop',
|
||||
startedAt: 'now',
|
||||
gatewayBackendVersion: '0.1.0',
|
||||
singBoxVersion: '1.12.13',
|
||||
};
|
||||
};
|
||||
|
||||
const client = createDataplaneClient('/run/dataplane.sock', send);
|
||||
assert.equal((await client.refresh()).running, true);
|
||||
const status = await client.refresh();
|
||||
assert.equal(status.running, true);
|
||||
assert.equal(status.gatewayBackendVersion, '0.1.0');
|
||||
assert.equal(status.singBoxVersion, '1.12.13');
|
||||
await client.apply();
|
||||
await client.restart();
|
||||
assert.equal((await client.stop()).running, false);
|
||||
|
||||
@@ -103,6 +103,10 @@ test('GET and domain mutations return one state shape with monotonic revisions',
|
||||
const singboxPath = path.join(binDir, 'sing-box');
|
||||
const workingSingbox = `#!/usr/bin/env node
|
||||
if (process.argv[2] === 'check') process.exit(0);
|
||||
if (process.argv[2] === 'version') {
|
||||
console.log('sing-box version 1.12.13');
|
||||
process.exit(0);
|
||||
}
|
||||
process.on('SIGTERM', () => process.exit(0));
|
||||
setInterval(() => {}, 60_000);
|
||||
`;
|
||||
@@ -155,6 +159,13 @@ setInterval(() => {}, 60_000);
|
||||
});
|
||||
|
||||
const initial = await waitForState(port, child, () => stderr);
|
||||
const version = await request(port, '/api/version');
|
||||
assert.deepEqual(version, {
|
||||
apiVersion: 1,
|
||||
location: 'mac',
|
||||
components: { macClient: '0.1.0' },
|
||||
runtime: { singBox: '1.12.13' },
|
||||
});
|
||||
assertStateSnapshot(initial);
|
||||
assert.equal(initial.selection.appliedServerId, 'test-vpn');
|
||||
assert.equal(JSON.stringify(initial).includes(subscriptionUrl), false);
|
||||
|
||||
33
test/server/version.test.js
Normal file
33
test/server/version.test.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import { buildVersionInfo } from '../../src/server/version.js';
|
||||
import { HARBOR_VERSIONS, versionCompatibility } from '../../src/shared/versions.js';
|
||||
|
||||
test('component versions enforce one Harbor major and one Gateway major.minor', () => {
|
||||
assert.deepEqual(versionCompatibility(HARBOR_VERSIONS), {
|
||||
compatible: true,
|
||||
major: true,
|
||||
gateway: true,
|
||||
});
|
||||
assert.equal(versionCompatibility({
|
||||
macClient: '1.9.4',
|
||||
gatewayClient: '1.3.1',
|
||||
gatewayBackend: '1.3.8',
|
||||
}).compatible, true);
|
||||
assert.equal(versionCompatibility({
|
||||
macClient: '1.0.0',
|
||||
gatewayClient: '1.3.0',
|
||||
gatewayBackend: '1.4.0',
|
||||
}).compatible, false);
|
||||
});
|
||||
|
||||
test('runtime version info reports the installed sing-box binary', () => {
|
||||
const run = () => ({ stdout: 'sing-box version 1.12.13\n', stderr: '' });
|
||||
assert.deepEqual(buildVersionInfo('gateway', run), {
|
||||
apiVersion: 1,
|
||||
location: 'gateway',
|
||||
components: { gatewayBackend: HARBOR_VERSIONS.gatewayBackend },
|
||||
runtime: { singBox: '1.12.13' },
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user