Skip to content

Commit a61bf19

Browse files
author
Zheyuan
committed
fix(settings): display objects as JSON instead of [object Object]
1 parent 5fe81d6 commit a61bf19

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

packages/cli/src/utils/settingsUtils.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,55 @@ describe('SettingsUtils', () => {
734734
);
735735
expect(result).toBe('false');
736736
});
737+
738+
it('should display objects as JSON strings, not "[object Object]"', () => {
739+
vi.mocked(getSettingsSchema).mockReturnValue({
740+
experimental: {
741+
type: 'object',
742+
label: 'Experimental',
743+
category: 'Experimental',
744+
requiresRestart: true,
745+
default: {},
746+
description: 'Experimental settings',
747+
showInDialog: false,
748+
properties: {
749+
gemmaModelRouter: {
750+
type: 'object',
751+
label: 'Gemma Model Router',
752+
category: 'Experimental',
753+
requiresRestart: true,
754+
default: {},
755+
description: 'Gemma model router settings',
756+
showInDialog: true,
757+
},
758+
},
759+
},
760+
} as unknown as SettingsSchemaType);
761+
762+
// Test with empty object (default)
763+
const emptySettings = makeMockSettings({});
764+
const emptyResult = getDisplayValue(
765+
'experimental.gemmaModelRouter',
766+
emptySettings,
767+
emptySettings,
768+
);
769+
expect(emptyResult).toBe('{}');
770+
expect(emptyResult).not.toBe('[object Object]');
771+
772+
// Test with object containing values
773+
const settings = makeMockSettings({
774+
experimental: {
775+
gemmaModelRouter: { enabled: true, host: 'localhost' },
776+
},
777+
});
778+
const result = getDisplayValue(
779+
'experimental.gemmaModelRouter',
780+
settings,
781+
settings,
782+
);
783+
expect(result).toBe('{"enabled":true,"host":"localhost"}*');
784+
expect(result).not.toContain('[object Object]');
785+
});
737786
});
738787

739788
describe('getDisplayValue with units', () => {

packages/cli/src/utils/settingsUtils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,14 @@ export function getDisplayValue(
284284

285285
let valueString = String(value);
286286

287-
if (definition?.type === 'enum' && definition.options) {
287+
// handle object types by stringifying them
288+
if (
289+
definition?.type === 'object' &&
290+
value !== null &&
291+
typeof value === 'object'
292+
) {
293+
valueString = JSON.stringify(value);
294+
} else if (definition?.type === 'enum' && definition.options) {
288295
const option = definition.options?.find((option) => option.value === value);
289296
valueString = option?.label ?? `${value}`;
290297
}

0 commit comments

Comments
 (0)