regenerate.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/bin/bash
  2. set -eo pipefail
  3. run_test() {
  4. SANDBOX_TYPE=$SANDBOX_TYPE \
  5. WORKSPACE_BASE=$WORKSPACE_BASE \
  6. MAX_ITERATIONS=$MAX_ITERATIONS \
  7. WORKSPACE_MOUNT_PATH=$WORKSPACE_MOUNT_PATH \
  8. AGENT=$agent \
  9. poetry run pytest -s ./tests/integration/test_agent.py::$test_name
  10. # return exit code of pytest
  11. return $?
  12. }
  13. if [ -z $WORKSPACE_MOUNT_PATH ]; then
  14. WORKSPACE_MOUNT_PATH=$(pwd)
  15. fi
  16. if [ -z $WORKSPACE_BASE ]; then
  17. WORKSPACE_BASE=$(pwd)
  18. fi
  19. WORKSPACE_MOUNT_PATH+="/_test_workspace"
  20. WORKSPACE_BASE+="/_test_workspace"
  21. SANDBOX_TYPE="ssh"
  22. MAX_ITERATIONS=10
  23. agents=("MonologueAgent" "CodeActAgent" "PlannerAgent" "SWEAgent")
  24. tasks=(
  25. "Fix typos in bad.txt."
  26. "Write a shell script 'hello.sh' that prints 'hello'."
  27. "Use Jupyter IPython to write a text file containing 'hello world' to '/workspace/test.txt'."
  28. )
  29. test_names=(
  30. "test_edits"
  31. "test_write_simple_script"
  32. "test_ipython"
  33. )
  34. num_of_tests=${#test_names[@]}
  35. num_of_agents=${#agents[@]}
  36. if [ "$num_of_tests" -ne "${#test_names[@]}" ]; then
  37. echo "Every task must correspond to one test case"
  38. exit 1
  39. fi
  40. rm -rf logs
  41. rm -rf $WORKSPACE_BASE
  42. for ((i = 0; i < num_of_tests; i++)); do
  43. task=${tasks[i]}
  44. test_name=${test_names[i]}
  45. # skip other tests if only one test is specified
  46. if [[ -n "$ONLY_TEST_NAME" && "$ONLY_TEST_NAME" != "$test_name" ]]; then
  47. continue
  48. fi
  49. for ((j = 0; j < num_of_agents; j++)); do
  50. agent=${agents[j]}
  51. # skip other agents if only one agent is specified
  52. if [[ -n "$ONLY_TEST_AGENT" && "$ONLY_TEST_AGENT" != "$agent" ]]; then
  53. continue
  54. fi
  55. echo -e "\n\n\n\n========Running $test_name for $agent========\n\n\n\n"
  56. rm -rf $WORKSPACE_BASE
  57. mkdir $WORKSPACE_BASE
  58. if [ -d "tests/integration/workspace/$test_name" ]; then
  59. cp -r tests/integration/workspace/$test_name/* $WORKSPACE_BASE
  60. fi
  61. if [ "$TEST_ONLY" = true ]; then
  62. set -e
  63. else
  64. # Temporarily disable 'exit on error'
  65. set +e
  66. fi
  67. run_test
  68. TEST_STATUS=$?
  69. # Re-enable 'exit on error'
  70. set -e
  71. if [[ $TEST_STATUS -ne 0 ]]; then
  72. echo -e "\n\n\n\n========$test_name failed, regenerating test data for $agent========\n\n\n\n"
  73. sleep 1
  74. rm -rf $WORKSPACE_BASE
  75. mkdir -p $WORKSPACE_BASE
  76. if [ -d "tests/integration/workspace/$test_name" ]; then
  77. cp -r tests/integration/workspace/$test_name/* $WORKSPACE_BASE
  78. fi
  79. rm -rf logs
  80. rm -rf tests/integration/mock/$agent/$test_name/*
  81. # set -x to print the command being executed
  82. set -x
  83. echo -e "/exit\n" | \
  84. SANDBOX_TYPE=$SANDBOX_TYPE \
  85. WORKSPACE_BASE=$WORKSPACE_BASE \
  86. DEBUG=true \
  87. WORKSPACE_MOUNT_PATH=$WORKSPACE_MOUNT_PATH AGENT=$agent \
  88. poetry run python ./opendevin/core/main.py \
  89. -i $MAX_ITERATIONS \
  90. -t "$task Do not ask me for confirmation at any point." \
  91. -c $agent
  92. set +x
  93. mkdir -p tests/integration/mock/$agent/$test_name/
  94. mv logs/llm/**/* tests/integration/mock/$agent/$test_name/
  95. echo -e "\n\n\n\n========$test_name test data regenerated for $agent, rerun test again to verify========\n\n\n\n"
  96. # Temporarily disable 'exit on error'
  97. set +e
  98. run_test
  99. TEST_STATUS=$?
  100. # Re-enable 'exit on error'
  101. set -e
  102. if [[ $TEST_STATUS -ne 0 ]]; then
  103. echo -e "\n\n\n\n========$test_name for $agent RERUN FAILED========\n\n\n\n"
  104. echo -e "There are multiple possibilities:"
  105. echo -e " 1. The agent is unable to finish the task within $MAX_ITERATIONS steps."
  106. echo -e " 2. The agent thinks itself has finished the task, but fails the validation in the test code."
  107. echo -e " 3. There is something non-deterministic in the prompt."
  108. echo -e " 4. There is a bug in this script, or in OpenDevin code."
  109. echo -e "NOTE: Some of the above problems could sometimes be fixed by a retry (with a more powerful LLM)."
  110. echo -e " You could also consider improving the agent, increasing MAX_ITERATIONS, or skipping this test for this agent."
  111. exit 1
  112. else
  113. echo -e "\n\n\n\n========$test_name for $agent RERUN PASSED========\n\n\n\n"
  114. sleep 1
  115. fi
  116. else
  117. echo -e "\n\n\n\n========$test_name for $agent PASSED========\n\n\n\n"
  118. sleep 1
  119. fi
  120. done
  121. done
  122. rm -rf logs
  123. rm -rf $WORKSPACE_BASE
  124. echo "Done!"