feat(enforcement): adapter pattern with PolicyRouter (RTR)#15
Merged
Conversation
- Add BaseAdapter ABC with capability declarations: supported_policy_keys, supported_languages, config_targets, supported_clause_kinds, output_modes, supported_stages (ENF-epic extension stubs included per spec) - Add ConfigFragment dataclass as the in-memory artifact adapters produce - Wrap existing ESLint generator in ESLintAdapter(BaseAdapter) - Wrap existing Ruff generator in RuffAdapter(BaseAdapter) - Add StackDetector that scans project files by extension to identify the technology stack (python, javascript, typescript); skips build/cache dirs - Add PolicyRouter: matches active constraint fields to adapters by capability AND detected stack; reports unroutable policy keys - Refactor EnforcementPipeline.compile() to use the router instead of hard-coded adapter calls; accepts optional detected_stack override - Add 44 unit/integration tests covering all new components - 380 tests passing, ruff + mypy clean
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BaseAdapterABC with capability declarations (supported_policy_keys,supported_languages,config_targets,supported_clause_kinds,output_modes,supported_stages) so the router can inspect adapters without running themESLintAdapter/RuffAdaptersubclasses — no behaviour change, just the new interface layered on topStackDetectorthat scans project files by extension (*.py→ python,*.ts/tsx→ typescript,*.js/jsx→ javascript) skipping build/cache dirsPolicyRouterthat matches active constraint fields to adapters by capability AND detected stack, and reports unroutable policy keys (patterns, architecture, config_enforcement) as explicit skipsEnforcementPipeline.compile()to use the router; adds optionaldetected_stackoverride for tests and callers that already know the stackTest plan
tests/unit/test_adapter_registry.pycovering BaseAdapter contract, ESLintAdapter/RuffAdapter capabilities, StackDetector, PolicyRouter routing logic, unroutable key reporting, and all three integration scenarios (Python-only, JS-only, mixed)detected_stackwhere needed (1 test)