Skip to content

test(amber): cover the PVE websocket endpoint and the missing-interpreter guard - #7847

Merged
aglinxinyuan merged 2 commits into
apache:mainfrom
aglinxinyuan:cov/pve-websocket-endpoint
Aug 22, 2026
Merged

aglinxinyuan merged 2 commits into
apache:mainfrom
aglinxinyuan:cov/pve-websocket-endpoint

Conversation

@aglinxinyuan

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

A new spec for PveWebsocketResource.scala, which had none, plus one test for PveManager.deletePackages' missing-interpreter guard. 43 → 47 tests.

File Before After
PveWebsocketResource.scala 0/9 lines (0%) 9/9 (100%)

That 9-line figure is the only gain this PR can measure locally, and the PveManager half is CI-only. Measured before and after, PveManager.scala is bit-for-bit unchanged locally: 170/228 lines, 154/228 branch-complete, 40/140 branches. The reason is that local Windows coverage of that file is the mirror image of CI's — the interpreter is never found here, so PveResourceSpec's 6 pre-existing failures already take both guards' true arms incidentally. On Linux those are precisely the missed arms. On CI the bundle adds 4 fully-covered lines (453, 454, 525, 527) and completes 2 branch arms (452, 524); since Codecov counts a line with any missed arm as missed, those two arms are themselves 2 more fully-covered lines, so 15 lines on Codecov's metric, 13 of which go missed → covered.

Line 526 stays partial permanently: logger.error(msg) expands to LazyLogging's one-sided if (isErrorEnabled).

Attribution was measured per spec with suite-name filters, not inferred. PveWebsocketResourceSpec owns all 9 lines of the websocket file and PveManager 453/454 with arm 452; the deletePackages test owns 521/522/525/527 with arm 524. The two owned sets do not overlap.

What adversarial review changed

The first draft reported 8 mutations and 0 survivors. Re-derived independently, it was 14 mutations with 4 survivors, and two of the four were real defects rather than equivalent mutants:

  • Setting the pump's done flag to false passed every test. That is not equivalent: with the flag never set, the pump re-enters queue.take() after session.close() and parks forever, because nothing further is ever enqueued — leaking one global-EC thread per websocket connection. The blind spot was the fixture, which stubbed isOpen as always-true and close() as a counter, so neither termination condition was observable. Now the fixture counts guard evaluations: the guard reads the session exactly n times for an n-line sentinel-terminated stream, because the (n+1)th pass short-circuits on the flag, so a third read can only happen under the mutant. All three tests now kill it.
  • The catch arm's [ERR] ${e.getMessage} could be replaced by a constant and survive, and the finally sentinel was only ever exercised on the happy path. A new test passes an empty packages list, so .get(0) throws inside the Future — before PveManager is entered at all, needing no fake runner. It pins the catch arm and makes "the client always gets a sentinel even when the action blows up" a proven claim rather than a happy-path inference.

One new test was dropped as redundant, proven by measurement rather than argument: PveWebsocketResourceSpec alone already covers the whole line set the dropped installUserPackages test owned, and under the mutation that deletes the guard's return, PveResourceSpec's failure count drops from 6 to 4 — it contributes nothing to that kill.

A fixture literal was also deleted: "packages" -> ["colorama==0.4.6","idna"] is unobservable, since the guard returns before the list is read. Two version-pinned strings implying a contract that no test constrains.

Verification

14 mutations, 10 killed, 4 survivors, every survivor listed. The two repaired survivors were each confirmed surviving on the unrepaired bundle first, then confirmed killed after — not assumed.

Mutation Killed by
pump's done = true → done = false all 3 websocket tests, on the guard-evaluation assertion
catch arm message → a constant reports the action's own exception and still sends the sentinel
finally sentinel __DONE__ → __FINISHED__ all 3 websocket tests, including the new failure-path one
if (line == "__DONE__") → != all 3 websocket tests
unknown-action message → a constant reports an unknown action and closes on the sentinel
pveName argument → a literal routes action=install with the cuid and pveName from the handshake
cuid parse → 0 same test, distinct assertion
deletePackages guard message → a constant reports a missing interpreter and stops before the system-package check
deletePackages guard return List(msg) → empty list same test, plus an existing PveResource case
installUserPackages guard return deleted the websocket install test alone

The four survivors, stated plainly. All four are mutant-surviving gaps, not merely uncovered paths:

  • while (!done && session.isOpen) → while (!done) survives: every session in this spec is open for the whole exchange, so that conjunct never decides anything. The pump's guard is pinned at entry only. Killing it needs a closed-session test whose only available assertion is "nothing was sent", which against a Future means a sleep with no event to wait on. (The new guard-evaluation counter does not accidentally cover it — under this mutant isOpen is never called at all.)
  • The missing-action default can be replaced with garbage and survive: all three tests supply action explicitly. Exercising the default means driving action=create, which goes straight to the real process runner — a real venv plus pip install -r amber/requirements.txt.
  • Replacing the parsed package list with Nil, and inverting filter(_.nonEmpty), both survive — the whole 8-line parse chain is unobservable behind the guard's early return.

On the file reaching 100%

Worth qualifying rather than leaving as a headline. Those 9 tracked lines are the straight-line handshake prologue. JaCoCo emits no BRANCH counter element for this file: the class element contains exactly onOpen and <init>, with no $anonfun$onOpen$* lambdas, because every conditional sits inside a Future { … } body that the SyntheticFilter drops. Those conditionals are asserted but not counted, and only 2 of the 4 things action can dispatch to are asserted at all.

Reported, not pinned

onOpen parses cuid outside the Future, so a handshake missing cuid or pveName throws NumberFormatException/NPE straight out of onOpen and the client is told nothing — the catch arm inside the Future cannot see it. The new failure-path test deliberately keeps cuid valid and throws inside the Future, so it pins the catch arm without cementing that behaviour.

No production file is touched.

Any related issues, documentation, discussions?

Closes #7846

How was this PR tested?

sbt "WorkflowExecutionService/testOnly org.apache.texera.web.resource.pythonvirtualenvironment.PveResourceSpec org.apache.texera.web.resource.pythonvirtualenvironment.PveWebsocketResourceSpec"
[info] Tests: succeeded 41, failed 6, canceled 1, ignored 0, pending 0

PveWebsocketResourceSpec is 3/3 green across 5 runs. The 6 failures are pre-existing on Windows and untouched by this change — they are the Scripts/python.exe family, identical by name before and after, and the pre-bundle baseline on this machine is 43 run / 37 succeeded / 6 failed / 1 canceled. The new guard-evaluation assertion carries a bounded 500 ms wait per test, and it is not a race: on correct code the third guard pass short-circuits and never reads the session, so the latch can only be counted down by a mutant.

Test/scalafmtCheck and Test/scalafix --check both pass.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 5)

…eter guard

PveWebsocketResource had no spec: 9 tracked lines at 0%, one call site.
Adds one, plus a test for deletePackages' missing-interpreter guard.

The 9 lines are the only locally measurable gain. PveManager is bit-for-bit
unchanged locally before and after, because Windows never finds the
interpreter, so the pre-existing failures already take both guards' true
arms; on Linux those are the missed arms. On CI the bundle adds 4 covered
lines and completes 2 branch arms.

14 mutations, 10 killed. Two survivors from the first pass were real
defects, not equivalent mutants: setting the pump's done flag to false
parks it in queue.take() forever, leaking a thread per connection, and the
catch arm's message could be replaced by a constant. Both are now pinned --
the first by counting session-guard evaluations, the second by a new test
that throws inside the Future. The four remaining survivors are recorded in
the spec header as mutant-surviving gaps.
Copilot AI lite review requested due to automatic review settings August 22, 2026 11:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @mengw15
    You can notify them by mentioning @mengw15 in a comment.

@github-actions

github-actions Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ No material benchmark regressions detected

🟢 0 better · 🔴 0 worse · ⚪ 15 noise (<±5%) · 0 without baseline

Compared against main b7c33b0 benchmarked on this same runner, so the delta is largely free of cross-runner hardware noise. The "7d avg" column still reflects the gh-pages dashboard. Treat <±5% as noise unless repeated.

Dashboard · Run

config throughput MB/s latency max Δ latest / 7d
⚪ bs=10 sw=10 sl=64 626 0.382 15,491/20,180/20,180 us ⚪ within ±5% / 🔴 +40.3%
⚪ bs=100 sw=10 sl=64 1,339 0.818 71,844/98,191/98,191 us ⚪ within ±5% / 🟢 +23.7%
⚪ bs=1000 sw=10 sl=64 1,530 0.934 652,561/731,091/731,091 us ⚪ within ±5% / 🟢 +36.8%
Baseline details

Latest main b7c33b0 from same runner

config metric PR latest main 7d avg Δ latest Δ 7d
bs=10 sw=10 sl=64 throughput 626 tuples/sec 625 tuples/sec 833.79 tuples/sec +0.2% -24.9%
bs=10 sw=10 sl=64 MB/s 0.382 MB/s 0.381 MB/s 0.509 MB/s +0.3% -24.9%
bs=10 sw=10 sl=64 p50 15,491 us 15,587 us 11,864 us -0.6% +30.6%
bs=10 sw=10 sl=64 p95 20,180 us 20,676 us 14,381 us -2.4% +40.3%
bs=10 sw=10 sl=64 p99 20,180 us 20,676 us 18,035 us -2.4% +11.9%
bs=100 sw=10 sl=64 throughput 1,339 tuples/sec 1,378 tuples/sec 1,083 tuples/sec -2.8% +23.6%
bs=100 sw=10 sl=64 MB/s 0.818 MB/s 0.841 MB/s 0.661 MB/s -2.7% +23.7%
bs=100 sw=10 sl=64 p50 71,844 us 72,243 us 93,077 us -0.6% -22.8%
bs=100 sw=10 sl=64 p95 98,191 us 102,797 us 99,553 us -4.5% -1.4%
bs=100 sw=10 sl=64 p99 98,191 us 102,797 us 108,604 us -4.5% -9.6%
bs=1000 sw=10 sl=64 throughput 1,530 tuples/sec 1,519 tuples/sec 1,119 tuples/sec +0.7% +36.8%
bs=1000 sw=10 sl=64 MB/s 0.934 MB/s 0.927 MB/s 0.683 MB/s +0.8% +36.8%
bs=1000 sw=10 sl=64 p50 652,561 us 659,159 us 909,247 us -1.0% -28.2%
bs=1000 sw=10 sl=64 p95 731,091 us 710,209 us 952,561 us +2.9% -23.2%
bs=1000 sw=10 sl=64 p99 731,091 us 710,209 us 985,186 us +2.9% -25.8%
Raw CSV
config_idx,batch_size,schema_width,string_len,num_batches,total_ms,total_tuples,total_bytes,tuples_per_sec,mb_per_sec,lat_p50_us,lat_p95_us,lat_p99_us
0,10,10,64,20,319.42,200,128000,626,0.382,15490.70,20180.02,20180.02
1,100,10,64,20,1493.18,2000,1280000,1339,0.818,71843.69,98191.22,98191.22
2,1000,10,64,20,13068.10,20000,12800000,1530,0.934,652561.07,731090.88,731090.88

@codecov-commenter

codecov-commenter commented Aug 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.65%. Comparing base (b6a855a) to head (4965a7a).
⚠️ Report is 7 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #7847      +/-   ##
============================================
+ Coverage     91.50%   91.65%   +0.14%     
- Complexity     4499     4511      +12     
============================================
  Files          1174     1173       -1     
  Lines         47356    47352       -4     
  Branches       5307     5307              
============================================
+ Hits          43335    43399      +64     
+ Misses         2356     2289      -67     
+ Partials       1665     1664       -1     
Flag Coverage Δ *Carryforward flag
access-control-service 81.00% <ø> (ø) Carriedforward from cbff5e8
agent-service 98.62% <ø> (ø) Carriedforward from cbff5e8
amber 88.46% <ø> (+0.38%) ⬆️
computing-unit-managing-service 73.67% <ø> (ø) Carriedforward from cbff5e8
config-service 86.73% <ø> (ø) Carriedforward from cbff5e8
file-service 75.74% <ø> (ø) Carriedforward from cbff5e8
frontend 93.23% <ø> (ø) Carriedforward from cbff5e8
notebook-migration-service 79.13% <ø> (ø) Carriedforward from cbff5e8
pyamber 97.52% <ø> (ø) Carriedforward from cbff5e8
workflow-compiling-service 77.19% <ø> (ø) Carriedforward from cbff5e8

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mengw15 mengw15 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Xinyuan Lin <xinyual3@uci.edu>
@aglinxinyuan
aglinxinyuan enabled auto-merge August 22, 2026 22:24
@aglinxinyuan
aglinxinyuan added this pull request to the merge queue Aug 22, 2026
Merged via the queue into apache:main with commit ce0510d Aug 22, 2026
21 checks passed
@aglinxinyuan
aglinxinyuan deleted the cov/pve-websocket-endpoint branch August 22, 2026 22:48
renovate-bot pushed a commit to renovate-bot/apache-_-texera that referenced this pull request Aug 23, 2026
### What changes were proposed in this PR?

`PveWebsocketResource.onOpen` read the handshake parameters in its
prologue, outside the `Future` that owns both the `catch` arm that turns
a failure into an `[ERR]` line and the pump that writes to the socket. A
handshake missing `cuid`, carrying an empty value list for it, or
carrying a non-numeric one threw out of `onOpen` itself, ahead of both —
so the endpoint's own error contract could not see it:

```
Before:  ?pveName=env&action=install  ->  NumberFormatException out of onOpen  ->  socket closes, nothing sent
After:   ?pveName=env&action=install  ->  [ERR] Missing required parameter: cuid  ->  __DONE__
```

The client side makes that silent close worse than a lost message:
`computing-unit-selection.component.ts` clears `isInstalling`/`isLocked`
only when `onmessage` sees `__DONE__`, and there is no `onclose`
handler, so the pip modal stayed locked on "installing" with an empty
log until the user navigated away.

The three reads move inside the `try`, so a malformed handshake now
travels the same path as any other failure — an `[ERR]` line followed by
the sentinel. A `requiredParam` helper rejects an absent key, an empty
value list, and a blank value alike; the last one is reachable from the
wire, since `?pveName=` arrives as `[""]` and used to resolve to a venv
directory named `" "` rather than failing.

| Handshake | Before | After |
| --- | --- | --- |
| no `cuid` | NPE out of `onOpen`, socket closes empty | `[ERR] Missing
required parameter: cuid` then `__DONE__` |
| `cuid` present, value list empty | IndexOutOfBoundsException, same |
same as above |
| `cuid=abc` | NumberFormatException, same | `[ERR] Invalid cuid: abc`
then `__DONE__` |
| `pveName=` (blank) | resolved a venv path with a whitespace name |
`[ERR] Missing required parameter: pveName` then `__DONE__` |

Well-formed handshakes are untouched: the parsed `cuid`/`pveName` reach
`PveManager` exactly as before.

### Any related issues, documentation, discussions?

Follows apache#7847, which added `PveWebsocketResourceSpec` and deliberately
left this path unpinned so that fixing it would not have to fight a test
that had cemented it.

### How was this PR tested?

Four cases added to `PveWebsocketResourceSpec` — `cuid` absent, `cuid`
with an empty value list, a non-numeric `cuid`, and a blank `pveName` —
each asserting the client receives both the `[ERR]` line and the
sentinel, and that the pump stops rather than parking in `queue.take()`.

```bash
sbt "WorkflowExecutionService/testOnly org.apache.texera.web.resource.pythonvirtualenvironment.PveWebsocketResourceSpec"
```

`Tests: succeeded 7, failed 0`. Written before the fix: all four failed
against the old source with the escaping exception itself
(`NullPointerException`, `IndexOutOfBoundsException`,
`NumberFormatException`) rather than an assertion mismatch, which is the
defect stated as a test. Hoisting the reads back out of the `Future`
fails all four again.

Mutation testing on the new code — 4 mutants, 4 killed: dropping the
`values == null` arm, dropping the `isEmpty` arm, hardcoding `cuid` into
the message instead of interpolating the parameter name, and swallowing
a bad `cuid` as `0`.

`PveResourceSpec`, the other suite in the package, is unaffected —
locally it reports 6 pre-existing failures that all come from the
Windows interpreter path (`Scripts\python.exe`), unrelated to the
endpoint.

```bash
sbt scalafmtCheckAll "scalafixAll --check"
```

Clean.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 5)
aglinxinyuan added a commit that referenced this pull request Aug 23, 2026
### What changes were proposed in this PR?

`PveWebsocketResource.onOpen` read the handshake parameters in its
prologue, outside the `Future` that owns both the `catch` arm that turns
a failure into an `[ERR]` line and the pump that writes to the socket. A
handshake missing `cuid`, carrying an empty value list for it, or
carrying a non-numeric one threw out of `onOpen` itself, ahead of both —
so the endpoint's own error contract could not see it:

```
Before:  ?pveName=env&action=install  ->  NumberFormatException out of onOpen  ->  socket closes, nothing sent
After:   ?pveName=env&action=install  ->  [ERR] Missing required parameter: cuid  ->  __DONE__
```

The client side makes that silent close worse than a lost message:
`computing-unit-selection.component.ts` clears `isInstalling`/`isLocked`
only when `onmessage` sees `__DONE__`, and there is no `onclose`
handler, so the pip modal stayed locked on "installing" with an empty
log until the user navigated away.

The three reads move inside the `try`, so a malformed handshake now
travels the same path as any other failure — an `[ERR]` line followed by
the sentinel. A `requiredParam` helper rejects an absent key, an empty
value list, and a blank value alike; the last one is reachable from the
wire, since `?pveName=` arrives as `[""]` and used to resolve to a venv
directory named `" "` rather than failing.

| Handshake | Before | After |
| --- | --- | --- |
| no `cuid` | NPE out of `onOpen`, socket closes empty | `[ERR] Missing
required parameter: cuid` then `__DONE__` |
| `cuid` present, value list empty | IndexOutOfBoundsException, same |
same as above |
| `cuid=abc` | NumberFormatException, same | `[ERR] Invalid cuid: abc`
then `__DONE__` |
| `pveName=` (blank) | resolved a venv path with a whitespace name |
`[ERR] Missing required parameter: pveName` then `__DONE__` |

Well-formed handshakes are untouched: the parsed `cuid`/`pveName` reach
`PveManager` exactly as before.

### Any related issues, documentation, discussions?

Follows #7847, which added `PveWebsocketResourceSpec` and deliberately
left this path unpinned so that fixing it would not have to fight a test
that had cemented it.

### How was this PR tested?

Four cases added to `PveWebsocketResourceSpec` — `cuid` absent, `cuid`
with an empty value list, a non-numeric `cuid`, and a blank `pveName` —
each asserting the client receives both the `[ERR]` line and the
sentinel, and that the pump stops rather than parking in `queue.take()`.

```bash
sbt "WorkflowExecutionService/testOnly org.apache.texera.web.resource.pythonvirtualenvironment.PveWebsocketResourceSpec"
```

`Tests: succeeded 7, failed 0`. Written before the fix: all four failed
against the old source with the escaping exception itself
(`NullPointerException`, `IndexOutOfBoundsException`,
`NumberFormatException`) rather than an assertion mismatch, which is the
defect stated as a test. Hoisting the reads back out of the `Future`
fails all four again.

Mutation testing on the new code — 4 mutants, 4 killed: dropping the
`values == null` arm, dropping the `isEmpty` arm, hardcoding `cuid` into
the message instead of interpolating the parameter name, and swallowing
a bad `cuid` as `0`.

`PveResourceSpec`, the other suite in the package, is unaffected —
locally it reports 6 pre-existing failures that all come from the
Windows interpreter path (`Scripts\python.exe`), unrelated to the
endpoint.

```bash
sbt scalafmtCheckAll "scalafixAll --check"
```

Clean.

Backport notes -- two places where `release/v1.2` differs from the source commit's
branch, so the cherry-pick did not apply as-is:

- `PveManager.createNewPve`/`installUserPackages` still take an `isLocal` flag here, so
  `val isLocal = !KubernetesConfig.kubernetesComputingUnitEnabled` stays in `onOpen`'s
  prologue rather than moving into the `try` with the other three reads. It reads
  configuration, not the handshake, so none of the failure modes this commit fixes can
  originate from it, and the endpoint's error contract is unchanged by where it sits.
- The spec's `pythonBinFor` helper drops the source commit's Windows
  `Scripts/python.exe` arm. This branch's `PveManager.pythonBinPath` resolves
  `bin/python` unconditionally -- the platform split is a later change to `PveManager`
  that this backport does not carry -- so keeping the arm would assert an interpreter
  path the endpoint under test cannot produce.

### Was this PR authored or co-authored using generative AI tooling?

(backported from commit c9a0ddf)

Generated-by: Claude Code (Opus 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cover the PVE websocket endpoint and the missing-interpreter guards

4 participants