Skip to content

#71: Consume nemar-cli /<id>/page-bundle.json on dataset detail - #72

Merged
neuromechanist merged 2 commits into
mainfrom
feature/issue-71-page-bundle-consumer
May 27, 2026
Merged

neuromechanist merged 2 commits into
mainfrom
feature/issue-71-page-bundle-consumer

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Wires the website's dataset detail SSR fetch chain to the unified GET /<id>/page-bundle.json?v=<v> endpoint shipped in nemar-cli#617 (closed; all 130 datasets backfilled to schema 1.1). One upstream call now serves landing + metadata + summary + catalog_row, replacing three of the four parallel fetches at the top of src/pages/dataset/[id].astro. QA aggregates stay separate (intentionally out of the bundle per #617 scope) and run in parallel with the bundle fetch.

The bundle accepts ?v=<v> or no version (resolves to landing.latest internally), so deep links and bare /dataset/<id> URLs both pay one RTT regardless of how the user arrived.

The pre-#71 four-way fan-out stays as the fallback path: bundle 404 / 503 / timeout / parse-error all degrade transparently to the existing helpers, so older datasets without warm bundle entries, transient upstream outages, and rolling deploys never break a render.

Closes #71

Files touched

  • src/lib/data-api.ts — BundleField<T> + DatasetPageBundle types, getDatasetPageBundleOutcome helper (4s timeout, tighter than the 5s fan-out default so a slow bundle fails fast), bundleFieldToOutcome adapter that lifts the bundle's per-field envelopes into the existing FetchOutcome union (so resolveDatasetPageStatus is reused unchanged), bundleUrl builder.
  • src/pages/dataset/[id].astro — bundle-first SSR with the previous Promise.all preserved verbatim inside the else branch.
  • src/lib/data-api.test.ts — 8 new tests (adapter contract + fixture roundtrip + schema 1.1 readme.content contract).
  • test/fixtures/dataset-page-bundle-on005505.min.json — 16 KB slim of the live bundle (paths trimmed from 5,409 to 10, subjects from 136 to 5; readme.content kept intact for Phase 2 verification).

Test plan

  • bun run typecheck — 0 errors / 0 warnings / 0 hints
  • bun run lint — biome clean (organizeImports applied by --write)
  • bun run test — 401/401 (was 393; +8 in data-api.test.ts)
  • bun run build — astro build clean, Workers-runtime warnings unchanged
  • Post-deploy verification: devtools network panel on https://ww2.nemar.org/dataset/on005505 should show ONE data.nemar.org fetch (the page-bundle) plus the QA fetch on cold isolate, instead of three separate ones. The deferred /api/dataset/<id>/{readme,tree} partial fetches still happen client-side as before.
  • /browse against the Pages preview — verify cold first-paint TTFB drops to ~1 s (current is closer to ~2 s due to serial fan-out + slowest of getMetadataOutcome's 5 s timeout).
  • Force-fallback verification by temporarily pointing PUBLIC_DATA_BASE_URL at a bogus host: page must still render via the fan-out path, with the [dataset/<id>] bundle unavailable warning visible in dev server logs.

Out of scope (follow-up issues to file if perf gap persists)

  • Summary handoff to the deferred partial endpoints: readme.ts and tree.ts still fetch summary.json themselves on the client side. The bundle already carries summary.data — a future change could inline it into the SSR HTML and skip those fetches entirely. Out of scope here (requires shared SSR state or a separate proxy design).
  • Removing the now-redundant fan-out helpers: getLandingOutcome, getMetadataOutcome, getDataset stay because they're the fallback path AND they're used directly by the partial endpoints' resolution chains. Cleanup once we're confident the bundle is universally reliable.

Wires the website's dataset detail SSR fetch chain to the unified
GET /<id>/page-bundle.json?v=<v> endpoint (nemar-cli#617). One
upstream call replaces three of the four previous parallel fetches
(landing + metadata + catalog_row); QA stays separate (intentionally
out of the bundle per #617 scope). The bundle accepts ?v=<v> or no
version (resolves to landing.latest internally), so deep links and
bare /dataset/<id> both pay one RTT.

Adds:
- BundleField<T> + DatasetPageBundle types in src/lib/data-api.ts
- getDatasetPageBundleOutcome(id, v) helper (4s timeout, FetchOutcome
  shape so the existing resolveDatasetPageStatus works unchanged)
- bundleFieldToOutcome adapter that lifts the bundle's per-field
  { ok, data } envelope into the existing FetchOutcome union
- bundle-first SSR in dataset/[id].astro with the pre-#71 fan-out
  intact as the fallback (404 / 503 / timeout / parse error all
  fall through cleanly)
- 8 unit tests against a captured 16KB real-shape fixture, including
  schema 1.1 readme.content roundtrip so Phase 2's Step 0.5 contract
  stays pinned

401/401 tests pass; bun run build clean.

Closes #71
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 27, 2026 •

Copy link
Copy Markdown

Five sonnet reviewers ran in parallel. Critical + important fixes:

- code-reviewer + pr-test-analyzer: DatasetPageBundle.catalog_row
  was typed BundleField<Dataset>, but the bundle endpoint actually
  emits a structurally sparse subset (no id, doi, status, etc.).
  Define a dedicated BundleCatalogRow with the fields the bundle
  guarantees; switch catalog_row's generic to it; update the
  consumer's catalogRow variable type. Dataset is now unused in
  data-api.ts so the import is dropped.

- code-reviewer + pr-test-analyzer (forced into scope by the type
  fix): enrichedMetadata.license checked catalogRow?.doi (a typo
  for ?.license, plus ?: instead of ||) so the catalog's license
  never reached the rendered output for any code path. The
  BundleCatalogRow type made the broken reference a type error,
  forcing the fix. Now: license falls back from metadata.license
  to catalog_row.license to null in the canonical || chain that
  the sibling modalities/tasks/authors branches already use.

- comment-analyzer + type-design-analyzer + code-reviewer:
  bundleFieldToOutcome's "bundle field ok=false" statusText was
  misleading when the actual cause was ok=true with data=null.
  Split into two distinct sentinel strings so Workers logs can
  triage which side of the worker's contract broke. Add a test
  asserting the new wording for the ok=true+data=null branch.

- silent-failure-hunter: the partial-bundle warning conflated
  complete=false (real upstream failure) with enrichment_degraded
  alone (routine OpenNeuro sparse-catalog state). Log only on
  complete=false so chronic noise doesn't dilute the genuine
  signal.

- silent-failure-hunter: parse_error was the only non-ok bundle
  outcome that signals CLI contract drift (200 with unparseable
  body); everything else is transient infrastructure. Branch the
  fallback log so parse_error fires at error level and the rest
  stay at warn.

- code-reviewer (wording): the bundle-restructured fan-out is
  still effectively four-way (three SSR fetches + QA), just
  reorganized. Fix the misleading "three-way" comment.

- comment-analyzer: tighten the BundleField doc with a scope-
  narrowing parenthetical so a future change to
  resolveDatasetPageStatus that consults summary/catalog_row
  doesn't silently invalidate the adapter contract.

Deferred per existing-scope policy: extracting the enrichedMetadata
merger to a pure helper for separate test coverage (pr-test-
analyzer 6/10), bundle-vs-fan-out race pattern to bound 9s worst-
case TTFB (code-reviewer important, follow-up issue territory).

401/401 tests pass; bun run build clean.
@neuromechanist
neuromechanist merged commit a103f26 into main May 27, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feature/issue-71-page-bundle-consumer branch June 21, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consume nemar-cli /<id>/page-bundle.json on dataset detail

1 participant