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>
This commit is contained in:
Marsel Safin
2026-08-03 16:31:22 -05:00
committed by GitHub
co-authored by Copilot
parent f8b3d604e1
commit ab468c4db7
2 changed files with 21 additions and 2 deletions
+4 -2
View File
@@ -737,8 +737,10 @@ def resolve_events(
if override_file.exists():
try:
override = yaml.safe_load(override_file.read_text(encoding="utf-8")) or {}
except yaml.YAMLError:
logger.warning("Could not parse %s; ignoring override", override_file)
except (OSError, UnicodeError, yaml.YAMLError):
logger.warning(
"Could not read or parse %s; ignoring override", override_file
)
override = {}
integrations = override.get("integrations", {}) if isinstance(override, dict) else {}
if isinstance(integrations, dict) and integration_key in integrations:
+17
View File
@@ -128,6 +128,23 @@ class TestResolveEvents:
)
assert result == {}
def test_unreadable_yaml_override_keeps_prior_layers(self, tmp_path):
"""An unreadable override is ignored like malformed YAML."""
override_file = tmp_path / ".specify" / "integration-events.yml"
override_file.parent.mkdir(parents=True, exist_ok=True)
override_file.write_bytes(b"\xff\xfe")
result = resolve_events(
"claude",
{"events": {"post_tool_use": {"command": "speckit.tdd.validate"}}},
tmp_path,
None,
)
assert result == {
"post_tool_use": [{"command": "speckit.tdd.validate"}]
}
def test_no_config_no_events(self, tmp_path):
"""Safe fallback with empty config/options."""
result = resolve_events("claude", None, tmp_path, None)