agentleFS
Microsoft AzureKnown publisherAzure/ARO-HCP/test-integration/claude.md

ARO-HCP / test-integration

CLAUDE.md39 starsChanged 2 months agoApache-2.0View on GitHub

Artifact-driven integration tests for frontend, backend, and admin services. Tests run against a mock Cosmos DB by default. Tests are declarative: you define a sequence of numbered step directories under an artifacts tree. The framework discovers them automatically via //go:embed artifacts and fs.ReadDir().

The file

We split this claude.md into the rules it gives an agent

8 rules. About 0 are common, 3 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Create a new directory under the appropriate artifacts/<Suite>/<ResourceType>/ path

    line 39
  2. Very specific:

    Add step directories with the NN-<stepType>-<description>/ naming convention

    line 40
  3. Distinctive:

    Put JSON files in each step directory (resource documents, expected results, keys)

    line 41
  4. Distinctive:

    No key file needed

    line 133
  5. Distinctive:

    Place standard Kubernetes resource JSON/YAML files directly in the step directory

    line 134
  6. Very specific:

    Before the first node pool httpCreate/httpReplace:

    line 177
  7. Very specific:

    When the update should reach Cluster Service (GetCluster / UpdateCluster):

    line 189
  8. Very specific:

    Place these immediately before the cluster update step.

    line 195

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
claude.md

test-integration

Artifact-driven integration tests for frontend, backend, and admin services. Tests run against a mock Cosmos DB by default.

Directory Layout

test-integration/
├── admin/                          # Admin API integration tests
├── backend/                        # Backend controller tests
├── frontend/                       # Frontend service tests
├── utils/
│   ├── databasemutationhelpers/   # Step framework, assertions, step_*.go implementations
│   ├── integrationutils/          # Test infrastructure (mock cosmos, cluster service mock, HTTP servers)
│   └── controllertesthelpers/     # Controller test framework

How Tests Work

Tests are declarative: you define a sequence of numbered step directories under an artifacts tree. The framework discovers them automatically via //go:embed artifacts and fs.ReadDir().

Artifact tree structure

artifacts/<SuiteName>/<ResourceType>/<TestCase>/
  00-load-initial-state/
  01-httpCreate-resource/
  02-httpGet-resource/
  ...
  99-cosmosCompare-end-state/
  • Each test case is a directory containing numbered step subdirectories
  • Steps execute sequentially, sorted by their numeric prefix (NN-)
  • Step type is parsed from the directory name: NN-<stepType>-<description>/

Adding a new test

  1. Create a new directory under the appropriate artifacts/<Suite>/<ResourceType>/ path
  2. Add step directories with the NN-<stepType>-<description>/ naming convention
  3. Put JSON files in each step directory (resource documents, expected results, keys)
  4. The test framework discovers it automatically -- no Go code changes needed

Step Types

Loading steps

Step typePurpose
load / loadCosmosLoad raw JSON documents directly into cosmos
loadClusterServiceLoad mock cluster service state (files suffixed -cluster.json, -nodepool.json, -externalauth.json, -autoscaler.json, -hypershiftdetails.json, -provisionshard.json)
kubernetesLoadCreate Kubernetes resources via fake clientsets
kubernetesApplyUpdate existing K8s resources from JSON/YAML files. Can be partial files.
migrateCosmosTrigger database schema migrations

HTTP API steps (ARM REST calls)

Step typePurposeCompares response?
httpGetGET a single resourceYes, via ResourceInstanceEquals
httpListLIST resourcesYes, each item compared
httpCreate / httpReplacePUT a resourceNo (checks error only)
httpPostPOST a resourceNo (checks error only)
httpPatchPATCH a resourceNo (checks error only)
httpDeleteDELETE a resourceNo (checks error only)

Database CRUD steps (direct DB operations)

Step typePurpose
createCreate resource via DB CRUD API
getGet resource by parsed ResourceID
getByIDGet by cosmos ID
listList resources in container
replaceReplace entire resource
replaceWithETagReplace with optimistic concurrency
deleteDelete resource
listActiveOperationsList in-progress operations for a resource

Untyped database steps

Step typePurpose
untypedGetGet untyped document
untypedListList untyped documents
untypedListRecursiveRecursively list untyped descendants
untypedDeleteDelete untyped document

Assertion / control steps

Step typePurpose
cosmosCompareAssert entire cosmos state matches expected JSON documents
kubernetesCompareAssert K8s resource state matches expected JSON files (uses ResourceInstanceEquals)
completeOperationMark an async operation as succeeded
setClusterServiceIDStamp a Cluster Service internal ID onto a cluster/node pool/external auth doc. Clusters get a random CS HREF (matching mock PostCluster behavior) unless cluster-service-id.json is provided. Node pools and external auths derive from the parent cluster's stored CS ID. Node pool create: add an explicit setClusterServiceID-cluster step (or loadCosmos with a pre-stamped cluster) before the first node pool httpCreate/httpReplace, since node pool creation requires the parent cluster to have a clusterServiceID. External auth creation does not require a parent Cluster Service ID. Cluster update: when a cluster httpReplace/httpPatch should call the Cluster Service mock (GetCluster/UpdateCluster), add setClusterServiceID-cluster (with fixed cluster-service-id.json) immediately followed by loadClusterService-cluster before the update step. See Cluster Service ID patterns below.

Step Directory Contents

Most steps contain:

  • 00-key.json -- identifies the target resource (format varies by step type)
  • One or more *.json files -- resource documents or expected results
  • expected-error.txt (optional) -- expected error substring for error-checking steps

Key file formats

HTTP steps:

{"resourceID": "/subscriptions/.../providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/name"}

Typed CRUD steps:

{
  "parentResourceId": "/subscriptions/.../providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/name",
  "resourceType": "Microsoft.RedHatOpenShift/hcpOpenShiftClusters/hcpOpenShiftControllers"
}

Untyped recursive steps:

{
  "parentResourceId": "/subscriptions/.../...",
  "resourceType": "Microsoft.RedHatOpenShift/hcpOpenShiftClusters",
  "descendents": [
    {"resourceType": "Microsoft.RedHatOpenShift/hcpOpenShiftClusters/nodePools", "resourceName": "pool-name"}
  ]
}

Kubernetes steps (kubernetesLoad, kubernetesApply, kubernetesCompare):

  • No key file needed
  • Place standard Kubernetes resource JSON/YAML files directly in the step directory
  • Resources are identified by their apiVersion, kind, metadata.name, and optionally metadata.namespace

Cosmos Document ID Format

The .id field in cosmos documents is a UUID V5 derived from the resource's ARM resource ID:

  • Lowercase the entire resource ID
  • Generate a UUID V5 using a fixed namespace UUID (bf1ee0a1-0147-41ed-a083-d3cbbf7bea99) and the lowercased resource ID as the name

Example: /subscriptions/AAA/resourceGroups/BBB/providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/CCC becomes: <uuid-v5-hash> (e.g., a1b2c3d4-e5f6-5789-abcd-ef0123456789)

The UUID V5 format provides:

  • Deterministic IDs (same resource ID always produces the same UUID)
  • Compliance with Cosmos DB key length limits
  • URL-safe characters (no / or | delimiters)

Implementation: internal/api/arm/types_cosmosdata.go:ResourceIDStringToCosmosID()

ResourceInstanceEquals (comparison logic)

per_resource_comparer.go -- the core assertion function used by all comparison steps.

Always stripped from both expected and actual before comparison:

  • Cosmos internals: _rid, _self, _etag, _attachments, _ts
  • cosmosMetadata.etag
  • endTime (for operations)
  • Timestamps: startTime, lastTransitionTime, operationId
  • Internal tracking: activeOperationId, internalId (including under intermediateResourceDoc)
  • Controller condition lastTransitionTime entries

Stripped only for Operation resources (detected via resourceType field or operationId presence):

  • id, resourceId, cosmosMetadata -- these are UUID-based for operations

Not stripped (now compared) for non-operation resources:

  • id -- must match the pipe-delimited cosmos ID for cosmos documents, or the ARM resource ID for HTTP responses

Cluster Service ID patterns

The frontend only calls the Cluster Service mock on cluster update when the Cosmos document already has a clusterServiceID (frontend/pkg/frontend/cluster.go). Integration tests must make that ID explicit and seed the mock when exercising update paths.

Node pool create

Before the first node pool httpCreate/httpReplace:

  1. NN-setClusterServiceID-cluster/00-key.json — parent cluster resourceID from the cluster create step
  2. No cluster-service-id.json — parent gets a random CS HREF at runtime (matches backend PostCluster behavior)
  3. Child setClusterServiceID-resource derives the child CS ID from the parent's stored ID

Skip when the parent is pre-stamped via loadCosmos (e.g. cluster-creating / cluster-deleting fixtures).

External auth creation does not need setClusterServiceID-cluster. External auth create and update operations use an empty internalId, even when updating a legacy resource with a stored clusterServiceID.

Cluster update (httpReplace / httpPatch)

When the update should reach Cluster Service (GetCluster / UpdateCluster):

  1. NN-setClusterServiceID-cluster/00-key.json — cluster resourceID
  2. NN-setClusterServiceID-cluster/cluster-service-id.json — fixed HREF, e.g. "/api/clusters_mgmt/v1/clusters/cs-{suite-name}"
  3. NN+1-loadClusterService-cluster/cs-{suite-name}-cluster.json and cs-{suite-name}-autoscaler.json — mock fixtures whose href matches the stamped ID

Place these immediately before the cluster update step. Complete any in-flight create operation first if the suite creates then updates (see noop-update, create-current).

cosmosCompare after CS-backed update: bump the cluster document's cosmosMetadata.instanceVersion (typically +1). clusterServiceID and activeOperationId are stripped by ResourceInstanceEquals and need not match exactly. Reference: Cluster/read-old-data, Cluster/create-current.

Error-path updates that fail validation before CS (e.g. update-to-illegal-value, update-reject-cluster-version-skew-patch) may still include the stamp/load steps for consistency, but the mock is not consulted when validation rejects the request first.

Running Tests

go test ./test-integration/frontend/...
go test ./test-integration/backend/...
go test ./test-integration/admin/...

Tests run against mock infrastructure by default. Set FRONTEND_SIMULATION_TESTING=true to also run against real Cosmos DB.

The frontend starts real cluster, node pool, ServiceProviderCluster (SPC), and ServiceProviderNodePool (SPNP) informers before fixtures are loaded. The artifact harness waits for visible DB membership, instance versions, and typed content to match these caches before HTTP create/replace/patch/delete steps. Go tests that mutate storage directly should call IntegrationTestInfo.WaitForFrontendCaches before cache-dependent requests. Integration informers use a test-only short relist interval for same-version fixture replacements and hard deletes; production defaults are unchanged. Readiness requires HTTP 200 from frontend /healthz and admin /healthz/ready, and servers must be cancelled and joined before storage cleanup.

SPC and SPNP documents are backend-owned. Frontend admission reads them from the cache and never initializes missing documents. Explicitly seed SPC before cluster updates and node pool creation, and SPNP before node pool updates or cluster updates that inspect existing node pools, using loadCosmos steps or typed DB creates. Preserve expected Cosmos snapshots by loading the provider documents they expect rather than relying on frontend side effects.

Key Source Files

  • utils/databasemutationhelpers/resource_crud_test_util.go -- test orchestration, step discovery
  • utils/databasemutationhelpers/per_resource_comparer.go -- assertion/comparison logic
  • utils/databasemutationhelpers/step_*.go -- individual step implementations
  • utils/integrationutils/utils.go -- test infrastructure setup (mock cosmos, HTTP servers)
  • utils/integrationutils/kube_mock.go -- fake Kubernetes clientsets with informer support
  • utils/integrationutils/cluster_service_mock.go -- OCM cluster service mock
  • internal/databasetesting/mock_dbclient.go -- in-memory cosmos mock

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.