|
| 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