From 2ec6103c5b6552f6c8d0af1a76ee978d6f4b0e0c Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Sat, 21 Nov 2026 14:53:50 -0300 Subject: [PATCH 1/4] test: run the suite under a wrapper lifetime mode with run_tests.sh --wrapper-lifetime run_tests.sh --wrapper-lifetime [:] passes the build setting NS_TEST_WRAPPER_LIFETIME to xcodebuild. A new TestRunner build phase, "Apply Test App Config" (after Copy Bundle Resources), writes the bundled app/package.json from TestRunner/app/package.json on every build, adding "wrapperLifetime": { mode, scope } when the setting is present. The tracked package.json is never modified, so nothing has to be restored after a failed or interrupted run, and a later default build drops the override even though Xcode skips re-copying the unchanged app folder. After the run, scripts/check-wrapper-lifetime-report.sh fails it unless the junit reports contain "reports the configured mode and scope (/)", the spec that names the mode the runtime actually read. --- README.md | 8 +++ run_tests.sh | 43 +++++++++++++- scripts/check-wrapper-lifetime-report.sh | 70 ++++++++++++++++++++++ tools/apply-test-app-config.mjs | 75 ++++++++++++++++++++++++ v8ios.xcodeproj/project.pbxproj | 22 +++++++ 5 files changed, 216 insertions(+), 2 deletions(-) create mode 100755 scripts/check-wrapper-lifetime-report.sh create mode 100644 tools/apply-test-app-config.mjs diff --git a/README.md b/README.md index 58990240d..a3d481d70 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,14 @@ Runtime initialization took 55ms If all tests pass, everything is good! At this point you can make changes to the runtime, add breakpoints and step through with the debugger. In the next section we'll see how to attach the runtime to an existing NativeScript application allowing us to debug runtime issues in actual apps. +## Running the suite from the command line + +`./run_tests.sh` builds TestRunner, runs the suite on a simulator and leaves the results in `build/tests/`. `./run_tests.sh --help` lists every option; the common ones: + +- `--temp-sim` runs on a throwaway simulator that is deleted afterwards; `--keep-sim` creates (once) and reuses a simulator named after the checkout. +- `-a` / `--asan` runs under AddressSanitizer. +- `--wrapper-lifetime [:]` runs the suite under a wrapper lifetime mode (`resurrecting`, `rooted` or `canary`; scope `extended` or `all`, default `extended`), e.g. `./run_tests.sh --temp-sim --wrapper-lifetime canary:all`. It sets `"wrapperLifetime"` in the built app's `package.json` only; `TestRunner/app/package.json` is left untouched. From `xcodebuild`, pass the build setting `NS_TEST_WRAPPER_LIFETIME=:` instead. + ## Node.js in Xcode builds Building the `NativeScript` target generates the runtime JS builtins with `tools/js2c.mjs`, and building the `TestRunner` target copies jasmine-core from `node_modules` into the test app with `tools/stage-test-runner-deps.mjs`; both need Node.js. Xcode runs build phases with a minimal `PATH` and never reads your shell profile, so a node managed by nvm/fnm/volta/asdf is invisible to it. The build phase instead sources two files from the repo root: diff --git a/run_tests.sh b/run_tests.sh index 51bf0642f..48fb67052 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -295,6 +295,13 @@ Simulator options: Run options: -a, --asan Run under AddressSanitizer (-enableAddressSanitizer YES) + --wrapper-lifetime [:] + Run the suite under a wrapper lifetime mode: the built app's + package.json gets "wrapperLifetime": { mode, scope } (the + source TestRunner/app/package.json is not modified), and the + run fails unless the suite reports that mode. + mode: resurrecting | rooted | canary + scope: extended | all (default: extended) -t, --temp-folder Write results to a random temp folder instead of build/tests/ -h, --help Show this help @@ -320,6 +327,7 @@ SIM_RUNTIME="" DELETE_TARGET="" TEST_FOLDER="" CATALYST=0 +WRAPPER_LIFETIME="" set_sim_mode() { if [ -n "$SIM_MODE" ] && [ "$SIM_MODE" != "$1" ]; then @@ -367,6 +375,8 @@ while [ $# -gt 0 ]; do --list-sims) set_sim_mode "list-sims"; shift ;; --delete-sims) set_sim_mode "delete-sims"; shift ;; --catalyst) CATALYST=1; shift ;; + --wrapper-lifetime|--wrapper-lifetime=*) + take_value "--wrapper-lifetime" "$1" "${2:-}" "$has_next"; WRAPPER_LIFETIME="$OPT_VALUE"; shift "$OPT_SHIFT" ;; -a|--asan) ASAN=1; shift ;; -t|--temp-folder) TEMP_FOLDER=1; shift ;; -h|--help) usage; exit 0 ;; @@ -407,10 +417,23 @@ if { [ -n "$SIM_DEVICE_TYPE" ] || [ -n "$SIM_RUNTIME" ]; } && [ "$CREATES_SIM" - die_usage "--device-type and --runtime only apply when a simulator may be created." fi if [ -n "$SIM_MODE" ] && [ "$SIM_MODE" != "temp-sim" ] && [ "$SIM_MODE" != "keep-sim" ]; then - if [ "$ASAN" -eq 1 ] || [ "$TEMP_FOLDER" -eq 1 ]; then - die_usage "--asan and --temp-folder do not apply to --$SIM_MODE." + if [ "$ASAN" -eq 1 ] || [ "$TEMP_FOLDER" -eq 1 ] || [ -n "$WRAPPER_LIFETIME" ]; then + die_usage "--asan, --temp-folder and --wrapper-lifetime do not apply to --$SIM_MODE." fi fi +if [ -n "$WRAPPER_LIFETIME" ]; then + WL_MODE="${WRAPPER_LIFETIME%%:*}" + WL_SCOPE="extended" + [[ "$WRAPPER_LIFETIME" == *:* ]] && WL_SCOPE="${WRAPPER_LIFETIME#*:}" + case "$WL_MODE" in + resurrecting|rooted|canary) ;; + *) die_usage "--wrapper-lifetime: unknown mode '$WL_MODE' (resurrecting, rooted or canary)." ;; + esac + case "$WL_SCOPE" in + extended|all) ;; + *) die_usage "--wrapper-lifetime: unknown scope '$WL_SCOPE' (extended or all)." ;; + esac +fi sim_label() { local name @@ -562,6 +585,11 @@ if [ "$ASAN" -eq 1 ]; then echo "AddressSanitizer: enabled" XCODEBUILD_ARGS+=(-enableAddressSanitizer YES) fi +if [ -n "$WRAPPER_LIFETIME" ]; then + echo "Wrapper lifetime: $WL_MODE/$WL_SCOPE" + # Read by the TestRunner target's "Apply Test App Config" build phase. + XCODEBUILD_ARGS+=("NS_TEST_WRAPPER_LIFETIME=$WL_MODE:$WL_SCOPE") +fi set -o pipefail xcodebuild -project "$SCRIPT_DIR/v8ios.xcodeproj" -scheme TestRunner \ @@ -582,4 +610,15 @@ if command -v xcparse &>/dev/null; then find "$TEST_FOLDER/test-out" -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx verify-junit-xml fi +if [ -n "$WRAPPER_LIFETIME" ]; then + if ! ls "$TEST_FOLDER"/test-out/*junit*.xml >/dev/null 2>&1 && [ -d "$TEST_FOLDER/test_results.xcresult" ]; then + "$SCRIPT_DIR/scripts/export-test-attachments.sh" --result "$TEST_FOLDER/test_results.xcresult" \ + --output "$TEST_FOLDER/test-out" >/dev/null + fi + if ! "$SCRIPT_DIR/scripts/check-wrapper-lifetime-report.sh" --reports "$TEST_FOLDER/test-out" \ + --expect "$WL_MODE/$WL_SCOPE"; then + [ $TEST_EXIT -ne 0 ] || TEST_EXIT=1 + fi +fi + exit $TEST_EXIT diff --git a/scripts/check-wrapper-lifetime-report.sh b/scripts/check-wrapper-lifetime-report.sh new file mode 100755 index 000000000..d8d4888f1 --- /dev/null +++ b/scripts/check-wrapper-lifetime-report.sh @@ -0,0 +1,70 @@ +#!/bin/bash +# Fails unless the JS suite's junit reports show it ran under the expected +# wrapper lifetime mode and scope. The mode reaches the app through a build +# phase, so a passing suite alone does not prove which mode it exercised; the +# "Wrapper lifetime modes" suite names a spec after the mode the runtime read. +set -euo pipefail + +usage() { + echo "Usage: ./scripts/check-wrapper-lifetime-report.sh --reports --expect /" + echo "" + echo " --reports directory holding the suite's *junit*.xml reports" + echo " --expect / mode and scope the suite must report, e.g. canary/all" + echo " -h, --help show this help" +} + +REPORTS="" +EXPECT="" +while [ $# -gt 0 ]; do + case "$1" in + --reports) + [ $# -ge 2 ] || { echo "--reports needs a value" >&2; usage >&2; exit 1; } + REPORTS="$2" + shift 2 + ;; + --reports=*) REPORTS="${1#*=}"; shift ;; + --expect) + [ $# -ge 2 ] || { echo "--expect needs a value" >&2; usage >&2; exit 1; } + EXPECT="$2" + shift 2 + ;; + --expect=*) EXPECT="${1#*=}"; shift ;; + -h|--help) + usage + exit 0 + ;; + *) + echo "Unknown argument: $1" >&2 + usage >&2 + exit 1 + ;; + esac +done + +if [ -z "$REPORTS" ] || [ -z "$EXPECT" ]; then + echo "--reports and --expect are required" >&2 + usage >&2 + exit 1 +fi + +REPORT_FILES=() +while IFS= read -r -d '' f; do + REPORT_FILES+=("$f") +done < <(find "$REPORTS" -maxdepth 1 -name "*junit*.xml" -print0 2>/dev/null) + +if [ "${#REPORT_FILES[@]}" -eq 0 ]; then + echo "error: no *junit*.xml report in $REPORTS" >&2 + exit 1 +fi + +# Must match the spec title in TestRunner/app/tests/WrapperLifetimeModesTests.js. +NEEDLE="reports the configured mode and scope ($EXPECT)" +if grep -qF "$NEEDLE" "${REPORT_FILES[@]}"; then + echo "Wrapper lifetime: suite ran under $EXPECT" + exit 0 +fi + +echo "error: the suite did not report wrapper lifetime $EXPECT" >&2 +FOUND=$(grep -ohE 'reports the configured mode and scope \([a-z]+/[a-z]+\)' "${REPORT_FILES[@]}" | sort -u || true) +echo " reported: ${FOUND:-no wrapper lifetime mode spec in the reports}" >&2 +exit 1 diff --git a/tools/apply-test-app-config.mjs b/tools/apply-test-app-config.mjs new file mode 100644 index 000000000..8a5e17d5f --- /dev/null +++ b/tools/apply-test-app-config.mjs @@ -0,0 +1,75 @@ +#!/usr/bin/env node +// Writes the TestRunner app's package.json into the built app bundle, with +// per-run overrides applied. Invoked by the TestRunner target's "Apply Test App +// Config" phase, which runs after Copy Bundle Resources. + +import { readFileSync, writeFileSync } from "node:fs"; +import { parseArgs } from "node:util"; + +const MODES = ["resurrecting", "rooted", "canary"]; +const SCOPES = ["extended", "all"]; + +const usage = `Usage: node tools/apply-test-app-config.mjs --source --out [options] + +Writes to , applying the given overrides. + + --source the app's package.json in the source tree + --out the package.json inside the built app bundle + --wrapper-lifetime [:] + set "wrapperLifetime": { mode, scope } + mode: ${MODES.join(" | ")} + scope: ${SCOPES.join(" | ")} (default: extended) + -h, --help show this help`; + +function fail(message) { + console.error(`error: ${message}\n\n${usage}`); + process.exit(1); +} + +let values; +try { + ({ values } = parseArgs({ + options: { + source: { type: "string" }, + out: { type: "string" }, + "wrapper-lifetime": { type: "string" }, + help: { type: "boolean", short: "h" }, + }, + strict: true, + })); +} catch (e) { + fail(e.message); +} +if (values.help) { + console.log(usage); + process.exit(0); +} +if (!values.source || !values.out) { + fail("--source and --out are required"); +} + +const source = readFileSync(values.source, "utf8"); +let output = source; + +const lifetime = values["wrapper-lifetime"]; +if (lifetime !== undefined) { + const [mode, scope = "extended", ...rest] = lifetime.split(":"); + if (rest.length || !MODES.includes(mode) || !SCOPES.includes(scope)) { + fail(`invalid --wrapper-lifetime '${lifetime}'`); + } + const config = JSON.parse(source); + config.wrapperLifetime = { ...config.wrapperLifetime, mode, scope }; + output = `${JSON.stringify(config, null, 4)}\n`; + console.log(`wrapperLifetime: ${mode}/${scope}`); +} + +// The bundle copy is rewritten on every build, override or not: Xcode skips +// re-copying an unchanged app folder, so an override from an earlier build +// would otherwise survive into the next one. +let current = null; +try { + current = readFileSync(values.out, "utf8"); +} catch {} +if (current !== output) { + writeFileSync(values.out, output); +} diff --git a/v8ios.xcodeproj/project.pbxproj b/v8ios.xcodeproj/project.pbxproj index dca5caf46..22c6a2431 100644 --- a/v8ios.xcodeproj/project.pbxproj +++ b/v8ios.xcodeproj/project.pbxproj @@ -1908,6 +1908,7 @@ C2DDEB13229EA89000345BFE /* Frameworks */, 7A51E7C02F00000000000001 /* Stage Test Runner Dependencies */, C2DDEB14229EA89000345BFE /* Resources */, + 7A51E7C02F00000000000002 /* Apply Test App Config */, C2C8EE7722CE54EE001F8CEC /* Embed Frameworks */, ); buildRules = ( @@ -2188,6 +2189,27 @@ shellPath = /bin/sh; shellScript = "set -e\ncd \"${SRCROOT}\"\n[ -f .xcode.env ] && . ./.xcode.env\n[ -f .xcode.env.local ] && . ./.xcode.env.local\nif [ -z \"${NODE_BINARY:-}\" ] || [ ! -x \"${NODE_BINARY:-}\" ]; then\n echo \"error: no usable node for tools/stage-test-runner-deps.mjs (NODE_BINARY='${NODE_BINARY:-}'). Run 'npm run setup-xcode-env' in the runtime repo to record your node in .xcode.env.local\" >&2\n exit 1\nfi\n\"$NODE_BINARY\" tools/stage-test-runner-deps.mjs --out-dir TestRunner/app/Infrastructure/Jasmine/vendor\n"; }; + 7A51E7C02F00000000000002 /* Apply Test App Config */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "$(SRCROOT)/TestRunner/app/package.json", + ); + name = "Apply Test App Config"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(TARGET_BUILD_DIR)/$(UNLOCALIZED_RESOURCES_FOLDER_PATH)/app/package.json", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "set -e\ncd \"${SRCROOT}\"\n[ -f .xcode.env ] && . ./.xcode.env\n[ -f .xcode.env.local ] && . ./.xcode.env.local\nif [ -z \"${NODE_BINARY:-}\" ] || [ ! -x \"${NODE_BINARY:-}\" ]; then\n echo \"error: no usable node for tools/apply-test-app-config.mjs (NODE_BINARY='${NODE_BINARY:-}'). Run 'npm run setup-xcode-env' in the runtime repo to record your node in .xcode.env.local\" >&2\n exit 1\nfi\nset -- --source TestRunner/app/package.json --out \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/app/package.json\"\n# NS_TEST_WRAPPER_LIFETIME=[:] on the xcodebuild command line (run_tests.sh --wrapper-lifetime).\nif [ -n \"${NS_TEST_WRAPPER_LIFETIME:-}\" ]; then\n set -- \"$@\" --wrapper-lifetime \"${NS_TEST_WRAPPER_LIFETIME}\"\nfi\n\"$NODE_BINARY\" tools/apply-test-app-config.mjs \"$@\"\n"; + }; C27E5DB322F31FF800498ED0 /* ShellScript */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; From 42b34ad2318fc00cb8169617b5d85c76b76cb8b1 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Sat, 21 Nov 2026 14:53:51 -0300 Subject: [PATCH 2/4] ci: add a canary/all wrapper lifetime test lane A third entry in the PR test matrix, "Test (canary)", builds and runs the suite like "Test" with NS_TEST_WRAPPER_LIFETIME=canary:all, then checks the junit reports show the suite ran under canary/all. Its compilation cache falls back to the default variant's keys, which main seeds, since the compiled code is the same. --- .github/workflows/pull_request.yml | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 7dfafa7c6..4b9cd64ea 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -85,8 +85,8 @@ jobs: runs-on: macos-15 needs: build strategy: - # The two variants answer different questions; one failing must not - # cancel the other. + # The variants answer different questions; one failing must not cancel + # the others. fail-fast: false matrix: include: @@ -94,12 +94,26 @@ jobs: xcodebuild-args: "" artifact-suffix: "" cache-variant: default + cache-fallback-variant: "" + wrapper-lifetime: "" # Only code compiled here is instrumented: the runtime and the test # fixtures, not the prebuilt V8 archives. - name: Test (ASan) xcodebuild-args: "-enableAddressSanitizer YES" artifact-suffix: "-asan" cache-variant: asan + cache-fallback-variant: "" + wrapper-lifetime: "" + # The same build as "Test" with a different app config, so it can + # start from the default variant's cache (only that one is seeded + # from main). wrapper-lifetime is the "/" the suite + # must report. + - name: Test (canary) + xcodebuild-args: "NS_TEST_WRAPPER_LIFETIME=canary:all" + artifact-suffix: "-canary" + cache-variant: canary + cache-fallback-variant: default + wrapper-lifetime: canary/all steps: - uses: maxim-lobanov/setup-xcode@ed7a3b1fda3918c0306d1b724322adc0b8cc0a90 # v1.7.0 with: @@ -120,7 +134,10 @@ jobs: # A distinct segment per variant: a bare prefix of one would also match # the other's keys. npm_release.yml saves the "default" variant from main. key: xcode-cas-${{ runner.os }}-${{ runner.arch }}-test-${{ matrix.cache-variant }}-${{ github.sha }} - restore-keys: xcode-cas-${{ runner.os }}-${{ runner.arch }}-test-${{ matrix.cache-variant }}- + # actions/cache drops the empty line when there is no fallback. + restore-keys: | + xcode-cas-${{ runner.os }}-${{ runner.arch }}-test-${{ matrix.cache-variant }}- + ${{ matrix.cache-fallback-variant && format('xcode-cas-{0}-{1}-test-{2}-', runner.os, runner.arch, matrix.cache-fallback-variant) || '' }} - name: Enable Xcode compilation cache run: | echo "XCODE_XCCONFIG_FILE=$GITHUB_WORKSPACE/tools/ci-compilation-cache.xcconfig" >> "$GITHUB_ENV" @@ -179,6 +196,11 @@ jobs: ls "$TEST_FOLDER"/test-out/*junit*.xml > /dev/null 2>&1 || { echo "::error::No JUnit report in $TEST_FOLDER/test-out"; exit 1; } find $TEST_FOLDER/test-out -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx junit-cli-report-viewer find $TEST_FOLDER/test-out -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx verify-junit-xml + - name: Validate wrapper lifetime mode + if: ${{ matrix.wrapper-lifetime != '' }} + env: + EXPECTED_WRAPPER_LIFETIME: ${{ matrix.wrapper-lifetime }} + run: ./scripts/check-wrapper-lifetime-report.sh --reports "$TEST_FOLDER/test-out" --expect "$EXPECTED_WRAPPER_LIFETIME" - name: Collect test diagnostics if: failure() uses: ./.github/actions/collect-test-diagnostics From 956ad7a3f0630647daa4a5ddd31d777bd45b349c Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Sat, 21 Nov 2026 17:00:24 -0300 Subject: [PATCH 3/4] ci: run the canary/all wrapper lifetime pass inside the Test job Replace the separate "Test (canary)" matrix entry, which rebuilt the app on its own runner, with a second pass in the "Test" job on the same build. Both matrix entries now build once with build-for-testing and run the suite with test-without-building, keeping the retry policy and result bundles. When a matrix entry sets wrapper-lifetime-pass, tools/apply-test-app-config.mjs rewrites the built app's app/package.json and the suite runs again with test-without-building, which runs no build phases, so the rewrite holds. The simulator installs the rewritten bundle without re-signing. That pass has its own result folder, retry, junit export, report summary and validation, including check-wrapper-lifetime-report.sh, and runs even when the default pass failed. Its xcresults go into the job's test-results artifact. The canary cache variant and its restore-key fallback are gone; the cache keys match main again. --- .github/workflows/pull_request.yml | 97 +++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 30 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 4b9cd64ea..af2ee1f13 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -85,35 +85,28 @@ jobs: runs-on: macos-15 needs: build strategy: - # The variants answer different questions; one failing must not cancel - # the others. + # The two variants answer different questions; one failing must not + # cancel the other. fail-fast: false matrix: include: + # wrapper-lifetime-pass: ":" to run the suite a second + # time, on the same build, under that wrapper lifetime mode. - name: Test xcodebuild-args: "" artifact-suffix: "" cache-variant: default - cache-fallback-variant: "" - wrapper-lifetime: "" + wrapper-lifetime-pass: "canary:all" # Only code compiled here is instrumented: the runtime and the test # fixtures, not the prebuilt V8 archives. - name: Test (ASan) xcodebuild-args: "-enableAddressSanitizer YES" artifact-suffix: "-asan" cache-variant: asan - cache-fallback-variant: "" - wrapper-lifetime: "" - # The same build as "Test" with a different app config, so it can - # start from the default variant's cache (only that one is seeded - # from main). wrapper-lifetime is the "/" the suite - # must report. - - name: Test (canary) - xcodebuild-args: "NS_TEST_WRAPPER_LIFETIME=canary:all" - artifact-suffix: "-canary" - cache-variant: canary - cache-fallback-variant: default - wrapper-lifetime: canary/all + wrapper-lifetime-pass: "" + env: + # Must match the simulator named in "Wait for the test simulator". + TEST_DESTINATION: "platform=iOS Simulator,OS=latest,name=iPhone 16 Pro" steps: - uses: maxim-lobanov/setup-xcode@ed7a3b1fda3918c0306d1b724322adc0b8cc0a90 # v1.7.0 with: @@ -134,10 +127,7 @@ jobs: # A distinct segment per variant: a bare prefix of one would also match # the other's keys. npm_release.yml saves the "default" variant from main. key: xcode-cas-${{ runner.os }}-${{ runner.arch }}-test-${{ matrix.cache-variant }}-${{ github.sha }} - # actions/cache drops the empty line when there is no fallback. - restore-keys: | - xcode-cas-${{ runner.os }}-${{ runner.arch }}-test-${{ matrix.cache-variant }}- - ${{ matrix.cache-fallback-variant && format('xcode-cas-{0}-{1}-test-{2}-', runner.os, runner.arch, matrix.cache-fallback-variant) || '' }} + restore-keys: xcode-cas-${{ runner.os }}-${{ runner.arch }}-test-${{ matrix.cache-variant }}- - name: Enable Xcode compilation cache run: | echo "XCODE_XCCONFIG_FILE=$GITHUB_WORKSPACE/tools/ci-compilation-cache.xcconfig" >> "$GITHUB_ENV" @@ -150,25 +140,28 @@ jobs: run: | mkdir -p dist-test echo TEST_FOLDER=$(pwd)/dist-test >> $GITHUB_ENV - # Must match the simulator named in the Xcode Tests -destination. + # Must match the simulator named in TEST_DESTINATION. - name: Wait for the test simulator run: ./scripts/wait-for-simulator.sh --name "iPhone 16 Pro" + - name: Build for testing + id: build-for-testing + run: set -o pipefail && xcodebuild -project v8ios.xcodeproj -scheme TestRunner -destination "$TEST_DESTINATION" ${{ matrix.xcodebuild-args }} build-for-testing | xcpretty - name: Xcode Tests uses: nick-fields/retry@ad984534de44a9489a53aefd81eb77f87c70dc60 # v4.0.0 # try to run the tests with xcpretty. If it fails then try again without xcpretty twice for better log output # the xcode tests are a bit flaky and they should never fail on this step, as this step only collects the JS test results as junit xml with: - # Build (~10m) + the runtime suite's report-wait (up to 10m, see - # TestRunnerTests.swift) need more than 20m headroom per attempt. - timeout_minutes: 40 + # The runtime suite's report-wait alone can take 10m (see + # TestRunnerTests.swift), plus app install and launch. + timeout_minutes: 25 max_attempts: 2 - command: set -o pipefail && xcodebuild -project v8ios.xcodeproj -scheme TestRunner -resultBundlePath $TEST_FOLDER/test_results -destination platform\=iOS\ Simulator,OS\=latest,name\=iPhone\ 16\ Pro ${{ matrix.xcodebuild-args }} test | xcpretty + command: set -o pipefail && xcodebuild -project v8ios.xcodeproj -scheme TestRunner -resultBundlePath $TEST_FOLDER/test_results -destination "$TEST_DESTINATION" ${{ matrix.xcodebuild-args }} test-without-building | xcpretty # Keep the failed attempt's bundle — it holds the diagnostics of the # failure being retried. Everything else at the result path must go # (including extensionless staging leftovers), or the retry dies with # "Existing file at -resultBundlePath". on_retry_command: rm -rf $TEST_FOLDER/test_results_attempt1.xcresult; mv $TEST_FOLDER/test_results.xcresult $TEST_FOLDER/test_results_attempt1.xcresult 2>/dev/null; for f in $TEST_FOLDER/test_results*; do [ "$f" = "$TEST_FOLDER/test_results_attempt1.xcresult" ] || rm -rf "$f"; done; xcrun simctl shutdown all - new_command_on_retry: xcodebuild -project v8ios.xcodeproj -scheme TestRunner -resultBundlePath $TEST_FOLDER/test_results -destination platform\=iOS\ Simulator,OS\=latest,name\=iPhone\ 16\ Pro ${{ matrix.xcodebuild-args }} test + new_command_on_retry: xcodebuild -project v8ios.xcodeproj -scheme TestRunner -resultBundlePath $TEST_FOLDER/test_results -destination "$TEST_DESTINATION" ${{ matrix.xcodebuild-args }} test-without-building - name: Xcode compilation cache size if: ${{ !cancelled() }} run: du -sh "$NS_COMPILATION_CACHE_DIR" || true @@ -196,11 +189,53 @@ jobs: ls "$TEST_FOLDER"/test-out/*junit*.xml > /dev/null 2>&1 || { echo "::error::No JUnit report in $TEST_FOLDER/test-out"; exit 1; } find $TEST_FOLDER/test-out -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx junit-cli-report-viewer find $TEST_FOLDER/test-out -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx verify-junit-xml - - name: Validate wrapper lifetime mode - if: ${{ matrix.wrapper-lifetime != '' }} + # Second pass: the same build with "wrapperLifetime" set in the built + # app's package.json. It runs whatever the first pass's outcome, so a + # default-mode failure still yields this pass's results and diagnostics. + # test-without-building runs no build phases, so the rewrite stands. + - name: Configure the built app for the wrapper lifetime pass + id: wrapper-lifetime-app + if: ${{ !cancelled() && matrix.wrapper-lifetime-pass != '' && steps.build-for-testing.outcome == 'success' }} env: - EXPECTED_WRAPPER_LIFETIME: ${{ matrix.wrapper-lifetime }} - run: ./scripts/check-wrapper-lifetime-report.sh --reports "$TEST_FOLDER/test-out" --expect "$EXPECTED_WRAPPER_LIFETIME" + WRAPPER_LIFETIME: ${{ matrix.wrapper-lifetime-pass }} + run: | + APP="$(find build -maxdepth 2 -type d -path 'build/*-iphonesimulator/TestRunner.app')" + [ -n "$APP" ] && [ "$(printf '%s\n' "$APP" | wc -l)" -eq 1 ] || { echo "::error::Expected one built TestRunner.app under build/, found: ${APP:-none}"; exit 1; } + node tools/apply-test-app-config.mjs --source TestRunner/app/package.json --out "$APP/app/package.json" --wrapper-lifetime "$WRAPPER_LIFETIME" + echo "WL_TEST_FOLDER=$TEST_FOLDER/wrapper-lifetime" >> "$GITHUB_ENV" + mkdir -p "$TEST_FOLDER/wrapper-lifetime" + - name: Xcode Tests (wrapper lifetime ${{ matrix.wrapper-lifetime-pass }}) + if: ${{ !cancelled() && steps.wrapper-lifetime-app.outcome == 'success' }} + uses: nick-fields/retry@ad984534de44a9489a53aefd81eb77f87c70dc60 # v4.0.0 + with: + timeout_minutes: 25 + max_attempts: 2 + command: set -o pipefail && xcodebuild -project v8ios.xcodeproj -scheme TestRunner -resultBundlePath $WL_TEST_FOLDER/test_results -destination "$TEST_DESTINATION" ${{ matrix.xcodebuild-args }} test-without-building | xcpretty + on_retry_command: rm -rf $WL_TEST_FOLDER/test_results_attempt1.xcresult; mv $WL_TEST_FOLDER/test_results.xcresult $WL_TEST_FOLDER/test_results_attempt1.xcresult 2>/dev/null; for f in $WL_TEST_FOLDER/test_results*; do [ "$f" = "$WL_TEST_FOLDER/test_results_attempt1.xcresult" ] || rm -rf "$f"; done; xcrun simctl shutdown all + new_command_on_retry: xcodebuild -project v8ios.xcodeproj -scheme TestRunner -resultBundlePath $WL_TEST_FOLDER/test_results -destination "$TEST_DESTINATION" ${{ matrix.xcodebuild-args }} test-without-building + - name: Extract test results (wrapper lifetime) + if: ${{ !cancelled() && steps.wrapper-lifetime-app.outcome == 'success' }} + run: | + if [ -d "$WL_TEST_FOLDER/test_results.xcresult" ]; then + ./scripts/export-test-attachments.sh --result "$WL_TEST_FOLDER/test_results.xcresult" --output "$WL_TEST_FOLDER/test-out" + fi + - name: Test report summary (wrapper lifetime) + if: ${{ !cancelled() && steps.wrapper-lifetime-app.outcome == 'success' }} + uses: mikepenz/action-junit-report@6ef3fdcfcd5f0b5d14df3e659ef19b8c6820f93d # v6.6.1 + with: + check_name: JUnit Test Report (wrapper lifetime ${{ matrix.wrapper-lifetime-pass }}) + report_paths: dist-test/wrapper-lifetime/test-out/*junit*.xml + annotate_only: true + detailed_summary: true + - name: Validate Test Results (wrapper lifetime) + if: ${{ !cancelled() && steps.wrapper-lifetime-app.outcome == 'success' }} + env: + WRAPPER_LIFETIME: ${{ matrix.wrapper-lifetime-pass }} + run: | + ls "$WL_TEST_FOLDER"/test-out/*junit*.xml > /dev/null 2>&1 || { echo "::error::No JUnit report in $WL_TEST_FOLDER/test-out"; exit 1; } + find $WL_TEST_FOLDER/test-out -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx junit-cli-report-viewer + find $WL_TEST_FOLDER/test-out -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx verify-junit-xml + ./scripts/check-wrapper-lifetime-report.sh --reports "$WL_TEST_FOLDER/test-out" --expect "${WRAPPER_LIFETIME/:/\/}" - name: Collect test diagnostics if: failure() uses: ./.github/actions/collect-test-diagnostics @@ -215,6 +250,8 @@ jobs: path: | ${{env.TEST_FOLDER}}/test_results.xcresult ${{env.TEST_FOLDER}}/test_results_attempt1.xcresult + ${{env.TEST_FOLDER}}/wrapper-lifetime/test_results.xcresult + ${{env.TEST_FOLDER}}/wrapper-lifetime/test_results_attempt1.xcresult test-catalyst: name: Test (Mac Catalyst) runs-on: macos-15 From 3a6b21d93c3336dd8060598f7ba1d7535e3561c8 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Sun, 22 Nov 2026 16:40:02 -0300 Subject: [PATCH 4/4] ci: boot the test simulator during the build, and fix the wrapper lifetime pass's mode check test-without-building no longer overlaps the simulator boot with the build the way a single test action did, so the first pass spent about six minutes preparing a cold device. wait-for-simulator.sh --boot starts the boot in the background once the device is listed. The pass's mode check compared against "canary\/all": bash kept the backslash of the ${var/:/\/} replacement. tr builds the expected "/" instead. Rewriting the built app's package.json breaks the bundle's seal; the pass re-seals it ad hoc, keeping its entitlements, before installing it. --- .github/workflows/pull_request.yml | 9 +++++++-- scripts/wait-for-simulator.sh | 14 +++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index af2ee1f13..3f4941b47 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -141,8 +141,10 @@ jobs: mkdir -p dist-test echo TEST_FOLDER=$(pwd)/dist-test >> $GITHUB_ENV # Must match the simulator named in TEST_DESTINATION. + # --boot leaves the simulator booting in the background, so the boot + # overlaps build-for-testing instead of delaying the first test run. - name: Wait for the test simulator - run: ./scripts/wait-for-simulator.sh --name "iPhone 16 Pro" + run: ./scripts/wait-for-simulator.sh --name "iPhone 16 Pro" --boot - name: Build for testing id: build-for-testing run: set -o pipefail && xcodebuild -project v8ios.xcodeproj -scheme TestRunner -destination "$TEST_DESTINATION" ${{ matrix.xcodebuild-args }} build-for-testing | xcpretty @@ -202,6 +204,9 @@ jobs: APP="$(find build -maxdepth 2 -type d -path 'build/*-iphonesimulator/TestRunner.app')" [ -n "$APP" ] && [ "$(printf '%s\n' "$APP" | wc -l)" -eq 1 ] || { echo "::error::Expected one built TestRunner.app under build/, found: ${APP:-none}"; exit 1; } node tools/apply-test-app-config.mjs --source TestRunner/app/package.json --out "$APP/app/package.json" --wrapper-lifetime "$WRAPPER_LIFETIME" + # Rewriting a resource breaks the bundle's seal; re-seal it ad hoc, + # keeping the build's entitlements. + codesign --force --sign - --timestamp=none --preserve-metadata=entitlements "$APP" echo "WL_TEST_FOLDER=$TEST_FOLDER/wrapper-lifetime" >> "$GITHUB_ENV" mkdir -p "$TEST_FOLDER/wrapper-lifetime" - name: Xcode Tests (wrapper lifetime ${{ matrix.wrapper-lifetime-pass }}) @@ -235,7 +240,7 @@ jobs: ls "$WL_TEST_FOLDER"/test-out/*junit*.xml > /dev/null 2>&1 || { echo "::error::No JUnit report in $WL_TEST_FOLDER/test-out"; exit 1; } find $WL_TEST_FOLDER/test-out -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx junit-cli-report-viewer find $WL_TEST_FOLDER/test-out -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx verify-junit-xml - ./scripts/check-wrapper-lifetime-report.sh --reports "$WL_TEST_FOLDER/test-out" --expect "${WRAPPER_LIFETIME/:/\/}" + ./scripts/check-wrapper-lifetime-report.sh --reports "$WL_TEST_FOLDER/test-out" --expect "$(printf '%s' "$WRAPPER_LIFETIME" | tr ':' '/')" - name: Collect test diagnostics if: failure() uses: ./.github/actions/collect-test-diagnostics diff --git a/scripts/wait-for-simulator.sh b/scripts/wait-for-simulator.sh index a575913fa..5cec7a983 100755 --- a/scripts/wait-for-simulator.sh +++ b/scripts/wait-for-simulator.sh @@ -7,15 +7,17 @@ set -euo pipefail usage() { - echo "Usage: ./scripts/wait-for-simulator.sh --name [--timeout ]" + echo "Usage: ./scripts/wait-for-simulator.sh --name [--timeout ] [--boot]" echo "" echo " --name simulator device name, e.g. \"iPhone 16 Pro\"" echo " --timeout give up after this long (default: 300)" + echo " --boot once found, start booting it in the background and return" echo " -h, --help show this help" } NAME="" TIMEOUT=300 +BOOT=0 while [ $# -gt 0 ]; do case "$1" in --name) @@ -36,6 +38,10 @@ while [ $# -gt 0 ]; do TIMEOUT="${1#--timeout=}" shift ;; + --boot) + BOOT=1 + shift + ;; -h|--help) usage exit 0 @@ -79,6 +85,12 @@ while :; do found="$(find_device || true)" if [ -n "$found" ]; then echo "Found simulator \"$NAME\": $found (after ${SECONDS}s)" + if [ "$BOOT" -eq 1 ]; then + # Detached so later steps (the build) run while it boots; xcodebuild + # waits for a booting device on its own. + nohup xcrun simctl bootstatus "${found%% *}" -b > /dev/null 2>&1 & + echo "Booting ${found%% *} in the background" + fi exit 0 fi if [ "$SECONDS" -ge "$deadline" ]; then