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
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
<configuration>
<skip>false</skip>
<skipTests>false</skipTests>
<failIfNoTests>true</failIfNoTests>
<argLine>${argLine} -Xmx1024m -Dfile.encoding=UTF-8</argLine>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/target/test-classes</additionalClasspathElement>
Expand Down Expand Up @@ -362,7 +363,6 @@
<junit.version>4.13.2</junit.version>
<slf4j.version>2.0.18</slf4j.version>
<lombok.version>1.18.46</lombok.version>
<jackson.version>2.22.0</jackson.version>
<junit-jupiter.version>6.1.0</junit-jupiter.version>
<commons-lang.version>2.6</commons-lang.version></properties>
</profile>
Expand Down Expand Up @@ -468,7 +468,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Dependency versions -->
<commons-exec.version>1.6.0</commons-exec.version>
<jackson.version>2.17.2</jackson.version>
<jackson.version>2.22.4</jackson.version>
<java-websocket.version>1.6.0</java-websocket.version>
<junit.version>5.11.4</junit.version>
<lombok.version>1.18.46</lombok.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Loading