Datasets:
Download test_release.py from chembricks/chemistry-knowledge: direct link, hf CLI and curl.
- Browser
- Download file 4.58 kB
-
https://huggingface.co/datasets/chembricks/chemistry-knowledge/resolve/main/test_release.py
- Command line
-
hf download hf://datasets/chembricks/chemistry-knowledge/test_release.py
-
curl -L -o test_release.py https://huggingface.co/datasets/chembricks/chemistry-knowledge/resolve/main/test_release.py
4.58 kB
| """Regression checks for public-copy curation and provenance.""" | |
| import copy | |
| import hashlib | |
| import json | |
| import pytest | |
| from build_dataset import clean_claim_ids, privacy_issues, public_tool_row, schema_for | |
| from verify import pointer, verify_evidence | |
| def canonical(value): | |
| return json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False, allow_nan=False).encode() | |
| def example_row(): | |
| # Synthetic bookkeeping fixture, not a chemistry observation. | |
| value = {"line": 7, "ts": "2026-09-17T00:00:00Z", "duration_ms": 1, | |
| "tool": "fixture_tool", "args": {"smiles": "C", "properties": ["fixture"]}, | |
| "request_id": "fixture-request", "status": "ok", | |
| "request": {"id": 1, "jsonrpc": "2.0", "method": "tools/call", | |
| "params": {"name": "fixture_tool", "arguments": {"smiles": "C", "properties": ["fixture"]}, | |
| "_meta": {"workspaces": {"/home/example/private": {"session": "not-public"}}}}}, | |
| "response": {"jsonrpc": "2.0", "id": 1, "result": { | |
| "_meta": {"request_id": "fixture-request", "model_version": "fixture-v1"}, | |
| "structuredContent": {"number": 1.25, "trust_factor": 75.5}}}} | |
| value["sha256"] = hashlib.sha256(canonical(value)).hexdigest() | |
| return value | |
| def public_projection(): | |
| original = example_row() | |
| public, removed = public_tool_row(original) | |
| return original, public, { | |
| "request_id": public["request_id"], "tool": public["tool"], "status": public["status"], | |
| "timestamp": public["ts"], "duration_ms": public["duration_ms"], "source_line": public["line"], | |
| "row_sha256": public["sha256"], "source_row_sha256": original["sha256"], | |
| "omitted_metadata_fields": removed, "args_json": json.dumps(public["args"]), | |
| "response_json": json.dumps(public["response"]), "public_row_json": json.dumps(public), | |
| } | |
| def test_projection_removes_only_client_metadata(): | |
| original = example_row() | |
| before = copy.deepcopy(original) | |
| public, removed = public_tool_row(original) | |
| assert original == before | |
| assert public["args"] == original["args"] | |
| assert public["response"] == original["response"] | |
| assert public["response"]["result"]["_meta"]["request_id"] == "fixture-request" | |
| assert removed == ["request.params._meta"] | |
| assert public["sha256"] != original["sha256"] | |
| assert not privacy_issues(public) | |
| assert privacy_issues(original) | |
| def test_public_evidence_hash_checks_the_response(): | |
| original, public, exported = public_projection() | |
| verify_evidence(exported) | |
| public["response"]["result"]["structuredContent"]["number"] = 2.5 | |
| exported["response_json"] = json.dumps(public["response"]) | |
| exported["public_row_json"] = json.dumps(public) | |
| with pytest.raises(AssertionError, match="hash"): | |
| verify_evidence(exported) | |
| def test_flat_argument_column_cannot_disagree_with_public_row(): | |
| _, _, exported = public_projection() | |
| exported["args_json"] = json.dumps({"smiles": "CC"}) | |
| with pytest.raises(AssertionError, match="Arguments"): | |
| verify_evidence(exported) | |
| def test_passed_arithmetic_does_not_override_ineligible_sources(): | |
| record = {"claims": [{"id":"primary", "verdict":"inconclusive"}, | |
| {"id":"arithmetic", "verdict":"passed"}, | |
| {"id":"independent", "verdict":"passed"}]} | |
| confidence = {"primary":{"context_eligible":False}, | |
| "arithmetic":{"context_eligible":False}, | |
| "independent":{"context_eligible":True}} | |
| assert clean_claim_ids(record,confidence) == {"independent"} | |
| def test_schema_supports_nullable_scalars_and_rejects_shape_drift(): | |
| schema = schema_for([{"value":None,"tags":[]}, {"value":1.0,"tags":["low-trust"]}]) | |
| assert schema["properties"]["value"]["type"] == ["null","number"] | |
| with pytest.raises(ValueError, match="columns"): | |
| schema_for([{"value":1}, {"unexpected":1}]) | |
| def test_pointer_decodes_nested_response_text_and_escaped_keys(): | |
| response = {"result":{"content":[{"text":json.dumps({"a/b":{"~key":1.25}})}]}} | |
| assert pointer(response,"/result/content/0/text/a~1b/~0key") == 1.25 | |
| with pytest.raises(KeyError): | |
| pointer(response,"/result/absent") | |
| def test_secret_scan_checks_dictionary_keys_as_well_as_values(): | |
| assert privacy_issues({"workspaces":{"/home/example/private":{}}}) | |
| assert privacy_issues("gh" + "p_" + "x"*40) | |
| assert not privacy_issues({"request_id":"fixture-request","model":"recorded-model"}) | |