fix: prefer current conversation thread in hwlab cli

This commit is contained in:
Codex
2026-06-03 00:43:55 +08:00
parent f557b5adf4
commit 0445981f62
2 changed files with 60 additions and 5 deletions
+55
View File
@@ -350,6 +350,61 @@ test("hwlab-cli client agent send submits async and returns trace without waitin
assert.ok(result.payload.waitPolicy.nextCommands.some((command: string) => command.includes("agent result trc_test")));
});
test("hwlab-cli client agent send prefers selected conversation thread over stale workspace thread", async () => {
const calls: any[] = [];
const result = await runHwlabCli([
"client",
"agent",
"send",
"--base-url",
"http://web.test",
"--cookie",
"hwlab_session=session-a",
"--message",
"continue after failed turn",
"--trace-id",
"trc_thread_current",
"--conversation-id",
"cnv_thread_current"
], {
fetchImpl: async (url, init) => {
calls.push({ url: String(url), init, body: init?.body ? JSON.parse(String(init.body)) : null });
if (String(url).endsWith("/v1/workbench/workspace?projectId=prj_device_pod_workbench")) {
return new Response(JSON.stringify({
ok: true,
workspace: {
workspaceId: "wsp_thread_current",
revision: 9,
selectedConversationId: "cnv_thread_current",
selectedAgentSessionId: "ses_thread_current",
selectedConversation: {
conversationId: "cnv_thread_current",
sessionId: "ses_thread_current",
threadId: "thread-current"
},
workspace: {
threadId: "thread-stale"
}
}
}), { status: 200 });
}
if (String(url).endsWith("/v1/agent/chat")) {
return new Response(JSON.stringify({ accepted: true, status: "running", traceId: "trc_thread_current", resultUrl: "/v1/agent/chat/result/trc_thread_current" }), { status: 202 });
}
return new Response(JSON.stringify({ status: "completed", traceId: "trc_thread_current", conversationId: "cnv_thread_current", reply: { role: "assistant", content: "ok" } }), { status: 200 });
},
sleep: async () => {}
});
assert.equal(result.exitCode, 0);
assert.equal(calls[1].url, "http://web.test/v1/agent/chat");
assert.equal(calls[1].body.conversationId, "cnv_thread_current");
assert.equal(calls[1].body.sessionId, "ses_thread_current");
assert.equal(calls[1].body.threadId, "thread-current");
assert.equal(result.payload.continuation.threadId, "thread-current");
assert.equal(result.payload.workspace.threadId, "thread-current");
});
test("hwlab-cli client agent send waits only when --wait is explicit", async () => {
const calls: any[] = [];
const result = await runHwlabCli([
+5 -5
View File
@@ -1840,12 +1840,12 @@ function workbenchThreadId(workspace: any, workspaceJson: any) {
const selectedAgentSession = workspace?.selectedAgentSession && typeof workspace.selectedAgentSession === "object" ? workspace.selectedAgentSession : {};
const selectedConversationJson = workspaceJson?.selectedConversation && typeof workspaceJson.selectedConversation === "object" ? workspaceJson.selectedConversation : {};
const selectedAgentSessionJson = workspaceJson?.selectedAgentSession && typeof workspaceJson.selectedAgentSession === "object" ? workspaceJson.selectedAgentSession : {};
return text(workspaceJson?.threadId)
|| text(workspace?.threadId)
|| text(selectedConversation.threadId)
return text(selectedConversation.threadId ?? selectedConversation.session?.threadId)
|| text(selectedAgentSession.threadId)
|| text(selectedConversationJson.threadId)
|| text(selectedAgentSessionJson.threadId);
|| text(selectedConversationJson.threadId ?? selectedConversationJson.session?.threadId)
|| text(selectedAgentSessionJson.threadId)
|| text(workspaceJson?.threadId)
|| text(workspace?.threadId);
}
function workspaceSummaryFromSession(session: any) {