Repository navigation
test(amber): cover the PVE websocket endpoint and the missing-interpreter guard - #7847
Conversation
…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.
Automated Reviewer SuggestionsBased on the
|
✅ No material benchmark regressions detected🟢 0 better · 🔴 0 worse · ⚪ 15 noise (<±5%) · 0 without baseline
Baseline detailsLatest main
Raw CSVconfig_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 Report✅ All modified and coverable lines are covered by tests. 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
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Xinyuan Lin <xinyual3@uci.edu>
### 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)
### 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)
What changes were proposed in this PR?
A new spec for
PveWebsocketResource.scala, which had none, plus one test forPveManager.deletePackages' missing-interpreter guard. 43 → 47 tests.PveWebsocketResource.scalaThat 9-line figure is the only gain this PR can measure locally, and the PveManager half is CI-only. Measured before and after,
PveManager.scalais 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, soPveResourceSpec'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-sidedif (isErrorEnabled).Attribution was measured per spec with suite-name filters, not inferred.
PveWebsocketResourceSpecowns all 9 lines of the websocket file andPveManager453/454 with arm 452; thedeletePackagestest 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:
falsepassed every test. That is not equivalent: with the flag never set, the pump re-entersqueue.take()aftersession.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 stubbedisOpenas always-true andclose()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.[ERR] ${e.getMessage}could be replaced by a constant and survive, and thefinallysentinel was only ever exercised on the happy path. A new test passes an emptypackageslist, so.get(0)throws inside theFuture— beforePveManageris 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:
PveWebsocketResourceSpecalone already covers the whole line set the droppedinstallUserPackagestest owned, and under the mutation that deletes the guard'sreturn,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.
done = true→done = falsefinallysentinel__DONE__→__FINISHED__if (line == "__DONE__")→!=cuidparse →0deletePackagesguard message → a constantdeletePackagesguardreturn List(msg)→ empty listPveResourcecaseinstallUserPackagesguardreturndeletedThe 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 aFuturemeans a sleep with no event to wait on. (The new guard-evaluation counter does not accidentally cover it — under this mutantisOpenis never called at all.)actiondefault can be replaced with garbage and survive: all three tests supplyactionexplicitly. Exercising the default means drivingaction=create, which goes straight to the real process runner — a real venv pluspip install -r amber/requirements.txt.Nil, and invertingfilter(_.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
onOpenand<init>, with no$anonfun$onOpen$*lambdas, because every conditional sits inside aFuture { … }body that theSyntheticFilterdrops. Those conditionals are asserted but not counted, and only 2 of the 4 thingsactioncan dispatch to are asserted at all.Reported, not pinned
onOpenparsescuidoutside theFuture, so a handshake missingcuidorpveNamethrowsNumberFormatException/NPE straight out ofonOpenand the client is told nothing — the catch arm inside theFuturecannot see it. The new failure-path test deliberately keepscuidvalid and throws inside theFuture, 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?
PveWebsocketResourceSpecis 3/3 green across 5 runs. The 6 failures are pre-existing on Windows and untouched by this change — they are theScripts/python.exefamily, 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/scalafmtCheckandTest/scalafix --checkboth pass.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 5)