Add --description option for state directory metadata#372
Merged
Conversation
Reviewer's GuideAdds a new --description/-d CLI option and underlying metadata support so state directories can store human-readable descriptions and parent lineage in .newa-metadata.yaml, and surfaces these descriptions in newa list output. The PR introduces a StateMetadata helper, wires description handling into new, copy, extract, and update flows, and adds unit tests and documentation. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The description-handling logic is currently spread across
main,initialize_state_dir, and the copy/extract branches with slightly different code paths; consider centralizing this into a small helper (e.g., inmetadataor a dedicated utility) to reduce duplication and keep the behavior consistent for all state-dir operations. - In
list_cmd,StateMetadata.get_description()reparses the YAML file on each call; if there are many state directories this could become a bottleneck, so consider reading once per directory (or caching insideStateMetadata) instead of callingread()on everyget_description().
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The description-handling logic is currently spread across `main`, `initialize_state_dir`, and the copy/extract branches with slightly different code paths; consider centralizing this into a small helper (e.g., in `metadata` or a dedicated utility) to reduce duplication and keep the behavior consistent for all state-dir operations.
- In `list_cmd`, `StateMetadata.get_description()` reparses the YAML file on each call; if there are many state directories this could become a bottleneck, so consider reading once per directory (or caching inside `StateMetadata`) instead of calling `read()` on every `get_description()`.
## Individual Comments
### Comment 1
<location path="newa/cli/metadata.py" line_range="19-23" />
<code_context>
+ self.state_dir = state_dir
+ self.metadata_file = state_dir / METADATA_FILENAME
+
+ def read(self) -> dict[str, Any]:
+ """Read metadata from the state directory."""
+ if not self.metadata_file.exists():
+ return {}
+ return yaml_parser().load(self.metadata_file.read_text()) or {}
+
+ def write(self, data: dict[str, Any]) -> None:
</code_context>
<issue_to_address>
**suggestion:** Handle malformed metadata files more defensively
If `.newa-metadata.yaml` is corrupted or partially written, `yaml_parser().load(...)` may raise and prevent commands like `list` from running. Please catch YAML parsing errors here and return `{}` (and optionally log a warning) so a bad metadata file doesn’t break the CLI for that state dir.
Suggested implementation:
```python
def read(self) -> dict[str, Any]:
"""Read metadata from the state directory."""
if not self.metadata_file.exists():
return {}
yaml = yaml_parser()
try:
data = yaml.load(self.metadata_file.read_text()) or {}
except Exception as exc: # be defensive against malformed / partial YAML
logging.getLogger(__name__).warning(
"Failed to parse metadata file %s: %s",
self.metadata_file,
exc,
)
return {}
# Ensure we always return a mapping for callers expecting dict[str, Any]
if not isinstance(data, dict):
logging.getLogger(__name__).warning(
"Metadata file %s did not contain a mapping; ignoring its contents",
self.metadata_file,
)
return {}
return data
```
To compile and run correctly, this change also requires:
1. Adding `import logging` at the top of `newa/cli/metadata.py` if it is not already imported.
2. If your project has a preferred logging pattern (e.g. a module-level `logger = logging.getLogger(__name__)`), you can create and reuse that instead of calling `logging.getLogger(__name__)` inline in the `read` method.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Adds support for human-readable descriptions on state directories, stored in .newa-metadata.yaml files. This helps users distinguish between multiple state directories for the same erratum (e.g., original runs, debug sessions, retests). Features: - New --description/-d option to set description on state directories - Automatic default descriptions for copied/extracted state directories - Displays descriptions in 'newa list' output - Tracks parent state directory for lineage tracking - Support for updating descriptions on existing state directories Usage examples: - New run: newa -d "Full RC1 validation" event --erratum 12345 - Copy: newa -D /path/run-123 --copy-state-dir -d "Debug session" - Extract: newa -E archive.tar.gz -d "From Jenkins job #456" - Update: newa -D /path/run-123 -d "Updated description" Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
9041d80 to
888f6a8
Compare
Collaborator
Author
fixed |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds support for human-readable descriptions on state directories, stored in .newa-metadata.yaml files. This helps users distinguish between multiple state directories for the same erratum (e.g., original runs, debug sessions, retests).
Features:
Usage examples:
Summary by Sourcery
Add support for human-readable metadata on state directories and surface it in CLI behavior and list output.
New Features:
Enhancements:
Tests: