Skip to content

Add native smoke test for JabSrv - #16822

Merged
koppor merged 6 commits into
JabRef:mainfrom
wanling0000:feat/jabsrv-native-smoke-test-v2
Sep 3, 2026
Merged

koppor merged 6 commits into
JabRef:mainfrom
wanling0000:feat/jabsrv-native-smoke-test-v2

Conversation

@wanling0000

Copy link
Copy Markdown
Collaborator

Summary

  1. Add native smoke test for JabSrv.
  2. Fix a native-image bug that the smoke test caught in the CAYW endpoint.

How it works (the loop):

  1. Build the native binary
  2. Start it in the background, serving all the test .bib files.
  3. Run the existing tests with -Pjabsrv.native.smoke=<port>. Jersey's test framework can run tests against an external test container, which sends every request to the running binary.

Bug the smoke test caught (and this PR fixes): CAYWResource.isLibraryPathAccessAllowed calls GraphicsEnvironment.isHeadless(). In the native image the AWT native libraries (e.g. libawt_lwawt.dylib on macOS) are not bundled, so that call throws UnsatisfiedLinkError and the endpoint returns 500 for an unknown library path.

Fixed by treating an unavailable AWT as headless.

Files:

  • jabsrv/build.gradle.kts: add the nativeSmokeTest task (external-container system properties + read the exclude list).
  • gradle/modules.properties: map the Jersey external test-framework provider module.
  • jabsrv/src/test/nativeimage/smoke-excluded-tests.txt: the excluded tests.
  • .github/workflows/jabsrv-native-smoke-test.yml: CI workflow.
  • jabsrv/src/main/java/org/jabref/http/server/cayw/CAYWResource.java: guard isHeadless() so an unavailable AWT is treated as headless (the native fix above).

Steps to test

  1. Terminal A: start it serving the test libraries (absolute paths, so the library ids match the tests):

Build the native binary with a Liberica NIK Full JDK:

./gradlew :jabsrv-cli:nativeCompile -PuseLibericaJdkFull=true
pkill -f 'nativeCompile/jabsrv'
jabsrv-cli/build/native/nativeCompile/jabsrv -p 9998 \
"$PWD"/jabsrv/src/test/resources/org/jabref/http/server/*-server-test.bib \
"$PWD/jablib/src/main/resources/Chocolate.bib"

  1. Terminal B: run the smoke test:
./gradlew :jabsrv:nativeSmokeTest -Pjabsrv.native.smoke=9998

Expected: BUILD SUCCESSFUL. The reused *ResourceTest classes pass against the native binary; the headless / GUI-only tests in smoke-excluded-tests.txt are skipped.

Related issues and pull requests

Closes NA

This PR is part of the JabRef components as native images project.

Follow-up to #16565

AI usage

claude-opus-4-8


AI CHECKLIST.md walkthrough

Checklist

  • I own the copyright of the code submitted and I license it under the MIT license
  • If AI tools were used, I disclosed them in the "AI usage" section and reviewed, understood, and take full ownership of all AI-generated code
  • I manually tested my changes in running JabRef (always required)
  • [/] I added JUnit tests for changes (if applicable)
  • [/] I added screenshots in the PR description (if change is visible to the user)
  • [/] I added one sentence (max 20 words) to CHANGELOG.md describing the change from the user's point of view (if the change is visible to the user)
  • [/] I checked the user documentation for up to dateness and submitted a pull request to our user documentation repository

@github-actions github-actions Bot added component: cite-as-you-write cayw (similar to better-bibtex for Zotero) component: jabsrv JabRef's http server labels Sep 2, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Add JabSrv native-image smoke testing and headless fallback

🧪 Tests 🐞 Bug fix ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• Adds CI smoke coverage running existing server tests against the native JabSrv binary.
• Configures Jersey’s external container and excludes GUI- and harness-dependent scenarios.
• Treats unavailable AWT libraries as headless to prevent CAYW endpoint failures.
Diagram

graph TD
  CI["GitHub Actions"] --> NIK["Liberica NIK"] --> BIN["Native Binary"] --> SRV["JabSrv Server"] --> CAYW["CAYW Guard"]
  CI --> TEST["Smoke Task"] --> JERSEY["Jersey External"] --> SRV
  EXCLUDES["Exclusion List"] --> TEST
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Dedicated native HTTP smoke suite
  • ➕ Avoids exclusions caused by assumptions in the in-process test harness
  • ➕ Allows scenarios tailored to standalone native behavior
  • ➖ Duplicates existing resource-test coverage and assertions
  • ➖ Creates an additional test suite requiring ongoing synchronization
2. Gradle-managed server lifecycle
  • ➕ Provides a single local command that builds, starts, tests, and stops JabSrv
  • ➕ Centralizes readiness checks and process cleanup outside CI YAML
  • ➖ Adds Gradle process-management complexity and platform-specific behavior
  • ➖ Couples the test task to the native binary location and build lifecycle
3. Narrow AWT failure handling
  • ➕ Catches the expected native linkage failure without swallowing fatal JVM errors
  • ➕ Preserves the same fail-closed security behavior
  • ➖ May require handling multiple specific linkage or initialization failure types
  • ➖ Could miss an unexpected native-image-specific throwable

Recommendation: Keep the Jersey external-container approach because it maximizes reuse of established resource tests while exercising the real native executable. Retain explicit exclusions for irreproducible GUI and harness scenarios, but consider catching LinkageError or UnsatisfiedLinkError instead of Throwable so catastrophic errors are not silently treated as headless operation.

Files changed (5) +207 / -1

Bug fix (1) +8 / -1
CAYWResource.javaFail closed when AWT is unavailable +8/-1

Fail closed when AWT is unavailable

• Guards GraphicsEnvironment.isHeadless() so missing native AWT libraries are treated as headless. This rejects unapproved CAYW library paths instead of returning an internal server error in native images.

jabsrv/src/main/java/org/jabref/http/server/cayw/CAYWResource.java

Other (4) +199 / -0
jabsrv-native-smoke-test.ymlRun native JabSrv smoke tests in CI +126/-0

Run native JabSrv smoke tests in CI

• Adds a cross-platform workflow that builds JabSrv with Liberica NIK, starts the binary with test libraries, waits for readiness, and runs the external-container test task. Ubuntu runs for pull requests, while macOS runs after merge or in the merge queue; manual runs can upload binaries.

.github/workflows/jabsrv-native-smoke-test.yml

modules.propertiesMap the Jersey external test provider +1/-0

Map the Jersey external test provider

• Registers the Jersey external test-framework provider in the module dependency catalog for smoke-test runtime resolution.

gradle/modules.properties

build.gradle.ktsDefine the native external-container test task +41/-0

Define the native external-container test task

• Adds the conditional Jersey external-provider dependency and a nativeSmokeTest task reusing server test classes against a configurable port. The task applies exclusions from the native-image smoke list and emits full failure details.

jabsrv/build.gradle.kts

smoke-excluded-tests.txtExclude unsupported native smoke scenarios +31/-0

Exclude unsupported native smoke scenarios

• Lists GUI-gated, harness-dependent, and mock-dependent resource tests that cannot run meaningfully against one standalone native process. Comments document why each exclusion category remains covered by normal tests.

jabsrv/src/test/nativeimage/smoke-excluded-tests.txt

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Actions use mutable tags ⊘ Outdated 📘 Rule violation ⛨ Security
Description
The new workflow references actions/checkout, graalvm/setup-graalvm, and
actions/upload-artifact using mutable version tags. Unreviewed upstream changes could therefore
execute in CI without a repository change.
Code

.github/workflows/jabsrv-native-smoke-test.yml[59]

+        uses: actions/checkout@v7
Evidence
Compliance rule 39 requires every third-party action to be pinned to a full commit SHA, but all
three external actions added by this workflow use mutable tags.

.github/workflows/jabsrv-native-smoke-test.yml[59-59]
.github/workflows/jabsrv-native-smoke-test.yml[74-74]
.github/workflows/jabsrv-native-smoke-test.yml[122-122]
Best Practice: Learned patterns

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The workflow uses mutable version tags for three external GitHub Actions instead of reviewed full commit SHAs.
## Issue Context
Pin each action to a 40-character commit SHA. The corresponding release tag may be retained as an explanatory comment.
## Fix Focus Areas
- .github/workflows/jabsrv-native-smoke-test.yml[59-59]
- .github/workflows/jabsrv-native-smoke-test.yml[74-74]
- .github/workflows/jabsrv-native-smoke-test.yml[122-122]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Throwable catch is overbroad ✓ Resolved 📘 Rule violation ☼ Reliability
Description
Catching Throwable around the AWT headless check intercepts unrelated initialization, resource,
and fatal JVM failures such as OutOfMemoryError and ThreadDeath, then misrepresents them as an
unavailable AWT environment. This can reject legitimate requests with a misleading headless-mode
warning while hiding the underlying failure and stack trace; the catch should be limited to the
expected native-link failure.
Code

jabsrv/src/main/java/org/jabref/http/server/cayw/CAYWResource.java[270]

+        } catch (Throwable awtUnavailable) {
Evidence
Compliance rule 13 requires narrow, specific exception handling, but the changed code catches the
root Throwable type around GraphicsEnvironment.isHeadless() and forces every failure into the
headless branch, whose false result becomes a BadRequestException. The workflow identifies
missing AWT libraries and the resulting UnsatisfiedLinkError as the expected condition, while
nearby GUI failure handling preserves and logs the actual exception instead of discarding it.

AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling: AGENTS.md: Use Narrow, Specific, and Exceptional Exception Handling
jabsrv/src/main/java/org/jabref/http/server/cayw/CAYWResource.java[267-273]
jabsrv/src/main/java/org/jabref/http/server/cayw/CAYWResource.java[229-236]
jabsrv/src/main/java/org/jabref/http/server/cayw/CAYWResource.java[267-279]
jabsrv/src/main/java/org/jabref/http/server/cayw/CAYWResource.java[282-289]
.github/workflows/jabsrv-native-smoke-test.yml[68-71]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`isLibraryPathAccessAllowed` catches every `Throwable` around the AWT headless check, masking fatal JVM errors and unrelated initialization or resource failures as ordinary headless behavior.
## Issue Context
The documented native-image failure is an `UnsatisfiedLinkError` caused by unavailable AWT native libraries. Narrow the catch to this expected failure so only it activates the headless fallback, while unrelated errors propagate with their original diagnostics and stack traces.
## Fix Focus Areas
- jabsrv/src/main/java/org/jabref/http/server/cayw/CAYWResource.java[267-276]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. AWT failure is not logged ✓ Resolved 📘 Rule violation ◔ Observability
Description
The caught AWT linkage failure is converted into headless = true without logging the throwable,
losing its stack trace and diagnostic context. Log it at debug level or higher with the throwable as
the final argument.
Code

jabsrv/src/main/java/org/jabref/http/server/cayw/CAYWResource.java[R270-272]

+        } catch (Throwable awtUnavailable) {
+            // Native image has no bundled AWT libs, so isHeadless() throws; treat that as headless.
+            headless = true;
Evidence
Compliance rule 14 requires handled exceptions to be logged with the throwable as the final logger
argument, but the new catch body only adds a comment and assigns true.

AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument: AGENTS.md: Log Exceptions with the Throwable as the Final Logger Argument
jabsrv/src/main/java/org/jabref/http/server/cayw/CAYWResource.java[270-272]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The AWT failure is handled without recording the throwable, so the reason for entering fallback mode cannot be diagnosed.
## Issue Context
Use a parameterized logger call at debug level or higher and pass the caught throwable as the final logger argument.
## Fix Focus Areas
- jabsrv/src/main/java/org/jabref/http/server/cayw/CAYWResource.java[270-272]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

4. Default smoke task lacks provider ✓ Resolved 🐞 Bug ≡ Correctness
Description
nativeSmokeTest defaults to port 9998 when jabsrv.native.smoke is absent, but the external
Jersey provider is only added when that property exists. Running :jabsrv:nativeSmokeTest without
the property therefore configures ExternalTestContainerFactory while omitting its implementation
from the task classpath, causing test initialization to fail.
Code

jabsrv/build.gradle.kts[R24-26]

+    if (project.hasProperty("jabsrv.native.smoke")) {
+        runtimeOnly("org.glassfish.jersey.tests.framework.provider.external")
+    }
Evidence
The provider dependency is conditional, while the task is registered unconditionally, uses the test
runtime classpath, defaults the missing property to 9998, and always names the external factory.
ServerTest.setUp() initializes Jersey for the selected tests, so that factory must be present at
runtime.

jabsrv/build.gradle.kts[23-26]
jabsrv/build.gradle.kts[40-45]
jabsrv/build.gradle.kts[58-63]
jabsrv/src/test/java/org/jabref/http/server/ServerTest.java[59-65]
gradle/modules.properties[24-26]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`nativeSmokeTest` can be invoked without `jabsrv.native.smoke` and defaults to port 9998, but its required external Jersey provider is only included when that property is supplied.
## Issue Context
Make the task configuration internally consistent. Either require `jabsrv.native.smoke` with a clear configuration error, or give the task a dedicated classpath that always contains the external provider.
## Fix Focus Areas
- jabsrv/build.gradle.kts[23-26]
- jabsrv/build.gradle.kts[40-63]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can add REVIEW.md to your repo root and Qodo follows it on every PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread jabsrv/build.gradle.kts Resolved
wanling0000 and others added 2 commits September 2, 2026 22:35
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jabref-machine jabref-machine added the status: changes-required Pull requests that are not yet complete label Sep 2, 2026
JabLS and JabSrv native smoke tests now live in one workflow with one job each. The macOS matrix entry is dropped for pull_request and merge_group (same reasoning as JabRef#16784/JabRef#16788: a skipped job still occupies a scarce mac runner), so it only runs on push to main/main-release and workflow_dispatch. The Linux link libraries are installed via the cached apt action, and the Jersey external test container is always on the test runtime classpath since Grizzly stays the default.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MwTYeDrUGGtdpcvTAKV15
@koppor

koppor commented Sep 3, 2026 •

Copy link
Copy Markdown
Member

🤖 Generated with Claude Code

Pushed 7594304 and 6283982 to this branch (maintainer edits):

  • macOS only on main: as in Skip macOS-silicon jabkit native build in the merge queue #16784 / Drop macOS jabkit native matrix entry instead of skipping steps #16788 for the jabkit native build, the macos-15 matrix entry is dropped (not step-skipped, which would still occupy a scarce mac runner) for pull_request and merge_group. It runs on push to main/main-release and workflow_dispatch. The entry is computed inline via fromJSON(...) in the matrix, so no extra compute-matrix job is needed.
  • Workflows stay one per component (jabls, jabsrv): the per-component path filters are what keeps a jabls-only change from building the jabsrv native image. The jabkit smoke tests stay in binaries.yml, since they run on the binary packaged there anyway.
  • apt packages via awalsh128/cache-apt-pkgs-action instead of manual apt-get; all actions in both workflows are pinned by commit SHA.
  • jabsrv/build.gradle.kts: the Jersey external test container provider is now always on the test runtime classpath. Grizzly is Jersey's default container factory, so :jabsrv:test still uses it when both are present (verified locally: all tests pass, no "multiple TestContainerFactory" warning).

@jabref-machine jabref-machine added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed status: changes-required Pull requests that are not yet complete labels Sep 3, 2026
The per-component path filters are the point of separate workflows: a jabls-only change must not build the jabsrv native image and vice versa. Both workflows keep the macOS-on-main-only matrix and now pin every action to a commit SHA.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MwTYeDrUGGtdpcvTAKV15
@koppor
koppor enabled auto-merge September 3, 2026 00:50
@koppor
koppor added this pull request to the merge queue Sep 3, 2026
@github-actions github-actions Bot added the status: to-be-merged PRs which are accepted and should go into the merge-queue. label Sep 3, 2026
@jabref-machine jabref-machine added status: no-bot-comments and removed status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers labels Sep 3, 2026
Merged via the queue into JabRef:main with commit 1630e76 Sep 3, 2026
82 of 83 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: cite-as-you-write cayw (similar to better-bibtex for Zotero) component: jabsrv JabRef's http server dev: build-system dev: ci-cd project: gsoc status: to-be-merged PRs which are accepted and should go into the merge-queue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants