Skip to content

Commit f34900c

Browse files
committed
fix(js-sdk): accept empty ping responses
1 parent 7e57438 commit f34900c

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

sdks/sandbox/javascript/src/adapters/healthAdapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class HealthAdapter implements ExecdHealth {
2020
constructor(private readonly client: ExecdClient) {}
2121

2222
async ping(): Promise<boolean> {
23-
const { error, response } = await this.client.GET("/ping");
23+
const { error, response } = await this.client.GET("/ping", { parseAs: "text" });
2424
throwOnOpenApiFetchError({ error, response }, "Execd ping failed");
2525
return true;
2626
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2026 Alibaba Group Holding Ltd.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import assert from "node:assert/strict";
16+
import test from "node:test";
17+
18+
import { HealthAdapter, createExecdClient } from "../dist/internal.js";
19+
import { SandboxApiException } from "../dist/index.js";
20+
21+
test("HealthAdapter treats empty 200 ping responses as healthy", async () => {
22+
const health = new HealthAdapter(createExecdClient({
23+
baseUrl: "http://execd.test",
24+
async fetch(request) {
25+
assert.equal(new URL(request.url).pathname, "/ping");
26+
return new Response("", { status: 200 });
27+
},
28+
}));
29+
30+
assert.equal(await health.ping(), true);
31+
});
32+
33+
test("HealthAdapter still maps ping API errors", async () => {
34+
const health = new HealthAdapter(createExecdClient({
35+
baseUrl: "http://execd.test",
36+
async fetch() {
37+
return Response.json({ code: "UNAVAILABLE", message: "not ready" }, { status: 503 });
38+
},
39+
}));
40+
41+
await assert.rejects(() => health.ping(), SandboxApiException);
42+
});

0 commit comments

Comments
 (0)