Skip to content

Commit f4a7fef

Browse files
Copilotpelikhan
andauthored
Polish compact help formatting and test assertions
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 6936fd9 commit f4a7fef

2 files changed

Lines changed: 26 additions & 18 deletions

File tree

actions/setup/js/mcp_cli_bridge.cjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ function summarizeHelpText(value, maxLen) {
859859
*/
860860
function formatCompactNameLines(names, maxLines) {
861861
if (!Array.isArray(names) || names.length === 0) {
862+
// Callers spread the result into help lines, so empty input should contribute no lines.
862863
return [];
863864
}
864865
if (!Number.isFinite(maxLines) || maxLines <= 0) {
@@ -868,6 +869,7 @@ function formatCompactNameLines(names, maxLines) {
868869
let current = " ";
869870
for (const name of names) {
870871
const token = current.trim() ? `, ${name}` : name;
872+
// A single very long name may still exceed the width target; we keep it intact.
871873
const shouldStartNewLine = current.length + token.length > COMPACT_NAME_LINE_TARGET_WIDTH;
872874
if (shouldStartNewLine) {
873875
lines.push(current);
@@ -880,9 +882,10 @@ function formatCompactNameLines(names, maxLines) {
880882
lines.push(current);
881883
}
882884
if (lines.length > maxLines) {
883-
// Keep all names visible by collapsing overflow into the last allowed line.
885+
// Keep maxLines - 1 full lines and collapse the remaining names into the final allowed line.
884886
const compactTail = lines
885887
.slice(maxLines - 1)
888+
// Trim per-line indentation before rebuilding a single indented tail line.
886889
.map(line => line.trim())
887890
.join(", ");
888891
return [...lines.slice(0, maxLines - 1), ` ${compactTail}`];

actions/setup/js/mcp_cli_bridge.test.cjs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,11 @@ describe("mcp_cli_bridge.cjs", () => {
221221
showHelp("safeoutputs", tools);
222222

223223
const outputLines = stdoutChunks.join("").trimEnd().split("\n");
224+
const output = outputLines.join("\n");
224225
expect(outputLines.length).toBeLessThanOrEqual(20);
225-
expect(outputLines.join("\n")).not.toMatch(/\.\.\. \+\d+ more command\(s\)/);
226+
expect(output).not.toMatch(/\.\.\. \+\d+ more command\(s\)/);
226227
for (const tool of tools) {
227-
expect(outputLines.join("\n")).toContain(tool.name);
228+
expect(output).toContain(tool.name);
228229
}
229230
});
230231

@@ -237,10 +238,11 @@ describe("mcp_cli_bridge.cjs", () => {
237238
showHelp("safeoutputs", tools);
238239

239240
const outputLines = stdoutChunks.join("").trimEnd().split("\n");
241+
const output = outputLines.join("\n");
240242
expect(outputLines.length).toBeLessThanOrEqual(20);
241-
expect(outputLines.join("\n")).not.toMatch(/\.\.\. \+\d+ more command\(s\)/);
243+
expect(output).not.toMatch(/\.\.\. \+\d+ more command\(s\)/);
242244
for (const tool of tools) {
243-
expect(outputLines.join("\n")).toContain(tool.name);
245+
expect(output).toContain(tool.name);
244246
}
245247
});
246248

@@ -262,14 +264,15 @@ describe("mcp_cli_bridge.cjs", () => {
262264
]);
263265

264266
const outputLines = stdoutChunks.join("").trimEnd().split("\n");
267+
const output = outputLines.join("\n");
265268
expect(outputLines.length).toBeLessThanOrEqual(30);
266-
expect(outputLines.join("\n")).not.toMatch(/\.\.\. \+\d+ more option\(s\)/);
267-
expect(outputLines.join("\n")).toContain("Required options are marked with *.");
269+
expect(output).not.toMatch(/\.\.\. \+\d+ more option\(s\)/);
270+
expect(output).toContain("Required options are marked with *.");
268271
for (let i = 1; i <= 24; i++) {
269-
expect(outputLines.join("\n")).toContain(`--field_${i}`);
272+
expect(output).toContain(`--field_${i}`);
270273
}
271-
expect(outputLines.join("\n")).toContain("--field_1*");
272-
expect(outputLines.join("\n")).toContain("--field_2*");
274+
expect(output).toContain("--field_1*");
275+
expect(output).toContain("--field_2*");
273276
});
274277

275278
it("does not truncate command help when options exactly fit the line budget", () => {
@@ -290,15 +293,16 @@ describe("mcp_cli_bridge.cjs", () => {
290293
]);
291294

292295
const outputLines = stdoutChunks.join("").trimEnd().split("\n");
296+
const output = outputLines.join("\n");
293297
expect(outputLines.length).toBeLessThanOrEqual(30);
294-
expect(outputLines.join("\n")).not.toMatch(/\.\.\. \+\d+ more option\(s\)/);
295-
expect(outputLines.join("\n")).toContain("Required options are marked with *.");
298+
expect(output).not.toMatch(/\.\.\. \+\d+ more option\(s\)/);
299+
expect(output).toContain("Required options are marked with *.");
296300
for (let i = 1; i <= 13; i++) {
297-
expect(outputLines.join("\n")).toContain(`--field_${i}`);
301+
expect(output).toContain(`--field_${i}`);
298302
}
299303
});
300304

301-
it("keeps required-note when required options are in the compact list", () => {
305+
it("keeps required note when required options are in the compact list", () => {
302306
const properties = {};
303307
for (let i = 1; i <= 24; i++) {
304308
properties[`field_${i}`] = { type: "string", description: `Field ${i}.` };
@@ -316,10 +320,11 @@ describe("mcp_cli_bridge.cjs", () => {
316320
]);
317321

318322
const outputLines = stdoutChunks.join("").trimEnd().split("\n");
319-
expect(outputLines.join("\n")).not.toMatch(/\.\.\. \+\d+ more option\(s\)/);
320-
expect(outputLines.join("\n")).toContain("Required options are marked with *.");
321-
expect(outputLines.join("\n")).toContain("--field_23*");
322-
expect(outputLines.join("\n")).toContain("--field_24*");
323+
const output = outputLines.join("\n");
324+
expect(output).not.toMatch(/\.\.\. \+\d+ more option\(s\)/);
325+
expect(output).toContain("Required options are marked with *.");
326+
expect(output).toContain("--field_23*");
327+
expect(output).toContain("--field_24*");
323328
});
324329

325330
describe("stdin placeholder removed — '-' is always a literal value", () => {

0 commit comments

Comments
 (0)