Skip to content

test: point oembed API tests at the CI mock-server instead of real providers - #41482

Merged
ggazzo merged 5 commits into
developfrom
test/oembed-mock-provider
Jul 21, 2026
Merged

test: point oembed API tests at the CI mock-server instead of real providers#41482
ggazzo merged 5 commits into
developfrom
test/oembed-mock-provider

Conversation

@KevLehman

@KevLehman KevLehman commented Jul 20, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

The chat.sendMessage oembed API tests fetched real external sites (YouTube's oembed endpoint, rocket.chat) at test time, so slow or failed external fetches flaked the suite — e.g. should generate previews of chosen URL when the previewUrls array is provided failing with expected {} not to be empty after its fixed 1s sleep.

This points the whole oembed suite at the mock-server already used by the ABAC API tests:

  • providers.ts registers a TEST_MODE-only oembed provider that resolves http://mock-server.local:8080/video/* URLs through GET /oembed on the mock-server; tests program that endpoint per case with captured real provider payloads (YouTube video, Spotify rich).
  • docker-compose-ci.yml adds a mock-server.local network alias, since single-label hostnames fail server-fetch SSRF domain validation.
  • The CE api job now also starts mock-server (the EE job already does via COMPOSE_PROFILES=api).
  • The flaky fixed sleep(1000) is replaced with the existing retry polling helper.

New coverage on top of the converted tests, using real captured oembed responses:

  • full metadata of a rich provider response (title/type/provider/thumbnail, oembedHtml max-width injection, non-string values dropped)
  • provider response with no string values embeds only oembedUrl
  • provider error response (500) embeds no metadata

Locally verified against the pinned mockserver image: path matching ignores query strings, string bodies work for the generic-page (pageTitle) case, and the dotted alias resolves via docker DNS from a peer container.

Steps to test or reproduce

Run the api E2E suite; the [Chat] /chat.sendMessage oembed block no longer performs any external network request.

Further comments

Test-only change, no changeset.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Improved link previews for supported video and rich-media URLs.
    • Enhanced preview metadata handling, including iframe content and provider responses.
    • Prevented invalid or incomplete metadata from appearing in message previews.
    • Improved behavior when preview providers return errors or when messages contain more than five external URLs.
  • Tests

    • Expanded end-to-end coverage for chat message previews and link-preview edge cases.

Task: CORE-2457

@dionisio-bot

dionisio-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is targeting the wrong base branch. It should target 8.8.0, but it targets 8.7.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 775135e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The E2E workflow now starts the mock server for API tests. Test mode registers a mock OEmbed provider, and chat API tests use deterministic mock URLs to validate previews, metadata extraction, provider errors, and URL limits.

Changes

Mock-backed OEmbed E2E coverage

Layer / File(s) Summary
Test-mode OEmbed provider
apps/meteor/server/services/messages/lib/oembed/providers.ts
Registers a mock-server.dev OEmbed provider when TEST_MODE is enabled.
Mock-server runtime wiring
.github/workflows/ci-test-e2e.yml, docker-compose-ci.yml
Starts mock-server for API E2E runs and adds the mock-server.dev Docker network alias.
Chat OEmbed test coverage
apps/meteor/tests/end-to-end/api/chat.ts
Uses mock-server fixtures and validates preview selection, URL limits, metadata extraction, and provider error handling.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested labels: type: chore

Suggested reviewers: ggazzo, sampaiodiego

Sequence Diagram(s)

sequenceDiagram
  participant OEmbedE2ETest
  participant RocketChat
  participant MockServer
  OEmbedE2ETest->>MockServer: Configure mock responses
  OEmbedE2ETest->>RocketChat: Post message with mock URL
  RocketChat->>MockServer: Request OEmbed data or page HTML
  MockServer-->>RocketChat: Return configured response
  RocketChat-->>OEmbedE2ETest: Return preview metadata
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: switching oembed API tests from real providers to the CI mock-server.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 68.61%. Comparing base (8d4507d) to head (775135e).
⚠️ Report is 10 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #41482      +/-   ##
===========================================
+ Coverage    68.58%   68.61%   +0.02%     
===========================================
  Files         4134     4134              
  Lines       160802   160842      +40     
  Branches     29244    29336      +92     
===========================================
+ Hits        110294   110369      +75     
+ Misses       45403    45378      -25     
+ Partials      5105     5095      -10     
Flag Coverage Δ
e2e 58.87% <ø> (+<0.01%) ⬆️
e2e-api 45.35% <50.00%> (+0.02%) ⬆️
unit 70.58% <ø> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@KevLehman KevLehman added this to the 8.8.0 milestone Jul 21, 2026
@KevLehman
KevLehman marked this pull request as ready for review July 21, 2026 16:30
@KevLehman
KevLehman requested review from a team as code owners July 21, 2026 16:30

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (2)
apps/meteor/server/services/messages/lib/oembed/providers.ts (1)

103-110: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Inline comments here may run against the "avoid code comments" guideline — likely fine to keep as-is.

Both files add explanatory comments (mock-provider rationale, SSRF-allowlist/TLD quirks, reset-cadence rationale). As per coding guidelines, **/*.{ts,tsx,js} says to "Avoid code comments in the implementation," but that guideline block's own text frames it around "Playwright tests," and neither file here is a Playwright spec (providers.ts is server code; chat.ts is mocha/chai/supertest). Given the ambiguity and that these specific comments explain non-obvious cross-file behavior, I'd lean toward keeping them.

  • apps/meteor/server/services/messages/lib/oembed/providers.ts#L103-L110: comment at line 104 explaining the TEST_MODE provider's purpose.
  • apps/meteor/tests/end-to-end/api/chat.ts#L1266-L1320: comments at lines 1266, 1270, and 1313 explaining mock URL routing, the fixed-wait rationale, and mock-server reset semantics.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/meteor/server/services/messages/lib/oembed/providers.ts` around lines
103 - 110, Keep the explanatory comments at the TEST_MODE provider registration
in providers.ts and the mock-server setup/reset flow in chat.ts (lines
1266-1320); no code changes are required because these comments document
non-obvious behavior.

Source: Coding guidelines

.github/workflows/ci-test-e2e.yml (1)

194-201: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Verified: explicit service targeting starts mock-server correctly despite the api profile not being activated.

Docker Compose explicitly documents that "when you explicitly target a service on the command line that has one or more profiles assigned, ... Compose runs that service regardless of whether its profile is activated," so this script works as intended without needing COMPOSE_PROFILES.

Separately: this step now gates docker compose up --wait on mock-server's health, but that service's healthcheck (docker-compose-ci.yml, unchanged) has no start_period and only 5 retries at a 2s interval — unlike rocketchat's own healthcheck in the same file, which has start_period: 60s. Since --wait fails the whole invocation the moment a targeted service reports unhealthy, a slow CI runner could intermittently fail this step even if mock-server would have come up healthy moments later.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/ci-test-e2e.yml around lines 194 - 201, Increase the
resilience of the mock-server healthcheck used by the services array in the CI
workflow: update its healthcheck configuration in docker-compose-ci.yml to allow
slow CI startup, using an appropriate start_period and/or more retries while
preserving the existing readiness check. Keep the rocketchat healthcheck and
explicit service targeting unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In @.github/workflows/ci-test-e2e.yml:
- Around line 194-201: Increase the resilience of the mock-server healthcheck
used by the services array in the CI workflow: update its healthcheck
configuration in docker-compose-ci.yml to allow slow CI startup, using an
appropriate start_period and/or more retries while preserving the existing
readiness check. Keep the rocketchat healthcheck and explicit service targeting
unchanged.

In `@apps/meteor/server/services/messages/lib/oembed/providers.ts`:
- Around line 103-110: Keep the explanatory comments at the TEST_MODE provider
registration in providers.ts and the mock-server setup/reset flow in chat.ts
(lines 1266-1320); no code changes are required because these comments document
non-obvious behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e3a22e11-3c0f-41c9-ae0a-316c328a4604

📥 Commits

Reviewing files that changed from the base of the PR and between 8d4507d and 775135e.

📒 Files selected for processing (4)
  • .github/workflows/ci-test-e2e.yml
  • apps/meteor/server/services/messages/lib/oembed/providers.ts
  • apps/meteor/tests/end-to-end/api/chat.ts
  • docker-compose-ci.yml
📜 Review details
⏰ Context from checks skipped due to timeout. (3)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Hacktron Security Check
  • GitHub Check: 🔨 Test UI (EE) / MongoDB 8.0 coverage (2/5)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/server/services/messages/lib/oembed/providers.ts
  • apps/meteor/tests/end-to-end/api/chat.ts
🧠 Learnings (3)
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/server/services/messages/lib/oembed/providers.ts
  • apps/meteor/tests/end-to-end/api/chat.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/server/services/messages/lib/oembed/providers.ts
  • apps/meteor/tests/end-to-end/api/chat.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/server/services/messages/lib/oembed/providers.ts
  • apps/meteor/tests/end-to-end/api/chat.ts
🔇 Additional comments (1)
docker-compose-ci.yml (1)

230-235: LGTM!

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

No issues found across 4 files

Re-trigger cubic

@KevLehman KevLehman added the stat: QA assured Means it has been tested and approved by a company insider label Jul 21, 2026
@KevLehman

Copy link
Copy Markdown
Member Author

/jira CORE

@ggazzo
ggazzo merged commit caed5c4 into develop Jul 21, 2026
99 of 101 checks passed
@ggazzo
ggazzo deleted the test/oembed-mock-provider branch July 21, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants