mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 16:10:49 +00:00
test: harden docker live readiness
This commit is contained in:
@@ -31,6 +31,25 @@ function buildAuthHeaders(token, cookie) {
|
||||
return headers;
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
|
||||
function extractModelIds(modelsJson) {
|
||||
const models = Array.isArray(modelsJson)
|
||||
? modelsJson
|
||||
: Array.isArray(modelsJson?.data)
|
||||
? modelsJson.data
|
||||
: Array.isArray(modelsJson?.models)
|
||||
? modelsJson.models
|
||||
: [];
|
||||
return models
|
||||
.map((entry) => entry?.id ?? entry?.model ?? entry?.name)
|
||||
.filter((value) => typeof value === "string");
|
||||
}
|
||||
|
||||
const signinRes = await fetch(`${baseUrl}/api/v1/auths/signin`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
@@ -50,25 +69,34 @@ const authHeaders = {
|
||||
accept: "application/json",
|
||||
};
|
||||
|
||||
const modelsRes = await fetch(`${baseUrl}/api/models`, { headers: authHeaders });
|
||||
if (!modelsRes.ok) {
|
||||
throw new Error(`/api/models failed: HTTP ${modelsRes.status} ${await modelsRes.text()}`);
|
||||
let modelIds = [];
|
||||
let targetModel = "";
|
||||
let lastModelsError = "";
|
||||
for (let attempt = 1; attempt <= 24; attempt += 1) {
|
||||
const modelsRes = await fetch(`${baseUrl}/api/models`, { headers: authHeaders }).catch(
|
||||
(error) => {
|
||||
lastModelsError = error instanceof Error ? error.message : String(error);
|
||||
return undefined;
|
||||
},
|
||||
);
|
||||
if (modelsRes?.ok) {
|
||||
const modelsJson = await modelsRes.json();
|
||||
modelIds = extractModelIds(modelsJson);
|
||||
targetModel =
|
||||
modelIds.find((id) => id === "openclaw/default") ?? modelIds.find((id) => id === "openclaw");
|
||||
if (targetModel) {
|
||||
break;
|
||||
}
|
||||
lastModelsError = `missing openclaw model: ${JSON.stringify(modelIds)}`;
|
||||
} else if (modelsRes) {
|
||||
lastModelsError = `HTTP ${modelsRes.status} ${await modelsRes.text()}`;
|
||||
}
|
||||
await sleep(5_000);
|
||||
}
|
||||
const modelsJson = await modelsRes.json();
|
||||
const models = Array.isArray(modelsJson)
|
||||
? modelsJson
|
||||
: Array.isArray(modelsJson?.data)
|
||||
? modelsJson.data
|
||||
: Array.isArray(modelsJson?.models)
|
||||
? modelsJson.models
|
||||
: [];
|
||||
const modelIds = models
|
||||
.map((entry) => entry?.id ?? entry?.model ?? entry?.name)
|
||||
.filter((value) => typeof value === "string");
|
||||
const targetModel =
|
||||
modelIds.find((id) => id === "openclaw/default") ?? modelIds.find((id) => id === "openclaw");
|
||||
if (!targetModel) {
|
||||
throw new Error(`openclaw model missing from Open WebUI model list: ${JSON.stringify(modelIds)}`);
|
||||
throw new Error(
|
||||
`openclaw model missing from Open WebUI model list after retry: ${JSON.stringify(modelIds)} (${lastModelsError})`,
|
||||
);
|
||||
}
|
||||
|
||||
const chatRes = await fetch(`${baseUrl}/api/chat/completions`, {
|
||||
|
||||
Reference in New Issue
Block a user