From 79b34f51c5cd9c953a273513ae73cf1d33f6f641 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 13:01:27 +0000 Subject: [PATCH 1/9] Initial plan From 0190cb5f58701348482a0a6feaec9cf7e4f6e7d1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 13:04:47 +0000 Subject: [PATCH 2/9] Add OAF_PIDFILE environment variable support to ow.server.checkIn Co-authored-by: nmaguiar <11761746+nmaguiar@users.noreply.github.com> --- docs/openaf-flags.md | 6 ++++ docs/openaf.md | 1 + js/owrap.server.js | 13 +++++++-- tests/autoTestAll.Server.js | 52 +++++++++++++++++++++++++++++++++++ tests/autoTestAll.Server.yaml | 8 +++++- 5 files changed, 77 insertions(+), 3 deletions(-) diff --git a/docs/openaf-flags.md b/docs/openaf-flags.md index ff15172c6..43313a03b 100644 --- a/docs/openaf-flags.md +++ b/docs/openaf-flags.md @@ -38,6 +38,12 @@ Central list of noteworthy runtime flags and environment variables. | OAF_SIGNATURE_KEY | (unset) | Public key for signature validation | | OAF_VALIDATION_STRICT | false | Require integrity + signature both | +## Server Management + +| Env | Default | Purpose | +|-----|---------|---------| +| OAF_PIDFILE | (unset) | Override PID file path in ow.server.checkIn | + ## Misc Performance / Behavior | Flag | Purpose | diff --git a/docs/openaf.md b/docs/openaf.md index 2e807a21c..110d732d3 100644 --- a/docs/openaf.md +++ b/docs/openaf.md @@ -483,6 +483,7 @@ ow.sec.closeMainSBuckets(); ow.loadServer(); // Process management +// Note: The PID file path can be overridden by setting the OAF_PIDFILE environment variable var isRunning = ow.server.checkIn("server.pid", function(existingPid) { log("Server already running with PID: " + existingPid); diff --git a/js/owrap.server.js b/js/owrap.server.js index 65fce9ddc..d20197915 100644 --- a/js/owrap.server.js +++ b/js/owrap.server.js @@ -14,7 +14,9 @@ OpenWrap.server = function() { * Optionally you can provide an onShutdown function to execute any code needed upon controlled shutdown * of the server and provide an onAlreadyRunning function (that will received the corresponding aPidFile). * If the onAlreadyRunning function returns false the process will exit with -1 (or the anExitCode provided), - * if true will continue processing. + * if true will continue processing. The aPidFile parameter can be overridden by setting the OAF_PIDFILE + * environment variable.\ + * \ * Example:\ * \ * var params = processExpr();\ @@ -41,7 +43,14 @@ OpenWrap.server.prototype.checkIn = function(aPidFile, onAlreadyRunning, onShutd var ret = false; if (isUndefined(anExitCode)) anExitCode = -1; - if (isUndefined(aPidFile)) aPidFile = "server.pid"; + // Override aPidFile with OAF_PIDFILE environment variable if set + var envPidFile = getEnv("OAF_PIDFILE"); + if (isDefined(envPidFile) && envPidFile != "") { + aPidFile = envPidFile; + } else { + if (isUndefined(aPidFile)) aPidFile = "server.pid"; + } + ret = pidCheckIn(aPidFile); if (ret && isDefined(onShutdown)) addOnOpenAFShutdown(onShutdown); if (!ret) { diff --git a/tests/autoTestAll.Server.js b/tests/autoTestAll.Server.js index 9aeffac0b..15be8b1a5 100644 --- a/tests/autoTestAll.Server.js +++ b/tests/autoTestAll.Server.js @@ -395,4 +395,56 @@ $ch("queue::test").destroy(); }; + + exports.testCheckInWithEnvVar = function() { + ow.loadServer(); + + // Test 1: Default behavior without environment variable + var testPid1 = "test_checkin_1.pid"; + io.rm(testPid1); + + var result1 = ow.server.checkIn(testPid1, function() { return false; }); + ow.test.assert(result1, true, "Problem with checkIn creating PID file"); + ow.test.assert(io.fileExists(testPid1), true, "Problem with checkIn - PID file should exist"); + + pidCheckOut(testPid1); + io.rm(testPid1); + + // Test 2: Environment variable overrides the parameter + var testPid2 = "test_checkin_2.pid"; + var envPid = "test_checkin_env.pid"; + io.rm(testPid2); + io.rm(envPid); + + // Set environment variable + java.lang.System.setProperty("OAF_PIDFILE", envPid); + + var result2 = ow.server.checkIn(testPid2, function() { return false; }); + ow.test.assert(result2, true, "Problem with checkIn when using environment variable"); + ow.test.assert(io.fileExists(envPid), true, "Problem with checkIn - Environment variable PID file should exist"); + ow.test.assert(io.fileExists(testPid2), false, "Problem with checkIn - Parameter PID file should not exist when env var is set"); + + pidCheckOut(envPid); + io.rm(envPid); + + // Clear environment variable + java.lang.System.clearProperty("OAF_PIDFILE"); + + // Test 3: Environment variable overrides even when parameter is undefined + var envPid3 = "test_checkin_env3.pid"; + io.rm(envPid3); + + java.lang.System.setProperty("OAF_PIDFILE", envPid3); + + var result3 = ow.server.checkIn(void 0, function() { return false; }); + ow.test.assert(result3, true, "Problem with checkIn when using environment variable with undefined parameter"); + ow.test.assert(io.fileExists(envPid3), true, "Problem with checkIn - Environment variable PID file should exist when parameter is undefined"); + ow.test.assert(io.fileExists("server.pid"), false, "Problem with checkIn - Default PID file should not exist when env var is set"); + + pidCheckOut(envPid3); + io.rm(envPid3); + + // Clear environment variable + java.lang.System.clearProperty("OAF_PIDFILE"); + }; })(); \ No newline at end of file diff --git a/tests/autoTestAll.Server.yaml b/tests/autoTestAll.Server.yaml index 5d35c766f..4aac564aa 100644 --- a/tests/autoTestAll.Server.yaml +++ b/tests/autoTestAll.Server.yaml @@ -80,6 +80,11 @@ jobs: to : oJob Test exec: args.func = args.tests.testQueue; + - name: Server::CheckIn with environment variable + from: Server::Init + to : oJob Test + exec: args.func = args.tests.testCheckInWithEnvVar; + todo: # Server tests # ------------ @@ -97,4 +102,5 @@ todo: - Server::Locks - Server::Auth - Server::AuthApp - - Server::Queue \ No newline at end of file + - Server::Queue + - Server::CheckIn with environment variable \ No newline at end of file From 37fe9e5298aab572df77f61c1eae52fee42c0c19 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 13:07:30 +0000 Subject: [PATCH 3/9] Update test to use realistic approach for OAF_PIDFILE testing Co-authored-by: nmaguiar <11761746+nmaguiar@users.noreply.github.com> --- tests/autoTestAll.Server.js | 76 +++++++++++++++-------------------- tests/autoTestAll.Server.yaml | 6 +-- 2 files changed, 36 insertions(+), 46 deletions(-) diff --git a/tests/autoTestAll.Server.js b/tests/autoTestAll.Server.js index 15be8b1a5..522625c76 100644 --- a/tests/autoTestAll.Server.js +++ b/tests/autoTestAll.Server.js @@ -396,55 +396,45 @@ $ch("queue::test").destroy(); }; - exports.testCheckInWithEnvVar = function() { + exports.testCheckIn = function() { ow.loadServer(); - // Test 1: Default behavior without environment variable - var testPid1 = "test_checkin_1.pid"; - io.rm(testPid1); + // Test 1: Default behavior without parameter - should use default "server.pid" + io.rm("server.pid"); - var result1 = ow.server.checkIn(testPid1, function() { return false; }); - ow.test.assert(result1, true, "Problem with checkIn creating PID file"); - ow.test.assert(io.fileExists(testPid1), true, "Problem with checkIn - PID file should exist"); + var result1 = ow.server.checkIn(void 0, function() { return false; }); + ow.test.assert(result1, true, "Problem with checkIn creating default PID file"); + ow.test.assert(io.fileExists("server.pid"), true, "Problem with checkIn - default PID file should exist"); - pidCheckOut(testPid1); - io.rm(testPid1); - - // Test 2: Environment variable overrides the parameter - var testPid2 = "test_checkin_2.pid"; - var envPid = "test_checkin_env.pid"; - io.rm(testPid2); - io.rm(envPid); - - // Set environment variable - java.lang.System.setProperty("OAF_PIDFILE", envPid); - - var result2 = ow.server.checkIn(testPid2, function() { return false; }); - ow.test.assert(result2, true, "Problem with checkIn when using environment variable"); - ow.test.assert(io.fileExists(envPid), true, "Problem with checkIn - Environment variable PID file should exist"); - ow.test.assert(io.fileExists(testPid2), false, "Problem with checkIn - Parameter PID file should not exist when env var is set"); - - pidCheckOut(envPid); - io.rm(envPid); - - // Clear environment variable - java.lang.System.clearProperty("OAF_PIDFILE"); + pidCheckOut("server.pid"); + io.rm("server.pid"); - // Test 3: Environment variable overrides even when parameter is undefined - var envPid3 = "test_checkin_env3.pid"; - io.rm(envPid3); + // Test 2: Specified PID file parameter + var testPid = "test_checkin.pid"; + io.rm(testPid); - java.lang.System.setProperty("OAF_PIDFILE", envPid3); + var result2 = ow.server.checkIn(testPid, function() { return false; }); + ow.test.assert(result2, true, "Problem with checkIn creating specified PID file"); + ow.test.assert(io.fileExists(testPid), true, "Problem with checkIn - specified PID file should exist"); + ow.test.assert(io.fileExists("server.pid"), false, "Problem with checkIn - default PID file should not exist when custom specified"); - var result3 = ow.server.checkIn(void 0, function() { return false; }); - ow.test.assert(result3, true, "Problem with checkIn when using environment variable with undefined parameter"); - ow.test.assert(io.fileExists(envPid3), true, "Problem with checkIn - Environment variable PID file should exist when parameter is undefined"); - ow.test.assert(io.fileExists("server.pid"), false, "Problem with checkIn - Default PID file should not exist when env var is set"); - - pidCheckOut(envPid3); - io.rm(envPid3); - - // Clear environment variable - java.lang.System.clearProperty("OAF_PIDFILE"); + pidCheckOut(testPid); + io.rm(testPid); + + // Test 3: Test that OAF_PIDFILE environment variable would override if set + // Note: This test verifies the code logic exists but cannot actually set env vars at runtime + // The environment variable functionality should be tested by setting OAF_PIDFILE before + // starting the OpenAF process in real-world usage or CI environments + var envPidFile = getEnv("OAF_PIDFILE"); + if (isDefined(envPidFile) && envPidFile != "") { + io.rm(envPidFile); + var result3 = ow.server.checkIn("should_be_overridden.pid", function() { return false; }); + ow.test.assert(result3, true, "Problem with checkIn when OAF_PIDFILE is set"); + ow.test.assert(io.fileExists(envPidFile), true, "Problem with checkIn - OAF_PIDFILE file should exist"); + ow.test.assert(io.fileExists("should_be_overridden.pid"), false, "Problem with checkIn - parameter file should not exist when OAF_PIDFILE is set"); + + pidCheckOut(envPidFile); + io.rm(envPidFile); + } }; })(); \ No newline at end of file diff --git a/tests/autoTestAll.Server.yaml b/tests/autoTestAll.Server.yaml index 4aac564aa..4b2b19ba3 100644 --- a/tests/autoTestAll.Server.yaml +++ b/tests/autoTestAll.Server.yaml @@ -80,10 +80,10 @@ jobs: to : oJob Test exec: args.func = args.tests.testQueue; - - name: Server::CheckIn with environment variable + - name: Server::CheckIn from: Server::Init to : oJob Test - exec: args.func = args.tests.testCheckInWithEnvVar; + exec: args.func = args.tests.testCheckIn; todo: # Server tests @@ -103,4 +103,4 @@ todo: - Server::Auth - Server::AuthApp - Server::Queue - - Server::CheckIn with environment variable \ No newline at end of file + - Server::CheckIn \ No newline at end of file From 3f55671bae084561b1973e860ba0d067123ca4f6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 13:09:07 +0000 Subject: [PATCH 4/9] Improve test comments to explain OAF_PIDFILE testing approach Co-authored-by: nmaguiar <11761746+nmaguiar@users.noreply.github.com> --- tests/autoTestAll.Server.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/autoTestAll.Server.js b/tests/autoTestAll.Server.js index 522625c76..cf180ba3d 100644 --- a/tests/autoTestAll.Server.js +++ b/tests/autoTestAll.Server.js @@ -421,10 +421,14 @@ pidCheckOut(testPid); io.rm(testPid); - // Test 3: Test that OAF_PIDFILE environment variable would override if set - // Note: This test verifies the code logic exists but cannot actually set env vars at runtime - // The environment variable functionality should be tested by setting OAF_PIDFILE before - // starting the OpenAF process in real-world usage or CI environments + // Test 3: Verify OAF_PIDFILE environment variable behavior + // Note: Environment variables cannot be set at runtime in Java (they're inherited from parent process) + // This test checks if OAF_PIDFILE is set in the environment and validates override behavior + // To test this functionality in CI, set OAF_PIDFILE before running the test suite + // Example CI configuration: + // env: + // OAF_PIDFILE: test_env.pid + // run: cd tests && ../ojob autoTestAll.yaml var envPidFile = getEnv("OAF_PIDFILE"); if (isDefined(envPidFile) && envPidFile != "") { io.rm(envPidFile); From 8deb6b17aa4f807d44347f7ab893beb5f0456215 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 13:10:17 +0000 Subject: [PATCH 5/9] Fix documentation formatting and improve test filename clarity Co-authored-by: nmaguiar <11761746+nmaguiar@users.noreply.github.com> --- js/owrap.server.js | 3 +-- tests/autoTestAll.Server.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/js/owrap.server.js b/js/owrap.server.js index d20197915..6107d2ed5 100644 --- a/js/owrap.server.js +++ b/js/owrap.server.js @@ -15,8 +15,7 @@ OpenWrap.server = function() { * of the server and provide an onAlreadyRunning function (that will received the corresponding aPidFile). * If the onAlreadyRunning function returns false the process will exit with -1 (or the anExitCode provided), * if true will continue processing. The aPidFile parameter can be overridden by setting the OAF_PIDFILE - * environment variable.\ - * \ + * environment variable. * Example:\ * \ * var params = processExpr();\ diff --git a/tests/autoTestAll.Server.js b/tests/autoTestAll.Server.js index cf180ba3d..9c527afe1 100644 --- a/tests/autoTestAll.Server.js +++ b/tests/autoTestAll.Server.js @@ -432,10 +432,10 @@ var envPidFile = getEnv("OAF_PIDFILE"); if (isDefined(envPidFile) && envPidFile != "") { io.rm(envPidFile); - var result3 = ow.server.checkIn("should_be_overridden.pid", function() { return false; }); + var result3 = ow.server.checkIn("test_param.pid", function() { return false; }); ow.test.assert(result3, true, "Problem with checkIn when OAF_PIDFILE is set"); ow.test.assert(io.fileExists(envPidFile), true, "Problem with checkIn - OAF_PIDFILE file should exist"); - ow.test.assert(io.fileExists("should_be_overridden.pid"), false, "Problem with checkIn - parameter file should not exist when OAF_PIDFILE is set"); + ow.test.assert(io.fileExists("test_param.pid"), false, "Problem with checkIn - parameter file should not exist when OAF_PIDFILE is set"); pidCheckOut(envPidFile); io.rm(envPidFile); From 1ce42fbddf503d81b7f0c7a595431b9169c309ac Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 13:11:26 +0000 Subject: [PATCH 6/9] Simplify logic and enhance test coverage for OAF_PIDFILE Co-authored-by: nmaguiar <11761746+nmaguiar@users.noreply.github.com> --- js/owrap.server.js | 3 +-- tests/autoTestAll.Server.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/js/owrap.server.js b/js/owrap.server.js index 6107d2ed5..2ebb49355 100644 --- a/js/owrap.server.js +++ b/js/owrap.server.js @@ -46,9 +46,8 @@ OpenWrap.server.prototype.checkIn = function(aPidFile, onAlreadyRunning, onShutd var envPidFile = getEnv("OAF_PIDFILE"); if (isDefined(envPidFile) && envPidFile != "") { aPidFile = envPidFile; - } else { - if (isUndefined(aPidFile)) aPidFile = "server.pid"; } + if (isUndefined(aPidFile)) aPidFile = "server.pid"; ret = pidCheckIn(aPidFile); if (ret && isDefined(onShutdown)) addOnOpenAFShutdown(onShutdown); diff --git a/tests/autoTestAll.Server.js b/tests/autoTestAll.Server.js index 9c527afe1..71706193a 100644 --- a/tests/autoTestAll.Server.js +++ b/tests/autoTestAll.Server.js @@ -431,6 +431,7 @@ // run: cd tests && ../ojob autoTestAll.yaml var envPidFile = getEnv("OAF_PIDFILE"); if (isDefined(envPidFile) && envPidFile != "") { + // Test 3a: Environment variable overrides explicit parameter io.rm(envPidFile); var result3 = ow.server.checkIn("test_param.pid", function() { return false; }); ow.test.assert(result3, true, "Problem with checkIn when OAF_PIDFILE is set"); @@ -439,6 +440,17 @@ pidCheckOut(envPidFile); io.rm(envPidFile); + + // Test 3b: Environment variable overrides default (undefined parameter) + io.rm(envPidFile); + io.rm("server.pid"); + var result4 = ow.server.checkIn(void 0, function() { return false; }); + ow.test.assert(result4, true, "Problem with checkIn when OAF_PIDFILE is set with undefined parameter"); + ow.test.assert(io.fileExists(envPidFile), true, "Problem with checkIn - OAF_PIDFILE file should exist when parameter is undefined"); + ow.test.assert(io.fileExists("server.pid"), false, "Problem with checkIn - default file should not exist when OAF_PIDFILE is set"); + + pidCheckOut(envPidFile); + io.rm(envPidFile); } }; })(); \ No newline at end of file From 64b40b1693e47f423a42210bed7208e149a16f5c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 13:12:16 +0000 Subject: [PATCH 7/9] Add trim() to handle whitespace-only environment variable values Co-authored-by: nmaguiar <11761746+nmaguiar@users.noreply.github.com> --- js/owrap.server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/owrap.server.js b/js/owrap.server.js index 2ebb49355..7b20f17e7 100644 --- a/js/owrap.server.js +++ b/js/owrap.server.js @@ -44,8 +44,8 @@ OpenWrap.server.prototype.checkIn = function(aPidFile, onAlreadyRunning, onShutd // Override aPidFile with OAF_PIDFILE environment variable if set var envPidFile = getEnv("OAF_PIDFILE"); - if (isDefined(envPidFile) && envPidFile != "") { - aPidFile = envPidFile; + if (isDefined(envPidFile) && String(envPidFile).trim() != "") { + aPidFile = String(envPidFile).trim(); } if (isUndefined(aPidFile)) aPidFile = "server.pid"; From 675294f88a4a7f8e0071e1827b617b7d7740e8e3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 13:13:31 +0000 Subject: [PATCH 8/9] Fix spacing and improve test documentation clarity Co-authored-by: nmaguiar <11761746+nmaguiar@users.noreply.github.com> --- js/owrap.server.js | 1 - tests/autoTestAll.Server.js | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/js/owrap.server.js b/js/owrap.server.js index 7b20f17e7..755656e0e 100644 --- a/js/owrap.server.js +++ b/js/owrap.server.js @@ -48,7 +48,6 @@ OpenWrap.server.prototype.checkIn = function(aPidFile, onAlreadyRunning, onShutd aPidFile = String(envPidFile).trim(); } if (isUndefined(aPidFile)) aPidFile = "server.pid"; - ret = pidCheckIn(aPidFile); if (ret && isDefined(onShutdown)) addOnOpenAFShutdown(onShutdown); if (!ret) { diff --git a/tests/autoTestAll.Server.js b/tests/autoTestAll.Server.js index 71706193a..7fa82122a 100644 --- a/tests/autoTestAll.Server.js +++ b/tests/autoTestAll.Server.js @@ -423,8 +423,9 @@ // Test 3: Verify OAF_PIDFILE environment variable behavior // Note: Environment variables cannot be set at runtime in Java (they're inherited from parent process) - // This test checks if OAF_PIDFILE is set in the environment and validates override behavior - // To test this functionality in CI, set OAF_PIDFILE before running the test suite + // This test checks if OAF_PIDFILE is set in the environment and validates override behavior. + // If OAF_PIDFILE is not set, these tests will be skipped (which is expected behavior). + // To test this functionality in CI, set OAF_PIDFILE before running the test suite. // Example CI configuration: // env: // OAF_PIDFILE: test_env.pid From 0bad8d265414452fa4a2938dc9af7595f29f3174 Mon Sep 17 00:00:00 2001 From: Nuno Aguiar Date: Wed, 11 Feb 2026 13:20:13 +0000 Subject: [PATCH 9/9] use modern functions --- js/owrap.server.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/owrap.server.js b/js/owrap.server.js index 755656e0e..13bd91dc5 100644 --- a/js/owrap.server.js +++ b/js/owrap.server.js @@ -43,9 +43,9 @@ OpenWrap.server.prototype.checkIn = function(aPidFile, onAlreadyRunning, onShutd if (isUndefined(anExitCode)) anExitCode = -1; // Override aPidFile with OAF_PIDFILE environment variable if set - var envPidFile = getEnv("OAF_PIDFILE"); - if (isDefined(envPidFile) && String(envPidFile).trim() != "") { - aPidFile = String(envPidFile).trim(); + var envPidFile = getEnv("OAF_PIDFILE") + if (isDef(envPidFile) && String(envPidFile).trim() != "") { + aPidFile = String(envPidFile).trim() } if (isUndefined(aPidFile)) aPidFile = "server.pid"; ret = pidCheckIn(aPidFile);