feat: add decision runtime conformance with optional OPA adapter - #2
Merged
Merged
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Runtime failures are misreported as divergences, scalar equality changes existing semantics, and the OPA process protocol lacks tests.
Review effort: Balanced
Findings: 2
Open (3)
What changed in this PR
Adds a reference decision-runtime contract and optional OPA/Rego adapter for conformance testing.
Changes:
- Introduces runtime and conformance APIs.
- Adds reference and OPA implementations plus CLI integration.
- Adds tests, capability declarations, and documentation.
| File | Description |
|---|---|
src/application/ports/decision-runtime.ts |
Defines the runtime contract. |
src/application/decision-conformance.ts |
Compares declared cases across runtimes. |
src/infrastructure/reference/reference-decision-runtime.ts |
Wraps native decision evaluation. |
src/infrastructure/opa/rego-generator.ts |
Generates Rego policies. |
src/infrastructure/opa/opa-decision-runtime.ts |
Executes decisions through OPA. |
src/interfaces/cli/main.ts |
Adds conformance commands. |
src/index.ts |
Exports the new APIs. |
tests/conformance.test.mjs |
Tests conformance and generation. |
framework/capabilities.json |
Declares runtime capabilities. |
README.md |
Documents CLI usage. |
docs/TESTING.md |
Documents conformance testing. |
docs/ROADMAP.md |
Updates planned runtime work. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+40
to
+43
| const passed = | ||
| Object.is(reference.value, testCase.expected) && | ||
| Object.is(candidate.value, reference.value) && | ||
| candidate.ruleId === reference.ruleId; |
Comment on lines
+54
to
+55
| } catch (error) { | ||
| cases.push({ |
| try { | ||
| writeFileSync(policy, generateDecisionRego(request.decisionId, request.spec), 'utf8'); | ||
| const query = `data.${opaPackageName(request.decisionId)}.result`; | ||
| const result = spawnSync( |
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.


Contexto
O PRD as a Code já possui
DecisionSpec,evaluateDecision(), casos de decisão e o roadmap de comparação diferencial. Este PR formaliza esse comportamento como uma semântica de referência e adiciona um primeiro runtime candidato: OPA/Rego.A intenção não é transformar OPA na autoridade semântica do produto nem adicionar um policy server. O objetivo é provar que uma decisão especificada no framework pode ser portada para outro runtime sem alterar o comportamento declarado.
O que muda
DecisionRuntime;ReferenceDecisionRuntimesobre oevaluateDecision()existente;conformDecision()para comparar casos declarados entre reference e runtime candidato;dmn-table/v1;OpaDecisionRuntime, executado poropa eval;Limites intencionais
Este PR não:
Decision.schema.json;BusinessRuleSBVR;O
DecisionSpecatual continua sendo a representação executável da v0.3 eevaluateDecision()continua sendo a referência.Arquitetura
Próximo PR proposto
Adicionar uma porta/protocolo de Fact Resolver conformance, permitindo testar:
sem introduzir SQL/Mongo/Redis no core do framework.
Verificação
--runtime opa.