aglinxinyuan opened a new issue, #5665:
URL: https://github.com/apache/texera/issues/5665

   ## Background
   
   `ImageUtility` in `common/workflow-operator` 
(`operator/visualization/ImageUtility.scala`) currently lacks a dedicated 
unit-spec. It is the small helper that emits the Python snippet used by 
visualization operators to base64-encode binary image data into an `<img>` tag. 
The snippet is interpolated into generated Python; any drift in the string 
silently breaks every image-rendering visualization operator.
   
   ```scala
   def encodeImageToHTML(): String = {
     s"""
        |        import base64
        |        try:
        |            encoded_image_data = base64.b64encode(binary_image_data)
        |            encoded_image_str = encoded_image_data.decode("utf-8")
        |        except Exception as e:
        |            yield {'html-content': self.render_error("Binary input is 
not valid")}
        |            return
        |        html = f'<img src="data:image;base64,{encoded_image_str}" 
alt="Image" style="max-width: 100vw; max-height: 90vh; width: auto; height: 
auto;">'
        |""".stripMargin
   }
   ```
   
   ## Behavior to pin
   
   | Surface | Contract |
   | --- | --- |
   | `encodeImageToHTML` | returns a non-empty String |
   | Snippet imports `base64` | the substring `"import base64"` appears |
   | Snippet calls `base64.b64encode(binary_image_data)` | the substring 
appears verbatim |
   | Snippet decodes to UTF-8 | the substring `'.decode("utf-8")'` appears |
   | Snippet emits an `<img>` tag with `data:image;base64,...` | the substring 
`'data:image;base64,{encoded_image_str}'` appears (verifies the f-string 
template) |
   | Snippet handles binary-decode failure via a `try/except` block | the 
substring `"except Exception"` and `"Binary input is not valid"` both appear |
   | Determinism | two calls return the exact same string (no random / 
timestamp content) |
   | Snippet contains a top-level `html =` assignment | the substring `"html = 
f"` appears so downstream code can reference `html` |
   
   ## Scope
   
   - New spec file: `ImageUtilitySpec.scala` (matches the 
`<srcClassName>Spec.scala` convention).
   - Pin by `contains` on the canonical substrings above — that's resilient to 
incidental whitespace changes while still catching real drift.
   - No production-code changes.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to