-
Notifications
You must be signed in to change notification settings - Fork 91
validator: introduce mode-aware constructors and validation API #1177
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
Open
teresaromero
wants to merge
30
commits into
elastic:main
Choose a base branch
from
teresaromero:549-validation-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 22 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
c2b6ed7
Update .gitignore to include .scratch directory
teresaromero 1166296
Add internal Mode scaffolding for validation modes
teresaromero 892c661
Add public constructor API with mode-aware validators (task 02)
teresaromero a5c8cfc
Add eager path/fs validation to NewFromPath and NewFromFS constructors
teresaromero 30cfd76
Fix API: NewFromZip drops mode param, NewFromFS ModeSource uses linke…
teresaromero d482f31
Fix lint: add godoc comments to exported modes package symbols
teresaromero 2769edc
Add mode.Valid() guard in NewSpec and improve Validate() closer error…
teresaromero 324c4a0
Fix TestLegacyPreservation_FromZip to match NewFromZip signature change
teresaromero d999602
Add support for mode-aware constructors and validation APIs in changelog
teresaromero fe83a0a
Address PR review: fix API semantics, tests, and remove private newFr…
teresaromero 491658c
Fix TestNewFromZip_ConstructorSucceeds file handle leak on Windows
teresaromero 15750f5
Update .gitignore to remove .scratch directory entry
teresaromero fcaf8c2
Refactor Validator constructors to remove Option parameter
teresaromero f4e266e
refactor POV on modes validation
teresaromero e9d0013
remove unused public mode
teresaromero cbd3b7c
Improve documentation for validation API and modes
teresaromero 0f275c0
Add unit tests for mode validation
teresaromero d1efd03
Add integration tests for link file behavior across validation modes
teresaromero 4233331
Remove unused test case for package validation without links in TestL…
teresaromero da2a325
Remove wrapping around specFn
teresaromero 8539209
Restore Option C Validator API with mode-embedded FS and fix link blo…
teresaromero b0049ff
Improve godoc comments for validation modes API
teresaromero d4508b1
Add copyright notice to modes.go file
teresaromero 8d441f1
Move modes into internal validator pkg
teresaromero 15cc91e
Refactor validator API to streamline mode handling
teresaromero cc5e273
Remove modes.go file and consolidate mode definitions in validator.go
teresaromero 2a3fef8
Add comprehensive tests for ValidateFromFS and ValidateFromZip methods
teresaromero d8a2a6c
Refactor validation mode constants for clarity and consistency
teresaromero ebac0c7
Refactor validator instantiation to unify creation method
teresaromero d895e49
Add logging for validation mode in technical preview
teresaromero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| // or more contributor license agreements. Licensed under the Elastic License; | ||
| // you may not use this file except in compliance with the Elastic License. | ||
|
|
||
| package modes | ||
|
|
||
| // Mode represents the validation context: which semantic rules run and how | ||
| // linked (.link) files are handled during package validation. | ||
| type Mode string | ||
|
|
||
| const ( | ||
| // Legacy preserves the original validation behavior: linked files are | ||
| // resolved transparently and no rules are mode-gated. | ||
| Legacy Mode = "legacy" | ||
| // Source validates a package as a checked-out source tree: linked files | ||
| // are resolved transparently and source-only rules are enforced. | ||
| Source Mode = "source" | ||
| // Build validates a package as a built artifact: linked files are | ||
| // unconditionally blocked and build-only rules are enforced. | ||
| Build Mode = "build" | ||
| ) | ||
|
|
||
| // Valid reports whether m is a recognised validation mode. | ||
| func (m Mode) Valid() bool { | ||
| switch m { | ||
| case Legacy, Source, Build: | ||
| return true | ||
| } | ||
| return false | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| // or more contributor license agreements. Licensed under the Elastic License; | ||
| // you may not use this file except in compliance with the Elastic License. | ||
|
|
||
| package modes | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestValid(t *testing.T) { | ||
| tests := map[string]struct { | ||
| mode Mode | ||
| valid bool | ||
| }{ | ||
| "valid": { | ||
| mode: Legacy, | ||
| valid: true, | ||
| }, | ||
| "invalid": { | ||
| mode: Mode("invalid"), | ||
| valid: false, | ||
| }, | ||
| "source": { | ||
| mode: Source, | ||
| valid: true, | ||
| }, | ||
| "build": { | ||
| mode: Build, | ||
| valid: true, | ||
| }, | ||
| "": { | ||
| mode: Mode(""), | ||
| valid: false, | ||
| }, | ||
| } | ||
|
|
||
| for name, test := range tests { | ||
| t.Run(name, func(t *testing.T) { | ||
| assert.Equal(t, test.valid, test.mode.Valid(), "mode %s should be %v", test.mode, test.valid) | ||
| }) | ||
| } | ||
| } |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package validator | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| import ( | ||
| "io/fs" | ||
|
|
||
| "github.com/elastic/package-spec/v3/code/go/internal/linkedfiles" | ||
| "github.com/elastic/package-spec/v3/code/go/internal/validator/modes" | ||
| ) | ||
|
|
||
| // Mode represents the validation context: which rules apply and how linked files | ||
| // are handled when creating a Validator from a path. | ||
| // Use ModeLegacy, ModeSource, or ModeBuild. | ||
| type Mode struct { | ||
| internal modes.Mode | ||
| // wrapFS builds the filesystem for path-based validation (NewFromPath). | ||
| // It is not applied by NewFromFS, which takes the caller's filesystem as-is. | ||
| wrapFS func(location string, fsys fs.FS) fs.FS | ||
| } | ||
|
|
||
| var ( | ||
| // ModeLegacy preserves the original validation behavior: linked (.link) files | ||
| // are resolved transparently and no rules are mode-gated. | ||
| // Use this mode when backward compatibility with existing callers is required. | ||
| ModeLegacy = Mode{ | ||
| internal: modes.Legacy, | ||
| wrapFS: func(location string, fsys fs.FS) fs.FS { | ||
| return linkedfiles.NewFS(location, fsys) | ||
| }, | ||
| } | ||
|
|
||
| // ModeSource validates a package as a checked-out source tree. | ||
| // Linked (.link) files are resolved transparently. | ||
| // Source-only rules (e.g. dev-folder checks) are enforced; build-only rules are skipped. | ||
| ModeSource = Mode{ | ||
| internal: modes.Source, | ||
| wrapFS: func(location string, fsys fs.FS) fs.FS { | ||
| return linkedfiles.NewFS(location, fsys) | ||
| }, | ||
| } | ||
|
|
||
| // ModeBuild validates a package as a built artifact — the output of | ||
| // elastic-package build, a zip archive, or a package served by the registry. | ||
| // Linked (.link) files are unconditionally blocked. | ||
| // Build-only rules are enforced; source-only rules are skipped. | ||
| ModeBuild = Mode{ | ||
| internal: modes.Build, | ||
| wrapFS: func(_ string, fsys fs.FS) fs.FS { | ||
| return linkedfiles.NewBlockFS(fsys) | ||
| }, | ||
| } | ||
| ) | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.