Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-pandas-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ocpp-debugkit/toolkit': patch
---

Add a meter-value-zero scenario to ensure a flat zero meter register does not report a failure.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ validate behavior against known scenarios.
firmware update failures, suspicious session duration, slow CSMS responses,
heartbeat interval violations, meter value anomalies, unresponsive CSMS, and
repeated boot notifications.
- **Scenario Evaluator** — 19 predefined scenarios with expected failure
- **Scenario Evaluator** — 20 predefined scenarios with expected failure
outcomes for testing the analysis engine. Supports external scenario files.
- **Replay Engine** — Deterministic, pure replay engine with step forward/back,
jump-to-event, and configurable playback speed.
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ report generation, React components, and CLI.
firmware update failures, suspicious session duration, slow CSMS responses,
heartbeat interval violations, meter value anomalies, unresponsive CSMS, and
repeated boot notifications.
- **Scenario Evaluator** — 19 predefined scenarios with expected failure
- **Scenario Evaluator** — 20 predefined scenarios with expected failure
outcomes for testing the analysis engine. Supports external scenario files.
- **Replay Engine** — Deterministic, pure replay engine with step forward/back,
jump-to-event, and configurable playback speed. No timers or I/O.
Expand Down
163 changes: 163 additions & 0 deletions packages/toolkit/src/scenarios/__scenarios__/meter-value-zero.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
export default {
name: 'meter-value-zero',
description:
'Transaction with a flat zero meter register throughout. A zero reading is a valid negative control and must not trigger METER_VALUE_ANOMALY.',
trace: {
traceId: 'scenario-meter-value-zero',
metadata: {
stationId: 'CS-SYNTHETIC-021',
ocppVersion: '1.6',
source: 'synthetic-scenario',
description:
'Station completes a four-minute transaction while the cumulative energy register remains at zero.',
},
events: [
{
timestamp: '2026-01-15T09:00:00.000Z',
direction: 'CS_TO_CSMS',
message: [
2,
'msg-001',
'BootNotification',
{
chargePointVendor: 'SyntheticVendor',
chargePointModel: 'SM-100',
chargePointSerialNumber: 'CS-SYNTHETIC-021',
firmwareVersion: '1.0.0',
},
],
},
{
timestamp: '2026-01-15T09:00:00.500Z',
direction: 'CSMS_TO_CS',
message: [
3,
'msg-001',
{ currentTime: '2026-01-15T09:00:00.500Z', interval: 300, status: 'Accepted' },
],
},
{
timestamp: '2026-01-15T09:00:30.000Z',
direction: 'CS_TO_CSMS',
message: [2, 'msg-002', 'Authorize', { idTag: 'SYNTHETIC-TAG-021' }],
},
{
timestamp: '2026-01-15T09:00:30.500Z',
direction: 'CSMS_TO_CS',
message: [3, 'msg-002', { idTagInfo: { status: 'Accepted' } }],
},
{
timestamp: '2026-01-15T09:01:00.000Z',
direction: 'CS_TO_CSMS',
message: [
2,
'msg-003',
'StartTransaction',
{ connectorId: 1, idTag: 'SYNTHETIC-TAG-021', meterStart: 0 },
],
},
{
timestamp: '2026-01-15T09:01:00.500Z',
direction: 'CSMS_TO_CS',
message: [3, 'msg-003', { idTagInfo: { status: 'Accepted' }, transactionId: 100021 }],
},
{
timestamp: '2026-01-15T09:02:00.000Z',
direction: 'CS_TO_CSMS',
message: [
2,
'msg-004',
'MeterValues',
{
connectorId: 1,
transactionId: 100021,
meterValue: [
{
sampledValue: [
{ value: '0', measurand: 'Energy.Active.Import.Register', unit: 'Wh' },
],
},
],
},
],
},
{
timestamp: '2026-01-15T09:02:00.500Z',
direction: 'CSMS_TO_CS',
message: [3, 'msg-004', {}],
},
{
timestamp: '2026-01-15T09:03:00.000Z',
direction: 'CS_TO_CSMS',
message: [
2,
'msg-005',
'MeterValues',
{
connectorId: 1,
transactionId: 100021,
meterValue: [
{
sampledValue: [
{ value: '0', measurand: 'Energy.Active.Import.Register', unit: 'Wh' },
],
},
],
},
],
},
{
timestamp: '2026-01-15T09:03:00.500Z',
direction: 'CSMS_TO_CS',
message: [3, 'msg-005', {}],
},
{
timestamp: '2026-01-15T09:04:00.000Z',
direction: 'CS_TO_CSMS',
message: [
2,
'msg-006',
'MeterValues',
{
connectorId: 1,
transactionId: 100021,
meterValue: [
{
sampledValue: [
{ value: '0', measurand: 'Energy.Active.Import.Register', unit: 'Wh' },
],
},
],
},
],
},
{
timestamp: '2026-01-15T09:04:00.500Z',
direction: 'CSMS_TO_CS',
message: [3, 'msg-006', {}],
},
{
timestamp: '2026-01-15T09:05:00.000Z',
direction: 'CS_TO_CSMS',
message: [
2,
'msg-007',
'StopTransaction',
{
transactionId: 100021,
idTag: 'SYNTHETIC-TAG-021',
meterStop: 0,
reason: 'Local',
},
],
},
{
timestamp: '2026-01-15T09:05:00.500Z',
direction: 'CSMS_TO_CS',
message: [3, 'msg-007', { idTagInfo: { status: 'Accepted' } }],
},
],
},
expectedFailures: [],
assertions: [{ type: 'no_failures', params: {} }],
};
15 changes: 13 additions & 2 deletions packages/toolkit/src/scenarios/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
firmwareUpdateFailureScenario,
refusedAuthorizationScenario,
heartbeatTimeoutScenario,
meterValueZeroScenario,
} from './index.js';
import { parseTrace, buildSessionTimeline, detectFailures } from '../core/index.js';

Expand All @@ -30,8 +31,8 @@ import { parseTrace, buildSessionTimeline, detectFailures } from '../core/index.
// ---------------------------------------------------------------------------

describe('scenario registry', () => {
it('exports exactly 19 scenarios', () => {
expect(scenarios).toHaveLength(19);
it('exports exactly 20 scenarios', () => {
expect(scenarios).toHaveLength(20);
});

it('exports scenario names in order', () => {
Expand All @@ -55,6 +56,7 @@ describe('scenario registry', () => {
'firmware-update-failure',
'refused-authorization',
'heartbeat-timeout',
'meter-value-zero',
]);
});

Expand Down Expand Up @@ -87,6 +89,7 @@ describe('scenario registry', () => {
expect(getScenario('firmware-update-failure')).toBe(firmwareUpdateFailureScenario);
expect(getScenario('refused-authorization')).toBe(refusedAuthorizationScenario);
expect(getScenario('heartbeat-timeout')).toBe(heartbeatTimeoutScenario);
expect(getScenario('meter-value-zero')).toBe(meterValueZeroScenario);
});

it('getScenario returns undefined for unknown name', () => {
Expand Down Expand Up @@ -242,6 +245,14 @@ describe('scenario engine integration', () => {
const failures = detectFailures(result.events, sessions);
expect(failures.some((f) => f.code === 'TIMEOUT_NO_HEARTBEAT')).toBe(true);
});

it('meter-value-zero: no failures detected', () => {
const trace = JSON.stringify(meterValueZeroScenario.trace);
const result = parseTrace(trace);
const sessions = buildSessionTimeline(result.events);
const failures = detectFailures(result.events, sessions);
expect(failures).toHaveLength(0);
});
});

// ---------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions packages/toolkit/src/scenarios/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import firmwareUpdateSuccess from './__scenarios__/firmware-update-success.js';
import firmwareUpdateFailure from './__scenarios__/firmware-update-failure.js';
import refusedAuthorization from './__scenarios__/refused-authorization.js';
import heartbeatTimeout from './__scenarios__/heartbeat-timeout.js';
import meterValueZero from './__scenarios__/meter-value-zero.js';

// ---------------------------------------------------------------------------
// Scenarios derived from core fixtures
Expand Down Expand Up @@ -74,6 +75,7 @@ const firmwareUpdateSuccessScenario: Scenario = firmwareUpdateSuccess as unknown
const firmwareUpdateFailureScenario: Scenario = firmwareUpdateFailure as unknown as Scenario;
const refusedAuthorizationScenario: Scenario = refusedAuthorization as unknown as Scenario;
const heartbeatTimeoutScenario: Scenario = heartbeatTimeout as unknown as Scenario;
const meterValueZeroScenario: Scenario = meterValueZero as unknown as Scenario;

// ---------------------------------------------------------------------------
// Registry
Expand All @@ -99,6 +101,7 @@ export const scenarios = [
firmwareUpdateFailureScenario,
refusedAuthorizationScenario,
heartbeatTimeoutScenario,
meterValueZeroScenario,
] as const;

export const scenarioNames = [
Expand All @@ -121,6 +124,7 @@ export const scenarioNames = [
'firmware-update-failure',
'refused-authorization',
'heartbeat-timeout',
'meter-value-zero',
] as const;

export {
Expand All @@ -143,6 +147,7 @@ export {
firmwareUpdateFailureScenario,
refusedAuthorizationScenario,
heartbeatTimeoutScenario,
meterValueZeroScenario,
};

export { compareScenarioReports } from './compare.js';
Expand Down
4 changes: 2 additions & 2 deletions tests/external-fixture/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ const scenarios = await import('@ocpp-debugkit/toolkit/scenarios');

assert(Array.isArray(scenarios.scenarios), 'scenarios is an array');
assert(
scenarios.scenarios.length === 19,
`19 scenarios exported (got ${scenarios.scenarios.length})`,
scenarios.scenarios.length === 20,
`20 scenarios exported (got ${scenarios.scenarios.length})`,
);
assert(typeof scenarios.getScenario === 'function', 'getScenario is a function');
assert(scenarios.getScenario('normal-session') !== undefined, 'normal-session scenario exists');
Expand Down
Loading