Add the pytest suite and fix the bugs it found

The suite takes its data from the vectors and fixtures: 3635 tests, 97.9% branch
coverage, and paperspec check and paperspec stress give the same results as before.
Fixed: receipts.verify_signature raised KeyError for a record without a format;
traces.DOC_TAG matched a tag followed by a line feed; paperspec load and paperspec check
left SQLite connections open; the site builder copied the output folder's subfolders into
itself.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B8cL4zN4XpaQF5cBtASzfq
This commit is contained in:
alexmandClaude committed 2026-10-19 04:32:44 -04:00
1 parent 30d310f64d
commit a8fc7237ae
76 files changed
+15564 -80

No files matched your search

+119
View File
@@ -0,0 +1,119 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2026 Scienting
#
# Source Code: https://git.scient.ing/papers/paperspec
# See the LICENSE.md file for full license terms.
"""Helpers for the tests of the signing, receipt, log, trace and annotation-body modules."""
import base64
import functools
import hashlib
import json
from hypothesis import settings
from conftest import FIXTURES, ROOT
from paperspec import crypto, mldsa, receipts
from paperspec.schema import Store, validate
PROPS = settings(derandomize=True, database=None, deadline=None, max_examples=50)
"""The hypothesis settings of these tests: deterministic, nothing written to the checkout."""
HALE = "hale2026harmonic-damb"
DRAFT = "writer2027fixed-ynr7.v3"
RECORDS = FIXTURES / "records"
@functools.cache
def schema_store():
"""The schemas of the repository, linted and compiled once for the whole run."""
return Store(str(ROOT / "schemas"))
@functools.cache
def rule_chapters():
"""The chapter of each rule in `registry/rules.json`, by rule ID."""
text = (ROOT / "registry" / "rules.json").read_text(encoding="utf-8")
return {r["id"]: r["chapter"] for r in json.loads(text)["rules"]}
def accepted_by_schema(annotation):
"""Whether `schemas/annotation.schema.json` accepts `annotation`."""
return validate(schema_store(), "annotation.schema.json", annotation) == []
def secret(name):
"""The 32-byte secret the fixtures derive for the key called `name`."""
return hashlib.sha256(("paperspec fixture key: " + name).encode()).digest()
def roster_key(key_id, role="editor", scheme="ed25519", purposes=("sign",), **extra):
"""A roster entry for the fixture key `key_id`, registered before every fixture date."""
if scheme == "ml-dsa-65":
public = mldsa.public_key(secret(key_id))
else:
public = crypto.ed25519_public(secret(key_id))
entry = {
"id": key_id,
"role": role,
"scheme": scheme,
"public": base64.b64encode(public).decode("ascii"),
"purposes": list(purposes),
"registered_at": "2026-09-01T00:00:00Z",
"revoked_at": None,
}
entry.update(extra)
return entry
def roster_of(*keys):
"""A roster keyed by ID from the entries made by `roster_key`."""
return {k["id"]: k for k in keys}
def fixture_roster():
"""The roster of `fixtures/records/roster.json`, keyed by key ID."""
keys = json.loads((RECORDS / "roster.json").read_text(encoding="utf-8"))["keys"]
return {k["id"]: k for k in keys}
def fixture_receipts():
"""The signed records of the main example's `receipts.jsonl`, in file order."""
path = FIXTURES / "packages" / HALE / "receipts.jsonl"
return [json.loads(x) for x in path.read_text(encoding="utf-8").splitlines()]
def receipt(nodes, by="ana", at="2026-10-11T12:00:00Z", level="F3", **extra):
"""An unsigned receipt over `nodes`, a list of (node ID, node hash) pairs."""
rec = {
"format": "scienting-receipt/1",
"doc": HALE,
"rev": 0,
"level": level,
"scope": "all",
"nodes": [list(n) for n in nodes],
"evidence": [],
"by": by,
"at": at,
}
rec.update(extra)
return rec
def sealed(rec, signer=None):
"""`rec` sealed with the fixture secret of its `by` (or of `signer`)."""
name = signer or rec["by"]
return receipts.seal(rec, secret(name), name)
def revocation(by, at="2026-10-11T13:00:00Z", **target):
"""A revocation signed by the fixture key `by`; `target` gives `receipt`, or `signer` and `period`."""
rec = {
"format": "scienting-revocation/1",
"reason": "Revoked for a test.",
"by": by,
"at": at,
}
rec.update(target)
return receipts.seal(rec, secret(by), by)