chore(recipe): remove back-compat shims introduced by #1107#1118
Conversation
Closes #1114. The Stage 2 of #983. Now that #1108 migrated all in-tree CLI/API callers off the deprecated package-global path, remove the back-compat shims so the deprecated symbols are gone from the public surface. External Go importers using the deprecated path must migrate to the per-DataProvider variants. Symbols removed from pkg/recipe: - SetDataProvider / GetDataProvider (and the globalDataProvider / dataProviderGeneration / dataProviderMu / getDataProviderGeneration package-globals) - EffectiveDataProvider (was the bound-first / global-fallback shim) - DefaultRegistry (package-singleton criteria registry shim over GetCriteriaRegistryFor(GetDataProvider())) - ParseCriteriaServiceType / ParseCriteriaAcceleratorType / ParseCriteriaIntentType / ParseCriteriaOSType / ParseCriteriaPlatformType (package-level shims over DefaultRegistry().ParseService / .ParseAccelerator / etc.) - AllCriteriaServiceTypes / AllCriteriaAcceleratorTypes / AllCriteriaIntentTypes / AllCriteriaOSTypes / AllCriteriaPlatformTypes (package-level shims over DefaultRegistry().AllServiceTypes / etc.) - BuildCriteria + WithCriteriaService / WithCriteriaAccelerator / WithCriteriaIntent / WithCriteriaOS / WithCriteriaPlatform / WithCriteriaNodes (and the CriteriaOption type — its sibling RegistryCriteriaOption + BuildCriteriaWithRegistry path remains) - LoadFromFile (package-level wrapper over LoadFromFileWithProvider) Symbols removed from pkg/validator/catalog: - Load(version, commit) — back-compat shim over LoadWithDataProvider Symbols removed from pkg/config: - (*RecipeSpec).ResolveCriteria — back-compat shim over ResolveCriteriaWithRegistry(DefaultRegistry()) Migration & ripples: - pkg/api/recipe_handler.go: ParseCriteriaFromRequest / ParseCriteriaFromBody / ParseCriteriaFromValues now take an explicit *recipe.CriteriaRegistry parameter; the handler passes h.client.CriteriaRegistry(). - pkg/recipe/handler.go and handler_query.go: pass GetCriteriaRegistryFor(b.DataProvider()) on the registry-aware path. - pkg/recipe/criteria.go: validateAndConvertRawSpec / LoadCriteriaFromFile / LoadCriteriaFromFileWithContext / loadCriteriaFromHTTPWithContext now take an explicit *CriteriaRegistry. - (*Criteria).Validate now uses an ephemeral registry and is paired with a new ValidateWithRegistry(reg) for callers holding a real one. - pkg/fingerprint/(*Fingerprint).ToCriteria now takes a *recipe.CriteriaRegistry; pkg/cli/query.go passes client.CriteriaRegistry(). - pkg/cli/snapshot.go: uses recipe.NewCriteriaRegistry().ParseOS instead of the package-level shim. - pkg/cli/recipe.go: help text + tab completions use the static GetCriteria*Types instead of the package-singleton's AllCriteria*Types, matching the pre-PR effective behavior at help-generation time. - pkg/cli/evidence_digest.go: constructs an explicit embedded DataProvider for ComputeRecipeDigest. - pkg/evidence/attestation/ComputeRecipeDigest now takes a recipe.DataProvider parameter (was: relied on the package-global). - pkg/client/v1/aicr.go criteriaFromRequest takes a *recipe.CriteriaRegistry; the resolve path passes the Client's own registry via GetCriteriaRegistryFor(builder.DataProvider()). - pkg/config/resolve.go ResolveCriteriaWithRegistry's nil-fallback now builds NewCriteriaRegistry() (an ephemeral empty registry) instead of DefaultRegistry(). - pkg/validator/catalog/LoadWithDataProvider's nil-fallback now uses NewEmbeddedDataProvider directly instead of GetDataProvider(). - pkg/recipe/adapter.go / components.go / metadata_store.go nil-fallbacks: same swap. - pkg/bundler/bundler.go: drops recipe.EffectiveDataProvider in favor of inline nil-check on provider before the LayeredDataProvider type assertion (type assertions on nil interface return zero/false). - pkg/recipe/criteria_registry.go GetCriteriaRegistryFor(nil) now returns a fresh NewCriteriaRegistry() (not cached) instead of caching against the package-global provider. Test updates: - Deleted TestDataProviderGeneration, TestEffectiveDataProvider, TestRecipeResult_GetValuesForComponent_BoundProviderSurvivesGlobalSwap, TestLoadCatalog_DoesNotLeakRegistryOnFailure, TestDefaultRegistry_Singleton, TestBuildCriteria, TestWithCriteriaOS, TestWithCriteriaNodes — they exercised the deleted shim paths. - Deleted pkg/recipe/criteria_registry_parse_test.go in full — every test in it targeted a deleted symbol. - Updated remaining tests to use the per-provider variants (NewCriteriaRegistry() in place of DefaultRegistry(), method-form reg.ParseService in place of ParseCriteriaServiceType, etc.). - Removed TestMain in validators/deployment that pre-initialized the package-global to avoid a parallel-test race — that race is gone with the global itself. External Go importers must update: - import path / call patterns from the deleted symbols above + per-provider equivalents (recipe.WithDataProvider, the + (*CriteriaRegistry).Parse* methods, BuildCriteriaWithRegistry, + LoadFromFileWithProvider, catalog.LoadWithDataProvider, + ResolveCriteriaWithRegistry). No behavior change for in-tree CLI/REST callers (they were migrated in #1108). make qualify clean.
Coverage Report ✅
Coverage BadgeMerging this branch changes the coverage (2 decrease, 3 increase)
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Enterprise Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR removes package-global recipe DataProvider/DefaultRegistry shims and makes provider and criteria-registry usage explicit across the codebase. It adds NewCriteriaRegistry, switches parsing/validation to registry-bound methods, introduces LoadFromFileWithProvider, changes nil-provider fallbacks to an embedded provider, updates handlers/CLI/client to thread registries from their DataProvider, and migrates tests to the new APIs while deleting tests that asserted global-provider/singleton behavior. Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
…rror wrap Addresses CodeRabbit review on #1118: - pkg/recipe: introduce a package-level defaultEmbeddedProvider singleton used as the nil-fallback by LoadMetadataStoreFor, GetComponentRegistryFor, and GetManifestContentWithProvider. Constructing a fresh *EmbeddedDataProvider on every nil call would change the registryCache / storeCache key identity each time, defeating the per-DataProvider cache and causing unbounded growth on the default path. A single instance gives the cache a stable key. - pkg/recipe/adapter.go, components.go, metadata_store.go: switch every nil-fallback site to use defaultEmbeddedProvider. - pkg/recipe/adapter.go: update GetManifestContentWithProvider and RecipeResult.GetValuesForComponent godoc to reflect the embedded fallback (was: "falls back to GetDataProvider()"). - pkg/recipe/criteria_registry.go: drop the now-stale "use DefaultRegistry for the package singleton consulted by ParseCriteria*Type" wording; retarget the docs to NewCriteriaRegistry (ephemeral) and GetCriteriaRegistryFor (per-DataProvider). Drop the "global default" reference on GetCriteriaRegistryFor. - pkg/client/v1/aicr.go criteriaFromRequest: replace errors.Wrap with errors.PropagateOrWrap when surfacing recipe.BuildCriteriaWithRegistry failures so structured error codes (e.g., ErrCodeInvalidRequest from registry parse) survive the boundary instead of being clobbered with a fixed ErrCodeInvalidRequest wrapper. Build, lint, and tests clean on affected packages.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pkg/recipe/metadata_store.go (1)
90-92:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winGoDoc still references removed
GetDataProvider()fallback.Lines 90-92 state "A nil provider falls back to GetDataProvider()" but the implementation at line 118 now uses
defaultEmbeddedProvider. Update the comment to reflect the actual embedded-data singleton fallback behavior.Suggested fix
-// A nil provider falls back to GetDataProvider() so the legacy -// loadMetadataStore(ctx) entry point — which consults the package-global -// provider — continues to work transparently. +// A nil provider falls back to the package-level embedded-data singleton +// (defaultEmbeddedProvider) so the legacy loadMetadataStore(ctx) entry +// point continues to work transparently.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/recipe/metadata_store.go` around lines 90 - 92, Update the GoDoc to reflect the actual fallback behavior: change the comment that says "A nil provider falls back to GetDataProvider()" to state that a nil provider falls back to the package-level embedded-data singleton `defaultEmbeddedProvider` so that `loadMetadataStore(ctx)` continues to work; reference `loadMetadataStore` and `defaultEmbeddedProvider` in the comment to make the behavior explicit.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@pkg/recipe/metadata_store.go`:
- Around line 90-92: Update the GoDoc to reflect the actual fallback behavior:
change the comment that says "A nil provider falls back to GetDataProvider()" to
state that a nil provider falls back to the package-level embedded-data
singleton `defaultEmbeddedProvider` so that `loadMetadataStore(ctx)` continues
to work; reference `loadMetadataStore` and `defaultEmbeddedProvider` in the
comment to make the behavior explicit.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Enterprise
Run ID: a2874611-02b0-4add-8119-97c7f07ebda9
📒 Files selected for processing (6)
pkg/client/v1/aicr.gopkg/recipe/adapter.gopkg/recipe/components.gopkg/recipe/criteria_registry.gopkg/recipe/metadata_store.gopkg/recipe/provider.go
There was a problem hiding this comment.
Review verified against cac8a55a.
Two functional findings are posted inline below (query POST criteria validation). The remaining items are doc/godoc cleanup that can't be attached inline because those files aren't part of this PR's diff:
Doc/godoc cleanup (files not in this PR):
-
docs/contributor/data.md(~L1698–L1816) — the global-provider section still documents removed/global APIs and stale guidance:SetDataProvider,GetDataProvider,GetDataProviderGeneration,DefaultRegistry(),ParseCriteriaServiceType,AllCriteria{...}Types(), and "callLoadCatalogright afterSetDataProvider". (recipe.LoadCatalog(ctx)itself still exists — only the surrounding guidance is stale.) Suggest rewriting around the per-provider API:NewBuilder(WithDataProvider(dp)),GetCriteriaRegistryFor(dp)/NewCriteriaRegistry(),(*CriteriaRegistry).ParseService(and siblings),GetCriteria{...}Types()for the static lists,LoadMetadataStoreFor(ctx, dp),GetComponentRegistryFor(dp), and(*client.Client).LoadCatalog(ctx). -
docs/contributor/validator.md(L235) — image-tag resolution is described as "applied bycatalog.Load", butcatalog.Load(version, commit)was removed in favor ofcatalog.LoadWithDataProvider(dp, version, commit). -
pkg/recipe/doc.go(L158–L164) — package godoc still says callers "may continue to useSetDataProvider/GetDataProvider… remain functional for back-compat" and that a nil provider "falls back toGetDataProvider()". Both are now false — the accessors are gone and the nil fallback routes throughdefaultEmbeddedProvider. This is misleading to the external-importer audience the PR's breaking-change note targets.
Minor: stale code comments still reference the removed EffectiveDataProvider / GetDataProvider() / AllCriteriaServiceTypes in pkg/recipe/{adapter,criteria,metadata,metadata_store,components,builder}.go (the bundler.go ones are flagged inline below).
Note: the earlier cache-key-stability findings (fresh *EmbeddedDataProvider per nil-call defeating storeCache/registryCache) were verified as already resolved on this head by the defaultEmbeddedProvider singleton in provider.go — not re-raised here.
…ale comments Addresses three more findings on #1118: - pkg/recipe/handler_query.go: the POST branch validated req.Criteria with the no-arg Validate() (which uses a fresh ephemeral NewCriteriaRegistry — OSS-only), while the GET branch parsed against the per-provider registry already in scope (`reg`). A criteria value contributed by a `--data` overlay would be accepted on GET and rejected with HTTP 400 on POST against the same handler — a real GET/POST asymmetry. Switch the POST validation to ValidateWithRegistry(reg) so both verbs honor the same registry. - pkg/api/recipe_handler.go: same fix in the API server's query handler — POST now validates with ValidateWithRegistry(h.client.CriteriaRegistry()). - pkg/bundler/bundler.go: two stale comments referenced EffectiveDataProvider (removed by this PR) falling back to the package-global. Rewrite both to describe the current behavior: bundler asserts on the bound provider directly; a nil interface returns (nil, false) from the LayeredDataProvider type assertion without panicking, equivalent to no external data. Build + lint + tests clean.
yuanchen8911
left a comment
There was a problem hiding this comment.
Approving. The two functional findings — query POST --data criteria validation in pkg/recipe/handler_query.go and pkg/api/recipe_handler.go — are resolved via ValidateWithRegistry, CI is green, and no blockers remain.
A few minor doc/godoc cleanups remain (non-blocking — fine as a follow-up):
docs/contributor/data.mdstill documents removed global-provider and criteria-registry APIs (SetDataProvider,GetDataProvider,GetDataProviderGeneration,DefaultRegistry(),AllCriteria{...}Types()).pkg/recipe/doc.gostill tells external importers thatSetDataProvider/GetDataProviderremain functional for back-compat — worth correcting since this PR removes them.docs/contributor/validator.mdstill references the removedcatalog.Load(nowcatalog.LoadWithDataProvider).
PR NVIDIA#1118 removed the package-global data-provider and criteria-registry shims, but three docs still referenced the deleted APIs: - docs/contributor/data.md: rewrote the CLI-init example to the per-command aicr.Client pattern, dropped the "package-global accessors" subsection, and refreshed the Criteria Registry prose + API-surface table to the per-DataProvider API (GetCriteriaRegistryFor / NewCriteriaRegistry / (*CriteriaRegistry).Parse*/All*Types, (*aicr.Client).LoadCatalog). - pkg/recipe/doc.go: removed the "SetDataProvider/GetDataProvider remain functional" claim and updated the ParseCriteriaFromRequest/Body and LoadCriteriaFromFile examples to pass the new registry argument. - docs/contributor/validator.md: catalog.Load -> catalog.LoadWithDataProvider.
Summary
Remove the back-compat shims in
pkg/recipeandpkg/validator/catalogthat were retained from #1107 so the deprecated package-global path is gone from the public surface. The Stage 2 of #983.Fixes: #1114
Related: #983, #987, #1076 (epic, closed), #1107, #1108
Motivation
#1107 introduced per-
DataProviderisolation but kept the legacy entry points as thin shims so #1108 could land without forcing every caller to migrate in lockstep. Now that #1108 has shipped and all in-tree callers consume the per-provider path throughpkg/client/v1.Client, the shims serve no in-tree purpose. Keeping them invites new code to reach for the global path and leaks the deprecated symbols intopkg/recipe's Public (evolving) surface indefinitely.Type of Change
Component(s) Affected
pkg/cli)pkg/api)pkg/recipe)pkg/bundler)pkg/validator,pkg/validator/catalog)pkg/config,pkg/fingerprint,pkg/evidence/attestation)pkg/client/v1facade,validators/*Symbols removed
pkg/recipeSetDataProvider,GetDataProvider(and theglobalDataProvider/dataProviderGeneration/dataProviderMu/getDataProviderGenerationpackage-globals)recipe.NewBuilder(recipe.WithDataProvider(dp)); hold and passDataProviderexplicitlypkg/recipeEffectiveDataProvider(bound-first/global-fallback shim)LayeredDataProvidertype assertion is nil-safepkg/recipeDefaultRegistry(singleton overGetCriteriaRegistryFor(GetDataProvider()))recipe.NewCriteriaRegistry()for an ephemeral one;recipe.GetCriteriaRegistryFor(dp)for per-providerpkg/recipeParseCriteriaServiceType/…Accelerator/…Intent/…OS/…Platform(*CriteriaRegistry).ParseService/.ParseAccelerator/.ParseIntent/.ParseOS/.ParsePlatformpkg/recipeAllCriteriaServiceTypes/…Accelerator/…Intent/…OS/…Platform(*CriteriaRegistry).AllServiceTypesetc., orGetCriteriaServiceTypesetc. (static OSS lists)pkg/recipeBuildCriteria+WithCriteriaService/…Accelerator/…Intent/…OS/…Platform/…Nodes(and theCriteriaOptiontype)BuildCriteriaWithRegistry+WithServiceRegistry/WithAcceleratorRegistry/ etc. (RegistryCriteriaOptiontype)pkg/recipeLoadFromFileLoadFromFileWithProviderpkg/validator/catalogLoad(version, commit)LoadWithDataProvider(dp, version, commit)pkg/config(*RecipeSpec).ResolveCriteria()(*RecipeSpec).ResolveCriteriaWithRegistry(reg)Signature changes (registry threading)
recipe.ParseCriteriaFromRequest(r *http.Request)(r *http.Request, reg *CriteriaRegistry)recipe.ParseCriteriaFromValues(values url.Values)(values url.Values, reg *CriteriaRegistry)recipe.ParseCriteriaFromBody(body io.Reader, contentType string)(body io.Reader, contentType string, reg *CriteriaRegistry)recipe.LoadCriteriaFromFile(path string)(path string, reg *CriteriaRegistry)recipe.LoadCriteriaFromFileWithContext(ctx, path)(ctx, path, reg *CriteriaRegistry)fingerprint.(*Fingerprint).ToCriteria()(reg *recipe.CriteriaRegistry)attestation.ComputeRecipeDigest(ctx, path, kubeconfig, version)(ctx, dp recipe.DataProvider, path, kubeconfig, version)(*Criteria).ValidateValidateWithRegistry(reg)for callers holding a registryA nil registry on any of the new signatures falls back to a fresh ephemeral
NewCriteriaRegistry()— only hardcoded OSS values will validate. Callers that need--dataoverlay values to flow through must pass a non-nil registry (typicallyclient.CriteriaRegistry()).In-tree call-site migrations
pkg/api/recipe_handler.go→ passesh.client.CriteriaRegistry()pkg/recipe/handler.go,handler_query.go→GetCriteriaRegistryFor(b.DataProvider())pkg/cli/snapshot.go,pkg/cli/recipe.go→ freshNewCriteriaRegistry()/ staticGetCriteria*Types()pkg/cli/evidence_digest.go→ constructs an embeddedDataProviderforComputeRecipeDigestpkg/client/v1/aicr.go→criteriaFromRequest(req, GetCriteriaRegistryFor(builder.DataProvider()))pkg/bundler/bundler.go→ inline nil-check + direct type assertion (provider.(*recipe.LayeredDataProvider))pkg/recipe/components.go,metadata_store.go,adapter.go→NewEmbeddedDataProvider(GetEmbeddedFS(), "")instead ofGetDataProvider()pkg/recipe/criteria_registry.goGetCriteriaRegistryFor(nil)→ returns a fresh ephemeral registry (not cached) instead of caching against the globalTest updates
Deleted (their target symbols are gone):
TestDataProviderGeneration,TestEffectiveDataProviderinpkg/recipe/provider_test.goTestRecipeResult_GetValuesForComponent_BoundProviderSurvivesGlobalSwapinpkg/recipe/adapter_test.goTestLoadCatalog_DoesNotLeakRegistryOnFailure,TestDefaultRegistry_Singletoninpkg/recipe/criteria_registry_test.goTestBuildCriteria,TestWithCriteriaOS,TestWithCriteriaNodesinpkg/recipe/criteria_test.gopkg/recipe/criteria_registry_parse_test.gofile — every test in it targeted a deleted symbolTestMaininvalidators/deployment/expected_resources_test.go(workaround for a parallel-test race inglobalDataProviderlazy init; race is gone with the global)Migrated:
reg.ParseService(...)instead ofParseCriteriaServiceType(...)DefaultRegistry()now useNewCriteriaRegistry()pkg/bundler/bundler_test.go'sSet/GetDataProviderswap →recipeResult.BindDataProvider(layered)pkg/validator/catalog/catalog_test.go'sSet/GetDataProviderswap → pass the layered provider directly toLoadWithDataProviderpkg/client/v1/aicr_internal_test.go,aicr_test.goBuildCriteria+WithCriteria*→BuildCriteriaWithRegistry(nil, ...)+WithXRegistryBehavior
No in-tree behavior change. All in-tree callers were migrated by #1108; this PR only removes the deprecated entry points and updates a few remaining call sites that still hit them.
For external Go importers: any caller still on the deprecated path must migrate. See the symbol mapping table above.
Testing
pkg/trustfails locally due to a sandbox network restriction (TUF endpoint not in allowlist); CI has network access and the test passed there for prior PRs of mine.Risk Assessment
Rollout notes: Release notes for the next minor must call this out as a breaking change. External importers update per the symbol mapping table above. No
// Deprecated:warnings preceded this removal in tree, but the symbols carried//nolint:staticcheck // back-compat fallback ... (#983 Stage 2)comments indicating their intended lifetime.Checklist
make test(race) passes locally (modulo pre-existing pkg/trust sandbox-network failure)make lintpasses// Deprecated:symbols intentionally left behindgit commit -S)