Repository navigation
test(ocpp): cover OCPP 2.0.1 log/firmware lifecycle supersession and cleanup paths - #1997
Conversation
SummaryThe following content is AI-generated and provides a summary of the pull request: PR Checklist
Does this PR introduce a breaking change?
Test: OCPP 2.0.1 GetLog Supersession & Log-Upload Abort CoverageTest-only PR — zero changes under What's covered
|
| Gap | Status | Action |
|---|---|---|
#1 firmware clearActiveFirmwareUpdate else-branch |
✅ Already covered | None |
#1 log clearActiveLogUpload else-branch |
➕ Added | 2 new tests |
#2 handleRequestGetLog supersession |
➕ Added | 2 new tests |
#3 handleRequestUpdateFirmware supersession |
✅ Already covered | None |
#4 stop() AbortController abort assertion |
➕ Added | 1 new test |
#5 Log-upload AbortController mid-flight abort boundary |
➕ Added | 1 new test |
Verification
pnpm format/pnpm typecheck/pnpm lint— all cleanpnpm test— 2996 → 3002 tests, 0 fail, 6 pre-existing skips (delta = +6)pnpm build— exit 0
Closes #1974
- 🔄 Regenerate and Update Summary
- ✏️ Insert as PR Description (deletes this comment)
- 🗑️ Delete comment
PR Bot Information
Version: 1.27.6
- GithubContextProvider: refactor(ocpp): extract per-station state plumbing into shared OCPPIncomingRequestService base #1983
- GithubContextProvider: fix(ocpp): drive FirmwareStatusNotification trigger from last-sent notification (L01.FR.26) #1981
- GithubContextProvider: Update issue templates #5
- GithubContextProvider: fix(ocpp): guard post-stop() handler dispatch against WeakMap resurrection #1992
- GithubContextProvider: refactor: audit backlog cleanup — JSDoc gaps, physics warning, ATG robustness, comment sweep #1962
- GithubContextProvider: fix(ocpp): guard OCPP 1.6 UpdateFirmware deferred-timer schedule against sealed state writes #1994
- GithubContextProvider: Bump @typescript-eslint/parser from 5.24.0 to 5.25.0 #2
- LLM:
anthropic--claude-4.6-sonnet - Summary Prompt: Default Prompt
- Event Trigger:
pull_request.opened - GithubContextProvider: fix(ocpp): implement OCPP 1.6 GetDiagnostics supersession via AbortController #1991
- GithubContextProvider: fix(ocpp): cancel deferred OCPP 1.6 firmware setTimeout on stop() #1984
- File Content Strategy: Full file content
- GithubContextProvider: Bump @types/node from 16.11.35 to 17.0.34 #3
- GithubContextProvider: fix(ocpp): reset stationInfo.firmwareStatus on abort/exception in simulateFirmwareUpdateLifecycle #1976
- GithubContextProvider: Bump @typescript-eslint/eslint-plugin from 5.24.0 to 5.25.0 #4
- Correlation ID:
fe8a9ff0-7d66-11f1-9703-e158900b82d4 - GithubContextProvider: Bump chalk from 4.1.2 to 5.0.1 #1
- GithubContextProvider: [FEATURE] Add integration test coverage for OCPP 2.0.1 lifecycle supersession and cleanup paths #1974
- Output Template: Repository PR Template
There was a problem hiding this comment.
The PR adds 6 well-structured regression tests covering the OCPP 2.0.1 GetLog supersession and abort-boundary gaps. The tests are clearly organized with good AAA comments and proper use of the project's helper infrastructure. Three issues were identified: the clearActiveLogUpload tests reuse the outer beforeEach station with a different service instance (isolation risk), an inconsistency between calls.length and the canonical callCount() mock API, and a subtle assumption that the state reset in the supersession test is synchronous that should be made explicit.
PR Bot Information
Version: 1.27.6
- File Content Strategy: Full file content
- Agent Instructions:
- Correlation ID:
fe8a9ff0-7d66-11f1-9703-e158900b82d4 - LLM:
anthropic--claude-4.6-sonnet - Event Trigger:
pull_request.opened
| await describe('clearActiveLogUpload', async () => { | ||
| await it('should log at debug and preserve state for a superseded (non-matching) requestId', t => { | ||
| // Arrange | ||
| const service = new OCPP20IncomingRequestService() | ||
| const plumbing = asPlumbing(service) | ||
| const debugMock = t.mock.method(logger, 'debug') | ||
| const state = plumbing.getOrCreateStationState(station) |
There was a problem hiding this comment.
Bug: station from outer beforeEach is used inside a nested describe that creates its own service instance, but the station belongs to a different service instance.
In the clearActiveLogUpload tests (lines 402–434), station refers to the outer beforeEach-created station, while service is a freshly-constructed new OCPP20IncomingRequestService(). The outer service (used in testableService) and this inner service maintain separate stationsState WeakMaps, so plumbing.getOrCreateStationState(station) seeds state in the inner service's map. However, the outer station was created by the outer beforeEach, making the test dependent on the outer setup surviving into nested describe scope — this is fragile and couples tests to outer lifecycle fixtures.
More critically, the outer station is reset on every afterEach via standardCleanup(), but the inner service is not the one that owns it. If test ordering ever changes or the outer station reference becomes stale, assertions on state.activeLogUploadRequestId could silently pass on a wrong/shared state object.
Consider using a locally-created station inside each clearActiveLogUpload test (same pattern used by PostStopResurrection.test.ts's createStation()) for full isolation:
| await describe('clearActiveLogUpload', async () => { | |
| await it('should log at debug and preserve state for a superseded (non-matching) requestId', t => { | |
| // Arrange | |
| const service = new OCPP20IncomingRequestService() | |
| const plumbing = asPlumbing(service) | |
| const debugMock = t.mock.method(logger, 'debug') | |
| const state = plumbing.getOrCreateStationState(station) | |
| await describe('clearActiveLogUpload', async () => { | |
| await it('should log at debug and preserve state for a superseded (non-matching) requestId', t => { | |
| // Arrange | |
| const { station: localStation } = createMockStationWithRequestTracking() | |
| const service = new OCPP20IncomingRequestService() | |
| const plumbing = asPlumbing(service) | |
| const debugMock = t.mock.method(logger, 'debug') | |
| const state = plumbing.getOrCreateStationState(localStation) | |
| state.activeLogUploadRequestId = 200 | |
| // Act: a stale/superseded completion for requestId 199 | |
| plumbing.clearActiveLogUpload(localStation, 199) | |
| // Assert: else-branch fired the debug log and left state untouched | |
| assert.strictEqual(debugMock.mock.callCount(), 1) | |
| assert.strictEqual(state.activeLogUploadRequestId, 200) | |
| }) | |
| await it('should reset state and not log for a matching requestId', t => { | |
| // Arrange | |
| const { station: localStation } = createMockStationWithRequestTracking() | |
| const service = new OCPP20IncomingRequestService() | |
| const plumbing = asPlumbing(service) | |
| const debugMock = t.mock.method(logger, 'debug') | |
| const state = plumbing.getOrCreateStationState(localStation) | |
| state.activeLogUploadAbortController = new AbortController() | |
| state.activeLogUploadRequestId = 200 | |
| // Act: the active upload completes cleanly | |
| plumbing.clearActiveLogUpload(localStation, 200) | |
| // Assert: state cleared, no "Ignoring" debug log | |
| assert.strictEqual(state.activeLogUploadRequestId, undefined) | |
| assert.strictEqual(state.activeLogUploadAbortController, undefined) | |
| assert.strictEqual(debugMock.mock.callCount(), 0) | |
| }) | |
| }) |
Double-check suggestion before committing. Edit this comment for amendments.
Please provide feedback on the review comment by checking the appropriate box:
- 🌟 Awesome comment, a human might have missed that.
- ✅ Helpful comment
- 🤷 Neutral
- ❌ This comment is not helpful
| status: LogStatusEnumType.AcceptedCanceled, | ||
| }) | ||
| assert.strictEqual(priorAbortController.signal.aborted, true) | ||
| assert.strictEqual(state.activeLogUploadRequestId, undefined) |
There was a problem hiding this comment.
Logic Error: The assertion on state.activeLogUploadRequestId at line 324 passes even if the supersession path never resets the requestId, because the LogStatusNotification send (which fires the .catch — see line 344) completes asynchronously. The assertion is checked synchronously before any microtasks drain, so activeLogUploadRequestId being undefined at this point is only guaranteed if the reset happens synchronously inside handleRequestGetLog before the notification is fired off.
This is fine if the implementation does reset synchronously, but the test does not verify this assumption with a comment. More importantly, if the implementation is ever changed so that the reset happens in a .then() continuation, this assertion would silently become a false positive.
The test should either add an explicit comment that the reset is synchronous, or add await flushMicrotasks() before this assertion and verify the state holds after async settling.
Please provide feedback on the review comment by checking the appropriate box:
- 🌟 Awesome comment, a human might have missed that.
- ✅ Helpful comment
- 🤷 Neutral
- ❌ This comment is not helpful
| assert.strictEqual(response.status, LogStatusEnumType.AcceptedCanceled) | ||
| // The rejection is swallowed by the .catch and logged at error | ||
| await flushMicrotasks() | ||
| assert.strictEqual(errorMock.mock.calls.length, 1) |
There was a problem hiding this comment.
Logic Error: errorMock.mock.calls.length is accessed using .length, but createLoggerMocks returns a LoggerMockResult whose errorMock type has type { mock: { calls: MockCall[] } }. This is consistent. However, in the sibling clearActiveLogUpload tests (lines 414, 433), t.mock.method(logger, 'debug') is used directly to access debugMock.mock.callCount() with the callCount() method — while here errorMock.mock.calls.length uses the .length property. These two inconsistent patterns for checking mock call counts make the test suite harder to maintain and can mask differences in the mock API.
The style guide mandates strict assertions. callCount() is a method on Node's MockFunctionContext and is the canonical API. Should use .mock.callCount() consistently rather than mixing .mock.calls.length.
| assert.strictEqual(errorMock.mock.calls.length, 1) | |
| assert.strictEqual(errorMock.mock.callCount(), 1) |
Double-check suggestion before committing. Edit this comment for amendments.
Please provide feedback on the review comment by checking the appropriate box:
- 🌟 Awesome comment, a human might have missed that.
- ✅ Helpful comment
- 🤷 Neutral
- ❌ This comment is not helpful
c53ba4c to
93af283
Compare
93af283 to
6556ced
Compare
6556ced to
a131b61
Compare
Description
Regression-guard capstone for the OCPP 2.0.1 lifecycle supersession / cleanup work introduced by #1962 and hardened across #1976 / #1981 / #1983 / #1984 / #1991 / #1992 / #1994.
Test-only PR — zero changes under
src/. Scope was defined by a per-gap coverage audit, then extended in review to complete the firmware↔log symmetry.Closes #1974Per-gap coverage
clearActiveLogUploadelse-branchactiveLogUploadStatusclearing)clearActiveFirmwareUpdateelse-branchhandleRequestGetLogsupersessionAcceptedCanceled)handleRequestUpdateFirmwaresupersessionUpdateFirmware.test.tsL327-368; abort behaviorally locked by the finally-guard test)stop()integrationAbortControllers aborted + fields cleared)interruptibleSleep, noUploaded,finallycleanup ran)Net: +9 tests (GetLog 9→15, PostStopResurrection 14→15, UpdateFirmware 27→29); 0 existing tests weakened or removed; full suite 0 failures (6 pre-existing skips).
Pre-existing test-quality fixes in the touched files (from the review):
mock.method(...)withsimulateMock.mock.mockImplementation(...)(reconfigure thebeforeEachmock, no double-wrap), and added an expliciterrorMockassertion so the tests lock "rejection swallowed and logged aterror" instead of passing vacuously.assert.ok(length >= 1)→assert.strictEqual(length, 1).OCPP 2.0.1 spec grounding (verified against the spec text)
AcceptedCanceled(GetLogResponse) → gap Bump @typescript-eslint/parser from 5.24.0 to 5.25.0 #2.LogStatusNotification(AcceptedCanceled)→ gap Bump @typescript-eslint/parser from 5.24.0 to 5.25.0 #2 terminal-notification assertion.Uploadedonly on success → gap Update issue templates #5 assertsUploadedis NOT emitted after a mid-flight abort.N01.Mutation-sanity (temporary local reverts, not committed) — 9 guarded lines verified
Each revert failed exactly its target test, then was restored:
handleRequestGetLogabort ·simulateLogUploadLifecycle!signal.abortedguard · GET_LOG listener|| AcceptedCanceleddisjunct ·resetStationStateresetActive*Statecalls ·simulateLogUploadLifecyclefinallycleanup ·clearActiveFirmwareUpdateelse-branch debug ·clearActiveFirmwareUpdatematching reset ·resetActiveLogUploadStateactiveLogUploadStatusclear · GET_LOG listenerlogger.errorlevel.Note:
handleRequestGetLogboth aborts and resets the requestId (double guard), so the gap #5 test drivessimulateLogUploadLifecycledirectly and keeps the requestId claimed, isolating the!signal.abortedguard.Review (findings-driven, ≥2 parallel reviewers per round; 4 rounds)
K01→N01; supersession describe →N01 - GetLog supersession (N01.FR.12/FR.20); describes promoted to top-level; symmetric abort-controller assertion.finallyassertion; completed theclearActiveFirmwareUpdatesymmetry; rejected a false positive (firmware supersession sends no notification).errorMockassertions to both rejection tests, and theactiveLogUploadStatusassertion. Reviewer findings targeting pre-existing UpdateFirmware tests (FR-label rewrites, unrelated assertion styles) were classified out-of-scope for this test-additions PR.Verification gates
pnpm format/pnpm typecheck(0) /pnpm lint(0) clean on edited files.pnpm test— full suite 0 failures (6 pre-existing skips); changed files 50 → 59 tests (+9); no existing test removed.pnpm build— exit 0.Does this PR introduce a breaking change?