Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions .github/workflows/jabls-native-smoke-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,55 +35,46 @@ concurrency:
group: "${{ github.workflow }}-${{ github.head_ref || github.ref }}"
cancel-in-progress: true

# native-image on the macOS runner is the slowest build and mac runners are scarce, so the
# macOS entry is dropped for pull_request and merge_group (not merely skipped: a skipped-steps
# job would still occupy a macos-15 runner slot, see #16784 and #16788). It still runs on
# push to main/main-release and workflow_dispatch.

jobs:
native-smoke-test:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-22.04
runOnPullRequest: true
- os: macos-15
runOnPullRequest: false
os: ${{ fromJSON((github.event_name == 'pull_request' || github.event_name == 'merge_group') && '["ubuntu-22.04"]' || '["ubuntu-22.04", "macos-15"]') }}
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} JabLS native smoke test
timeout-minutes: 60

steps:
- name: Skip native build (not needed for this event)
if: github.event_name == 'pull_request' && matrix.runOnPullRequest != true
run: echo "Skipping macOS native build on pull_request; it runs in the merge queue."

- name: Checkout
if: github.event_name != 'pull_request' || matrix.runOnPullRequest == true
uses: actions/checkout@v7
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 1
submodules: 'true'
show-progress: 'false'

- uses: ./.github/actions/setup-gradle
if: github.event_name != 'pull_request' || matrix.runOnPullRequest == true

- name: Set up GraalVM
if: github.event_name != 'pull_request' || matrix.runOnPullRequest == true
uses: graalvm/setup-graalvm@v1
uses: graalvm/setup-graalvm@0426e2e191540e8514dff98dc52a5f5146a2a276 # v1.6.6
with:
distribution: 'graalvm'
java-version: '25'
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Build JabLS native binary
if: github.event_name != 'pull_request' || matrix.runOnPullRequest == true
run: gradle :jabls-cli:nativeCompile

- name: Run JabLS native smoke test
if: github.event_name != 'pull_request' || matrix.runOnPullRequest == true
run: python3 jabls-cli/src/test/nativeimage/jabls-smoke-test.py

- name: Upload JabLS native binary
if: ${{ github.event_name == 'workflow_dispatch' && inputs.upload-as-artifact }}
uses: actions/upload-artifact@v7
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: jabls-native-${{ matrix.os }}
path: jabls-cli/build/native/nativeCompile/
Expand Down
127 changes: 127 additions & 0 deletions .github/workflows/jabsrv-native-smoke-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: JabSrv Native Smoke Test

on:
push:
branches:
- main
- main-release
paths:
- 'jabsrv/**'
- 'jabsrv-cli/**'
- 'jablib/**'
- '!jablib/src/test/**'
- 'versions/**'
- '.github/workflows/jabsrv-native-smoke-test.yml'
pull_request:
paths:
- 'jabsrv/**'
- 'jabsrv-cli/**'
- 'jablib/**'
- '!jablib/src/test/**'
- 'versions/**'
- '.github/workflows/jabsrv-native-smoke-test.yml'
merge_group:
workflow_dispatch:
inputs:
upload-as-artifact:
description: "Upload the native binary as a workflow artifact"
type: boolean
default: false

permissions:
contents: read

concurrency:
group: "${{ github.workflow }}-${{ github.head_ref || github.ref }}"
cancel-in-progress: true

# native-image on the macOS runner is the slowest build and mac runners are scarce, so the
# macOS entry is dropped for pull_request and merge_group (not merely skipped: a skipped-steps
# job would still occupy a macos-15 runner slot, see #16784 and #16788). It still runs on
# push to main/main-release and workflow_dispatch.

jobs:
native-smoke-test:
strategy:
fail-fast: false
matrix:
os: ${{ fromJSON((github.event_name == 'pull_request' || github.event_name == 'merge_group') && '["ubuntu-22.04"]' || '["ubuntu-22.04", "macos-15"]') }}
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} JabSrv native smoke test
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 1
submodules: 'true'
show-progress: 'false'

- uses: ./.github/actions/setup-gradle

# In graalvm/setup-graalvm, distribution "liberica" means Liberica NIK; jdk+fx is the
# Full package, needed because the jabsrv image bundles the CAYW JavaFX picker (GraalVM CE
# cannot compile JavaFX's Glass toolkit). AWT native libs still aren't bundled, so CAYW
# detects headless defensively at runtime.
- name: Set up Liberica NIK (native-image with AWT + JavaFX support)
uses: graalvm/setup-graalvm@0426e2e191540e8514dff98dc52a5f5146a2a276 # v1.6.6
with:
distribution: 'liberica'
java-package: 'jdk+fx'
java-version: '25'
github-token: ${{ secrets.GITHUB_TOKEN }}

# The jabsrv image bundles the CAYW JavaFX picker, so native-image links against JavaFX's
# GTK/X11/GL toolkit. GitHub's Linux runners lack those -dev libraries (macOS links system
# frameworks instead). Only needed to link the binary; the headless data plane never loads them.
- name: Install JavaFX native link libraries (Linux)
if: runner.os == 'Linux'
uses: awalsh128/cache-apt-pkgs-action@553a35bb8ebd9fcabcb1c9451aa4c98e1b4ca8a9 # v1.6.3
with:
packages: libgtk-3-dev libglib2.0-dev libpango1.0-dev libcairo2-dev libatk1.0-dev libgdk-pixbuf-2.0-dev libharfbuzz-dev libxtst-dev libgl1-mesa-dev
version: 1.0

- name: Build JabSrv native binary
run: gradle :jabsrv-cli:nativeCompile -PuseLibericaJdkFull=true

- name: Run JabSrv native smoke test
run: |
# The native binary is an external Jersey test container: start it
# serving the union of the test .bib files, then run the reused
# *ResourceTest classes against it. Absolute paths are required so the
# library ids match TestBibFile (id = hash of the path). AWT native libs
# aren't bundled in the image; CAYW detects headless defensively, so no
# -Djava.awt.headless flag is needed.
"$GITHUB_WORKSPACE/jabsrv-cli/build/native/nativeCompile/jabsrv" -p 9998 \
"$GITHUB_WORKSPACE/jabsrv/src/test/resources/org/jabref/http/server/general-server-test.bib" \
"$GITHUB_WORKSPACE/jabsrv/src/test/resources/org/jabref/http/server/groups-server-test.bib" \
"$GITHUB_WORKSPACE/jabsrv/src/test/resources/org/jabref/http/server/xss-server-test.bib" \
"$GITHUB_WORKSPACE/jablib/src/main/resources/Chocolate.bib" &
server_pid=$!
trap "kill $server_pid 2>/dev/null || true" EXIT

# Wait for the server to accept requests (up to ~30s).
server_ready=false
for _ in $(seq 1 30); do
if curl -sf http://localhost:9998/libraries >/dev/null; then
echo "jabsrv is serving"
server_ready=true
break
fi
sleep 1
done

if [ "$server_ready" != "true" ]; then
echo "jabsrv did not start within 30 seconds"
exit 1
fi

gradle :jabsrv:nativeSmokeTest -Pjabsrv.native.smoke=9998 -PuseLibericaJdkFull=true

- name: Upload JabSrv native binary
if: ${{ github.event_name == 'workflow_dispatch' && inputs.upload-as-artifact }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: jabsrv-native-${{ matrix.os }}
path: jabsrv-cli/build/native/nativeCompile/
if-no-files-found: error
1 change: 1 addition & 0 deletions gradle/modules.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ org.glassfish.jersey.core.server=org.glassfish.jersey.core:jersey-server
org.glassfish.jersey.inject.hk2=org.glassfish.jersey.inject:jersey-hk2
org.glassfish.jersey.tests.framework.core=org.glassfish.jersey.test-framework:jersey-test-framework-core
org.glassfish.jersey.tests.framework.provider.grizzly=org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-grizzly2
org.glassfish.jersey.tests.framework.provider.external=org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-external
org.jabref.htmltonode=org.jabref:html-to-node
org.jabref.latexconv=org.jabref:latex-conv
tools.jackson.databind=tools.jackson.core:jackson-databind
Expand Down
41 changes: 41 additions & 0 deletions jabsrv/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.language.base.plugins.LifecycleBasePlugin

plugins {
id("org.jabref.gradle.module")
Expand All @@ -19,6 +20,9 @@ testModuleInfo {
runtimeOnly("org.tinylog.api")
runtimeOnly("org.tinylog.impl")
runtimeOnly("org.apache.logging.log4j.to.slf4j")
// Jersey's external test container, used by nativeSmokeTest. Harmless for the regular
// test task: with both providers present JerseyTest picks its default (Grizzly).
runtimeOnly("org.glassfish.jersey.tests.framework.provider.external")
}

tasks.test {
Expand All @@ -29,3 +33,40 @@ tasks.test {
}
maxParallelForks = 1
}

val testSourceSet = sourceSets.test.get()

tasks.register<Test>("nativeSmokeTest") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Runs server tests against a running native jabsrv binary (external Jersey container)."
testClassesDirs = testSourceSet.output.classesDirs
classpath = testSourceSet.runtimeClasspath
maxParallelForks = 1

useJUnitPlatform()

filter {
includeTestsMatching("org.jabref.http.server.*")
}

testLogging {
events("FAILED")
exceptionFormat = TestExceptionFormat.FULL
}

val smokePort = (project.findProperty("jabsrv.native.smoke") as String?)?.toIntOrNull()
?: throw GradleException("nativeSmokeTest requires -Pjabsrv.native.smoke=<port> (the port the running native jabsrv binary serves on).")
systemProperty(
"jersey.config.test.container.factory",
"org.glassfish.jersey.test.external.ExternalTestContainerFactory"
)
systemProperty("jersey.config.test.container.port", smokePort.toString())

// Skip the tests that cannot pass against a GUI-less standalone binary.
val excludeFile = layout.projectDirectory.file("src/test/nativeimage/smoke-excluded-tests.txt")
providers.fileContents(excludeFile).asText.orNull
?.lines()
?.map { it.substringBefore('#').trim() }
?.filter { it.isNotEmpty() }
?.forEach { filter.excludeTestsMatching(it) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,15 @@ private boolean isLibraryPathAccessAllowed(Path requestedLibraryPath) {
return false;
}

if (GraphicsEnvironment.isHeadless()) {
boolean headless;
try {
headless = GraphicsEnvironment.isHeadless();
} catch (LinkageError awtUnavailable) {
// Native image doesn't bundle AWT libs, so isHeadless() fails to link; treat that as headless.
LOGGER.debug("AWT unavailable (native image without bundled AWT libs); treating as headless.", awtUnavailable);
headless = true;
}
if (headless) {
LOGGER.warn("Rejecting CAYW library path access in headless mode: {}", requestedLibraryPath);
return false;
}
Expand Down
31 changes: 31 additions & 0 deletions jabsrv/src/test/nativeimage/smoke-excluded-tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Tests that cannot pass against a standalone (GUI-less) native jabsrv binary.
# Consumed by the `nativeSmokeTest` task in jabsrv/build.gradle.kts, one
# `excludeTestsMatching` pattern per non-comment line. `#` starts a comment.
#
# These stay green in the normal `:jabsrv:test` (in-process Grizzly, mocked
# GUI) run — they are excluded only from the native smoke gate.

# --- GUI-gated: standalone has UiMessageHandler.NONE, so the write/select
# endpoints return 400 "Only possible in GUI mode." before reaching the
# 204/404/410/200 logic the assertions expect. ---
org.jabref.http.server.CitationsResourceTest.addToDemoLibraryReturns404
org.jabref.http.server.CitationsResourceTest.addToUnknownLibraryReturns404
org.jabref.http.server.CitationsResourceTest.addToOpenLibraryWithExpiredKeyReturns410
org.jabref.http.server.EntriesResourceTest.importToOpenLibrarySwitchesToThatLibrary
org.jabref.http.server.EntriesResourceTest.importToCurrentLibraryHasEmptyTarget
org.jabref.http.server.EntriesResourceTest.importCslJsonConvertsEntryType
org.jabref.http.server.EntriesResourceTest.importToUnknownLibraryReturns404
org.jabref.http.server.cayw.CAYWResourceTest.biblatex
org.jabref.http.server.cayw.CAYWResourceTest.servedLibraryPathIsAccepted

# --- Harness: the external test container is one already-running process, so
# ServerTest.setAvailableLibraries (tearDown + setUp) is a no-op and the binary
# always serves the union of all test libraries. These two assert the exact
# GET /libraries membership, which that union breaks. ---
org.jabref.http.server.LibrariesResourceTest.defaultOneTestLibrary
org.jabref.http.server.LibrariesResourceTest.twoExplicitTestLibraries

# --- Mock-dependent: stubs SrvStateManager.getOpenDatabases() to empty, which the
# external binary ignores (it serves real, non-empty libraries with shared static
# state), so the empty-databases scenario can't be reproduced here. ---
org.jabref.http.server.cayw.CAYWResourceTest.emptyOpenDatabasesDoesNotCrash
Loading