Skip to content

Add EZID service, DataCite XML builder, and skill - #109

Merged
neuromechanist merged 2 commits into
devfrom
106-phase-1-ezid-service-datacite-xml-builder-claude-code-skill
Feb 11, 2026
Merged

neuromechanist merged 2 commits into
devfrom
106-phase-1-ezid-service-datacite-xml-builder-claude-code-skill

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Phase 1 of the EZID DOI migration (Epic #105, closes #106):

  • EZID API client (backend/src/services/ezid.ts): Full ANVL encoding/decoding, mint/get/update/delete/makePublic operations, test and production shoulder constants
  • DataCite XML builder (backend/src/services/datacite.ts): Generates kernel-4 XML with all 20 DataCite metadata fields, maps BIDS dataset_description.json to DataCite, supports enrichment (ORCIDs, affiliations, related DOIs, funding)
  • Claude Code skill (.claude/plugins/ezid-doi/): API reference, DataCite field documentation, BIDS-to-DataCite mapping, example scripts, /ezid-test command
  • Tests: 32 unit tests + 17 sandbox integration tests mirroring zenodo-sandbox.test.ts pattern

Test plan

  • Unit tests: bun test test/ezid.test.ts test/datacite.test.ts (32 tests)
  • Sandbox tests: RUN_EZID_TESTS=true bun test test/ezid-sandbox.test.ts (17 tests)
  • Full DOI lifecycle verified against test shoulder doi:10.5072/FK2
  • DataCite XML with all 20 fields: creators with ORCID/ROR, subjects, rights, descriptions, relatedIdentifiers, fundingReferences, sizes, formats, version
  • Connectivity test script: bash .claude/plugins/ezid-doi/skills/ezid-api/scripts/test-connectivity.sh

Phase 1 of EZID DOI migration (#106):

- backend/src/services/ezid.ts: EZID API client with ANVL
  encoding, mint/get/update/delete/makePublic operations
- backend/src/services/datacite.ts: DataCite kernel-4 XML builder
  mapping all 20 metadata fields from BIDS data
- .claude/plugins/ezid-doi/: Claude Code skill with API reference,
  DataCite field docs, metadata mapping, example scripts
- test/ezid.test.ts: Unit + live API tests (32 tests)
- test/datacite.test.ts: XML builder + BIDS mapping tests
- test/ezid-sandbox.test.ts: Sandbox integration tests matching
  zenodo-sandbox.test.ts pattern (opt-in via RUN_EZID_TESTS=true)

Tested against EZID test shoulder doi:10.5072/FK2. Full lifecycle
verified: mint -> get -> update -> make public -> update metadata.
Type improvements:
- Add controlled vocabulary union types (ResourceTypeGeneral,
  ContributorType, DateType, RelationType, DescriptionType)
- Add discriminated union for EzidMintOptions (dataciteXml vs
  dataciteFields mutual exclusivity)
- Consolidate per-author enrichment maps into single
  authorEnrichment record in DataCiteEnrichment
- Add BidsDatasetDescription interface replacing unsafe as casts

Error handling:
- Add HTTP status validation in ezidRequest for non-ANVL responses
- Wrap fetch in try/catch with EZID context
- Fix body || undefined to body !== undefined check
- Add mandatory field validation in buildDataCiteXml
- Add empty-string auth validation in basicAuthHeader
- Fix percentDecode for multi-byte UTF-8 via decodeURIComponent
- Add parseEzidStatus for unavailable | reason parsing
- Improve parseStatusLine for unknown response formats

Tests:
- Add ANVL continuation line, edge case, and roundtrip tests
- Add colon preservation, combined encoding tests
- Add PDDL license, double-quote escaping tests
- Add buildDataCiteXml validation error tests
- Add BIDS Funding fallback and enrichment priority tests
- Use describe.skipIf for sandbox tests (honest skip reporting)
- Improve assertion specificity on error messages
@neuromechanist

Copy link
Copy Markdown
Contributor Author

PR Review Summary

Comprehensive review run with 5 specialized agents: code-reviewer, silent-failure-hunter, pr-test-analyzer, type-design-analyzer, and code-simplifier. All findings addressed in fccac36.

Critical Issues (3 found, 3 fixed)

# Issue Fix
1 ezidRequest no HTTP status validation; HTML error pages produce garbled messages Added guard: non-ok responses that aren't ANVL "error:" throw with HTTP status and truncated body
2 fetch exceptions propagate with no EZID context Wrapped fetch in try/catch, errors now include method and path
3 checkStatus returns silent false for unexpected responses Now caught by ezidRequest HTTP guard before reaching checkStatus

High Issues (5 found, 5 fixed)

# Issue Fix
4 percentDecode corrupts multi-byte UTF-8 (e.g. accented names) Switched to decodeURIComponent with byte-level fallback
5 buildDataCiteXml no mandatory field validation Added upfront checks: identifier, creators, titles, publisher, publicationYear
6 8 unsafe as casts on BIDS fields in bidsToDataCite Created BidsDatasetDescription interface; replaced all casts with safe coercion (Array.isArray, typeof)
7 EzidStatus parsing doesn't handle unavailable | reason Added parseEzidStatus() helper; added unavailableReason?: string to EzidIdentifier
8 makeUnavailable bypasses updateIdentifier with duplicated error handling Added JSDoc explaining why (EZID requires unavailable | <reason> not representable as EzidStatus)

Medium Issues (4 found, 4 fixed)

# Issue Fix
9 body || undefined converts empty string body to no body Changed to body !== undefined ? body : undefined
10 parseStatusLine conflates unrecognized format with explicit error Now returns descriptive Unexpected EZID response: "..."
11 Object.keys(fields).pop() mutation pattern in decodeAnvl Changed to keys[keys.length - 1]
12 Empty-string auth credentials produce broken Basic auth header Added validation in basicAuthHeader

Type Design Improvements (5 found, 5 fixed)

# Issue Fix
13 resourceTypeGeneral, contributorType, dateType, relationType all bare string Added union types: ResourceTypeGeneral, ContributorType, DateType, RelationType, DescriptionType
14 dataciteXml and dataciteFields not mutually exclusive Added discriminated union for EzidMintOptions with never guards
15 Three separate Record<string, string> maps for per-author enrichment Consolidated into single authors?: Record<string, AuthorEnrichment>
16 created/updated timestamps semantics unclear Added JSDoc: "Unix epoch seconds"
17 getDoiUrl duplicated extractDoi logic Simplified to reuse extractDoi

Test Coverage Gaps (12 found, 12 fixed)

# Gap New Tests
18 ANVL continuation line decoding untested decodeAnvl handles continuation lines
19 decodeAnvl edge cases untested handles empty body, handles status-only body, skips malformed lines
20 percentDecode combined/multi-byte untested handles combined encodings, handles multi-byte UTF-8
21 Encode/decode roundtrip untested percentEncode/percentDecode roundtrip
22 Colon preservation in ANVL values not explicit encodeAnvl preserves colons in values
23 PDDL license variants untested maps PDDL, maps PDDL-1.0
24 escapeXml double-quote untested escapes double quotes in attribute values
25 buildDataCiteXml validation errors untested throws on missing identifier, throws on empty creators/titles, throws on invalid publicationYear
26 BIDS Funding fallback untested maps BIDS Funding to fundingReferences, prefers enrichment fundingInfo
27 Sandbox tests fake-pass when skipped Replaced if (!SHOULD_RUN) return with describe.skipIf(!SHOULD_RUN)
28 Sandbox error assertions too weak (toContain("error")) Tightened to toContain("EZID delete error"), toContain("EZID mint error"), toContain("EZID")

Test Results

  • 49 unit tests pass (was 32, added 17 new)
  • 17 sandbox integration tests properly skip without RUN_EZID_TESTS=true
  • Total: 66 tests across 3 files

Files Changed

File Changes
backend/src/services/datacite.ts +179/-60: Union types, enrichment consolidation, BidsDatasetDescription, validation
backend/src/services/ezid.ts +100/-35: HTTP guards, auth validation, discriminated union, parseEzidStatus
test/datacite.test.ts +118/-5: Validation, PDDL, double-quote, funding, enrichment tests
test/ezid-sandbox.test.ts +25/-88: describe.skipIf, tighter assertions, consolidated enrichment
test/ezid.test.ts +61/-0: Continuation lines, edge cases, UTF-8, roundtrip, colon tests

@neuromechanist
neuromechanist merged commit eb599ca into dev Feb 11, 2026
7 checks passed
@neuromechanist
neuromechanist deleted the 106-phase-1-ezid-service-datacite-xml-builder-claude-code-skill branch February 11, 2026 00:55
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