Repository navigation
Expand file tree
/
Copy pathcheck_ceiling_depth_semantics.py
More file actions
236 lines (200 loc) · 11.1 KB
/
Copy pathcheck_ceiling_depth_semantics.py
File metadata and controls
236 lines (200 loc) · 11.1 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/usr/bin/env python3
"""Semantic depth checks for proof-system primitives."""
from __future__ import annotations
import ast
import json
import sys
from copy import deepcopy
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parents[2]
BACKEND_ROOT = PROJECT_ROOT / "backend"
if str(BACKEND_ROOT) not in sys.path:
sys.path.insert(0, str(BACKEND_ROOT))
def _read(path: str) -> str:
return (PROJECT_ROOT / path).read_text(encoding="utf-8")
def _read_json(path: str) -> dict:
return json.loads((PROJECT_ROOT / path).read_text(encoding="utf-8"))
def _verify_replay_artifacts() -> list[str]:
from app.membranes.proofpack import verify_proof_pack
from app.membranes.timepack import verify_timepack
failures: list[str] = []
proofpacks = (
"examples/external/proofpacks/civil-conversion.proofpack.json",
"examples/external/proofpacks/panchanga-summary.proofpack.json",
"examples/external/proofpacks/payroll-row.proofpack.json",
)
timepacks = (
"examples/external/timepacks/civil-conversion.timepack.json",
"examples/external/timepacks/panchanga-summary.timepack.json",
"examples/external/timepacks/payroll-date-risk.timepack.json",
)
for path in proofpacks:
ok, reason = verify_proof_pack(_read_json(path))
if not ok:
failures.append(f"{path} failed proofpack verification: {reason}")
for path in timepacks:
ok, reason = verify_timepack(_read_json(path))
if not ok:
failures.append(f"{path} failed Timepack verification: {reason}")
civil = _read_json("examples/external/proofpacks/civil-conversion.proofpack.json")
tampered_civil = deepcopy(civil)
tampered_civil["membrane"]["result"]["ad_date"] = "2099-01-01"
ok, reason = verify_proof_pack(tampered_civil)
if ok or reason == "verified":
failures.append("tampered civil proofpack unexpectedly verified")
payroll = _read_json("examples/external/timepacks/payroll-date-risk.timepack.json")
tampered_payroll = deepcopy(payroll)
tampered_payroll["aggregate_witness_hash"] = "sha256:tampered"
ok, reason = verify_timepack(tampered_payroll)
if ok or reason != "timepack_aggregate_hash_mismatch":
failures.append("tampered payroll Timepack did not fail aggregate hash verification")
return failures
def _failures() -> list[str]:
failures: list[str] = []
embed = _read("static/parva-embed.js")
if "innerHTML" in embed:
failures.append("static/parva-embed.js must not use innerHTML")
if "textContent" not in embed or "replaceChildren" not in embed:
failures.append("static/parva-embed.js must render via DOM text APIs")
capsule = _read("backend/app/membranes/capsule.py")
if "AuthorityTaint.STRUCTURED_OFFICIAL" in capsule:
failures.append("membrane capsule must not hardcode structured_official authority")
if "sample-2082-calendar-notice" in capsule:
failures.append("membrane capsule must not hardcode the sample 2082 source docket")
if "resolve_convert_bs_to_ad_source" not in capsule:
failures.append("membrane capsule must use dynamic source resolution")
verifier = _read("backend/app/membranes/verifier.py")
if "replay_verify" not in verifier:
failures.append("membrane verifier must dispatch to replay verification")
operation_verifiers = {
"convert_bs_to_ad": "bs_to_gregorian",
"ad_to_bs": "gregorian_to_bs",
"validate_bs_date": "is_valid_bs_date",
"holiday": "holiday_membership",
"working_day": "working_day_policy",
"fiscal_year": "fiscal_year_payload",
"bs_months": "bs_months_payload",
"panchanga_summary": "build_panchanga_summary_capsule",
}
for operation, recompute_marker in operation_verifiers.items():
replay = PROJECT_ROOT / f"backend/app/membranes/operation_verifiers/{operation}.py"
if not replay.exists():
failures.append(f"{operation} operation replay verifier is missing")
continue
replay_source = replay.read_text(encoding="utf-8")
common_marker = (
"replayed_result_mismatch"
if operation in {"convert_bs_to_ad", "panchanga_summary"}
else "verify_common_replay"
)
if recompute_marker not in replay_source or common_marker not in replay_source:
failures.append(f"{operation} replay verifier must recompute operation results")
if operation not in {"convert_bs_to_ad", "panchanga_summary"} and "expected_result" not in replay_source:
failures.append(f"{operation} replay verifier must compare expected_result")
common_replay = _read("backend/app/membranes/operation_verifiers/common.py")
if "source_docket_resolution_mismatch" not in common_replay:
failures.append("civil replay verifier must enforce source docket resolution")
if "source_authority_overclaim" not in common_replay:
failures.append("civil replay verifier must reject source authority overclaims")
local_kernel = _read("packages/parva-local-kernel/src/membranes.ts")
if "Boolean(membrane.identity_hash && membrane.witness_hash)" in local_kernel:
failures.append("local kernel verifyMembrane must not be field-presence-only")
if "identity_hash_mismatch" not in local_kernel or "witness_hash_mismatch" not in local_kernel:
failures.append("local kernel verifyMembrane must validate identity and witness hashes")
if "proof_pack_result_hash_mismatch" not in local_kernel or "source_snapshot_hash_mismatch" not in local_kernel:
failures.append("local kernel verifyMembrane must validate proof-pack and source snapshot linkage")
if "replayMembrane" not in local_kernel or "replayCivilResult" not in local_kernel:
failures.append("local kernel must perform formula-based civil membrane replay")
if "replayPanchangaMembrane" not in local_kernel:
failures.append("local kernel must perform component-level Panchanga fixture replay")
local_panchanga = _read("packages/parva-local-kernel/src/panchanga.ts")
for marker in (
"'tithi.number'",
"'nakshatra.name'",
"fallback_provider_claims_jpl",
"panchanga_not_ritual_final_authority_missing",
):
if marker not in local_panchanga:
failures.append(f"local kernel Panchanga replay missing marker {marker}")
local_civil = _read("packages/parva-local-kernel/src/civil.ts")
for marker in ("function bsToAd", "function adToBs", "holidayResult", "workingDayResult", "fiscalYearResult", "verifyBsMonthReplay"):
if marker not in local_civil:
failures.append(f"local kernel civil replay missing {marker}")
if not (PROJECT_ROOT / "packages/parva-local-kernel/package.json").exists():
failures.append("local kernel must be a buildable npm package")
if len(list((PROJECT_ROOT / "tests/fixtures/proof/civil").glob("*.json"))) < 12:
failures.append("shared civil proof fixtures must cover core replay cases")
if not list((PROJECT_ROOT / "tests/fixtures/proof/panchanga").glob("*.json")):
failures.append("Panchanga proof fixtures are missing")
if not (PROJECT_ROOT / "reports/proof_contract/route_proof_matrix.json").exists():
failures.append("route proof contract matrix is missing")
for proof_artifact in (
"examples/external/proofpacks/civil-conversion.proofpack.json",
"examples/external/proofpacks/panchanga-summary.proofpack.json",
"examples/external/timepacks/payroll-date-risk.timepack.json",
"data/public/release-artifact-manifest.json",
"reports/source_coverage/coverage_matrix.json",
):
if not (PROJECT_ROOT / proof_artifact).exists():
failures.append(f"required proof/release artifact missing: {proof_artifact}")
routes = _read("backend/app/calendar/routes.py")
if "proof: str | None" not in routes or "build_convert_bs_to_ad_capsule" not in routes:
failures.append("core BS-to-AD route must expose membrane proof mode")
for route_marker in ("build_ad_to_bs_capsule", "build_validate_bs_date_capsule"):
if route_marker not in routes:
failures.append(f"calendar route must expose proof mode via {route_marker}")
if "build_panchanga_summary_capsule" not in routes:
failures.append("Panchanga route must expose method-docketed proof mode")
app = _read("frontend/src/App.jsx")
if 'path="/proof"' not in app:
failures.append("frontend proof viewer route /proof is missing")
panchanga_provider = _read("backend/app/panchanga/ephemeris_provider.py")
if "JplEphemerisProvider" not in panchanga_provider or "kernel_hash" not in panchanga_provider:
failures.append("Panchanga ephemeris layer must expose JPL provider interface with kernel hash")
panchanga_proof = _read("backend/app/panchanga/proof.py")
for marker in ("not_panchanga_authority", "not_ritual_final_authority", "ephemeris_metadata", "method_dockets"):
if marker not in panchanga_proof:
failures.append(f"Panchanga proof path missing {marker}")
compliance_routes = _read("backend/app/api/compliance_routes.py")
for route_marker in ("build_holiday_capsule", "build_working_day_capsule"):
if route_marker not in compliance_routes:
failures.append(f"compliance route must expose proof mode via {route_marker}")
enterprise_routes = _read("backend/app/api/enterprise_routes.py")
for route_marker in ("build_fiscal_year_capsule", "build_bs_months_capsule"):
if route_marker not in enterprise_routes:
failures.append(f"enterprise route must expose proof mode via {route_marker}")
public_openapi = _read("docs/api-docs/openapi.public-reference.json")
for schema_name in ("ProofReceipt", "ProofPack", "Timepack", "BoundaryVector", "FieldProvenance", "EphemerisProviderMetadata"):
if schema_name not in public_openapi:
failures.append(f"public OpenAPI missing proof schema {schema_name}")
verify_public = _read("scripts/release/verify_public.py")
for gate in (
"check_local_kernel_package.py",
"generate_route_proof_matrix.py",
"generate_source_coverage_report.py",
"verify_release_artifact_manifest.py",
"check_public_surface_security.py",
):
if gate not in verify_public:
failures.append(f"public verification missing semantic gate {gate}")
try:
ast.parse(_read("backend/app/membranes/capsule.py"))
ast.parse(_read("backend/app/membranes/verifier.py"))
ast.parse(_read("backend/app/panchanga/proof.py"))
except SyntaxError as exc:
failures.append(f"proof-system Python syntax error: {exc}")
try:
failures.extend(_verify_replay_artifacts())
except Exception as exc: # noqa: BLE001
failures.append(f"proof artifact evidence verification failed: {exc}")
return failures
def main() -> int:
failures = _failures()
if failures:
for failure in failures:
print(f"FAIL: {failure}")
return 1
print("Ceiling depth semantic checks passed.")
return 0
if __name__ == "__main__":
raise SystemExit(main())