Skip to content

Commit ceb924f

Browse files
authored
fix(rest): format single-digit history length query (#1200)
* fix(rest): format history length query parameter This fixes #1197 * fix(rest): format history length query parameter for v0.3 Apply the same single-digit formatting fix to RestTransport_v0_3, whose getTask still used %2d and padded single-digit history lengths with a leading space, producing an invalid query parameter such as historyLength= 5. Add a regression test using a single-digit history length. This fixes #1197
1 parent a51b6b3 commit ceb924f

4 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎client/transport/rest/src/main/java/org/a2aproject/sdk/client/transport/rest/RestTransport.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public Task getTask(TaskQueryParams taskQueryParams, @Nullable ClientCallContext
141141
try {
142142
StringBuilder url = new StringBuilder(Utils.buildBaseUrl(agentInterface, taskQueryParams.tenant()));
143143
if (taskQueryParams.historyLength() != null && taskQueryParams.historyLength() > 0) {
144-
url.append(String.format("/tasks/%1s?historyLength=%2d", taskQueryParams.id(), taskQueryParams.historyLength()));
144+
url.append(String.format("/tasks/%s?historyLength=%d", taskQueryParams.id(), taskQueryParams.historyLength()));
145145
} else {
146146
url.append(String.format("/tasks/%1s", taskQueryParams.id()));
147147
}

‎client/transport/rest/src/test/java/org/a2aproject/sdk/client/transport/rest/RestTransportTest.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,15 @@ public void testGetTask() throws Exception {
189189
request()
190190
.withMethod("GET")
191191
.withPath("/tasks/de38c76d-d54c-436c-8b9f-4c2703648d64")
192+
.withQueryStringParameter("historyLength", "5")
192193
)
193194
.respond(
194195
response()
195196
.withStatusCode(200)
196197
.withBody(GET_TASK_TEST_RESPONSE)
197198
);
198199
ClientCallContext context = null;
199-
TaskQueryParams request = new TaskQueryParams("de38c76d-d54c-436c-8b9f-4c2703648d64", 10);
200+
TaskQueryParams request = new TaskQueryParams("de38c76d-d54c-436c-8b9f-4c2703648d64", 5);
200201
RestTransport instance = new RestTransport(CARD);
201202
Task task = instance.getTask(request, context);
202203
assertEquals("de38c76d-d54c-436c-8b9f-4c2703648d64", task.id());

‎compat-0.3/client/transport/rest/src/main/java/org/a2aproject/sdk/compat03/client/transport/rest/RestTransport_v0_3.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public Task_v0_3 getTask(TaskQueryParams_v0_3 taskQueryParams, @Nullable ClientC
140140
try {
141141
String url;
142142
if (taskQueryParams.historyLength() > 0) {
143-
url = agentUrl + String.format("/v1/tasks/%1s?historyLength=%2d", taskQueryParams.id(), taskQueryParams.historyLength());
143+
url = agentUrl + String.format("/v1/tasks/%s?historyLength=%d", taskQueryParams.id(), taskQueryParams.historyLength());
144144
} else {
145145
url = agentUrl + String.format("/v1/tasks/%1s", taskQueryParams.id());
146146
}

‎compat-0.3/client/transport/rest/src/test/java/org/a2aproject/sdk/compat03/client/transport/rest/RestTransport_v0_3_Test.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,15 @@ public void testGetTask() throws Exception {
188188
request()
189189
.withMethod("GET")
190190
.withPath("/v1/tasks/de38c76d-d54c-436c-8b9f-4c2703648d64")
191+
.withQueryStringParameter("historyLength", "5")
191192
)
192193
.respond(
193194
response()
194195
.withStatusCode(200)
195196
.withBody(GET_TASK_TEST_RESPONSE)
196197
);
197198
ClientCallContext_v0_3 context = null;
198-
TaskQueryParams_v0_3 request = new TaskQueryParams_v0_3("de38c76d-d54c-436c-8b9f-4c2703648d64", 10);
199+
TaskQueryParams_v0_3 request = new TaskQueryParams_v0_3("de38c76d-d54c-436c-8b9f-4c2703648d64", 5);
199200
RestTransport_v0_3 instance = new RestTransport_v0_3(CARD);
200201
Task_v0_3 task = instance.getTask(request, context);
201202
assertEquals("de38c76d-d54c-436c-8b9f-4c2703648d64", task.id());

0 commit comments

Comments
 (0)