Skip to content

Commit 4726755

Browse files
committed
test: avoid live text helper temp arrays
1 parent 23341e5 commit 4726755

2 files changed

Lines changed: 35 additions & 25 deletions

File tree

‎src/gateway/gateway-acp-bind.live.test.ts‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,21 @@ function normalizeAcpAgent(raw: string | undefined): LiveAcpAgent {
9898
}
9999

100100
function extractAssistantTexts(messages: unknown[]): string[] {
101-
return messages
102-
.map((entry) => {
103-
if (!entry || typeof entry !== "object") {
104-
return undefined;
105-
}
106-
const role = (entry as { role?: unknown }).role;
107-
if (role !== "assistant") {
108-
return undefined;
109-
}
110-
return extractFirstTextBlock(entry);
111-
})
112-
.filter((value): value is string => typeof value === "string" && value.trim().length > 0);
101+
const texts: string[] = [];
102+
for (const entry of messages) {
103+
if (!entry || typeof entry !== "object") {
104+
continue;
105+
}
106+
const role = (entry as { role?: unknown }).role;
107+
if (role !== "assistant") {
108+
continue;
109+
}
110+
const text = extractFirstTextBlock(entry);
111+
if (typeof text === "string" && text.trim().length > 0) {
112+
texts.push(text);
113+
}
114+
}
115+
return texts;
113116
}
114117

115118
function createAcpRecallPrompt(

‎src/gateway/gateway-codex-bind.live.test.ts‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,20 @@ async function getFreeGatewayPort(): Promise<number> {
104104
}
105105

106106
function extractAssistantTexts(messages: unknown[]): string[] {
107-
return messages
108-
.map((entry) => {
109-
if (!entry || typeof entry !== "object") {
110-
return undefined;
111-
}
112-
return (entry as { role?: unknown }).role === "assistant"
113-
? extractFirstTextBlock(entry)
114-
: undefined;
115-
})
116-
.filter((value): value is string => typeof value === "string" && value.trim().length > 0);
107+
const texts: string[] = [];
108+
for (const entry of messages) {
109+
if (!entry || typeof entry !== "object") {
110+
continue;
111+
}
112+
if ((entry as { role?: unknown }).role !== "assistant") {
113+
continue;
114+
}
115+
const text = extractFirstTextBlock(entry);
116+
if (typeof text === "string" && text.trim().length > 0) {
117+
texts.push(text);
118+
}
119+
}
120+
return texts;
117121
}
118122

119123
function formatAssistantTextPreview(texts: string[], maxChars = 800): string {
@@ -134,9 +138,12 @@ async function waitForOutboundText(params: {
134138
const startedAt = Date.now();
135139

136140
while (Date.now() - startedAt < timeoutMs) {
137-
const outboundTexts = params.replies
138-
.map((reply) => reply.text)
139-
.filter((value) => value.trim().length > 0);
141+
const outboundTexts: string[] = [];
142+
for (const reply of params.replies) {
143+
if (reply.text.trim().length > 0) {
144+
outboundTexts.push(reply.text);
145+
}
146+
}
140147
const minReplyCount = params.minReplyCount ?? 1;
141148
const matchedText = outboundTexts
142149
.slice(Math.max(0, minReplyCount - 1))

0 commit comments

Comments
 (0)