fix: use internal caserun API orchestration URL

This commit is contained in:
lyon
2026-06-26 17:24:58 +08:00
parent 9a367582d5
commit 7d7cd8a8d4
2 changed files with 24 additions and 3 deletions
+3 -1
View File
@@ -27,7 +27,7 @@ test("cloud-api exposes web CaseRun cases, run status, events and aggregate", as
};
const server = createCloudApiServer({
accessController,
env: { PATH: process.env.PATH, HWLAB_CASERUN_CASE_REPO: root, HWLAB_CASERUN_STATE_DIR: stateRoot },
env: { PATH: process.env.PATH, HWLAB_CASERUN_CASE_REPO: root, HWLAB_CASERUN_STATE_DIR: stateRoot, HWLAB_ENVIRONMENT: "v03", HWLAB_CLOUD_API_PORT: "6667" },
caseRunExecutor: async (context: any, emit: any) => {
seen.push(context.parsed);
await emit("prepared", { runDir: context.parsed.runDir });
@@ -60,11 +60,13 @@ test("cloud-api exposes web CaseRun cases, run status, events and aggregate", as
assert.equal(startResponse.status, 202);
assert.ok(["queued", "running"].includes(startPayload.status));
assert.match(startPayload.runId, /^web-d601-f103-v2-compile-/u);
assert.equal(startPayload.runtimeApiUrl, serverUrl(server));
const runPayload = await waitForRun(server, startPayload.runId, "completed");
assert.equal(runPayload.summary.jobId, "job-test");
assert.equal(seen[0].noCaseRepoRecord, true);
assert.equal(seen[0].caseRepo, root);
assert.equal(seen[0].apiUrl, "http://hwlab-cloud-api.hwlab-v03.svc.cluster.local:6667");
const eventsResponse = await fetch(`${serverUrl(server)}/v1/caserun/runs/${startPayload.runId}/events`);
const eventsPayload = await eventsResponse.json();
+21 -2
View File
@@ -141,13 +141,14 @@ async function defaultCaseRunExecutor(context: any, emit: (stage: string, payloa
}
function caseContextForRecord(record: any, input: any) {
const internalApiUrl = internalRuntimeApiUrlForCaseRun(record, input.env ?? {});
const parsed = {
_: [],
caseId: record.caseId,
runId: record.runId,
runDir: record.runDir,
caseRepo: input.caseRepo,
apiUrl: record.runtimeApiUrl,
apiUrl: internalApiUrl,
noCaseRepoRecord: true,
stateDir: path.join(input.stateRoot, "cli")
};
@@ -157,7 +158,8 @@ function caseContextForRecord(record: any, input: any) {
...process.env,
...input.env,
HWLAB_CASE_REPO: input.caseRepo,
HWLAB_RUNTIME_API_URL: record.runtimeApiUrl,
HWLAB_RUNTIME_API_URL: internalApiUrl,
HWLAB_CASERUN_PUBLIC_RUNTIME_API_URL: record.runtimeApiUrl,
HWLAB_RUNTIME_ENDPOINT_LOCKED: "1"
},
fetchImpl: input.fetchImpl ?? globalThis.fetch,
@@ -323,6 +325,23 @@ function runtimeApiUrlFromRequest(request: IncomingMessage, env: Record<string,
return `${proto}://${host}`.replace(/\/+$/u, "");
}
function internalRuntimeApiUrlForCaseRun(record: any, env: Record<string, string | undefined>) {
const explicit = String(env.HWLAB_CASERUN_INTERNAL_API_URL ?? env.HWLAB_RUNTIME_INTERNAL_API_URL ?? "").trim();
if (explicit) return explicit.replace(/\/+$/u, "");
const namespace = String(env.HWLAB_NAMESPACE ?? env.POD_NAMESPACE ?? env.KUBERNETES_NAMESPACE ?? namespaceFromEnvironment(env.HWLAB_ENVIRONMENT) ?? "").trim();
const port = String(env.HWLAB_CLOUD_API_PORT ?? env.HWLAB_PORT ?? env.PORT ?? "6667").trim() || "6667";
if (namespace) return `http://hwlab-cloud-api.${namespace}.svc.cluster.local:${port}`;
return String(record.runtimeApiUrl ?? "").replace(/\/+$/u, "");
}
function namespaceFromEnvironment(value: string | undefined) {
const text = String(value ?? "").trim();
if (!text) return "";
if (/^hwlab-[a-z0-9-]+$/u.test(text)) return text;
if (/^[a-z0-9-]+$/u.test(text)) return `hwlab-${text}`;
return "";
}
async function readJsonBody(request: IncomingMessage, limitBytes: number) {
let size = 0;
const chunks = [] as Buffer[];