Skip to content

fix(devops): key locale list by position instead of scraped priority - #760

Open
Max Stegmeyer (mstegmeyer) wants to merge 1 commit into
trunkfrom
fix/locale-scraper-priority-keys
Open

fix(devops): key locale list by position instead of scraped priority#760
Max Stegmeyer (mstegmeyer) wants to merge 1 commit into
trunkfrom
fix/locale-scraper-priority-keys

Conversation

@mstegmeyer

Copy link
Copy Markdown
Contributor

Problem

#757 rewrote all 648 lines of SupportedLocales.php without changing a single locale code. All 202 regions, their order and their locale lists are byte-for-byte identical — only the array keys shifted from 0-based to 1-based:

         'AL' => [
-            0 => 'en_US',
+            1 => 'en_US',
         ],

The scraper copied PayPal's "Language support priority" column verbatim into the array keys, and PayPal renumbered that column from 0-based to 1-based.

That is not cosmetic. LocaleCodeProvider::findMatchingSupportedLocale() falls back to SupportedLocales::LOCALES[$regionCode][0], so with 1-based keys the lookup misses for all 202 regions:

Input trunk #757
en_ZA en_US en_GB (default)
de_AT de_DE en_GB (default)
en_IN en_IN en_GB (default)
fr_CA en_US en_GB (default)

Every locale that PayPal does not support directly but that is mappable via its region would have silently fallen back to en_GB instead of the region's preferred locale.

Fix

The scraped priority is now only used to sort a region's locales; the array key is the resulting position. The generated output no longer depends on how PayPal happens to number that column.

While in there, the scraper no longer trusts the page layout blindly — it previously read fixed column offsets (eq(1), eq(2), eq(3)) and accepted whatever text it found:

  • column positions are resolved from the table header, so added, removed or reordered columns cannot shift the scraped values
  • region codes, locale codes and priorities are validated per row
  • a minimum region count guards against a truncated scrape

Each of these now fails swag:paypal:scrape:locales loudly, so the weekly job cannot write a broken class and open a pull request for it.

SupportedLocalesTest pins the invariant on the generated file, so a regression fails CI on the automated locale update PR rather than needing to be spotted by eye.

Verification

  • Ran the fixed command against the live PayPal page: the regenerated SupportedLocales.php is byte-for-byte identical to trunk, confirming chore: Update PayPal locales #757 carried no actual locale change.
  • Reverting SupportedLocales.php to chore: Update PayPal locales #757's version fails both the new SupportedLocalesTest::testRegionHasPrioritizedLocaleCodeList (Locale codes of region "AL" are not a 0-based list) and the pre-existing LocaleCodeProviderTest::testGetFormattedLocaleCodeWithFallbackLocale.
  • phpunit tests/Util/SupportedLocalesTest.php tests/Util/LocaleCodeProviderTest.php → 207 tests, 2175 assertions, green.
  • phpstan clean on the touched files; php-cs-fixer reports no fixable files.

Note on #757's CI

#757 was red, but on unrelated infrastructure flakiness (composer HTTP/2 504 while downloading dependencies), not on this bug — so the failure that mattered was never actually reported. The pre-existing LocaleCodeProviderTest would have caught it had the suite run.

The locale scraper copied PayPal's "Language support priority" column
verbatim into the array keys of `SupportedLocales::LOCALES`. PayPal
renumbered that column from 0-based to 1-based, so the next scrape turned
every region into a 1-based array without changing a single locale code.

That silently breaks `LocaleCodeProvider::findMatchingSupportedLocale()`,
which falls back to `LOCALES[$regionCode][0]`: for all 202 regions the
lookup would miss and every unsupported-but-mappable locale would fall
back to `en_GB` instead of the region's preferred locale.

The priority is now only used to sort a region's locales, and the key is
the resulting position. On top of that the scraper no longer trusts the
page layout blindly:

- column positions are resolved from the table header, so added, removed
  or reordered columns cannot shift the scraped values
- region codes, locale codes and priorities are validated per row
- a minimum region count guards against a truncated scrape

All of these now fail the command loudly instead of writing a broken
class and opening a pull request for it.

`SupportedLocalesTest` pins the invariant on the generated file, so a
regression fails CI on the automated locale update pull request.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd1a82c3d5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment on lines +143 to +144
if ($cells->count() <= \max($columns)) {
return null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject incomplete locale rows instead of dropping them

If PayPal renders an individual locale row with too few <td> cells, this silently filters that row out; with 202 current regions, losing a few regions or locale variants still leaves the result above MINIMUM_REGIONS, so the weekly command can successfully rewrite SupportedLocales.php with incomplete data. A three-cell row previously reached the missing eq(3)->text() and failed rather than producing a truncated list, so throw for malformed data rows instead of returning null.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant