Repository navigation
feat: publish display labels for built-in event keys in capabilities - #713
all-hands-bot wants to merge 1 commit into
Conversation
A setup UI can only show event keys as raw strings today, so users have to guess or memorize keys like 'pull_request.*' or 'pr:opened'. Give every built-in catalog entry a human-readable display name and expose them in GET /v1/capabilities as eventLabelsBySource, keyed exactly like eventTypesBySource. Clients without labels keep showing the raw key.
|
Warning Your comment is too long (maximum is 65536 characters), so the coverage report was not added. See the job log for how to reduce it. |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Scope
In scope: this repository owns the automation service's event catalogs and the /v1/capabilities setup contract, and this PR publishes display labels from those catalogs through that endpoint. The Canvas-side dropdown is correctly tracked separately in OpenHands/OpenHands#19465. Design context in the PR description is adequate: intent, before/after contract shape, and compatibility all covered.
What I verified
- Pattern/label alignment:
event_labels(source)returns keys exactly matchingsupported_event_patterns(source)for all four catalog sources (checked locally). GitHub labels derive from the sameGITHUB_PAYLOAD_CLASSESiteration that produces patterns, so that side cannot drift; the keyed sources raiseKeyErroron drift, matching the stated fail-loudly design. - Contract:
_SetupContractModelcamelCase aliasing applies to the new field (eventLabelsBySourceverified viamodel_dump(by_alias=True)),default_factory=dictkeeps older clients unaffected, and the not-ready path returns{}consistently. - Tests:
tests/test_event_schemas.py— 61 passed locally, including the 5 newTestEventLabelstests. The router suite needs the Postgres testcontainer, which this environment cannot run (as the PR notes); CI'sunit-testsjob covers it and passes.
Blocking finding
The required backend check fails on this head (run 42330710895). The cause is this PR's own new test code: pyright (part of the backend pre-commit job) reports 8 errors in the new TestEventLabels class — event_labels() is typed dict[str, str] | None, and three of the five tests subscript or measure the result without narrowing the None branch. I reproduced all 8 errors locally with uv run pyright, at identical line numbers. The implementation files are pyright-clean (0 errors). This must be fixed before merge; the fix is small (assert the result is not None after each assignment, as the first test already does).
| """Two options with the same name would be indistinguishable.""" | ||
| for source in catalog_sources(): | ||
| labels = event_labels(source) | ||
| assert len(set(labels.values())) == len(labels) |
There was a problem hiding this comment.
Pyright error on this head (CI backend check fails): event_labels(source) is typed dict[str, str] | None, so labels.values() and len(labels) here are flagged (reportOptionalMemberAccess / reportArgumentType). Add assert labels is not None after the assignment, as test_every_supported_pattern_has_a_label already does for its own variables.
| """GitHub actions are free-form, so a pattern's label names the family.""" | ||
| labels = event_labels("github") | ||
|
|
||
| assert labels["pull_request.*"] == "Pull request activity" |
There was a problem hiding this comment.
Pyright errors on this line and the next (CI backend check fails): labels is dict[str, str] | None and is subscripted without narrowing (reportOptionalSubscript). Add assert labels is not None after line 1191.
| bitbucket = event_labels("bitbucket_data_center") | ||
| azure = event_labels("azure_devops") | ||
|
|
||
| assert jira["jira:issue_created"] == "Issue created" |
There was a problem hiding this comment.
Pyright errors on lines 1202–1205 (CI backend check fails): jira, bitbucket, and azure are each dict[str, str] | None and are subscripted without narrowing (reportOptionalSubscript). Add assert ... is not None after each assignment on lines 1198–1200.
Why
The setup UI can only offer event keys as raw strings today (
pull_request.*,pr:opened,jira:issue_created, …), so users configuring an event trigger have to guess, look up, or memorize the right key for their use case. The display names belong next to the catalogs that own the keys, and publishing them in the capabilities response lets any client render well-named options.Context: OpenHands/OpenHands#19465 tracks the Canvas side (a proper dropdown for the event key field). This PR is the backend half: authoritative, human-readable names for every built-in catalog entry.
What
EVENT_TYPE_LABELS/*_EVENT_TYPE_LABELS), alongside the keys they name.openhands/automation/event_schemas/catalog.pygainsevent_labels(source), returning labels keyed exactly likesupported_event_patterns(source)— a pattern missing a label raises, so the two lists cannot drift apart silently.GET /v1/capabilities(the setup contract, camelCase) now returnseventLabelsBySource: Record<source, Record<pattern, label>>alongsideeventTypesBySource. Backward compatible: the field defaults to{}, older clients ignore it, and newer clients against an older service fall back to showing raw keys.GitHub's patterns are families (actions are free-form), so their labels name the family ("Pull request activity"); keyed sources name each key exactly ("Pull request opened").
How I tested it
TestEventLabelsintests/test_event_schemas.py: every supported pattern has a non-empty label (drift guard for future catalog additions), labels are unique per source, spot checks per source, and a source without a catalog returnsNone.tests/test_capabilities_router.pyassertseventLabelsBySourcemirrorseventTypesBySourceper source with the expected names.Note: the full router test suite needs the Postgres testcontainer, which this environment cannot run (no Docker daemon);
tests/test_event_schemas.py::TestEventLabelsand the schema serialization check above cover the change end-to-end at the unit level, and CI runs the container suite.Jev-Fast-Audit
⚡ Jev fast audit · estimates · 0.34s · commit 2e8cb16
Strongest signal: No primary concern selected.
Evidence: No primary concern to locate.
Coverage: complete supplied coverage; 14/14 hunks, 9/9 files.
All estimates and evidence