|
33 | 33 | CapabilityResult, |
34 | 34 | CapabilityScope, |
35 | 35 | ) |
36 | | -from jacobian.contracts.lean import LeanEnvironment |
37 | | -from jacobian.contracts.lean_exploration import LeanProofStateArtifact |
38 | 36 | from jacobian.contracts.lean_metavariable_fields import ( |
39 | 37 | LeanElaborationContext, |
40 | 38 | LeanMetavariableFieldsArtifact, |
|
43 | 41 | LeanStructuredMetavariable, |
44 | 42 | ) |
45 | 43 | from jacobian.contracts.results import Execution, ExecutionStatus |
| 44 | +from jacobian.lean_frontend._state_validation import _load_validated_proof_state |
46 | 45 | from jacobian.lean_frontend.artifacts import ( |
47 | 46 | _environment_digest, |
48 | | - _environment_imports, |
49 | 47 | _proof_state_command, |
50 | 48 | _source_digest, |
51 | | - _state_digest_payload, |
52 | 49 | ) |
53 | 50 | from jacobian.lean_frontend.exploration import ( |
54 | 51 | _Resources, |
55 | 52 | _runtime_ms, |
56 | 53 | _validate_source_parts, |
57 | 54 | ) |
58 | 55 | from jacobian.lean_frontend.repl import _response_errors |
59 | | -from jacobian.storage.errors import StorageError |
60 | 56 |
|
61 | 57 |
|
62 | 58 | class LeanMetavariableFieldsAdapter: |
@@ -113,10 +109,14 @@ def invoke(self, request: CapabilityRequest) -> CapabilityResult: |
113 | 109 | validated.environment, |
114 | 110 | installation, |
115 | 111 | ) |
116 | | - bound_state = self._load_bound_state( |
| 112 | + bound_state = _load_validated_proof_state( |
| 113 | + self.resources, |
117 | 114 | validated.state_uri, |
118 | 115 | expected_environment=validated.environment, |
119 | 116 | expected_environment_digest=environment_digest, |
| 117 | + invalid_state_hint=( |
| 118 | + "Use a state URI returned by a proof-state capability." |
| 119 | + ), |
120 | 120 | ) |
121 | 121 | if bound_state.completed: |
122 | 122 | raise CapabilityInvocationError( |
@@ -326,56 +326,6 @@ def invoke(self, request: CapabilityRequest) -> CapabilityResult: |
326 | 326 | artifact_uris=(validated.state_uri, artifact.artifact_uri), |
327 | 327 | ) |
328 | 328 |
|
329 | | - def _load_bound_state( |
330 | | - self, |
331 | | - state_uri: str, |
332 | | - *, |
333 | | - expected_environment: LeanEnvironment, |
334 | | - expected_environment_digest: str, |
335 | | - ) -> LeanProofStateArtifact: |
336 | | - try: |
337 | | - stored = self.resources.store.get(state_uri) |
338 | | - if ( |
339 | | - stored.manifest.schema_uri != self.resources.state_schema_uri |
340 | | - or stored.manifest.semantics_uri != self.resources.semantics_uri |
341 | | - ): |
342 | | - raise ValueError("artifact is not a Lean proof state") |
343 | | - state = LeanProofStateArtifact.model_validate(stored.payload) |
344 | | - except (StorageError, ValidationError, ValueError) as exc: |
345 | | - raise CapabilityInvocationError( |
346 | | - CapabilityDiagnostic( |
347 | | - code="INVALID_LEAN_PROOF_STATE", |
348 | | - stage="state_loading", |
349 | | - message="The supplied state artifact is unavailable or invalid.", |
350 | | - hint="Use a state URI returned by a proof-state capability.", |
351 | | - ) |
352 | | - ) from exc |
353 | | - installation = self.resources.installations[expected_environment] |
354 | | - expected_imports = _environment_imports(expected_environment) |
355 | | - if ( |
356 | | - state.environment is not expected_environment |
357 | | - or state.environment_digest != expected_environment_digest |
358 | | - or state.imports != expected_imports |
359 | | - or state.lean_version != installation.lean_version |
360 | | - or state.lean_commit != installation.lean_commit |
361 | | - or state.mathlib_commit != installation.mathlib_commit |
362 | | - or state.source_digest |
363 | | - != _source_digest(state.statement, state.tactic_prefix) |
364 | | - or state.state_digest != _state_digest_payload(state) |
365 | | - ): |
366 | | - raise CapabilityInvocationError( |
367 | | - CapabilityDiagnostic( |
368 | | - code="STALE_LEAN_PROOF_STATE", |
369 | | - stage="state_validation", |
370 | | - message=( |
371 | | - "The proof state no longer matches its source or the " |
372 | | - "current pinned Lean environment." |
373 | | - ), |
374 | | - hint="Recreate the proof state under the current environment.", |
375 | | - ) |
376 | | - ) |
377 | | - return state |
378 | | - |
379 | 329 |
|
380 | 330 | def install_lean_metavariable_fields_capability( |
381 | 331 | resources: _Resources, |
|
0 commit comments