diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..2b04bd3 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,22 @@ +name: Tests + +on: + pull_request: + push: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: astral-sh/setup-uv@v6 + with: + enable-cache: true + - name: Install Python + run: uv python install 3.12 + - name: Install dependencies + run: uv sync --frozen --python 3.12 + - name: Run tests + run: uv run --python 3.12 python -m unittest discover -s tests -v diff --git a/tests/test_run_bash_script.py b/tests/test_run_bash_script.py new file mode 100644 index 0000000..15ae17b --- /dev/null +++ b/tests/test_run_bash_script.py @@ -0,0 +1,34 @@ +import tempfile +import unittest +from pathlib import Path + +from src.server import app + + +class RunBashScriptTest(unittest.TestCase): + def test_executes_script_and_returns_output(self) -> None: + with tempfile.TemporaryDirectory() as working_dir: + marker = Path(working_dir) / "marker.txt" + script = f"printf osworld-server-ok | tee {marker.name}" + + with app.test_client() as client: + response = client.post( + "/run_bash_script", + json={"script": script, "working_dir": working_dir}, + ) + + self.assertEqual(response.status_code, 200, response.get_json()) + self.assertEqual( + response.get_json(), + { + "status": "success", + "output": "osworld-server-ok", + "error": "", + "returncode": 0, + }, + ) + self.assertEqual(marker.read_text(), "osworld-server-ok") + + +if __name__ == "__main__": + unittest.main()