fix(events): preserve a non-UTF-8 config.toml on hook install/teardown - #3963
Open
marcelsafin wants to merge 1 commit into
Open
fix(events): preserve a non-UTF-8 config.toml on hook install/teardown#3963marcelsafin wants to merge 1 commit into
marcelsafin wants to merge 1 commit into
Conversation
_merge_toml_fragment() and _remove_toml_entries() read the user's config.toml with bare read_text() calls, so a non-UTF-8 (or otherwise unreadable) file crashed install_integration_events() and remove_integration_events() with a raw UnicodeDecodeError — and the merge path regenerates the file from what it read, so it would have discarded the user's bytes had it not crashed first. Every JSON merge/remove path already goes through _load_user_json(), which skips on an unreadable file to preserve user content (github#22). Abort the merge (returning False so the caller skips tracking, S5) and skip the teardown cleanup with a warning, leaving the user's bytes untouched in both directions. Assisted-by: GitHub Copilot (model: claude-fable-5, autonomous) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Prevents Codex hook installation and teardown from corrupting or crashing on unreadable/non-UTF-8 user configuration.
Changes:
- Safely skips TOML merge and cleanup when decoding fails.
- Avoids manifest tracking for skipped merges.
- Adds install and teardown regression tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/specify_cli/events.py |
Handles unreadable TOML while preserving user content. |
tests/integrations/test_events.py |
Tests byte preservation during install and teardown. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Description
_merge_toml_fragment()and_remove_toml_entries()read the user'sconfig.toml(Codex hooks) with bareread_text()calls, so a non-UTF-8 (or otherwise unreadable) file crashesinstall_integration_events()andremove_integration_events()with a rawUnicodeDecodeError— and the merge path regenerates the file from what it read, so it would have discarded the user's bytes had it not crashed first. Every JSON merge/remove path already goes through_load_user_json(), which skips on an unreadable file precisely to preserve user content (#22).Fix:
Falseso the caller skips tracking the untouched file (same S5 contract as_merge_copilot_json), leaving the user's bytes intact;Testing
uv run specify --helpuv sync && uv run pytest(6,311 passed, 176 skipped)config.toml, teardown after the config was rewritten as non-UTF-8; both fail on main, pass with fix)ruff check src testscleanAI Disclosure
Implemented autonomously by GitHub Copilot CLI (model: Claude Fable 5) under human direction; TDD (failing test first), full suite and lint verified locally. Commit includes
Assisted-by/Co-authored-bytrailers.