Skip to content

Phase 3: Rich metadata enrichment for DataCite DOIs - #115

Merged
neuromechanist merged 7 commits into
devfrom
feature/issue-108-phase3-enrichment
Feb 11, 2026
Merged

neuromechanist merged 7 commits into
devfrom
feature/issue-108-phase3-enrichment

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Closes #108

Phase 3 of the EZID DOI epic (#105). Adds rich metadata enrichment for DataCite DOI records:

  • LLM enrichment: OpenRouter API extracts description, keywords, funding, related DOIs from README
  • Upload-time ORCID collection: Prompts co-authors for ORCID during dataset upload
  • Admin doi enrich command: Interactive enrichment with LLM + manual ORCID editing
  • nemar_metadata.json: Canonical enrichment file stored in dataset repos
  • Backend enrichment endpoint: POST /admin/datasets/:id/enrichment commits to repo + caches in D1
  • Dataset stats: Sizes and formats from GitHub tree API, included in DataCite XML

Code quality improvements (from 2 rounds of PR review)

  • Extracted handleCommandError, getS3Config, startStep, revertVisibilityChanges helpers
  • Added isValidRelationType runtime validator (no unsafe casts)
  • Fixed empty catch blocks across codebase
  • Net reduction of ~185 lines through deduplication

Test plan

  • bun test - 335 pass, 0 fail, 20 skip
  • bunx biome check - pre-existing issues only (not from this PR)
  • Manual: nemar admin doi enrich nm099999 --sandbox
  • Manual: nemar admin doi enrich nm099999 --sandbox --no-llm

Files changed

File Change
backend/src/services/datacite.ts NemarMetadata, parseNemarMetadata(), isValidRelationType(), sizes/formats
backend/src/db/migrations/0008_enrichment.sql enrichment_json, enrichment_updated_at columns
backend/src/routes/admin.ts Enrichment + files endpoints, getS3Config/startStep/revertVisibilityChanges helpers
backend/src/routes/webhooks.ts Read nemar_metadata.json during version DOI creation
src/lib/llm-enrich.ts New: OpenRouter LLM enrichment service
src/lib/api.ts submitEnrichment(), getDatasetFiles()
src/commands/dataset.ts Upload-time ORCID collection, step count fix
src/commands/admin.ts doi enrich command, handleCommandError helper, publish fixes
test/doi-provider.test.ts 30 new tests for enrichment parsing and validation
test/publish-workflow.test.ts Fix stderr assertion for ora spinner output

Phase 3 of EZID DOI epic (#108): adds NemarMetadata type/parser,
LLM-based enrichment from README via OpenRouter, upload-time ORCID
collection for co-authors, admin doi enrich command, backend
enrichment endpoint, DB migration, and 22 new tests.
- Add try-catch around LLM JSON.parse with contextual error message
- Export validateLlmResult for testing; add 8 tests
- Add isValidRelationType validator; filter invalid types in conversion
- Replace empty catch blocks with logged warnings in dataset/admin CLIs
- Add console.error to /files endpoint error handler
- Remove duplicate formatDatasetSize, use shared formatBytes
- Fix stale "placeholder" comment on DOI section
- Fix publication step count: CLI now shows all 14 orchestrator steps
- Extract revertVisibilityChange helper (removes ~60 lines duplication)
- Extract getS3Config helper (replaces 9 inline S3 credential objects)
- Extract startStep helper (replaces 14 current_step DB updates)
- Add handleCommandError helper for CLI error handling
- Add isValidRelationType validator with Set lookup
- Clean up type guards in llm-enrich.ts
- Remove duplicate audit log comment
- Replace nested ternary with lookup map in dataset.ts
Replace 3 duplicate error display patterns (spinner.fail + console.log
of same message) with handleCommandError helper. Update tests to check
stderr where ora spinner output lands.
Deduplicate ORCID regex (was in admin.ts and dataset.ts),
error message extraction pattern (7+ instances), and GitHub
file content fetching via gh api subprocess.
- Derive RelationType from const array (single source of truth)
- parseNemarMetadata: reject unrecognized versions, validate
  relationType at parse time
- nemarMetadataToEnrichment: merge funding (was overwrite),
  deduplicate related DOIs by doi+relationType
- validateLlmResult: validate relationType, validate funding
  field types (awardNumber/awardTitle must be string)
- Backend: add warnings array to DOI update response, surface
  enrichment parse failures in webhook response
- Fix extension extraction for files without dots
- Fix JSDoc claiming endpoint refreshes DOIs (it doesn't)
- CLI: warn on BIDS parse failure, re-attempt DOI fetch before
  refresh, remove stale comments, wrap writeFileSync in try-catch
- Add 13 new tests (version check, partial fields, merge/dedup,
  funding conversion, enrichFromReadme early return)
@github-actions

github-actions Bot commented Feb 11, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR115

Version: 0.3.11-PR115.fd6f8b5
Commit: fd6f8b5


🤖 Updated on each push.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

PR Review: Comprehensive Review with All Fixes Applied

Ran 6 review agents in parallel. All findings addressed in 3 commits.

Review Findings and Fixes

datacite.ts:

  • Derived RelationType from const array (single source of truth, eliminates sync risk)
  • parseNemarMetadata now rejects unrecognized versions and validates relationType at parse time
  • nemarMetadataToEnrichment: funding now merges (was overwrite), related DOIs deduplicated by doi+relationType
  • Updated JSDoc with per-field merge semantics

backend admin.ts:

  • Fixed JSDoc claiming enrichment endpoint refreshes DOIs (it doesn't)
  • Fixed extension extraction for files without dots (e.g., README no longer becomes .README)
  • Added warnings array to DOI update response to surface enrichment parse failures

webhooks.ts:

  • Added enrichment_warning field to version DOI response when nemar_metadata.json parsing fails

CLI admin.ts:

  • Replaced empty catch {} on BIDS description parse with user-visible warning
  • Added DOI fetch retry before refresh (handles transient errors)
  • Warns user to manually refresh if DOI info unavailable
  • Removed stale comments about discarded approaches
  • Fixed let doiInfo implicit any

CLI dataset.ts:

  • Wrapped writeFileSync for nemar_metadata.json in try-catch (non-fatal on failure)
  • Improved ORCID catch block to distinguish API errors from file errors
  • Note: code-reviewer flagged nemar_metadata.json as "not committed" but this is a false positive; it is picked up by saveDataset's git add -A in Step 11

llm-enrich.ts:

  • Changed "Valid relationType values" to "Common relationType values (see DataCite schema for full list)"
  • Added relation type validation in validateLlmResult
  • Added type validation for funding field types (awardNumber/awardTitle must be string)

Tests (13 new, 348 total):

  • parseNemarMetadata: version rejection, partial relatedDois, partial fundingReferences, relationType validation at parse time
  • nemarMetadataToEnrichment: funding merge/dedup, related DOIs dedup, funding field mapping, description/methods passthrough
  • validateLlmResult: relation type filtering, non-string awardNumber filtering
  • enrichFromReadme: returns empty when no API key

CI Status

All checks green: lint, unit-test, api-test, e2e-sandbox, zenodo-sandbox-test, publish, changes.

Commits

  1. a03147f - Phase 3 implementation (cherry-picked from dev)
  2. c70760f - Fix silent failures, validate types
  3. 38d948c - Simplify code, extract helpers
  4. 647308e - Extract ORCID_REGEX, errorDetail, fetchGitHubFileContent
  5. e081d60 - Address review: merge semantics, validation, warnings, 13 new tests
  6. fd6f8b5 - Fix lint: type annotation, biome formatting

@neuromechanist
neuromechanist merged commit 7a3338f into dev Feb 11, 2026
8 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-108-phase3-enrichment branch March 6, 2026 23:56

This branch was previously deployed

1 inactive deployment
npm — fd6f8b50 Deployed Feb 11, 2026 by neuromechanist via publish #192
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