Skip to content

fix(sdk): createPedestrian emitted a shape type no consumer recognises - #100

Merged
kosuke55 merged 1 commit into
mainfrom
fix/pedestrian-shape-type
Aug 10, 2026
Merged

fix(sdk): createPedestrian emitted a shape type no consumer recognises#100
kosuke55 merged 1 commit into
mainfrom
fix/pedestrian-shape-type

Conversation

@kosuke55

Copy link
Copy Markdown
Owner

Problem

Scenes built with createPedestrian silently lose every pedestrian:

const snapshot = createSnapshot([...lane, createVehicle(100, 25), createPedestrian(300, 25)])
exportToOpenScenario(snapshot, {})
// → 1 ScenarioObject (the vehicle). The pedestrian is gone, with no warning.

Cause

createPedestrian returned type: 'pedestrian', but nothing in the SDK or the editor handles that shape type:

  • the editor has only ever stored placed participants as vehicle — pedestrians are a templateId, not a shape type
  • exporter/openscenario.ts skips anything that is not vehicle, then picks <Pedestrian> vs <Vehicle> from PEDESTRIAN_PATTERNS

So the factory disagreed with its own consumers. createVehicle and createPedestrian differ only in the default templateId ('filled'), which already matches the exporter's pedestrian patterns — the shape type was the only thing wrong.

Fix

Return type: 'vehicle', and document why in a doc comment: the name createPedestrian naturally invites type: 'pedestrian', so without an explanation the same change is likely to be reintroduced.

Verification

With plain Node against the built dist/:

pedestrian shape type: vehicle / templateId: filled
entities: 2 [ 'Vehicle_0', 'Pedestrian_1' ]
has <Pedestrian>: true
pedestrianCategory: pedestrian

Existing suite: 325 passed, 4 skipped.

Test

Added __tests__/helpersFactoryContract.test.ts.

It runs factory output through the exporter instead of asserting the shape type. Asserting shape.type === 'vehicle' would pass while telling us nothing about whether a pedestrian actually survives export — and the consequence is the part that was broken.

No existing test referenced createPedestrian at all, which is why this went unnoticed. I confirmed both new cases fail when the old type is restored.

`createPedestrian` returned `type: 'pedestrian'`, but nothing in the SDK or
the editor handles that type:

- the editor has only ever stored placed participants as `vehicle`
  (pedestrians are a `templateId`, not a shape type)
- `exporter/openscenario.ts` iterates `shape.type !== 'vehicle' && continue`
  and picks `<Pedestrian>` vs `<Vehicle>` from PEDESTRIAN_PATTERNS

So scenes built with `createPedestrian` silently lost every pedestrian:
`exportToOpenScenario` emitted 0 ScenarioObjects for them, with no warning.
`createVehicle` and `createPedestrian` differ only in the default templateId
('filled'), which already matches the exporter's pedestrian patterns.

Return `type: 'vehicle'` so the factory agrees with its own consumers, and
document why, since the naming otherwise invites the same mistake again.

Verified with plain Node: a lane + createVehicle + createPedestrian scene now
emits 2 entities named Vehicle_0 / Pedestrian_1, with
`<Pedestrian pedestrianCategory="pedestrian">`.

Adds __tests__/helpersFactoryContract.test.ts. It runs factory output through
the exporter rather than asserting the shape type, because the type alone would
not have caught the consequence. No existing test referenced createPedestrian,
which is why this went unnoticed. Confirmed both cases fail when the old type
is restored.
@kosuke55 kosuke55 added the run-tests Trigger CI test execution label Aug 10, 2026
@kosuke55
kosuke55 merged commit 910dcee into main Aug 10, 2026
4 checks passed
@kosuke55
kosuke55 deleted the fix/pedestrian-shape-type branch August 10, 2026 13:06
kosuke55 added a commit that referenced this pull request Aug 10, 2026
The README documented only the extension (iframe) workflow, while the
factories and exporters also work from plain Node.js since the ESM fix
(#99) and the factory fixes (#100, #101). Add a copy-paste runnable
example that builds a lane + driving path + vehicle and exports
OpenDRIVE / OpenSCENARIO / Lanelet2, notes the 0.17.0 requirement, and
points scenario logic (triggers, speed profiles) to the editor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-tests Trigger CI test execution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant