feat(migrate): id migration with inline cross-reference resolution - #2
Merged
Merged
Conversation
Add the one-time migration from old self-referential ids to nanopub-based ids, the np-sign-"-r" pattern reimplemented for nanopub-py: - references.py: detect inter-term references, cycle-aware topological ordering (order_terms), and split_references classifying each reference as resolve- inline / defer (in-batch back-edge) / dangling (unknown target, kept + warned). - migrate.py: orchestrator that mints defining nanopubs in dependency order with acyclic references resolved to new thing URIs inline, then publishes superseding nanopubs for the deferred cyclic links (e.g. symmetric isIsomerOf). - cli/migrate.py: pubmate-migrate CLI (resumable via the id-map). - cli/_signing.py: shared signing-material resolution; mint-publish reuses it. Tests cover ordering (acyclic, 2-/3-cycles, self-ref, determinism), splitting (resolve/defer/dangling), the orchestrator (inline resolution, cycle-> supersede, idempotent re-run), and the CLI. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds the one-time identifier migration: turn an existing vocabulary whose terms reference each other by their old ids into trusty-artifact-code defining nanopubs, rewriting the inter-term references to the new thing URIs.
This is nanopub-java's
np sign -r("resolve cross-nanopub references") pattern, reimplemented for nanopub-py: aResource→IRIrewrite over each assertion, plus the ordering that makes it sound.How
references.py— detect inter-term references; cycle-aware topological ordering (order_terms);split_referencesclassifies each reference as resolve-inline / defer (in-batch back-edge) / dangling (target neither minted nor in the batch — kept with its old id and reported).migrate.py(migrate_terms) — mint each term's defining nanopub in dependency order with acyclic references resolved to new thing URIs inline; then publish a superseding nanopub for each held-back cyclic link (e.g. symmetricisIsomerOf). Resumable via the id-map.cli/migrate.py—pubmate-migrate.cli/_signing.py— shared signing-material resolution;mint-publishrefactored onto it.A reference can be baked into a defining nanopub only if its target is already minted (fixed artifact code), which topological order guarantees for all acyclic edges; genuine cycles have no single-pass fixed point, so they go through superseding.
Tests & validation
isIsomerOfcycles, and every other inter-term link resolved to a newRA…URI. (It also flagged 7 danglingisMetaboliteOfreferences to 3 absent terms — a source-data issue, handled gracefully.)