Files
pikasTech-HWLAB/internal/cloud/code-agent-agentrun-steer.test.ts
T

108 lines
4.3 KiB
TypeScript

import assert from "node:assert/strict";
import { test } from "bun:test";
import { steerAgentRunChatTurn } from "./code-agent-agentrun-adapter.ts";
import { createCodeAgentTraceStore } from "./code-agent-trace-store.ts";
test("late requested steer uses AgentRun session send and returns actual turn authority", async () => {
const calls = [];
const managerUrl = "http://127.0.0.1:16681";
const fetchImpl = async (input, init = {}) => {
const url = new URL(String(input));
const body = JSON.parse(String(init.body));
calls.push({ method: init.method, path: url.pathname, body });
return new Response(JSON.stringify({
ok: true,
data: {
action: "session-send",
decision: "turn",
internalCommandType: "turn",
run: {
id: "run_actual_turn",
status: "pending",
backendProfile: "deepseek",
sessionRef: body.run.sessionRef
},
command: {
id: "cmd_actual_turn",
runId: "run_actual_turn",
state: "pending",
type: "turn",
dispatchIntent: {
id: "dispatch_actual_turn",
state: "pending",
runnerJobId: "rjob_actual_turn",
attemptCount: 0,
durable: true
}
},
runnerAdmission: { state: "pending", disposition: "created", durable: true }
}
}), { status: 200, headers: { "content-type": "application/json" } });
};
const env = {
AGENTRUN_MGR_URL: managerUrl,
HWLAB_CODE_AGENT_AGENTRUN_ALLOW_NON_K3S_URL: "1",
HWLAB_CODE_AGENT_AGENTRUN_PROVIDER_ID: "NC01",
HWLAB_CODE_AGENT_AGENTRUN_SOURCE_COMMIT: "0123456789abcdef0123456789abcdef01234567",
HWLAB_CODE_AGENT_DEFAULT_PROVIDER_PROFILE: "deepseek",
HWLAB_CODE_AGENT_AGENTRUN_DEEPSEEK_SECRET_NAME: "agentrun-test-provider-deepseek",
HWLAB_CODE_AGENT_AGENTRUN_GITHUB_TOOL_SECRET_NAME: "agentrun-test-tool-github-pr",
HWLAB_CODE_AGENT_AGENTRUN_UNIDESK_SSH_TOOL_SECRET_NAME: "agentrun-test-tool-unidesk-ssh",
HWLAB_RUNTIME_API_URL: "http://hwlab-cloud-api.hwlab-v03.svc.cluster.local:6667",
HWLAB_RUNTIME_WEB_URL: "http://hwlab-cloud-web.hwlab-v03.svc.cluster.local:8080",
HWLAB_RUNTIME_NAMESPACE: "hwlab-v03",
HWLAB_RUNTIME_LANE: "v03",
HWLAB_RUNTIME_ENDPOINT_LOCKED: "1",
HWLAB_CODE_AGENT_ASSEMBLED_RUNTIME: "1",
UNIDESK_MAIN_SERVER_IP: "http://74.48.78.17:18081"
};
const traceStore = createCodeAgentTraceStore();
const result = await steerAgentRunChatTurn({
traceId: "trc_target_turn",
currentResult: {
conversationId: "cnv_late_steer",
sessionId: "ses_hwlab_late_steer",
threadId: "019e8078-db67-7750-a5d9-1a99f3abd445",
agentRun: {
managerUrl,
backendProfile: "deepseek",
providerId: "NC01",
sessionId: "ses_agentrun_late_steer",
runId: "run_target_turn",
commandId: "cmd_target_turn",
durableDispatch: true
}
},
params: {
message: "continue after target completed",
steerTraceId: "trc_actual_turn",
userMessageId: "msg_actual_turn_user",
projectId: "prj_hwpod_workbench",
conversationId: "cnv_late_steer",
sessionId: "ses_hwlab_late_steer",
threadId: "019e8078-db67-7750-a5d9-1a99f3abd445",
submittedAt: "2026-07-22T12:00:00.000Z"
},
options: { env, fetchImpl },
traceStore
});
assert.equal(calls.length, 1);
assert.equal(calls[0].method, "POST");
assert.equal(calls[0].path, "/api/v1/sessions/ses_agentrun_late_steer/send");
assert.equal(calls[0].body.payload.requestedDelivery, "steer");
assert.equal(calls[0].body.payload.targetTraceId, "trc_target_turn");
assert.equal(calls[0].body.commandIdempotencyKey, "trc_actual_turn");
assert.equal(calls[0].body.createRunnerJob, true);
assert.equal(result.requestedDelivery, "steer");
assert.equal(result.delivery, "turn");
assert.equal(result.traceId, "trc_actual_turn");
assert.equal(result.targetTraceId, "trc_target_turn");
assert.equal(result.agentRun.runId, "run_actual_turn");
assert.equal(result.agentRun.commandId, "cmd_actual_turn");
assert.equal(result.agentRun.dispatchIntentId, "dispatch_actual_turn");
assert.equal(result.agentRun.durableDispatch, true);
assert.equal(traceStore.snapshot("trc_actual_turn").events.some((event) => event.label === "agentrun:delivery:resolved" && event.delivery === "turn"), true);
});