Skip to content

Phase 3: versioned access UX + file-removed tombstones - #505

Merged
neuromechanist merged 2 commits into
feature/issue-449-epic-data-httpsfrom
feature/issue-497-phase3-versioned-ux
May 15, 2026
Merged

neuromechanist merged 2 commits into
feature/issue-449-epic-data-httpsfrom
feature/issue-497-phase3-versioned-ux

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Phase 3 of epic #449. Closes #497, part of epic #449.

Replaces the Phase 1 placeholder at `//` with a sitemap-style dataset landing page, adds a version picker to directory index pages, and adds structured 404 responses for files that were removed between versions.

What ships

  • Sitemap landing page `//` — content-negotiated HTML (browsers) / JSON (default for machine clients). Lists every published version with DOI, publish date, browse URL, and manifest URL. `?format=json` / `?format=html` overrides Accept.
  • Version picker above the file table on directory index pages. Sibling links (no JS, no ``) preserve the current sub-path when switching versions. Structured tombstone 404s: when a file path is absent in the requested version but existed in an older one, the 404 body carries `reason: "removed"`, `last_seen_version`, `last_seen_url`. Walk capped at 10 prior versions. "Files removed since vN-1" collapsible footer on directory index pages, linking each dropped name to its prior-version URL. HTML 404 page form for tombstones (when `Accept: text/html`). Code shape (consistent with Phase 1+2) All new logic is in pure helpers in `data-router.ts` (testable without D1/S3): `findLastSeenVersion`, `diffRemovedSince`, `pickResponseFormat`, `buildLandingPayload`, `renderDatasetLandingHtml`, `renderTombstone404Html`. `renderIndexHtml` extended with two optional args — old callers compile unchanged, regression test pins the no-arg byte-for-byte output. Route handlers wire D1 + S3 once per request (single `dataset_versions` query feeds picker + diff + tombstone walk). Tests 84 unit tests pass (52 from Phase 1+2 + 32 new). Includes a multi-version manifest fixture, a 12-version chain that exercises the lookback cap, and a defense-in-depth escape test for the picker. E2E: new tests for the landing page (JSON + HTML), the "all versions" footer link, generic 404 vs tombstone 404 content negotiation. Tombstone E2E gracefully skips when `nm099999` lacks two versions with a path drop — unit-test multi-version fixture covers the same branch with hand-built manifests, matching Phase 2's skip pattern. Docs `docs/reference/data-api.md` — new sections for the landing page, version picker, tombstones, and the "removed since" footer. Updated response-code table. `docs/guides/downloading.md` — short user-facing callout with a `curl | jq` example of the tombstone response. Out of scope (per Phase 3: versioned access UX + file-removed tombstones #497) 0-byte S3 placeholders with `x-amz-website-redirect-location` for `s3://nemar/.../dataset/vX.Y.Z/` (epic body explicitly deferred). Bruno's sidecar-in-metadata.json ask — sidecars already work today via the per-path route (git-backed in the manifest, 302 to raw.githubusercontent.com). Reply will be posted to S3 dataset/ prefix: tool-agnostic cloud-like access to NEMAR datasets #449 after this merges. Test plan [x] `bun test test/data-route.unit.test.ts` — 84 pass, 0 fail [x] `bun x tsc --noEmit` from `backend/` — clean [ ] Once the epic ships, smoke-test `data.nemar.org/nm000103/` in a browser and confirm the landing page + picker render [ ] After Phase 3 merge, reply to @bruAristimunha on S3 dataset/ prefix: tool-agnostic cloud-like access to NEMAR datasets #449 clarifying the sidecar contract

Closes #497, part of epic #449.

- Sitemap-style dataset landing page at /<id>/ with content negotiation
  (HTML for browsers, JSON for machine clients). Lists every published
  version with DOI, publish date, browse URL, and manifest URL.
- Version picker (sibling links) in directory index pages when the
  dataset has more than one published version. Preserves the current
  sub-path so switching versions on /sub-01/eeg/ lands on the same
  directory in the target version.
- Structured tombstone 404s: when a path 404s but existed in an older
  version, return reason: 'removed' + last_seen_version + last_seen_url.
  Lookback walk capped at 10 prior versions.
- 'Files removed since vN-1' footer on directory index pages (collapsible
  details/summary) with links into the prior version.
- HTML 404 page form (Accept: text/html) for tombstones.
- 32 new unit tests covering findLastSeenVersion, diffRemovedSince,
  pickResponseFormat, the renderIndexHtml extensions, buildLandingPayload,
  renderDatasetLandingHtml, and renderTombstone404Html. 84 unit tests
  total, all passing.
- E2E tests for the landing page JSON and HTML forms; tombstone E2E
  skips gracefully when nm099999 lacks two versions with a path drop
  (the unit test multi-version fixture covers the same branch).
From the 3-agent /review-pr pass on PR #505:

- HIGH (security): renderTombstone404Html now escapes lastSeen.href in
  the href attribute, not just the link text. Adds a regression test
  with a synthetic hostile href.
- HIGH (silent failure): loadManifest now wraps getManifest in
  try/catch. A transient S3/network throw on the hot Phase 3 paths
  (tombstone walk fans out up to 10 fetches per 404, removed-since
  footer fetches the prior version on every directory render) no
  longer 500s the request -- degrades to no-tombstone / no-footer.
- HIGH (silent failure): loadVersionRows absorbs D1 errors and returns
  an empty array, with a logged error. The version picker and
  removed-since features are presentational; their D1 query failing
  must not cascade a 500 onto a file-redirect that would otherwise
  succeed.
- MEDIUM: file 404 JSON bodies now echo version + path, parity with
  the HTML 404 form. Lets a JSON consumer self-describe a 404 without
  re-parsing the request URL.
- Promotes toVersionTag to a shared exported helper in data-router.ts;
  metadataJsonHandler reuses it (was a duplicated inline coercion).
  Adds focused unit tests; the coercion bug class (mixed tag-form and
  bare versions in D1) is the highest-impact silent regression
  identified by the test analyst.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review pass (3 sonnet agents in parallel)

Findings addressed in 406f0ac:

  • HIGH (code-reviewer): lastSeen.href was interpolated raw into the href=\"...\" attribute in renderTombstone404Html (only the link text was escaped). Fixed; added a regression unit test with a synthetic hostile href that includes \"><script>.
  • HIGH (silent-failure-hunter): getManifest can throw on S3/network errors; loadManifest didn't catch and the throw propagated up through the new tombstone walk and the removed-since footer fetch. Both are presentational features; a transient S3 blip shouldn't 500 a 404. Fixed: loadManifest now wraps getManifest in try/catch and returns null with a logged error.
  • HIGH (silent-failure-hunter): The new loadVersionRows D1 query is called after the manifest is confirmed present in fileOrIndexHandler. A D1 throw would have killed an otherwise-successful file redirect (the version picker is a side-feature). Fixed: loadVersionRows catches and returns [] with a logged error.
  • MEDIUM: file 404 JSON bodies now echo version + path for parity with the HTML 404 form (the HTML page renders them visibly; the JSON shape didn't).
  • Test gap (test-analyzer, criticality 8): toVersionTag was a duplicated inline coercion in data.ts. Promoted to an exported helper in data-router.ts, reused in metadataJsonHandler, and pinned with focused unit tests. This is the highest-impact silent-regression class identified by the test pass (mixed tag-form / bare-version D1 rows).

Findings dismissed:

  • Host-header spoof in last_seen_url -- false positive on a Cloudflare Worker with a bound custom domain. The hunter tagged this as dismissable themselves.
  • "E2E test for ?format=html on landing page" -- low risk; pickResponseFormat is unit-tested for that branch and datasetRootResponse calls it identically to the JSON-format E2E test that is present.
  • "Renderer receives bare-version input directly" -- only reachable if a caller bypasses buildLandingPayload. Not a real production path.
  • "Removed-since footer never verified end-to-end at the route level" -- the E2E fixture (single-version nm099999) can't exercise this branch. Same gap as the tombstone E2E; same mitigation (multi-version unit fixture).

Unit test count: 52 -> 88 (Phase 3 adds 36). All passing.

Ready to merge.

@github-actions

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR505

Version: 0.8.15-PR505.406f0ac
Commit: 406f0ac


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit b3edd29 into feature/issue-449-epic-data-https May 15, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feature/issue-497-phase3-versioned-ux branch May 18, 2026 11:10

This branch was previously deployed

1 inactive deployment
npm — 406f0ac3 Deployed May 15, 2026 by neuromechanist via publish #913
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.

1 participant