close
Skip to content

[2.x] fix(package-manager): reject extensions incompatible with current Flarum major version#4412

Merged
imorland merged 2 commits into2.xfrom
im/fix-package-manager-incompatible-extension-install
Mar 7, 2026
Merged

[2.x] fix(package-manager): reject extensions incompatible with current Flarum major version#4412
imorland merged 2 commits into2.xfrom
im/fix-package-manager-incompatible-extension-install

Conversation

@imorland
Copy link
Copy Markdown
Member

@imorland imorland commented Mar 7, 2026

Fixes #4408

Summary

Extensions with "flarum/core": "*" (or other overly broad constraints like "^1.0") pass Composer's resolver on 2.x — because * technically satisfies ^2.0 — but the extension code was written for 1.x and breaks at runtime.

This adds a pre-install compatibility check via the Packagist p2 API before handing off to Composer:

  1. Fetch repo.packagist.org/p2/{package}.json to get the latest stable release's composer.json metadata.
  2. Check the flarum/core constraint using Composer\Semver:
    • Constraints that satisfy both 1.0.0 and 2.0.0 (e.g. *, >=1.0) are treated as too permissive and rejected — an extension genuinely targeting 2.x would use ^2.0.
    • Constraints that don't satisfy the running Flarum version (e.g. ^1.0) are rejected.
  3. Fails open — if Packagist is unreachable, the package has no stable releases, or there's no flarum/core requirement, the install proceeds and Composer's own resolver is the final gate.

The frontend already has a translation string for extension_incompatible_with_instance; the error handler is updated to catch the new KnownError type and display it as an alert.

Changes

  • RequireExtensionHandler — injects GuzzleHttp\Client, runs assertFlarumCompatibility() before Composer
  • ExtensionIncompatibleWithFlarumException — new KnownError with type extension_incompatible_with_instance
  • errorHandler.ts — handles extension_incompatible_with_instance directly (shows alert, closes modal)
  • RequireExtensionCompatibilityTest — 11 unit tests using GuzzleHttp\Handler\MockHandler, covering all constraint scenarios and fail-open cases

Test plan

  • Try installing a 1.x-only extension ("flarum/core": "^1.0") → error alert appears immediately, Composer never runs
  • Try installing an extension with "flarum/core": "*" → same result
  • Try installing a valid 2.x extension → installs normally
  • Run composer test:unit → all 11 unit tests green

🤖 Generated with Claude Code

imorland and others added 2 commits March 7, 2026 22:18
…rum major version

Extensions with '*' or overly broad flarum/core constraints (e.g. '^1.0')
pass Composer's resolver on 2.x but fail at runtime. Add a pre-install
check via the Packagist p2 API before invoking Composer.

- RequireExtensionHandler: fetch the package's latest stable release from
  repo.packagist.org/p2 and check its flarum/core constraint using
  Composer\Semver. Constraints satisfying both 1.x and 2.x (e.g. '*') are
  treated as too permissive and rejected. Fails open if Packagist is
  unreachable or the package has no stable releases.
- ExtensionIncompatibleWithFlarumException: new KnownError with type
  'extension_incompatible_with_instance' for a clean pre-Composer rejection.
- errorHandler.ts: handle 'extension_incompatible_with_instance' directly,
  showing the existing incompatibility translation and closing the modal.
- Unit tests: cover all constraint cases and fail-open scenarios using
  Guzzle's MockHandler — no real HTTP calls.

Fixes #4408

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@imorland imorland requested a review from a team as a code owner March 7, 2026 22:18
@imorland imorland changed the title fix(package-manager): reject extensions incompatible with current Flarum major version [2.x] fix(package-manager): reject extensions incompatible with current Flarum major version Mar 7, 2026
@imorland imorland added this to the 2.0.0-beta.8 milestone Mar 7, 2026
@imorland imorland merged commit 07b8891 into 2.x Mar 7, 2026
34 checks passed
@imorland imorland deleted the im/fix-package-manager-incompatible-extension-install branch March 7, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[2.x] Package manager shows/installs extensions incompatible with Flarum 2.x

2 participants