/claim #837
This PR implements comprehensive coverage tracking for permission rules, specifically detecting when parts of conditions are skipped due to short-circuit evaluation (e.g., when A OR B evaluates A as true, B is never executed).
Previously, the coverage command would mark a permission as “covered” if any part of the condition was asserted, even if other parts were skipped due to short-circuit logic. This led to incomplete coverage assessments.
Example from issue:
permission view = system.view or ((is_public or (is_partner and partner) or (viewer or company.maintain or organization.maintain or team.view)) not denied)
Asserting only system.view would mark the entire permission as covered, even though other components were never tested.
Implemented a comprehensive coverage tracking system that:
internal/coverage/registry.go: Thread-safe registry for tracking node visits with SourceInfo (Line:Column)internal/coverage/discovery.go: AST walker that discovers and registers all logic nodes during schema parsinginternal/engines/coverage_test.go: Comprehensive test for short-circuit detectioninternal/engines/check.go: Added trace() wrapper to instrument evaluation paths and track visitspkg/development/development.go: Integrated logic coverage into coverage command outputpkg/development/coverage/coverage.go: Extended coverage info with logic node trackingpkg/cmd/coverage.go: Updated to display logic coverage informationproto/base/v1/base.proto: Added PositionInfo message for source position trackingpkg/dsl/compiler/compiler.go: Enhanced to populate PositionInfo during compilation✅ Source Position Tracking: Every node includes Line:Column information from source
✅ Unique Node IDs: Deterministic path-based IDs (e.g., repository#edit.0, repository#edit.1)
✅ Short-Circuit Detection: Correctly identifies skipped nodes in:
sync.RWMutex for concurrent accessTestCheckEngineCoverage: Verifies short-circuit detection for OR operationsTestRegistry: Validates registry functionality and thread safetyTestDiscover: Confirms AST discovery correctly registers all logic nodesTest Case:
permission edit = owner or admin
// When owner=true, admin (path: repository#edit.1) correctly identified as uncovered
All tests pass successfully.
The coverage command now reports:
Example:
Logic Coverage: 50%
Uncovered Logic Nodes:
- repository#edit.1 (Line: 26, Column: 25) [OR]
Description: Second operand of OR expression was skipped due to short-circuit
PositionInfo in tokens to track source positionsVisitCount == 0 to identify gapsNone. This is a backward-compatible enhancement.
Closes #837
See COVERAGE_READINESS.md for detailed implementation assessment and verification. The implementation correctly detects when parts of permission rules are skipped due to short-circuit evaluation, providing detailed coverage information with exact source positions for uncovered nodes.
New Features
Behavioral
Tests
Matías J. Magni
@info3
Permify.co
@Permify