]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commit
fix(charging-station): retain creation options so a reset keeps station identity...
authorDaniel <7558512+DerGenaue@users.noreply.github.com>
Fri, 17 Jul 2026 17:10:37 +0000 (19:10 +0200)
committerGitHub <noreply@github.com>
Fri, 17 Jul 2026 17:10:37 +0000 (19:10 +0200)
commit723aab3ddb9ca84480d7adc5b726e8eb73503df2
treec4ddddf9be8295564afa7dd88f513d8b7d92ea96
parent6f7bcb64be5467894e595dbdc9d3ad4703fb1541
fix(charging-station): retain creation options so a reset keeps station identity (#2019)

* fix(charging-station): retain creation options so a reset keeps station identity

On an OCPP Reset (and on a template-file reload) the station was
re-initialized via initialize() with no arguments, dropping the
creation-time options. The restarted station reverted to the template
defaults, losing its fixed identity (reappearing as CS-BASIC-000N with a
new hashId) and its configured supervision URL; the original station
never came back.

Retain the creation options on the instance and re-pass them in reset()
and in the template-watcher reload. setSupervisionUrl() also updates the
retained snapshot so a runtime supervision-URL change survives a reboot
(but not a full simulator restart, which reconstructs the worker from the
original options). The snapshot is in-memory only: it is never persisted
and never written to the template.

Closes #2017.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Daniel <7558512+DerGenaue@users.noreply.github.com>
* fix(charging-station): clone the retained creation options

setSupervisionUrl updates the retained options in place so a later reset
re-applies the current supervision URL. Clone them at construction so that
in-place update never mutates the shared worker data passed from the worker
thread.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Daniel <7558512+DerGenaue@users.noreply.github.com>
* test(charging-station): cover identity retention across a reset

A non-persistent station keeps its configured identity across a reset only
when the creation options are re-applied; a persistent one restores it from
its saved configuration without them. This locks the behavior and scopes the
options fix to the non-persistent case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Daniel <7558512+DerGenaue@users.noreply.github.com>
* refactor(charging-station): re-apply retained options on reset only when non-persistent

Address review feedback on the identity-retention fix:
- Rename the retained-options field to creationOptions (clearer; no longer
  shadows the options parameters).
- Re-apply the creation options on reset/template-reload only for a
  non-persistent station, via the reinitializeOptions getter. A persistent
  station restores from its saved config, which stays the source of truth, so
  re-applying them would needlessly override it (and collapse an OCPP-config
  station's supervision URL). The unconditional setSupervisionUrl mirror is kept,
  with a sharpened comment explaining why it must run for both branches.
- Cover the reset -> initialize wiring (both persistence modes) and the
  setSupervisionUrl-across-reset retention with unit tests.

No change to the fixed behavior: a reset still keeps the configured identity.

* refactor(charging-station): factor setSupervisionUrl credential updates into a helper

Deduplicate the supervisionUser/supervisionPassword null-checks that were
applied twice (to stationInfo and to the retained creation options) into a
single applyCredentials() closure. No behavior change.

* test(charging-station): cover OCPP-config supervision URL retention across reset

- Add a regression test for the non-persistent supervisionUrlOcppConfiguration
  path: after setSupervisionUrl(), a real reset() must still dial the new URL
  (the branch the setSupervisionUrl mirror comment reasons about, previously
  untested).
- Prefix all test titles with "should" per tests/TEST_STYLE_GUIDE.md.
- Clear the real SharedLRUCache singleton in afterEach so a cached template
  cannot bleed between tests.
- Support optional template field overrides in the makeTemplate helper.

* refactor(charging-station): rename reinitialization getter and fix its mirror comment

- Rename the reinitializeOptions getter to reinitializationOptions (noun form,
  consistent with the wsConnectionUrl/hasEvses getters).
- Correct the setSupervisionUrl mirror comment: the retained-options mirror is
  load-bearing on a cache-cold reinitialization (template reload), not on a plain
  warm-cache reset() (whose in-place OCPP-key cache mutation already carries the
  URL). No behavior change.

* test(charging-station): add a genuine OCPP-config supervision-URL reload guard

The previous OCPP-config test drove a warm-cache reset() and passed even with the
retained-options mirror deleted (a false guard): the cached template still carried
the mutated OCPP key. Add a cache-cold reload test (clear SharedLRUCache, then
reinitialize) that re-seeds the key from configuredSupervisionUrl and therefore
fails if the mirror is removed. Relabel the warm-cache reset test and correct its
comment to reflect that it exercises the cache-mutation path, not the mirror.

* docs(charging-station): tighten the setSupervisionUrl mirror comment

Condense the retained-options mirror comment (~11 -> 8 lines) while preserving
every load-bearing detail: it runs for both branches, a cache-cold reload
re-seeds the OCPP key from configuredSupervisionUrl, a warm reset() survives via
the cached template mutation, and the mirror is in-memory only.

---------

Signed-off-by: Daniel <7558512+DerGenaue@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
tests/charging-station/ChargingStation-ResetIdentity.test.ts [new file with mode: 0644]