Skip to content

Fix media suggestion order and run the QUnit tests in CI - #53

Draft
JeroenDeDauw wants to merge 3 commits into
masterfrom
fix/mediasuggester-follow-up
Draft

JeroenDeDauw wants to merge 3 commits into
masterfrom
fix/mediasuggester-follow-up

Conversation

@JeroenDeDauw

@JeroenDeDauw JeroenDeDauw commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Follows-up to #52

In Chrome and Edge, media suggestions starting with the typed term came out in reverse search order. For the term Foo and the search results Foo 1, Bar Foo, Foo 2, Foo 3, Baz foo, the suggester gave Foo 3, Foo 2, Foo 1, Bar Foo, Baz foo; it now gives Foo 1, Foo 2, Foo 3, Bar Foo, Baz foo. This PR also tests the API error response that #52 fixed, and repairs the PHPStan and Code style jobs, which had failed at Composer install since 2026-08-24.

Pending: a CI job for the QUnit tests, which CI never ran. Pushing it needs the workflow scope on this branch's token; nothing else here depends on it.

Human input

Goal and shape: goal from @JeroenDeDauw, shape Claude's.

Outcome: not reviewed by a human yet. Left for you: the order in Chrome on a wiki (matching is case-sensitive), and the QUnit job once it is in.

Claude's calls

  • Not discussed with @JeroenDeDauw:
    • The order rule: files starting with the term first, both groups in search order, as the AI review proposed.
    • The fix keeps the in-place sort, the smaller change, relying on Array.prototype.sort being stable, as it is in every browser MediaWiki supports.
    • Codesniffer goes to ^52, as in Bump mediawiki-codesniffer to ^52 to unblock Composer Maps#938; you now need PHP 8.3 to install the dev tools locally.
    • Adding the QUnit job: REL1_46 only, and core's runner with its Chrome target instead of npm run qunit, because in Firefox the order test passes even with the old comparator. It installs Wikibase from git, because the dist archive lacks the submodules the suggester needs.
  • Considered by Claude, omitted: other suggester issues, outside this follow-up and not filed. The JSONP request makes every search anonymous, so read-restricted wikis get no suggestions, and matching is case-sensitive and treats underscores and spaces differently.
  • Not verified: the order in a real browser, with or without the fix, and the QUnit job.
  • Where your judgment helps: whether an exact file name match should always come first, as the method's old doc comment said.

Changes

  • resources/jquery.ui.mediasuggester.js: the comparator returned -1 whenever its first argument matched, also when both did; it now returns 0 within a group. The doc comment now states the prefix rule.
  • tests/js/jquery.ui.mediasuggester.tests.js: the error-response test, and the order test, which replaces 'put matching file name on top of result list'. 'search integration' no longer depends on getting the API's own array back.
  • composer.json: codesniffer 46.0.0 pins squizlabs/php_codesniffer 3.11.3, which Composer blocks under advisory PKSA-rdkp-vv9z-mjkg; 52 pins the fixed 3.13.6.
Verification evidence
  • CI on e6a5e34: https://github.com/ProfessionalWiki/WikibaseLocalMedia/actions/runs/43115093969, 10 of 10 jobs green. Code style ran codesniffer 52.0.1 over 14 files with no findings, PHPStan 2.3.5 reported nothing, and PHPUnit passed on REL1_40 to REL1_46 and master.

  • QUnit in V8 (Node 24, jsdom, jQuery 3.7.1, jQuery UI and Wikibase's suggester from a MediaWiki 1.43 tree):

    Suggester search integration error response order
    this PR pass pass pass
    master pass pass fail: Foo 3, Foo 2, Foo 1, Bar Foo, Baz foo
    before Fix media suggester crash when search returns several files #52 pass fail: timeout fail: TypeError
    "contains the term" rule pass pass fail
    filter and concat instead of sort pass pass pass
  • AI review (pr-review with code-review, security-review, review-tests and a design pass): goal sound, design good-enough, no blocking findings. Its test findings are applied.

AI-authored — Claude Code, Opus 5.5 (max), on a Professional Wiki account

Both jobs have failed at their Composer install step since 2026-08-24.
mediawiki/mediawiki-codesniffer ^46.0.0 resolves only to 46.0.0, which pins
squizlabs/php_codesniffer 3.11.3, and Composer blocks that version under
security advisory PKSA-rdkp-vv9z-mjkg. Codesniffer 52 pins the fixed 3.13.6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JeroenDeDauw
JeroenDeDauw force-pushed the fix/mediasuggester-follow-up branch 2 times, most recently from 93acdbd to bbecd5d Compare November 11, 2026 21:27
JeroenDeDauw and others added 2 commits November 11, 2026 23:50
Before #52, a
response without a search list, such as an API error, left the search
pending, so the input kept its loading state. The test pins that search()
now resolves with no suggestions.

'search integration' now reads the requested term from the request, not
from a property set on the result array.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The comparator that puts files starting with the search term first
returned -1 whenever its first file matched, also when both files did,
which breaks the sort contract. V8 then reversed the matching files: for
the term Foo and the search results Foo 1, Bar foo, Foo 2, Foo 3, Baz foo,
Chrome and Edge listed Foo 3, Foo 2, Foo 1, Bar foo, Baz foo. Firefox
happened to keep the intended order.

The comparator now returns 0 within a group, so the stable sort keeps the
API's relevance order in both: Foo 1, Foo 2, Foo 3, Bar foo, Baz foo. The
new test replaces the three-hit ordering test, whose single match it covers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JeroenDeDauw
JeroenDeDauw force-pushed the fix/mediasuggester-follow-up branch from bbecd5d to e6a5e34 Compare November 11, 2026 22:50
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