Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/cli/src/config/settings-validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,34 @@ describe('settings-validation', () => {
expect(result.success).toBe(false);
});

it('should coerce "true" and "false" strings to boolean', () => {
const stringBoolSettings = {
general: {
vimMode: 'true',
enableAutoUpdate: 'false',
},
};

const result = validateSettings(stringBoolSettings);
expect(result.success).toBe(true);
if (result.success && result.data) {
const data = result.data as any;
expect(data.general.vimMode).toBe(true);
expect(data.general.enableAutoUpdate).toBe(false);
}
});
Comment thread
midnight-wonderer marked this conversation as resolved.

it('should still reject other string values for boolean fields', () => {
const invalidSettings = {
general: {
vimMode: '1',
},
};

const result = validateSettings(invalidSettings);
expect(result.success).toBe(false);
});

it('should validate number fields correctly', () => {
const validSettings = {
model: {
Expand Down
14 changes: 12 additions & 2 deletions packages/cli/src/config/settings-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ function buildZodSchemaFromJsonSchema(def: any): z.ZodTypeAny {
return z.string();
}
if (def.type === 'number') return z.number();
if (def.type === 'boolean') return z.boolean();
if (def.type === 'boolean') {
return z.preprocess((val) => {
if (val === 'true') return true;
if (val === 'false') return false;
return val;
}, z.boolean());
Comment thread
midnight-wonderer marked this conversation as resolved.
}

if (def.type === 'array') {
if (def.items) {
Expand Down Expand Up @@ -135,7 +141,11 @@ function buildPrimitiveSchema(
case 'number':
return z.number();
case 'boolean':
return z.boolean();
return z.preprocess((val) => {
if (val === 'true') return true;
if (val === 'false') return false;
return val;
}, z.boolean());
Comment thread
midnight-wonderer marked this conversation as resolved.
default:
return z.unknown();
}
Expand Down