Skip to content

Commit 161c7d5

Browse files
fix
1 parent 056bd86 commit 161c7d5

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

src/config/mcp-options.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,26 @@ export function parser(
553553
return yargsInstance
554554
.config('config', 'Path to JSON configuration file', configPath => {
555555
try {
556-
return JSON.parse(readFileSync(configPath, 'utf-8'));
556+
const parsed = JSON.parse(readFileSync(configPath, 'utf-8'));
557+
if (
558+
typeof parsed !== 'object' ||
559+
parsed === null ||
560+
Array.isArray(parsed)
561+
) {
562+
throw new Error('Config must be a JSON object');
563+
}
564+
565+
return yargs()
566+
.parserConfiguration({
567+
'strip-aliased': true,
568+
'camel-case-expansion': false,
569+
})
570+
.options(options)
571+
.config(parsed)
572+
.strict()
573+
.fail(false)
574+
.exitProcess(false)
575+
.parseSync([]);
557576
} catch (err) {
558577
throw new Error(`Invalid JSON config file: ${(err as Error).message}`);
559578
}

tests/cli.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -479,21 +479,23 @@ describe('cli args parsing', () => {
479479
}),
480480
'cd4a.test.config.mixed.json',
481481
);
482-
const args = parseArguments(['--config', testConfig.path]);
483-
assert.strictEqual(args.config, testConfig.path);
484-
assert.strictEqual(args.categoryMemory, true);
482+
assert.throws(
483+
() => parseArguments(['--config', testConfig.path]),
484+
/Invalid JSON config file: Unknown argument: no-category-memory/,
485+
);
485486
});
486487

487-
it('parses config should allow dashed property`', async () => {
488+
it('parses config should not allow dashed property', async () => {
488489
using testConfig = createTempFile(
489490
JSON.stringify({
490491
headless: true,
491492
'category-memory': false,
492493
}),
493494
'cd4a.test.config.mixed.json',
494495
);
495-
const args = parseArguments(['--config', testConfig.path]);
496-
assert.strictEqual(args.config, testConfig.path);
497-
assert.strictEqual(args.categoryMemory, false);
496+
assert.throws(
497+
() => parseArguments(['--config', testConfig.path]),
498+
/Invalid JSON config file: Unknown argument: category-memory/,
499+
);
498500
});
499501
});

0 commit comments

Comments
 (0)