test: harden remote control stress flow

This commit is contained in:
AI Bot
2026-05-11 23:12:47 +08:00
parent a311280238
commit 9c8ffebb92
7 changed files with 884 additions and 40 deletions

View File

@@ -38,6 +38,11 @@ import {
resolveMasterAgentTaskTimeoutMs,
runWithTaskTimeout,
} from "./master-task-timeout.mjs";
import {
buildComputerUseCompletionPayload,
buildMasterAgentTaskCompletionRequestBody,
buildRemoteExecutionCompletionPayload,
} from "./master-task-completion.mjs";
import { createSerializedRunner } from "./serialized-runner.mjs";
async function loadConfig(configPath) {
@@ -346,20 +351,7 @@ async function completeMasterAgentTask(config, runtime, payload) {
"Content-Type": "application/json",
...deviceTokenHeaders(config, runtime),
},
body: JSON.stringify({
deviceId: config.deviceId,
status: payload.status,
replyBody: payload.replyBody,
errorMessage: payload.errorMessage,
requestId: payload.requestId,
dispatchExecutionId: payload.dispatchExecutionId,
targetProjectId: payload.targetProjectId,
targetThreadId: payload.targetThreadId,
targetUrl: payload.targetUrl,
targetApp: payload.targetApp,
rawThreadReply: payload.rawThreadReply,
executionProgress: payload.executionProgress,
}),
body: JSON.stringify(buildMasterAgentTaskCompletionRequestBody(config, payload)),
},
);
@@ -450,32 +442,6 @@ function parseDispatchExecutionCompletion(rawOutput) {
};
}
function buildRemoteExecutionCompletionPayload(task, payload) {
return {
taskId: task.taskId,
status: payload.status === "failed" ? "failed" : "completed",
requestId: payload.requestId,
replyBody: typeof payload.replyBody === "string" ? payload.replyBody.trim() || undefined : undefined,
errorMessage: typeof payload.errorMessage === "string" ? payload.errorMessage.trim() || undefined : undefined,
dispatchExecutionId:
typeof payload.dispatchExecutionId === "string" ? payload.dispatchExecutionId.trim() || undefined : undefined,
targetProjectId:
typeof payload.targetProjectId === "string" ? payload.targetProjectId.trim() || undefined : undefined,
targetThreadId:
typeof payload.targetThreadId === "string" ? payload.targetThreadId.trim() || undefined : undefined,
targetUrl:
typeof payload.targetUrl === "string" ? payload.targetUrl.trim() || undefined : undefined,
targetApp:
typeof payload.targetApp === "string" ? payload.targetApp.trim() || undefined : undefined,
rawThreadReply:
typeof payload.rawThreadReply === "string" ? payload.rawThreadReply.trim() || undefined : undefined,
executionProgress:
payload.executionProgress && typeof payload.executionProgress === "object"
? payload.executionProgress
: undefined,
};
}
function runShortCommand(command, args, options = {}) {
return new Promise((resolve) => {
const child = spawn(command, args, {
@@ -592,6 +558,11 @@ async function runMasterAgentTask(config, runtime, task) {
if (computerUseResult.status === "failed") {
throw new Error(computerUseResult.errorMessage || "COMPUTER_USE_FAILED");
}
if (computerUseResult.status === "needs_user_action") {
return {
waitingUserActionCompletion: buildComputerUseCompletionPayload(task, computerUseResult),
};
}
return {
replyBody: computerUseResult.replyBody,
dispatchExecutionCompletion: {
@@ -707,6 +678,31 @@ async function runMasterAgentTask(config, runtime, task) {
: null,
};
})();
if (executionResult.waitingUserActionCompletion) {
const completion = await completeMasterAgentTask(
config,
runtime,
executionResult.waitingUserActionCompletion,
);
if (!completion.ok) {
throw new Error(`DIALOG_GUARD_COMPLETION_FAILED:${completion.status}:${completion.body}`);
}
runtime.activeMasterTask = {
taskId: task.taskId,
status: "needs_user_action",
completedAt: new Date().toISOString(),
detail: completion.body,
};
await postAppLog(config, runtime, {
projectId: "master-agent",
level: "info",
category: "local_agent.desktop_dialog_guard_waiting_user_action",
message: `Master Codex Node 等待用户处理桌面弹窗:${task.taskId}`,
detail: executionResult.waitingUserActionCompletion.summary,
mirrorToMaster: false,
});
return;
}
const { replyBody, dispatchExecutionCompletion, executionProgress } = executionResult;
const completion = await completeMasterAgentTask(