Skip to content

Commit e73221f

Browse files
committed
fix(cli): handle i18n object category names in formatCategories
A category name could arrive as an i18n object ({en, zh}) the same way tool descriptions already do. Reuse stringifyDesc for the name and only fall back to slug when it is a string, so tags never render as [object Object].
1 parent 86ca18a commit e73221f

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

packages/cli/src/output/formatter.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,10 @@ function formatCategories(categories) {
298298
for (const c of categories) {
299299
let label = "";
300300
if (typeof c === "string") label = c;
301-
else if (c && typeof c === "object") label = c.name || c.slug || "";
302-
label = String(label).trim();
301+
else if (c && typeof c === "object") {
302+
label = stringifyDesc(c.name) || (typeof c.slug === "string" ? c.slug : "");
303+
}
304+
label = label.trim();
303305
if (!label) continue;
304306
const key = label.toLowerCase();
305307
if (seen.has(key)) continue;

packages/cli/test/formatter.test.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ test("formatDiscoverResult renders object categories as names, not [object Objec
3030
assert.ok(output.includes("tags: finance, Market Data, slug-only"));
3131
});
3232

33+
test("formatDiscoverResult renders i18n object names via their string values", () => {
34+
const output = formatDiscoverResult(
35+
discoverResultWith([
36+
{ slug: "fx", name: { en: "Foreign Exchange", zh: "外汇" } },
37+
{ slug: "rates", name: { zh: "利率" } },
38+
{ slug: "crypto-fallback", name: {} },
39+
]),
40+
);
41+
assert.ok(!output.includes("[object Object]"));
42+
assert.ok(output.includes("tags: Foreign Exchange, 利率, crypto-fallback"));
43+
});
44+
3345
test("formatDiscoverResult still renders string categories", () => {
3446
const output = formatDiscoverResult(discoverResultWith(["finance", "market-data"]));
3547
assert.ok(output.includes("tags: finance, market-data"));

0 commit comments

Comments
 (0)