Skip to content

test: read the embed provider list even when parallel workers inherit it - #272

Closed
GTS-MEGHNI wants to merge 1 commit into
dev-null-sh:productionfrom
GTS-MEGHNI:fix/embeds-test-env
Closed

GTS-MEGHNI wants to merge 1 commit into
dev-null-sh:productionfrom
GTS-MEGHNI:fix/embeds-test-env

Conversation

@GTS-MEGHNI

Copy link
Copy Markdown
Contributor

Problem

production CI fails on one test, so every open PR shows a red tests check:

FAILED  Tests\Unit\Services\EmbedsTest > it reads the provider list from the environment
Failed asserting that two arrays are identical.

The test passes when you run it alone, which is why it's easy to miss.

Cause

It only fails when both of these are true, which is exactly what CI does:

  1. .env defines EMBEDS_PROVIDERS=. CI runs cp .env.example .env, and .env.example has that line.
  2. Tests run in parallel (pest --parallel). The main process loads .env into the real environment, and every worker inherits EMBEDS_PROVIDERS="".

Laravel's env repository never overwrites a variable that is already set. So Env::getRepository()->set('EMBEDS_PROVIDERS', ' youtube, ,spotify ') did nothing in a worker, and config/embeds.php read the empty value.

Fix

Only the test changes. It now uses a repository that is allowed to overwrite the variable (RepositoryBuilder::createWithDefaultAdapters()), and puts the original value back in a finally block, so other tests in the same worker see what they saw before.

config/embeds.php and the app don't change.

Testing

Ran tests/Unit/Services/EmbedsTest.php locally in three setups:

.env Run Before After
Copy of .env.example (like CI) --parallel 1 failed 8 passed
Copy of .env.example (like CI) one process 8 passed 8 passed
No EMBEDS_PROVIDERS line --parallel 8 passed 8 passed

Pint, Rector and type coverage (100%) pass.

Note

Several open PRs carry their own copy of a fix for this test inside unrelated changes (for example #125, #126, #141, #155, #172, #198, #236, #260, #265). Merging this one on its own unblocks all of them, and they can drop their copies.

🤖 Generated with Claude Code

CI copies .env.example, which sets EMBEDS_PROVIDERS to an empty string,
and runs the tests in parallel. The workers inherit that value from the
parent process, and Laravel's env repository never overwrites a variable
that is already set, so the test's own value was ignored and the provider
list came back empty. The test now sets the variable through a repository
that can overwrite it, and puts the original value back afterwards.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@brendt

brendt commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Appreciate it! We were late merging though and it has already been fixed

@brendt brendt closed this Oct 19, 2026
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.

2 participants