Page MenuHomePhabricator

WikimediaBadges tests fail when WikibaseClient is not loaded
Open, Needs TriagePublic

Description

The WikimediaBadges extension does not require WikibaseClient but tests are failing when it is not loaded:

17:01:01 1) Error
17:01:01 The data provider specified for WikimediaBadges\Tests\WikibaseClientSiteLinksForItemHookHandlerTest::testDoAddToSidebar is invalid.
17:01:01 Error: Class "Wikibase\DataModel\SiteLink" not found
17:01:01 /workspace/src/extensions/WikimediaBadges/tests/phpunit/includes/WikibaseClientSiteLinksForItemHookHandlerTest.php:72
17:01:01 /workspace/src/tests/phpunit/suites/ExtensionsTestSuite.php:37
17:01:01 /workspace/src/tests/phpunit/suites/ExtensionsTestSuite.php:46
17:01:01 
17:01:01 2) WikimediaBadges\Tests\WikibaseClientSiteLinksForItemHookHandlerTest::testDoAddToSidebar_disabled
17:01:01 Error: Interface "Wikibase\Client\Hooks\WikibaseClientSiteLinksForItemHook" not found
17:01:01 
17:01:01 /workspace/src/extensions/WikimediaBadges/includes/WikibaseClientSiteLinksForItemHookHandler.php:31
17:01:01 /workspace/src/includes/AutoLoader.php:183
17:01:01 /workspace/src/extensions/WikimediaBadges/tests/phpunit/includes/WikibaseClientSiteLinksForItemHookHandlerTest.php:224
Logs generated by test
17:01:01 
17:01:01 3) WikimediaBadges\Tests\WikibaseClientSiteLinksForItemHookHandlerTest::testAddToSidebar
17:01:01 Error: Class "WikimediaBadges\WikibaseClientSiteLinksForItemHookHandler" not found
17:01:01 
17:01:01 /workspace/src/extensions/WikimediaBadges/tests/phpunit/includes/WikibaseClientSiteLinksForItemHookHandlerTest.php:241

This test a hook provided by WikibaseClient and the test should be skipped when the extension is not loaded.

Event Timeline

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

[mediawiki/extensions/WikimediaBadges@master] tests: skip WikibaseClient tests when it is not loaded

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

I think this is expected? Extension:WikimediaBadges doesn’t directly say that it depends on WikibaseClient (maybe it should), but it “provides default themes to display badges generated by Extension:Wikibase Client”, and as far as I can tell from the code, it does nothing useful if WikibaseClient isn’t available. I doubt there’s a reason to install this extension without WikibaseClient.

Thanks! Then I guess we can make WikibaseClient a requirement in extension.json. And indeed when I look at mediawiki-config:

wmf-config/Wikibase.php
// Load Client extensions
if ( !empty( $wmgUseWikibaseClient ) ) {
    if ( !empty( $wmgUseWikibaseWikimediaBadges ) ) {
        wfLoadExtension( 'WikimediaBadges' );
    }

Thus I guess I can repurpose my patch to use a require :]

And that’s probably not going to work, as I mentioned in T410053#11371510:

it can’t be required in extension.json due to MediaWiki restrictions (compare T258822, T407355, EntitySchema change).

But I guess we can see what CI says.

And CI failed! Even though Wikibase has been successfully cloned, the installer can't find WikibaseClient or WikibaseRepository:

$ php maintenance/install.php --with-extensions
Error: A dependency error was encountered while installing the extension "WikimediaBadges": Could not find the registration file for the extension "WikibaseClient"

The reason is when given WikibaseClient as an extension name, it looks for an extension registry file named extensions/WikibaseClient/extension.json when the actual one is nested inside Wikibase and is extensions/Wikibase/extension-client.json.

Because I don't think we will ever split Wikibase in two standalone repository, we can do a remap in the installer to give it the proper filenames.

Then can be tested using:

	public function testIsLoadedWikibaseClient() {
		$this->assertTrue( ExtensionRegistry::getInstance()->isLoaded( 'WikibaseClient' ) );
	}
	public function testIsLoadedWikibaseRepository() {
		$this->assertTrue( ExtensionRegistry::getInstance()->isLoaded( 'WikibaseRepository' ) );
	}

With:

LocalSettings.php
$wgEnableWikibaseRepo = false;
$wgEnableWikibaseClient = true;
require_once "extensions/Wikibase/Wikibase.php"

Which yields:

$ ./phpunit extensions/WikimediaBadges --testdox --filter isLoaded
Wikibase Loading
 ✔ Is loaded wikibase client
 ✘ Is loaded wikibase repository

   ├ Failed asserting that false is true.

   ╵ extensions/WikimediaBadges/tests/phpunit/includes/WikibaseLoadingTest.php

Which I guess is what I expect.

I think that will also solve T258822 and its subtask by making it possible to express a requirement against the Wikibase client and/or the repository

we can do a remap in the installer to give it the proper filenames.

That sounds like option 1 of T258822#6373759 to me, which nobody in the subsequent discussion seemed to be in favor of (as far as I can tell now). If I understand correctly, @Ladsgroup wanted to go for T263101 instead.

I have added a mapping for the MediaWiki installer with https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1205175 , made my WikimediaBadges patch to depend on it and we will see what happens. I will then follow up on T258822.

My use case is to have install.php --with-extensions to work. Given the discussions on T258822 are from 5 years ago, I guess I will expedite with whatever is the easiest/simplest :]