config command line option - #295
Conversation
…place. Read and parse the supplied configuration file. Due to the possibility of url being in the config file, I moved the checking. Do not let undefined values override earlier values. Added schemas for configuration file processing. Added associated types.
Moved URL checking around a bit. Allow config.url to be missing the protocol.
programmatic API does NOT partially auto-prefix. Emojis are not part of a valid URL. Just throw the error from normalizeUrlScheme.
| } | ||
| } else if (engine === 'webkit') { | ||
| cfg.browser = 'safari'; | ||
| } else { // chromium |
There was a problem hiding this comment.
Can you run npm run prettier on the project? I think some of these minor formatting consistency things will be auto-fixed.
| throw err; | ||
| } | ||
|
|
||
| if (cfgStat.size > 4096) { // Arbitrary size |
There was a problem hiding this comment.
Any particular reason for blocking at > 4096 bytes?
I could see things like headers potentially grow above this.
There was a problem hiding this comment.
Good point.
Arbitrary size, maybe 32K would be better. I was hoping for some guidance.
There was a problem hiding this comment.
32K seems more reasonable.
What kind of situations do you think the size check will help with? People putting incorrect data in there for some reason? Unsure if we need the gate at all.
| ) | ||
| .addOption( | ||
| new Option( | ||
| '--config <string>', |
There was a problem hiding this comment.
Can you update README.md for the new --config option?
|
|
||
| let cfg: LaunchOptions = { url: baseConfig.url || '' }; // Always required | ||
|
|
||
| if (baseConfig.options) { |
There was a problem hiding this comment.
It wasn't immediately obvious to me that the config JSON file should have a top-level options: {} key that all CLI options go into.
After looking at the original issue, I see that this comes from the results\xxx\config.json having a top-level options: {}.
Maybe this can be just documented clearly, with an example, in README.md?
There was a problem hiding this comment.
Pull request overview
This PR adds support for supplying a configuration file to Telescope via a new CLI option (--config <file>), and updates the option resolution flow so CLI flags override values from that config file. It also shifts where defaults are applied (into executeTest) and adjusts URL resolution to allow the URL to come from positional args, --url, or the config file.
Changes:
- Add
--config <file>CLI option and load base configuration from a JSON file. - Introduce Zod schemas/types for the config file shape and options loaded from it.
- Refactor option/default merging and update a couple of programmatic/CLI tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/telescope/src/types.ts | Adds config option and new inferred types for config-file-related schemas. |
| packages/telescope/src/schemas.ts | Adds Zod schemas for config-file input and browser config/options blocks. |
| packages/telescope/src/index.ts | Adds --config flag, loads config in launchTest, and changes URL/default handling in executeTest. |
| packages/telescope/src/config.ts | Adds getBaseConfig() to parse config files and map them into LaunchOptions. |
| packages/telescope/tests/programmatic.test.ts | Updates programmatic URL/error handling expectations. |
| packages/telescope/tests/emulation.test.ts | Removes a test that asserted default browser selection in normalizeCLIConfig. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| export async function launchTest(options: LaunchOptions): Promise<TestResult> { | ||
| try { | ||
| return await executeTest(options); | ||
| const baseConfig = options.config ? getBaseConfig(options.config) : { url: '' }; | ||
| return await executeTest(options, baseConfig); | ||
| } catch (error) { |
There was a problem hiding this comment.
I need help creating a test. I'm not sure where the test config should live.
There was a problem hiding this comment.
I think a clone of params.test.ts that focuses on the --config options would be nice. I haven't written tests for this project yet either! But if you have access to a coding agent, it could probably start with some boilerplate.
Increased max config file size to 32Kb. Do not use `any` during config copying. Do not need so many try/catches since they throw Errors anyways. Cleaned up comments. Copy the URL as-an-argument into options if existing. Some schemas can be a string or false, but not true. Better URL schema checking.
Updated emulation test to use resolveOptions.
| ), | ||
| new Option( | ||
| '--disableJS', | ||
| `Disable JavaScript (default: ${DEFAULT_OPTIONS.disableJS})`) |
There was a problem hiding this comment.
Is there a reason some of the options use .default(xyz) and others describe the default in the description ... (default: xyz)?
|
Thanks for the updates @ozcoder! Lots of the changes look good. Only a few outstanding things left:
Thanks! |
Added the command line option
--config CONFIG_FILENAME. Command line options will override any options set in the configuration file.I've moved some things around, in particular defaults are handled in
executeTest. The URL to test can be in the configuration file or-u URLor as an argument to the command line.Closes #62