Repository navigation
Description
Phase 8 Task
Task ID: C1
Title: Issue #166 — Part 2 @link Fallback in Cross-Reference Fields
Source: Repo issue #166; spec authority OGC 23-002 §16.1
Severity: P1-Major (server-interop bug — connected-systems-go non-conformance)
Category: Bug Fix / Server Interop / Spec Conformance
Ownership: Ours (CSAPI module — csapi/formats/part2.ts + spec)
Phase 8 phase: C — Server-Interop Bug Fix
Goal
All Part 2 parsers extract cross-reference IDs from either the @id (scalar string) form OR the @link (object with href) form, per OGC 23-002 §16.1. The library is conformant for connected-systems-go servers (and any future server emitting the object form) without breaking interop with OpenSensorHub or Toolbox4OGC, which emit the scalar form.
Acceptance criterion (from P8-contribution-goal-and-definition.md): B1 — Part 2 parsers accept @link object form alongside @id scalar form; @id always wins when both are present.
Locked Decision
⚠️ This decision is locked. Do not re-litigate in this issue. Surface deviations to the user; do not silently re-decide.
Decision: Add a single extractCrossReferenceId(obj, fieldName) helper in csapi/formats/part2.ts (or its _helpers.ts) that:
- Returns the scalar
@idvalue when present and non-empty (authoritative form —@idalways wins). - Otherwise returns the last path segment of
@link.hrefwhen the@linkobject has astringhrefproperty (handles both full URLs and bare identifiers). - Returns
undefinedotherwise.
Replace every inline obj['<field>@id'] extraction in the affected parsers with a call to this helper. Do NOT change the scalar-form precedence; existing @id-form fixtures and tests must continue to pass without modification.
Locked in:
- P8-contribution-goal-and-definition.md §3 — Phase 8 design rails (acceptance criterion B1)
- P8-implementation-guide.md §3 — execution-level rails
- P8-implementation-guide §5.1 — canonical helper signature, replacement pattern, and 5-test pattern
- Issue #166 — authoritative finding
- OGC 23-002 §16.1 — spec authority
Problem Statement
OGC 23-002 §16.1 (paraphrased): a resource may reference another resource by either:
"system@id": "0o123"— scalar string identifier, OR"system@link": { "href": "https://api.example.com/systems/0o123", "title": "...", ... }— object form withhrefcarrying the identifier (last URL segment) or a bare ID.
Servers MAY emit either form; clients MUST accept either. The library currently only accepts @id. Against connected-systems-go, which emits the object form for cross-references, the affected parsers silently drop the cross-reference ID — Datastream.systemId, Observation.datastreamId/foiId/samplingFeatureId, Command.controlStreamId, CommandStatus.commandId all come back undefined even when the server fully advertised the relationship.
Affected parsers / fields:
| Parser | Cross-reference fields |
|---|---|
parseDatastream |
system@id / system@link.href |
parseControlStream |
system@id / system@link.href |
parseObservation |
datastream@id / datastream@link.href; foi@id / foi@link.href; samplingFeature@id / samplingFeature@link.href |
parseCommand |
controlstream@id / controlstream@link.href |
parseCommandStatus |
command@id / command@link.href |
Affected code: src/ogc-api/csapi/formats/part2.ts — at least 5 inline obj['<field>@id'] extractions across these parsers.
Impact: Silent data loss for any consumer talking to a connected-systems-go (or future spec-conformant) server. The smoke test against cs-go will surface the divergence end-to-end.
Files to Modify
| File | Action | Est. Lines | Purpose |
|---|---|---|---|
src/ogc-api/csapi/formats/part2.ts |
Modify | ~50 | Add extractCrossReferenceId(obj, fieldName) helper; replace 5+ inline obj['<field>@id'] extractions in parseDatastream, parseControlStream, parseObservation (3 fields), parseCommand, parseCommandStatus |
src/ogc-api/csapi/formats/part2.spec.ts |
Modify | ~250 | Add the 5-test pattern (scalar, object, both, bare-href, neither) for each affected parser/field — ~25–30 new test cases total |
fixtures/csapi/part2/<resource>-link-form.json |
Add (optional) | ~variable | Per-parser fixtures exercising the @link form to lock the contract end-to-end |
Cross-reference P8-implementation-guide §5.1 for the canonical files-modified list. If you find yourself adding a file that isn't in the implementation guide, stop — surface the question.
Implementation Approach
Pull the canonical helper, replacement pattern, and test pattern from P8-implementation-guide §5.1.
New helper in src/ogc-api/csapi/formats/part2.ts (or _helpers.ts):
/**
* Extracts a cross-reference ID from either the scalar `@id` form or the
* object `@link` form, per OGC 23-002 §16.1.
*
* The `@link` form carries an `href` that may be a full URL or just an
* identifier; the last path segment is used as the ID. When both forms
* are present, `@id` wins (it is the authoritative scalar form).
*/
function extractCrossReferenceId(
obj: Record<string, unknown>,
fieldName: string
): string | undefined {
// Form 1: scalar @id (authoritative; wins if both forms present)
const idValue = obj[`${fieldName}@id`];
if (typeof idValue === 'string' && idValue.length > 0) {
return idValue;
}
// Form 2: object @link with href
const linkValue = obj[`${fieldName}@link`];
if (
typeof linkValue === 'object' &&
linkValue !== null &&
typeof (linkValue as Record<string, unknown>).href === 'string'
) {
const href = (linkValue as Record<string, unknown>).href as string;
const lastSegment = href.split('/').filter(Boolean).pop();
if (lastSegment && lastSegment.length > 0) {
return lastSegment;
}
}
return undefined;
}Replacement pattern (apply at every cross-reference call site):
- ...(typeof obj['system@id'] === 'string'
- ? { systemId: obj['system@id'] as string }
- : {}),
+ ...((() => {
+ const systemId = extractCrossReferenceId(obj, 'system');
+ return systemId !== undefined ? { systemId } : {};
+ })()),Test pattern (5 cases per parser/field — multiply by ~5–6 fields = ~25–30 tests):
For each affected parser/field, add the canonical 5-test pattern verbatim from P8-implementation-guide §5.1:
- Parses ID from
<field>@id(scalar form) — preserves existing behavior - Parses ID from
<field>@link.href(object form, OGC 23-002 §16.1) — new behavior - Prefers
@idover@linkwhen both are present — locks the precedence invariant - Handles
@link.hrefas a bare identifier with no path — covers minimal-href edge case - Returns
undefinedwhen neither@idnor@linkis present — covers the empty-cross-reference case
Fixtures (optional): existing fixtures use the @id form and continue to pass unchanged. Adding one new fixture per parser exercising the @link form is allowed for end-to-end lock-in but is not required for the acceptance gate.
Scope — What NOT to Touch
- ❌ Do NOT modify files outside the "Files to Modify" table above. If a new cross-reference field appears anywhere outside
formats/part2.ts, surface it before editing. - ❌ Do NOT change the
@id-form precedence —@idalways wins when both forms are present - ❌ Do NOT modify or replace existing
@id-form fixtures — they must continue to parse identically - ❌ Do NOT modify
csapi/formats/part1.ts,formats/response.ts,formats/property.ts,formats/schema-response.ts,formats/geojson.ts, orformats/swecommon/**— Part 1 and other format families are out of scope - ❌ Do NOT introduce a
CSAPIErrorsubclass; if any new throw is needed inside the helper, useEndpointErrorper Task B2's locked decision - ❌ Do NOT add a
try/catchwrapper infactory.tsfor network errors — that's Task D1 - ❌ Do NOT pre-emptively refactor unrelated parser internals while you're in
formats/part2.ts - ❌ Do NOT rename
getDataStreams→getDatastreamsin any code or tests outside this task — that's Task B1 - ❌ Do NOT add
@deprecatedtags anywhere in Phase 8 (locked decision; PR unmerged ⇒ no consumers) - ❌ Do NOT absorb consumer-side ergonomic helpers (Phase 8 hard scope fence; Closed (wontfix): library is spec-correct; server-side root cause tracked at connected-systems-go#11; institutional knowledge preserved in references.md #168 / Closed (wontfix): heuristic coordinate extraction not adopted; architecturally correct path tracked at #171 #169 stay closed wontfix)
- ❌ Do NOT re-open a Phase 8 deferred finding (020, 025, 026) or a deferred CS-Go issue (Future-enhancement (deferred): async-iterator helpers for paginated CSAPI list methods — out-of-scope until upstream broadens scope #170, Deferred enhancement: SWE Common–aware result-vector extraction (out-of-scope until upstream broadens scope) #171). Specifically: this task fixes
@linkcross-reference extraction only; SWE Common-aware result extraction (Deferred enhancement: SWE Common–aware result-vector extraction (out-of-scope until upstream broadens scope) #171) and any auto-pagination helper (Future-enhancement (deferred): async-iterator helpers for paginated CSAPI list methods — out-of-scope until upstream broadens scope #170) remain deferred.
Acceptance Criteria
-
extractCrossReferenceId(obj, fieldName)helper added tosrc/ogc-api/csapi/formats/part2.ts(or its_helpers.ts) with the canonical signature and JSDoc - Helper prefers
@id(scalar) over@link(object) when both are present - Helper returns the last path segment of
@link.href(handles full URLs and bare IDs) - Helper returns
undefinedwhen neither form is present or well-formed - All 5+ inline
obj['<field>@id']extractions inparseDatastream,parseControlStream,parseObservation(3 fields),parseCommand, andparseCommandStatusreplaced with helper calls - 5-test pattern added for each affected parser/field — ~25–30 new test cases total
- Existing
@id-form fixtures and tests pass unchanged (regression-safe) - No
CSAPIErrorsubclass introduced; any helper-internal throw usesEndpointError(per B2's locked decision) - All modified files pass
npx prettier --check -
npm run typecheckexits 0 -
npm run lintexits 0 -
npm run test:browserexits 0 (specificallysrc/ogc-api/csapi/formats/part2.spec.ts— all new@linktests green; all existing tests still green) -
npm run test:nodeexits 0
Acceptance Gate (verification command)
The Phase 8 roadmap defines a specific verification command for this task (P8-ROADMAP §Phase C Task C1). Paste the output of these commands on the issue before closing:
# 1. Targeted spec — all new @link tests green; all existing tests green
npm run test:browser -- src/ogc-api/csapi/formats/part2.spec.ts
# 2. Confirm helper exists and is wired in at every cross-reference site
git grep -n "extractCrossReferenceId" -- src/ogc-api/csapi/formats/part2.ts
# Expected: 1 definition + ≥5 call sites
# 3. Confirm no inline obj['<field>@id'] extractions remain in the affected parsers
git grep -n "obj\\['.*@id'\\]" -- src/ogc-api/csapi/formats/part2.ts
# Expected: zero matches in the cross-reference extraction sites
# (some unrelated @id usages may remain in resource-self-id extraction;
# inspect each result before passing)
# 4. Full upstream QA suite (must mirror .github/workflows/qa.yml)
npm run format:check
npm run typecheck
npm run lint
npm run test:browser
npm run test:nodeExpected output:
part2.spec.tsrun: every new test case green; every pre-existing test case still greengit grepconfirms helper definition + ≥ 5 call sites; no remaining inlineobj['...@id']cross-reference extractions- All five upstream QA commands exit 0
Smoke-test marquee: Phase 8's smoke test (smoke-test-prompt-template-phase-8.md) Step 16 exercises the
@linkfallback against the livecs-goserver. That step is the end-to-end interop validation; a greenpart2.spec.tsdoes not satisfy the smoke test, only the unit-level acceptance gate.
Dependencies
Mandatory. Walk the P8-ROADMAP dependency graph and fill in every applicable row.
Blocked by: Task B2 (EndpointError standardization). Recommended sequencing per the roadmap: B2 → C1, so any helper-internal EndpointError throw lands on the standardized type and avoids one revisit. Mechanically, C1 could run before B2; the chosen order saves work.
Blocks: Nothing directly. Task D1 is sequenced last regardless.
Related: Smoke-test Step 16 (live cs-go @link validation); deferred issue #171 (SWE Common-aware result extraction — explicitly NOT this task)
Roadmap dependency row: P8-ROADMAP §Phase C Task C1: "Effort: Small-Medium (~3 hours: helper + 5 call-site swaps + 25 tests + optional fixtures). Risk: Low (@id is the preferred branch; @link is purely additive fallback). Dependencies: Task B2 (so any EndpointError throws inside the new helper are already on the standardized type). Independent of Tasks A1–A4 and B1."
References
| # | Document | What It Provides |
|---|---|---|
| 1 | P8-contribution-goal-and-definition.md | Phase 8 goal, scope, acceptance criteria, locked decisions |
| 2 | P8-implementation-guide.md §5.1 | Authoritative execution-level guide (this task) |
| 3 | P8-ROADMAP.md §Phase C Task C1 | Task ordering, dependencies, acceptance gate |
| 4 | Issue #166 | Authoritative "why" for this task |
| 5 | OGC 23-002 §16.1 | Spec authority for @link / @id cross-reference forms |
| 6 | src/ogc-api/csapi/formats/part2.ts |
Receives the helper + 5 call-site swaps |
| 7 | src/ogc-api/csapi/formats/part2.spec.ts |
Receives ~25–30 new test cases |
| 8 | smoke-test-prompt-template-phase-8.md Step 16 | Live cs-go @link validation |
| 9 | Issue #171 | Deferred — SWE Common result extraction (NOT this task) |
Activity
Sam-Bolling commentedon Apr 29, 2026
Superseded by #166 — Phase 8 absorbed Task C1 in place per the P8-ROADMAP.md Roadmap Summary directive: "Existing issues #166 and #167 already cover Tasks 7 and Task A4 respectively — those issues should be referenced in the corresponding Phase 8 task issue rather than duplicated."
Filing this as a separate Phase 8 wrapper issue was a process error. Issue #166 has been retitled and its body merged with the Phase 8 Task C1 specification (original finding preserved verbatim below the separator). Closing as duplicate.
docs(phase-8): cross-reference GitHub issues #166-#181 in P8-ROADMAP