gh67 - xts validate#71
Conversation
|
I have read the CLA Document and I hereby sign the CLA zghp seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. |
There was a problem hiding this comment.
Pull request overview
Adds a built-in xts validate subcommand to validate .xts files (YAML + basic structural checks) without running commands, along with documentation and tests.
Changes:
- Add CLI handling for
xts validate <file.xts>and implement.xtsfile validation logic. - Add pytest coverage for validate success and common failure modes.
- Document the new validate command in the README.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| test/test_xts_all_cases.py | Adds tests covering xts validate success and error cases (missing file, YAML error, invalid structure). |
| src/xts_core/xts.py | Implements validate command routing and validation helpers for .xts syntax/structure. |
| README.md | Documents xts validate usage and expected exit codes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def _validate_xts_structure(self, node, path='root'): | ||
| if isinstance(node, dict): | ||
| for key, value in node.items(): | ||
| if key == 'command': | ||
| self._validate_command_value(value, f'{path}/command') | ||
| elif isinstance(value, list): | ||
| error( | ||
| f'Invalid .xts structure at "{path}/{key}": ' | ||
| 'lists are not supported in XTS configuration ' | ||
| 'sections' | ||
| ) | ||
| else: | ||
| self._validate_xts_structure(value, f'{path}/{key}') | ||
| elif isinstance(node, list): | ||
| for index, item in enumerate(node): | ||
| self._validate_xts_structure(item, f'{path}[{index}]') | ||
|
|
There was a problem hiding this comment.
We should add a warning to show sections of the xts file that will be ignored by xts, because they do not contain a command key.
| def _validate_command_string(self, value, path): | ||
| for quote_char in ('"', "'"): | ||
| if value.count(quote_char) % 2 == 1: | ||
| error( | ||
| f'Invalid .xts command string at "{path}": ' | ||
| f'unbalanced {quote_char} quote' | ||
| ) | ||
|
|
| if not os.path.exists(xts_file): | ||
| error(f'xts file does not exist: {xts_file}') | ||
|
|
| if remaining_args[0] == 'validate': | ||
| self._run_validate_command(remaining_args[1:]) | ||
|
|
| xts validate /path/to/file.xts | ||
| ``` | ||
|
|
||
| This command reports syntax errors clearly and exits with code `0` for valid files or `1` for invalid files. |
No description provided.