-
Notifications
You must be signed in to change notification settings - Fork 1
test: add Bats coverage for uncovered Makefile targets #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| name: bats testing | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| bats: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 | ||
| with: | ||
| node-version: ${{ vars.NODE_VERSION }} | ||
|
|
||
| - name: Cache pnpm dependencies | ||
| id: cache-pnpm-dependencies | ||
| uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 | ||
| with: | ||
| path: node_modules | ||
| key: ${{ runner.os }}-dependencies-node-${{ vars.NODE_VERSION }}-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-dependencies-node-${{ vars.NODE_VERSION }}- | ||
|
|
||
| - name: Install pnpm | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| run: npm install -g pnpm@10.6.5 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add GitHub issue where we will move from pnpm to faster package manager that we are using in the CRM |
||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
|
|
||
| - name: Run Bats shell coverage | ||
| run: make test-bats BATS_FORMATTER=tap | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Bats Suite | ||
|
|
||
| This suite covers Makefile targets and `scripts/ci` helper flows that are not already | ||
| exercised by the pull request workflows. | ||
|
|
||
| ## Run locally | ||
|
|
||
| ```bash | ||
| make test-bats | ||
| ``` | ||
|
|
||
| Use `BATS_FORMATTER=tap` when you want CI-style output: | ||
|
|
||
| ```bash | ||
| make test-bats BATS_FORMATTER=tap | ||
| ``` | ||
|
|
||
| ## Maintain coverage | ||
|
|
||
| 1. Update `tests/bats/make-target-coverage.tsv` whenever a Makefile target is added, | ||
| removed, or reclassified. | ||
| 2. If a target is not already exercised by a PR workflow, add or update the Bats test | ||
| that covers its shell behavior. | ||
| 3. If a workflow already exercises the target, document that workflow in | ||
| `tests/bats/make-target-coverage.tsv` instead of duplicating the coverage. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #!/usr/bin/env bats | ||
|
|
||
| load './test_helper.bash' | ||
|
|
||
| setup() { | ||
| setup_ci_script_test_env | ||
| } | ||
|
|
||
| @test "batch_unit_mutation_lint.sh dispatches each DIND flow through existing make targets" { | ||
| local script_path="$PROJECT_ROOT/scripts/ci/batch_unit_mutation_lint.sh" | ||
|
|
||
| run_ci_script "$script_path" test-unit | ||
| [ "$status" -eq 0 ] | ||
| assert_log_contains 'make build' | ||
| assert_log_contains 'make create-temp-dev-container-dind TEMP_CONTAINER_NAME=website-dev-test' | ||
| assert_log_contains 'make copy-source-to-container-dind TEMP_CONTAINER_NAME=website-dev-test' | ||
| assert_log_contains 'make install-deps-in-container-dind TEMP_CONTAINER_NAME=website-dev-test' | ||
| assert_log_contains 'make run-unit-tests-dind TEMP_CONTAINER_NAME=website-dev-test' | ||
|
|
||
| reset_command_log | ||
| run_ci_script "$script_path" test-mutation | ||
| [ "$status" -eq 0 ] | ||
| assert_log_contains 'make run-mutation-tests-dind TEMP_CONTAINER_NAME=website-dev-test' | ||
|
|
||
| reset_command_log | ||
| run_ci_script "$script_path" test-lint | ||
| [ "$status" -eq 0 ] | ||
| assert_log_contains 'make run-eslint-tests-dind TEMP_CONTAINER_NAME=website-dev-lint' | ||
| assert_log_contains 'make run-typescript-tests-dind TEMP_CONTAINER_NAME=website-dev-lint' | ||
| assert_log_contains 'make run-markdown-lint-tests-dind TEMP_CONTAINER_NAME=website-dev-lint' | ||
| } | ||
|
|
||
| @test "batch_pw_load.sh dispatches its E2E, visual, and load flows through make and docker" { | ||
| local script_path="$PROJECT_ROOT/scripts/ci/batch_pw_load.sh" | ||
|
|
||
| run_ci_script "$script_path" test-e2e | ||
| [ "$status" -eq 0 ] | ||
| assert_log_contains 'make start-prod' | ||
| assert_log_contains 'make test-e2e' | ||
| assert_log_contains 'docker compose -f common-healthchecks.yml -f docker-compose.test.yml exec -T playwright mkdir -p /app' | ||
| assert_log_contains 'docker compose -f common-healthchecks.yml -f docker-compose.test.yml cp playwright:/app/playwright-report/. playwright-report/' | ||
|
|
||
| reset_command_log | ||
| run_ci_script "$script_path" test-visual | ||
| [ "$status" -eq 0 ] | ||
| assert_log_contains 'make start-prod' | ||
| assert_log_contains 'make test-visual' | ||
| assert_log_contains 'docker compose -f common-healthchecks.yml -f docker-compose.test.yml exec -T playwright mkdir -p /app/src/test /app/src/config /app/pages/i18n' | ||
|
|
||
| reset_command_log | ||
| run_ci_script "$script_path" test-load | ||
| [ "$status" -eq 0 ] | ||
| assert_log_contains 'make start-prod' | ||
| assert_log_contains 'make build-k6' | ||
| assert_log_contains 'make create-k6-helper-container-dind K6_HELPER_NAME=website-k6-helper' | ||
| assert_log_contains 'make run-load-tests-dind K6_HELPER_NAME=website-k6-helper' | ||
| assert_log_contains 'docker cp src/test/load/. website-k6-helper:/loadTests/' | ||
| } | ||
|
|
||
| @test "batch_lhci_leak.sh handles CodeBuild skips and the DIND Lighthouse flows" { | ||
| local script_path="$PROJECT_ROOT/scripts/ci/batch_lhci_leak.sh" | ||
|
|
||
| run env \ | ||
| -C "$SCRIPT_SANDBOX" \ | ||
| PATH="$STUB_BIN_DIR:$PATH" \ | ||
| COMMAND_LOG="$COMMAND_LOG" \ | ||
| CODEBUILD_BUILD_ID=website:1 \ | ||
| "$script_path" test-memory-leak | ||
| [ "$status" -eq 0 ] | ||
| assert_output_contains 'Memory leak tests: SKIPPED' | ||
|
|
||
| reset_command_log | ||
| run_ci_script "$script_path" test-lighthouse-desktop | ||
| [ "$status" -eq 0 ] | ||
| assert_log_contains 'make start-prod' | ||
| assert_log_contains 'make install-chromium-lhci' | ||
| assert_log_contains 'make test-chromium' | ||
| assert_log_contains 'make lighthouse-desktop-dind' | ||
|
|
||
| reset_command_log | ||
| run_ci_script "$script_path" test-lighthouse-mobile | ||
| [ "$status" -eq 0 ] | ||
| assert_log_contains 'make start-prod' | ||
| assert_log_contains 'make install-chromium-lhci' | ||
| assert_log_contains 'make test-chromium' | ||
| assert_log_contains 'make lighthouse-mobile-dind' | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| #!/usr/bin/env bats | ||
|
|
||
| load './test_helper.bash' | ||
|
|
||
| @test "make target coverage manifest accounts for every Makefile target" { | ||
| local manifest_path="$PROJECT_ROOT/tests/bats/make-target-coverage.tsv" | ||
| local expected_targets="$BATS_TEST_TMPDIR/expected-targets.txt" | ||
| local manifest_targets="$BATS_TEST_TMPDIR/manifest-targets.txt" | ||
|
|
||
| [ -f "$manifest_path" ] | ||
|
|
||
| awk -F: '/^[A-Za-z0-9_.-]+:/{ if ($1 !~ /^\./) print $1 }' \ | ||
| "$PROJECT_ROOT/Makefile" \ | ||
| | sort -u > "$expected_targets" | ||
|
|
||
| tail -n +2 "$manifest_path" | cut -f1 | sort -u > "$manifest_targets" | ||
|
|
||
| run diff -u "$expected_targets" "$manifest_targets" | ||
| [ "$status" -eq 0 ] | ||
| } | ||
|
|
||
| @test "every Bats-covered target points at an existing test file" { | ||
| local manifest_path="$PROJECT_ROOT/tests/bats/make-target-coverage.tsv" | ||
|
|
||
| [ -f "$manifest_path" ] | ||
|
|
||
| while IFS=$'\t' read -r target coverage evidence details; do | ||
| [ -n "$target" ] || continue | ||
| [ "$target" != "target" ] || continue | ||
|
|
||
| [ -f "$PROJECT_ROOT/$evidence" ] | ||
|
|
||
| if [ "$coverage" = "bats" ]; then | ||
| run awk -v target="$target" ' | ||
| BEGIN { found = 0 } | ||
| { | ||
| for (i = 1; i <= NF; i++) { | ||
| if ($i == target) { | ||
| found = 1 | ||
| } | ||
| } | ||
| } | ||
| END { exit(found ? 0 : 1) } | ||
| ' FS='[^A-Za-z0-9_.-]+' "$PROJECT_ROOT/$evidence" | ||
| [ "$status" -eq 0 ] | ||
|
RudoiDmytro marked this conversation as resolved.
|
||
| fi | ||
| done < "$manifest_path" | ||
| } | ||
|
|
||
| @test "CI helper scripts only call existing Makefile targets" { | ||
| local expected_targets="$BATS_TEST_TMPDIR/known-targets.txt" | ||
| local hard_coded_targets="$BATS_TEST_TMPDIR/script-targets.txt" | ||
| local missing_targets="$BATS_TEST_TMPDIR/missing-targets.txt" | ||
|
|
||
| awk -F: '/^[A-Za-z0-9_.-]+:/{ if ($1 !~ /^\./) print $1 }' \ | ||
| "$PROJECT_ROOT/Makefile" \ | ||
| | sort -u > "$expected_targets" | ||
|
|
||
| grep -RhoE 'make [A-Za-z0-9_.-]+' "$PROJECT_ROOT/scripts/ci" \ | ||
| | awk '{ print $2 }' \ | ||
| | sort -u > "$hard_coded_targets" | ||
|
|
||
| comm -23 "$hard_coded_targets" "$expected_targets" > "$missing_targets" | ||
|
|
||
| run test ! -s "$missing_targets" | ||
| [ "$status" -eq 0 ] | ||
| } | ||
|
|
||
| @test "a pull request workflow runs make test-bats with explicit read-only permissions" { | ||
| local workflows_with_bats="$BATS_TEST_TMPDIR/workflows-with-bats.txt" | ||
| local workflow_path | ||
|
|
||
| grep -RFl 'make test-bats' "$PROJECT_ROOT/.github/workflows" > "$workflows_with_bats" | ||
| run test -s "$workflows_with_bats" | ||
| [ "$status" -eq 0 ] | ||
|
|
||
| while IFS= read -r workflow_path; do | ||
| run grep -F 'pull_request:' "$workflow_path" | ||
| [ "$status" -eq 0 ] | ||
|
|
||
| run grep -F 'contents: read' "$workflow_path" | ||
| [ "$status" -eq 0 ] | ||
|
|
||
| run grep -F 'contents: write' "$workflow_path" | ||
| [ "$status" -ne 0 ] | ||
| done < "$workflows_with_bats" | ||
| } | ||
|
|
||
| @test "repository docs explain how to run and maintain the Bats suite" { | ||
| run grep -F 'make test-bats' "$PROJECT_ROOT/README.md" | ||
| [ "$status" -eq 0 ] | ||
|
|
||
| run grep -F 'make-target-coverage.tsv' "$PROJECT_ROOT/CONTRIBUTING.md" | ||
| [ "$status" -eq 0 ] | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.