-
Notifications
You must be signed in to change notification settings - Fork 37
feat(settings): settings path can be set through command-line #538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| /* | ||
| Copyright 2025 Marc Nuri San Felix | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| describe('CLI module test suite', () => { | ||
| let parseSettingsPath; | ||
| let consoleErrorSpy; | ||
|
|
||
| beforeEach(() => { | ||
| jest.resetModules(); | ||
| consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
| ({parseSettingsPath} = require('../')); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| consoleErrorSpy.mockRestore(); | ||
| }); | ||
|
|
||
| describe('parseSettingsPath', () => { | ||
| test('with no --settings-path flag, should return null', () => { | ||
| // Given | ||
| const args = ['--some-other-flag', 'value']; | ||
| // When | ||
| const result = parseSettingsPath(args); | ||
| // Then | ||
| expect(result).toBeNull(); | ||
| expect(consoleErrorSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('with valid --settings-path, should return the path', () => { | ||
| // Given | ||
| const args = ['--settings-path', '/path/to/settings.json']; | ||
| // When | ||
| const result = parseSettingsPath(args); | ||
| // Then | ||
| expect(result).toBe('/path/to/settings.json'); | ||
| expect(consoleErrorSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('with relative --settings-path, should return the path', () => { | ||
| // Given | ||
| const args = ['--settings-path', './settings.json']; | ||
| // When | ||
| const result = parseSettingsPath(args); | ||
| // Then | ||
| expect(result).toBe('./settings.json'); | ||
| expect(consoleErrorSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('with --settings-path and other flags, should return the path', () => { | ||
| // Given | ||
| const args = ['--no-sandbox', '--settings-path', '/custom/settings.json', '--disable-gpu']; | ||
| // When | ||
| const result = parseSettingsPath(args); | ||
| // Then | ||
| expect(result).toBe('/custom/settings.json'); | ||
| expect(consoleErrorSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('with --settings-path but no value, should return null and log error', () => { | ||
| // Given | ||
| const args = ['--settings-path']; | ||
| // When | ||
| const result = parseSettingsPath(args); | ||
| // Then | ||
| expect(result).toBeNull(); | ||
| expect(consoleErrorSpy).toHaveBeenCalledWith('Error: --settings-path requires a valid file path argument'); | ||
| }); | ||
|
|
||
| test('with --settings-path followed by another flag, should return null and log error', () => { | ||
| // Given | ||
| const args = ['--settings-path', '--no-sandbox']; | ||
| // When | ||
| const result = parseSettingsPath(args); | ||
| // Then | ||
| expect(result).toBeNull(); | ||
| expect(consoleErrorSpy).toHaveBeenCalledWith('Error: --settings-path requires a valid file path argument'); | ||
| }); | ||
|
|
||
| test('with --settings-path containing null byte, should return null and log error', () => { | ||
| // Given | ||
| const args = ['--settings-path', '/path/to/\0settings.json']; | ||
| // When | ||
| const result = parseSettingsPath(args); | ||
| // Then | ||
| expect(result).toBeNull(); | ||
| expect(consoleErrorSpy).toHaveBeenCalledWith('Error: --settings-path contains invalid characters'); | ||
| }); | ||
|
|
||
| test('with empty string after --settings-path, should return null and log error', () => { | ||
| // Given | ||
| const args = ['--settings-path', '']; | ||
| // When | ||
| const result = parseSettingsPath(args); | ||
| // Then | ||
| expect(result).toBeNull(); | ||
| expect(consoleErrorSpy).toHaveBeenCalledWith('Error: --settings-path requires a valid file path argument'); | ||
| }); | ||
|
|
||
| test('with --settings-path at end of args, should return null and log error', () => { | ||
| // Given | ||
| const args = ['--no-sandbox', '--settings-path']; | ||
| // When | ||
| const result = parseSettingsPath(args); | ||
| // Then | ||
| expect(result).toBeNull(); | ||
| expect(consoleErrorSpy).toHaveBeenCalledWith('Error: --settings-path requires a valid file path argument'); | ||
| }); | ||
|
|
||
| test('with path containing spaces, should return the path', () => { | ||
| // Given | ||
| const args = ['--settings-path', '/path with spaces/settings.json']; | ||
| // When | ||
| const result = parseSettingsPath(args); | ||
| // Then | ||
| expect(result).toBe('/path with spaces/settings.json'); | ||
| expect(consoleErrorSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('with path containing special characters, should return the path', () => { | ||
| // Given | ||
| const args = ['--settings-path', '/path/with-special_chars.123/settings.json']; | ||
| // When | ||
| const result = parseSettingsPath(args); | ||
| // Then | ||
| expect(result).toBe('/path/with-special_chars.123/settings.json'); | ||
| expect(consoleErrorSpy).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| Copyright 2025 Marc Nuri San Felix | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * Parses command line arguments to extract the custom settings path. | ||
| * Validates that the value after --settings-path is a valid path and not another flag. | ||
| * | ||
| * @param {string[]} args - Command line arguments array | ||
| * @returns {string|null} The settings path if valid, null otherwise | ||
| */ | ||
| const parseSettingsPath = args => { | ||
| const settingsPathIndex = args.indexOf('--settings-path'); | ||
| if (settingsPathIndex === -1) { | ||
| return null; | ||
| } | ||
|
|
||
| const settingsPathValue = args[settingsPathIndex + 1]; | ||
|
|
||
| // Validate that there is a value and it's not another flag | ||
| if (!settingsPathValue || settingsPathValue.startsWith('--')) { | ||
| console.error('Error: --settings-path requires a valid file path argument'); | ||
| return null; | ||
| } | ||
|
|
||
| // Basic validation: path should not contain null bytes (security) | ||
| if (settingsPathValue.includes('\0')) { | ||
| console.error('Error: --settings-path contains invalid characters'); | ||
| return null; | ||
| } | ||
|
|
||
| return settingsPathValue; | ||
| }; | ||
|
|
||
| module.exports = {parseSettingsPath}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.