Repository navigation
feat(simulator): add forceTransactionOnInvalidIdToken template flag - #1907
Conversation
Allow station-initiated transactions to continue even when CSMS replies with a non-Accepted IdToken status (OCPP 1.6 idTagInfo.status, OCPP 2.0.1 idTokenInfo.status). Default false preserves spec-compliant behavior. The flag is non-spec-compliant by design (violates OCPP 2.0.1 E05.FR.09, E05.FR.10, E06.FR.04 when enabled) and is intended for testing edge-case charging station implementations that ignore CSMS rejection. JSDoc on the field warns explicitly; README entry flags it as a non-spec-compliant test override. Scope in OCPP 2.0.1 is limited to TransactionEvent eventType=Started; mid-transaction revocation (Updated/Ended event types) still triggers deauthorization regardless of the flag. The OCPP 2.0.1 \`StopTxOnInvalidId\` device-model variable is left untouched — the template flag short-circuits ahead of the variable's accounting branch. Tests: 16 new test cases across both OCPP namespaces covering force-on/off, mid-tx revocation preservation, override marker log presence, auth cache non-relaxation, pre-Start guard preservation, and full status-enum parity (8 OCPP 2.0.1 statuses). Closes #1826
SummaryThe following content is AI-generated and provides a summary of the pull request: Add
|
| Flag | OCPP 1.6 (idTagInfo.status ≠ Accepted) |
OCPP 2.0.1 Started (idTokenInfo.status ≠ Accepted) |
OCPP 2.0.1 Updated/Ended |
|---|---|---|---|
false (default) |
Abort + reset connector | De-authorize transaction | De-authorize |
true |
Continue transaction + emit warn log | Continue transaction + emit warn log | Still de-authorizes |
Mid-transaction revocation (Updated/Ended event types in OCPP 2.0.1) always tears down regardless of the flag, preserving E05.FR.09 / E05.FR.10 / E06.FR.04 semantics.
Changes
src/types/ChargingStationTemplate.ts: Added optionalforceTransactionOnInvalidIdTokenfield with JSDoc warning documenting the non-spec-compliant nature.src/charging-station/TemplateSchema.ts: Added Zod schema entry for the new optional boolean field.src/utils/Constants.ts: AddedforceTransactionOnInvalidIdToken: falsetoDEFAULT_STATION_INFO.src/charging-station/ocpp/1.6/OCPP16ResponseService.ts: Refactored the Accepted/Rejected branches to share the transaction-success path whenidTokenAccepted || forceTransactionOnInvalidIdToken. Authorization cache update remains unconditional.src/charging-station/ocpp/2.0/OCPP20ResponseService.ts: Extended theisIdTokenAcceptedcheck on theStartedevent type, and added aoverrideRejectiongate to skip deauthorization only foreventType === Started. Emits a distinct override warn-log line with literalforceTransactionOnInvalidIdToken=truefor audit.README.md: Added new row in the configuration table documenting the flag as a non-spec-compliant test override.tests/charging-station/ocpp/1.6/OCPP16ResponseService-ForceTxOnInvalid.test.ts(new): 4 test cases covering force-tx behavior, override marker logging, auth cache preservation, and pre-Start guard integrity.tests/charging-station/ocpp/2.0/OCPP20ResponseService-ForceTxOnInvalid.test.ts(new): 7 test cases including mid-transaction revocation preservation, override marker logging,nullidTokenInfo handling, and parameterized parity across all 8 non-Accepted status enum values.
GitHub Issues
- #1826: [FEATURE] Allow force-run transaction even if it was not accepted by the backend
- 🔄 Regenerate and Update Summary
- ✏️ Insert as PR Description (deletes this comment)
- 🗑️ Delete comment
PR Bot Information
Version: 1.25.0
- LLM:
anthropic--claude-4.6-sonnet - Summary Prompt: Default Prompt
- GithubContextProvider: [FEATURE] Allow force-run transaction even if it was not accepted by the backend #1826
- File Content Strategy: Full file content
- Output Template: Default Template
- Correlation ID:
08a814e5-c5ff-4ee8-9495-2d83b6f2b506 - Event Trigger:
pull_request.opened
There was a problem hiding this comment.
The PR introduces a well-structured and thoroughly tested feature, but there is one critical bug: fixedName?: boolean was accidentally deleted from the ChargingStationTemplate interface while the new field was being inserted — it must be restored to avoid breaking all code that reads stationInfo.fixedName.
PR Bot Information
Version: 1.25.0
- LLM:
anthropic--claude-4.6-sonnet - Agent Instructions:
- File Content Strategy: Full file content
- Correlation ID:
08a814e5-c5ff-4ee8-9495-2d83b6f2b506 - Event Trigger:
pull_request.opened
The forceTransactionOnInvalidIdToken JSDoc rewrite in 73e3358 accidentally deleted the adjacent fixedName?: boolean field on ChargingStationTemplate, breaking 30+ TS errors in CI (ChargingStationNameTemplate Pick keyed on fixedName). Local pnpm test does not run tsc --noEmit, so the regression was invisible until CI. Also fix a CI-only error in OCPP20ResponseService-ForceTxOnInvalid.test.ts: endedConnector is typed as ConnectorStatus | undefined; replace the optional-chain assertions with an explicit if/fail guard so TS narrows the type for the subsequent strict-equal assertions.
Phase-4 review-C MINOR-1: the 2.0-T2 test asserts that \`startUpdatedMeterValues\` is called but stubs the helper, so a wire-level regression where the interval binds to the wrong connector would not be caught. Phase 6 golden-set with the live mock CSMS will close that gap; add a TODO comment to make the deferral explicit. Phase-4 review-C NIT-1: the T7 enum-parity loop omits ConcurrentTx; this is correct (ConcurrentTx is not an IdToken rejection in OCPP 2.0.1) but deserves an inline comment to prevent a future contributor from adding it naively.
PR #1907 — Escalation summary for human review
TL;DRIssue #1826 closed by adding Recommended action: merge. What changed
Loop trail
Total wall-clock: ~3.5 hours (within manifest 4h cap). Risk register statusAll risks from Phase-2 design §7 are mitigated, deferred with rationale, or proven non-issues:
Decisions you should second-check(In autonomous mode these are the items that would have caused escalation; in sync mode you should still glance at them.)
Pitfalls discovered & capitalized into skill v1.3.1The
Plus the existing Cleanup status
What you, human, do now
|
…rify docs Follow-up to #1907 applying post-review fixes from a 3-angle audit (production / types-schema-readme / tests-adversarial). Production (OCPP 2.0): - Simplify defensive `else if (overrideRejection && status !== Accepted)` to `else if (overrideRejection)` in handleResponseTransactionEvent; the second predicate is entailed by the enclosing if/else. - Trim duplicated 5-line comment block down to a 2-line pointer to the canonical JSDoc on ChargingStationTemplate.forceTransactionOnInvalidIdToken. Documentation: - ChargingStationTemplate JSDoc: disambiguate from the OCPP variables StopTransactionOnInvalidId (1.6) and StopTxOnInvalidId (2.0.1) which control mid-transaction stop on revocation and have inverse polarity; state independence from ocppStrictCompliance. - README row: same disambiguation appended to the cell. Tests (OCPP 1.6 ForceTxOnInvalid): - T5 (pre-Start guard): change response status from Accepted to Invalid so the test exercises the flag-vs-guard interaction it claims to lock. - T6 (new): status-enum parity loop via Object.values(OCPP16AuthorizationStatus) excluding Accepted and ConcurrentTx (3 instances: Blocked, Expired, Invalid). - T2: replicate the Phase-6 fake-timer-fence TODO from the sibling 2.0 file (MV pump observability disclosure). - Rename test titles to should [verb] per tests/TEST_STYLE_GUIDE.md \xa71. Tests (OCPP 2.0 ForceTxOnInvalid): - buildTransactionEventRequest: add optional idToken parameter to exercise the auth-cache update path at handleResponseTransactionEvent. - T8 (new): C10.FR.01/04/05 auth-cache invariant test, parametric over [flag=true, flag=false] (2 instances) asserting updateAuthorizationCache is called with the supplied idToken and the CSMS-replied idTokenInfo. - T4 (Ended): add deauth call-count assertion (=== 0); locks the cleanup-runs-before-deauth-gate ordering invariant. The deauth path is reached but no-ops because cleanupEndedTransaction clears transactionId first, so getConnectorIdByTransactionId returns null. A regression that reorders cleanup after the gate (or preserves transactionId on Ended) flips this to 1. - T7 (parity): replace static 8-element array with Object.values(OCPP20AuthorizationStatusEnumType).filter(...). Same 8 instances today; future enum additions are auto-covered. - T6: split into 2 it() blocks (flag-on / flag-off) eliminating the mid-test standardCleanup+remock pattern. Each block additionally asserts that the override-marker warn-log is NOT emitted on null idTokenInfo, locking the invariant against an A6-style regression where the override-marker else-if is hoisted outside the outer null guard. - Rename test titles to should [verb]. Verification: - pnpm typecheck exit 0 - pnpm lint exit 0 - pnpm test: 0 fail across the full suite - 23/23 GREEN on the two ForceTxOnInvalid files (was 17/17; +6 new) - Three mutation experiments confirm regression-detection strength: * Drop `|| forceTransactionOnInvalidIdToken` from OCPP16 gate (line 427): T2 + 3 parity tests fail with `false !== true` on transactionStarted. * Replace `if (requestPayload.idToken != null)` with `if (false)` in OCPP20 cache update (line 519): T8 (both flag states) fails `0 !== 1`. * Bypass the OCPP16 unauthorized-remote-start guard (lines 315-329): T5 only fails (regression-localized to that scenario).
…d log Follow-up to review v2 of #1907 closing the two actionable findings (B4 Low, N1 nit). Two remaining v2 nits (B5 multi-line JSDoc, R3 test cast) are intentionally deferred — rationale in /tmp/pr-1907-review-v2/fixes-design.md. B4 — ChargingStationTemplate.forceTransactionOnInvalidIdToken JSDoc and the matching README row both gain a one-clause disambiguation: "Independent of `ocppStrictCompliance` (operates on response handling, not schema validation)". Mirrors the pattern used by the sibling `outOfOrderEndMeterValues` row (which cites ITS `ocppStrictCompliance` coupling), preventing readers from inferring a non-existent coupling for the new flag. N1 — OCPP20ResponseService.handleResponseTransactionEvent override warn log now reads "...on eventType=Started despite..." (was "...on Started despite..."). The `eventType=` prefix removes ambiguity with OCPP connector state names (Charging, Available) and aligns the log vocabulary with the JSDoc, the inline reference comment, and the test fixture (`requestPayload.eventType === OCPP20TransactionEventEnumType.Started`). The override-marker substring `forceTransactionOnInvalidIdToken=true` is preserved verbatim, so the four test assertions that grep for it remain unaffected. Verification: - pnpm typecheck exit 0 - pnpm lint exit 0 - pnpm test: 0 fail across the full suite - 23/23 GREEN on the two ForceTxOnInvalid files (count unchanged; doc-only changes) - README table re-aligned by prettier on save (column padding shifted 421 -> 460 chars to fit the longer description); diff is mechanical whitespace, content change is one clause.
Three pre-existing post-merge warnings introduced by the squash-merge of #1907 on the file: `tests/charging-station/ocpp/2.0/OCPP20ResponseService-ForceTxOnInvalid.test.ts` - Lines 67-68: `jsdoc/require-param-description` — fill the empty `@param idToken.idToken` and `@param idToken.type` sub-property descriptions auto-inserted by eslint-plugin-jsdoc. - Line 298: `@cspell/spellchecker` — replace "remock" with "re-mock" (English-correct hyphenation, matches existing repo idioms like "re-entrant", "re-export"). Verification: pnpm lint exit 0 with 0 errors / 0 warnings; focused `pnpm test` on the file: 16/16 GREEN (substring assertions unaffected).
Summary
Adds the
forceTransactionOnInvalidIdTokenstation-template boolean (defaultfalse) so the simulator can be configured to continue a transaction even when the CSMS rejects the IdToken. This models real charging stations whose local policy / offline-cache / regulatory mode lets them proceed despite a CSMSInvalid/Blocked/Expired/NoCredit/ etc. response.Closes #1826.
Behaviour
idTagInfo.status≠ Accepted)idTokenInfo.status≠ Accepted)false(default)trueThe OCPP 2.0.1 override is scoped to
eventType=Started: mid-transaction revocation (Updated/Ended event types) always tears down regardless of the flag, preserving E05.FR.09 / E05.FR.10 / E06.FR.04 mid-tx semantics.Spec divergence
This flag is non-spec-compliant by design:
StopTxOnInvalidId(default true) is left untouched. The template flag short-circuits ahead ofrequestDeauthorizeTransactionand therefore also ahead of the variable'sMaxEnergyOnInvalidIdaccounting branch — documented precedence: template flag wins.Both the field's JSDoc and the README entry flag this as a non-spec-compliant test override with a
do NOT enable on production stationswarning.Files changed
src/types/ChargingStationTemplate.ts— new optional field with@warning-style JSDoc.src/charging-station/TemplateSchema.ts— Zod entry.src/utils/Constants.ts—DEFAULT_STATION_INFOdefaultfalse.src/charging-station/ocpp/1.6/OCPP16ResponseService.ts— refactored Accepted/Rejected branches to share the success path underidTokenAccepted || forceTransactionOnInvalidIdToken. Auth cache update stays unconditional. Pre-Start local-state guards (:315-329) untouched.src/charging-station/ocpp/2.0/OCPP20ResponseService.ts— two gates: (a)isIdTokenAcceptedternary in the Started case extended with the flag, (b) deauth gate widened witheventType !== Started || flag !== true. Distinct override warn-log line carrying the literalforceTransactionOnInvalidIdToken=truefor audit.README.md— new row in the configuration table, flagged as non-spec-compliant test override, citing inverted E2E scenarios (P5A authorize, P5B/G19 transaction-start).tests/charging-station/ocpp/1.6/OCPP16ResponseService-ForceTxOnInvalid.test.ts(NEW) — 5 cases (T2 force-tx, T3 override marker, T4 auth-cache untouched, T5 pre-Start guards still abort, plus alphabetical-status default-on test).tests/charging-station/ocpp/2.0/OCPP20ResponseService-ForceTxOnInvalid.test.ts(NEW) — 7 cases including the parameterised 8-status enum parity (T7).Verification
pnpm formatclean.pnpm lintexit 0 (3 cspell warnings on existing codebase, unrelated).pnpm test: 2769 pass / 0 fail / 6 skipped (pre-existing).pnpm build+pnpm --filter cli buildclean.git checkout HEAD -- src/) and the new tests left in place,pnpm testfails with1 !== 0on deauth-call counts. Re-applying the source restores GREEN.Loop hygiene
Developed via the
agentic-loop-engineeringskill v1.3.0 dogfood:loop-manifest.schema.json(draft-2020-12).Loop manifest, scope, designs, and audit trail under
~/.hermes/loops/issue-1826-force-tx-on-invalid/.