From 71d9611ea1a17793b798b374d2fa96d3c55c9be0 Mon Sep 17 00:00:00 2001 From: sharmagot Date: Mon, 12 Jan 2026 04:08:40 -0500 Subject: [PATCH] Report detailed client_os with robust fallback and tests --- .../lib/connection-parameters.js | 8 ++- .../client/vertica-connection-params-tests.js | 2 +- .../connection-parameters/client-os-tests.js | 52 +++++++++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 packages/vertica-nodejs/test/unit/connection-parameters/client-os-tests.js diff --git a/packages/vertica-nodejs/lib/connection-parameters.js b/packages/vertica-nodejs/lib/connection-parameters.js index c00f56a7..4c28739c 100644 --- a/packages/vertica-nodejs/lib/connection-parameters.js +++ b/packages/vertica-nodejs/lib/connection-parameters.js @@ -144,9 +144,13 @@ class ConnectionParameters { } try { - this.client_os = os.platform() + this.client_os = `${os.type()} ${os.release()} ${os.arch()}` } catch (e) { - this.client_os = "" + try { + this.client_os = os.platform() + } catch (e2) { + this.client_os = "unknown" + } } try { diff --git a/packages/vertica-nodejs/mochatest/integration/client/vertica-connection-params-tests.js b/packages/vertica-nodejs/mochatest/integration/client/vertica-connection-params-tests.js index 4255b4e7..88dc3042 100644 --- a/packages/vertica-nodejs/mochatest/integration/client/vertica-connection-params-tests.js +++ b/packages/vertica-nodejs/mochatest/integration/client/vertica-connection-params-tests.js @@ -114,7 +114,7 @@ describe('vertica-nodejs handling auditing connection properties', function() { assert.equal(res.rows[0].client_pid, process.pid) assert.equal(res.rows[0].client_type, "Node.js Driver") assert.equal(res.rows[0].client_version, vertica.version) - assert.equal(res.rows[0].client_os, os.platform()) + assert.equal(res.rows[0].client_os, `${os.type()} ${os.release()} ${os.arch()}`) assert.equal(res.rows[0].client_os_user_name, os.userInfo().username) assert.equal(res.rows[0].client_os_hostname, os.hostname()) client.end() diff --git a/packages/vertica-nodejs/test/unit/connection-parameters/client-os-tests.js b/packages/vertica-nodejs/test/unit/connection-parameters/client-os-tests.js new file mode 100644 index 00000000..c914b44d --- /dev/null +++ b/packages/vertica-nodejs/test/unit/connection-parameters/client-os-tests.js @@ -0,0 +1,52 @@ +'use strict' +const helper = require('../test-helper') +const assert = require('assert') +const os = require('os') +const ConnectionParameters = require('../../../lib/connection-parameters') + +const suite = new helper.Suite() + +suite.test('client_os provides detailed OS string', function () { + const subject = new ConnectionParameters() + const expected = `${os.type()} ${os.release()} ${os.arch()}` + assert.equal(subject.client_os, expected) +}) + +suite.test('client_os falls back to os.platform() when detailed retrieval fails', function () { + const originalType = os.type + const originalRelease = os.release + const originalArch = os.arch + try { + os.type = function () { throw new Error('type fail') } + os.release = function () { throw new Error('release fail') } + os.arch = function () { throw new Error('arch fail') } + + const subject = new ConnectionParameters() + assert.equal(subject.client_os, os.platform()) + } finally { + os.type = originalType + os.release = originalRelease + os.arch = originalArch + } +}) + +suite.test('client_os uses "unknown" when both detailed and platform retrieval fail', function () { + const originalType = os.type + const originalRelease = os.release + const originalArch = os.arch + const originalPlatform = os.platform + try { + os.type = function () { throw new Error('type fail') } + os.release = function () { throw new Error('release fail') } + os.arch = function () { throw new Error('arch fail') } + os.platform = function () { throw new Error('platform fail') } + + const subject = new ConnectionParameters() + assert.equal(subject.client_os, 'unknown') + } finally { + os.type = originalType + os.release = originalRelease + os.arch = originalArch + os.platform = originalPlatform + } +})