monolith/S05 virtual: test the upstream row's Size after an accepted Clear cache

What this does

Adds the test case that Step 10 of the monolith/S05 virtual plan asks for. After an accepted Clear cache on a remote upstream row, the virtual detail page does not re-read its upstream list, and the row's Size cell keeps the value it showed before. Step 10's MR, !258346 (merged), added the Size column without this case. This MR only adds tests. upstream_repository_actions.vue passes the new case unchanged.

Closes #631623 (closed)

Related to #631075 (closed)

Changes

  • repository_detail_spec.js: createComponent takes an optional clearCacheHandler and registers clearRepositoryCacheMutation on the mock Apollo client.
  • New Clear cache on a remote upstream row block under a virtual repository. It fully mounts the page over the generated upstream fixture and clicks Clear cache on the remote maven-central-proxy row. It then checks three things: the mutation went out for that upstream, the upstream list was read only once, and the row's Size reads 1.46 MiB both before and after the click.

How to set up and validate locally

All steps run from the repository root on this branch. If the detail spec fails across the board on master too (for example this.$refs.dropdown.focusToggle is not a function), your node_modules is behind package.json, so run yarn install --frozen-lockfile first.

Step 1: Generate the fixtures the spec imports

bundle exec rspec \
  ee/spec/frontend/fixtures/artifact_registry/repository.rb \
  ee/spec/frontend/fixtures/artifact_registry/repository_artifacts.rb \
  ee/spec/frontend/fixtures/artifact_registry/repository_upstream_repositories.rb \
  ee/spec/frontend/fixtures/artifact_registry/repository_statistics.rb

Expected: 0 failures.

Output (✅)
8 examples, 0 failures

Step 2: Run the new case

node_modules/.bin/jest ee/spec/frontend/packages_and_registries/artifact_registry/repositories/detail/repository_detail_spec.js \
  -t 'Clear cache on a remote upstream row'

Expected: 4 passed.

Output (✅)
Clear cache on a remote upstream row
  ✓ renders the size the upstream list read returned for the row
  once the clear is accepted
    ✓ clears the cache of the upstream the row names
    ✓ issues no second upstream list read, so the page does not refetch the list
    ✓ keeps the size the row rendered before the clear, because nothing re-reads it
Tests:       175 skipped, 4 passed, 179 total

Step 3: Run the whole detail spec and the row actions spec

node_modules/.bin/jest \
  ee/spec/frontend/packages_and_registries/artifact_registry/repositories/detail/repository_detail_spec.js \
  ee/spec/frontend/packages_and_registries/artifact_registry/repositories/detail/upstream_repository_actions_spec.js

Expected: both suites pass.

Output (✅)
PASS ee/spec/frontend/packages_and_registries/artifact_registry/repositories/detail/upstream_repository_actions_spec.js
PASS ee/spec/frontend/packages_and_registries/artifact_registry/repositories/detail/repository_detail_spec.js
Test Suites: 2 passed, 2 total
Tests:       222 passed, 222 total

Step 4: Check that the case fails if Clear cache refetches the upstream list

Make Clear cache re-read the upstream list, run the case, then revert.

git apply <<'PATCH'
diff --git a/ee/app/assets/javascripts/packages_and_registries/artifact_registry/repositories/detail/upstream_repository_actions.vue b/ee/app/assets/javascripts/packages_and_registries/artifact_registry/repositories/detail/upstream_repository_actions.vue
index 7c5d15525d90..d8794e777275 100644
--- a/ee/app/assets/javascripts/packages_and_registries/artifact_registry/repositories/detail/upstream_repository_actions.vue
+++ b/ee/app/assets/javascripts/packages_and_registries/artifact_registry/repositories/detail/upstream_repository_actions.vue
@@ -98,6 +98,8 @@ export default {
           mutation: clearRepositoryCacheMutation,
           input: { name },
           update: evictClearedRepositoryDetails(name),
+          refetchQueries: ['getArtifactRegistryRepositoryUpstreamRepositories'],
+          awaitRefetchQueries: true,
         });
 
         if (!accepted) return;
PATCH
node_modules/.bin/jest ee/spec/frontend/packages_and_registries/artifact_registry/repositories/detail/repository_detail_spec.js \
  -t 'Clear cache on a remote upstream row'
git checkout -- ee/app/assets/javascripts/packages_and_registries/artifact_registry/repositories/detail/upstream_repository_actions.vue

Expected: issues no second upstream list read fails with Expected number of calls: 1, Received number of calls: 2.

Output (✅ (fails as intended))
✓ renders the size the upstream list read returned for the row
✓ clears the cache of the upstream the row names
✕ issues no second upstream list read, so the page does not refetch the list
✓ keeps the size the row rendered before the clear, because nothing re-reads it
● ... › once the clear is accepted › issues no second upstream list read, so the page does not refetch the list
  Expected number of calls: 1
  Received number of calls: 2
Tests:       1 failed, 175 skipped, 3 passed, 179 total

Step 5: Check that the case fails if Clear cache changes the row's Size

Make Clear cache rewrite the row's sizeBytes to 0 in the cache (through the association, because the upstream summary has no cache key of its own), run the case, then revert. The patch also switches the upstream read to cache-first so the Size assertion is tested on its own.

Why the patch also changes the fetch policy

The upstream read is cache-and-network. On Apollo Client 3.5, a cache write to the list it watches triggers a network re-read, and the fixture's real size comes back. So the cache rewrite alone already fails Step 4's request-count check. Switching to cache-first stops that re-read, so the run shows the Size check failing by itself.

git apply <<'PATCH'
diff --git a/ee/app/assets/javascripts/packages_and_registries/artifact_registry/repositories/detail/repository_detail.vue b/ee/app/assets/javascripts/packages_and_registries/artifact_registry/repositories/detail/repository_detail.vue
index 4803bbb9516a..efc30316d8c8 100644
--- a/ee/app/assets/javascripts/packages_and_registries/artifact_registry/repositories/detail/repository_detail.vue
+++ b/ee/app/assets/javascripts/packages_and_registries/artifact_registry/repositories/detail/repository_detail.vue
@@ -114,7 +114,7 @@ export default {
     },
     upstreamRepositories: {
       query: getRepositoryUpstreamRepositoriesQuery,
-      fetchPolicy: fetchPolicies.CACHE_AND_NETWORK,
+      fetchPolicy: fetchPolicies.CACHE_FIRST,
       variables() {
         return { organizationId: this.organizationGid, name: this.repositoryName };
       },
diff --git a/ee/app/assets/javascripts/packages_and_registries/artifact_registry/repositories/detail/upstream_repository_actions.vue b/ee/app/assets/javascripts/packages_and_registries/artifact_registry/repositories/detail/upstream_repository_actions.vue
index 7c5d15525d90..814e278cf8f9 100644
--- a/ee/app/assets/javascripts/packages_and_registries/artifact_registry/repositories/detail/upstream_repository_actions.vue
+++ b/ee/app/assets/javascripts/packages_and_registries/artifact_registry/repositories/detail/upstream_repository_actions.vue
@@ -97,7 +97,16 @@ export default {
         const accepted = await executeDeleteMutation(this.$apollo, {
           mutation: clearRepositoryCacheMutation,
           input: { name },
-          update: evictClearedRepositoryDetails(name),
+          update: (cache, result) => {
+            evictClearedRepositoryDetails(name)(cache, result);
+            cache.modify({
+              id: cache.identify({
+                __typename: 'ArtifactRegistryUpstreamRepositoryAssociation',
+                id: this.associationId,
+              }),
+              fields: { upstreamRepository: (summary) => ({ ...summary, sizeBytes: '0' }) },
+            });
+          },
         });
 
         if (!accepted) return;
PATCH
node_modules/.bin/jest ee/spec/frontend/packages_and_registries/artifact_registry/repositories/detail/repository_detail_spec.js \
  -t 'Clear cache on a remote upstream row'
git checkout -- \
  ee/app/assets/javascripts/packages_and_registries/artifact_registry/repositories/detail/upstream_repository_actions.vue \
  ee/app/assets/javascripts/packages_and_registries/artifact_registry/repositories/detail/repository_detail.vue

Expected: keeps the size the row rendered before the clear fails with Expected: "1.46 MiB", Received: "0 B".

Output (✅ (fails as intended))
✓ renders the size the upstream list read returned for the row
✓ clears the cache of the upstream the row names
✓ issues no second upstream list read, so the page does not refetch the list
✕ keeps the size the row rendered before the clear, because nothing re-reads it
  Expected: "1.46 MiB"
  Received: "0 B"
Tests:       1 failed, 175 skipped, 3 passed, 179 total

Ran locally on this branch at 909010d7e5f. Steps 4 and 5 were pasted as written and reverted cleanly (git status empty afterwards).

Evidence

This MR only changes a Jest spec. No client, GraphQL, or UI code changes, so the validation runs above are the evidence. Steps 4 and 5 cover the issue's second acceptance item: the case fails if Clear cache refetches the list or changes the row's Size.

Rails console

N/A (no client change).

GraphiQL

N/A (no GraphQL change).

Screen recordings

N/A (no user-visible change).

🤖 Generated with Claude Code

Edited by Fiona McCawley

Merge request reports

Loading
Loading