Datasets:
File size: 6,436 Bytes
3397fcb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | """Public artifact contract: sanitized scalars only, no private material."""
import hashlib
import json
from pathlib import Path
import subprocess
import sys
import tempfile
import unittest
HERE = Path(__file__).resolve().parent
ROOT = HERE.parent
EXPORT = HERE / "export_evidence.py"
EVIDENCE = ROOT / "results" / "processed" / "evidence.json"
class EvidenceExportTests(unittest.TestCase):
def setUp(self):
self.assertIsNotNone(EXPORT.exists() and EXPORT, "export script missing")
self.document = json.loads(EVIDENCE.read_text())
self.raw = EVIDENCE.read_text()
def test_no_private_paths_credentials_or_prompts_escape(self):
for marker in ("/Users/", "/Volumes/", "sk-", "hf_", "Bearer ", "api-key",
"api_key", "BEGIN PRIVATE", "ssh-rsa"):
self.assertNotIn(marker, self.raw, f"leaked {marker}")
# A prompt or transcript leak would introduce long free-form prose.
longest = max((len(v) for v in self.document["checkpoint"]["quantized_rows_verified"]), default=0)
self.assertLess(longest, 200)
def test_qualification_flags_are_explicitly_negative(self):
q = self.document["qualification"]
self.assertFalse(q["minimum_20_tps_met"])
self.assertFalse(q["actual_near_limit_context_met"])
self.assertFalse(q["peer_review_claimed"])
self.assertFalse(q["ranked_intelligence_claimed"])
def test_every_numeric_metric_is_finite_and_every_flag_boolean(self):
def walk(node, path="root"):
if isinstance(node, dict):
for key, value in node.items():
walk(value, f"{path}.{key}")
elif isinstance(node, list):
for i, value in enumerate(node):
walk(value, f"{path}[{i}]")
elif isinstance(node, float):
self.assertFalse(node != node or node in (float("inf"), float("-inf")), path)
walk(self.document)
def test_failed_and_timed_out_runs_are_retained_not_dropped(self):
repairs = self.document["speculative_repairs"]
self.assertEqual(len(repairs), 2)
for run in repairs:
self.assertTrue(run["timed_out"])
self.assertFalse(run["completed"])
self.assertFalse(run["independent_gate_pass"])
self.assertIsNot(run["elapsed_s"], None)
def test_all_four_synthetic_conditions_and_parity_are_present(self):
conditions = self.document["synthetic_conditions"]
self.assertEqual(len(conditions), 4)
for condition in conditions:
self.assertTrue(condition["greedy_token_parity"])
self.assertEqual(len(condition["trials"]), 4)
labels = [trial["label"] for trial in condition["trials"]]
self.assertEqual(sum("plain" in x for x in labels), 2)
self.assertGreaterEqual(sum(("dflash" in x) or ("mtp" in x) for x in labels), 2)
def test_memory_policy_records_refusal_then_success_at_same_input(self):
policy = self.document["memory_policy"]
self.assertFalse(policy["refusal_before_switch"]["completed"])
self.assertTrue(policy["after_supported_switch_off"]["completed"])
self.assertFalse(policy["after_supported_switch_off"]["prompt_reduced"])
self.assertEqual(policy["effective_child_setting"][0]["system_memory_guard"], "0")
def test_protocol_matrix_covers_both_endpoints_and_three_dialects(self):
matrix = self.document["protocol_matrix"]
for kind in ("non_streaming", "streaming"):
rows = matrix[kind]
self.assertEqual(len(rows), 6, kind)
self.assertEqual({r["endpoint"] for r in rows}, {"native", "magpie"})
self.assertEqual({r["protocol"] for r in rows}, {"chat", "responses", "anthropic"})
self.assertTrue(all(r["passed"] for r in rows), kind)
def test_export_refuses_when_a_private_marker_would_escape(self):
fable_root = ROOT.parent.parent / "fable"
real_local = ROOT.parent.parent / "coder390" / "mlx-native" / "raw"
real_guard = fable_root / "memory-guard-fix" / "raw"
with tempfile.TemporaryDirectory() as temp:
fake = Path(temp) / "poisoned"
fake.mkdir()
# Reuse every real input, but make one identity field private.
for source in (fable_root / "deployment" / "raw").glob("*.json"):
(fake / source.name).write_bytes(source.read_bytes())
# runtime_profile reaches the artifact unfiltered by text(), so a
# private value here proves the serialized-blob guard is load-bearing.
doc = json.loads((fake / "final-cutover-audit.json").read_text())
doc["runtime_profile"] = "/Users/someone/private"
(fake / "final-cutover-audit.json").write_text(json.dumps(doc))
code = EXPORT.read_text().replace(
'LOCAL = ROOT / "coder390" / "mlx-native" / "raw"',
f'LOCAL = Path({str(real_local)!r})',
).replace(
'FABLE = ROOT / "fable" / "deployment" / "raw"',
f'FABLE = Path({str(fake)!r})',
).replace(
'GUARD = ROOT / "fable" / "memory-guard-fix" / "raw"',
f'GUARD = Path({str(real_guard)!r})',
)
script = Path(temp) / "export.py"
script.write_text(code)
result = subprocess.run([sys.executable, str(script), str(Path(temp) / "out.json")],
capture_output=True, text=True)
self.assertNotEqual(result.returncode, 0, "poisoned export succeeded")
self.assertIn("private marker", (result.stdout + result.stderr).lower())
self.assertFalse((Path(temp) / "out.json").exists())
class ChecksumTests(unittest.TestCase):
def test_manifest_matches_files(self):
manifest = ROOT / "SHA256SUMS"
self.assertTrue(manifest.exists(), "SHA256SUMS missing")
for line in manifest.read_text().splitlines():
if not line.strip():
continue
digest, name = line.split(" ", 1)
path = ROOT / name
if not path.exists():
self.fail(f"manifest lists missing file: {name}")
self.assertEqual(hashlib.sha256(path.read_bytes()).hexdigest(), digest, name)
if __name__ == "__main__":
unittest.main()
|