Skip to content

Upstream license lineage resolver and license-check - #2372

Merged
neuromechanist merged 10 commits into
feature/issue-2182-epic-pq-decidefrom
feature/issue-2182-license-lineage
Nov 25, 2026
Merged

neuromechanist merged 10 commits into
feature/issue-2182-epic-pq-decidefrom
feature/issue-2182-license-lineage

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2361, epic #2182 (card D1; ADR 0139 decision 7).

What

  • shared/license-lineage.ts: one resolver, shared by the CLI and the Worker. It finds a dataset's upstream sources (SourceDatasets, enrichment IsDerivedFrom/IsIdenticalTo, the attestation's upstream source, the README), reads each source's license and resource type (DataCite, then Crossref, then OpenAlex; 8 s per fetch, at most 10 sources), normalizes it into the closed set, and combines the sources on a restriction lattice into one closed outcome. Every outcome and source status has a statement, what was read, a remedy and a docs anchor in LINEAGE_COPY / SOURCE_STATUS_COPY; a missing entry fails the typecheck. User-Agent nemar-license-check/1, no contact details. A fetch error is unresolved, never compatible, never cached, and never falls through to the next registry.
  • GET /admin/datasets/:id/license-lineage: read-only, computed on demand, registry answers cached per DOI for 24 hours in the Worker cache. No migration.
  • nemar dataset license-check <path> (exit 0 for compatible, compatible_attribution, compatible_nc; 2 otherwise; 1 for an unreadable path) and nemar admin dataset publish license-lineage <id>, printing the same lines from the copy table.
  • src/lib/provenance.ts now uses the shared rule. Behavior change: an unrecognized source license needs permission instead of passing with a warning.

Deviations from the card (lead ruling, 2026-11-25)

  1. Fourth resolver for OpenNeuro and PhysioNet. Measured on 2026-11-25: DataCite holds an empty rightsList for every OpenNeuro and PhysioNet record sampled, Crossref has neither, and OpenAlex has no license for them. When DataCite returns a Dataset record with no usable rights and the DOI or landing URL is OpenNeuro or PhysioNet, the resolver asks that repository's own API (OpenNeuro GraphQL snapshot description.License; PhysioNet /api/v1/project/published/<slug>/<ver>/ license name and access_policy). Resolver ids openneuro and physionet; same timeout, cache and unresolved-on-failure. A PhysioNet access policy other than Open maps to physionet-credentialed or physionet-restricted whatever the license name. PhysioNet URLs go to the PhysioNet API directly, which also returns the project's DOI.
  2. README DOIs are taken only under data-repository prefixes (OpenNeuro, Zenodo, PhysioNet, figshare, OSF, Dryad, Dataverse), since READMEs cite papers; SourceDatasets and the attestation take any DOI.
  3. Admin command path. The card named nemar admin dataset license-lineage; ADR 0135 caps admin dataset at twelve visible children (test/admin-write-flag.unit.test.ts), so the command is nemar admin dataset publish license-lineage <id>, beside the other publication-request commands.
  4. No shared/openapi.json entry. That document is the public catalog surface only, and backend/test/openapi-document.test.ts pins exactly its four paths.

License classes (lead ruling 2026-11-25): MIT, BSD-2-Clause, BSD-3-Clause and Apache-2.0 normalize to permissive-attribution, which behaves like CC BY (compatible_attribution; the copy says these are software licenses applied to data and still require attribution); the Creative Commons Public Domain Mark normalizes to cc0. Other versions and clauses (BSD-4-Clause, Apache-1.1, GPL) stay other.

Lattice, most restrictive first: redistribution_prohibited > needs_permission > source_is_publication > unresolved > share_alike_mismatch > compatible_nc > compatible_attribution > compatible (no_upstream_declared only stands alone). More than 10 sources: the extra ones are listed not_checked, which counts as unresolved.

Tests

  • test/license-lineage.test.ts: every outcome, normalization, the DataCite access-rights and Crossref content-version/TDM filters, source extraction and URL mapping, two-source combinations, a timeout and a 5xx giving unresolved, caching, all against a local stand-in serving responses recorded on 2026-11-25 (test/fixtures/license-lineage/, with a README naming each DOI, URL and fetch date).
  • backend/test/license-lineage-route.test.ts: the real admin router over D1, a GitHub contents stand-in and the recorded registries (other hosts refused).
  • test/license-check-spawn.test.ts (process tier): the real CLI on a fixture BIDS directory; outcome, sources, evidence URLs, remedy, docs link, JSON form and exit codes.
  • test/license-lineage.integration.test.ts (live tier by name): one real OpenNeuro DOI through DataCite and OpenNeuro.
  • Each rule was mutated one line at a time (filters, fall-through on failure, lattice order in both directions, pair conflicts, PhysioNet policy, README prefix filter, failure caching, SA version, NC widening, unknown-license permissive, source cap); every mutant failed a test.
  • Pure unit tier: 27847 pass, 6 fail; all 6 are outside this PR: account-copy-parity (2), git-annex-remote and pr-review-calibrate fail identically on the base c7c8fe2c, repull-pipeline-run passes alone (a 5 s timeout under load), and the ADR 0135 cap failure was fixed by the last commit.
  • Gates: bun run typecheck, bun run lint, biome on touched files, the pure unit tier, and the targeted tests above. The remote live tier is not awaited for this phase PR.

Review round 1 fixes

  • Input read states (result.inputs): a missing dataset_description.json is distinct from an unparseable one, and likewise .nemar/metadata.json. A missing or unparseable description gives unresolved with source status description_unreadable (never no_upstream_declared); an unparseable metadata file adds metadata_unreadable. The route answers 422 for an unparseable file (502 stays for a repository read failure); the CLI exits 1 naming the file.
  • CLI path: must be a directory holding dataset_description.json; every read failure is one line and exit 1, no stack trace.
  • A 200 that is HTML, {}, an array, or GraphQL {errors, data: null} gives unparseable and unresolved; a PhysioNet record without a string access_policy is unparseable.
  • Share-alike: a source version with no target version is a mismatch.
  • The dataset's own DOIs (DatasetDOI, and NEMAR's prefix 10.82901 in the README) are not sources.
  • Cached hits are validated against the vocabulary; a bad hit is a miss.
  • lineageLines prints the copy's read line, per resolver (RESOLVER_READ).
  • The upload prompt prints a copy sentence for an unrecognized source license.
  • Fixtures 03 and 04: one contributor's personal name redacted and their ORCID iD removed; README and index.json list both edits.
  • Not changed: the ODbL version (rejected by the lead).

Docs anchors for A10

All on https://docs.nemar.org/policies/contributor-terms/ (LINEAGE_ANCHORS in shared/license-lineage.ts; a test fails if a copy entry uses any other): #license-lineage, #license-lineage-compatible, #license-lineage-compatible-attribution, #license-lineage-compatible-nc, #license-lineage-share-alike-mismatch, #license-lineage-needs-permission, #license-lineage-redistribution-prohibited, #license-lineage-source-is-publication, #license-lineage-no-upstream-declared, #license-lineage-unresolved.

Resolver, compatibility lattice and copy tables (epic #2182 card D1), with recorded DataCite, Crossref, OpenAlex, OpenNeuro and PhysioNet fixtures. Tested: bun test test/license-lineage.test.ts; live DOI test passed locally.
An unrecognized source license now needs permission instead of passing. Tested: bun test test/license-provenance.test.ts test/license-tier.test.ts.
GET /admin/datasets/:id/license-lineage, read-only, Worker-cached per DOI. Tested: route test and admin route inventory.
nemar dataset license-check <path> and nemar admin dataset license-lineage <id>. Tested: CLI spawn test against a recorded stand-in, export surface pin.
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR2372

Version: 0.10.40-PR2372.8c2b0de
Commit: 8c2b0de


🤖 Updated on each push.

ADR 0135 caps admin dataset at twelve visible children (test/admin-write-flag.unit.test.ts). Adds spawn tests for the admin command. Tested: license-check-spawn, admin-write-flag.
MIT, BSD-2/3-Clause and Apache-2.0 become permissive-attribution (compatible_attribution); the Public Domain Mark becomes cc0 (lead ruling 2026-11-25). Tested: license-lineage, license-provenance, license-tier, spawn and route tests.
Review round 1 item 10. Tested: bun test test/license-lineage.test.ts.
Review round 1 items 1-8: read states for the description and metadata (422 and CLI exit 1 when unparseable), CLI path checks, unparseable 200 bodies, strict SA version, PhysioNet access policy, own-DOI exclusion, cache validation, read lines and anchors. Tested: lineage, spawn, route tests.
Review round 1 item 9. Tested: bun test test/license-provenance.test.ts.
Review round 2: license-check exits outside every try, an unreadable description leaves target_license null (printed unknown), and the fixtures README explains the kept curator names. Tested: targeted lineage files.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Merge gate (lead, local per the plan's phase rule): head 8c2b0de; typecheck clean; biome clean; targeted tests 184 pass, 0 fail. Review: round 1 panel (code+tests; errors+comments+types), 3 important and 6 suggestions fixed, 1 rejected (ODbL version, consistent with the card); round 2 delta review clean, 2 suggestions fixed in 8c2b0de. Remote CI: 19 pass; unit-pure shard 2 fails on unrelated timeouts (different files on the first run and on the rerun, none touched by this diff, all passing locally on this head), filed as #2377.

@neuromechanist
neuromechanist merged commit 442ce5c into feature/issue-2182-epic-pq-decide Nov 25, 2026
48 of 53 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-2182-license-lineage branch November 25, 2026 22:32

This branch was previously deployed

1 inactive deployment
npm — 8c2b0de0 Deployed Nov 25, 2026 by neuromechanist via publish #4876
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