Skip to content

Commit 3648f3f

Browse files
committed
feat(core): implement trace parser, normalizer, and Zod schemas
- parseTrace() accepts JSON Object, JSONL, and bare array trace formats - normalizeEvents() classifies message types, infers directions (ADR-0004), and normalizes timestamps to epoch milliseconds (ADR-0005) - Zod schemas validate all untrusted input, preventing prototype pollution - Input size limit (10 MB) and event count limit (10,000) enforced - Malformed individual events are skipped with ParseWarning (ADR-0007) - Added Failure, Scenario, SessionSummary, ValidationResult types - 78 new unit tests (46 normalizer + 32 parser) Closes #20
1 parent 4038713 commit 3648f3f

11 files changed

Lines changed: 1612 additions & 34 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@ocpp-debugkit/core': minor
3+
---
4+
5+
Implement trace parser, event normalizer, and Zod schemas.
6+
7+
- `parseTrace()` accepts JSON Object, JSONL, and bare array trace formats
8+
- `normalizeEvents()` classifies message types, infers directions (ADR-0004),
9+
and normalizes timestamps to epoch milliseconds (ADR-0005)
10+
- Zod schemas validate all untrusted input, preventing prototype pollution
11+
- Input size limit (10 MB) and event count limit (10,000) enforced
12+
- Malformed individual events are skipped with `ParseWarning` (ADR-0007)
13+
- Added `Failure`, `Scenario`, `SessionSummary`, `ValidationResult` types
14+
- 78 new unit tests (46 normalizer + 32 parser)

‎CURRENT_STATE.md‎

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@
88

99
## Active Milestone
1010

11-
**M0.5 — Protocol & Trace-Format Design Phase**
11+
**v0.1.0 — Inspector MVP**
1212

13-
Design spike resolving all foundational design decisions before core
14-
implementation. Produces ADRs, trace format specification, and synthetic
15-
trace fixtures that validate the proposed internal event model.
13+
Building the first usable release: trace → timeline → failures detected →
14+
report exported. CLI and web inspector.
1615

1716
## What's Done
1817

1918
### GitHub Infrastructure
2019

2120
- ✅ GitHub milestones created (M0, M0.5, v0.1.0, v0.2.0, v0.3.0, v1.0.0)
2221
- ✅ GitHub labels created (type, package, priority, workflow)
23-
- ✅ Tracking issues created for M0 and M0.5
22+
- ✅ Tracking issues created for M0, M0.5, and v0.1.0 (#20–#32)
2423

2524
### Monorepo & Tooling (PR #12)
2625

@@ -55,37 +54,31 @@ trace fixtures that validate the proposed internal event model.
5554
- ✅ `README.md` (description, badges, architecture, quickstart, support, links)
5655
- ✅ `SECURITY.md` (vulnerability reporting, security principles)
5756

58-
### Protocol & Trace-Format Design (in progress — this PR)
59-
60-
- ✅ 9 ADRs covering all design decisions:
61-
- ADR-0001: OCPP version scope (1.6 JSON primary)
62-
- ADR-0002: Input trace formats (JSON Object + JSONL)
63-
- ADR-0003: Canonical internal event model
64-
- ADR-0004: Message direction representation
65-
- ADR-0005: Timestamp normalization
66-
- ADR-0006: Session correlation strategy
67-
- ADR-0007: Malformed trace handling
68-
- ADR-0008: Browser-local processing & privacy
69-
- ADR-0009: Future protocol-version extensibility
57+
### Protocol & Trace-Format Design (PR #19)
58+
59+
- ✅ 9 ADRs covering all design decisions
7060
- ✅ `docs/trace-format-spec.md` — full trace format specification
71-
- ✅ 3 synthetic trace fixtures in `packages/core/src/__fixtures__/`:
72-
- `normal-session.json` — complete charging session (no failures)
73-
- `failed-auth.json` — failed authorization (expects `FAILED_AUTHORIZATION`)
74-
- `connector-fault.json` — connector fault during session (expects `CONNECTOR_FAULT`)
75-
- ✅ `packages/core/src/types.ts` — proposed canonical types (`Event`, `Trace`, `Session`, etc.)
76-
- ✅ `packages/core/src/fixtures/index.ts` — fixture registry
77-
- ✅ `packages/core/src/fixtures.test.ts` — 28 validation tests proving fixtures conform to the proposed event model
61+
- ✅ 3 synthetic trace fixtures in `packages/core/src/__fixtures__/`
62+
- ✅ Proposed canonical types and fixture validation tests
63+
64+
### Core Package — Data Model + Parser + Normalizer (in progress — this PR)
65+
66+
- ✅ `packages/core/src/schemas.ts` — Zod schemas for all input types
67+
- ✅ `packages/core/src/normalizer.ts` — `normalizeEvents()`, direction inference (ADR-0004), timestamp normalization (ADR-0005)
68+
- ✅ `packages/core/src/parser.ts` — `parseTrace()` accepting JSON Object, JSONL, bare array
69+
- ✅ `packages/core/src/types.ts` — updated with `Failure`, `Scenario`, `SessionSummary`, `ValidationResult` types
70+
- ✅ `packages/core/src/normalizer.test.ts` — 46 tests
71+
- ✅ `packages/core/src/parser.test.ts` — 32 tests
72+
- ✅ Untrusted-input handling: safe JSON parsing, size limits (10 MB), event count limits (10,000), prototype pollution protection, malformed event skip-and-flag
7873

7974
## What's Next
8075

81-
1. **M0.5 complete** → maintainer reviews and merges this PR
82-
2. Proceed to v0.1.0 (Inspector MVP):
83-
- Issue #13: Core data model + trace parser + event normalizer
84-
- Issue #14: Core timeline + failure detection + summarizer + validator
85-
- Issue #15: Core public API export + package config
86-
- Issue #16: Scenarios package (format + 5 initial scenarios)
87-
- Issue #17: Reporter package (Markdown report generator)
88-
- Issue #18: CLI package (scaffold + inspect + report + scenario commands)
76+
1. **Issue #20** (this PR) → complete: data model + parser + normalizer
77+
2. **Issue #21**: Core timeline + failure detection + summarizer + validator
78+
3. **Issue #22**: Core public API export + package config
79+
4. **Issue #23**: Scenarios package (format + 5 initial scenarios)
80+
5. **Issue #24**: Reporter package (Markdown report generator)
81+
6. **Issue #25**: CLI package (scaffold + inspect + report + scenario commands)
8982

9083
## Known Blockers / Decisions Pending
9184

@@ -95,7 +88,7 @@ trace fixtures that validate the proposed internal event model.
9588

9689
| Package | Status | Version |
9790
|---------|--------|---------|
98-
| `@ocpp-debugkit/core` | in progress (types + fixtures) | 0.0.0 |
91+
| `@ocpp-debugkit/core` | in progress (parser + normalizer done) | 0.0.0 |
9992
| `@ocpp-debugkit/scenarios` | not started | — |
10093
| `@ocpp-debugkit/reporter` | not started | — |
10194
| `@ocpp-debugkit/cli` | not started | — |

‎packages/core/package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"test": "vitest run",
2424
"clean": "rm -rf dist .turbo"
2525
},
26-
"dependencies": {},
26+
"dependencies": {
27+
"zod": "^4.4.3"
28+
},
2729
"devDependencies": {
2830
"typescript": "^5.7.0",
2931
"vitest": "^3.0.0"

‎packages/core/src/index.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,28 @@
22
* Barrel export for the @ocpp-debugkit/core package.
33
*/
44

5+
// Types
56
export * from './types.js';
7+
8+
// Schemas (Zod)
9+
export * from './schemas.js';
10+
11+
// Parser
12+
export { parseTrace, ParseError, MAX_INPUT_SIZE_BYTES, MAX_EVENT_COUNT } from './parser.js';
13+
export type { TraceFormat } from './parser.js';
14+
15+
// Normalizer
16+
export {
17+
normalizeEvents,
18+
normalizeTimestamp,
19+
inferDirection,
20+
reverseDirection,
21+
classifyMessageType,
22+
extractAction,
23+
extractPayload,
24+
extractErrorCode,
25+
extractErrorDescription,
26+
} from './normalizer.js';
27+
28+
// Fixtures
629
export * from './fixtures/index.js';

0 commit comments

Comments
 (0)