From 53d657799f4c9707b5a4d8cf1500dbd9b6c85292 Mon Sep 17 00:00:00 2001 From: loong10k <20489781+loong10k@users.noreply.github.com> Date: Wed, 4 Nov 2026 07:36:02 +0800 Subject: [PATCH] fix: align Jackson patch and verify main in CI --- .github/workflows/ci.yml | 10 ++-- pom.xml | 4 +- .../openclaw/JacksonCompatibilityTest.java | 53 +++++++++++++++++++ 3 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 src/test/java/io/github/easy4j/openclaw/JacksonCompatibilityTest.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b8645ab..352a86c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,18 +1,18 @@ -# CI workflow for the feature/2.0.x line (JDK 17) +# CI workflow for main and the feature/2.0.x line (JDK 17) # # Triggers: -# - push / pull_request on the feature/2.0.x branch +# - push / pull_request on main and feature/2.0.x # - manual workflow_dispatch # # Runs `mvn -B clean verify` which includes the JaCoCo coverage gate -# (90% line coverage, haltOnFailure=false) configured in the POM. +# (90% line coverage, haltOnFailure=true) configured in the POM. name: CI on: push: - branches: [feature/2.0.x] + branches: [main, feature/2.0.x] pull_request: - branches: [feature/2.0.x] + branches: [main, feature/2.0.x] workflow_dispatch: permissions: diff --git a/pom.xml b/pom.xml index 724e43d..41940d6 100644 --- a/pom.xml +++ b/pom.xml @@ -191,6 +191,7 @@ false false + true ${argLine} -Xmx1024m -Dfile.encoding=UTF-8 ${basedir}/target/test-classes @@ -362,7 +363,6 @@ 4.13.2 2.0.18 1.18.46 - 2.22.0 6.1.0 2.6 @@ -468,7 +468,7 @@ UTF-8 1.6.0 - 2.17.2 + 2.22.4 1.6.0 5.11.4 1.18.46 diff --git a/src/test/java/io/github/easy4j/openclaw/JacksonCompatibilityTest.java b/src/test/java/io/github/easy4j/openclaw/JacksonCompatibilityTest.java new file mode 100644 index 0000000..f9eb5e6 --- /dev/null +++ b/src/test/java/io/github/easy4j/openclaw/JacksonCompatibilityTest.java @@ -0,0 +1,53 @@ +package io.github.easy4j.openclaw; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.github.easy4j.openclaw.api.model.ChatMessage; +import io.github.easy4j.openclaw.api.model.ChatRequest; +import io.github.easy4j.openclaw.api.model.ChatResponse; +import io.github.easy4j.openclaw.api.model.ThinkOption; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +class JacksonCompatibilityTest { + private final ObjectMapper mapper = new ObjectMapper(); + + @Test + void preservesGatewayRequestNamesUnicodeAndNullOmission() throws Exception { + ChatRequest request = ChatRequest.builder() + .model("openclaw/default") + .messages(List.of(ChatMessage.ofUser("你好 🌍"))) + .maxCompletionTokens(128).build(); + var json = mapper.readTree(mapper.writeValueAsBytes(request)); + assertEquals(128, json.get("max_completion_tokens").asInt()); + assertEquals("你好 🌍", json.at("/messages/0/content").asText()); + assertFalse(json.has("maxCompletionTokens")); + assertFalse(json.has("temperature")); + } + + @Test + void readsForwardCompatibleGatewayResponseAndSnakeCase() throws Exception { + ChatResponse response = mapper.readValue(""" + {"id":"chat-1","future_field":{},"choices":[ + {"index":0,"finish_reason":"stop","future_choice":true, + "message":{"role":"assistant","content":"完成"}}]} + """, ChatResponse.class); + assertEquals("chat-1", response.getId()); + assertTrue(response.getChoices().get(0).isStop()); + assertEquals("完成", response.getChoices().get(0).getMessage().getContent()); + } + + @Test + void preservesCustomThinkBooleanAndLevelCodecsAndRejectsInvalidTokens() throws Exception { + for (String json : List.of("true", "false", "\"low\"", "\"medium\"", "\"high\"")) { + ThinkOption option = mapper.readValue(json, ThinkOption.class); + assertEquals(json, mapper.writeValueAsString(option)); + } + assertNull(mapper.readValue("null", ThinkOption.class)); + assertThrows(IOException.class, () -> mapper.readValue("{}", ThinkOption.class)); + assertThrows(IllegalArgumentException.class, () -> mapper.readValue("\"invalid\"", ThinkOption.class)); + } +}