Skip to content

Fix tests and CI#65

Merged
JeroenDeDauw merged 6 commits into
masterfrom
fix-tests
Feb 24, 2025
Merged

Fix tests and CI#65
JeroenDeDauw merged 6 commits into
masterfrom
fix-tests

Conversation

@alistair3149

@alistair3149 alistair3149 commented Feb 24, 2025

Copy link
Copy Markdown
Member

Key changes

  • Fix tests that are broken on 1.43
  • Add CI for MW 1.39+ and PHP 8.1+
  • Drop tests for MW 1.35
  • Refactor install MW step to use the same implementation as other repo
  • Update GitHub Actions versions in CI

Summary by CodeRabbit

  • New Features
    • Introduced an automated installation tool that streamlines MediaWiki setup, including extension configuration and enhanced debugging features.
  • Bug Fixes
    • Revised error message formatting for media embedding issues, ensuring users receive clearer, more consistent feedback when problems occur.
  • Documentation
    • Updated platform requirements to reflect compatibility with newer PHP (up to 8.3) and MediaWiki (up to 1.43) versions.
  • Improvements
    • Enhanced CI pipeline flexibility with expanded version support and improved error handling.

@alistair3149
alistair3149 marked this pull request as ready for review February 24, 2025 21:09
@coderabbitai

coderabbitai Bot commented Feb 24, 2025

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This update revises the CI pipeline and test configuration. The CI workflow now expands the test matrix to cover more MediaWiki versions, improves caching with updated action versions, and adjusts test conditions and job properties. A new installation script automates MediaWiki setup including dependency installation and error reporting configuration. In addition, the PHPUnit configuration is streamlined by removing the “System” testsuite. Several tests are enhanced by adding group annotations, updating assertion checks, and refining method parameter types. The parser test suite also now reflects updated error message HTML structures and versioning.

Changes

File(s) Change Summary
.github/workflows/ci.yml Updated CI configuration: expanded test matrix (additional MediaWiki versions, PHP pairing, and experimental flag), added continue-on-error, upgraded caching actions to v4, changed checkout and installation steps, and modified conditions for PHPUnit, parser, static-analysis, and code-style jobs.
.github/workflows/installMediaWiki.sh New script that automates MediaWiki installation from a specified branch, handles dependency installation via Composer, performs SQLite database setup, configures detailed error reporting, and loads a specified extension with composer merging.
phpunit.xml.dist Removed the "System" testsuite declaration, leaving only "Unit" and "Integration" suites.
tests/Integration/BitbucketFunctionIntegrationTest.php, tests/Integration/EmbedFunctionIntegrationTest.php Added @group Database annotation in both Integration test files and updated assertions in the EmbedFunction test to use getCategoryNames() with a simple array format instead of an associative array.
tests/TestEnvironment.php Updated the parse method signature to accept a nullable Title parameter (?Title $contextPage = null), enhancing input flexibility.
tests/Unit/Adapters/ParserFunctionEmbedPresenterTest.php Revised error-checking in the testShowErrorBuildsErrorHtml method by replacing assertStringContainsEither with an assertThat check employing logicalOr to allow one of three expected error indicators.
tests/parser/parserTests.txt Incremented the version number from 2 to 3 and updated the HTML structure of error messages for tests covering non-existing files, invalid Bitbucket URLs, and disallowed file types.
README.md Updated platform requirements: minimum PHP version remains at 8.0, maximum tested version updated to 8.3, and MediaWiki version requirement updated to a maximum tested version of 1.43.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between accb6d8 and 9fb1a14.

📒 Files selected for processing (1)
  • tests/parser/parserTests.txt (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/parser/parserTests.txt

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🧹 Nitpick comments (1)
.github/workflows/installMediaWiki.sh (1)

17-23: Consider using environment variables for sensitive data.

The database credentials and admin password are hardcoded. Consider using environment variables for sensitive data.

+DB_USER="${DB_USER:-root}"
+DB_NAME="${DB_NAME:-mw}"
+ADMIN_PASS="${ADMIN_PASS:-AdminPassword}"
+
 php maintenance/install.php \
 	--dbtype sqlite \
-	--dbuser root \
-	--dbname mw \
+	--dbuser "$DB_USER" \
+	--dbname "$DB_NAME" \
 	--dbpath "$(pwd)" \
 	--scriptpath="" \
-	--pass AdminPassword WikiName AdminUser
+	--pass "$ADMIN_PASS" WikiName AdminUser
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f9d144d and b35b6ac.

📒 Files selected for processing (8)
  • .github/workflows/ci.yml (9 hunks)
  • .github/workflows/installMediaWiki.sh (1 hunks)
  • phpunit.xml.dist (0 hunks)
  • tests/Integration/BitbucketFunctionIntegrationTest.php (1 hunks)
  • tests/Integration/EmbedFunctionIntegrationTest.php (2 hunks)
  • tests/TestEnvironment.php (1 hunks)
  • tests/Unit/Adapters/ParserFunctionEmbedPresenterTest.php (1 hunks)
  • tests/parser/parserTests.txt (4 hunks)
💤 Files with no reviewable changes (1)
  • phpunit.xml.dist
✅ Files skipped from review due to trivial changes (1)
  • tests/Integration/BitbucketFunctionIntegrationTest.php
🔇 Additional comments (33)
tests/TestEnvironment.php (1)

24-24: LGTM! Improved type declaration.

The change to use the explicit nullable type ?Title instead of the implicit Title = null makes the code more type-safe and self-documenting.

tests/Integration/EmbedFunctionIntegrationTest.php (2)

13-13: LGTM! Added database group annotation.

The @group Database annotation properly categorizes this test as requiring database access.


64-65: LGTM! Updated category assertions to use new API.

The assertions have been correctly updated to use getCategoryNames() instead of getCategories(), aligning with MediaWiki's API changes.

Also applies to: 69-69

tests/Unit/Adapters/ParserFunctionEmbedPresenterTest.php (1)

40-47: LGTM! Enhanced error message assertions.

The test now properly handles multiple error message formats across different MediaWiki versions using PHPUnit's built-in assertThat with logicalOr.

tests/parser/parserTests.txt (4)

1-1: Version Update Verification

The version indicator has been updated to "Version 3". Please ensure that all related documentation, configurations, and test references are updated to reflect this new version.


32-32: Updated Error Message for Missing File

The error markup for the embed function when a file is not found now follows the new HTML structure. Confirm that the frontend styling and any client-side processing correctly interpret this format.


42-42: Updated Error Message for Invalid Bitbucket URL

The HTML structure for the Bitbucket error message has been updated and appears consistent with the new design standards. Please verify that these changes integrate seamlessly with your overall error handling.


52-52: Updated Error Message for Disallowed File Extension

The error message for embedding files with disallowed extensions now uses the updated HTML format. Make sure that any integration tests or UI components that rely on this output are adjusted accordingly.

.github/workflows/ci.yml (25)

10-10: Continue-on-Error Configuration in Test Job

The continue-on-error: ${{ matrix.experimental }} property now lets experimental matrix configurations bypass some failures. Double-check that this behavior is intentional to avoid masking genuine issues during CI runs.


15-33: Matrix Configuration for CI Jobs

The test job’s matrix now includes multiple MediaWiki versions (REL1_39 through master) with corresponding PHP versions and an experimental flag. Please verify that the PHP version assignments and the use of the experimental flag precisely match the project's compatibility and testing objectives.


49-57: Updated MediaWiki Cache Action

The workflow now uses actions/cache@v4 for caching the MediaWiki installation, with explicit exclusions for extensions and vendor directories. Confirm that these cache paths meet your build and performance expectations.


59-64: Updated Composer Cache Action

Composer caching has been updated to use actions/cache@v4. This should help speed up dependency resolution; please ensure that the cache key (composer-php${{ matrix.php }}) remains unique per PHP version.


65-68: Usage of Checkout Action V4 for EarlyCopy

The repository is now checked out using actions/checkout@v4 into the EarlyCopy directory. Verify that all subsequent steps referencing this path correctly locate the intended files.


69-73: Refactored MediaWiki Installation Step

The installation process now executes via the custom script (installMediaWiki.sh) located in the EarlyCopy directory. Please check that the specified working directory (working-directory: ~) is appropriate and that the script completes successfully for all defined MediaWiki versions.


74-77: Extensions Repository Checkout

The subsequent checkout for the ExternalContent extension (to mediawiki/extensions/ExternalContent) appears correctly configured. Ensure that this path remains consistent with your project structure.


90-91: Conditional Execution for Code Coverage

The code coverage steps are now executed conditionally when matrix.mw == 'master'. This is a good strategy to limit resource-intensive operations to the master branch, but please confirm that this is the desired behavior.


97-99: Parser Tests Conditional Execution

The parser tests are set to run only if matrix.mw is greater than or equal to "REL1_43". Since this comparison is string-based, please verify that the lexicographical ordering behaves as intended across all matrix entries.


101-110: Static Analysis Job Matrix Setup

The static-analysis job targets MediaWiki version 'REL1_43' with PHP 8.3, which appears to be a streamlined configuration for code analysis. Confirm that this subset adequately covers your static analysis needs.


124-132: Static Analysis MediaWiki Cache

The cache setup for MediaWiki in the static-analysis job correctly uses actions/cache@v4 with the key mw_static_analysis. Ensure that this key remains distinct from other cache keys to prevent conflicts.


134-138: Static Analysis Composer Cache

The Composer cache configuration for static-analysis is updated to use version v4 with a unique cache key. This should help maintain performance consistency during the analysis.


140-143: Static Analysis Repository Checkout

Retrieving the repository into the EarlyCopy directory for the static-analysis job is consistent with the test job process. Please verify that the paths used throughout remain aligned.


144-148: Static Analysis MediaWiki Installation

Similar to the test job, the static-analysis job installs MediaWiki using the custom installation script from the EarlyCopy directory. Confirm that the working directory configuration and script execution are functioning as expected.


149-152: Static Analysis Extensions Checkout

The step checking out the ExternalContent extension for the static-analysis job appears correctly structured. No issues are detected.


159-161: PHPStan Analysis Configuration

The PHPStan step is configured to run with error formatting piped through cs2pr. Verify that the PHPStan and cs2pr versions used are compatible and that the output meets your integration requirements.


162-163: Psalm Analysis Configuration

The Psalm step employs the --shepherd and --stats options. Confirm these flags provide the desired level of detail for your static analysis reporting.


166-174: Code Style Job Matrix Setup

The code-style job now targets MediaWiki version 'REL1_43' with PHP 8.3. Validate that these settings are sufficient for enforcing your project’s coding standards.


189-197: Code Style MediaWiki Cache

The caching configuration for MediaWiki in the code-style job leverages actions/cache@v4 with a cache key consistent with static analysis. This setup looks solid—ensure that it aligns with your caching strategy.


199-204: Code Style Composer Cache

The Composer cache for the code-style job is updated similarly and uses a distinct cache key (composer_static_analysis), which should help avoid collisions.


205-208: Code Style Repository Checkout

The repository checkout into the EarlyCopy directory is repeated here for the code-style job. Please verify that this usage is consistent with subsequent path references.


209-213: Code Style MediaWiki Installation

The installation of MediaWiki via the custom script in the EarlyCopy directory is now part of the code-style job as well. Ensure that the working-directory configuration (~) is intended and that the installation process is robust across all conditions.


214-217: Code Style Extensions Checkout

The step for checking out the ExternalContent extension is consistent with previous jobs. Confirm that the destination path remains valid.


218-223: Composer Configuration for Code Style

The Composer configuration and installation steps in the code-style job are straightforward and follow best practices. No issues detected.


224-225: PHP CodeSniffer Execution

Running PHPCS with the -p -s flags is an effective way to enforce and display coding standards. Ensure that the defined standards align with your project requirements.

Comment on lines +8 to +11
wget "https://github.com/wikimedia/mediawiki/archive/refs/heads/$MW_BRANCH.tar.gz" -nv

tar -zxf $MW_BRANCH.tar.gz
mv mediawiki-$MW_BRANCH mediawiki

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for download and extraction.

The script should check for successful download and extraction of MediaWiki.

-wget "https://github.com/wikimedia/mediawiki/archive/refs/heads/$MW_BRANCH.tar.gz" -nv
-
-tar -zxf $MW_BRANCH.tar.gz
-mv mediawiki-$MW_BRANCH mediawiki
+if ! wget "https://github.com/wikimedia/mediawiki/archive/refs/heads/$MW_BRANCH.tar.gz" -nv; then
+  echo "Failed to download MediaWiki"
+  exit 1
+fi
+
+if ! tar -zxf "$MW_BRANCH.tar.gz"; then
+  echo "Failed to extract MediaWiki"
+  exit 1
+fi
+mv "mediawiki-$MW_BRANCH" mediawiki
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
wget "https://github.com/wikimedia/mediawiki/archive/refs/heads/$MW_BRANCH.tar.gz" -nv
tar -zxf $MW_BRANCH.tar.gz
mv mediawiki-$MW_BRANCH mediawiki
if ! wget "https://github.com/wikimedia/mediawiki/archive/refs/heads/$MW_BRANCH.tar.gz" -nv; then
echo "Failed to download MediaWiki"
exit 1
fi
if ! tar -zxf "$MW_BRANCH.tar.gz"; then
echo "Failed to extract MediaWiki"
exit 1
fi
mv "mediawiki-$MW_BRANCH" mediawiki

Comment on lines +5 to +6
MW_BRANCH=$1
EXTENSION_NAME=$2

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add input validation for command line arguments.

The script should validate that both required arguments are provided and non-empty.

-MW_BRANCH=$1
-EXTENSION_NAME=$2
+if [ -z "$1" ] || [ -z "$2" ]; then
+  echo "Usage: $0 <mw_branch> <extension_name>"
+  exit 1
+fi
+
+MW_BRANCH="$1"
+EXTENSION_NAME="$2"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
MW_BRANCH=$1
EXTENSION_NAME=$2
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 <mw_branch> <extension_name>"
exit 1
fi
MW_BRANCH="$1"
EXTENSION_NAME="$2"

echo '$wgShowDBErrorBacktrace = true;' >> LocalSettings.php
echo '$wgDevelopmentWarnings = true;' >> LocalSettings.php

echo 'wfLoadExtension( "'$EXTENSION_NAME'" );' >> LocalSettings.php

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use safer string interpolation for extension loading.

The current string concatenation could be unsafe if $EXTENSION_NAME contains special characters.

-echo 'wfLoadExtension( "'$EXTENSION_NAME'" );' >> LocalSettings.php
+printf 'wfLoadExtension( "%s" );\n' "$EXTENSION_NAME" >> LocalSettings.php
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
echo 'wfLoadExtension( "'$EXTENSION_NAME'" );' >> LocalSettings.php
printf 'wfLoadExtension( "%s" );\n' "$EXTENSION_NAME" >> LocalSettings.php

@coderabbitai coderabbitai 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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
README.md (1)

102-103: Update Platform Requirements and Unordered List Style

The updated platform requirements accurately reflect that the extension now supports PHP 8.0 or later (tested up to 8.3) and MediaWiki 1.35 or later (tested up to 1.43 and master). However, note that the unordered list items on these lines use asterisks (*) while other sections (e.g., line 15) use dashes (-) for list markers. For consistency with the markdown style guidelines (as also flagged by static analysis), please consider updating these lines to use dashes.

A potential diff for this change:

-* [PHP] 8.0 or later (tested up to 8.3)
-* [MediaWiki] 1.35 or later (tested up to 1.43 and master)
+ - [PHP] 8.0 or later (tested up to 8.3)
+ - [MediaWiki] 1.35 or later (tested up to 1.43 and master)
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

102-102: Unordered list style
Expected: dash; Actual: asterisk

(MD004, ul-style)


103-103: Unordered list style
Expected: dash; Actual: asterisk

(MD004, ul-style)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b35b6ac and 4626d7f.

📒 Files selected for processing (1)
  • README.md (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
README.md

102-102: Unordered list style
Expected: dash; Actual: asterisk

(MD004, ul-style)


103-103: Unordered list style
Expected: dash; Actual: asterisk

(MD004, ul-style)

@JeroenDeDauw
JeroenDeDauw merged commit 6dbf932 into master Feb 24, 2025
@JeroenDeDauw
JeroenDeDauw deleted the fix-tests branch February 24, 2025 23:21
Comment thread README.md
* [PHP] 8.0 or later (tested up to 8.1)
* [MediaWiki] 1.35 or later (tested up to 1.39 and master)
* [PHP] 8.0 or later (tested up to 8.3)
* [MediaWiki] 1.35 or later (tested up to 1.43 and master)

@malberts malberts Feb 25, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we're dropping CI for 1.35, then we should remove support for it completely. Otherwise, we have no way to verify that 1.35 works with any new changes (which is not worth spending time on since it's EOL anwyay).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes

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.

3 participants