diff --git a/tests/e2e/project_template/test_static_crawlers_templates.py b/tests/e2e/project_template/test_static_crawlers_templates.py index eb25425f1a..9486cba921 100644 --- a/tests/e2e/project_template/test_static_crawlers_templates.py +++ b/tests/e2e/project_template/test_static_crawlers_templates.py @@ -113,13 +113,17 @@ async def test_static_crawler_actor_at_apify( try: assert build_process.returncode == 0 - # Stagehand needs the model API key in `os.environ` at run time; register it as a secret env var - # on the deployed actor version so the platform injects it into the run. + # Stagehand needs the model API key in `os.environ` at run time. Env vars are baked into the + # build at build creation time, so registering the env var on the version after `apify push` + # is not enough — we must trigger a fresh build for the env var to be included. + build_number: str | None = None if crawler_type == 'stagehand': env_vars = actor.version('0.0').env_vars() await env_vars.create(name='OPENAI_API_KEY', value=os.environ['OPENAI_API_KEY'], is_secret=True) + rebuild = await actor.build(version_number='0.0', wait_for_finish=600) + build_number = rebuild['buildNumber'] - started_run_data = await actor.start(memory_mbytes=8192) + started_run_data = await actor.start(memory_mbytes=8192, build=build_number) actor_run = client.run(started_run_data['id']) finished_run_data = await actor_run.wait_for_finish()