From a092e253ddd114efd44fca5d2be5ebba05aacdf4 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Sun, 17 May 2026 20:25:45 +0200 Subject: [PATCH 1/2] test: rebuild stagehand actor after registering OPENAI_API_KEY Apify bakes a version's env vars into the build at build-creation time, so registering OPENAI_API_KEY after `apify push` had no effect on the run. Trigger a fresh build between the env-var creation and `actor.start()` so the secret is present at runtime. --- .../e2e/project_template/test_static_crawlers_templates.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/e2e/project_template/test_static_crawlers_templates.py b/tests/e2e/project_template/test_static_crawlers_templates.py index eb25425f1a..d5e0d80eab 100644 --- a/tests/e2e/project_template/test_static_crawlers_templates.py +++ b/tests/e2e/project_template/test_static_crawlers_templates.py @@ -113,11 +113,13 @@ 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. 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) + await actor.build(version_number='0.0', wait_for_finish=600) started_run_data = await actor.start(memory_mbytes=8192) actor_run = client.run(started_run_data['id']) From d1d175343c6f9a0b8bf3009fba950ba176e82c62 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Tue, 19 May 2026 16:48:58 +0200 Subject: [PATCH 2/2] require a specific build --- .../e2e/project_template/test_static_crawlers_templates.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/e2e/project_template/test_static_crawlers_templates.py b/tests/e2e/project_template/test_static_crawlers_templates.py index d5e0d80eab..9486cba921 100644 --- a/tests/e2e/project_template/test_static_crawlers_templates.py +++ b/tests/e2e/project_template/test_static_crawlers_templates.py @@ -116,12 +116,14 @@ async def test_static_crawler_actor_at_apify( # 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) - await actor.build(version_number='0.0', wait_for_finish=600) + 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()