feat: map codex realtime thread status
This commit is contained in:
73
tests/fixtures/codex-app-server-runtime.mjs
vendored
73
tests/fixtures/codex-app-server-runtime.mjs
vendored
@@ -394,6 +394,79 @@ rl.on("line", (line) => {
|
||||
},
|
||||
});
|
||||
}
|
||||
if (process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_REALTIME_EVENTS === "1") {
|
||||
send({
|
||||
method: "thread/status/changed",
|
||||
params: {
|
||||
threadId: message.params?.threadId,
|
||||
status: {
|
||||
type: "active",
|
||||
activeFlags: ["waitingOnApproval", "waitingOnUserInput"],
|
||||
},
|
||||
},
|
||||
});
|
||||
send({
|
||||
method: "thread/realtime/started",
|
||||
params: {
|
||||
threadId: message.params?.threadId,
|
||||
realtimeSessionId: "rt-session-1",
|
||||
version: "v2",
|
||||
},
|
||||
});
|
||||
send({
|
||||
method: "thread/realtime/sdp",
|
||||
params: {
|
||||
threadId: message.params?.threadId,
|
||||
sdp: "v=0 secret-sk-should-not-leak",
|
||||
},
|
||||
});
|
||||
send({
|
||||
method: "thread/realtime/transcript/delta",
|
||||
params: {
|
||||
threadId: message.params?.threadId,
|
||||
role: "assistant",
|
||||
delta: "正在分析 Codex ",
|
||||
},
|
||||
});
|
||||
send({
|
||||
method: "thread/realtime/transcript/done",
|
||||
params: {
|
||||
threadId: message.params?.threadId,
|
||||
role: "assistant",
|
||||
text: "正在分析 Codex App Server 实时事件。",
|
||||
},
|
||||
});
|
||||
send({
|
||||
method: "thread/realtime/outputAudio/delta",
|
||||
params: {
|
||||
threadId: message.params?.threadId,
|
||||
audio: {
|
||||
data: "audio-secret-payload",
|
||||
sampleRate: 24000,
|
||||
numChannels: 1,
|
||||
samplesPerChannel: 480,
|
||||
itemId: "audio-item-1",
|
||||
},
|
||||
},
|
||||
});
|
||||
send({
|
||||
method: "thread/realtime/itemAdded",
|
||||
params: {
|
||||
threadId: message.params?.threadId,
|
||||
item: {
|
||||
type: "message",
|
||||
text: "raw realtime item should not be persisted",
|
||||
},
|
||||
},
|
||||
});
|
||||
send({
|
||||
method: "thread/realtime/closed",
|
||||
params: {
|
||||
threadId: message.params?.threadId,
|
||||
reason: "completed",
|
||||
},
|
||||
});
|
||||
}
|
||||
send({
|
||||
method: "item/agentMessage/delta",
|
||||
params: {
|
||||
|
||||
@@ -359,6 +359,57 @@ test("codex app-server runner maps guardian approval and file-change events with
|
||||
}
|
||||
});
|
||||
|
||||
test("codex app-server runner maps thread status and realtime events without leaking transport payloads", async () => {
|
||||
const previous = process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_REALTIME_EVENTS;
|
||||
process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_REALTIME_EVENTS = "1";
|
||||
try {
|
||||
const runnerConfig = getCodexAppServerRunnerConfig(process.env, {
|
||||
codexAppServerEnabled: true,
|
||||
codexAppServerCommand: process.execPath,
|
||||
codexAppServerArgs: ["tests/fixtures/codex-app-server-runtime.mjs"],
|
||||
codexAppServerWorkdir: repoRoot,
|
||||
codexAppServerTimeoutMs: 5000,
|
||||
masterAgentModel: "gpt-5.4",
|
||||
});
|
||||
|
||||
const result = await executeCodexAppServerTask(runnerConfig, {
|
||||
taskId: "task-app-server-realtime",
|
||||
taskType: "conversation_reply",
|
||||
targetCodexThreadRef: "019d-app-server-thread",
|
||||
targetCodexFolderRef: repoRoot,
|
||||
executionPrompt: "开启实时协作并回写状态",
|
||||
});
|
||||
|
||||
assert.equal(result.status, "completed");
|
||||
assert.deepEqual(result.executionProgress.threadStatus, {
|
||||
type: "active",
|
||||
activeFlags: ["waitingOnApproval", "waitingOnUserInput"],
|
||||
waitingOnApproval: true,
|
||||
waitingOnUserInput: true,
|
||||
});
|
||||
assert.deepEqual(result.executionProgress.realtime, {
|
||||
status: "closed",
|
||||
sessionId: "rt-session-1",
|
||||
version: "v2",
|
||||
transcriptRole: "assistant",
|
||||
transcriptPreview: "正在分析 Codex App Server 实时事件。",
|
||||
audioChunkCount: 1,
|
||||
itemCount: 1,
|
||||
closeReason: "completed",
|
||||
});
|
||||
const serialized = JSON.stringify(result.executionProgress);
|
||||
assert.equal(serialized.includes("audio-secret-payload"), false);
|
||||
assert.equal(serialized.includes("v=0 secret"), false);
|
||||
assert.equal(serialized.includes("raw realtime item should not be persisted"), false);
|
||||
} finally {
|
||||
if (previous === undefined) {
|
||||
delete process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_REALTIME_EVENTS;
|
||||
} else {
|
||||
process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_REALTIME_EVENTS = previous;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("codex app-server runner bridges source thread context into target thread through inject_items", async () => {
|
||||
const previous = process.env.BOSS_CODEX_APP_SERVER_FIXTURE_INTER_THREAD;
|
||||
process.env.BOSS_CODEX_APP_SERVER_FIXTURE_INTER_THREAD = "1";
|
||||
|
||||
@@ -154,3 +154,67 @@ test("POST task progress preserves Codex approval, warning, and file-change summ
|
||||
assert.equal(progress?.warnings?.[0]?.message, "检测到需要用户确认的命令执行。");
|
||||
assert.equal(progress?.fileChanges?.[0]?.path, "src/app/page.tsx");
|
||||
});
|
||||
|
||||
test("POST task progress preserves Codex thread status and realtime summaries", async () => {
|
||||
const task = await data.queueMasterAgentTask({
|
||||
taskId: "route-progress-realtime-task",
|
||||
projectId: "group-progress-test",
|
||||
taskType: "dispatch_execution",
|
||||
requestMessageId: "msg-route-progress-realtime",
|
||||
requestText: "让目标线程继续开发并回写实时状态",
|
||||
executionPrompt: "让目标线程继续开发并回写实时状态",
|
||||
requestedBy: "krisolo",
|
||||
requestedByAccount: "krisolo",
|
||||
deviceId: "mac-studio",
|
||||
targetProjectId: "master-agent",
|
||||
targetThreadId: "master-agent-thread",
|
||||
});
|
||||
await data.claimNextMasterAgentTask("mac-studio");
|
||||
|
||||
const response = await postProgress(
|
||||
new NextRequest(`http://127.0.0.1:3000/api/v1/master-agent/tasks/${task.taskId}/progress`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"x-boss-device-token": "boss-mac-studio-token",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
deviceId: "mac-studio",
|
||||
status: "running",
|
||||
executionProgress: {
|
||||
steps: [{ text: "监听 Codex realtime 事件", status: "running" }],
|
||||
threadStatus: {
|
||||
type: "active",
|
||||
activeFlags: ["waitingOnApproval", "waitingOnUserInput"],
|
||||
waitingOnApproval: true,
|
||||
waitingOnUserInput: true,
|
||||
},
|
||||
realtime: {
|
||||
status: "streaming",
|
||||
sessionId: "rt-session-1",
|
||||
version: "v2",
|
||||
transcriptRole: "assistant",
|
||||
transcriptPreview: "正在分析 Codex App Server 实时事件。",
|
||||
audioChunkCount: 1,
|
||||
itemCount: 1,
|
||||
},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
{ params: Promise.resolve({ taskId: task.taskId }) },
|
||||
);
|
||||
|
||||
assert.equal(response.status, 200);
|
||||
|
||||
const state = await data.readState();
|
||||
const progress = state.projects
|
||||
.find((project) => project.id === "master-agent")
|
||||
?.messages.find((message) => message.executionProgress?.taskId === task.taskId)
|
||||
?.executionProgress;
|
||||
assert.equal(progress?.threadStatus?.type, "active");
|
||||
assert.equal(progress?.threadStatus?.waitingOnApproval, true);
|
||||
assert.equal(progress?.threadStatus?.waitingOnUserInput, true);
|
||||
assert.equal(progress?.realtime?.status, "streaming");
|
||||
assert.equal(progress?.realtime?.transcriptPreview, "正在分析 Codex App Server 实时事件。");
|
||||
assert.equal(progress?.realtime?.audioChunkCount, 1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user