omi
omi copied to clipboard
fix(plugins/omi-stack-overflow-app): handle NoneType in answer owner, support URL question targets, and add test suite
Description
In plugins/omi-stack-overflow-app, several critical edge cases and failure modes lead to unhandled 500 errors and degraded user experience:
-
Crash on Deleted/Anonymous Users (
AttributeError: 'NoneType' object has no attribute 'get'):- In
_format_answer, the code accesseditem.get("owner", {}).get("display_name"). - When answers are posted by deleted or anonymous users, the Stack Exchange API returns
owner: null. - Calling
.get()onNonethrowsAttributeError: 'NoneType' object has no attribute 'get', causing unhandled 500 error in the chat tool.
- In
-
Inability to Resolve Question URLs or Conversational IDs:
- Both
get_questionandget_top_answersdo direct coercionint(question_id). - When users or LMMs paste full Stack Overflow or Stack Exchange URLs (e.g., https://stackoverflow.com/questions/11227809/... or https://superuser.com/q/12345), or mention prefix targets (
question: 12345), the tool fails withquestion_id must be an integer. - Missing site inference when a URL specifies a different Stack Exchange network site (e.g.
superuser.com,askubuntu.com,mathoverflow.net).
- Both
-
Dirty Input / Non-finite Coercion:
_safe_limitcould misbehave when passedNaN,Infor boolean flags._safe_tagsand_clean_textlacked guards against malformed input payloads and invisible unicode spoofing._clean_textunescaped HTML before stripping tags, leading to tag-stripping of legitimate code identifiers.
-
Zero Test Coverage & CI Contract Gap:
- There was no hermetic unit test suite verifying the endpoints and helper sanitizers.
- The plugin had no registered test contract in
.github/checks-manifest.yaml.
Proposed Solution
- Implement defensive
_parse_question_targetextracting integer question IDs and auto-detecting Stack Exchange network sites from URLs and conversational strings. - Defensively guard
_format_answeragainstowner: nullby verifyingisinstance(owner, dict). - Correct
_clean_textexecution order and sanitize limits against boolean and non-finite types. - Add comprehensive hermetic test suite (26 unit tests) running without external dependencies.
- Register
omi-stack-overflow-testsunder.github/checks-manifest.yaml.