feat(lint): introduce structured-first lint validation#65
Merged
ghaskins merged 3 commits intomanetu:mainfrom Apr 8, 2026
Merged
feat(lint): introduce structured-first lint validation#65ghaskins merged 3 commits intomanetu:mainfrom
ghaskins merged 3 commits intomanetu:mainfrom
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
d9f7356 to
2b4a3f2
Compare
…n/lint
Add a new pkg/policydomain/lint package that exposes a Lint() function
returning []Diagnostic — a unified type carrying file path, line/column,
severity, entity context, and source category. This allows third-party
consumers (e.g. CodeMirror editors) to use the same validation logic as
the CLI and implement their own frontend.
Key changes:
- Diagnostic type: Source, Severity, Location{File,Start{Line,Col}},
Entity{Domain,Type,ID,Field}, Message, Category
- YAML validation preserves line numbers from yaml.v3 error strings
- Rego AST parse errors now expose ast.Error.Location.{Row,Col}
- Regal violations map synthetic-file lines back to YAML file lines
via computeRegoOffsets() (yaml.Node tree walk)
- OPA check replaced with in-process ast.CompileModules — no more
shell-out to opa check, errors carry line/col from ast.Errors
- registry.NewRegistryPermissive() loads domains without fail-fast on
validation errors so all phases can run even when refs are broken
- mpe lint CLI rewritten as a thin Diagnostic formatter, same output
- Regal tests skip gracefully under GODEBUG=fips140=only (OPA crypto.md5
is not FIPS-safe; this was a pre-existing upstream limitation)
Signed-off-by: Greg Haskins <greg@manetu.com>
2b4a3f2 to
6b567a6
Compare
- Add SourceRegistry diagnostic source for domain-loading errors that are not YAML syntax failures (e.g. unknown apiVersion, wrong kind) - Surface parsers.LoadFromBytes errors as SourceRegistry diagnostics instead of silently skipping the file - Fix registry creation error diagnostic from misleading SourceYAML to SourceRegistry - Guard regoOffsets map lookups against nil in opacheck.go and regal.go (explicit nil check makes fallback intent clear) - Add RegalTimeout to Options (default 60 s) and apply context.WithTimeout before calling Regal to prevent indefinite hangs - Export SyntheticRegoName so it can be unit-tested directly - Centralize mapper fallback ID format in mapperFallbackID() helper, eliminating the three-way duplication across rego, opacheck, and regal - Rename LintFromStrings parameter files → contents for clarity - Add tests: TestSyntheticRegoName, TestLintFromStrings_AllInvalidYAML, TestLintFromStrings_UnknownAPIVersion Signed-off-by: Greg Haskins <greg@manetu.com>
muralisrini
previously approved these changes
Apr 7, 2026
core.go had 0% coverage because all existing tests called plint.Lint() directly, bypassing Execute() entirely. This adds an executeCmd() helper that constructs a real cli.Command with the lint subcommand's flags and drives Execute() end-to-end. Integration tests via executeCmd(): - No files specified -> error - Valid file, multiple valid files -> success paths - Unsupported file extension (.json) -> warning + skip - --no-opa-flags, --opa-flags explicit, MPE_CLI_OPA_FLAGS env var - Invalid YAML, bad Rego, OPA check failure, reference error - --regal with violations (printResult Regal-violations path) - --regal with no Rego (printResult Regal-passed path) Direct unit tests for unexported helpers (same-package access): - TestRegalTitle: both branches (with/without colon separator) - TestPrintDiagnostic_AllSources: SourceYAML, SourceCycle, SourceRego without line, SourceOPACheck without line, SourceRegal without entity, and the empty-file "unknown" fallback - TestPrintResult_NoFileDiagnostics: byFile[""] path for no-file diagnostics - TestPrintFileSuccesses_ParseFailure: parsers.Load error -> "Valid YAML" - TestPrintFileSuccesses_MapperNoID: mapper with no name/mrn -> "mapper[N]" Result: core.go coverage 0% -> 99.1% (only unreachable TOCTOU path remains) Signed-off-by: Greg Haskins <greg@manetu.com>
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.
Add a new pkg/policydomain/lint package that exposes a Lint() function returning []Diagnostic — a unified type carrying file path, line/column, severity, entity context, and source category. This allows third-party consumers (e.g. CodeMirror editors) to use the same validation logic as the CLI and implement their own frontend.
Key changes: