Skip to content

Commit 3cd6c9c

Browse files
authored
feat(ci): Last CI step checking for non-exercised tests (#4533)
These changes add a last step in the build that compares the list of executed top level test functions with the list of existing top-level test functions in the source branch code. :memo: Doesn't detect missing runs of run-time generated tests like table based test cases. :memo: Only relevant for test cases defined under `./flow` :memo: Future test selection implementations should propagate run selected to tests to the filter of this command. Related PoC: #4510
1 parent 04a87e8 commit 3cd6c9c

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

.github/workflows/flow.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,3 +713,51 @@ jobs:
713713
o11y-api-key-id: ${{ secrets.CI_O11Y_TARGET_API_KEY_ID }}
714714
o11y-api-key-secret: ${{ secrets.CI_O11Y_TARGET_API_KEY_SECRET }}
715715
o11y-query-endpoint: ${{ secrets.CI_O11Y_TARGET_QUERY_ENDPOINT }}
716+
717+
- name: Check all present test functions in the source branch were exercised in CI
718+
# Compares the top-level tests that actually ran in CI (from the
719+
# normalized results produced by the ingest step above) against every top-level
720+
# test defined under ./flow, and fails if the branch defines tests CI never ran.
721+
# Only runs for pull request builds; skipped for non-PR builds (e.g. push to main).
722+
# Parens matter: && binds tighter than || in GitHub Actions expressions.
723+
if: |
724+
(success() || failure()) &&
725+
(github.event_name == 'pull_request' || github.event_name == 'pull_request_target')
726+
working-directory: ./flow
727+
run: |
728+
set -uo pipefail
729+
tmp="${RUNNER_TEMP:-/tmp}"
730+
731+
ndjson="../logs/normalized-test-results.ndjson"
732+
if [ ! -s "$ndjson" ]; then
733+
echo "::error::No normalized test results at ${ndjson} (results ingestion disabled or no tests ran); failing check."
734+
exit 1
735+
fi
736+
737+
# (run-tests): top-level test functions observed in CI results, with subtests
738+
# collapsed onto their parent (TestFoo/sub -> TestFoo).
739+
# This collapse is necessary because the branch test enumeration below only lists top-level tests functions.
740+
jq -r '.test' "$ndjson" | { grep '^Test' || true; } | awk -F '/' '{ print $1 }' | sort -u > "${tmp}/run-tests.txt"
741+
if [ ! -s "${tmp}/run-tests.txt" ]; then
742+
echo "::error::No 'Test*' entries found in CI results; failing check."
743+
exit 1
744+
fi
745+
746+
# (tests-in-branch): every top-level test function defined in the source branch.
747+
if ! go test -list '.*' ./... > "${tmp}/go-list.txt" 2> "${tmp}/go-list.err"; then
748+
echo "::error::'go test -list' failed (likely a compilation error already surfaced by the test step); failing check."
749+
cat "${tmp}/go-list.err"
750+
exit 1
751+
fi
752+
{ grep '^Test' "${tmp}/go-list.txt" || true; } | sort -u > "${tmp}/tests-in-branch.txt"
753+
754+
# Tests defined in the branch but never observed in CI results.
755+
missing="$(comm -13 "${tmp}/run-tests.txt" "${tmp}/tests-in-branch.txt")"
756+
if [ -z "$missing" ]; then
757+
echo "All source-branch tests were exercised in CI."
758+
exit 0
759+
fi
760+
761+
echo "The following tests in the source branch have not been run in CI:"
762+
printf '%s\n' "$missing"
763+
exit 1

0 commit comments

Comments
 (0)