From 2d586a97ff623cf42277dcb6011bb2444bbb7792 Mon Sep 17 00:00:00 2001 From: Pamela Fox Date: Tue, 19 Aug 2025 11:28:22 -0700 Subject: [PATCH 1/4] Add test coverage to workflow --- .github/workflows/python-test.yaml | 7 ++++++- .gitignore | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-test.yaml b/.github/workflows/python-test.yaml index 22257db72b..a6f3a7d103 100644 --- a/.github/workflows/python-test.yaml +++ b/.github/workflows/python-test.yaml @@ -61,7 +61,12 @@ jobs: run: black . --check --verbose - name: Run Python tests if: runner.os != 'Windows' - run: pytest -s -vv --cov --cov-fail-under=89 + run: pytest -s -vv --cov --cov-report=xml --cov-fail-under=90 + - name: Check diff coverage + if: runner.os != 'Windows' + run: | + git fetch origin main:refs/remotes/origin/main + diff-cover coverage.xml --compare-branch=origin/main --fail-under=90 - name: Run E2E tests with Playwright id: e2e if: runner.os != 'Windows' diff --git a/.gitignore b/.gitignore index 185ad0f3ef..05bbf3b060 100644 --- a/.gitignore +++ b/.gitignore @@ -54,6 +54,7 @@ coverage.xml .hypothesis/ .pytest_cache/ cover/ +coverage_report.html # Translations *.mo From 5d029134293a31621d71ee88fd8c731496685426 Mon Sep 17 00:00:00 2001 From: Pamela Fox Date: Tue, 19 Aug 2025 11:36:12 -0700 Subject: [PATCH 2/4] Add diff_cover package --- requirements-dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements-dev.txt b/requirements-dev.txt index c035649f27..994b969b17 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -12,3 +12,4 @@ pytest-snapshot pre-commit pip-tools mypy==1.14.1 +diff_cover From 1207ed939aa43ef70a5cc84122fc487aed8381e2 Mon Sep 17 00:00:00 2001 From: Pamela Fox Date: Tue, 19 Aug 2025 11:44:58 -0700 Subject: [PATCH 3/4] Update worklow --- .github/workflows/python-test.yaml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-test.yaml b/.github/workflows/python-test.yaml index a6f3a7d103..ee14ea05e0 100644 --- a/.github/workflows/python-test.yaml +++ b/.github/workflows/python-test.yaml @@ -29,6 +29,9 @@ jobs: node_version: ["20.14", "22"] steps: - uses: actions/checkout@v5 + with: + # Fetch full history so diff-cover can compute a merge base with origin/main + fetch-depth: 0 - name: Install uv uses: astral-sh/setup-uv@v6 with: @@ -65,8 +68,10 @@ jobs: - name: Check diff coverage if: runner.os != 'Windows' run: | - git fetch origin main:refs/remotes/origin/main - diff-cover coverage.xml --compare-branch=origin/main --fail-under=90 + BASE_REF="${{ github.base_ref }}" + if [ -z "$BASE_REF" ]; then BASE_REF="main"; fi + git fetch origin "$BASE_REF:refs/remotes/origin/$BASE_REF" + diff-cover coverage.xml --compare-branch="origin/$BASE_REF" --fail-under=90 - name: Run E2E tests with Playwright id: e2e if: runner.os != 'Windows' From 7b57d39235ebfc9757b4747d0529648eff54bd0c Mon Sep 17 00:00:00 2001 From: Pamela Fox Date: Tue, 19 Aug 2025 11:52:43 -0700 Subject: [PATCH 4/4] Update CONTRIBUTING.md --- .github/workflows/python-test.yaml | 2 +- CONTRIBUTING.md | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.github/workflows/python-test.yaml b/.github/workflows/python-test.yaml index ee14ea05e0..0fb5f6ee55 100644 --- a/.github/workflows/python-test.yaml +++ b/.github/workflows/python-test.yaml @@ -64,7 +64,7 @@ jobs: run: black . --check --verbose - name: Run Python tests if: runner.os != 'Windows' - run: pytest -s -vv --cov --cov-report=xml --cov-fail-under=90 + run: pytest -s -vv --cov --cov-report=xml --cov-fail-under=89 - name: Check diff coverage if: runner.os != 'Windows' run: | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f3d1d104d6..d0b2e83c97 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,8 +17,9 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio - [Running unit tests](#running-unit-tests) - [Running E2E tests](#running-e2e-tests) - [Code style](#code-style) -- [Adding new azd environment variables](#adding-new-azd-environment-variables) -- [Adding new UI strings](#adding-new-ui-strings) +- [Adding new features](#adding-new-features) + - [Adding new azd environment variables](#adding-new-azd-environment-variables) + - [Adding new UI strings](#adding-new-ui-strings) ## Submitting a Pull Request (PR) @@ -62,10 +63,18 @@ Run the tests: python -m pytest ``` -Check the coverage report to make sure your changes are covered. +If test snapshots need updating (and the changes are expected), you can update them by running: ```shell -python -m pytest --cov +python -m pytest --snapshot-update +``` + +Once tests are passing, generate a coverage report to make sure your changes are covered: + +```shell +pytest --cov --cov-report=xml && \ +diff-cover coverage.xml --format html:coverage_report.html && \ +open coverage_report.html ``` ## Running E2E tests @@ -118,7 +127,15 @@ python -m black If you followed the steps above to install the pre-commit hooks, then you can just wait for those hooks to run `ruff` and `black` for you. -## Adding new azd environment variables +## Adding new features + +We recommend using GitHub Copilot Agent mode when adding new features, +as this project includes [.github/copilot-instructions.md](.github/copilot-instructions.md) file +that instructs Copilot on how to generate code for common code changes. + +If you are not using Copilot Agent mode, consult both that file and suggestions below. + +### Adding new azd environment variables When adding new azd environment variables, please remember to update: @@ -128,7 +145,7 @@ When adding new azd environment variables, please remember to update: 1. [ADO pipeline](.azdo/pipelines/azure-dev.yml). 1. [Github workflows](.github/workflows/azure-dev.yml) -## Adding new UI strings +### Adding new UI strings When adding new UI strings, please remember to update all translations. For any translations that you generate with an AI tool,