Skip to content

Commit ab468c4

Browse files
marcelsafinCopilot
andauthored
fix(events): ignore non-UTF-8 event overrides (#3897)
Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f8b3d60 commit ab468c4

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/specify_cli/events.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,10 @@ def resolve_events(
737737
if override_file.exists():
738738
try:
739739
override = yaml.safe_load(override_file.read_text(encoding="utf-8")) or {}
740-
except yaml.YAMLError:
741-
logger.warning("Could not parse %s; ignoring override", override_file)
740+
except (OSError, UnicodeError, yaml.YAMLError):
741+
logger.warning(
742+
"Could not read or parse %s; ignoring override", override_file
743+
)
742744
override = {}
743745
integrations = override.get("integrations", {}) if isinstance(override, dict) else {}
744746
if isinstance(integrations, dict) and integration_key in integrations:

tests/integrations/test_events.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,23 @@ def test_layer2_empty_events_disables(self, tmp_path):
128128
)
129129
assert result == {}
130130

131+
def test_unreadable_yaml_override_keeps_prior_layers(self, tmp_path):
132+
"""An unreadable override is ignored like malformed YAML."""
133+
override_file = tmp_path / ".specify" / "integration-events.yml"
134+
override_file.parent.mkdir(parents=True, exist_ok=True)
135+
override_file.write_bytes(b"\xff\xfe")
136+
137+
result = resolve_events(
138+
"claude",
139+
{"events": {"post_tool_use": {"command": "speckit.tdd.validate"}}},
140+
tmp_path,
141+
None,
142+
)
143+
144+
assert result == {
145+
"post_tool_use": [{"command": "speckit.tdd.validate"}]
146+
}
147+
131148
def test_no_config_no_events(self, tmp_path):
132149
"""Safe fallback with empty config/options."""
133150
result = resolve_events("claude", None, tmp_path, None)

0 commit comments

Comments
 (0)