Question

Codex cloud task: tests pass on my laptop but fail in the cloud with missing SUPABASE_URL

Solved, 180 viewsasked by rosa_m

I started giving Codex tasks from the web instead of the CLI, so it can work while I sleep. Every task ends with failing tests:

Locally everything is green. The keys are in my .env.local, which is in .gitignore.

What I’ve tried

Asked Codex to fix the tests. It mocked the whole Supabase client, the tests went green, and the actual feature was untested. Reverted that.

Comment

2 answers

Marked as helpful by the asker
jb_supa

The cloud task works on a fresh copy of your repo from GitHub, and .env.local is not in there (good). You need to give the environment its own variables in the Codex environment settings.

What I would do:

  • Don't give it your production keys. Give it a separate test project, or run Supabase locally in the setup script if your tests need a real database.
  • Put the non-secret values (the URL, the anon key of the test project) in environment variables.
  • Anything that must stay secret goes in secrets. Those are only available while the setup script runs, not while the agent works, which is exactly what you want for keys.

And reverting the mock was the right call. "Make the tests pass" is a dangerous task for an agent, because deleting the check is also a way to pass.

Comment
Made a second Supabase project just for Codex. Tests are green for real now. rosa_m
sanne_dev

One more thing for the setup script: seed the test project from the repo, not by hand. If your tests expect rows to exist, a fresh environment with an empty database fails in a way that looks like a code bug, and Codex will go and "fix" it.

I keep a supabase/seed.sql and a scripts/test-setup.sh that resets and seeds, and the Codex environment runs that script. Then the cloud run, my laptop and CI all start from the same data.

And put a line in AGENTS.md: "Never mock the Supabase client to make a test pass. If the environment is broken, stop and say so." After what happened to you I would not leave that to judgement.

Comment
The never-mock line is going straight into AGENTS.md. rosa_m
+1 on the seed script. An empty database is the second most common cloud failure after missing env vars. jb_supa