Skip to content

feat(roads): add CIFS v2 inbound parser and outbound emitter - #464

Merged
Medformatik merged 2 commits into
mainfrom
feat/cifs-parser-emitter
Nov 26, 2026
Merged

Medformatik merged 2 commits into
mainfrom
feat/cifs-parser-emitter

Conversation

@Medformatik

Copy link
Copy Markdown
Contributor

What changed and why

Adds first-class CIFS v2 (Closure and Incident Feed Specification) support in both directions — inbound parsing (format: "cifs", XML and JSON) and outbound publishing (GET /cifs.xml and GET /cifs.json) — backed by the pinned official Google/Waze XML Schema (cifsv2.xsd), model crosswalk, and end-to-end PostGIS verification.

Conformance & canonical model

  • Pinned standard: Added packages/conformance/src/standards/cifs-v2.ts pinning https://www.gstatic.com/road-incidents/cifsv2.xsd by SHA-256 (a82ffb2cd92610a739bc55c9ab4b270e66e74cb546a9f5e59a34ce9af45e0f6b) for test-time xmllint-wasm validation.
  • Vocabularies & crosswalk: Added packages/model-roads/src/vocabularies/cifs.ts (all 7 types, 36 XSD subtypes, 2 doc-only inbound subtypes, directions, roadsides, lane statuses) and packages/model-roads/src/crosswalk/cifs.ts (CIFS_SITUATIONS and XSD-valid outbound CIFS_INCIDENTS). Registered "cifs" in @openconditions/model (MappingTarget) and @openconditions/model-roads (format: "cifs", external_id_scheme extended with cifs:incident and cifs:parent_event), and regenerated model schemas, docs, and feed schemas.

Inbound CIFS parser (@openconditions/roads)

  • Implemented parseCifsSnapshot and parseCifs in packages/roads/src/cifs.ts for CIFS XML (<incidents>) and CIFS JSON ({ incidents: [...] }, flat or wrapped { incident: {...} }, plus legacy nested location objects with flat/legacy conflict rejection).
  • Registered cifs in SITUATION_PARSERS, SNAPSHOT_REPORTERS, ACCOUNTED_PARTIAL_FORMATS, and situations("cifs", { reparseUnchanged: true, transactionalRoles: true }):
    • Defaults to situationsComplete: false with bounded retrieval TTL (freshness.expiresAt), only authorizing snapshot omission withdrawal when a catalogue source explicitly declares snapshot: { completeness: "complete" }.
    • Conditional 304 Not Modified responses replay the last accepted payload to renew retrieval TTL on healthy feeds; failed or malformed polls neither poison the held payload nor advance validators.
    • Explicit failure envelopes (including success: false, ok: false, error/errors, and numeric or string HTTP error statuses such as "503"), malformed records, duplicate XML elements, explicit JSON nulls on critical fields, and conflicting duplicate IDs fail closed.
  • Preserves strict routing safety:
    • Validates (type, subtype) pairs before classification; accounts CHIT_CHAT as terminal.
    • Sets roadState: "closed" on ROAD_CLOSED* while retaining cause classification; marks closures missing starttime as validity.status = "unknown", and keeps single-point, circular, zero-length, or >20 km closures normalization: "partial" so they never route.
    • Preserves ordered-line direction (ONE_DIRECTION / omitted → positive/geometry) and never widens single-point ONE_DIRECTION to bilateral.
    • Validates <lanes> / <lane_impact> strictly (0-based → 1-based normalization, non-traffic lane exclusion, empty <lane/> detection, count/roadside conflict downgrade, never synthesizing all_lanes_closed), <source> provenance, <parent_event> external IDs, and recurring <schedule> windows (rejecting DST-crossing windows including overnight transitions and end-only bounds).

Outbound CIFS emitter & ingest API (@openconditions/publishers, services/ingest)

  • Implemented cifsIncidentsOf, situationsToCifsXml, and situationsToCifsJson in packages/publishers/src/situation-cifs.ts with shared projection and diagnostics:
    • Emits strictly XSD-valid cifsv2.xsd values (never writes deprecated CONSTRUCTION, CHIT_CHAT, or doc-only subtypes).
    • Exports ROAD_CLOSED only for complete, active or confirmed-scheduled, mandatory, road-wide (non-lane-scoped) closures with explicit validity.start and a non-circular LineString (0 m < length ≤ 20,000 m on serialized 6-decimal coordinates).
    • Single-point closures are always withheld; single-point non-closure alerts are exported only with explicit bilateral evidence (direction.value === "both").
    • Enforces strict lane consistency (isAffirmativeLaneClosure and extractCompleteLanes), intersects bounded weekly occurrences in local timezone for cross-bucket lane conflict detection, enforces XML-safe code-point minimum lengths (@id ≥ 3, <street> ≥ 2, <description> ≥ 1), and encodes incident IDs so root and split namespaces are disjoint, poll-stable, and immune to XML 1.0 §3.3.3 attribute whitespace normalization.
  • Added GET /cifs.xml and GET /cifs.json in services/ingest backed by a shared complete repeatable-read public snapshot helper (readCompletePublicSnapshot, 20,000-situation and 32 MiB byte caps, 413 JSON with Cache-Control: no-store, X-Data-License), updated services/ingest/openapi.json, added projection.cifs / exports.cifs to feed-inspect, and documented the contract in docs/cifs.md, docs/speed-coverage.md, README.md, and services/ingest/README.md.

Verification and limits

All checks ran locally in this worktree against base 6b0edf98:

  • pnpm build — passed (36/36 packages).
  • pnpm lint (biome check, prettier --check, check-import-boundaries) — passed.
  • pnpm typecheck — passed (69/69 packages).
  • pnpm check-credentials, pnpm check:model, pnpm check:feed-schemas, pnpm feeds:lint — all passed.
  • pnpm test:unit — passed (7,956+ unit tests across 572 test files, plus re-verification of all 8 CIFS-related test suites: 66/66 tests passing, including xmllint-wasm validation against pinned cifsv2.xsd, XML/JSON roundtrip, random fuzzing, OpenAPI drift, and feed-inspect).
  • pnpm exec vitest run --project integration services/ingest/src/__tests__/cifs-feed.integration.test.ts (Docker PostGIS 16 via Testcontainers) — passed (10/10 tests covering /cifs.xml, /cifs.json, XSD validation, query rejection, public scoping, 304 TTL renewal, transactional role recovery after malformed polls, string-status "503" failure envelope refusal, and qualified complete-feed withdrawal).

Limits:

  • No new live CIFS catalogue feed was added in this PR (only the format support, fixture, and export endpoints); real-world Waze Partner Hub ingestion validation was not run against external hosted Waze infrastructure.
  • Only the CIFS PostGIS integration test file was run from the integration project; unrelated integration test files were not run locally.

Release and upgrade impact

  • Additive format & endpoints: Adds "cifs" to road feed formats, cifs:incident / cifs:parent_event to external_id_scheme, and public read endpoints GET /cifs.xml and GET /cifs.json to services/ingest. No database migrations or configuration changes are required for existing deployments.
  • Public package exports: @openconditions/model-roads, @openconditions/roads, and @openconditions/publishers gain new additive CIFS exports; feed-inspect adds projection.cifs and exports.cifs while retaining schemaVersion: 2.

Comment thread packages/roads/src/cifs.ts Fixed
@Medformatik
Medformatik merged commit 2de5460 into main Nov 26, 2026
22 checks passed
@Medformatik
Medformatik deleted the feat/cifs-parser-emitter branch November 26, 2026 22:21
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants