You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
⚠️ This issue has been split into two parts for safe execution
Per the Phase 7 Scope & Split Assessment, this issue has ~45 call sites across 7 test files that each require semantic judgment (choosing the correct parser callback per resource type). Doing the implementation + all test updates in one pass exceeds safe single-pass capacity.
This parent issue should be closed when both #154 and #155 are resolved.
Original issue body (preserved for reference)
Finding
parseCollectionResponse casts the raw features or items array directly to T[] without validating any element. The function promises CollectionResponse<T> but delivers CollectionResponse<unknown> masked as typed. Every downstream caller receives data it believes is typed but which may contain null, numbers, or malformed objects.
parseCollectionResponse is the single boundary where untyped server JSON enters the CSAPI typed system. If this boundary is dishonest, all of CSAPI's type safety downstream is illusory. Array.isArray confirms an array exists but says nothing about element types. The as T[] cast tells TypeScript the elements are T without any runtime verification.
Affected code:
// src/ogc-api/csapi/formats/response.ts, lines 98–103letitems: T[];if(Array.isArray(obj.features)){items=obj.featuresasT[];// ← no element validation}elseif(Array.isArray(obj.items)){items=obj.itemsasT[];// ← same}
Scenario:
// Server returns { "items": [null, 42, { "no-id": true }] }constresult=parseCollectionResponse<Datastream>(body);result.items[0].id// TypeError: Cannot read properties of nullresult.items[1].id// TypeError: undefined is not a property of number// TypeScript shows no warning — it believes items are all Datastream
Impact: All Part 2 parsers and integration tests that call parseCollectionResponse receive unvalidated items. If a server returns malformed elements, runtime TypeErrors occur at field access with no TS warning at the call site. Currently ~45 call sites across 7 test files (response.spec.ts, discovery.spec.ts, command.spec.ts, navigation.spec.ts, observation.spec.ts, pipeline.spec.ts, index.spec.ts). There are no production (non-test) call sites — the function is exported via formats/index.ts for consumer use but is not called internally by other production code.
Per the Phase 7 Scope & Split Assessment, this issue has ~45 call sites across 7 test files that each require semantic judgment (choosing the correct parser callback per resource type). Doing the implementation + all test updates in one pass exceeds safe single-pass capacity.
Split Issues
parseItemcallback inparseCollectionResponse+ unit tests (response.ts,response.spec.ts)discovery.spec.ts,command.spec.ts,navigation.spec.ts,observation.spec.ts,pipeline.spec.ts)Execution Order
parseItemcallback inparseCollectionResponse+ unit tests #154 (Part 1) — implement the core changeparseCollectionResponseparseItemcallback #155 (Part 2) — fix the integration test call sitesThis parent issue should be closed when both #154 and #155 are resolved.
Original issue body (preserved for reference)
Finding
parseCollectionResponsecasts the rawfeaturesoritemsarray directly toT[]without validating any element. The function promisesCollectionResponse<T>but deliversCollectionResponse<unknown>masked as typed. Every downstream caller receives data it believes is typed but which may containnull, numbers, or malformed objects.Review Source: Senior developer code review of
clean-pr—docs/code-review/003-pending-p1-unchecked-generic-cast-response.mdSeverity: P1-Critical
Category: Type Safety
Ownership: Ours
Problem Statement
parseCollectionResponseis the single boundary where untyped server JSON enters the CSAPI typed system. If this boundary is dishonest, all of CSAPI's type safety downstream is illusory.Array.isArrayconfirms an array exists but says nothing about element types. Theas T[]cast tells TypeScript the elements areTwithout any runtime verification.Affected code:
Scenario:
Impact: All Part 2 parsers and integration tests that call
parseCollectionResponsereceive unvalidated items. If a server returns malformed elements, runtime TypeErrors occur at field access with no TS warning at the call site. Currently ~45 call sites across 7 test files (response.spec.ts,discovery.spec.ts,command.spec.ts,navigation.spec.ts,observation.spec.ts,pipeline.spec.ts,index.spec.ts). There are no production (non-test) call sites — the function is exported viaformats/index.tsfor consumer use but is not called internally by other production code.