mirror of
https://github.com/ChromeDevTools/chrome-devtools-mcp.git
synced 2026-09-28 11:22:57 +08:00
fix(config): preserve raw values for config coercion (#2747)
Fixes #2746. Returning the inner yargs parser result applies option coercers twice, so JSON-configured viewport and wsHeaders fail. Returning the original JSON values after strict validation lets the outer parser coerce them once and preserves CLI overrides. Tests: npm run test -- tests/cli.test.ts and npm run check-format pass. The full npm run test reaches five unrelated PWA failures because the test server cannot bind 0.0.0.0:10236 with EACCES on this Windows host.
This commit is contained in:
@@ -456,7 +456,7 @@ export function parser(
|
||||
throw new Error('Config must be a JSON object');
|
||||
}
|
||||
|
||||
return yargs()
|
||||
yargs()
|
||||
.parserConfiguration({
|
||||
'strip-aliased': true,
|
||||
'camel-case-expansion': false,
|
||||
@@ -467,6 +467,7 @@ export function parser(
|
||||
.fail(false)
|
||||
.exitProcess(false)
|
||||
.parseSync([]);
|
||||
return parsed;
|
||||
} catch (err) {
|
||||
throw new Error(`Invalid JSON config file: ${(err as Error).message}`);
|
||||
}
|
||||
|
||||
@@ -487,6 +487,34 @@ describe('cli args parsing', () => {
|
||||
assert.strictEqual(args.categoryMemory, true);
|
||||
});
|
||||
|
||||
it('applies config coercion for viewport and wsHeaders', async () => {
|
||||
using testConfig = createTempFile(
|
||||
JSON.stringify({
|
||||
wsEndpoint: 'ws://127.0.0.1:9222/devtools/browser/abc123',
|
||||
wsHeaders: '{"Authorization":"Bearer token"}',
|
||||
viewport: '1280x720',
|
||||
}),
|
||||
'cd4a.test.config.coercion.json',
|
||||
);
|
||||
const args = parseArguments(['--config', testConfig.path]);
|
||||
assert.deepStrictEqual(args.viewport, {width: 1280, height: 720});
|
||||
assert.deepStrictEqual(args.wsHeaders, {Authorization: 'Bearer token'});
|
||||
});
|
||||
|
||||
it('lets cli options override coerced config values', async () => {
|
||||
using testConfig = createTempFile(
|
||||
JSON.stringify({viewport: '1280x720'}),
|
||||
'cd4a.test.config.coercion-override.json',
|
||||
);
|
||||
const args = parseArguments([
|
||||
'--config',
|
||||
testConfig.path,
|
||||
'--viewport',
|
||||
'800x600',
|
||||
]);
|
||||
assert.deepStrictEqual(args.viewport, {width: 800, height: 600});
|
||||
});
|
||||
|
||||
it('parses config should not allow no prefix', async () => {
|
||||
using testConfig = createTempFile(
|
||||
JSON.stringify({
|
||||
|
||||
Reference in New Issue
Block a user