Add paperspec correct, check math forms and datasets, and give the tools public names

The work the other paper tools planned for paperspec (paperdesk PLAN M5.4,
paperform PLAN 4.2):

- paperspec correct and paperspec.revision apply proposed corrections to a
  package, folder or zip, and write it only once it validates.
- doc.math.form is checked: label and style commands always, the form's own
  spelling when papermath is installed or forms= is passed.
- paperspec.datasets and seven doc.dataset.* rules check a package's datasets.
- fixtures/invalid gains suspect-witness and math-form-label (33 in all).
- Canonical JSON reads numbers as doubles, so 1e20 round-trips.
- The registries and the JSON-LD context ship in the wheel.
- Public names for what paperdesk and paperform imported as private ones,
  with the old names kept as aliases.
- The text and lossy-projection functions are about three times faster
  through the gate, tested equal to the old code on every code point.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013XwDhn4LkrKQfw4ArDEr2E
This commit is contained in:
alexmandClaude committed 2026-10-20 22:10:17 -04:00
1 parent 8c07dd7c15
commit 4fb8b4f5a7
70 files changed
+4470 -270

No files matched your search

+160
View File
@@ -6,11 +6,13 @@
"""Addresses, anchors and their resolution (spec/06)."""
import json
from fractions import Fraction
import pytest
from hypothesis import given, settings, strategies as st
from conftest import ROOT
from helpers_lib1 import (
HALE,
build_doc,
@@ -820,3 +822,161 @@ class TestResolveContainers:
got["reason"]
== "the successor holds fewer than half of the original leaves"
)
# --- following IDs and resolving addresses ------------------------------------------
KEY = "hale2026harmonic-damb"
def _jsonl(name):
"""The records of `nodes.jsonl` or `ids.jsonl` of the Hale package, as stored."""
path = ROOT / HALE / f"{name}.jsonl"
return [json.loads(line) for line in path.read_text("utf-8").splitlines()]
class TestFollow:
def test_follow_is_the_old_private_name(self):
assert anchors._follow is anchors.follow
def test_a_live_node_is_followed_to_itself(self, tree):
assert anchors.follow(tree["state"], tree["s1"]) == (tree["s1"], [], None)
def test_an_alias_gives_a_chain_and_the_alias_kind(self, tree):
ids = [{"id": "aaaaaaa", "kind": "alias", "successor": tree["s1"]}]
got = anchors.follow(_edit(tree["state"], {}, ids=ids), "aaaaaaa")
assert got == (tree["s1"], ["aaaaaaa"], "alias")
def test_a_retirement_makes_the_chain_retired_even_after_an_alias(self, tree):
ids = [
{"id": "aaaaaaa", "kind": "alias", "successor": "bbbbbbb"},
{"id": "bbbbbbb", "kind": "retired", "successor": tree["s1"]},
]
got = anchors.follow(_edit(tree["state"], {}, ids=ids), "aaaaaaa")
assert got == (tree["s1"], ["aaaaaaa", "bbbbbbb"], "retired")
def test_a_deletion_ends_the_chain_without_a_node(self, tree):
ids = [{"id": "ddddddd", "kind": "retired", "successor": None}]
got = anchors.follow(_edit(tree["state"], {}, ids=ids), "ddddddd")
assert got == (None, ["ddddddd"], "retired")
def test_an_unknown_id_gives_no_node_and_no_chain(self, tree):
assert anchors.follow(tree["state"], "zzzzzzz") == (None, [], None)
class TestResolveAddress:
@pytest.fixture
def hale(self):
nodes = _jsonl("nodes")
sentence_id = next(n["id"] for n in nodes if n["kind"] == "sentence")
return {
"nodes": nodes,
"ids": _jsonl("ids"),
"sid": sentence_id,
"hash": next(n["node_hash"] for n in nodes if n["id"] == sentence_id),
}
def _resolve(self, hale, tail, **kw):
return anchors.resolve_address(
hale["nodes"], hale["ids"], f"{KEY}#{tail}", **kw
)
def test_an_unpinned_address_of_a_live_node_is_current(self, hale):
assert self._resolve(hale, hale["sid"]) == {
"result": "current",
"node": hale["sid"],
"node_hash": hale["hash"],
}
def test_a_pin_that_starts_the_node_hash_is_current(self, hale):
got = self._resolve(hale, f"{hale['sid']}@{hale['hash'][:6]}")
assert got["result"] == "current"
def test_a_pin_that_differs_is_stale(self, hale):
other = "000000" if not hale["hash"].startswith("000000") else "ffffff"
got = self._resolve(hale, f"{hale['sid']}@{other}")
assert got["result"] == "stale"
assert got["reason"] == "the pin differs from the node hash"
assert got["node"] == hale["sid"]
def test_a_span_is_carried_to_a_current_result(self, hale):
got = self._resolve(hale, f"{hale['sid']}@{hale['hash'][:6]}[3:9]")
assert got["span"] == [3, 9]
def test_an_empty_span_is_a_valid_address_and_resolves(self, hale):
assert anchors.parse_address(f"{KEY}#{hale['sid']}[4:4]")["span"] == [4, 4]
assert self._resolve(hale, f"{hale['sid']}[4:4]")["span"] == [4, 4]
def test_a_reversed_span_is_not_an_address(self, hale):
assert self._resolve(hale, f"{hale['sid']}[9:3]") == {
"result": "stale",
"node": None,
"reason": "not an address",
}
def test_the_grammar_takes_any_node_part_so_a_short_one_parses(self):
assert anchors.parse_address(f"{KEY}#n1")["node"] == "n1"
def test_an_alias_is_followed_and_its_pin_judged(self, hale):
node = next(n for n in hale["nodes"] if n["id"] == "hca6dc5")
got = self._resolve(hale, f"b-p01-text-003@{node['node_hash'][:6]}")
assert got == {
"result": "current",
"node": "hca6dc5",
"node_hash": node["node_hash"],
"via": ["b-p01-text-003"],
}
def test_a_retirement_with_a_successor_is_stale_and_names_the_successor(self, hale):
got = self._resolve(hale, "ayea71r")
assert got["result"] == "stale"
assert got["reason"] == "retired"
assert got["node"] == "xjns57z"
assert got["via"] == ["ayea71r"]
def test_a_deletion_is_stale_without_a_node(self, hale):
assert self._resolve(hale, "v8e4z6z") == {
"result": "stale",
"node": None,
"via": ["v8e4z6z"],
"reason": "retired without a successor",
}
def test_an_unknown_node_is_stale(self, hale):
assert self._resolve(hale, "zzzzzzz") == {
"result": "stale",
"node": None,
"reason": "unknown node",
}
def test_text_that_is_not_an_address_is_stale(self, hale):
got = anchors.resolve_address(hale["nodes"], hale["ids"], "nonsense")
assert got["reason"] == "not an address"
def test_given_values_replace_the_stored_node_hash(self, hale):
values = {hale["sid"]: {"node_hash": "abcdef" + "0" * 58}}
got = self._resolve(hale, f"{hale['sid']}@abcdef", values=values)
assert got["result"] == "current"
assert got["node_hash"] == "abcdef" + "0" * 58
assert (
self._resolve(hale, f"{hale['sid']}@{hale['hash'][:6]}", values=values)[
"result"
]
== "stale"
)
def test_a_node_without_a_hash_fails_a_pin_but_not_an_unpinned_address(self):
nodes = [{"id": "n1"}]
assert anchors.resolve_address(nodes, [], f"{KEY}#n1@abcdef")["result"] == (
"stale"
)
assert anchors.resolve_address(nodes, [], f"{KEY}#n1")["result"] == "current"
def test_it_agrees_with_resolve_on_every_node_of_the_unchanged_document(self):
nodes, ids = _jsonl("nodes"), _jsonl("ids")
for n in nodes:
got = anchors.resolve_address(
nodes, ids, f"{KEY}#{n['id']}@{n['node_hash'][:6]}"
)
assert got["result"] == "current"
assert got["node"] == n["id"]