Skip to content

feat(ocpp2): add TransactionEvent command support - #1607

Merged
jerome-benoit merged 80 commits into
mainfrom
feat/transaction-event
Feb 20, 2026
Merged

jerome-benoit merged 80 commits into
mainfrom
feat/transaction-event

Conversation

@jerome-benoit

@jerome-benoit jerome-benoit commented Nov 18, 2025 •

Copy link
Copy Markdown
Contributor

PR Checklist

  • Please add a description of your changes.
  • Please ensure title follows conventional commits.
  • We need your changes to come with unit tests in order to keep this project in quality and easy to maintain.
  • If your changes contain any new feature please be sure to document it.
  • Please add a link to the open issue or task that this pull request will resolve.

Does this PR introduce a breaking change?

  • Yes
  • No

If yes please indicate it in the title and add migration info into the documentation.


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

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

This PR adds comprehensive OCPP authentication support and TransactionEvent command functionality for OCPP 2.0. The changes introduce a unified authentication system that works across OCPP 1.6 and 2.0, along with context-aware TransactionEvent handling.

Key changes:

  • Introduces UUIDv4 type for type-safe UUID handling
  • Implements unified authentication architecture with multiple strategies (Local, Remote, Certificate)
  • Adds extensive test coverage for authentication components
  • Implements context-aware TriggerReason selection for OCPP 2.0 TransactionEvents

Reviewed Changes

Copilot reviewed 49 out of 49 changed files in this pull request and generated 20 comments.

Show a summary per file
File Description
ui/web/src/types/UUID.ts Defines UUIDv4 type for standardized UUID format
ui/web/src/composables/Utils.ts Updates UUID utilities to use UUIDv4 type
src/charging-station/ocpp/auth/types/AuthTypes.ts Core authentication type definitions and enums
src/charging-station/ocpp/auth/utils/*.ts Validation and helper utilities for auth
src/charging-station/ocpp/auth/strategies/*.ts Authentication strategy implementations
tests/charging-station/ocpp/auth/**/*.test.ts Comprehensive test suite for auth system
src/types/ocpp/2.0/Transaction.ts OCPP 2.0 TransactionContext interface
tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-TransactionEvent.test.ts TransactionEvent tests

Comment thread ui/web/src/types/UUID.ts Resolved
Comment thread ui/web/src/types/UUID.ts Resolved
Comment thread ui/web/src/types/UUID.ts Resolved
Comment thread ui/web/src/types/UUID.ts Resolved
Comment thread ui/web/src/types/UUID.ts Resolved
Comment thread ui/web/src/types/UUID.ts Resolved
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
Copilot AI review requested due to automatic review settings November 18, 2025 17:24

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 49 out of 49 changed files in this pull request and generated no new comments.

jerome-benoit and others added 8 commits November 18, 2025 19:14
Add InMemoryAuthCache with comprehensive security features:
- LRU eviction when cache reaches capacity
- TTL-based automatic expiration (configurable, default 1h)
- Built-in rate limiting (10 req/min per identifier, configurable)
- Memory usage tracking and comprehensive statistics
- 45 conformance tests covering G03.FR.01 requirements

Security improvements:
- Mitigates S2 (rate limiting prevents DoS on auth endpoints)
- Mitigates S3 (TTL prevents stale authorization persistence)
- Tracks evictions, hits, misses, expired entries

Completes Phase 2.3 (Security Hardening) and G03.FR.01 cache tests.
Update factory, interfaces, and service to support cache integration:
- AuthComponentFactory.createAuthCache() now instantiates InMemoryAuthCache
- Add evictions field to CacheStats interface
- Add rateLimit field to AuthStats interface (blockedRequests, rateLimitedIdentifiers, totalChecks)
- Make OCPPAuthServiceImpl.getStats() async to fetch cache stats from strategies
- Update factory test to expect cache instance

Enables monitoring of cache evictions and rate limiting events.
…cess

Changed test to access token-3 instead of token-1 twice to properly verify
LRU eviction behavior. Now expects token-1 (oldest) to be evicted instead
of token-2.
Add configurable authorization behavior to OCPP 2.0 mock server:
- Whitelist/blacklist mode for token validation
- Offline mode simulation (network failure)
- Rate limiting simulation (NotAtThisTime responses)
- Pre-authorization for remote start transactions
- CLI arguments for runtime configuration

This enables comprehensive testing of:
- G03.FR.02 (offline authorization)
- G03.FR.03 (remote start pre-authorization)
- G03.FR.04 (whitelist/blacklist management)
Add 9 tests for OCPP 2.0 offline authorization scenarios:

G03.FR.02.001 - Offline detection (3 tests):
- Detect station offline when not in accepted state
- Detect station online when in accepted state
- Verify correct OCPP version

G03.FR.02.002 - Remote availability check (2 tests):
- Return false when offline even with valid config
- Handle errors gracefully when checking availability

G03.FR.02.003 - Configuration validation (3 tests):
- Initialize with default configuration
- Validate configuration schema for offline auth
- Monitor offline state via getStatus method

These tests verify the adapter correctly detects offline
state and reports availability for fallback to LocalAuthStrategy.
- Implement 20 unit tests for RequestStartTransaction with pre-authorization
- Cover successful remote start with valid token (G03.FR.03.001)
- Cover remote start rejected with blocked token (G03.FR.03.002)
- Cover remote start with group token validation (G03.FR.03.003)
- Cover remote start without EVSE ID error cases (G03.FR.03.004)
- Cover remote start on occupied connector (G03.FR.03.005)
- Cover remote start with charging profile (G03.FR.03.006)
- Add request validation checks (G03.FR.03.007)
- Add service initialization tests (G03.FR.03.008)
- All tests validate OCPP 2.0.1 data structures
- Update task completion tracking (Phase 2.2: 67% complete)

Effort: 2.5j | Tests: 20 | Status: ✅ All passing
- Mark G03.FR.03 remote start tests complete (20 tests)
- Document G03.FR.04 blocker (SendLocalList not implemented)
- Update Phase 2 completion: 94% (25.5j/27j)
- Total progress: 43j/74j (58%)

Phase 2.2 pragmatically complete with gaps documented.
Copilot AI review requested due to automatic review settings November 24, 2025 11:06

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 52 out of 52 changed files in this pull request and generated no new comments.

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
Copilot AI review requested due to automatic review settings November 24, 2025 11:23

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 54 out of 54 changed files in this pull request and generated 2 comments.

Comment thread ui/web/src/composables/Utils.ts Resolved
Comment thread ui/web/src/types/UUID.ts Resolved
jerome-benoit and others added 24 commits February 17, 2026 21:21
Mock isRemoteAvailable and sendTransactionEvent to avoid singleton
dependency issues that cause test failures on Windows CI environment.
The OCPP20VariableManager singleton behaves differently across platforms,
and mocking isolates unit tests from runtime dependencies.
Ensure transactionEvseSent and transactionIdTokenSent are reset
alongside transactionSeqNo to prevent test order dependencies
across platforms (fixes Windows CI failures).
…ile validation

- Add validateIdentifierString() for OCPP 2.0.1 identifier validation
- Accept non-empty string ≤36 chars for transactionId (UUID is RECOMMENDED)
- Enforce TxProfile purpose for RequestStartTransaction (OCPP 2.0.1 §2.10)
- Reject chargingProfile.transactionId in RequestStartTransaction
- Add comprehensive unit tests for new validation logic
…2.0.1 E02.FR.09/10)

Implements periodic transaction event transmission at configurable TxUpdatedInterval:

- Add transactionTxUpdatedSetInterval field to ConnectorStatus type
- Implement startTxUpdatedInterval() and stopTxUpdatedInterval() methods
- Export OCPP20TransactionEventEnumType and OCPP20TriggerReasonEnumType
- Export OCPP20ServiceUtils from ocpp/index.ts
- Timer lifecycle: starts on RequestStartTransaction
- Timer cleanup: stops on RequestStopTransaction
- OCPP 2.0 only, guards prevent 1.6 activation
- Safely handles null/undefined connectors and intervals
- Follows E02.FR.09/10 specification

All tests passing (121/121), lint passing, build successful.
…ne queueing

- Add comprehensive tests for TxUpdatedInterval timer lifecycle (start/stop)
- Test MeterValuePeriodic trigger reason for periodic TransactionEvents
- Verify seqNo increment across periodic events
- Test independent timers per connector
- Add offline queueing tests for WebSocket disconnection scenarios
- Test seqNo preservation in queued events
- Verify FIFO queue drain order on reconnection
- Test seqNo continuity across online→offline→online transitions
- Test independent queues per connector
- Remove unnecessary eslint-disable camelcase directive
- Fix unused parameter warning with underscore prefix
- Rename variables from snake_case to camelCase
Add setInstanceForTesting() method to OCPPAuthServiceFactory to allow
tests to inject mock auth services without relying on ESM module
internals. This fixes Windows CI failures caused by ESM module caching
differences between platforms.

Changes:
- Add OCPPAuthServiceFactory.setInstanceForTesting() static method
- Update createMockAuthService() to return proper OCPPAuthService type
- Update RequestStartTransaction tests to use new method
- Update RequestStopTransaction tests to use new method
- Remove dynamic import workarounds that failed on Windows
…factory

- Add globalThis-based instance sharing to OCPPAuthServiceFactory
  Required for cross-module mock injection with dynamic imports
- Add missing mock methods to ChargingStationFactory:
  - isWebSocketConnectionOpened() - prevents offline queueing in tests
  - getNumberOfEvses() - required for EVSE validation
  - startTxUpdatedInterval() / stopTxUpdatedInterval() - for timer tests
- Remove redundant null check in validateChargingProfile()
  TypeScript types guarantee id and stackLevel are always present
…plementation

The test incorrectly expected UUID format validation, but the actual
OCPP 2.0.1 spec and implementation only validates identifier strings
(non-empty, ≤36 characters). Updated test to use a >36 char string and
expect the correct error message.
…entQueue from serialization

The new connector status fields transactionTxUpdatedSetInterval (NodeJS.Timeout)
and transactionEventQueue (runtime queue) cannot be serialized to JSON and must
be excluded when saving charging station configuration.
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed for 'e-mobility-charging-stations-simulator-webui'

Failed conditions
28.6% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed for 'e-mobility-charging-stations-simulator'

Failed conditions
4.3% Coverage on New Code (required ≥ 80%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@jerome-benoit
jerome-benoit merged commit 369acbe into main Feb 20, 2026
34 of 36 checks passed
@jerome-benoit
jerome-benoit deleted the feat/transaction-event branch February 24, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants