-
Notifications
You must be signed in to change notification settings - Fork 5
refactor(checkers): let declarations own provider runtimes #1299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d4f07c8
3004c7f
3d9e943
7a5c0f4
533e497
1922bc3
5680a34
1db4eb1
eac30f8
d9b7d6e
c55e4e7
18dc43b
567236f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from collections.abc import Callable, Mapping | ||
| from collections.abc import Mapping | ||
| from dataclasses import dataclass | ||
| from typing import Any, Literal | ||
|
|
||
|
|
@@ -59,7 +59,6 @@ | |
| from jacobian.verification.service import VerificationService | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
| _OPTIONAL_EXACT_REPLAY_PROVIDERS = frozenset({"jacobian.exact-domain-checkers"}) | ||
|
|
||
|
|
||
| @dataclass(frozen=True, slots=True) | ||
|
|
@@ -86,60 +85,45 @@ class _InstalledDeclaration: | |
| @dataclass(frozen=True, slots=True) | ||
| class _DeclaredRuntimeGroup: | ||
| probe: CapabilityProviderRuntime | ||
| factory: Callable[..., CapabilityProviderRuntime] | ||
| members: tuple[tuple[InstalledDomainBundle, ExactReplayCheckerDeclaration], ...] | ||
| factories: tuple[Callable[..., CapabilityProviderRuntime], ...] | ||
|
|
||
|
|
||
| def _declaration_factory( | ||
| declaration: ExactReplayCheckerDeclaration, | ||
| ) -> Callable[..., CapabilityProviderRuntime]: | ||
| factory = declaration.provider_runtime_factory | ||
| if factory is None: | ||
| raise ValueError( | ||
| "exact replay checker declaration requires a provider runtime factory" | ||
| ) | ||
| return factory | ||
|
|
||
|
|
||
| def _declared_runtime_groups( | ||
| pairs: tuple[tuple[InstalledDomainBundle, ExactReplayCheckerDeclaration], ...], | ||
| ) -> tuple[_DeclaredRuntimeGroup, ...]: | ||
| probes: dict[ | ||
| Callable[..., CapabilityProviderRuntime], CapabilityProviderRuntime | ||
| ] = {} | ||
| grouped: dict[ | ||
| str, | ||
| tuple[ | ||
| CapabilityProviderRuntime, | ||
| list[Callable[..., CapabilityProviderRuntime]], | ||
| list[tuple[InstalledDomainBundle, ExactReplayCheckerDeclaration]], | ||
| ], | ||
| ] = {} | ||
| for installed, declaration in pairs: | ||
| factory = _declaration_factory(declaration) | ||
| probe = probes.setdefault(factory, factory()) | ||
| factory = object.__getattribute__(declaration, "provider_runtime_factory") | ||
| probe = factory() if factory is not None else declaration.provider_runtime | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a custom factory returns a AGENTS.md reference: AGENTS.md:L155-L159 Useful? React with 👍 / 👎. |
||
| if probe is None: | ||
| continue | ||
| if not isinstance(probe, CapabilityProviderRuntime): | ||
| raise TypeError( | ||
| "provider runtime factory must return CapabilityProviderRuntime" | ||
| ) | ||
| current = grouped.get(probe.provider) | ||
| if current is None: | ||
| grouped[probe.provider] = (probe, [factory], [(installed, declaration)]) | ||
| grouped[probe.provider] = (probe, [(installed, declaration)]) | ||
| continue | ||
| existing_probe, factories, members = current | ||
| if existing_probe != probe: | ||
| existing_probe, members = current | ||
| if existing_probe.model_dump(mode="json") != probe.model_dump(mode="json"): | ||
| raise ValueError( | ||
| "exact replay grouped distinct probes under one provider " | ||
| f"identity: {probe.provider}" | ||
| ) | ||
| if factory not in factories: | ||
| factories.append(factory) | ||
| members.append((installed, declaration)) | ||
| return tuple( | ||
| _DeclaredRuntimeGroup( | ||
| probe=probe, | ||
| factory=factories[0], | ||
| members=tuple(members), | ||
| factories=tuple(factories), | ||
| ) | ||
| for probe, factories, members in grouped.values() | ||
| for probe, members in grouped.values() | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -150,15 +134,13 @@ def _authorize_replay_operation( | |
| authorize: bool, | ||
| provider_runtime: CapabilityProviderRuntime, | ||
| source_available: bool, | ||
| optional: bool, | ||
| capability_id: str, | ||
| diagnostics: list[CapabilityDiagnostic], | ||
| ) -> str | None: | ||
| if provider_runtime.availability is CapabilityProviderAvailability.AVAILABLE: | ||
| return installer.install(operation, authorize=authorize).checker_id | ||
| can_omit = ( | ||
| provider_runtime.provider in _OPTIONAL_EXACT_REPLAY_PROVIDERS | ||
| and source_available | ||
| ) | ||
| can_omit = optional and source_available | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a declaration-owned optional runtime is not Python-FLINT, this generic omission branch still emits AGENTS.md reference: AGENTS.md:L211-L214 Useful? React with 👍 / 👎. |
||
| if not can_omit: | ||
| return installer.install(operation, authorize=authorize).checker_id | ||
| diagnostic = CapabilityDiagnostic( | ||
|
|
@@ -191,18 +173,11 @@ def _authorized_provider_runtimes( | |
| for _installed, declaration in group.members | ||
| if (checker_id := checker_ids[declaration.capability_id]) is not None | ||
| ) | ||
| runtime = group.factory(checker_ids=authorized) | ||
| for factory in group.factories: | ||
| if factory is group.factory: | ||
| continue | ||
| other = factory(checker_ids=authorized) | ||
| if other != runtime: | ||
| raise ValueError( | ||
| "exact replay grouped distinct runtimes under one provider " | ||
| f"identity: {group.probe.provider}" | ||
| ) | ||
| runtime = group.probe.model_copy(update={"checker_ids": authorized}) | ||
| existing = provider_runtimes.get(runtime.provider) | ||
| if existing is not None and existing != runtime: | ||
| if existing is not None and existing.model_dump( | ||
| mode="json" | ||
| ) != runtime.model_dump(mode="json"): | ||
| raise ValueError( | ||
| "exact replay grouped distinct runtimes under one provider " | ||
| f"identity: {runtime.provider}" | ||
|
|
@@ -225,15 +200,26 @@ def install_exact_domain_checkers( | |
| """Install independent exact replay against dynamically registered schemas.""" | ||
|
|
||
| installer = CheckerInstaller(checkers) | ||
| groups = _declared_runtime_groups(_available_declaration_bundles(bundles)) | ||
| available_declarations = _available_declaration_bundles(bundles) | ||
| checker_ids: dict[str, str | None] = {} | ||
| declaration_providers: dict[str, str] = {} | ||
| diagnostics: list[CapabilityDiagnostic] = [] | ||
| checker_ids.update( | ||
| (declaration.capability_id, None) | ||
| for _installed, declaration in available_declarations | ||
| ) | ||
| if not authorize and not installer.bind_existing: | ||
| return ExactDomainCheckerInstallation( | ||
| checker_ids=checker_ids, | ||
| provider_runtimes={}, | ||
| declaration_providers={}, | ||
| ) | ||
| source_available = ( | ||
| exact_domain_checker_source_provider_runtime().availability | ||
| is CapabilityProviderAvailability.AVAILABLE | ||
| ) | ||
| with batch_checker_manifest_measurement(): | ||
| groups = _declared_runtime_groups(available_declarations) | ||
| for group in groups: | ||
| for installed, declaration in group.members: | ||
| declaration_providers[declaration.capability_id] = group.probe.provider | ||
|
|
@@ -264,6 +250,7 @@ def install_exact_domain_checkers( | |
| authorize=authorize, | ||
| provider_runtime=group.probe, | ||
| source_available=source_available, | ||
| optional=declaration.optional, | ||
| capability_id=declaration.capability_id, | ||
| diagnostics=diagnostics, | ||
| ) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.