]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commit
fix(ui-server): classify broadcast responses without handlers (#1924)
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 24 Jun 2026 20:11:56 +0000 (22:11 +0200)
committerGitHub <noreply@github.com>
Wed, 24 Jun 2026 20:11:56 +0000 (22:11 +0200)
commit84fad8272fe91b8ec3d9ad2162139ab8d87b2f92
treeb929719263a333947df2007c8b881019534547aa
parent2f2dc35dcdecf0f8af93c2100eb865565fb1ff59
fix(ui-server): classify broadcast responses without handlers (#1924)

* fix(ui-server): classify broadcast responses without handlers

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* fix(ui-server): preserve internal broadcast origin

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* fix(ui-server): cleanup broadcast aggregation reliably

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* test(ui-server): ensure late response cleanup

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* refactor(types): introduce UIRequestOrigin enum and widen ProtocolRequestHandler

- Promote 'internal' | 'transport' string-literal union to enum
  UIRequestOrigin { INTERNAL, TRANSPORT } hosted in src/types/UIProtocol.ts.
  Matches SCREAMING_SNAKE_CASE convention used across the file
  (ProcedureName, ResponseStatus, BroadcastChannelProcedureName).
- Promote UIRequestContext interface to src/types/UIProtocol.ts.
- Widen canonical ProtocolRequestHandler with optional context? parameter
  (backwards-compatible).
- Re-export UIRequestOrigin and UIRequestContext from src/types/index.ts.
- Drop the local UIServiceProtocolRequestHandler shadow in AbstractUIService.ts;
  consume the canonical ProtocolRequestHandler.
- Replace inline 'internal' / 'transport' literals at the two AbstractUIService
  defaults and the AbstractUIServer.sendInternalRequest call site.

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* refactor(ui-server): tighten handleProtocolRequest, rename log context, align terminology

- Tighten the canonical ProtocolRequestHandler in src/types/UIProtocol.ts:
  required params (uuid, procedureName, payload) match the runtime invariant
  guaranteed by the ProtocolRequest tuple destructure in requestHandler();
  return union collapses to Promise<ResponsePayload | undefined> | ... | undefined.
- Tighten handleProtocolRequest signature accordingly and drop the dead
  'Invalid protocol request' runtime throw (unreachable: requestHandler only
  calls it after the tuple has been destructured into non-null values).
- Rename interface BroadcastResponseLogContext to
  BroadcastChannelResponseLogContext for symmetry with the
  BroadcastChannel{ProcedureName, RequestContext, ...} family, and export
  it so test helpers can type-check the structured log payload.
- Align log strings in logBroadcastResponseWithoutHandler from
  'transport handler' to 'response handler' to match the public API
  (hasResponseHandler / responseHandlers). Test names and regex matchers
  updated atomically.

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* style(ui-server): rename active to stopped and document rollback invariants

- Rename AbstractUIService.active boolean to stopped (default false, flipped
  by stop()). The branch label 'late broadcast response after UI service
  stop' now matches the field name; the read site at
  logBroadcastResponseWithoutHandler reads as 'if (this.stopped) debug,
  else warn' without needing a comment.
- Invert the two log branches under requestContext == null accordingly:
  the stopped branch leads with debug, the active branch with warn.
- Add a 1-line rationale comment on the try/catch in
  sendBroadcastChannelRequest documenting the bookkeeping/dispatch
  atomicity invariant (rollback the just-recorded context if the worker
  dispatch throws).
- Add a 1-line rationale comment on the try/finally in
  UIServiceWorkerBroadcastChannel.responseHandler documenting the
  aggregation-state release invariant under a sendResponse throw.

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* test(ui-server): extract expectSingleLog, assert log context, regress dispatch rollback

- Add expectSingleLog(mocks, level, pattern, contextShape?) to
  UIServerTestUtils.ts. Collapses the repeated
  'warnMock.length === 0 / debugMock.length === 1 + typeof guard +
  assert.match' block previously duplicated across six broadcast-response
  tests. Accepts an optional structured contextShape that, when provided,
  deep-equals the second logger argument against the
  BroadcastChannelResponseLogContext payload.
- Rewrite the six broadcast-response classification tests to invoke the
  helper. Each test now asserts the full structured log context (origin,
  procedureName, status, uuid, hashIds{Failed,Succeeded}), not just the
  message string — catching regressions that swap origin, drop
  procedureName, or omit hashIds propagation into the log payload.
- Add a new regression test 'should rollback expected responses when
  broadcast dispatch throws' that stubs uiServiceWorkerBroadcastChannel
  .sendRequest to throw, calls service.requestHandler with a broadcast
  procedure, and asserts service.getBroadcastChannelExpectedResponses
  rolled back to 0 — locking the try/catch invariant introduced in this
  PR.

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* refactor(ui-server): address post-design-pass nits

- tests: replace Reflect.get + double 'as never' chain in the broadcast
  dispatch rollback regression test with a typed cast to
  UIServiceWorkerBroadcastChannel. Kills both 'as never' casts and the
  '(): never' return annotation. Field rename now fails the test loudly
  via TS instead of silently mis-testing.
- tests: rename 'should warn on untracked broadcast responses while
  service is active' to '... before service stop' so the test name
  matches the post-rename 'stopped' field vocabulary.
- types: add JSDoc on the new public surface introduced by this PR -
  UIRequestOrigin, UIRequestContext, ProtocolRequestHandler widening
  (UIProtocol.ts), and BroadcastChannelResponseLogContext
  (AbstractUIService.ts). Docs describe contract, not mechanism.

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
---------

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/broadcast-channel/UIServiceWorkerBroadcastChannel.ts
src/charging-station/ui-server/AbstractUIServer.ts
src/charging-station/ui-server/ui-services/AbstractUIService.ts
src/charging-station/ui-server/ui-services/UIService001.ts
src/types/UIProtocol.ts
src/types/index.ts
tests/charging-station/ui-server/UIServerTestUtils.ts
tests/charging-station/ui-server/ui-services/AbstractUIService.test.ts