From 46f12955084bbdfd9ae0f9c6bc6dfdd6689f7cba Mon Sep 17 00:00:00 2001 From: Joaquin Campero Date: Mon, 6 Nov 2023 22:52:43 +0100 Subject: [PATCH] chore(prompt): prompt_on_access test --- tests_e2e/__specs/execute_tool_with_args.py | 44 +++++++++++++++++++ tests_e2e/execute_tool_with_args/app.yml | 8 +++- .../python_module_prompt_on_access.py | 15 ++++--- 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/tests_e2e/__specs/execute_tool_with_args.py b/tests_e2e/__specs/execute_tool_with_args.py index 6069ff59..cc76905c 100644 --- a/tests_e2e/__specs/execute_tool_with_args.py +++ b/tests_e2e/__specs/execute_tool_with_args.py @@ -588,3 +588,47 @@ def test_should_prompt_fuzzy_file_search(): .input("file_c") .exit() ) + + +def test_should_handle_prompt_on_access_true(): + ( + as_a_user(__file__) + .run_hexagon(["prompt-on-access"]) + .then_output_should_be( + [ + "Enter name:", + ] + ) + .input("John") + .then_output_should_be( + [ + "Enter name: John", + "name: John", + ], + ) + .then_output_should_be( + [ + "Enter age:", + ] + ) + .input("24") + .then_output_should_be( + [ + "Enter age: 24", + "age: 24", + ] + ) + .then_output_should_be( + [ + "Enter age:", + ] + ) + .input("45") + .then_output_should_be( + [ + "Enter age: 45", + "age 2: 45", + ] + ) + .exit() + ) diff --git a/tests_e2e/execute_tool_with_args/app.yml b/tests_e2e/execute_tool_with_args/app.yml index 63a2e467..43062277 100644 --- a/tests_e2e/execute_tool_with_args/app.yml +++ b/tests_e2e/execute_tool_with_args/app.yml @@ -41,4 +41,10 @@ tools: action: python_module_prompt type: shell alias: p - long_name: Python Module Script With Prompt \ No newline at end of file + long_name: Python Module Script With Prompt + + - name: prompt-on-access + action: python_module_prompt_on_access + type: shell + alias: poa + long_name: Python Module Script With Prompt On Access \ No newline at end of file diff --git a/tests_e2e/execute_tool_with_args/python_module_prompt_on_access.py b/tests_e2e/execute_tool_with_args/python_module_prompt_on_access.py index 90f83f68..7949aa38 100644 --- a/tests_e2e/execute_tool_with_args/python_module_prompt_on_access.py +++ b/tests_e2e/execute_tool_with_args/python_module_prompt_on_access.py @@ -12,10 +12,11 @@ class Args(ToolArgs): they get parsed loaded automatically by hexagon """ - name: OptionalArg[str] - age: OptionalArg[str] - country: OptionalArg[Union[str, int]] - likes: OptionalArg[List[str]] + name: OptionalArg[str] = None + age: OptionalArg[int] = None + + class Config: + prompt_on_access = True def main( @@ -24,7 +25,9 @@ def main( env_args: Any = None, cli_args: Args = None, ): + # if prompt_on_access is set to True, the prompt will be shown when accessing the value log.result(f"name: {cli_args.name}") log.result(f"age: {cli_args.age}") - log.result(f"country: {cli_args.country}") - log.result(f"likes: {cli_args.likes}") + + # if arg has already been accessed, subsequent prompt should work as expected + log.result(f"age 2: {cli_args.age.prompt()}")