Page MenuHomePhabricator

CI tests fail with TypeError: array_map(): Argument #2 ($array) must be of type array, null given
Open, MediumPublic

Description

Background

We had a fatal which occurred if a menu item was created with just a href while working on adding the donate link to Vector 2022. This meant we needed to update Vector to defensively protect against fatals.

In Minerva adding the following hook will cause Minerva to fatal:

$wgHooks['SkinTemplateNavigation::Universal'][] = function ( $out, &$s ) {
	$s['user-menu']['x'] = [ 'icon' => 'x' ];
};

Going forward it would be useful for skins to be able to make valid assumptions about menu items e.g. they have text/html and if they have an icon they also have a href by adding some basic validation to skin menu items. For now, we do minimal changes to avoid having to review too many existing links.

Acceptance criteria

  • Check every menu item has a text or html key going forward (so it has a label)
  • If a menu has an icon, check it also has a href.

Original

When sending a patch to Quibble (which runs MediaWiki tests), we get an unrelated tests errors:

TypeError: array_map(): Argument #2 ($array) must be of type array, null given
4) MediaWiki\Tests\Actions\ActionEntryPointTest::testViewRedirectPage
Failed asserting that '[7cd4412cbfda768dd2ce920d] [no req]   TypeError: array_map(): Argument #2 ($array) must be of type array, null given

Backtrace:
from /workspace/src/skins/Vector/includes/Components/VectorComponentUserLinks.php(192)\n
#0 /workspace/src/skins/Vector/includes/Components/VectorComponentUserLinks.php(192): array_map()\n
#1 [internal function]: MediaWiki\Skins\Vector\Components\VectorComponentUserLinks::MediaWiki\Skins\Vector\Components\{closure}()\n
#2 /workspace/src/skins/Vector/includes/Components/VectorComponentUserLinks.php(188): array_map()\n
#3 [internal function]: MediaWiki\Skins\Vector\Components\VectorComponentUserLinks::MediaWiki\Skins\Vector\Components\{closure}()\n
#4 /workspace/src/skins/Vector/includes/Components/VectorComponentUserLinks.php(176): array_map()\n
#5 /workspace/src/skins/Vector/includes/Components/VectorComponentUserLinks.php(153): MediaWiki\Skins\Vector\Components\VectorComponentUserLinks::updateMenuItemStyles()\n
#6 /workspace/src/skins/Vector/includes/Components/VectorComponentUserLinks.php(362): MediaWiki\Skins\Vector\Components\VectorComponentUserLinks->getMenus()\n
#7 /workspace/src/skins/Vector/includes/SkinVector22.php(523): MediaWiki\Skins\Vector\Components\VectorComponentUserLinks->getTemplateData()\n
#8 /workspace/src/includes/Skin/SkinMustache.php(51): MediaWiki\Skins\Vector\SkinVector22->getTemplateData()\n
#9 /workspace/src/includes/Skin/SkinTemplate.php(172): MediaWiki\Skin\SkinMustache->generateHTML()\n
#10 /workspace/src/includes/Skin/Skin.php(670): MediaWiki\Skin\SkinTemplate->outputPage()\n
#11 /workspace/src/includes/Output/OutputPage.php(3313): MediaWiki\Skin\Skin->outputPageFinal()\n
#12 /workspace/src/includes/Actions/ActionEntryPoint.php(162): MediaWiki\Output\OutputPage->output()\n
#13 /workspace/src/includes/MediaWikiEntryPoint.php(180): MediaWiki\Actions\ActionEntryPoint->execute()\n
#14 /workspace/src/tests/phpunit/includes/Actions/ActionEntryPointTest.php(497): MediaWiki\MediaWikiEntryPoint->run()\n
#15 /workspace/src/vendor/phpunit/phpunit/src/Framework/TestCase.php(1617): MediaWiki\Tests\Actions\ActionEntryPointTest->testViewRedirectPage()\n
#16 /workspace/src/vendor/phpunit/phpunit/src/Framework/TestCase.php(1223): PHPUnit\Framework\TestCase->runTest()\n
#17 /workspace/src/vendor/phpunit/phpunit/src/Framework/TestResult.php(729): PHPUnit\Framework\TestCase->runBare()\n
#18 /workspace/src/vendor/phpunit/phpunit/src/Framework/TestCase.php(973): PHPUnit\Framework\TestResult->run()\n
#19 /workspace/src/vendor/phpunit/phpunit/src/Framework/TestSuite.php(685): PHPUnit\Framework\TestCase->run()\n
#20 /workspace/src/vendor/phpunit/phpunit/src/Framework/TestSuite.php(685): PHPUnit\Framework\TestSuite->run()\n
#21 /workspace/src/vendor/phpunit/phpunit/src/Framework/TestSuite.php(685): PHPUnit\Framework\TestSuite->run()\n
#22 /workspace/src/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(651): PHPUnit\Framework\TestSuite->run()\n
#23 /workspace/src/vendor/phpunit/phpunit/src/TextUI/Command.php(146): PHPUnit\TextUI\TestRunner->run()\n
#24 /workspace/src/vendor/phpunit/phpunit/src/TextUI/Command.php(99): PHPUnit\TextUI\Command->run()\n
#25 /workspace/src/vendor/phpunit/phpunit/phpunit(107): PHPUnit\TextUI\Command::main()\n
#26 /workspace/src/vendor/bin/phpunit(122): include(string)\n
#27 {main}\n

Event Timeline

Patch recently merged in mediawiki/skins/Vector:

https://gerrit.wikimedia.org/r/c/mediawiki/skins/Vector/+/1269718 Re-add p-personal id to the user menu
https://gerrit.wikimedia.org/r/c/mediawiki/skins/Vector/+/1266338 Clean up anon editor links code and unused Hooks.php code for T420964.

The first adds an id to an element, so unlikely.
The second does touch VectorComponentUserLinks.

After a quick check on https://gerrit.wikimedia.org/r/q/project:mediawiki/core+status:open that fails for any patch so I will revert the Vector patch. To be investigated is why CI did not catch it.

Change #1269962 had a related patch set uploaded (by Hashar; author: Hashar):

[mediawiki/skins/Vector@master] Revert "Clean up anon editor links code and unused Hooks.php code"

https://gerrit.wikimedia.org/r/1269962

Change #1269962 merged by jenkins-bot:

[mediawiki/skins/Vector@master] Revert "Clean up anon editor links code and unused Hooks.php code"

https://gerrit.wikimedia.org/r/1269962

hashar claimed this task.

I am closing this since CI is working again. I have mentioned the revert and the error on T420964 for follow up actions.

hashar triaged this task as Unbreak Now! priority.Apr 10 2026, 9:41 AM

I have not looked at why the patch passed tests and got merged and then eventually led to other workflows to suddenly fail.

ActionEntryPointTest is a MediaWikiIntegrationTestCase. It sounds like some hook is being used incorrectly that is causing errors in Minerva and Vector 2022. T422861: PHP Warning: Undefined array key "href" sounds related.

I don't think reverting this is enough without understanding the cause.

Change #1270073 had a related patch set uploaded (by Jdlrobson; author: Jdlrobson):

[mediawiki/core@master] Ensure consistency across links data structure

https://gerrit.wikimedia.org/r/1270073

@hashar it looks like the integration test varies on the result of $services->getTempUserConfig(); (and configuration AutoCreateTempUser) which might explain why it tested fine in Vector but not in core. I suspect something is setting AutoCreateTempUser as a side effect?

Jdlrobson-WMF lowered the priority of this task from Unbreak Now! to Medium.Mon, Apr 13, 8:19 PM

I've reapplied the Vector code now it has additional resilience.

I've suggested adding some code that validates the menu object after running the hook to allow skins to make sensible assumptions about the format going forward.
This will also help us debug T422861: PHP Warning: Undefined array key "href". e.g. https://gerrit.wikimedia.org/r/1270073 - this will make it easier to debug if it ever happens again.

I have not looked at why the patch passed tests and got merged and then eventually led to other workflows to suddenly fail.

It seems the tests are running in a pre-temporary accounts state as well as temporary accounts state so I think there is an additional question here for our continuous integration. How is that possible? I think https://gerrit.wikimedia.org/r/1270073 might help narrowing down the issue.

I only just noticed this was marked UBN so reducing priority to medium given the immediate issue has now been addressed.

Change #1270550 had a related patch set uploaded (by Jdlrobson; author: Jdlrobson):

[mediawiki/extensions/GrowthExperiments@master] Don't set href for a link that has been unset

https://gerrit.wikimedia.org/r/1270550

Change #1270550 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@master] Don't set href for a link that has been unset

https://gerrit.wikimedia.org/r/1270550

Change #1275543 had a related patch set uploaded (by Jdlrobson; author: Jdlrobson):

[mediawiki/extensions/GrowthExperiments@wmf/1.46.0-wmf.24] Don't set href for a link that has been unset

https://gerrit.wikimedia.org/r/1275543

Change #1275543 abandoned by Jdlrobson:

[mediawiki/extensions/GrowthExperiments@wmf/1.46.0-wmf.24] Don't set href for a link that has been unset

Reason:

I've been unable to replicate this, so not seeing the value in backporting any more. I'll monitor this as it rolls out on the train.

https://gerrit.wikimedia.org/r/1275543

Jdlrobson-WMF updated the task description. (Show Details)