Skip to content

Commit f35ca79

Browse files
fix: Add required chromeinspector lib for debugging (#627)
1 parent 464ebe3 commit f35ca79

6 files changed

Lines changed: 128 additions & 1 deletion

File tree

javascript-modules-engine/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
<groupId>org.graalvm.regex</groupId>
6767
<artifactId>regex</artifactId>
6868
</dependency>
69+
<dependency>
70+
<groupId>org.graalvm.tools</groupId>
71+
<artifactId>chromeinspector</artifactId>
72+
</dependency>
6973
</dependencies>
7074

7175
<build>
@@ -78,7 +82,7 @@
7882
<instructions>
7983
<_dsannotations>*</_dsannotations>
8084
<!-- those OSGI dependencies are not provided by Jahia and should be embedded in the bundle -->
81-
<Embed-Dependency>bndlib,commons-pool2,pax-swissbox-bnd,graal-sdk,truffle-api,js,icu4j,regex</Embed-Dependency>
85+
<Embed-Dependency>bndlib,chromeinspector,commons-pool2,pax-swissbox-bnd,graal-sdk,truffle-api,js,icu4j,regex</Embed-Dependency>
8286
</instructions>
8387
<!-- because the Java classes of javascript-modules-engine-java are unpacked into the target/classes folder, -->
8488
<!-- the dependency can and should be excluded to avoid duplicates -->

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@
128128
<artifactId>regex</artifactId>
129129
<version>${graalvm.version}</version>
130130
</dependency>
131+
<dependency>
132+
<groupId>org.graalvm.tools</groupId>
133+
<artifactId>chromeinspector</artifactId>
134+
<version>${graalvm.version}</version>
135+
</dependency>
131136

132137
<!-- Jahia dependencies: -->
133138
<dependency>

tests/assets/provisioning.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Uninstall the JS modules shipped with Jahia to use the one we want to test
2+
- uninstallBundle: "javascript-modules-engine"
13
- installBundle:
24
- "mvn:org.jahia.modules/legacy-default-components"
35
- "mvn:org.jahia.modules/calendar"
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
describe("Check that GraalVM debugger can be enabled", () => {
2+
// these ports must be exposed in docker-compose.yml
3+
const ports = [9229, 10229];
4+
5+
ports.forEach((port) => {
6+
it(`Check that GraalVM debugger can be enabled on port ${port}`, function () {
7+
// extract the host from the JAHIA_URL env var
8+
const host = Cypress.env("JAHIA_URL").split("//")[1].split(":")[0];
9+
10+
// delete the config
11+
deleteGraalVMConfig();
12+
waitForCurlExitCode(
13+
host,
14+
port,
15+
CONNECTION_ERROR_CODES,
16+
"debugger should be disabled by default (no config)",
17+
);
18+
19+
// Enable the debugger
20+
enableGraalVMDebugger(port);
21+
waitForCurlExitCode(host, port, CONNECTION_OK, "debugger should be enabled when configured");
22+
verifyGraalVMInspector(host, port);
23+
});
24+
});
25+
});
26+
27+
// Constants for curl exit codes
28+
const CONNECTION_OK = 0;
29+
const CONNECTION_ERROR_CODES = [7, 56]; // 7=ECONNREFUSED, 56=ECONNRESET
30+
31+
/**
32+
* Wait for curl to return the expected exit code when connecting to host:port Exit codes:
33+
* 0=success, 7=ECONNREFUSED, 56=ECONNRESET
34+
*/
35+
function waitForCurlExitCode(
36+
host: string,
37+
port: number,
38+
expectedExitCode: number | number[],
39+
errorMsg: string,
40+
) {
41+
const expectedCodes = Array.isArray(expectedExitCode) ? expectedExitCode : [expectedExitCode];
42+
43+
cy.waitUntil(
44+
() =>
45+
cy
46+
.exec(`curl -s -o /dev/null -w "%{http_code}" http://${host}:${port}/json/version`, {
47+
failOnNonZeroExit: false,
48+
timeout: 4000,
49+
})
50+
.then((result) => {
51+
const actualCode = result.code;
52+
53+
if (expectedCodes.includes(actualCode)) {
54+
const msg =
55+
actualCode === 0
56+
? `Connection successful (HTTP ${result.stdout})`
57+
: `Got expected connection error (exit code: ${actualCode})`;
58+
Cypress.log({ message: msg });
59+
return true;
60+
}
61+
62+
Cypress.log({
63+
message: `Waiting... got exit code ${actualCode}, expected ${expectedCodes.join(" or ")}`,
64+
});
65+
return false;
66+
}),
67+
{
68+
timeout: 5000,
69+
errorMsg: `${errorMsg} - Expected curl exit code ${expectedCodes.join(" or ")}`,
70+
},
71+
);
72+
}
73+
74+
/** Delete the GraalVM Engine configuration */
75+
function deleteGraalVMConfig() {
76+
cy.runProvisioningScript({
77+
script: {
78+
fileContent: JSON.stringify([
79+
{
80+
editConfiguration: "org.jahia.modules.javascript.modules.engine.jsengine.GraalVMEngine",
81+
content: "",
82+
},
83+
]),
84+
type: "application/yaml",
85+
},
86+
});
87+
}
88+
89+
/** Enable the GraalVM debugger on a given port */
90+
function enableGraalVMDebugger(port: number) {
91+
cy.apollo({
92+
variables: { inspect: `0.0.0.0:${port}`, suspend: false, secure: false },
93+
mutationFile: "graphql/enableGraalVMDebugger.graphql",
94+
});
95+
}
96+
97+
/** Verify the response is from the GraalVM Chrome DevTools inspector */
98+
function verifyGraalVMInspector(host: string, port: number) {
99+
cy.request(`http://${host}:${port}/json/version`).then((response) => {
100+
expect(response.status).to.equal(200);
101+
expect(response.body).to.have.property("Browser", "GraalVM");
102+
expect(response.body).to.have.property("Protocol-Version", "1.2");
103+
});
104+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
mutation enableGraalVMDebugger($inspect: String!, $suspend: String!, $secure: String!) {
2+
admin {
3+
jahia {
4+
configuration(pid: "org.jahia.modules.javascript.modules.engine.jsengine.GraalVMEngine") {
5+
polyGlotInspect: value(name: "polyglot.inspect", value: $inspect)
6+
polyGlotInspectSuspend: value(name: "polyglot.inspect.Suspend", value: $suspend)
7+
polyGlotInspectSecure: value(name: "polyglot.inspect.Secure", value: $secure)
8+
}
9+
}
10+
}
11+
}

tests/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ services:
77
- "8101:8101"
88
- "8000:8000"
99
- "9229:9229"
10+
- "10229:10229" # to test the debugger on a different port
1011
environment:
1112
- SUPER_USER_PASSWORD=${SUPER_USER_PASSWORD}
1213
- JAHIA_LICENSE=${JAHIA_LICENSE}

0 commit comments

Comments
 (0)