Skip to content

Commit fec0dec

Browse files
committed
fix: isolate invalid Unicode hook IDs
Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 667230a1-e9fa-4500-a57f-c1c482be2507
1 parent b7284f7 commit fec0dec

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

src/specify_cli/artifacts/_identifiers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ def _encode_hook_component(value: Any, field_label: str) -> str:
109109
raise IdentifierComponentError(
110110
f"Invalid {field_label}: value must not be empty"
111111
)
112-
return quote(value, safe="")
112+
try:
113+
return quote(value, safe="")
114+
except UnicodeEncodeError as exc:
115+
raise IdentifierComponentError(
116+
f"Invalid {field_label}: value cannot be UTF-8 encoded"
117+
) from exc
113118

114119

115120
def _decode_hook_component(value: str, field_label: str) -> str:

tests/test_artifact_command.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,42 @@ def test_flat_and_stack_listings_include_the_same_hook(
17201720
key: value for key, value in enriched.items() if key != "stack"
17211721
}
17221722

1723+
@pytest.mark.parametrize(
1724+
"hooks",
1725+
[
1726+
{
1727+
"before_specify": [{"command": "speckit.healthy.cmd"}],
1728+
"\ud800": [{"command": "speckit.invalid.cmd"}],
1729+
},
1730+
{
1731+
"before_specify": [
1732+
{"command": "speckit.healthy.cmd"},
1733+
{"command": "\ud800"},
1734+
]
1735+
},
1736+
],
1737+
ids=["invalid-event", "invalid-command"],
1738+
)
1739+
def test_invalid_unicode_hook_is_omitted_without_hiding_healthy_hooks(
1740+
self, spec_kit_project: Path, hooks: dict
1741+
):
1742+
_install_extension_with_hooks(
1743+
spec_kit_project,
1744+
"unicode-hooks",
1745+
hooks=hooks,
1746+
)
1747+
1748+
catalog = ArtifactCatalog(spec_kit_project)
1749+
flat_hooks = [row for row in catalog.list_artifacts() if row.kind == "hook"]
1750+
enriched_hooks = [
1751+
row for row in catalog.list_artifacts_with_stack() if row["kind"] == "hook"
1752+
]
1753+
1754+
assert [row.targetCommand for row in flat_hooks] == ["speckit.healthy.cmd"]
1755+
assert [row["targetCommand"] for row in enriched_hooks] == [
1756+
"speckit.healthy.cmd"
1757+
]
1758+
17231759
def test_declared_hook_has_artifact_and_stack_shape(
17241760
self, spec_kit_project: Path
17251761
):

0 commit comments

Comments
 (0)