omi icon indicating copy to clipboard operation
omi copied to clipboard

fix(plugins/omi-stack-overflow-app): handle NoneType in answer owner, support URL question targets, and add test suite

Open shuoYun114 opened this issue 2 months ago • 0 comments

Description

In plugins/omi-stack-overflow-app, several critical edge cases and failure modes lead to unhandled 500 errors and degraded user experience:

  1. Crash on Deleted/Anonymous Users (AttributeError: 'NoneType' object has no attribute 'get'):

    • In _format_answer, the code accessed item.get("owner", {}).get("display_name").
    • When answers are posted by deleted or anonymous users, the Stack Exchange API returns owner: null.
    • Calling .get() on None throws AttributeError: 'NoneType' object has no attribute 'get', causing unhandled 500 error in the chat tool.
  2. Inability to Resolve Question URLs or Conversational IDs:

    • Both get_question and get_top_answers do direct coercion int(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 with question_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).
  3. Dirty Input / Non-finite Coercion:

    • _safe_limit could misbehave when passed NaN, Inf or boolean flags.
    • _safe_tags and _clean_text lacked guards against malformed input payloads and invisible unicode spoofing.
    • _clean_text unescaped HTML before stripping tags, leading to tag-stripping of legitimate code identifiers.
  4. 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

  1. Implement defensive _parse_question_target extracting integer question IDs and auto-detecting Stack Exchange network sites from URLs and conversational strings.
  2. Defensively guard _format_answer against owner: null by verifying isinstance(owner, dict).
  3. Correct _clean_text execution order and sanitize limits against boolean and non-finite types.
  4. Add comprehensive hermetic test suite (26 unit tests) running without external dependencies.
  5. Register omi-stack-overflow-tests under .github/checks-manifest.yaml.

shuoYun114 avatar Sep 18 '26 10:09 shuoYun114