Skip to content

refactor(publish): make each nanopublication with nanopub-java too, and log where they differ (#936) - #952

Merged
tkuhn merged 1 commit into
masterfrom
feat/936-template-fill-guard
Nov 27, 2026
Merged

tkuhn merged 1 commit into
masterfrom
feat/936-template-fill-guard

Conversation

@tkuhn

@tkuhn tkuhn commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Part of #936. The publishing form is to make its nanopublications with the filler of nanopub-java instead of its own code. Before it does, this release makes each one a second time that way and logs where the two come out differently. That shows any differences on what people actually fill in, before the library's version is the one published.

Nothing changes for the user. The form's own nanopublication is still the one that is signed and published, and a failure of the comparison is only logged. Look for Template fill: in the log.

Change

  • template/FormRequest turns what is filled in on a form into nanopub-java's FillRequest:

    • each field's model under the name of its param_ link parameter, with its language tag;
    • the fill mode and the source (supersede, override, derive);
    • the space and the namespace that dynamic prefixes resolve to;
    • the labels the form looked up, the names of agents, the creator and the site's address.

    A field that still holds the template's default is left out. The library takes the default by itself, and leaves it out with an optional statement that lacks other values, as the form does. Passing such defaults as given values made the library refuse to leave them out with their statement, for instance in the view template's untouched action group.

  • template/TemplateFillGuard fills that request with TemplateFiller and compares the result with the form's nanopublication.

    • The comparison is triple by triple per graph, with each nanopublication's URI and what is minted under it written relative to it, and without the head, the creation time and the signature.
    • It logs that they are the same, or the triples only one of them has, or why the library would not fill the template.
  • PublishForm runs the guard on publishing and on preview, right before signing. It gets toFillRequest(), and TemplateContext gets getPrefixBase(token).

  • nanopub 1.99.0, which takes labels and the site in a request and makes the repetition rule public (feat(templates): give the filler what a form knows, and the repetition rule Nanopublication/nanopub-java#233).

  • docs/library-template-model.md: a section on the fill guard.

Testing

  • PublishFormFillGuardTest (4 tests) opens real forms and checks that the library makes the same nanopublication:

    • a new one with a language tag, repetitions and an introduced IRI;
    • one with the optional statements left out;
    • one with a default in a group that is filled in;
    • a new version with supersede.

    With the default rule switched off, three of them fail with the message the library gave on real nanopublications.

  • TemplateFillGuardTest (3 tests): the comparison, what the library cannot fill, and that failures are swallowed.

  • ./mvnw test with nanopub 1.99.0: 1,942 tests, no failures (26 skipped).

    • A first run had 13 errors in four classes that fetch templates from the registries: for about two minutes, the registries did not serve the default provenance template.
    • Those four classes then passed again, as did a second full run.
  • The nanopub skill's mirrors and local nanopublications, compared with a scratch harness that is not part of this PR. For each one it opened the form, built the nanopublication both ways, and compared:

    • Of the 380 made at Nanodash, 371 came out the same with supersede, and 370 with derive and with use.
    • Of the 3,716 others, 2,024 came out the same with supersede.
    • None came out different. The rest are cases the form also refuses on submit (invalid SPARQL, a newly minted assertion name), cases the form cannot build itself, or unsigned files.

🤖 Generated with Claude Code

…nd log where they differ (#936)

Before the form makes its nanopublications with the library's filler, this
makes each one a second time that way, on publishing and on preview, and
logs whether the two come out the same ("Template fill:"). The form's own
nanopublication is still the one that is signed and published.

- FormRequest turns the form's models into a FillRequest: values under
  their param_ names with language tags, fill mode and source, space and
  namespace, looked-up labels, agent names, creator and site. A field that
  still holds the template's default is left out, as the library takes the
  default itself and drops it with an optional statement.
- TemplateFillGuard fills that request with TemplateFiller and compares
  the result triple by triple per graph, relative to each nanopublication,
  without head, creation time and signature. Failures are only logged.
- TemplateContext.getPrefixBase(token) and PublishForm.toFillRequest().
- nanopub 1.99.0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@tkuhn
tkuhn merged commit f3fc26a into master Nov 27, 2026
8 checks passed
@tkuhn
tkuhn deleted the feat/936-template-fill-guard branch November 27, 2026 08:55
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 5.23.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant