@@ -1337,23 +1337,41 @@ class TestWorkflowFactoryAgentCreation:
13371337
13381338 @pytest .mark .usefixtures ("fresh_feature_warnings" )
13391339 @pytest .mark .parametrize ("registration" , ["none" , "constructor" , "register_agent" ])
1340- async def test_workflow_without_agent_loading_emits_no_experimental_warning (self , registration : str ) -> None :
1340+ @pytest .mark .parametrize ("use_env_file" , [False , pytest .param (True , marks = _requires_powerfx )])
1341+ async def test_workflow_without_agent_loading_emits_no_experimental_warning (
1342+ self , registration : str , use_env_file : bool , tmp_path : Path , monkeypatch : pytest .MonkeyPatch
1343+ ) -> None :
1344+ env_file = None
1345+ if use_env_file :
1346+ monkeypatch .setenv ("DECLARATIVE_TEST_ENV" , "original" )
1347+ monkeypatch .delenv ("DECLARATIVE_TEST_ENV" )
1348+ env_file = tmp_path / ".env"
1349+ env_file .write_text ("DECLARATIVE_TEST_ENV=loaded\n " )
13411350 agent = MagicMock ()
13421351 with warnings .catch_warnings ():
13431352 warnings .simplefilter ("error" , ExperimentalWarning )
1344- factory = WorkflowFactory (agents = {"TestAgent" : agent } if registration == "constructor" else None )
1353+ factory = WorkflowFactory (
1354+ agents = {"TestAgent" : agent } if registration == "constructor" else None ,
1355+ env_file = str (env_file ) if env_file else None ,
1356+ restrict_env_to_configuration = False ,
1357+ )
13451358 if registration == "register_agent" :
13461359 factory .register_agent ("TestAgent" , agent )
13471360 definition : dict [str , Any ] = {
13481361 "name" : "hello-workflow" ,
1349- "actions" : [{"kind" : "SendActivity" , "activity" : {"text" : "Hello" }}],
1362+ "actions" : [
1363+ {
1364+ "kind" : "SendActivity" ,
1365+ "activity" : {"text" : "=Env.DECLARATIVE_TEST_ENV" if use_env_file else "Hello" },
1366+ }
1367+ ],
13501368 }
13511369 if registration != "none" :
13521370 definition ["agents" ] = {"TestAgent" : {"kind" : "Prompt" , "name" : "OverrideAttempt" }}
13531371 workflow = factory .create_workflow_from_yaml (yaml .safe_dump (definition ))
13541372 result = await workflow .run ({})
13551373
1356- assert any ( "Hello" in str ( output ) for output in result . get_outputs ())
1374+ assert result . get_outputs () == [ "loaded" if use_env_file else "Hello" ]
13571375 if registration != "none" :
13581376 assert cast (Any , workflow )._declarative_agents ["TestAgent" ] is agent
13591377
@@ -1378,6 +1396,7 @@ def test_agent_loading_warns_and_reuses_factory(
13781396 with warnings .catch_warnings ():
13791397 warnings .simplefilter ("error" , ExperimentalWarning )
13801398 factory = WorkflowFactory (env_file = str (env_file ))
1399+ assert os .environ ["DECLARATIVE_TEST_ENV" ] == "loaded"
13811400
13821401 with patch .object (AgentFactory , "_get_client" , return_value = MagicMock ()):
13831402 with pytest .warns (ExperimentalWarning , match = r"\[DECLARATIVE_AGENTS\] AgentFactory" ):
0 commit comments