@@ -465,9 +465,9 @@ async def test_file_based_prompt_registers_two_actions() -> None:
465465 # Load prompts from directory
466466 load_prompt_folder (ai .registry , prompt_dir )
467467
468- # Actions are registered with registry_definition_key (e.g., "dotprompt/ filePrompt")
468+ # Actions are registered with registry_definition_key (e.g., "filePrompt")
469469 # We need to look them up by kind and name (without the /prompt/ prefix)
470- action_name = 'dotprompt/ filePrompt' # registry_definition_key format
470+ action_name = 'filePrompt' # registry_definition_key format
471471
472472 prompt_action = ai .registry .lookup_action (ActionKind .PROMPT , action_name )
473473 executable_prompt_action = ai .registry .lookup_action (ActionKind .EXECUTABLE_PROMPT , action_name )
@@ -491,7 +491,7 @@ async def test_prompt_and_executable_prompt_return_types() -> None:
491491 prompt_file .write_text ('hello {{name}}' )
492492
493493 load_prompt_folder (ai .registry , prompt_dir )
494- action_name = 'dotprompt/ testPrompt'
494+ action_name = 'testPrompt'
495495
496496 prompt_action = ai .registry .lookup_action (ActionKind .PROMPT , action_name )
497497 executable_prompt_action = ai .registry .lookup_action (ActionKind .EXECUTABLE_PROMPT , action_name )
@@ -540,7 +540,73 @@ async def test_prompt_function_uses_lookup_prompt() -> None:
540540
541541 load_prompt_folder (ai .registry , prompt_dir )
542542
543- # Use prompt() function to look up the file-based prompt
544- executable = await prompt (ai .registry , 'promptFuncTest' )
545- response = await executable ({'name' : 'World' })
546- assert 'World' in response .text
543+ # Use ai.prompt() to look up the file-based prompt
544+ executable = await ai .prompt ('promptFuncTest' )
545+
546+ # Verify it can be executed
547+ response = await executable ({'name' : 'Genkit' })
548+ assert 'Genkit' in response .text
549+
550+
551+ @pytest .mark .asyncio
552+ async def test_automatic_prompt_loading ():
553+ """Test that Genkit automatically loads prompts from a directory."""
554+ with tempfile .TemporaryDirectory () as tmp_dir :
555+ # Create a prompt file
556+ prompt_content = """---
557+ name: testPrompt
558+ ---
559+ Hello {{name}}!
560+ """
561+ prompt_file = Path (tmp_dir ) / 'test.prompt'
562+ prompt_file .write_text (prompt_content )
563+
564+ # Initialize Genkit with the temporary directory
565+ ai = Genkit (prompt_dir = tmp_dir )
566+
567+ # Verify the prompt is registered
568+ # File-based prompts are registered with an empty namespace by default
569+ actions = ai .registry .list_serializable_actions ()
570+ assert '/prompt/test' in actions
571+ assert '/executable-prompt/test' in actions
572+
573+
574+ @pytest .mark .asyncio
575+ async def test_automatic_prompt_loading_default_none ():
576+ """Test that Genkit does not load prompts if prompt_dir is None."""
577+ ai = Genkit (prompt_dir = None )
578+ actions = ai .registry .list_serializable_actions ()
579+
580+ # Check that no prompts are registered (assuming a clean environment)
581+ dotprompts = [key for key in actions .keys () if '/prompt/' in key or '/executable-prompt/' in key ]
582+ assert len (dotprompts ) == 0
583+
584+
585+ @pytest .mark .asyncio
586+ async def test_automatic_prompt_loading_defaults_mock ():
587+ """Test that Genkit defaults to ./prompts when prompt_dir is not specified and dir exists."""
588+ from unittest .mock import ANY , MagicMock , patch
589+
590+ with patch ('genkit.ai._aio.load_prompt_folder' ) as mock_load , patch ('genkit.ai._aio.Path' ) as mock_path :
591+ # Setup mock to simulate ./prompts existing
592+ mock_path_instance = MagicMock ()
593+ mock_path_instance .is_dir .return_value = True
594+ mock_path .return_value = mock_path_instance
595+
596+ Genkit ()
597+ mock_load .assert_called_once_with (ANY , dir_path = mock_path_instance )
598+
599+
600+ @pytest .mark .asyncio
601+ async def test_automatic_prompt_loading_defaults_missing ():
602+ """Test that Genkit skips loading when ./prompts is missing."""
603+ from unittest .mock import ANY , MagicMock , patch
604+
605+ with patch ('genkit.ai._aio.load_prompt_folder' ) as mock_load , patch ('genkit.ai._aio.Path' ) as mock_path :
606+ # Setup mock to simulate ./prompts missing
607+ mock_path_instance = MagicMock ()
608+ mock_path_instance .is_dir .return_value = False
609+ mock_path .return_value = mock_path_instance
610+
611+ Genkit ()
612+ mock_load .assert_not_called ()
0 commit comments