























@@ -54,9 +54,14 @@ const { testing, runCodexAppServerSideQuestion } = await import("./side-question
5454type ServerRequest = Required<Pick<RpcRequest, "id" | "method">> & {
5555params?: RpcRequest["params"];
5656};
57+type ClientRequest = (
58+method: string,
59+requestParams?: unknown,
60+options?: unknown,
61+) => Promise<unknown>;
57625863type FakeClient = {
59-request: ReturnType<typeof vi.fn>;
64+request: ReturnType<typeof vi.fn<ClientRequest>>;
6065addNotificationHandler: ReturnType<typeof vi.fn>;
6166addRequestHandler: ReturnType<typeof vi.fn>;
6267notifications: Array<(notification: CodexServerNotification) => void>;
@@ -71,7 +76,7 @@ function createFakeClient(): FakeClient {
7176const client: FakeClient = {
7277 notifications,
7378 requests,
74-request: vi.fn(),
79+request: vi.fn<ClientRequest>(),
7580addNotificationHandler: vi.fn((handler: (notification: CodexServerNotification) => void) => {
7681notifications.push(handler);
7782return () => {
@@ -625,19 +630,21 @@ describe("runCodexAppServerSideQuestion", () => {
625630return {};
626631}
627632if (method === "turn/start") {
628-setTimeout(async () => {
629-approvalResponse = await client.handleRequest({
630-id: 42,
631-method: "item/commandExecution/requestApproval",
632-params: {
633-threadId: "side-thread",
634-turnId: "turn-1",
635-itemId: "cmd-side",
636-command: "/bin/bash -lc 'node -v'",
637-cwd: "/tmp/workspace",
638-},
639-});
640-client.emit(turnCompleted("side-thread", "turn-1", "Side answer."));
633+setTimeout(() => {
634+void (async () => {
635+approvalResponse = await client.handleRequest({
636+id: 42,
637+method: "item/commandExecution/requestApproval",
638+params: {
639+threadId: "side-thread",
640+turnId: "turn-1",
641+itemId: "cmd-side",
642+command: "/bin/bash -lc 'node -v'",
643+cwd: "/tmp/workspace",
644+},
645+});
646+client.emit(turnCompleted("side-thread", "turn-1", "Side answer."));
647+})();
641648}, 0);
642649return turnStartResult("turn-1");
643650}
@@ -913,20 +920,22 @@ describe("runCodexAppServerSideQuestion", () => {
913920return {};
914921}
915922if (method === "turn/start") {
916-setTimeout(async () => {
917-toolResponse = await client.handleRequest({
918-id: 42,
919-method: "item/tool/call",
920-params: {
921-threadId: "side-thread",
922-turnId: "turn-1",
923-callId: "tool-1",
924-tool: "wiki_status",
925-arguments: { topic: "AGENTS.md" },
926-},
927-});
928-client.emit(agentDelta("side-thread", "turn-1", "Tool answer."));
929-client.emit(turnCompleted("side-thread", "turn-1", "Tool answer."));
923+setTimeout(() => {
924+void (async () => {
925+toolResponse = await client.handleRequest({
926+id: 42,
927+method: "item/tool/call",
928+params: {
929+threadId: "side-thread",
930+turnId: "turn-1",
931+callId: "tool-1",
932+tool: "wiki_status",
933+arguments: { topic: "AGENTS.md" },
934+},
935+});
936+client.emit(agentDelta("side-thread", "turn-1", "Tool answer."));
937+client.emit(turnCompleted("side-thread", "turn-1", "Tool answer."));
938+})();
930939}, 0);
931940return turnStartResult("turn-1");
932941}
@@ -966,20 +975,22 @@ describe("runCodexAppServerSideQuestion", () => {
966975return {};
967976}
968977if (method === "turn/start") {
969-setTimeout(async () => {
970-await client.handleRequest({
971-id: 42,
972-method: "item/tool/call",
973-params: {
974-threadId: "side-thread",
975-turnId: "turn-1",
976-callId: "tool-1",
977-tool: "wiki_status",
978-arguments: { topic: "AGENTS.md" },
979-},
980-});
981-client.emit(agentDelta("side-thread", "turn-1", "Tool answer."));
982-client.emit(turnCompleted("side-thread", "turn-1", "Tool answer."));
978+setTimeout(() => {
979+void (async () => {
980+await client.handleRequest({
981+id: 42,
982+method: "item/tool/call",
983+params: {
984+threadId: "side-thread",
985+turnId: "turn-1",
986+callId: "tool-1",
987+tool: "wiki_status",
988+arguments: { topic: "AGENTS.md" },
989+},
990+});
991+client.emit(agentDelta("side-thread", "turn-1", "Tool answer."));
992+client.emit(turnCompleted("side-thread", "turn-1", "Tool answer."));
993+})();
983994}, 0);
984995return turnStartResult("turn-1");
985996}
@@ -1045,20 +1056,22 @@ describe("runCodexAppServerSideQuestion", () => {
10451056return {};
10461057}
10471058if (method === "turn/start") {
1048-setTimeout(async () => {
1049-await client.handleRequest({
1050-id: 42,
1051-method: "item/tool/call",
1052-params: {
1053-threadId: "side-thread",
1054-turnId: "turn-1",
1055-callId: "tool-1",
1056-tool: "wiki_status",
1057-arguments: { topic: "AGENTS.md" },
1058-},
1059-});
1060-client.emit(agentDelta("side-thread", "turn-1", "Tool answer."));
1061-client.emit(turnCompleted("side-thread", "turn-1", "Tool answer."));
1059+setTimeout(() => {
1060+void (async () => {
1061+await client.handleRequest({
1062+id: 42,
1063+method: "item/tool/call",
1064+params: {
1065+threadId: "side-thread",
1066+turnId: "turn-1",
1067+callId: "tool-1",
1068+tool: "wiki_status",
1069+arguments: { topic: "AGENTS.md" },
1070+},
1071+});
1072+client.emit(agentDelta("side-thread", "turn-1", "Tool answer."));
1073+client.emit(turnCompleted("side-thread", "turn-1", "Tool answer."));
1074+})();
10621075}, 0);
10631076return turnStartResult("turn-1");
10641077}
@@ -1098,35 +1111,37 @@ describe("runCodexAppServerSideQuestion", () => {
10981111return {};
10991112}
11001113if (method === "turn/start") {
1101-setTimeout(async () => {
1102-unrelatedUserInputResponse = await client.handleRequest({
1103-id: 42,
1104-method: "item/tool/requestUserInput",
1105-params: {
1106-threadId: "parent-thread",
1107-turnId: "parent-turn",
1108-itemId: "input-parent",
1109-questions: [],
1110-},
1111-});
1112-userInputResponse = await client.handleRequest({
1113-id: 43,
1114-method: "item/tool/requestUserInput",
1115-params: {
1116-threadId: "side-thread",
1117-turnId: "turn-1",
1118-itemId: "input-1",
1119-questions: [
1120-{
1121-id: "choice",
1122-header: "Choice",
1123-question: "Pick one",
1124-options: [{ label: "A", description: "" }],
1125-},
1126-],
1127-},
1128-});
1129-client.emit(turnCompleted("side-thread", "turn-1", "No input needed."));
1114+setTimeout(() => {
1115+void (async () => {
1116+unrelatedUserInputResponse = await client.handleRequest({
1117+id: 42,
1118+method: "item/tool/requestUserInput",
1119+params: {
1120+threadId: "parent-thread",
1121+turnId: "parent-turn",
1122+itemId: "input-parent",
1123+questions: [],
1124+},
1125+});
1126+userInputResponse = await client.handleRequest({
1127+id: 43,
1128+method: "item/tool/requestUserInput",
1129+params: {
1130+threadId: "side-thread",
1131+turnId: "turn-1",
1132+itemId: "input-1",
1133+questions: [
1134+{
1135+id: "choice",
1136+header: "Choice",
1137+question: "Pick one",
1138+options: [{ label: "A", description: "" }],
1139+},
1140+],
1141+},
1142+});
1143+client.emit(turnCompleted("side-thread", "turn-1", "No input needed."));
1144+})();
11301145}, 0);
11311146return turnStartResult("turn-1");
11321147}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。