From 07d706e5e973fe852d2932780028fc45e5b8ae5b Mon Sep 17 00:00:00 2001 From: Baptiste Grimaud Date: Tue, 27 Jan 2026 09:03:07 +0100 Subject: [PATCH 1/2] fix: Add required chromeinspector lib for debugging --- javascript-modules-engine/pom.xml | 6 +- pom.xml | 5 + .../e2e/engine/graalvmEngineTest.cy.ts | 104 ++++++++++++++++++ .../graphql/enableGraalVMDebugger.graphql | 11 ++ tests/docker-compose.yml | 1 + 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 tests/cypress/e2e/engine/graalvmEngineTest.cy.ts create mode 100644 tests/cypress/fixtures/graphql/enableGraalVMDebugger.graphql diff --git a/javascript-modules-engine/pom.xml b/javascript-modules-engine/pom.xml index c345ecbc..2dfcdde8 100644 --- a/javascript-modules-engine/pom.xml +++ b/javascript-modules-engine/pom.xml @@ -66,6 +66,10 @@ org.graalvm.regex regex + + org.graalvm.tools + chromeinspector + @@ -78,7 +82,7 @@ <_dsannotations>* - bndlib,commons-pool2,pax-swissbox-bnd,graal-sdk,truffle-api,js,icu4j,regex + bndlib,chromeinspector,commons-pool2,pax-swissbox-bnd,graal-sdk,truffle-api,js,icu4j, regex diff --git a/pom.xml b/pom.xml index 0251cc83..a1e51254 100644 --- a/pom.xml +++ b/pom.xml @@ -128,6 +128,11 @@ regex ${graalvm.version} + + org.graalvm.tools + chromeinspector + ${graalvm.version} + diff --git a/tests/cypress/e2e/engine/graalvmEngineTest.cy.ts b/tests/cypress/e2e/engine/graalvmEngineTest.cy.ts new file mode 100644 index 00000000..e8f6b9bd --- /dev/null +++ b/tests/cypress/e2e/engine/graalvmEngineTest.cy.ts @@ -0,0 +1,104 @@ +describe("Check that GraalVM debugger can be enabled", () => { + // these ports must be exposed in docker-compose.yml + const ports = [9229, 10229]; + + ports.forEach((port) => { + it(`Check that GraalVM debugger can be enabled on port ${port}`, function () { + // extract the host from the JAHIA_URL env var + const host = Cypress.env("JAHIA_URL").split("//")[1].split(":")[0]; + + // delete the config + deleteGraalVMConfig(); + waitForCurlExitCode( + host, + port, + CONNECTION_ERROR_CODES, + "debugger should be disabled by default (no config)", + ); + + // Enable the debugger + enableGraalVMDebugger(port); + waitForCurlExitCode(host, port, CONNECTION_OK, "debugger should be enabled when configured"); + verifyGraalVMInspector(host, port); + }); + }); +}); + +// Constants for curl exit codes +const CONNECTION_OK = 0; +const CONNECTION_ERROR_CODES = [7, 56]; // 7=ECONNREFUSED, 56=ECONNRESET + +/** + * Wait for curl to return the expected exit code when connecting to host:port Exit codes: + * 0=success, 7=ECONNREFUSED, 56=ECONNRESET + */ +function waitForCurlExitCode( + host: string, + port: number, + expectedExitCode: number | number[], + errorMsg: string, +) { + const expectedCodes = Array.isArray(expectedExitCode) ? expectedExitCode : [expectedExitCode]; + + cy.waitUntil( + () => + cy + .exec(`curl -s -o /dev/null -w "%{http_code}" http://${host}:${port}/json/version`, { + failOnNonZeroExit: false, + timeout: 4000, + }) + .then((result) => { + const actualCode = result.code; + + if (expectedCodes.includes(actualCode)) { + const msg = + actualCode === 0 + ? `Connection successful (HTTP ${result.stdout})` + : `Got expected connection error (exit code: ${actualCode})`; + Cypress.log({ message: msg }); + return true; + } + + Cypress.log({ + message: `Waiting... got exit code ${actualCode}, expected ${expectedCodes.join(" or ")}`, + }); + return false; + }), + { + timeout: 5000, + errorMsg: `${errorMsg} - Expected curl exit code ${expectedCodes.join(" or ")}`, + }, + ); +} + +/** Delete the GraalVM Engine configuration */ +function deleteGraalVMConfig() { + cy.runProvisioningScript({ + script: { + fileContent: JSON.stringify([ + { + editConfiguration: "org.jahia.modules.javascript.modules.engine.jsengine.GraalVMEngine", + content: "", + }, + ]), + type: "application/yaml", + }, + }); +} + +/** Enable the GraalVM debugger on a given port */ +function enableGraalVMDebugger(port: number) { + cy.apollo({ + variables: { inspect: `0.0.0.0:${port}`, suspend: false, secure: false }, + mutationFile: "graphql/enableGraalVMDebugger.graphql", + }); +} + +/** Verify the response is from the GraalVM Chrome DevTools inspector */ +function verifyGraalVMInspector(host: string, port: number) { + cy.request(`http://${host}:${port}/json/version`).then((response) => { + expect(response.status).to.equal(200); + expect(response.body).to.have.property("Browser", "GraalVM"); + expect(response.body).to.have.property("Protocol-Version", "1.2"); + }); +} diff --git a/tests/cypress/fixtures/graphql/enableGraalVMDebugger.graphql b/tests/cypress/fixtures/graphql/enableGraalVMDebugger.graphql new file mode 100644 index 00000000..6056df9d --- /dev/null +++ b/tests/cypress/fixtures/graphql/enableGraalVMDebugger.graphql @@ -0,0 +1,11 @@ +mutation enableGraalVMDebugger($inspect: String!, $suspend: String!, $secure: String!) { + admin { + jahia { + configuration(pid: "org.jahia.modules.javascript.modules.engine.jsengine.GraalVMEngine") { + polyGlotInspect: value(name: "polyglot.inspect", value: $inspect) + polyGlotInspectSuspend: value(name: "polyglot.inspect.Suspend", value: $suspend) + polyGlotInspectSecure: value(name: "polyglot.inspect.Secure", value: $secure) + } + } + } +} diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 5bed894d..e74b0dac 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -7,6 +7,7 @@ services: - "8101:8101" - "8000:8000" - "9229:9229" + - "10229:10229" # to test the debugger on a different port environment: - SUPER_USER_PASSWORD=${SUPER_USER_PASSWORD} - JAHIA_LICENSE=${JAHIA_LICENSE} From dc18ba33f6121f269d7cac6824d418fcc6c5fdf5 Mon Sep 17 00:00:00 2001 From: Baptiste Grimaud Date: Tue, 27 Jan 2026 10:09:31 +0100 Subject: [PATCH 2/2] fix provisioning --- javascript-modules-engine/pom.xml | 2 +- tests/assets/provisioning.yml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/javascript-modules-engine/pom.xml b/javascript-modules-engine/pom.xml index 2dfcdde8..8fbf1178 100644 --- a/javascript-modules-engine/pom.xml +++ b/javascript-modules-engine/pom.xml @@ -82,7 +82,7 @@ <_dsannotations>* - bndlib,chromeinspector,commons-pool2,pax-swissbox-bnd,graal-sdk,truffle-api,js,icu4j, regex + bndlib,chromeinspector,commons-pool2,pax-swissbox-bnd,graal-sdk,truffle-api,js,icu4j,regex diff --git a/tests/assets/provisioning.yml b/tests/assets/provisioning.yml index 9dc9d366..0200d80a 100644 --- a/tests/assets/provisioning.yml +++ b/tests/assets/provisioning.yml @@ -1,3 +1,5 @@ +# Uninstall the JS modules shipped with Jahia to use the one we want to test +- uninstallBundle: "javascript-modules-engine" - installBundle: - "mvn:org.jahia.modules/legacy-default-components" - "mvn:org.jahia.modules/calendar"