eugenegujing opened a new pull request, #9214:
URL: https://github.com/apache/texera/pull/9214

   ### What changes were proposed in this PR?
   
   **Root cause.** The frontend sends the PVE websocket's `packages` query 
parameter as a JSON array (`virtual-environment.service.ts:104`), but 
`PveWebsocketResource.onOpen` never decoded it: it stripped the brackets, split 
the whole value on every comma and deleted every double quote. A pip 
requirement that itself contains a comma, such as `example>=1,<2`, was 
therefore split into two entries, and pip was run for `example>=1` and for the 
invalid fragment `<2`. JSON escapes were lost the same way, and a truncated 
value was accepted silently.
   
   ```text
   Before:  ["example>=1,<2"] -> strip/split/delete quotes -> 
List("example>=1", "<2") -> two pip runs
   After:   ["example>=1,<2"] -> Jackson List[String]      -> 
List("example>=1,<2")    -> one pip run
   ```
   
   **Before (local main 92e86d420, package `tabulate`, operator `>=`, version 
`0.8,<1`; the frontend sent `packages=["tabulate>=0.8,<1"]`).**
   
   <img width="1456" height="829" alt="01-add-package-tabulate-ge-0 8-lt-1" 
src="https://github.com/user-attachments/assets/0364cd41-1077-44dc-b041-a7608224cede";
 />
   
   <img width="1456" height="829" alt="02-pip-log-first-fragment-tabulate-ge-0 
8-installed" 
src="https://github.com/user-attachments/assets/0d840134-4b10-49f6-9b64-88f05fe392c9";
 />
   
   <img width="1456" height="829" 
alt="03-pip-log-second-fragment-lt-1-invalid-requirement" 
src="https://github.com/user-attachments/assets/19fc1c1b-f8d6-48b7-b49e-37667e3cde57";
 />
   
   **After (this branch, same unit, same input; the environment was re-created 
first).**
   
   <img width="1201" height="726" alt="after-01-add-package-tabulate-ge-0 
8-lt-1" 
src="https://github.com/user-attachments/assets/c1c2ce0f-ffdc-4997-9440-37b38f2aca4d";
 />
   
   <img width="1201" height="726" 
alt="after-02-pip-log-single-requirement-tabulate-ge-0 8-lt-1" 
src="https://github.com/user-attachments/assets/f2c59e98-79b8-495d-b223-ee6b9f5afa64";
 />
   
   <img width="1201" height="726" 
alt="after-03-pip-log-exit-code-0-final-package-list" 
src="https://github.com/user-attachments/assets/1574f8fc-961c-40b9-b546-9f43dad6084a";
 />
   
   **Change.** The decoding moves into a package-private 
`PveWebsocketResource.parsePackages` helper that reads the value with the 
shared `JSONUtils.objectMapper` as `java.util.List[String]`, then trims entries 
and drops blank or null ones as before. A value that is not well-formed JSON or 
not an array of strings raises `IllegalArgumentException("Invalid packages 
parameter: <value>")`, which the existing catch arm turns into the `[ERR] ...` 
line followed by `__DONE__`. An absent parameter still defaults to `[]`, and 
the wire format is unchanged, so no frontend change is needed. A 
present-but-empty `packages=` value is now reported as `[ERR] Invalid packages 
parameter: ` followed by `__DONE__` instead of being treated as no packages; 
the frontend always sends at least `[]`, so only hand-rolled requests see this.
   
   ### Any related issues, documentation, discussions?
   
   Closes #9212
   
   ### How was this PR tested?
   
   Added to `PveWebsocketResourceSpec`:
   
   - `parsePackages` tests: empty array, several entries, one entry containing 
a comma, JSON escapes, trimming plus blank and `null` entries, malformed JSON, 
non-array JSON (object, bare string, nested array), empty value, whitespace 
around the array, non-ASCII and URL-like characters kept unchanged, `[null]`, a 
trailing comma (rejected: the shared mapper keeps Jackson's strict default), 
duplicate entries kept.
   - An `onOpen` test with a truncated `packages` value that asserts the `[ERR] 
Invalid packages parameter: ...` line and the `__DONE__` sentinel.
   
   The spec header's note that the parse chain was unobservable is updated 
accordingly.
   
   ```
   sbt "WorkflowExecutionService/testOnly 
org.apache.texera.web.resource.pythonvirtualenvironment.PveWebsocketResourceSpec"
   ```
   
   - Red (tests against the original parsing extracted unchanged into the 
helper): 11 passed, 10 failed, e.g. `List("example>=1", "<2") was not equal to 
List("example>=1,<2")`.
   - Green (with this change): 21 passed, 0 failed (7 existing + 14 new).
   - Mutation check: dropping the `filter(_.nonEmpty)` from the helper fails 
`trim entries and drop blank or null ones` (20 passed, 1 failed); restoring the 
original comma split inside the helper fails 10 of the 21 (11 passed, 10 
failed); restored afterwards.
   - `sbt WorkflowExecutionService/scalafmtCheck 
WorkflowExecutionService/Test/scalafmtCheck "WorkflowExecutionService/scalafix 
--check" "WorkflowExecutionService/Test/scalafix --check"`: all pass.
   
   ### Was this PR authored or co-authored using generative AI tooling?
   
   Yes. Generated-by: Claude Code (claude-fable-5-1). Co-authored with Claude; 
the author reviewed the change before submission.


-- 
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