Fix the accessibility audit for a deploy status badge

Review the AI's codeMedium15 minMicrosoft style

Your task

An AI generated a deploy status indicator: a pastel green or red dot with the word Passing or Failing. The pull request screenshot looks polished. But the label barely shows on white, and a screen reader stays silent when the status flips. Your team now runs every status indicator through an audit.

An assistant wrote audit_status_indicator(foreground_hex, background_hex, visible_text, aria_role). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • foreground_hex: the text color, like "#1b5e20".
  • background_hex: the background color.
  • visible_text: the indicator's visible text.
  • aria_role: the element's ARIA role, or "".
  • Return the problem codes found, sorted by plain character order. An empty list means the indicator passes.

Rules the tests check:

  • "color-only": visible_text is empty after trimming whitespace, so the colored dot is the only cue.
  • To parse a color, trim it and drop one leading #. Three hex digits are shorthand, so fff means ffffff. The result must be exactly 6 hex digits: 0 to 9 and a to f, in either case.
  • "unknown-color": either color does not parse. Then there is no contrast check.
  • "low-contrast": both colors parse and their contrast ratio is below 4.5, the WCAG AA minimum for normal text.
  • The contrast ratio follows WCAG 2. For each channel, c is the value divided by 255. Convert it to c / 12.92 when c is at most 0.03928, and otherwise to ((c + 0.055) / 1.055) raised to the power 2.4. A color's luminance is 0.2126 R + 0.7152 G + 0.0722 B, using the converted channels. The ratio is (lighter luminance + 0.05) / (darker luminance + 0.05).
  • "not-announced": the role, trimmed and lowercased, is neither status nor alert. Only those roles make a screen reader announce a change.

Examples

audit_status_indicator(foreground_hex: str, background_hex: str, visible_text: str, aria_role: str) -> list[str]
Example 1
Inputaudit_status_indicator("#9be89b", "#ffffff", "Passing", "")
Output["low-contrast", "not-announced"]
Example 2
Inputaudit_status_indicator("#1b5e20", "#ffffff", "Passing", "status")
Output[]
Example 3
Inputaudit_status_indicator("#f5a3a3", "#ffffff", "", "status")
Output["color-only", "low-contrast"]