From 49a6c5631b40b8b6806e33b8fa28c2f808b3bf33 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 20:48:55 +0000 Subject: [PATCH 1/2] Initial plan From bc16032aac47947bbd3068555799908a9e783349 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 20:51:58 +0000 Subject: [PATCH 2/2] Fix flake8 F824 error, add pytest-cov, and implement full CI pipeline Co-authored-by: joshuvavinith <146979257+joshuvavinith@users.noreply.github.com> --- .github/workflows/ci.yml | 55 +++++++++++++++++++++++++++------------- api.py | 2 -- requirements.txt | 1 + 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 75d7c6a..bc6e287 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,45 +6,66 @@ on: pull_request: branches: ["main", "master"] -# Restrict default GITHUB_TOKEN permissions to read-only permissions: contents: read jobs: - lint-and-test: + lint: runs-on: ubuntu-latest - permissions: - contents: read steps: - uses: actions/checkout@v4 - - name: Set up Python + - name: Set up Python 3.12 uses: actions/setup-python@v5 with: python-version: "3.12" + cache: "pip" + + - name: Install flake8 + run: pip install flake8 + + - name: Lint — blocking (syntax errors / undefined names) + run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + + - name: Lint — style warnings (non-blocking) + run: flake8 . --count --exit-zero --max-line-length=100 --statistics + + test: + needs: lint + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10", "3.11", "3.12"] + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: "pip" - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r requirements.txt - - name: Lint with flake8 - run: | - pip install flake8 - # Stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # Treat all other issues as warnings (non-blocking) - flake8 . --count --exit-zero --max-line-length=100 --statistics + - name: Run tests with coverage + env: + OPENAI_API_KEY: "offline-mode-no-key-required" + run: pytest test_chatbot.py -v --tb=short --cov=. --cov-report=xml - - name: Run tests - run: pytest test_chatbot.py -v + - name: Upload coverage report + uses: actions/upload-artifact@v4 + with: + name: coverage-${{ matrix.python-version }} + path: coverage.xml docker-build: + needs: test runs-on: ubuntu-latest - needs: lint-and-test - permissions: - contents: read steps: - uses: actions/checkout@v4 diff --git a/api.py b/api.py index 8eabdb5..42b2689 100644 --- a/api.py +++ b/api.py @@ -54,8 +54,6 @@ def clear_all_sessions() -> None: def _get_or_create_session(session_id: Optional[str]) -> tuple[str, ChatBot]: """Return (session_id, ChatBot) for the given session; create if missing.""" - global _default_bot - if session_id is None: # Create a new session session_id = str(uuid.uuid4()) diff --git a/requirements.txt b/requirements.txt index 256e933..0fe8029 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,4 +14,5 @@ uvicorn[standard]>=0.23.0 # Testing pytest>=7.4.0 +pytest-cov>=4.0.0 httpx>=0.25.0 \ No newline at end of file