mengw15 opened a new issue, #7888:
URL: https://github.com/apache/texera/issues/7888
### Task Summary
`AgentService` is at **83.38 % with 28 uncovered lines and 30 half-taken
branches**, and the largest coherent block is its WebSocket lifecycle: opening
the socket, dispatching each inbound message type, and tearing the connection
down. The spec drives the HTTP side well (47 `it()` blocks) but only ever
pushes one shape of socket message through.
`agent.service.spec.ts` already installs a `FakeWebSocket` double via
`vi.stubGlobal`, with an `instances` list and a `latest()` helper, so `new
WebSocket(...)` and `WebSocket.OPEN` already resolve to the double and handlers
can be fired synchronously. Pure EXTEND — the harness is in place, nothing new
to build.
Vitest/jsdom; see `frontend/TESTING.md` and `frontend/AGENTS.md`.
### Behavior to add
**`AgentService`**
(`frontend/src/app/workspace/service/agent/agent.service.ts`, codecov 83.38 % —
EXTEND `agent.service.spec.ts`)
- **`handleWebSocketMessage`** (451–539) — a `switch (message.type)` whose
arms are almost entirely unexercised. Push one message per arm through
`FakeWebSocket.latest().onmessage` and assert the effect:
- `message.workflowContent` (466) — the workflow subject receives the
content.
- `message.step` (478) with the nested `convertedStep.id` guard (498) —
cover a step that carries an id and one that does not.
- `message.state` (517) — the state subject advances.
- the error arm (534) — `notificationService.error(message.error || "Agent
error occurred")`; cover both an explicit message and an absent one so the `||`
fallback is taken.
- the `default` (539) — an unrecognised `message.type` logs the
unknown-type warning and changes nothing.
- **`startStatePolling`** (411–435) —
- the protocol ternary at 411: `window.location.protocol === "https:" ?
"wss:" : "ws:"`. Cover both by stubbing `window.location.protocol` for one test
(restore it in `afterEach`), and assert the URL the double was constructed with.
- the parse-failure path (424) — deliver a payload that is not valid JSON
and assert the service survives and reports it rather than throwing out of the
handler.
- the socket `onerror` path (429).
- the close handler's `if (tracking.websocket === ws)` guard (435) — cover
both the current socket closing and a stale socket closing after it has been
replaced, which must not clear the newer connection.
- **`stopStatePolling`** (548) — the `if (tracking)` guard; call it for a
tracked agent and for an unknown one.
- **`activateAgent`** (580) — `if (!tracking.websocket ||
tracking.websocket.readyState !== WebSocket.OPEN)`; cover no socket, a socket
in a non-open state, and an open socket.
- **`deactivateAgent`** (594–606) — the two early returns (no tracking;
already inactive) and the `if (tracking.websocket)` close branch.
Determinism notes:
- Drive every socket event by invoking the double's handler directly
(`onmessage`/`onerror`/`onclose`); never wait on a real socket or a timer.
- Do **not** add `vi.useFakeTimers()` merely to stop a reconnect timer
firing — a synchronous test body cannot let it run, and layering fake timers
over zone.js's patched `setTimeout` has produced Node-version-dependent
failures. If a test must assert a timer was cleared, spy on
`clearTimeout`/`clearInterval` instead.
- Reset `FakeWebSocket.instances` between tests, and restore
`window.location.protocol` in `afterEach` if a test overrode it.
- `vi.restoreAllMocks()` in `afterEach`; stub `notificationService` rather
than asserting on rendered toasts.
Note several open PRs touch this service (#6211, #6009, #5995, #5928, #5558,
#5275) — rebase before finishing.
### Task Type
- [ ] Refactor / Cleanup
- [ ] DevOps / Deployment / CI
- [x] Testing / QA
- [ ] Documentation
- [ ] Performance
- [ ] Other
--
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]