Wire elastic-package to package-spec validation modes#3617
Conversation
…h, ValidateBuiltFromZip Add three new exported functions that use the package-spec ModeSource and ModeBuild constructors instead of the deprecated ValidateFrom* free functions. Existing ValidateAndFilter* functions are kept untouched until callers are migrated. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace ValidateAndFilterFromPath/ValidateAndFilterFromZip with ValidateBuiltFromPath and ValidateBuiltFromZip in builder and installer packages to use the new named validation mode functions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…Filter* functions All call sites have been migrated to the named ValidateSource* and ValidateBuilt* functions, so the legacy wrappers are no longer referenced. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Four table-driven test functions (ValidateSourceFromPath, ValidateBuiltFromPath, ValidateBuiltFromZip) with local testdata fixtures covering both happy-path and cross-mode rejection cases: - source_package: has _dev/, passes ModeSource, fails ModeBuild (ValidateNoDevFolder) - built_package: has _embedded_ecs dynamic templates, passes ModeBuild, fails ModeSource (ValidateNoEmbeddedEcsInDynamicTemplates) - composable_source_package: uses package: stream references, passes ModeSource, fails ModeBuild (ValidateStreamInputMaterialized) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This replace is only needed during local development when working against an unpublished package-spec checkout. It must not be committed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The PR branch (teresaromero/package-spec@9c3e7024) cannot be fetched by the module proxy because the /v3 module path prevents Go from resolving fork commits until the PR is merged and the proxy indexes them. Replace with the local checkout, which is already at that exact commit. Remove this directive and bump the require version once PR elastic#1175 merges. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Extract validateFromPath helper to deduplicate ValidateSourceFromPath and ValidateBuiltFromPath (identical bodies, different mode constant). - Return allErrors unfiltered instead of dropping them when filterErrors fails; log the infrastructure error at debug level so it is not silently lost. - In ValidateBuiltFromZip, return allErrors (unfiltered) if the second zip.OpenReader or fsFromPackageZip call fails, preserving the validation result in all error paths. - Fix fsFromPackageZip to count only directory entries at the zip root; the previous check counted all entries, so a root-level non-directory file (e.g. __MACOSX metadata) would falsely trigger 'single directory expected'. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| return subDir, nil | ||
| } | ||
|
|
||
| // TODO: follow-up issue — move this logic into specerrors as an exported function so consumers don't reimplement it. |
Updated the validation functions to use more descriptive mode constants. Changed `ModeSource` to `SourceMode` and `ModeBuild` to `BuildMode`. Improved error handling in the validator creation process to provide clearer error messages. Adjusted validation calls to use the appropriate methods for path and zip validation.
TL;DRAll three failed Buildkite jobs are blocked before meaningful static checks/tests run because the PR adds a local Go module replacement for Remediation
Investigation detailsRoot CauseThis is a dependency/configuration failure introduced by the PR's // go.mod:59-61
// Local replace pointing to elastic/package-spec PR #1175 (teresaromero/package-spec@9c3e7024).
// Go cannot fetch fork commits for /v3 modules until the PR is merged and the proxy indexes it.
replace github.com/elastic/package-spec/v3 => ../package-specBuildkite checks out only Evidence
The Linux and macOS unit-test jobs fail with the same VerificationNot run locally against the PR head; the local checkout is at the base commit, and the CI logs plus PR diff directly identify the unresolved local replacement. What is this? | From workflow: PR Buildkite Detective Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not. |
💔 Build Failed
Failed CI StepsHistory
|
| result, err := filterErrors(allErrors, fsys) | ||
| if err != nil { | ||
| return err, nil | ||
| logger.Debugf("failed to filter validation errors: %v", err) |
There was a problem hiding this comment.
at this point allErrors is not nil; so in case any error happens during the filering, they were ignored... i've added a debug log with the error and return allErrors unfiltered; same un the zip case
mrodm
left a comment
There was a problem hiding this comment.
LGTM!
Tested locally to force failures in build and source modes and elastic-package lint and elastic-package build commands detected those.
Thanks!
Problem
elastic-packagecallspackage-specvalidation at several points in the lifecycle of a package — duringlint(source tree),build(built artifact, directory and zip), andinstall --zip(pre-built zip). All of these call sites were using the same deprecatedValidateFrom*/ValidateAndFilter*functions, which run inModeLegacy. This means the validation rules applied were identical regardless of whether the package was a source checkout or a built artifact.Why
package-specnow exposes explicit validation modes (ModeSourceandModeBuild) that reflect what a package actually is at each phase:ModeSourceallows source-only artifacts:_dev/directories,.linkfiles, andexternal: ecsfield references. These are normal in a checked-out package and are resolved or stripped during the build step.ModeBuildrejects those same artifacts. A built package that still contains_dev/or unresolvedexternal: ecsreferences is incorrect and should fail validation.Running
lintwithModeLegacy(instead ofModeSource) could silently allow or reject things inconsistently with what the source phase actually permits. RunningbuildandinstallwithModeLegacymeant that built artifacts carrying source-only remnants would not be caught.Changes
The
internal/validationpackage is rewritten to expose three named functions, one per validation context:ValidateSourceFromPath,ValidateBuiltFromPath, andValidateBuiltFromZip. The mode selection is encapsulated inside the validation package — call sites never referencevalidator.Modedirectly. Dead code (ValidateFromPath,ValidateFromZip) with zero callers is removed.All four call sites are updated to use the context-appropriate function:
lintusesValidateSourceFromPath;buildusesValidateBuiltFromPathandValidateBuiltFromZip;install --zipusesValidateBuiltFromZip.Tests are added to
internal/validationcovering the happy path for each new function.TestValidateBuiltFromPathandTestValidateBuiltFromZipeach include a rejection case confirming that a source package containing_dev/is rejected — guarding against silent reversion toModeLegacybehaviour on both the directory and zip code paths. AmakeZipFromDirtest helper generates zip fixtures on-the-fly, so no binary test fixture is committed.ValidateBuiltFromZipalso gainslogger.Debugfcalls in the two previously silent error paths (zip open failure and subdirectory extraction failure), making them visible under--verboseand consistent with the logging invalidateFromPath.Dependency
This PR depends on elastic/package-spec#1178 and package-spec being released
Testing
Tested by running a local build against the integrations packages. After the change, all packages validate as expected with no new failures and no regressions.