fix: unwrap agentrun manager envelopes
This commit is contained in:
@@ -268,7 +268,13 @@ async function postJson(fetchImpl, managerUrl, path, payload) {
|
||||
const text = await response.text();
|
||||
const body = text ? JSON.parse(text) : null;
|
||||
if (!response.ok) throw new Error(`AgentRun POST ${path} failed: status=${response.status} body=${JSON.stringify(body).slice(0, 500)}`);
|
||||
return body;
|
||||
return unwrapAgentRunEnvelope(path, body);
|
||||
}
|
||||
|
||||
function unwrapAgentRunEnvelope(path, body) {
|
||||
if (!body || typeof body !== "object" || !("ok" in body)) return body;
|
||||
if (body.ok === true) return body.data ?? null;
|
||||
throw new Error(`AgentRun POST ${path} failed: envelope=${JSON.stringify(body).slice(0, 500)}`);
|
||||
}
|
||||
|
||||
function normalizeBackendProfile(value) {
|
||||
|
||||
@@ -125,6 +125,27 @@ test("dispatchHwlabAgentRun posts run command and runner job with commandId", as
|
||||
assert.equal(requests[2].body.transientEnv.some((item) => item.name === "UNIDESK_SSH_CLIENT_TOKEN"), false);
|
||||
});
|
||||
|
||||
test("dispatchHwlabAgentRun unwraps AgentRun manager response envelopes", async () => {
|
||||
const fetchImpl = async (url, init) => {
|
||||
if (url.endsWith("/api/v1/runs")) return jsonResponse({ ok: true, data: { id: "run_hwlab_envelope" } });
|
||||
if (url.endsWith("/api/v1/runs/run_hwlab_envelope/commands")) return jsonResponse({ ok: true, data: { id: "cmd_hwlab_envelope" } });
|
||||
if (url.endsWith("/api/v1/runs/run_hwlab_envelope/runner-jobs")) return jsonResponse({ ok: true, data: { id: "job_hwlab_envelope", jobName: "agentrun-v01-runner-envelope" } });
|
||||
return jsonResponse({ ok: false, failureKind: "unexpected-path" }, { status: 404 });
|
||||
};
|
||||
|
||||
const result = await dispatchHwlabAgentRun({
|
||||
fetchImpl,
|
||||
traceId: "trc_hwlab_dispatch_envelope",
|
||||
prompt: "dispatch envelope smoke",
|
||||
commitId,
|
||||
unideskMainServerIp: "https://unidesk.example.test"
|
||||
});
|
||||
|
||||
assert.equal(result.run.id, "run_hwlab_envelope");
|
||||
assert.equal(result.command.id, "cmd_hwlab_envelope");
|
||||
assert.equal(result.runnerJob.jobName, "agentrun-v01-runner-envelope");
|
||||
});
|
||||
|
||||
function jsonResponse(body, { status = 200 } = {}) {
|
||||
return {
|
||||
ok: status >= 200 && status < 300,
|
||||
|
||||
Reference in New Issue
Block a user