[Bounty] Fix Public Holidays dict slice TypeError, country code whitespace validation, and add hermetic tests ( proposed)
Description
In plugins/omi-public-holidays-app/main.py, several edge cases cause unhandled Python exceptions and server errors when interacting with the Nager.Date public API:
-
TypeError: unhashable type: 'slice'on Non-List API Payloads: Inget_public_holidays,get_next_public_holidays, andget_long_weekends, code checked:holidays = await _request_json(...) if not holidays: return ChatToolResponse(...) lines.extend(_format_holiday(item) for item in holidays[: request.limit])If Nager.Date returns an error object as a JSON dictionary (such as
{"status": 404, "title": "Not Found"}when an invalid year or unsupported country code is queried),if not holidays:evaluates toFalse. The sliceholidays[: request.limit]immediately raisesTypeError: unhashable type: 'slice', crashing the endpoint with an uncaught 500 error. -
Lifespan HTTP Client Unavailability:
_request_jsondirectly accessedapp.state.http_client. When endpoints are tested or executed in serverless environments wherelifespanis not invoked, this raisedAttributeError: 'State' object has no attribute 'http_client'. -
Pydantic Validator
mode="before"Missing: Thecountry_codefield is declared asField(..., min_length=2, max_length=2)and uses@field_validator("country_code"). Because Pydantic v2 defaults tomode="after", inputs with leading or trailing whitespace (e.g." US ") fail core validation withString should have at most 2 charactersbefore_normalize_country_codecan strip the whitespace. -
Formatting Helper Defensiveness:
_format_holidayand_format_long_weekendlacked dictionary type guards and safe string coercions for types/bridge days, riskingAttributeErroron unexpected response structures. -
Missing Hermetic Unit Tests: The
omi-public-holidays-appplugin lacked any automated test suite.
Proposed Fix
- Added explicit
isinstance(..., list)checks before slicing inget_public_holidays,get_next_public_holidays, andget_long_weekends. - Added fallback
httpx.AsyncClientinitialization in_request_jsonifapp.state.http_clientis uninitialized or closed. - Added
mode="before"to@field_validator("country_code")acrossHolidayRequest,NextHolidayRequest, andLongWeekendRequest. - Hardened formatting helpers with type guards and safe defaults.
- Added a full hermetic test suite (
test_main.py) with stdlib stubs that passes 100% in clean CI environments, and registered it in.github/checks-manifest.yaml.
Proposed Bounty Reward: $40.00 USD / USDC (per established plugin bug fix bounties)
Receiving EVM Wallet Address (Base): 0xb5aFc89b57Fa8270bB7261348179D28099BEa2a0
I’m taking #13928. I’ll implement the bounded public-holidays input/response hardening and a deterministic hermetic test suite, then open a focused PR with the exact validation results. I’ll keep the change scoped to this issue and will provide payout details privately only after maintainer acceptance.