diff --git a/docs/research_domain_conformance.md b/docs/research_domain_conformance.md new file mode 100644 index 0000000..e2e8065 --- /dev/null +++ b/docs/research_domain_conformance.md @@ -0,0 +1,18 @@ +# Research-domain release conformance + +The acceptance matrix for [issue #9](https://github.com/Jev-Engineering/jraphyte/issues/9) uses authored evidence, isolated SQLite stores, and ephemeral test signing keys. + +| Acceptance area | Executable evidence | +| --- | --- | +| Multi-domain and unclassified sources, reclassification and retirement, evidence-derived membership, identity and refutation closure | [Contracts](../tests/test_research_domain_contracts.py), [transactions](../tests/test_research_domain_transactions.py), [reads](../tests/test_research_domain_reads.py), [retrieval](../tests/test_research_domain_retrieval.py), [identity conflicts](../tests/test_research_domain_identity_conflicts.py), and [prerequisite closure](../tests/test_research_domain_prerequisite_closure.py) | +| Unauthorized sources and labels, current ACLs and revocation on historical reads, and lexical and vector filtering | [Reads](../tests/test_research_domain_reads.py), [retrieval](../tests/test_research_domain_retrieval.py), [semantic boundary](../tests/test_research_domain_semantic_boundary.py), [GraphRAG security](../tests/test_graphrag_security.py), and [GraphRAG retrieval](../tests/test_graphrag_retrieval.py). The domain retrieval suites check the text passed to the embedding fixture. | +| Old database reopen and audit, append-only migration, exact historical assignment, stale index rejection and rebuild, cache invalidation, and deterministic replay | [Publication conformance](../tests/test_research_domain_publication_conformance.py), [projection](../tests/test_research_domain_projection.py), [transactions](../tests/test_research_domain_transactions.py), [reads and rebuild](../tests/test_research_domain_reads.py), [index phase integrity](../tests/test_research_domain_index_phase_ownership.py), and [replay integrity](../tests/test_research_domain_replay_integrity.py) | +| Taxonomy, classification and source binding, reviewer and model publication authority | [Contracts](../tests/test_research_domain_contracts.py), [review order](../tests/test_research_domain_review_order.py), [transactions](../tests/test_research_domain_transactions.py), [retry revalidation](../tests/test_research_domain_retry_revalidation.py), and [runtime transactions](../tests/test_runtime_transactions.py) | +| Schema tree parity, sdist-to-wheel build, installed wheel | [Packaging tests](../tests/test_research_domain_packaging.py), [wheel validator tests](../tests/test_research_domain_wheel_validator.py), and the [distribution jobs](../.github/workflows/test.yml) | +| Exact legacy bridge and live deployment | The exact legacy CLI uses a supplied copy of upstream Git blob `68217feec539d37e4a524432c93df035f9a0fe39`. Live deployment qualification requires separate operational evidence. | + +## Release evidence + +- The [normal release workflow](../.github/workflows/test.yml) runs `python tools/run_validation.py` on Linux with Python 3.11, 3.12, and 3.13. Record the run link and the executed, passed, and skipped test counts for each version. Record the six native Windows domain-index ownership cases on each of Python 3.12 and 3.13 with their exit status. +- Run `python -m build --outdir "$scratch/dist"` from the checkout. From outside the checkout run `python "$checkout/tools/validate_domain_wheel.py" --wheel "$wheel" --report "$scratch/wheel.json"` with the absolute wheel path. Record the wheel SHA-256, schema count, and installed conformance count. The installed lifecycle uses an authenticated SQLite read with two identical quotes. The chemistry query selects both evidence records, and the biology query selects only its reviewed evidence record. Each context is validated against current access and source status. +- Check the externally supplied legacy file with `git hash-object "$legacy"`, then run `python tools/check_legacy.py --core "$legacy" --output "$scratch/legacy.json"`. Record the exact blob and both the overall and nested classification check counts from that report. A skip in the normal release workflow leaves this gate unexecuted. diff --git a/tests/test_research_domain_legacy_bridge_contract.py b/tests/test_research_domain_legacy_bridge_contract.py index 6019613..bc3babc 100644 --- a/tests/test_research_domain_legacy_bridge_contract.py +++ b/tests/test_research_domain_legacy_bridge_contract.py @@ -3,7 +3,7 @@ Inherited methods must therefore not depend on attributes that only `__init__` creates. These tests build a bridge instance around a minimal SQLite store, so they need no external reviewed core. They are NOT a pinned-core conformance result: the exact -24-check gate (`tools/check_legacy.py --core ...`) is still required. +upstream gate runs via `tools/check_legacy.py --core ...`. """ import sqlite3 import threading diff --git a/tests/test_research_domain_packaging.py b/tests/test_research_domain_packaging.py index 4363178..d684468 100644 --- a/tests/test_research_domain_packaging.py +++ b/tests/test_research_domain_packaging.py @@ -17,7 +17,10 @@ class DomainPackagingTests(unittest.TestCase): def test_installed_resources_cover_domain_contracts(self): resources = files("trace_gc").joinpath("data", "schemas") names = {entry.name for entry in resources.iterdir() if entry.name.endswith(".schema.json")} - required = {name + ".schema.json" for name in ("research-domain-taxonomy", "classification-assignment")} + required = {name + ".schema.json" for name in ( + "research-domain-taxonomy", "classification-assignment", "classification-read-identity", + "research-domain-scope", "retrieval-query", + )} self.assertTrue(required <= names) for name in required: value = json.loads(resources.joinpath(name).read_text(encoding="utf-8")) @@ -96,6 +99,9 @@ def test_clean_regeneration_matches_both_trees(self): self.assertEqual(result.returncode, 0, result.stdout + result.stderr) generated = {p.name: p.read_bytes() for p in (target / "schemas/runtime").glob("*.schema.json")} packaged = {p.name: p.read_bytes() for p in (target / "trace_gc/data/schemas").glob("*.schema.json")} - expected = {p.name: p.read_bytes() for p in (root / "schemas/runtime").glob("*.schema.json")} + expected_runtime = {p.name: p.read_bytes() for p in (root / "schemas/runtime").glob("*.schema.json")} + expected_packaged = {p.name: p.read_bytes() for p in + (root / "trace_gc/data/schemas").glob("*.schema.json")} self.assertEqual(generated, packaged) - self.assertEqual(generated, expected) + self.assertEqual(generated, expected_runtime) + self.assertEqual(packaged, expected_packaged) diff --git a/tests/test_research_domain_publication_conformance.py b/tests/test_research_domain_publication_conformance.py index 0ad65a5..cd30478 100644 --- a/tests/test_research_domain_publication_conformance.py +++ b/tests/test_research_domain_publication_conformance.py @@ -18,6 +18,7 @@ def test_reference_classification_conformance_runs_all_write_boundaries_and_repl self.assertIn("signed_classification_stale_graph_cas", result["checks"]) self.assertIn("classification_planning_rejects_stale_predecessor", result["checks"]) self.assertIn("classification_preflight_rejects_stale_source_epoch", result["checks"]) + self.assertIn("authenticated_scoped_lexical_retrieval", result["checks"]) self.assertIn("historical_assignment_replay", result["checks"]) self.assertIn("classified_database_reopen_authenticated_audit", result["checks"]) self.assertEqual(result["provider_calls"], 0) diff --git a/tests/test_research_domain_wheel_validator.py b/tests/test_research_domain_wheel_validator.py index 6ae43b7..41abc73 100644 --- a/tests/test_research_domain_wheel_validator.py +++ b/tests/test_research_domain_wheel_validator.py @@ -48,12 +48,10 @@ def test_rejects_non_wheel_unsafe_member_and_missing_resources(self): self.tool.audit_wheel(self.make_wheel(directory, self.complete(), name="source.zip")) with self.assertRaisesRegex(ValueError, "unsafe wheel member"): self.tool.audit_wheel(self.make_wheel(directory, self.complete() + ["../escape.py"])) - partial = self.complete()[1:] - with self.assertRaisesRegex(ValueError, "lacks domain resources"): - self.tool.audit_wheel(self.make_wheel(directory, partial)) - no_taxonomy = self.complete()[:-1] - with self.assertRaisesRegex(ValueError, "lacks domain resources"): - self.tool.audit_wheel(self.make_wheel(directory, no_taxonomy)) + full = self.complete() + for missing in full: + with self.subTest(missing=missing), self.assertRaisesRegex(ValueError, "lacks domain resources"): + self.tool.audit_wheel(self.make_wheel(directory, [name for name in full if name != missing])) def test_installed_smoke_is_valid_python(self): compile(self.tool.SMOKE, "", "exec") @@ -93,6 +91,7 @@ def smoke_payload(self): "status": "PASS", "installed_imports": True, "checkout_imports": False, "schema_count": len(self.tool.DOMAIN_SCHEMAS), "domain_contract_lifecycle": "PASS", "reference_taxonomy_review": "PROPOSED", "cli_version": "TRACE-GC 0.4.0", + "domain_conformance_checks": 1, } def test_audit_and_install_share_a_private_copy(self): @@ -137,6 +136,9 @@ def test_rejects_malformed_or_extra_smoke_fields(self): json.dumps(dict(base, installed_imports=1)).encode(), json.dumps(dict(base, checkout_imports=True)).encode(), json.dumps(dict(base, schema_count=True)).encode(), + json.dumps({key: value for key, value in base.items() if key != "domain_conformance_checks"}).encode(), + *(json.dumps(dict(base, domain_conformance_checks=value)).encode() + for value in (True, 0, -1, 1.0, "1")), json.dumps(dict(base, cli_version="/private/tree")).encode(), ] with tempfile.TemporaryDirectory() as directory: diff --git a/tools/validate_domain_wheel.py b/tools/validate_domain_wheel.py index 90723b3..de9dc88 100644 --- a/tools/validate_domain_wheel.py +++ b/tools/validate_domain_wheel.py @@ -5,8 +5,9 @@ that every domain contract module and schema resource comes from the installed copy, then runs a synthetic contract lifecycle: multi-label, unclassified and superseding assignments, a complete bundle validation, and rejection of an -approved assignment that binds the packaged PROPOSED taxonomy. Synthetic -fixtures only: this is not deployment qualification or publication evidence. +approved assignment that binds the packaged PROPOSED taxonomy. The installed +SQLite lifecycle also validates authenticated domain-scoped lexical retrieval +using synthetic evidence. """ from __future__ import annotations @@ -21,27 +22,41 @@ import zipfile from pathlib import Path, PurePosixPath -DOMAIN_SCHEMAS = ("research-domain-taxonomy", "classification-assignment") +DOMAIN_SCHEMAS = ( + "research-domain-taxonomy", + "classification-assignment", + "classification-read-identity", + "research-domain-scope", + "retrieval-query", +) TAXONOMY = "trace_gc/data/research_domains/reference_taxonomy_v1.json" SMOKE = r''' import contextlib, copy, io, json, pathlib, sys +from importlib.resources import files root = pathlib.Path(sys.argv[1]).resolve() sys.path.insert(0, str(root)) import trace_gc.catalog, trace_gc.domains, trace_gc.ledger, trace_gc.validation, trace_gc.schema, trace_gc.cli from jsonschema import Draft202012Validator modules = (trace_gc.catalog, trace_gc.domains, trace_gc.ledger, trace_gc.validation, trace_gc.schema, trace_gc.cli) +def assert_installed(path): + assert pathlib.Path(path).resolve().is_relative_to(root), path + for module in modules: - assert pathlib.Path(module.__file__).resolve().is_relative_to(root), module.__file__ -schemas = pathlib.Path(trace_gc.domains.__file__).parent / "data" / "schemas" + assert_installed(module.__file__) +data = files("trace_gc").joinpath("data") +assert_installed(data.joinpath("research_domains", "reference_taxonomy_v1.json")) +schemas = data.joinpath("schemas") for name in json.loads(sys.argv[2]): path = schemas / (name + ".schema.json") + assert_installed(path) assert path.is_file(), name Draft202012Validator.check_schema(json.loads(path.read_text(encoding="utf-8"))) schema_count = len(list(schemas.glob("*.schema.json"))) from trace_gc.catalog import Catalog from trace_gc.canonical import dumps, loads from trace_gc.demo import relation +from trace_gc.domain_conformance import run_domain_conformance from trace_gc.domains import create_assignment, reference_taxonomy, validate_catalog from trace_gc.errors import ContractError from trace_gc.ledger import make_bundle @@ -80,8 +95,13 @@ outcome = trace_gc.validation.validate_bundle(loads(dumps(bundle))) assert outcome["status"] == "PASS" and not outcome["authorization_granted"], outcome assert {"DOMAIN_TAXONOMY", "CLASSIFICATION"} <= {e["stage"] for e in bundle["ledger"]} +domain = run_domain_conformance() +assert domain["status"] == "PASS" and domain["backend"] == "sqlite-reference-v1", domain +assert domain["checks_run"] == len(domain["checks"]), domain +assert "authenticated_scoped_lexical_retrieval" in domain["checks"], domain result = {"status": "PASS", "installed_imports": True, "checkout_imports": False, "schema_count": schema_count, - "domain_contract_lifecycle": "PASS", "reference_taxonomy_review": "PROPOSED"} + "domain_contract_lifecycle": "PASS", "reference_taxonomy_review": "PROPOSED", + "domain_conformance_checks": domain["checks_run"]} out = io.StringIO() with contextlib.redirect_stdout(out): try: @@ -90,6 +110,9 @@ assert exc.code in (None, 0), exc.code result["cli_version"] = out.getvalue().strip() assert result["cli_version"] +for name, module in tuple(sys.modules.items()): + if name == "trace_gc" or name.startswith("trace_gc."): + assert_installed(module.__file__) print(json.dumps(result)) ''' @@ -138,13 +161,15 @@ def _smoke_result(stdout: str) -> dict: "domain_contract_lifecycle": "PASS", "reference_taxonomy_review": "PROPOSED", } - if not isinstance(result, dict) or set(result) != {*required, "schema_count", "cli_version"}: + if not isinstance(result, dict) or set(result) != {*required, "schema_count", "cli_version", "domain_conformance_checks"}: raise invalid for key, expected in required.items(): if type(result[key]) is not type(expected) or result[key] != expected: raise invalid if type(result["schema_count"]) is not int or result["schema_count"] < len(DOMAIN_SCHEMAS): raise invalid + if type(result["domain_conformance_checks"]) is not int or result["domain_conformance_checks"] <= 0: + raise invalid version = result["cli_version"] if not isinstance(version, str) or not re.fullmatch(r"TRACE-GC [0-9][0-9A-Za-z.+!-]{0,63}", version): raise invalid diff --git a/trace_gc/domain_conformance.py b/trace_gc/domain_conformance.py index 04a3292..8ee5f22 100644 --- a/trace_gc/domain_conformance.py +++ b/trace_gc/domain_conformance.py @@ -18,10 +18,36 @@ from .domains import create_assignment, reference_taxonomy from .errors import ContractError, require from .plans import create_plan +from .retrieval.contracts import RetrievalBudget, query +from .retrieval.domains import research_domain_scope +from .retrieval.fixtures import demo_access +from .retrieval.service import HybridRetriever from .retrieval.store import SQLiteGraphAdapter from .trust import IssuerPolicy, Signer, authorize_plan +def _check_scoped_lexical(fixture, taxonomy_id: str, snapshot_id: str) -> None: + catalog = fixture.catalog + both = set(fixture.evidence_ids) + first, second = fixture.evidence_ids + quote = catalog.get(first, "evidence")["quote"] + require(quote == catalog.get(second, "evidence")["quote"], "DOMAIN_CONFORMANCE", + "scoped lexical fixture must offer the same quote from both sources") + retriever = HybridRetriever(SQLiteGraphAdapter(fixture.backend, audit_trust=fixture.trust), + access_policy=demo_access(catalog, snapshot_id, scope=SCOPE)) + for domain, expected in (("research:chemistry", both), ("research:biology", {first})): + request = query(requesting_component="domain-conformance", security_scope=SCOPE, + text=quote, strategies=["LEXICAL"], include_conflicts=False, + budget=RetrievalBudget(maximum_latency_ms=20000), + research_domain_scope=research_domain_scope(catalog, taxonomy_id, [domain])) + result = retriever.catalog.get(retriever.retrieve(request), "retrieval-result") + context_id = result["graph_context_id"] + retriever.validate_live_context(context_id) + context = retriever.catalog.get(context_id, "graph-context") + require(set(context["selected_evidence_ids"]) == expected, "DOMAIN_CONFORMANCE", + f"lexical evidence selection differs for {domain}") + + def run_domain_conformance(output: str | Path | None = None, *, backend_factory: Callable[..., Any] = SQLiteReferenceBackend, backend_label: str = "sqlite-reference-v1") -> dict[str, Any]: @@ -129,6 +155,8 @@ def interrupt(name): require(classified == dict(zip(f.source_ids, assignments, strict=True)), "DOMAIN_CONFORMANCE", "classification projection did not bind each exact assignment") checks.append("multi_source_assignment_publication") + _check_scoped_lexical(f, taxonomy_id, classified_snapshot_id) + checks.append("authenticated_scoped_lexical_retrieval") second = create_assignment(c, source_snapshot_id=f.source_ids[0], taxonomy_id=taxonomy_id, domain_ids=["research:physics"], review=review, classifier_id="isolated-domain-reviewer", classifier_version="conformance-v1", supersedes=assignments[0]) @@ -186,7 +214,7 @@ def interrupt(name): "final_graph_version": accepted["graph_version"], "final_state_hash": digest(accepted), "execution_mode": "SYNTHETIC", "label_origin": "FABRICATED_CONFORMANCE_ONLY", "provider_calls": 0, "production_graph_writes": 0, "production_qualification": "NOT_ESTABLISHED", - "scope": "Isolated classification lifecycle, atomicity, historical snapshots and authenticated journal conformance; not representative workload or operational qualification."} + "scope": "Isolated classification lifecycle, atomicity, historical snapshots, scoped retrieval and authenticated journal conformance; not representative workload or operational qualification."} finally: f.close() if output is not None: