Skip to content

#76: Pivot dataset detail to canonical sources (drop summary/bundle/partials) - #77

Merged
neuromechanist merged 1 commit into
mainfrom
feature/issue-76-canonical-sources-pivot
May 27, 2026
Merged

neuromechanist merged 1 commit into
mainfrom
feature/issue-76-canonical-sources-pivot

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

A week of cold-isolate patches on the dataset detail page (#65, #63, #64, #71, #74) failed to fix the user-reported HBN failure case (on005510 / 11 / 12 / 14). Investigation surfaced that we'd been engineering around a constraint that no longer binds — the canonical sources (GitHub raw + data.nemar.org/<id>/<v>/?format=json shipped today as nemar-cli#636 / v0.8.37) are fast and well-shaped. The duplicate-fetch pipeline we'd layered on top (summary.json consumer + page-bundle.json aggregator + the /api/dataset/<id>/{readme,tree} partial endpoints) was the actual failure surface.

This PR tears the whole pipeline out and replaces it with direct client-side consumption of the canonical sources. Net delete: ~1400 lines across 8 files, +740 lines added.

Closes #76.

The new architecture

  • SSR (dataset/[id].astro): just landing.json + metadata.json + the api.nemar.org catalog row + QA. Flat parallel fan-out, the pre-Consume nemar-cli /<id>/page-bundle.json on dataset detail #71 baseline.
  • README: deferred <article data-readme-defer> skeleton; the client script fetches raw.githubusercontent.com/<repo>/<v>/README.md (~276 ms via GitHub's CDN) and renders through the existing markdown.ts (already zero-dep and browser-safe — confirmed in the explorer audit). Falls back to metadata.description (SSR-passed via data-fallback-desc) when GitHub raw 404s.
  • Tree: deferred <section data-tree-defer> skeleton; the client script fetches data.nemar.org/<id>/<v>/?format=json (14 KB top-level with real per-file sizes), renders via the new renderTopLevel. Every directory is a closed <details data-dir-path="X"> with an empty [data-dir-target] slot. A capture-phase toggle listener on document fetches each subdirectory's listing on first expand and fills the slot via renderSubdir. data-loaded="true" guards against re-fetches.

Net additions

  • src/lib/dir-listing.ts — typed client (DirListing, DirListingEntry, fetchDirListing, fileDownloadUrl, dirListingUrl).
  • src/lib/render-dir-listing.ts — browser-side renderer; mirrors the existing .tree__* CSS class shapes so the global styles in BidsTree.astro apply unchanged.
  • src/lib/dir-listing.test.ts (8 tests) + src/lib/render-dir-listing.test.ts (10 tests) — URL construction + render markup pinning.
  • Rewritten <script> in src/pages/dataset/[id].astro — capture-phase toggle handler, GitHub raw fetch with metadata-description fallback, dir-listing fetch.

Deletions

  • src/pages/api/dataset/[id]/readme.ts — entire endpoint.
  • src/pages/api/dataset/[id]/tree.ts — entire endpoint.
  • src/lib/render-readme.ts, src/lib/render-tree.ts — both renderers (the partial endpoints' output). Their static fallback strings ("No description available", "File index unavailable") moved into the client script.
  • src/lib/bids-tree.ts — kept classifyFile only. buildTree, buildTreeFromPaths, TreeNode, sortAndSum gone.
  • src/lib/data-api.ts — kept the FetchOutcome machinery, resolveDatasetPageStatus, getLandingOutcome, getMetadataOutcome, isUnpublished, archiveZipUrl. Removed: Summary + all summary helpers, Manifest + all manifest helpers, BundleField / DatasetPageBundle / BundleCatalogRow + the bundle fetcher + adapter, findReadmePathInSummary, findReadmeContentInSummary, findReadmeEntry, fetchManifestEntryText, fetchGithubReadme.
  • Tests: render-tree.test.ts, render-unpublished.test.ts, tree-endpoint.test.ts. Trimmed the bundle/summary blocks out of data-api.test.ts and bids-tree.test.ts.
  • Fixture: test/fixtures/dataset-page-bundle-on005505.min.json.

License fallback

enrichedMetadata.license no longer reads from catalogRow?.license — Dataset (the api.nemar.org catalog row shape) doesn't have license. That field only existed on the bundle's BundleCatalogRow subset, which goes away with this PR. License now collapses to metadata.license || null. For datasets where metadata.license is set, behavior is unchanged. For the rare sparse-metadata + populated-catalog-license case, the rail shows no license; this is a small regression that the optional CLI follow-up (move license into the D1 catalog row OR add it to the JSON dir listing root response) can close cleanly.

CORS sanity check

Verified via curl preflight 2026-05-27: data.nemar.org/<id>/<v>/?format=json returns Access-Control-Allow-Origin: http://localhost:4321 (the Hono middleware on api.nemar.org's worker reflects allow-listed origins, including ww2.nemar.org, app.nemar.org, and localhost:4321). GitHub raw is Access-Control-Allow-Origin: * for public repos; all nemarDatasets/* repos are public per AGENTS.md.

Test plan

  • bun run typecheck — 0 errors / 0 warnings / 0 hints.
  • bun run lint — biome clean.
  • bun run test — 365/365 pass (was 403; deletion trimmed 38 bundle/summary tests).
  • bun run build — astro build clean.
  • bun run dev on on005514 / on005512 / on005510 / on005511: README + tree both render on the first cold-PoP visit, no refresh cycle. Subject directory click → subtree expands in < 500 ms.
  • /browse against the Pages preview at a cold PoP (cf-fra / cf-syd) — first visit succeeds.

Side effects on filed issues

  • Closes nemarOrg/nemar-cli#635 (schema 1.2 path_sizes) — obsoleted by JSON dir listings (sizes already in the listing).
  • Closes nemarOrg/website#73 (consume path_sizes) — same.
  • nemar-cli#616 (schema 1.1 readme.content) stays shipped but unused; the CLI can deprecate when convenient (filed as nemar-cli#TBD-retire).

What stays

  • Edge cache namespace + middleware (separate concern, untouched).
  • Discover page, all other routes, all auth surface.
  • renderMarkdown and markdown.test.ts — both unchanged, both reused by the new client script.

@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

A week of cold-isolate patches on the dataset detail page failed to
fix the user-reported HBN failure case (on005510 / 11 / 12 / 14).
The actual failure surface was the duplicate-fetch pipeline we built
on top of data.nemar.org: summary.json reconstruction, the page-
bundle adapter, and the deferred partial endpoints all re-fetched
summary.json from cold isolates on every visit. Closes the pattern
entirely.

Replaces the pipeline with direct consumption of the canonical
sources:

- README: client-side fetch to raw.githubusercontent.com/<repo>/<v>/
  README.md via GitHub's CDN, rendered with the existing markdown.ts
  which was already zero-dep and browser-safe.
- Tree: client-side fetch to data.nemar.org/<id>/<v>/?format=json
  (the JSON content negotiation shipped today as nemar-cli#636 /
  v0.8.37). Top-level JSON with real per-file sizes; native lazy-
  per-directory via <details> toggle + a capture-phase listener
  that fetches each subdirectory's listing on first expand.

SSR collapses back to landing + metadata + catalog + qa fan-out
(pre-#71 baseline). No bundle, no summary, no manifest, no partial
endpoints. enrichedMetadata loses the catalog license fallback
because Dataset doesn't carry license (the bundle's catalog_row
subset that did is gone with this PR); metadata.license is the
source.

Net delete: ~1400 lines across 8 files, +740 added. 365 tests pass
(was 403; deletion trimmed 38 bundle/summary tests).

Closes #76.
@neuromechanist
neuromechanist force-pushed the feature/issue-76-canonical-sources-pivot branch from 142ef66 to b853f4c Compare May 27, 2026 14:46
@neuromechanist
neuromechanist merged commit 74f2071 into main May 27, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feature/issue-76-canonical-sources-pivot 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.

Pivot to canonical sources: drop summary.json + page-bundle + partial endpoints

1 participant