Skip to content

Commit b3c9922

Browse files
committed
refactor(checkers): let declarations own provider runtimes
1 parent 73c6d17 commit b3c9922

3 files changed

Lines changed: 86 additions & 5 deletions

File tree

src/jacobian/checker_operations.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ class ExactReplayCheckerDeclaration:
9090
tags are used as written. If the domain omits the metadata, all four fields
9191
are strictly constructed from the producer capability ID so that no
9292
verifier metadata is absent at installation.
93+
94+
A declaration may own its complete clean-process provider runtime directly.
95+
Existing built-in families may continue to use the legacy central runtime
96+
registry while they are migrated. Direct runtimes must not carry checker
97+
IDs before operator authorization.
9398
"""
9499

95100
capability_id: str
@@ -102,6 +107,7 @@ class ExactReplayCheckerDeclaration:
102107
"operator-authorized Python-FLINT exact replay independent of the "
103108
"SymPy producer"
104109
)
110+
provider_runtime: CapabilityProviderRuntime | None = None
105111
verification_capability_id: str | None = None
106112
verification_title: str | None = None
107113
verification_description: str | None = None
@@ -120,6 +126,10 @@ def __post_init__(self) -> None:
120126
raise ValueError(
121127
f"exact replay checker declaration {field} must not be empty"
122128
)
129+
if self.provider_runtime is not None and self.provider_runtime.checker_ids:
130+
raise ValueError(
131+
"declaration-owned provider runtime must not pre-authorize checker IDs"
132+
)
123133
derived_id = derive_verification_capability_id(self.capability_id)
124134
explicit_text = (
125135
self.verification_title,

src/jacobian/exact_domain_checkers.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ class _InstalledDeclaration:
159159

160160

161161
def _provider_runtime_key(declaration: ExactReplayCheckerDeclaration) -> str:
162+
if declaration.provider_runtime is not None:
163+
return f"declaration:{declaration.capability_id}"
162164
if declaration.entrypoint_module == "jacobian_checkers.linear":
163165
return {
164166
"check_rational_solution": "linear-solution",
@@ -233,17 +235,30 @@ def install_exact_domain_checkers(
233235
features=("standard-library-rational-replay", "clean-process-checker"),
234236
),
235237
}
238+
available_declarations = _available_declaration_bundles(bundles)
236239
provider_runtimes = {
237240
runtime_key: factory() for runtime_key, factory in runtime_factories.items()
238241
}
242+
for _installed, declaration in available_declarations:
243+
if declaration.provider_runtime is None:
244+
continue
245+
runtime_key = _provider_runtime_key(declaration)
246+
previous = provider_runtimes.setdefault(
247+
runtime_key,
248+
declaration.provider_runtime,
249+
)
250+
if previous != declaration.provider_runtime:
251+
raise ValueError(
252+
"exact replay declarations disagree on their owned provider runtime"
253+
)
239254
checker_ids: dict[str, str | None] = {}
240255
declarations_by_id: dict[str, ExactReplayCheckerDeclaration] = {}
241256
diagnostics: list[CapabilityDiagnostic] = []
242257
exact_checker_source_available = (
243258
exact_domain_checker_source_provider_runtime().availability
244259
is CapabilityProviderAvailability.AVAILABLE
245260
)
246-
for installed, declaration in _available_declaration_bundles(bundles):
261+
for installed, declaration in available_declarations:
247262
declarations_by_id[declaration.capability_id] = declaration
248263
runtime_key = _provider_runtime_key(declaration)
249264
provider_runtime = provider_runtimes[runtime_key]
@@ -309,13 +324,21 @@ def install_exact_domain_checkers(
309324
)
310325
for runtime_key in provider_runtimes
311326
}
327+
resolved_provider_runtimes: dict[str, CapabilityProviderRuntime] = {}
328+
for runtime_key, provider_runtime in provider_runtimes.items():
329+
checker_ids_for_runtime = authorized_ids[runtime_key]
330+
factory = runtime_factories.get(runtime_key)
331+
resolved_provider_runtimes[runtime_key] = (
332+
factory(checker_ids=checker_ids_for_runtime)
333+
if factory is not None
334+
else provider_runtime.model_copy(
335+
update={"checker_ids": checker_ids_for_runtime}
336+
)
337+
)
312338
return ExactDomainCheckerInstallation(
313339
checker_ids=checker_ids,
314340
diagnostics=tuple(diagnostics),
315-
provider_runtimes={
316-
runtime_key: factory(checker_ids=authorized_ids[runtime_key])
317-
for runtime_key, factory in runtime_factories.items()
318-
},
341+
provider_runtimes=resolved_provider_runtimes,
319342
)
320343

321344

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from __future__ import annotations
2+
3+
import pytest
4+
5+
from jacobian.checker_operations import ExactReplayCheckerDeclaration
6+
from jacobian.contracts.capabilities import CapabilityInstallTier
7+
from jacobian.contracts.exact import CanonicalRational
8+
from jacobian.provider_runtime import source_provider_runtime
9+
10+
11+
def _runtime():
12+
return source_provider_runtime(
13+
"jacobian.test-declaration-checker",
14+
version="1",
15+
entrypoint="jacobian_checkers.linear:check_rational_solution",
16+
install_tier=CapabilityInstallTier.T1,
17+
license_id="MIT",
18+
features=("clean-process-checker",),
19+
)
20+
21+
22+
def test_exact_replay_declaration_owns_unassigned_provider_runtime() -> None:
23+
runtime = _runtime()
24+
declaration = ExactReplayCheckerDeclaration(
25+
"test.compute.value",
26+
CanonicalRational,
27+
"check_rational_solution",
28+
"test.value.replay",
29+
entrypoint_module="jacobian_checkers.linear",
30+
provider_runtime=runtime,
31+
)
32+
33+
assert declaration.provider_runtime == runtime
34+
assert declaration.provider_runtime.checker_ids == ()
35+
36+
37+
def test_exact_replay_declaration_rejects_preauthorized_runtime() -> None:
38+
runtime = _runtime().model_copy(update={"checker_ids": ("checker:test",)})
39+
40+
with pytest.raises(ValueError, match="must not pre-authorize checker IDs"):
41+
ExactReplayCheckerDeclaration(
42+
"test.compute.value",
43+
CanonicalRational,
44+
"check_rational_solution",
45+
"test.value.replay",
46+
entrypoint_module="jacobian_checkers.linear",
47+
provider_runtime=runtime,
48+
)

0 commit comments

Comments
 (0)