Files
Daniel Salazar 9ca1acf634 Benchmarks that gate PRs on I/O regressions, wider test baseline, and npm run check (#4644)
* feat(bench): backend benchmarks that fail a PR for waterfalled or uncached I/O

A scenario runs a request against the in-memory backend and records every
SQL, key-value, Redis and object-storage round trip on a modeled clock, then
reports round trips per destination, serial stages and modeled latency.
tools/bench.mjs runs the scenarios on a base commit and on the head and fails
on a regression the pull request description does not accept; benchmarks.yaml
runs that on every pull request.

Also adds npm run check (lint, type check, related tests and the benchmark
comparison for the files a branch changed) and describes the distributed
deployment in AGENTS.md.

* test(bench): scenarios for fs, kv, auth, apps, permissions, sharing and hosted sites

* test(puter-js): count the SDK unit tests in the coverage report

Only the bundle the API runners load was instrumented, so the unit tests next
to the SDK source never counted. In coverage mode the vitest config now
instruments SDK source for them and writes one shard per test file.

* test(puter-js): unit tests for ui messaging, dialogs, components, uploads, peer and smaller modules

* test(backend): cover fs, permission, app, worker, sharing, broadcast and user edge cases

* fix(backend): fs write flags are stored as booleans, app stats weeks are ISO weeks

- A write's boolean flags reach the store only once read as booleans; any
  positive number reads as true.
- App open stats grouped by week use ISO 8601 weeks for both the buckets
  and their labels on every database engine, so the two agree across a
  year boundary.

* fix(puter-js): dialog token source, legacy upload cancel, submenu state, typed-array views

- The sign-in dialog takes the token only from the popup it opened, and
  stops listening when it leaves the page.
- Cancelling a legacy upload rejects with `upload_aborted` and no longer
  runs the `error` callback.
- A context menu's submenu stays in step with its parent when the parent
  item is pressed or the submenu closes itself.
- The FileReader polyfill reads a typed-array view through its own offset
  and length.

* ci(bench): benchmark a pull request as merged into its base

The comparison ran the branch's own head against the tip of the base
branch, so a branch behind its base was charged for (or credited with)
what the base gained since. The head side is now the merge commit and
the base side its first parent. Shards also get a 15 minute timeout.

* test(broadcast): shutdown drain tests send boot's own events first

Boot queues cache updates that flush 10 ms later. A test body that
started after that flush counted it as its own request, which failed
'bounds a hung flush in onServerShutdown' on a slow runner.
2026-11-14 13:57:03 -07:00

211 lines
6.9 KiB
YAML

name: Benchmarks
# Runs the backend benchmarks on a change and on the commit before it (a pull
# request's base, or the previous commit on main), then compares the two. Both
# sides run on one runner, so the comparison never spans machines. A pull
# request fails on a regression it does not accept in its description; see
# doc/benchmarks.md. `edited` re-runs the check when the description changes.
on:
pull_request:
types: [opened, synchronize, reopened, edited]
push:
branches: [main]
permissions:
contents: read
pull-requests: write
concurrency:
group: benchmarks-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
jobs:
changes:
runs-on: ubuntu-latest
outputs:
backend: ${{ steps.filter.outputs.backend }}
steps:
- uses: actions/checkout@v7.0.1
with:
persist-credentials: false
- uses: dorny/paths-filter@v4.0.3
id: filter
with:
filters: |
backend:
- 'src/backend/**'
- 'extensions/**'
- 'tools/**'
- 'package.json'
- 'package-lock.json'
- '.github/workflows/benchmarks.yaml'
# Benchmark files are split across runners; each runs its share on both
# commits and uploads the two reports.
bench-shard:
needs: changes
if: needs.changes.outputs.backend == 'true'
name: bench shard ${{ matrix.shard }}/${{ strategy.job-total }}
runs-on: ubuntu-latest
# A shard takes about two minutes; a stuck scenario fails here instead of
# holding the runner for hours.
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3]
steps:
# A pull request is checked out merged into its base, and compared with
# that base (the merge's first parent). Comparing the branch's own head
# would count what the base gained since the branch was cut.
- name: Checkout
uses: actions/checkout@v7.0.1
with:
persist-credentials: false
fetch-depth: 2
- name: Pick the commit to compare against
id: base
env:
BEFORE: ${{ github.event.before }}
run: |
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
sha=$(git rev-parse HEAD^1)
else
sha=$BEFORE
git fetch --no-tags --depth=1 origin "$sha"
fi
echo "sha=$sha" >> "$GITHUB_OUTPUT"
- name: Set up Node.js
uses: actions/setup-node@v7.1.0
with:
node-version: '26'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run benchmarks on both commits
env:
BASE_SHA: ${{ steps.base.outputs.sha }}
CI: 'true'
run: >-
npm run bench:compare --
"$BASE_SHA"
--shard ${{ matrix.shard }}/${{ strategy.job-total }}
--report-only
- name: Upload reports
uses: actions/upload-artifact@v7.0.2
with:
name: bench-${{ matrix.shard }}
path: |
.bench/base/report.json
.bench/head/report.json
include-hidden-files: true
if-no-files-found: ignore
retention-days: 7
# The check to require. A skipped job would satisfy it, so this always runs:
# it passes when nothing relevant changed and fails when a shard did.
benchmarks:
needs: [changes, bench-shard]
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
steps:
- name: Check shard results
id: shards
env:
CHANGES_RESULT: ${{ needs.changes.result }}
BACKEND_CHANGED: ${{ needs.changes.outputs.backend }}
SHARDS_RESULT: ${{ needs.bench-shard.result }}
run: |
if [ "$CHANGES_RESULT" != "success" ]; then
echo "changes job: $CHANGES_RESULT"
exit 1
fi
if [ "$BACKEND_CHANGED" != "true" ]; then
echo "No backend changes."
exit 0
fi
if [ "$SHARDS_RESULT" != "success" ]; then
echo "bench shards: $SHARDS_RESULT"
exit 1
fi
echo "compare=true" >> "$GITHUB_OUTPUT"
- name: Checkout
if: steps.shards.outputs.compare == 'true'
uses: actions/checkout@v7.0.1
with:
persist-credentials: false
- name: Set up Node.js
if: steps.shards.outputs.compare == 'true'
uses: actions/setup-node@v7.1.0
with:
node-version: '26'
- name: Download reports
if: steps.shards.outputs.compare == 'true'
uses: actions/download-artifact@v8.0.2
with:
pattern: bench-*
path: .bench/shards
- name: Gather reports
if: steps.shards.outputs.compare == 'true'
run: |
mkdir -p .bench/all/base .bench/all/head
for shard in .bench/shards/bench-*; do
for side in base head; do
if [ -f "$shard/$side/report.json" ]; then
cp "$shard/$side/report.json" ".bench/all/$side/$(basename "$shard").json"
fi
done
done
# The description is passed through the environment, never interpolated
# into the script.
- name: Compare
id: compare
if: steps.shards.outputs.compare == 'true'
continue-on-error: true
env:
BENCH_ACCEPT_TEXT: ${{ github.event.pull_request.body }}
run: |
set +e
node tools/bench.mjs compare .bench/all/base .bench/all/head --markdown .bench/comparison.md
status=$?
cat .bench/comparison.md >> "$GITHUB_STEP_SUMMARY"
exit $status
# A fork's token cannot comment; the job summary carries the same table.
- name: Comment on the pull request
if: steps.shards.outputs.compare == 'true' && github.event_name == 'pull_request'
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
PR: ${{ github.event.pull_request.number }}
run: |
marker='<!-- puter-benchmarks -->'
{ echo "$marker"; cat .bench/comparison.md; } > .bench/comment.md
id=$(gh api "repos/$REPO/issues/$PR/comments" --paginate \
--jq ".[] | select(.body | startswith(\"$marker\")) | .id" | head -n 1)
if [ -n "$id" ]; then
gh api -X PATCH "repos/$REPO/issues/comments/$id" -F body=@.bench/comment.md > /dev/null
else
gh api -X POST "repos/$REPO/issues/$PR/comments" -F body=@.bench/comment.md > /dev/null
fi
# On main there is no description to accept a trade-off in, so a push
# only reports.
- name: Fail on unaccepted regressions
if: steps.compare.outcome == 'failure' && github.event_name == 'pull_request'
run: |
echo "Benchmarks regressed. See the job summary, and doc/benchmarks.md for how to accept a trade-off."
exit 1