Externalize the Artifact Registry activation refusals
What does this MR do and why?
The activation mutation artifactRegistryActivate returns a refusal as a string in its payload errors, at most one string per attempt. This MR makes the refusals GitLab owns translatable.
Which refusals reach whom:
- The setup page form (
ee/app/assets/javascripts/packages_and_registries/artifact_registry/setup/setup_form.vue) checks the slug rules client-side before it calls the mutation, and shows one message at a time. An invalid slug never reaches the server from the page, so the server's slug refusals reach only direct GraphQL API callers. API callers get their own request locale (GraphqlControllersets it), which is why they are worth translating. - The refusals the setup page can show are
:no_billing_anchor,:multiple_billing_anchorsand:mapping_lost. The form joins the payload errors with a space and shows them under the handle field.
What changes:
-
ee/lib/artifact_registry/slug_validator.rb: the four rule refusals reuse the setup form's own msgids, so they are already translated in 7 locales (fr, ga_IE, id_ID, it, ja, pt_BR, zh_CN; es has one of the four):ArtifactRegistry|Must be between %{min} and %{max} characters.(throughformat()with named placeholders)ArtifactRegistry|Only lowercase letters, digits and hyphens (-) are allowed. Remove any spaces or special characters.ArtifactRegistry|Must start and end with an alphanumeric character.ArtifactRegistry|Must not contain consecutive hyphens (--).
Each message is a full sentence with its own punctuation, so they are joined with a space (was
;), the same waysetup_form.vuejoins payload errors. The separate start and end rules became one boundary sentence. -
ee/app/services/artifact_registry/provision_namespace_service.rb::no_billing_anchor,:multiple_billing_anchorsand:mapping_lostare wrapped ins_()and given sentence case and a period:ArtifactRegistry|Organization has no top-level groups.ArtifactRegistry|Organization has more than one top-level group.ArtifactRegistry|Namespace mapping was removed during a concurrent request.
The words are the same as before. Sentence case and a period match the full-sentence neighbours
:already_activatedand:reonboarding_unavailable. This is done now because these msgids are new and have no translations yet; a later msgid change drops translations made in between. -
locale/gitlab.pot: regenerated withtooling/bin/gettext_extractor locale/gitlab.pot. The only change versus master is the three provision-service msgids (the slug msgids already exist). -
ee/spec/lib/artifact_registry/slug_validator_spec.rb:- Moved from
fast_spec_helpertospec_helper, becauses_()is not defined underfast_spec_helper. - A one-rule-per-row table asserts each rule's exact message. New rows:
aBc(only the charset sentence) and-slug-(the boundary sentence once). The''andnilrows pin the current output, which is the length, charset and boundary sentences. - A slug that breaks all four rules asserts the exact joined message in rule order.
- The same slug under
Gitlab::I18n.with_locale(:fr)asserts the French message. This catches a rule that dropss_(), because the default test locale is English. It compares only againsts_()under that locale, so a fuzzy or changed French entry cannot fail it.
- Moved from
-
ee/spec/services/artifact_registry/provision_namespace_service_spec.rb: pins the message for both anchor refusals and for:mapping_lost. -
ee/spec/requests/api/graphql/mutations/artifact_registry/activate_spec.rb: asserts withcontain_exactly(as the other examples in that file do) instead ofinclude, and its slug example usesab(one rule) instead ofA.
Deviations from the work item: the work item proposed wrapping the strings with "No behavior change". This MR also changes the English for the default locale. The slug refusals now use the form's wording, the separator changed from ; to a space, the start and end rules merged into one sentence, and the three provision-service refusals gained sentence case and a period. Dropping "ASCII" from the charset sentence loses some precision for API callers (an accented letter is a lowercase letter but is refused). This is accepted because the form already shows the same sentence.
Not changed: unresolvable_existing and the provision UnavailableError rescue. They are raised as service-unavailable errors and never reach the payload.
Follow-up:
- Refusals that come from Artifact Registry itself are still in English:
handle_api_errorin the provision service (409, 422 and other statuses) andartifact_registry_api_error_messageinee/app/graphql/resolvers/concerns/artifact_registry/renders_errors.rb. The:mapping_lostwording is also left for product copy. These are tracked in #633563. - The billing-anchor refusal copy is decided in #630929, which already covers how the page renders that refusal.
No changelog: the artifact_registry_ui feature flag is default_enabled: false.
Review round 1
@mkhalifa3 reviewed the first revision. Commit 8ff5ccb04f87 addresses the three threads:
- The boundary check is positive again, as in the frontend: it passes only when the slug starts and ends with
a-zor0-9.ABCand a blank slug get the boundary sentence again, as on master. Only API callers see this, because the setup form stops at its charset check. - The comment above the join is now one line:
# Each message is a full sentence, so a space joins them. - The French-locale example no longer asserts that the output does not match
/Must|Only/, because that depends on the content of the French .po file. It keeps theeqagainst the joineds_()messages underfr, which still fails if a rule dropss_(). If French loses one of these translations, the check for that rule stops proving anything, silently.
References
- Closes #631281 (closed)
- Raised in review: !258132 (comment 3923785463)
- Precedent for the
s_()style: !258132 (merged) - Follow-up: #633563
- Anchor refusal rendering and copy: #630929
Screenshots or screen recordings
Backend only. The table below was produced by running the real artifactRegistryActivate mutation in-process with GitlabSchema.execute on a development database, as the owner of the organization with the feature flag on. Before is master at 20b6503e, After is this MR.
| Call | Reaches | Before (master) | After |
|---|---|---|---|
slug A |
API only | must be between 3 and 63 characters; must contain only lowercase ASCII letters, digits, and hyphens; must start with an alphanumeric character; must end with an alphanumeric character |
Must be between 3 and 63 characters. Only lowercase letters, digits and hyphens (-) are allowed. Remove any spaces or special characters. Must start and end with an alphanumeric character. |
slug ABC |
API only | must contain only lowercase ASCII letters, digits, and hyphens; must start with an alphanumeric character; must end with an alphanumeric character |
Only lowercase letters, digits and hyphens (-) are allowed. Remove any spaces or special characters. Must start and end with an alphanumeric character. |
slug aBc |
API only | must contain only lowercase ASCII letters, digits, and hyphens |
Only lowercase letters, digits and hyphens (-) are allowed. Remove any spaces or special characters. |
slug a--b |
API only | must not contain consecutive hyphens |
Must not contain consecutive hyphens (--). |
slug a--b, fr locale |
API only | must not contain consecutive hyphens |
the French translation of the form's sentence |
| organization with no top-level group | setup page | organization has no top-level groups |
Organization has no top-level groups. |
| organization with two top-level groups | setup page | organization has more than one top-level group |
Organization has more than one top-level group. |
| organization with no top-level group, fr locale | setup page | organization has no top-level groups |
Organization has no top-level groups. (English until translators pick up the new msgid) |
Every refusal row also returned registry: null.
A valid slug on an organization with one top-level group returned errors: [] and a registry with status active, against a locally running Artifact Registry.
Submitting that same slug from a second organization under fr returned slug is already taken by another namespace. This is a refusal from Artifact Registry that stays in English, and it is covered by the follow-up.
How to set up and validate locally
Step 1. Paste this script into bin/rails console on this branch. Every refusal it checks is decided before any Artifact Registry call, so no Artifact Registry is needed. Expect seven PASS lines (the last is the French locale check). The groups are created with Group.create! rather than FactoryBot because the group factory's CI namespace mirror write can race GDK's Sidekiq and raise a unique-index error.
refuse = lambda do |organization, slug|
ArtifactRegistry::ProvisionNamespaceService.new(organization: organization, slug: slug, service_credential: nil).execute
end
suffix = SecureRandom.hex(4)
no_groups = FactoryBot.create(:organization, name: "ar-i18n-a-#{suffix}")
two_groups = FactoryBot.create(:organization, name: "ar-i18n-b-#{suffix}")
2.times { |i| Group.create!(organization: two_groups, name: "ar-i18n-g#{i}-#{suffix}", path: "ar-i18n-g#{i}-#{suffix}") }
checks = {
'too short and uppercase' => [refuse.call(no_groups, 'A'), :invalid_slug,
'Must be between 3 and 63 characters. Only lowercase letters, digits and hyphens (-) are allowed. ' \
'Remove any spaces or special characters. Must start and end with an alphanumeric character.'],
'one uppercase letter' => [refuse.call(no_groups, 'aBc'), :invalid_slug,
'Only lowercase letters, digits and hyphens (-) are allowed. Remove any spaces or special characters.'],
'leading hyphen' => [refuse.call(no_groups, '-abc'), :invalid_slug,
'Must start and end with an alphanumeric character.'],
'consecutive hyphens' => [refuse.call(no_groups, 'a--b'), :invalid_slug,
'Must not contain consecutive hyphens (--).'],
'no top-level group' => [refuse.call(no_groups, 'my-handle'), :no_billing_anchor,
'Organization has no top-level groups.'],
'two top-level groups' => [refuse.call(two_groups, 'my-handle'), :multiple_billing_anchors,
'Organization has more than one top-level group.']
}
checks.each do |name, (response, reason, message)|
ok = response.error? && response.reason == reason && response.message == message
puts "#{ok ? 'PASS' : 'FAIL'} #{name}: #{response.message.inspect}"
end
english = refuse.call(no_groups, 'a--b').message
french = Gitlab::I18n.with_locale(:fr) { refuse.call(no_groups, 'a--b').message }
puts "#{french == english ? 'FAIL' : 'PASS'} French locale: #{french.inspect}"Step 2. Confirm the three new provision-service msgids are in the translation template. Expect 3.
grep -c -E '^msgid "ArtifactRegistry\|(Organization has (no|more than one) top-level|Namespace mapping was removed)' locale/gitlab.potMR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.