Skip to content

Stabilize tests with HTTP request mocking#86

Merged
swissspidy merged 7 commits intomainfrom
copilot/fix-flaky-audio-provider-tests
Feb 11, 2026
Merged

Stabilize tests with HTTP request mocking#86
swissspidy merged 7 commits intomainfrom
copilot/fix-flaky-audio-provider-tests

Conversation

Copy link
Contributor

Copilot AI commented Feb 11, 2026

Six test scenarios were making real HTTP requests to audio.com, causing intermittent failures when the service was unreachable or slow.

Changes

Replaced real HTTP requests with mocked responses using the WP-CLI test framework's HTTP mocking utility:

  • features/add-oembed-provider.feature: 3 scenarios
    • Match an oEmbed provider
    • Discover a provider with limited response size
    • Only match an oEmbed provider if discover
  • features/provider.feature: 3 scenarios (same names)

Each mock returns an HTML page with valid oEmbed discovery <link> tags:

Given that HTTP requests to https://audio.com/audio-com/collections/ambient-focus will respond with:
  """
  HTTP/1.1 200
  Content-Type: text/html

  <!DOCTYPE html>
  <html>
  <head>
    <link rel="alternate" type="application/json+oembed" href="https://audio.com/oembed?format=json&url=..." title="...">
    <link rel="alternate" type="text/xml+oembed" href="https://audio.com/oembed?format=xml&url=..." title="...">
  </head>
  ...
  </html>
  """

This eliminates external service dependencies while maintaining test coverage for oEmbed discovery functionality.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.wordpress.org
    • Triggering command: /usr/bin/php /usr/bin/php /home/REDACTED/work/embed-command/embed-command/vendor/wp-cli/wp-cli/bin/../php/boot-fs.php core download --force --path=/tmp/wp-cli-test-core-download-cache (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Flaky audio provider tests</issue_title>
<issue_description>```
001 Scenario: Match an oEmbed provider # features/add-oembed-provider.feature:130
Then the return code should be 0 # features/add-oembed-provider.feature:142
$ wp embed provider match https://audio.com/audio-com/collections/ambient-focus

    Error: No oEmbed provider found for given URL.
    cwd: /tmp/wp-cli-test-run--698bf0335d1073.98861007/
    run time: 0.38755297660828
    exit status: 1 (RuntimeException)

002 Scenario: Discover a provider with limited response size # features/add-oembed-provider.feature:198
When I run wp embed provider match https://audio.com/audio-com/collections/ambient-focus # features/add-oembed-provider.feature:199
$ wp embed provider match https://audio.com/audio-com/collections/ambient-focus

    Error: No oEmbed provider found for given URL.
    cwd: /tmp/wp-cli-test-run--698bf035387a76.64233588/
    run time: 0.39840817451477
    exit status: 1 (RuntimeException)

003 Scenario: Only match an oEmbed provider if discover # features/add-oembed-provider.feature:245
Then the return code should be 0 # features/add-oembed-provider.feature:256
$ wp embed provider match https://audio.com/audio-com/collections/ambient-focus

    Error: No oEmbed provider found for given URL.
    cwd: /tmp/wp-cli-test-run--698bf035c7e016.36044166/
    run time: 0.37659192085266
    exit status: 1 (RuntimeException)

004 Scenario: Match an oEmbed provider # features/provider.feature:131
Then the return code should be 0 # features/provider.feature:143
$ wp embed provider match https://audio.com/audio-com/collections/ambient-focus

    Error: No oEmbed provider found for given URL.
    cwd: /tmp/wp-cli-test-run--698bf036b19877.74411875/
    run time: 0.48289489746094
    exit status: 1 (RuntimeException)

005 Scenario: Discover a provider with limited response size # features/provider.feature:199
When I run wp embed provider match https://audio.com/audio-com/collections/ambient-focus # features/provider.feature:200
$ wp embed provider match https://audio.com/audio-com/collections/ambient-focus

    Error: No oEmbed provider found for given URL.
    cwd: /tmp/wp-cli-test-run--698bf037b5d8e1.11950562/
    run time: 0.39745402336121
    exit status: 1 (RuntimeException)

006 Scenario: Only match an oEmbed provider if discover # features/provider.feature:246
Then the return code should be 0 # features/provider.feature:257
$ wp embed provider match https://audio.com/audio-com/collections/ambient-focus

    Error: No oEmbed provider found for given URL.
    cwd: /tmp/wp-cli-test-run--698bf038514275.81959407/
    run time: 0.34361886978149
    exit status: 1 (RuntimeException)

We should stabilize them and speed them up by using our request mocking util (`Given that HTTP requests to  ... will respond with`)</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@github-actions github-actions bot added command:embed-provider-match Related to 'embed provider match' command scope:testing Related to testing labels Feb 11, 2026
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix flaky audio provider tests in embed functionality Stabilize audio provider tests with HTTP request mocking Feb 11, 2026
Copilot AI requested a review from swissspidy February 11, 2026 12:33
@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy swissspidy changed the title Stabilize audio provider tests with HTTP request mocking Stabilize tests with HTTP request mocking Feb 11, 2026
@swissspidy swissspidy added this to the 2.1.1 milestone Feb 11, 2026
@swissspidy swissspidy marked this pull request as ready for review February 11, 2026 14:10
@swissspidy swissspidy requested a review from a team as a code owner February 11, 2026 14:10
Copilot AI review requested due to automatic review settings February 11, 2026 14:10
@swissspidy swissspidy merged commit fe96d57 into main Feb 11, 2026
52 of 53 checks passed
@swissspidy swissspidy deleted the copilot/fix-flaky-audio-provider-tests branch February 11, 2026 14:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to stabilize the Behat acceptance tests by eliminating flaky, real HTTP requests (notably to audio.com) and replacing them with deterministic mocked responses within the WP-CLI test framework.

Changes:

  • Added HTTP request mocking for audio.com oEmbed discovery in features/provider.feature.
  • Consolidated provider scenarios by removing features/add-oembed-provider.feature and moving relevant scenarios into features/provider.feature.
  • Removed multiple @require-wp-* scenario gates from features/fetch.feature and features/cache.feature.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
features/provider.feature Adds mocked audio.com discovery responses, moves provider scenarios here, and adjusts the limited-response-size scenario.
features/add-oembed-provider.feature Deleted (scenarios appear consolidated into features/provider.feature).
features/fetch.feature Removes @require-wp-* gating across scenarios.
features/cache.feature Removes @require-wp-4.9 gating on cache-find scenarios.
Comments suppressed due to low confidence (1)

features/fetch.feature:10

  • This PR description focuses on stabilizing audio.com tests via HTTP request mocking, but this file also removes a large number of @require-wp-* gates (and related WP-version rationale comments). That changes the supported test matrix/scope beyond the stated purpose; please either restore the gates if they’re still needed or update the PR description to reflect the broadened intent.
  Background:
    Given a WP install

  Scenario: Get HTML embed code for a given URL
    # Known provider not requiring discovery.
    When I run `wp embed fetch https://www.youtube.com/watch?v=dQw4w9WgXcQ --width=500`
    Then STDOUT should contain:
      """

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 214 to 220
Scenario: Discover a provider with limited response size
When I run `wp embed provider match https://audio.com/audio-com/collections/ambient-focus`
When I run `wp embed provider match https://developer.wordpress.org/news/`
Then save STDOUT as {DEFAULT_STDOUT}

# Response limit too small
When I try `wp embed provider match https://audio.com/audio-com/collections/ambient-focus --limit-response-size=10`
When I try `wp embed provider match https://developer.wordpress.org/news/ --limit-response-size=10`
Then the return code should be 1
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

The “Discover a provider with limited response size” scenario now makes a real HTTP request to https://developer.wordpress.org/news/. This reintroduces an external dependency and undermines the goal of stabilizing tests via HTTP mocking; it can still be flaky (network, redirects, content changes) and may fail in restricted CI environments. Consider using the HTTP mocking step for this URL too (or keep using the audio.com URL with a mocked HTML response sized to exercise the limit logic).

Copilot uses AI. Check for mistakes.
@@ -280,6 +312,13 @@ Feature: Manage oEmbed providers.
audio.com/
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

The docstring in this STDOUT expectation has inconsistent indentation on the audio.com/ line compared to the surrounding docstrings. Depending on how the Gherkin parser dedents docstrings, this can introduce a leading space in the expected substring and make the STDOUT should contain assertion fail unexpectedly.

Suggested change
audio.com/
audio.com/

Copilot uses AI. Check for mistakes.
Comment on lines 68 to 72
And the return code should be 0

@require-wp-4.9
Scenario: Find oEmbed cache post ID for a non-existent key
When I try `wp embed cache find foo`
Then STDERR should be:
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

This change removes the @require-wp-4.9 gates from the embed cache find scenarios, but the PR description doesn’t mention expanding/removing WordPress-version constraints. If the CI matrix still includes WP < 4.9, these scenarios are expected to fail because oembed_cache behavior differs; either keep the gates or document the new minimum supported WP version/testing matrix in the PR.

Copilot uses AI. Check for mistakes.
Comment on lines 130 to +133
Scenario: Match an oEmbed provider
# Mock the audio.com URL to return HTML with oEmbed discovery links
Given that HTTP requests to https://audio.com/audio-com/collections/ambient-focus will respond with:
"""
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

The PR description lists updates to features/add-oembed-provider.feature, but in this change set the scenarios appear to have been consolidated into features/provider.feature and the separate feature file removed. Please update the PR description (and/or explain the consolidation rationale) so reviewers understand the full scope of the changes.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:embed-provider-match Related to 'embed provider match' command scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky audio provider tests

2 participants