-
Notifications
You must be signed in to change notification settings - Fork 4
Run live Chrome coverage in release preparation #21
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
senamakel
merged 4 commits into
tinyhumansai:main
from
senamakel:tinybrowser-release-coverage
Sep 25, 2026
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,81 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| minimum="${1:-90}" | ||
| report="${2:-coverage.json}" | ||
| script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" | ||
| workspace="${3:-$script_dir/../..}" | ||
| workspace_root="$(cd "$workspace" && pwd -P)/" | ||
| # Gate handwritten production files under crates/<package>/src/. Integration | ||
| # tests, colocated test.rs modules, generated macro code in vendor/, and other | ||
| # worktrees are not production files. The browser tests still run and exercise | ||
| # the production files counted here. | ||
| source_root="${workspace_root}crates/" | ||
|
|
||
| covered_files="$(jq --arg source_root "$source_root" ' | ||
| [ | ||
| .data[].files[] | ||
| | select(.filename | startswith($source_root)) | ||
| | select(.filename | contains("/src/")) | ||
| | select(.filename | endswith("/test.rs") | not) | ||
| | select(.filename | endswith("/tests.rs") | not) | ||
| | select(.summary.lines.count > 0) | ||
| ] | ||
| | length | ||
| ' "$report")" | ||
|
|
||
| if [[ "$covered_files" -eq 0 ]]; then | ||
| echo "coverage report contains no production files with executable lines under crates/" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| summary="$(jq -r --arg workspace_root "$workspace_root" --arg source_root "$source_root" ' | ||
| .data[].files[] | ||
| | select(.filename | startswith($source_root)) | ||
| | select(.filename | contains("/src/")) | ||
| | select(.filename | endswith("/test.rs") | not) | ||
| | select(.filename | endswith("/tests.rs") | not) | ||
| | select(.summary.lines.count > 0) | ||
| | [ | ||
| (.filename | ltrimstr($workspace_root)), | ||
| (.summary.lines.percent | tostring), | ||
| (.summary.lines.covered | tostring), | ||
| (.summary.lines.count | tostring) | ||
| ] | ||
| | @tsv | ||
| ' "$report")" | ||
|
|
||
| printf 'File\tLine coverage\tCovered lines\tCoverable lines\n' | ||
| while IFS=$'\t' read -r file percent covered count; do | ||
| printf '%s\t%.2f%%\t%s\t%s\n' "$file" "$percent" "$covered" "$count" | ||
| done <<< "$summary" | ||
|
|
||
| if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then | ||
| { | ||
| printf '### Per-file line coverage\n\n' | ||
| printf '| File | Coverage | Lines |\n' | ||
| printf '| --- | ---: | ---: |\n' | ||
| while IFS=$'\t' read -r file percent covered count; do | ||
| printf '| %s | %.2f%% | %s/%s |\n' "$file" "$percent" "$covered" "$count" | ||
| done <<< "$summary" | ||
| } >> "$GITHUB_STEP_SUMMARY" | ||
| fi | ||
|
|
||
| failures="$(jq -r \ | ||
| --arg workspace_root "$workspace_root" \ | ||
| --arg source_root "$source_root" \ | ||
| --argjson minimum "$minimum" ' | ||
| .data[].files[] | ||
| | select(.filename | startswith($source_root)) | ||
| | select(.filename | contains("/src/")) | ||
| | select(.filename | endswith("/test.rs") | not) | ||
| | select(.filename | endswith("/tests.rs") | not) | ||
| | select(.summary.lines.count > 0) | ||
| | select(.summary.lines.percent < $minimum) | ||
| | "\(.filename | ltrimstr($workspace_root)): \(.summary.lines.percent)%" | ||
| ' "$report")" | ||
|
|
||
| if [[ -n "$failures" ]]; then | ||
| printf '\nFiles below %s%% line coverage:\n%s\n' "$minimum" "$failures" >&2 | ||
| exit 1 | ||
| fi |
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,135 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" | ||
| repo_root="$(cd "$script_dir/../.." && pwd -P)" | ||
| scratch="$(mktemp -d)" | ||
| scratch="$(cd "$scratch" && pwd -P)" | ||
| trap 'rm -rf "$scratch"' EXIT | ||
|
|
||
| python3 - "$scratch" <<'PY' > "$scratch/good.json" | ||
| import json | ||
| import sys | ||
|
|
||
| root = sys.argv[1] | ||
|
|
||
| def file(path, covered, count): | ||
| return { | ||
| "filename": f"{root}/{path}", | ||
| "summary": {"lines": {"covered": covered, "count": count, | ||
| "percent": covered / count * 100}}, | ||
| } | ||
|
|
||
| print(json.dumps({"data": [{"files": [ | ||
| file("crates/example/src/ops.rs", 9, 10), | ||
| file("crates/example/src/test.rs", 0, 10), | ||
| file("crates/example/tests/integration.rs", 0, 10), | ||
| file("vendor/tinybus/crates/tinybus/src/lib.rs", 0, 10), | ||
| ]}]})) | ||
| PY | ||
|
|
||
| python3 - "$scratch" <<'PY' > "$scratch/bad.json" | ||
| import json | ||
| import sys | ||
|
|
||
| root = sys.argv[1] | ||
| print(json.dumps({"data": [{"files": [{ | ||
| "filename": f"{root}/crates/example/src/ops.rs", | ||
| "summary": {"lines": {"covered": 8, "count": 10, "percent": 80}}, | ||
| }]}]})) | ||
| PY | ||
|
|
||
| python3 - "$scratch" <<'PY' > "$scratch/test-only.json" | ||
| import json | ||
| import sys | ||
|
|
||
| root = sys.argv[1] | ||
| print(json.dumps({"data": [{"files": [{ | ||
| "filename": f"{root}/crates/example/src/test.rs", | ||
| "summary": {"lines": {"covered": 10, "count": 10, "percent": 100}}, | ||
| }]}]})) | ||
| PY | ||
|
|
||
| ( | ||
| cd "$scratch" | ||
| "$script_dir/check-file-coverage-report.sh" 90 good.json "$scratch" > good.out | ||
| grep -q 'crates/example/src/ops.rs' good.out | ||
| if grep -Eq 'test.rs|integration.rs|vendor/' good.out; then | ||
| echo "test-only or vendored file was counted" >&2 | ||
| exit 1 | ||
| fi | ||
| if "$script_dir/check-file-coverage-report.sh" 90 bad.json "$scratch" > bad.out 2>&1; then | ||
| echo "production file below 90% passed" >&2 | ||
| exit 1 | ||
| fi | ||
| grep -q 'crates/example/src/ops.rs: 80%' bad.out | ||
| if "$script_dir/check-file-coverage-report.sh" 90 test-only.json "$scratch" > empty.out 2>&1; then | ||
| echo "report with no production files passed" >&2 | ||
| exit 1 | ||
| fi | ||
| grep -q 'no production files' empty.out | ||
| ) | ||
|
|
||
| mkdir "$scratch/fakebin" | ||
| cat > "$scratch/fakebin/cargo" <<'FAKE_CARGO' | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
| [[ "${TINYBROWSER_LIVE_TESTS:-}" == 1 ]] || { | ||
|
senamakel marked this conversation as resolved.
senamakel marked this conversation as resolved.
|
||
| echo "coverage did not opt in to live browser tests" >&2 | ||
| exit 1 | ||
| } | ||
| [[ "$1" == llvm-cov ]] | ||
| shift | ||
| for flag in --locked --workspace --all-targets --all-features --json; do | ||
| [[ " $* " == *" $flag "* ]] || exit 1 | ||
| done | ||
| while [[ "$1" != --output-path ]]; do shift; done | ||
| cp "$COVERAGE_FIXTURE" "$2" | ||
| FAKE_CARGO | ||
| chmod +x "$scratch/fakebin/cargo" | ||
| python3 - "$scratch/good.json" "$scratch" "$repo_root" <<'PY' > "$scratch/wrapper-good.json" | ||
| import json | ||
| import sys | ||
|
|
||
| report = json.load(open(sys.argv[1])) | ||
| for group in report["data"]: | ||
| for file in group["files"]: | ||
| file["filename"] = file["filename"].replace(sys.argv[2] + "/", sys.argv[3] + "/", 1) | ||
| print(json.dumps(report)) | ||
| PY | ||
| ( | ||
| cd "$repo_root" | ||
| TINYBROWSER_LIVE_TESTS=1 PATH="$scratch/fakebin:$PATH" \ | ||
| COVERAGE_FIXTURE="$scratch/wrapper-good.json" \ | ||
| "$script_dir/check-file-coverage.sh" 90 "$scratch/wrapped.json" > "$scratch/wrapped.out" | ||
| grep -q 'crates/example/src/ops.rs' "$scratch/wrapped.out" | ||
| if ( | ||
| unset TINYBROWSER_LIVE_TESTS | ||
| PATH="$scratch/fakebin:$PATH" COVERAGE_FIXTURE="$scratch/wrapper-good.json" \ | ||
| "$script_dir/check-file-coverage.sh" 90 "$scratch/not-opted-in.json" > "$scratch/not-opted-in.out" 2>&1 | ||
| ); then | ||
| echo "coverage gate accepted missing live-test opt-in" >&2 | ||
| exit 1 | ||
| fi | ||
| grep -q 'requires TINYBROWSER_LIVE_TESTS=1' "$scratch/not-opted-in.out" | ||
| if TINYBROWSER_CHROME="$scratch/missing-chrome" \ | ||
| TINYBROWSER_LIVE_TESTS=1 PATH="$scratch/fakebin:$PATH" \ | ||
| COVERAGE_FIXTURE="$scratch/wrapper-good.json" \ | ||
| "$script_dir/check-file-coverage.sh" 90 "$scratch/missing.json" > "$scratch/missing.out" 2>&1; then | ||
| echo "missing configured Chrome passed" >&2 | ||
| exit 1 | ||
| fi | ||
| grep -q 'not executable' "$scratch/missing.out" | ||
| ) | ||
| if ( | ||
| cd "$scratch" | ||
| TINYBROWSER_LIVE_TESTS=1 PATH="$scratch/fakebin:$PATH" \ | ||
| COVERAGE_FIXTURE="$scratch/wrapper-good.json" \ | ||
| "$script_dir/check-file-coverage.sh" 90 "$scratch/wrong-directory.json" > "$scratch/wrong-directory.out" 2>&1 | ||
| ); then | ||
| echo "coverage gate accepted a different working directory" >&2 | ||
| exit 1 | ||
| fi | ||
| grep -q 'run the coverage gate from the repository root' "$scratch/wrong-directory.out" | ||
|
|
||
| echo "coverage script tests passed" | ||
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
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.