Skip to content

refactor(recipe): move _ForTesting cache helpers off the public surface #1079

Description

@mchmarny

Summary

CachedStoreCountForTesting / CachedStoreContainsForTesting in pkg/recipe/metadata_store.go:342, 367 and CachedRegistryCountForTesting / CachedRegistryContainsForTesting in pkg/recipe/components.go:274, 295 are added by #1072 to the exported surface of pkg/recipe (marked Public (evolving) in docs/integrator/public-api.md:21).

The _ForTesting suffix is convention-only. Nothing prevents production callers from using them, and once they're in the exported surface they're subject to the same evolve-with-care contract as any other public symbol.

Motivation

The PR uses these helpers only from the facade tests (aicr_internal_test.go, aicr_test.go). They have no production use. Keeping them in pkg/recipe's public API:

  • pollutes the package surface for external consumers
  • locks in the helpers' signature as part of the contract
  • makes it harder to refactor the underlying cache (e.g., a future bounded-LRU replacement would need to maintain compatible counters)

Acceptance

Pick one approach; either is acceptable:

  • Move helpers to a pkg/recipe/internal/cachetest subpackage. Internal packages cannot be imported outside pkg/recipe/..., so the facade tests would need to live under that path or use an export shim.
  • Move helpers to pkg/recipe/cache_export_test.go with //go:build test (or package recipe_test + a shared test fixture) so they're only visible during go test. Facade tests pass through a fixture file in pkg/recipe.
  • Drop the count-based helpers entirely and assert eviction using only the per-DataProvider Contains* helpers; that's what the existing test in aicr_test.go (TestClient_NoCacheGrowthAcrossManyCloseCycles) already prefers.

Related

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions