-
-
Notifications
You must be signed in to change notification settings - Fork 132
1623 lines (1495 loc) · 76.4 KB
/
Copy pathtest.yml
File metadata and controls
1623 lines (1495 loc) · 76.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: Tests
on:
# Run on version tags so `release-packages.yml` can gate publish on a green
# Tests workflow for the exact commit being released. Direct pushes to main
# do NOT trigger tests — the gates that matter are PRs (pre-merge) and tags
# (pre-release).
push:
tags: ['v*']
pull_request:
branches: [main]
# `labeled` is here so the optional opt-in jobs (parity, compile-smoke,
# doc-tests) re-fire when a maintainer or the PR author applies the
# `run-extended-tests` label. Without it, applying the label on an
# existing PR wouldn't re-trigger the workflow.
types: [opened, synchronize, reopened, labeled]
paths-ignore:
- 'docs/src/**'
- '*.md'
- '!CLAUDE.md'
- '!CHANGELOG.md'
schedule:
# Nightly full-workspace cargo-test safety net (04:00 UTC). The per-PR
# cargo-test gate only exercises crates affected by the diff
# (scripts/ci_test_scope.py); a cross-crate regression that slips a scoped
# PR is caught here within a day. `schedule` is not `pull_request`, so the
# cargo-test job runs the full workspace.
- cron: '0 4 * * *'
# Manual escape hatch for the opt-in jobs. Maintainers (write access)
# can dispatch the workflow against any ref with `run_extended_tests=true`
# to run parity / compile-smoke / package smokes / doc-tests on demand
# without tagging a release.
workflow_dispatch:
inputs:
run_extended_tests:
description: 'Run extended tests (parity, compile-smoke, package smokes, doc-tests)'
type: boolean
default: false
concurrency:
group: test-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
MACOSX_DEPLOYMENT_TARGET: "13.0"
jobs:
# ---------------------------------------------------------------------------
# Lint: cargo fmt --check (formatting gate for every PR)
# ---------------------------------------------------------------------------
lint:
# Was macos-14 — moved to ubuntu-latest in v0.5.428 since `cargo fmt
# --check` is portable. The 6 multiplier-min cut is small in absolute
# terms (lint runs in ~30s) but it's free.
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v6
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
with:
shared-key: "${{ runner.os }}-perry"
# PRs read from cache; only main writes new entries.
# Avoids cache thrash from short-lived branches.
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Check formatting
run: cargo fmt --all -- --check
# File-size gate (v0.5.1019): fails the PR if any tracked source
# file exceeds the LOC threshold (5000 initially; eventual target
# is 2000). Big single-file modules are hard to read, slow IDE +
# cargo-check incrementality, and hide regressions in code review.
# Allowlist + exclusions live in the script.
- name: File size limit
run: ./scripts/check_file_size.sh
# GC write-barrier store-site inventory: every raw heap-slot store in
# perry-codegen / perry-runtime / perry-stdlib must be barriered or
# carry a justified GC_STORE_AUDIT(...) marker (or a justified entry
# in scripts/gc_store_site_allowlist.txt). Catches new unbarriered
# old->young store paths before they become nondeterministic segfaults.
- name: GC store-site inventory
run: |
python3 scripts/gc_store_site_inventory.py --self-test
python3 scripts/gc_store_site_inventory.py
# Handle-vs-pointer address classification audit: POINTER_TAG payloads
# can be heap pointers OR small registry handles (fetch/zlib/proxy/...),
# and code must classify by magnitude through value/addr_class.rs before
# dereferencing. Catches new hand-typed band literals (0x100000 etc.)
# and new `as *const GcHeader` casts outside addr_class.rs / gc/ before
# they become Linux-only segfaults (#1843, #4004, #4665, #4800 class).
# Allowlist: scripts/addr_class_allowlist.txt.
- name: Address-classification audit
run: |
python3 scripts/addr_class_inventory.py --self-test
python3 scripts/addr_class_inventory.py
# ---------------------------------------------------------------------------
# API docs drift gate (#465)
#
# Regenerates `docs/src/api/reference.md` and `docs/api/perry.d.ts` from
# the compile-time manifest in `crates/perry-api-manifest/src/entries.rs`,
# then `git diff --exit-code`s the result. Fails when a code change updated
# the manifest without re-committing the artifacts. Closes the "Release
# workflow regenerates docs automatically (no drift from code)" criterion
# — committing the diff is the easiest way to keep the docs in sync,
# since the diff is reviewable in the PR that introduces it.
# ---------------------------------------------------------------------------
api-docs-drift:
runs-on: ubuntu-latest
timeout-minutes: 30
env:
RUSTC_WRAPPER: sccache
# sccache on a LOCAL DISK cache, persisted as a single tarball via
# actions/cache (see the "Cache sccache objects" step) — NOT the GitHub
# Actions cache backend (SCCACHE_GHA_ENABLED). The GHA backend stores one
# cache object per compilation unit; GitHub's cache service throttled /
# LRU-evicted the thousands of tiny entries, so a full build wrote ~3.3k
# objects (≈35 min of write time) yet the next run got ~0% Rust hits
# (measured: 3 hits / 3209 misses, 613 write errors) — i.e. every run
# recompiled the dependency graph cold. A single tarball'd disk cache
# restores in one step and gives real cross-run hit rates. Note
# SCCACHE_CACHE_SIZE is honoured by the disk backend (it was a silent
# no-op under the GHA backend, which is why the old "2G" never mattered).
SCCACHE_GHA_ENABLED: "false"
SCCACHE_DIR: ${{ github.workspace }}/.sccache
SCCACHE_CACHE_SIZE: "12G"
CARGO_INCREMENTAL: "0"
steps:
- uses: actions/checkout@v6
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install sccache
uses: mozilla-actions/sccache-action@v0.0.10
# Persist the sccache disk cache across runs. The github.job +
# github.run_id key makes every run (including PRs) save its own fresh
# entry — distinct per job so the three sccache jobs don't collide on
# save — while the shared prefix restore-keys pull the most recent prior
# cache from ANY of them. The object cache therefore warms continuously
# and cross-pollinates instead of starting cold each run.
- name: Cache sccache objects
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.sccache
key: sccache-${{ runner.os }}-perry-${{ github.job }}-${{ github.run_id }}
restore-keys: |
sccache-${{ runner.os }}-perry-
- uses: Swatinem/rust-cache@v2
with:
shared-key: "${{ runner.os }}-perry"
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Regenerate API docs
run: ./scripts/regen_api_docs.sh
- name: Check for drift
run: |
if ! git diff --quiet -- docs/src/api/reference.md docs/api/perry.d.ts; then
echo ""
echo "::error::API docs drift detected. The compile-time manifest in"
echo "::error::crates/perry-api-manifest/src/entries.rs changed but the"
echo "::error::generated artifacts under docs/ weren't regenerated."
echo ""
echo "Fix by running:"
echo " ./scripts/regen_api_docs.sh"
echo " git add docs/src/api/reference.md docs/api/perry.d.ts"
echo " git commit -m 'docs: regenerate API reference + .d.ts'"
echo ""
echo "Diff:"
git --no-pager diff --stat -- docs/src/api/reference.md docs/api/perry.d.ts
echo ""
git --no-pager diff -- docs/src/api/reference.md docs/api/perry.d.ts | head -200
exit 1
fi
echo "✅ API docs match the manifest."
# ---------------------------------------------------------------------------
# Rust unit tests (266+ tests across all crates)
# ---------------------------------------------------------------------------
# Note: a separate `build` job that produced runtime/stdlib/compiler
# artifacts USED to live here. It only fed `binary-size` (which now does
# its own quick build) — every other job did `cargo build --release`
# itself anyway, so `needs: build` was a serializing barrier with no
# cache benefit. Removed in v0.5.387 along with the `actions/cache@v4`
# blocks (replaced by `Swatinem/rust-cache@v2`, which handles target/
# pruning intelligently and avoids the disk-pressure issue that
# required the manual simulator-runtime wipe + cache=registry-only
# workaround). Each downstream job below builds in parallel directly.
cargo-test:
# Was macos-14 — moved to ubuntu-latest in v0.5.392 to drop the 10×
# billing weight. cargo-test's `--exclude` list already filters out
# every macOS-specific UI crate (perry-ui-{ios,visionos,tvos,
# watchos,gtk4,android,windows} per the comment block below), so
# the platform-independent test set runs identically on Linux. The
# macOS-host coverage we lose here is negligible — these tests
# don't exercise any platform behavior; they're pure logic +
# codegen.
runs-on: ubuntu-latest
# The per-package serial build+prune loop below (plus the big stdlib links)
# takes ~50-60 min with a WARM sccache disk cache. A fully cold cache
# (recompiling the whole dependency graph) measured ~90-103 min, and PRs
# that invalidate perry-runtime/perry-codegen previously exceeded the old
# 120-min bound entirely. The bound is 180 to (a) leave headroom while the
# disk cache warms after the sccache-backend fix, and (b) still cut a true
# hang (e.g. a flaky link SIGBUS retry storm). Once warm hit rates are
# confirmed in CI this can come back down. NOTE: the old "~45-50 min" figure
# predated the sccache GHA-backend rot — it was never accurate once that
# cache stopped delivering Rust hits.
timeout-minutes: 180
# sccache (compiler-level cache, shared across ALL branches/jobs via the
# GitHub Actions cache backend) on top of Swatinem/rust-cache (target/ +
# registry). rust-cache only writes on main (save-if below), so PRs can't
# warm it — and any change to the constantly-churning perry-runtime
# invalidates the whole downstream target/, whereas sccache still reuses
# the unchanged compilation units. CARGO_INCREMENTAL=0 is required: sccache
# cannot cache incremental builds. SCCACHE_CACHE_SIZE bounds the on-runner
# cache so it doesn't compound this job's known disk pressure (the prune
# loop below).
env:
RUSTC_WRAPPER: sccache
# sccache on a LOCAL DISK cache, persisted as a single tarball via
# actions/cache (see the "Cache sccache objects" step) — NOT the GitHub
# Actions cache backend (SCCACHE_GHA_ENABLED). The GHA backend stores one
# cache object per compilation unit; GitHub's cache service throttled /
# LRU-evicted the thousands of tiny entries, so a full build wrote ~3.3k
# objects (≈35 min of write time) yet the next run got ~0% Rust hits
# (measured: 3 hits / 3209 misses, 613 write errors) — i.e. every run
# recompiled the dependency graph cold. A single tarball'd disk cache
# restores in one step and gives real cross-run hit rates. Note
# SCCACHE_CACHE_SIZE is honoured by the disk backend (it was a silent
# no-op under the GHA backend, which is why the old "2G" never mattered).
SCCACHE_GHA_ENABLED: "false"
SCCACHE_DIR: ${{ github.workspace }}/.sccache
SCCACHE_CACHE_SIZE: "12G"
CARGO_INCREMENTAL: "0"
steps:
- uses: actions/checkout@v6
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install sccache
uses: mozilla-actions/sccache-action@v0.0.10
# Persist the sccache disk cache across runs. The github.job +
# github.run_id key makes every run (including PRs) save its own fresh
# entry — distinct per job so the three sccache jobs don't collide on
# save — while the shared prefix restore-keys pull the most recent prior
# cache from ANY of them. The object cache therefore warms continuously
# and cross-pollinates instead of starting cold each run.
- name: Cache sccache objects
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.sccache
key: sccache-${{ runner.os }}-perry-${{ github.job }}-${{ github.run_id }}
restore-keys: |
sccache-${{ runner.os }}-perry-
- uses: Swatinem/rust-cache@v2
with:
shared-key: "${{ runner.os }}-perry"
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Run cargo test
# Exclude UI backends that don't build on the ubuntu-latest CI image:
# - perry-ui-macos / perry-ui-ios / perry-ui-tvos / perry-ui-watchos
# / perry-ui-visionos: depend on `objc2` which only compiles on
# Apple platforms (`compile_error!` in objc2/src/lib.rs:219).
# - perry-ui-gtk4: needs system pango/gtk via pkg-config; runner
# image doesn't have libgtk-4-dev installed by default.
# - perry-ui-android: needs Android NDK.
# - perry-ui-windows: needs win32 headers.
# - perry-ui-windows-winui: re-exports perry-ui-windows, so it inherits
# the same win32 / webview2-com dependency that won't build on Linux.
env:
# Rust's Ubuntu target can drive `cc` with `-fuse-ld=lld`; on the
# shared runner this has repeatedly terminated large test links with
# SIGBUS. Use the system linker for the cargo-test gate.
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS: "-C linker-features=-lld"
# Keep test artifacts small enough for the shared runner disk. The
# cargo-test job does not need line tables, and debug info was enough
# to make later package archives hit ENOSPC after several package
# test builds accumulated in target/debug.
CARGO_PROFILE_TEST_DEBUG: "0"
CARGO_PROFILE_DEV_DEBUG: "0"
# For `gh pr view` (PR changed-file list → affected-crate scope).
GH_TOKEN: ${{ github.token }}
run: |
(
while sleep 60; do
echo "cargo-test still running at $(date -u +%Y-%m-%dT%H:%M:%SZ)"
done
) &
cargo_test_heartbeat_pid=$!
trap 'kill "$cargo_test_heartbeat_pid" 2>/dev/null || true' EXIT
# Test scope: a per-PR run only exercises the crates the diff can
# affect (changed crates + their reverse-dependency closure, plus a
# `perry` edge for runtime-linked stdlib/ext archives) instead of the
# whole workspace (~90 min). Release tags, the nightly cron, and
# workflow_dispatch run the FULL workspace as the safety net. See
# scripts/ci_test_scope.py for the rules.
if [ "${{ github.event_name }}" = "pull_request" ]; then
changed_files="$(gh pr view "${{ github.event.pull_request.number }}" \
--json files --jq '.files[].path')"
echo "Changed files in PR:"; printf '%s\n' "$changed_files"
scope="$(printf '%s\n' "$changed_files" | python3 scripts/ci_test_scope.py)"
else
scope="$(python3 scripts/ci_test_scope.py --full </dev/null)"
fi
echo "Packages in test scope:"; printf '%s\n' "$scope"
if [ -z "$scope" ]; then
echo "No crates affected by this diff — nothing to test."
exit 0
fi
# #1444: perry-runtime's tests share process-global state — the
# per-thread arena/GC, the timer queues, and the `NOTIFIED` flag are
# process singletons. Running them across the default test-harness
# thread pool lets one test's `js_notify_main_thread` / timer
# scheduling perturb another's wait budget (the event_pump timing
# flakes) and races the GC/threading tests into intermittent SIGSEGV.
# Run perry-runtime single-threaded so the tests can't interfere.
if [ "${{ github.event_name }}" != "pull_request" ]; then
# ---- FULL run: release tags / nightly cron / workflow_dispatch ----
# Every target, including the slow auto-optimize integration tests.
if printf '%s\n' "$scope" | grep -qx 'perry-runtime'; then
RUST_TEST_THREADS=1 cargo test -p perry-runtime
fi
# `cargo test` only builds lib/bin/test targets — NOT the `staticlib`
# crate-type — so libperry_runtime.a / libperry_stdlib.a are never
# produced by the steps above; they only exist if restored from the
# cache. Integration tests that compile with PERRY_NO_AUTO_OPTIMIZE=1
# (e.g. functional_batch2_regressions) link the prebuilt archive
# directly and fail with "Could not find libperry_runtime.a" if the
# cached staticlib was invalidated. Build them explicitly.
if printf '%s\n' "$scope" | grep -qE '^(perry|perry-stdlib)$'; then
cargo build -p perry-runtime -p perry-stdlib -p perry-runtime-static -p perry-stdlib-static
fi
find target/debug/deps -maxdepth 1 -type f -perm -111 ! -name '*.so' -delete
# Large perry / perry-stdlib integration-test binaries: serialize
# builds and prune linked executables between packages so the runner
# disk doesn't exhaust mid-job.
export CARGO_BUILD_JOBS=1
for package in $(printf '%s\n' "$scope" | grep -vx 'perry-runtime'); do
echo "::group::cargo test -p $package"
cargo test -p "$package"
echo "::endgroup::"
cargo clean -p "$package" || true
find target/debug/deps -maxdepth 1 -type f -perm -111 ! -name '*.so' -delete
done
else
# ---- FAST per-PR run (<10 min target) ----
# Unit / lib / bin tests for the affected crates only. The slow
# auto-optimize *integration* tests (tests/*.rs — each shells out to
# `perry compile`, ~4–6 min apiece, ~30 of them) are NOT run per-PR;
# they run in the nightly full job, on release tags, and on demand
# via the `run-extended-tests` label. No staticlib dependency to
# build (no integration tests).
#
# Run each crate in its OWN `cargo test` invocation — NOT one
# multi-package invocation. Building several crates together unifies
# perry-runtime's cargo features, which turns on optional impls (e.g.
# `fetch`) whose extern symbols (`js_fetch_with_options`) live in a
# separate crate the other test binaries don't link → `undefined
# reference` at link. Per-package builds keep each crate's
# perry-runtime feature set isolated. CARGO_BUILD_JOBS=1 also bounds
# the heavy per-binary runtime link so the runner doesn't OOM.
# `--with-tests` drops crates whose `src/` has no unit tests (their
# lib test binary would link the runtime for zero tests).
export CARGO_BUILD_JOBS=1
# perry-runtime first, single-threaded (process-global state); it is
# a lib-only crate, so filter to --lib.
if printf '%s\n' "$scope" | grep -qx 'perry-runtime'; then
RUST_TEST_THREADS=1 cargo test --lib -p perry-runtime
fi
rest="$(printf '%s\n' "$scope" | grep -vx 'perry-runtime' \
| python3 scripts/ci_test_scope.py --with-tests || true)"
echo "Crates with unit tests in scope:"; printf '%s\n' "$rest"
for package in $rest; do
# `cargo test --lib` errors on a bin-only crate (perry), so pick
# the target filter per package: --lib --bins when it has a lib
# (lenient if it has no bins), else --bins.
if printf '%s\n' "$package" | python3 scripts/ci_test_scope.py --has-lib; then
target_filter="--lib --bins"
else
target_filter="--bins"
fi
echo "::group::cargo test $target_filter -p $package"
cargo test $target_filter -p "$package"
echo "::endgroup::"
done
fi
# ---------------------------------------------------------------------------
# GC write-barrier stress (optional / non-blocking)
#
# `crates/perry/tests/gc_write_barrier_stress.rs` runs compiled binaries
# under the slowest GC configuration (PERRY_GC_FORCE_EVACUATE +
# PERRY_GC_VERIFY_EVACUATION) to hunt a *rare* corruption window (#5029).
# Those tests are ~200s each and nondeterministic by nature, so they are a
# poor fit for the blocking per-PR `cargo-test` gate (one flake blocked
# every unrelated PR). They are `#[ignore]`d there and run here instead.
#
# Opt-in + informational: `continue-on-error` so a flake never fails the
# workflow; triggered by the `run-extended-tests` PR label, a
# `workflow_dispatch` with `run_extended_tests=true`, or a tag push.
# ---------------------------------------------------------------------------
gc-stress:
continue-on-error: true
if: >-
github.event_name == 'push' ||
(github.event_name == 'workflow_dispatch' && inputs.run_extended_tests) ||
(github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'run-extended-tests'))
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v6
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
shared-key: "${{ runner.os }}-perry"
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install clang
run: |
sudo apt-get update
sudo apt-get install -y clang
- name: Run GC write-barrier stress tests
env:
# Match the cargo-test gate's linker workaround (lld SIGBUS on the
# shared runner during large test links).
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS: "-C linker-features=-lld"
run: cargo test -p perry --test gc_write_barrier_stress -- --ignored
# ---------------------------------------------------------------------------
# Compiler-output regression gate
#
# Retains HIR, pre/post-opt LLVM IR, assembly, benchmark output, runtime
# counters, vectorization remarks, benchmark timing summaries, and FP
# contraction evidence for the primary CPU benchmark plus numeric fixtures.
# Fails when hot-loop structural contracts regress.
# ---------------------------------------------------------------------------
compiler-output-regression:
runs-on: ubuntu-latest
timeout-minutes: 45
env:
RUSTC_WRAPPER: sccache
# sccache on a LOCAL DISK cache, persisted as a single tarball via
# actions/cache (see the "Cache sccache objects" step) — NOT the GitHub
# Actions cache backend (SCCACHE_GHA_ENABLED). The GHA backend stores one
# cache object per compilation unit; GitHub's cache service throttled /
# LRU-evicted the thousands of tiny entries, so a full build wrote ~3.3k
# objects (≈35 min of write time) yet the next run got ~0% Rust hits
# (measured: 3 hits / 3209 misses, 613 write errors) — i.e. every run
# recompiled the dependency graph cold. A single tarball'd disk cache
# restores in one step and gives real cross-run hit rates. Note
# SCCACHE_CACHE_SIZE is honoured by the disk backend (it was a silent
# no-op under the GHA backend, which is why the old "2G" never mattered).
SCCACHE_GHA_ENABLED: "false"
SCCACHE_DIR: ${{ github.workspace }}/.sccache
SCCACHE_CACHE_SIZE: "12G"
CARGO_INCREMENTAL: "0"
steps:
- uses: actions/checkout@v6
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install sccache
uses: mozilla-actions/sccache-action@v0.0.10
# Persist the sccache disk cache across runs. The github.job +
# github.run_id key makes every run (including PRs) save its own fresh
# entry — distinct per job so the three sccache jobs don't collide on
# save — while the shared prefix restore-keys pull the most recent prior
# cache from ANY of them. The object cache therefore warms continuously
# and cross-pollinates instead of starting cold each run.
- name: Cache sccache objects
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.sccache
key: sccache-${{ runner.os }}-perry-${{ github.job }}-${{ github.run_id }}
restore-keys: |
sccache-${{ runner.os }}-perry-
- uses: Swatinem/rust-cache@v2
with:
shared-key: "${{ runner.os }}-perry"
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install clang
run: |
sudo apt-get update
sudo apt-get install -y clang
- name: Build compiler
run: cargo build -p perry
- name: Run harness unit tests
run: python3 -m unittest tests.test_compiler_output_regression
- name: Gate native-region proof compiler output
run: |
python3 scripts/compiler_output_regression.py suite \
--suite native-region-proof \
--perry target/debug/perry \
--benchmark-mode smoke \
--runs 1 \
--perf-counters off \
--print-summary
- name: Gate positive vectorization compiler output
run: |
python3 scripts/compiler_output_regression.py capture \
--perry target/debug/perry \
--workload vectorized_buffer_transform \
--benchmark-mode smoke \
--runs 1 \
--perf-counters off \
--gate \
--print-summary
- name: Gate HIR fact rewrite compiler output
run: |
python3 scripts/compiler_output_regression.py capture \
--perry target/debug/perry \
--workload hir_fact_rewrite \
--benchmark-mode smoke \
--runs 1 \
--perf-counters off \
--gate \
--print-summary
- name: Gate FP contraction modes
run: |
python3 scripts/compiler_output_regression.py capture \
--perry target/debug/perry \
--workload fma_contract \
--benchmark-mode smoke \
--runs 1 \
--perf-counters off \
--gate \
--fp-contract=on \
--clang-arg=-march=haswell \
--expect-fma=on \
--out-dir target/compiler-output-regression/fma_contract-fp-contract-on
python3 scripts/compiler_output_regression.py capture \
--perry target/debug/perry \
--workload fma_contract \
--benchmark-mode smoke \
--runs 1 \
--perf-counters off \
--gate \
--fast-math \
--fp-contract=off \
--clang-arg=-march=haswell \
--expect-fma=off \
--out-dir target/compiler-output-regression/fma_contract-fast-no-contract
- name: Upload compiler-output artifacts
if: always()
uses: actions/upload-artifact@v7
with:
name: compiler-output-regression
path: target/compiler-output-regression/
# ---------------------------------------------------------------------------
# Parity tests (Perry output vs Node.js)
# ---------------------------------------------------------------------------
parity:
# Release-publish decoupling: aspirational extended suite. Per maintainer
# decision it no longer BLOCKS package publishing — release-packages.yml's
# await-tests gate keys on this workflow's run conclusion, and job-level
# `continue-on-error: true` keeps a red result here from failing that
# conclusion. The job still runs on every tag + shows its own pass/fail as
# an informational signal (and core jobs — cargo-test/lint/api-docs-drift/
# compiler-output-regression — still gate publish).
continue-on-error: true
# Was macos-14 — moved to ubuntu-latest in v0.5.392. Parity tests
# just compare Perry's stdout against `node --experimental-strip-types`'s
# stdout per test file; both run cleanly on Linux. `gtimeout` on
# macOS is `timeout` on Linux (the run_parity_tests.sh wrapper
# detects either). Node 22+ is installed via setup-node@v4 below.
# 10× billing weight cut.
#
# v0.5.1018: gated to tag pushes only (`github.event_name == 'push'`).
# The pull_request trigger above still fires the workflow on PRs for
# the lint / cargo-test / api-docs-drift gates, but parity now only
# runs on release tags. Direct main commits + PR cycle no longer pay
# the ~20 min parity bill; release tagging still catches regressions
# before publish (release-packages.yml await-tests gate waits on
# this job by name for tag events).
#
# Opt-in: apply the `run-extended-tests` label to a PR, or dispatch
# the workflow manually with `run_extended_tests=true`, to run this
# job on demand. PR authors and maintainers can both apply labels.
if: >-
github.event_name == 'push' ||
(github.event_name == 'workflow_dispatch' && inputs.run_extended_tests) ||
(github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'run-extended-tests'))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
shared-key: "${{ runner.os }}-perry"
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '22'
- name: Build compiler
run: cargo build --release
- name: Run parity tests
run: ./run_parity_tests.sh
- name: Check parity threshold
run: |
set +e
python3 scripts/parity_threshold_gate.py \
--check \
--output-json test-parity/reports/parity_threshold_latest.json \
--output-md test-parity/reports/parity_threshold_latest.md
status=$?
set -e
cat test-parity/reports/parity_threshold_latest.md >> "$GITHUB_STEP_SUMMARY"
exit "$status"
- name: Check for new failures
run: |
REPORT="test-parity/reports/latest.json"
KNOWN="test-parity/known_failures.json"
# Filter empty strings — `run_parity_tests.sh` emits `compile: [""]`
# when there are zero compile failures (a printf+sed quirk in the
# JSON generator), and that empty entry would propagate to a
# spurious "NEW FAILURES: - " line and fail this gate.
jq -r '(.failures.parity // []) + (.failures.compile // []) | .[] | select(. != "")' "$REPORT" | sort -u > /tmp/all_fails.txt
if [[ -f "$KNOWN" ]]; then
# Issue #797 — known_failures.json moved from flat strings to
# structured records. Keep the audit metadata (the `_schema`
# key at the top of the file) out of the test-name set so
# CI doesn't try to match a real test against it.
jq -r 'keys[] | select(. != "_schema")' "$KNOWN" | sort -u > /tmp/known.txt
# Schema sanity check — every non-_schema entry must be an
# object with non-empty `category` and `reason`. Fails the
# build on malformed entries so the format doesn't silently
# drift back to the legacy flat-string shape.
bad="$(jq -r 'to_entries | map(select(.key != "_schema")) | .[] | select((.value | type) != "object" or (.value.category // "") == "" or (.value.reason // "") == "") | .key' "$KNOWN")"
if [[ -n "$bad" ]]; then
echo "Malformed known_failures.json entries (missing category/reason or not an object):"
echo "$bad" | sed 's/^/ - /'
exit 1
fi
else
: > /tmp/known.txt
fi
TOTAL=$(wc -l < /tmp/all_fails.txt | tr -d ' ')
comm -23 /tmp/all_fails.txt /tmp/known.txt > /tmp/new.txt
if [[ -s /tmp/new.txt ]]; then
echo "NEW FAILURES (not in known_failures.json):"
sed 's/^/ - /' /tmp/new.txt
exit 1
fi
echo "All ${TOTAL} failures are known/triaged."
- name: Generate parity matrix trend
run: |
python3 scripts/parity_matrix_trend.py \
--check \
--output-json test-parity/reports/parity_matrix_latest.json \
--output-md test-parity/reports/parity_matrix_latest.md
cat test-parity/reports/parity_matrix_latest.md >> "$GITHUB_STEP_SUMMARY"
- name: Upload parity report
if: always()
uses: actions/upload-artifact@v7
with:
name: parity-report
path: |
test-parity/reports/latest.json
test-parity/reports/parity_threshold_latest.json
test-parity/reports/parity_threshold_latest.md
test-parity/reports/parity_matrix_latest.json
test-parity/reports/parity_matrix_latest.md
# Capture per-test compile stderr written by run_parity_tests.sh into
# `test-parity/output/*.compile_error.log` so the long-tail
# macOS-14-only compile failures (tracked as `ci-env` in
# known_failures.json) can finally be diagnosed by reading the actual
# error message rather than inferring from the test family.
- name: Upload compile-error logs
if: always()
uses: actions/upload-artifact@v7
with:
name: parity-compile-errors-${{ runner.os }}
path: test-parity/output/*.compile_error.log
if-no-files-found: ignore
# ---------------------------------------------------------------------------
# Compile smoke test (all 130+ test files must compile)
# ---------------------------------------------------------------------------
compile-smoke:
# Release-publish decoupling (see `parity` above): aspirational extended
# suite, informational only — does not block package publishing.
continue-on-error: true
# Was macos-14 — moved to ubuntu-latest in v0.5.392. The smoke
# compiles every `test-files/*.ts` with the bare `perry foo.ts -o
# out` path; the auto-optimize cache + clang link steps work
# identically on Linux. The v0.5.385 sha256 sidecar is portable
# via `command -v sha256sum || shasum -a 256`. `xargs -P` is
# GNU on Linux (the macos-14 BSD xargs we tuned for behaves the
# same for our usage). Linux runners are 4-vCPU vs macos-14's 3,
# so could try NJOBS=4, but keeping NJOBS=3 + retry conservatively
# for the cargo auto-optimize race (issue tracked separately).
# 10× billing weight cut.
#
# v0.5.1018: gated to tag pushes only (`github.event_name == 'push'`).
# See the parity job comment above for rationale — release-packages.yml
# still requires this job on tag events before publishing.
#
# Opt-in: `run-extended-tests` PR label or `workflow_dispatch` with
# `run_extended_tests=true` runs this job on demand.
if: >-
github.event_name == 'push' ||
(github.event_name == 'workflow_dispatch' && inputs.run_extended_tests) ||
(github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'run-extended-tests'))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
shared-key: "${{ runner.os }}-perry"
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Build compiler
run: cargo build --release
- name: Issue #945 scalar method IR guard
run: |
PERRY_BIN="$PWD/target/release/perry" \
scripts/run_issue_945_scalar_method_ir_guard.sh
- name: Compile all test files
run: |
set -uo pipefail
export PERRY="$PWD/target/release/perry"
export LOGS_DIR="/tmp/perry_smoke_logs"
# Tests that are known to not compile cleanly under the bare
# `perry foo.ts -o out` smoke path. Sources:
# - test_ui_*: need `--target macos` / `ios-simulator` to pull
# in libperry_ui_*; the no-target compile path doesn't link
# the platform widgets.
# - test_timer: hangs on the runtime event loop under the
# no-arg compile path.
#
# The 11-entry Buffer/typed-array `ci-env` skip family that
# previously lived here (test_gap_buffer_ops, test_buffer_*,
# test_inline_uint8array_param, test_issue_167_*,
# test_issue_227_*, test_gap_fetch_response,
# test_issue_234_blob_methods, etc.) has been removed as of
# PR #239: the actual root cause was a missing
# `module.declare_function("llvm.assume", VOID, &[I1])` in
# `crates/perry-codegen/src/runtime_decls.rs`. Apple Clang
# ≥21 (Xcode 26 / local) auto-recognised the intrinsic;
# Apple Clang 15 (macos-14 runner / Xcode 15.x / LLVM 17)
# errored with `error: use of undefined value '@llvm.assume'`.
# Space-separated skip list (associative arrays require bash
# 4+; macOS-14 ships bash 3.2). Word-boundary match keeps the
# substring lookup safe.
# test_phase2v3_3_show_toast_set_text imports `setText` and
# `showToast` from perry/ui. The cross-platform stubs in
# perry-runtime/src/ui_text_registry.rs ARE meant to make the
# bare-target compile path work (no `--target` flag → host
# build), but the macOS doc-tests + this Linux compile-smoke
# both still fail at link time because the runtime registers
# the macOS-side handler in `perry-ui-macos/src/app_run.rs`,
# which is only linked when `needs_ui = true`. Without
# `--target macos`, perry-ui-macos isn't pulled in, and the
# cross-platform stubs route to a NULL handler → undefined
# symbol. The fix is a separate coordination work item with
# the v3.3 toast/setText worker (PR #322 family); skip-listing
# here unblocks the v9 CI smoke landing without papering over
# the underlying gap.
# test_ramda_user_import intentionally imports a user package
# (`ramda`) through the V8 fallback path. The compile-smoke
# runner does not npm-install optional package fixtures, so the
# strict unresolved-namespace diagnostic is expected here.
# test_take_screenshot imports perry/ui (same `--target gtk4`
# / pre-built libperry_ui_gtk4.a coupling as the test_ui_*
# family above — bare-target compile path doesn't link the
# platform widgets on Linux).
# test_issue_842_side_effect_dynamic_import compiles a barrel
# file that dynamic-imports a sibling helper; the smoke
# harness compiles each .ts standalone with `perry foo.ts -o
# out`, so the helper .o never gets produced and ld fails on
# the unresolved symbol. The test belongs in a multi-file
# integration runner, not the per-file smoke pass.
# test_jose_signverify_roundtrip references `jwtVerify` from
# the jose ext (#1025 sibling work). The bare smoke compile
# path doesn't link the jose-specific runtime symbol — same
# ld-unresolved-reference failure observed on #1038 pre-merge.
# Move to a jose-aware test runner once that crate's CI hook
# is wired up.
# test_ui_on_keydown_smoke / test_issue_1495_image_systemname /
# test_issue_1867_audio_playback / test_issue_2022_canvas_draw_image
# all import `perry/ui` (App/Image/Canvas/loadImage/keydown). Like the
# rest of the test_ui_* / media family above they need `--target
# macos` to link the platform widgets; the bare `perry foo.ts -o out`
# smoke path doesn't pull in libperry_ui_* on Linux, so they fail with
# ld undefined-symbol errors. ci-env, not a Perry codegen bug.
export SKIP_TESTS=" \
test_ui_comprehensive \
test_ui_controls \
test_ui_phase4 \
test_ui_on_keydown_smoke \
test_issue_1495_image_systemname \
test_issue_1867_audio_playback \
test_issue_2022_canvas_draw_image \
test_timer \
test_phase2v3_3_show_toast_set_text \
test_issue_351_media_playback \
test_issue_442_inline_button_bg \
test_issue_538_background_tasks \
test_issue_553_mobile_widgets \
test_issue_556_table_array \
test_issue_556_table_concat \
test_issue_610_foreach \
test_issue_610_smoke \
test_issue_640_navstack_textfield \
test_issue_763_reactive_textfield \
test_issue_764_state_at_module_init \
test_ramda_user_import \
test_take_screenshot \
test_issue_842_side_effect_dynamic_import \
test_jose_signverify_roundtrip \
test_parity_assert \
test_parity_async_hooks \
test_parity_buffer \
test_parity_child_process \
test_parity_cluster \
test_parity_crypto \
test_parity_dgram \
test_parity_diagnostics_channel \
test_parity_decimal \
test_parity_dns \
test_parity_dns_promises \
test_parity_dotenv \
test_parity_events \
test_parity_fs \
test_parity_fs_promises \
test_parity_http \
test_parity_http2 \
test_parity_https \
test_parity_lodash \
test_parity_module \
test_parity_moment \
test_parity_net \
test_parity_path \
test_parity_perf_hooks \
test_parity_process \
test_parity_querystring \
test_parity_readline \
test_parity_readline_promises \
test_parity_stream \
test_parity_stream_consumers \
test_parity_stream_promises \
test_parity_stream_web \
test_parity_sys \
test_parity_test \
test_parity_timers \
test_parity_timers_promises \
test_parity_tls \
test_parity_url \
test_parity_util \
test_parity_validator \
test_parity_worker_threads \
test_parity_zlib "
rm -rf "$LOGS_DIR"
mkdir -p "$LOGS_DIR"
# Worker function. Each test owns a unique marker filename
# (.pass / .fail / .skip) under $LOGS_DIR, so concurrent
# workers never race on the same file. Counts + failure list
# are aggregated below AFTER all workers finish — no shared
# bash-counter state crosses subshell boundaries. Per-test
# stderr is captured to $LOGS_DIR/<name>.compile_error.log so
# the artifact upload step preserves the actual error
# messages (long-tail macOS-14 codegen failures are tracked
# as `ci-env` in test-parity/known_failures.json and are
# otherwise diagnosed by inference, not data).
compile_one() {
local f="$1"
[[ -d "$f" ]] && return 0
local name
name=$(basename "$f" .ts)
if [[ "$SKIP_TESTS" == *" $name "* ]]; then
: > "$LOGS_DIR/${name}.skip"
return 0
fi
local err_log="$LOGS_DIR/${name}.compile_error.log"
# Try once. If perry compile fails, sleep 2s then retry.
# The xargs -P parallel pass can race when two workers both
# need an auto-optimize rebuild of the same feature combo —
# the loser's clang sees a momentarily-missing
# `target/perry-auto-<hash>/release/libperry_runtime.a` and
# bails with `errno=2`. Race window is sub-second so a
# single retry after a brief delay is the cheapest fix
# without serializing the workers entirely. `||` short-
# circuits on first success — the success path is unchanged.
try_compile() {
"$PERRY" "$f" -o "/tmp/perry_smoke_${name}" 2>"$err_log"
}
try_compile && status=0 || status=$?
if [[ $status -ne 0 ]]; then
# Retry-on-race semantics: the xargs -P parallel pass can
# race when two workers both need an auto-optimize rebuild
# of the same feature combo — the loser's clang sees a
# momentarily-missing libperry_runtime.a and bails. A single
# retry after a brief delay is the cheapest fix.
sleep 2
try_compile && status=0 || status=$?
fi
if [[ $status -eq 0 ]]; then
: > "$LOGS_DIR/${name}.pass"
rm -f "/tmp/perry_smoke_${name}" "$err_log"
else
: > "$LOGS_DIR/${name}.fail"
fi
}
export -f compile_one
# ubuntu-latest runners have 4 vCPUs; perry compile is
# CPU-bound for HIR/codegen but waits on the linker (clang)
# for a meaningful chunk of each test. v0.5.384 dropped to
# NJOBS=3 after NJOBS=6 hit a cargo auto-optimize file-lock
# race: two workers rebuilding the same `target/perry-auto-
# <hash>/lib*.a` led to one worker's clang seeing `errno=2`
# mid-link. v0.5.429 closed that race at the source via an
# OS file lock in `commands/compile/optimized_libs.rs::
# build_optimized_libs` (fslock dep — flock on Unix,
# LockFileEx on Windows; serializes per-hash, parallel across
# different hashes). NJOBS=6 is now safe again. Sequential
# baseline was ~26 min; NJOBS=3 → ~10-12 min; NJOBS=6 → ~6-8
# min on a 4-vCPU runner. The retry-once in compile_one stays
# as a belt-and-suspenders safety net for any remaining race
# corner the lock doesn't catch.
NJOBS="${PERRY_SMOKE_JOBS:-6}"
printf '%s\n' test-files/*.ts \
| xargs -P "$NJOBS" -n 1 -I{} bash -c 'compile_one "$@"' _ {}
# Count markers via shopt nullglob + bash array length. Pre-fix
# we used `ls -1 "$LOGS_DIR"/*.fail | wc -l` which fails when
# no matches exist (`ls` exits 1 on missing files), and with
# GH Actions' default `bash -eo pipefail` the failed pipe
# propagates errexit and kills the script BEFORE printing the
# summary line — so a clean run with zero failures still made
# compile-smoke exit 1 (PR #285 / v0.5.379 introduced this).
# nullglob makes an empty glob expand to nothing instead of
# the literal pattern, so the array length is correctly 0.
shopt -s nullglob
pass_files=("$LOGS_DIR"/*.pass)
fail_files=("$LOGS_DIR"/*.fail)
skip_files=("$LOGS_DIR"/*.skip)
PASS=${#pass_files[@]}
FAIL=${#fail_files[@]}
SKIP=${#skip_files[@]}