diff --git a/.github/workflows/collection-native-tests.yml b/.github/workflows/collection-native-tests.yml index 9af92c808..2c122ce8a 100644 --- a/.github/workflows/collection-native-tests.yml +++ b/.github/workflows/collection-native-tests.yml @@ -2,12 +2,26 @@ name: Collection native candidate tests on: workflow_dispatch: inputs: + platform: + description: Choose the native journey to run + type: choice + required: true + options: [android, ios] + default: android candidate_run_id: description: GitHub Actions run containing a candidate APK built from this exact SHA required: false artifact_name: description: Artifact containing one standalone APK with localhost HTTP enabled for the fixture API required: false + pull_request: + types: [ready_for_review] + branches: [main] + paths: + - .github/workflows/collection-native-tests.yml + - apps/collection/scripts/test-native-ios.sh + - apps/collection/scripts/check-native-ios-ledger.mjs + - apps/collection/test/native/ios-ledger.test.mjs permissions: contents: read actions: read @@ -16,21 +30,37 @@ defaults: shell: bash jobs: validate: + if: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.id == github.event.repository.id) }} + permissions: + contents: read runs-on: ubuntu-24.04 steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + ref: ${{ github.event.pull_request.head.sha || github.sha }} + persist-credentials: false - name: Test native input and state assertion guards + if: github.event_name == 'workflow_dispatch' run: python3 -m unittest discover -s apps/collection/test/native -p '*_test.py' - - env: + - name: Test iOS outage and retry evidence checks + if: github.event_name == 'pull_request' || inputs.platform == 'ios' + run: node --test apps/collection/test/native/ios-ledger.test.mjs + - if: github.event_name == 'workflow_dispatch' + env: + PLATFORM: ${{ inputs.platform }} RUN_ID: ${{ inputs.candidate_run_id }} ARTIFACT: ${{ inputs.artifact_name }} run: | + if [[ "$PLATFORM" == ios && ( -n "$RUN_ID" || -n "$ARTIFACT" ) ]]; then + echo "The iOS simulator builds its own synthetic candidate; APK inputs are Android-only." + exit 1 + fi if [[ -n "$RUN_ID" || -n "$ARTIFACT" ]]; then [[ "$RUN_ID" =~ ^[0-9]+$ ]] && test -n "$ARTIFACT" fi build: needs: validate - if: inputs.candidate_run_id == '' && inputs.artifact_name == '' + if: github.event_name == 'workflow_dispatch' && inputs.platform == 'android' && inputs.candidate_run_id == '' && inputs.artifact_name == '' runs-on: ubuntu-24.04 timeout-minutes: 45 steps: @@ -64,7 +94,7 @@ jobs: retention-days: 14 android: needs: [validate, build] - if: ${{ always() && needs.validate.result == 'success' && (needs.build.result == 'success' || (needs.build.result == 'skipped' && inputs.candidate_run_id != '' && inputs.artifact_name != '')) }} + if: ${{ always() && github.event_name == 'workflow_dispatch' && inputs.platform == 'android' && needs.validate.result == 'success' && (needs.build.result == 'success' || (needs.build.result == 'skipped' && inputs.candidate_run_id != '' && inputs.artifact_name != '')) }} runs-on: ubuntu-24.04 timeout-minutes: 30 steps: @@ -127,3 +157,44 @@ jobs: name: collection-native-results-${{ github.sha }} path: apps/collection/.maestro/results/ retention-days: 14 + ios: + needs: validate + if: ${{ (github.event_name == 'workflow_dispatch' && inputs.platform == 'ios') || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.id == github.event.repository.id) }} + # Official GitHub-hosted public preview. Actionlint 1.7.12's static label + # list predates it, so keep the published label as a fixed expression. + runs-on: ${{ 'xcode-27' }} + permissions: + contents: read + env: + LOVAT_EXPECTED_SOURCE_SHA: ${{ github.event.pull_request.head.sha || github.sha }} + timeout-minutes: 60 + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + ref: ${{ env.LOVAT_EXPECTED_SOURCE_SHA }} + persist-credentials: false + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 + with: + node-version: 24.6.0 + - uses: actions/setup-java@cf277c60eb25467037889841efdb72551f06f6c3 # v4.9.1 + with: + distribution: temurin + java-version: 17 + - run: npm ci + working-directory: apps/collection + - name: Install pinned Maestro + run: | + curl --fail --location --max-time 180 https://github.com/mobile-dev-inc/maestro/releases/download/cli-2.12.1/maestro.zip -o "$RUNNER_TEMP/maestro-ios.zip" + unzip -q "$RUNNER_TEMP/maestro-ios.zip" -d "$RUNNER_TEMP" + echo "$RUNNER_TEMP/maestro/bin" >> "$GITHUB_PATH" + - name: Build and exercise the installed simulator candidate + timeout-minutes: 50 + env: + LOVAT_DISPOSABLE_BUILD: "1" + run: bash apps/collection/scripts/test-native-ios.sh + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + if: always() + with: + name: collection-native-ios-results-${{ env.LOVAT_EXPECTED_SOURCE_SHA }} + path: apps/collection/.maestro/results/ios/ + retention-days: 14 diff --git a/apps/collection/.maestro/bootstrap.yaml b/apps/collection/.maestro/bootstrap.yaml index dd82c2a87..f960f31d2 100644 --- a/apps/collection/.maestro/bootstrap.yaml +++ b/apps/collection/.maestro/bootstrap.yaml @@ -3,9 +3,44 @@ appId: com.frc8033.lovatcollection - launchApp: clearState: true - openLink: "lovat-collection://set-url?u=http%3A%2F%2F127.0.0.1%3A9877" -- tapOn: - text: "OK" - optional: true +# The first-use handoff can take longer to appear than runFlow's condition wait. +- runFlow: + when: + platform: iOS + commands: + - extendedWaitUntil: + visible: '^(Open in [“"]Collection[”"][?]|API URL updated)$' + timeout: 30000 + - runFlow: + when: + visible: '^Open in [“"]Collection[”"][?]$' + commands: + - tapOn: "^Open$" + # iOS can dismiss the handoff without surfacing the route's alert. + # Give the first delivery time, then resend only from the welcome screen. + - extendedWaitUntil: + visible: "^API URL updated$" + timeout: 3000 + optional: true + - runFlow: + when: + visible: "^Begin$" + notVisible: '^(Open in [“"]Collection[”"][?]|API URL updated)$' + commands: + - openLink: "lovat-collection://set-url?u=http%3A%2F%2F127.0.0.1%3A9877" + - extendedWaitUntil: + visible: "^API URL updated$" + timeout: 30000 + - tapOn: "^OK$" + - assertNotVisible: "^API URL updated$" + - assertVisible: "^Begin$" +- runFlow: + when: + platform: Android + commands: + - tapOn: + text: "OK" + optional: true - tapOn: "Begin" - tapOn: "Code" - inputText: "SYNTHETIC" @@ -15,7 +50,7 @@ appId: com.frc8033.lovatcollection timeout: 20000 - tapOn: "Synthetic Scout" - extendedWaitUntil: - visible: "2026 Synthetic Event" + visible: "^2026 Synthetic Event(, Local fixture)?$" timeout: 20000 -- tapOn: "2026 Synthetic Event" +- tapOn: "^2026 Synthetic Event(, Local fixture)?$" - assertVisible: "Scout this match" diff --git a/apps/collection/.maestro/end-match.yaml b/apps/collection/.maestro/end-match.yaml index 50c36b9db..b660a9d1f 100644 --- a/apps/collection/.maestro/end-match.yaml +++ b/apps/collection/.maestro/end-match.yaml @@ -2,3 +2,9 @@ appId: com.frc8033.lovatcollection --- - tapOn: "End match" - tapOn: "End match" +# Match controls are landscape; the post-match form uses portrait. +- runFlow: + when: + platform: iOS + commands: + - setOrientation: PORTRAIT diff --git a/apps/collection/.maestro/enter-game.yaml b/apps/collection/.maestro/enter-game.yaml index 20c0d59d8..8e1d72856 100644 --- a/apps/collection/.maestro/enter-game.yaml +++ b/apps/collection/.maestro/enter-game.yaml @@ -1,6 +1,12 @@ appId: com.frc8033.lovatcollection --- - tapOn: "Scout this match" +# On iOS the app rotates its interface, but XCUITest can remain in portrait. +- runFlow: + when: + platform: iOS + commands: + - setOrientation: LANDSCAPE_LEFT - extendedWaitUntil: visible: "Start position Hub" timeout: 20000 diff --git a/apps/collection/.maestro/offline-restart.yaml b/apps/collection/.maestro/offline-restart.yaml index 29cc574ca..e8a9e610a 100644 --- a/apps/collection/.maestro/offline-restart.yaml +++ b/apps/collection/.maestro/offline-restart.yaml @@ -13,6 +13,16 @@ appId: com.frc8033.lovatcollection - launchApp: clearState: false - tapOn: "history" -- tapOn: - text: ".*1234.*" +- runFlow: + when: + platform: Android + commands: + - tapOn: + text: ".*1234.*" +- runFlow: + when: + platform: iOS + commands: + - tapOn: "^(Qualifier 1, )?1234 • .+$" + - assertVisible: "^1234 in Q1$" - assertVisible: "Upload" diff --git a/apps/collection/.maestro/reconnect.yaml b/apps/collection/.maestro/reconnect.yaml index 1fd41ccb0..1e570c3d7 100644 --- a/apps/collection/.maestro/reconnect.yaml +++ b/apps/collection/.maestro/reconnect.yaml @@ -1,5 +1,10 @@ appId: com.frc8033.lovatcollection --- +- runFlow: + when: + platform: iOS + commands: + - assertVisible: "^1234 in Q1$" - tapOn: "Upload" - extendedWaitUntil: notVisible: "Uploading" @@ -9,8 +14,18 @@ appId: com.frc8033.lovatcollection - launchApp: clearState: false - tapOn: "history" -- tapOn: - text: ".*1234.*" +- runFlow: + when: + platform: Android + commands: + - tapOn: + text: ".*1234.*" +- runFlow: + when: + platform: iOS + commands: + - tapOn: "^(Qualifier 1, )?1234 • .+$" + - assertVisible: "^1234 in Q1$" - assertNotVisible: "Upload" - tapOn: "Back" - tapOn: "Back" diff --git a/apps/collection/README.md b/apps/collection/README.md index 1d9ef9dab..b537e92cf 100644 --- a/apps/collection/README.md +++ b/apps/collection/README.md @@ -108,7 +108,7 @@ Tests execute real Zustand stores, AsyncStorage persistence, report serializatio The manual **Collection native candidate tests** workflow can build a fresh standalone synthetic Android APK when both inputs are empty, or accepts an APK artifact run/name and requires that artifact's source SHA to match the selected workflow revision. A failed native flow fails the workflow and retains JUnit/logs. It is a candidate/release check, not a required PR test until Android build stability is proven (LVT-217). The test build runs locally on GitHub with template test signing and loopback-only -fixture networking; it does not start cloud builds or publish releases. Use the existing `native-smoke-ios` EAS simulator profile for iOS candidates; run the same flows with a reachable local fixture, omitting Android airplane/ADB commands. iOS has no simulator airplane mode. +fixture networking; it does not start EAS builds or publish releases. Select `platform: ios` with no APK inputs to build and run the same journey on a clean GitHub iOS simulator. The simulator verifies a loopback API outage and app restart, not physical airplane mode, camera/QR or signed-device acceptance. Before a release, the release owner must run the candidate checks and record the build SHA/version, then manually verify camera permission grant/deny, physical-device multi-code QR transfer, background/restart persistence, and the iOS system/browser permission prompts. Unit/component tests do not claim to validate native camera, signing, installation or permissions. Native flows require a candidate device/build and are documented separately from the automated Pages suite. Related: LVT-259/260/261/262 and LVT-273. diff --git a/apps/collection/docs/manual-release-checks.md b/apps/collection/docs/manual-release-checks.md index dc09ae5f9..bc140b0c6 100644 --- a/apps/collection/docs/manual-release-checks.md +++ b/apps/collection/docs/manual-release-checks.md @@ -59,18 +59,24 @@ The Android runner verifies airplane/offline, real process restart, saved Histor reconnect/retry and one preserved UUID. Failures remain failures, with diagnostics. Do not use a personal device: bootstrap intentionally clears app storage. -For iOS, build the existing `native-smoke-ios` EAS simulator profile with Xcode 27 -from that same source SHA, record the run URL, version and artifact hash, install -on a disposable simulator, and run `.maestro/bootstrap.yaml`, -`.maestro/enter-game.yaml`, `.maestro/record-match.yaml`, `.maestro/end-match.yaml`, -`.maestro/offline-restart.yaml` and `.maestro/reconnect.yaml` in that order, -each in a separate Maestro invocation against the synthetic fixture -(`node test/native/fixture-api.mjs`). Stop the fixture before `enter-game.yaml` -and restart it before reconnect; iOS simulators have no airplane-mode API. -Retain Maestro JUnit/screenshots and the fixture submission ledger. This iOS -procedure is a pending operator check until its actual build/run evidence is -attached; a build profile alone is not a passed native test. Physical-device -rows above still apply after a simulator pass. +For iOS, dispatch the same workflow with `platform: ios` and leave the APK +inputs blank. It builds an unsigned, standalone app at the selected SHA and +installs it on a fresh iOS 27 simulator. The app records a synthetic report +while the loopback fixture is stopped, shows the upload failure and retains +the report across a process restart. Reconnect must submit exactly once with +the same UUID recorded before the outage. Retain the run, build hashes, +Maestro JUnit, screenshots and fixture ledger. + +The [GitHub Xcode 27 runner](https://github.com/actions/runner-images/blob/main/README.md) +is a public preview; runner availability is not a pass. This proves a +simulator endpoint outage and restart, not airplane mode, local-network +permission prompts, camera/QR transfer or a signed install/upgrade. Those +physical-device rows still apply even after a simulator pass. + +For changes to the iOS harness, marking a same-repository PR ready for +review can also run the iOS job against its exact head commit. This is +optional evidence, not a required PR check; it never starts Android and +does not rerun on every push. A release candidate still needs its own run. On Android CI, `scripts/prepare-native-android.py` runs before the shared `record-match.yaml` and `end-match.yaml` Maestro flows. It acknowledges only @@ -86,6 +92,7 @@ assertion. Outpost intake exists in every phase, so the flow does not race the real Auto timer. Failed idle capture cannot reuse an old snapshot. Each stage retains its JUnit result and diagnostics. -If CI cannot boot/install, attach its failure and run the same journey on a -physical test device. Record that separate result explicitly. Attach redacted -synthetic screenshots only; never publish real notes, strategy or login tokens. +If CI cannot boot/install, keep the simulator check pending and attach its +failure. Run and record the appropriate physical-device matrix separately. +Attach redacted synthetic screenshots only; never publish real notes, +strategy or login tokens. diff --git a/apps/collection/package-lock.json b/apps/collection/package-lock.json index 31f5078a7..96b6cb702 100644 --- a/apps/collection/package-lock.json +++ b/apps/collection/package-lock.json @@ -12,7 +12,7 @@ "@react-native-async-storage/async-storage": "2.2.0", "@react-native-community/datetimepicker": "9.2.1", "@react-native-community/slider": "5.2.1", - "@react-native-menu/menu": "^2.0.0", + "@react-native-menu/menu": "2.1.2", "@react-native-picker/picker": "2.11.4", "@types/react": "~19.3.0", "expo": "~58.0.26", @@ -5813,9 +5813,9 @@ } }, "node_modules/@react-native-menu/menu": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@react-native-menu/menu/-/menu-2.0.0.tgz", - "integrity": "sha512-hb8Mirw6aKPGONhgo52IiNpwHtISVrgCT3rMdFX1qS7eOFNzOcQh8d2UDnaH5zVpxN+QuvWtaaiRMGFpIjzdtA==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@react-native-menu/menu/-/menu-2.1.2.tgz", + "integrity": "sha512-Am/1HMt21CL+jr/fLTDWCddAUQYpMe8NpVSZrEbITXEMOaNxQqfNGApkuOY72hjV92aR7L7OHuqXLaqrlXZfOA==", "license": "MIT", "peerDependencies": { "react": "*", diff --git a/apps/collection/package.json b/apps/collection/package.json index fc18ce12a..da9a831d1 100644 --- a/apps/collection/package.json +++ b/apps/collection/package.json @@ -35,7 +35,7 @@ "@react-native-async-storage/async-storage": "2.2.0", "@react-native-community/datetimepicker": "9.2.1", "@react-native-community/slider": "5.2.1", - "@react-native-menu/menu": "^2.0.0", + "@react-native-menu/menu": "2.1.2", "@react-native-picker/picker": "2.11.4", "@types/react": "~19.3.0", "expo": "~58.0.26", diff --git a/apps/collection/patches/@react-native-menu+menu+2.0.0.patch b/apps/collection/patches/@react-native-menu+menu+2.0.0.patch deleted file mode 100644 index 5accb1f45..000000000 --- a/apps/collection/patches/@react-native-menu+menu+2.0.0.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/node_modules/@react-native-menu/menu/ios/MenuViewManager.mm b/node_modules/@react-native-menu/menu/ios/MenuViewManager.mm -index 3d149b3..6816e94 100644 ---- a/node_modules/@react-native-menu/menu/ios/MenuViewManager.mm -+++ b/node_modules/@react-native-menu/menu/ios/MenuViewManager.mm -@@ -1,6 +1,6 @@ - #import - #import --#import "RCTBridge.h" -+#import - - #ifdef RCT_NEW_ARCH_ENABLED - // NEW ARCH diff --git a/apps/collection/scripts/check-native-ios-ledger.mjs b/apps/collection/scripts/check-native-ios-ledger.mjs new file mode 100644 index 000000000..463aebceb --- /dev/null +++ b/apps/collection/scripts/check-native-ios-ledger.mjs @@ -0,0 +1,60 @@ +import assert from "node:assert/strict"; +import console from "node:console"; +import { readFileSync } from "node:fs"; +import process from "node:process"; +import { fileURLToPath } from "node:url"; + +const uuidPattern = + /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; +const load = "/collection/load"; +const submit = "/collection/submit"; +const legacySubmit = "/collection/scoutreports"; + +export function checkIosLedger(stage, ledger, original) { + const entries = ledger + .split("\n") + .filter(Boolean) + .map((line) => JSON.parse(line)); + assert.ok(entries.length > 0, "Expected the installed app to load a report"); + assert.equal(entries[0].path, load, "First request must load the report"); + const uuid = entries[0].uuid; + assert.match(uuid, uuidPattern); + assert.ok( + entries.every((entry) => entry.uuid === uuid), + "Report UUID changed during this journey", + ); + + if (stage === "before") { + assert.ok( + entries.every((entry) => entry.path === load), + "Nothing besides the initial report load may run before the outage", + ); + return uuid; + } + + assert.equal(stage, "after", "Expected before or after"); + assert.equal( + uuid, + original, + "Report UUID differs from the pre-outage record", + ); + const submissions = entries.filter(({ path }) => + [submit, legacySubmit].includes(path), + ); + assert.deepEqual( + submissions.map(({ path }) => path), + [submit], + "Expected exactly one successful synthetic submission on replay", + ); + assert.deepEqual( + entries.slice(-4).map(({ path }) => path), + [load, "/collection/start", "/collection/end", submit], + "Retry must replay the lifecycle before submitting", + ); + return uuid; +} + +if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) { + const [, , stage, file, original] = process.argv; + console.log(checkIosLedger(stage, readFileSync(file, "utf8"), original)); +} diff --git a/apps/collection/scripts/test-native-ios.sh b/apps/collection/scripts/test-native-ios.sh new file mode 100644 index 000000000..cdd69b110 --- /dev/null +++ b/apps/collection/scripts/test-native-ios.sh @@ -0,0 +1,146 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "$0")/.." + +# Never build or clear app data outside a disposable macOS Actions checkout. +test "${GITHUB_ACTIONS:-}" = true +test "${LOVAT_DISPOSABLE_BUILD:-}" = 1 +test "$(uname -s)" = Darwin +test "$(uname -m)" = arm64 +test "$(git rev-parse HEAD)" = "${LOVAT_EXPECTED_SOURCE_SHA:?Exact Actions source revision required}" +test ! -e ios +export CI=1 EXPO_NO_DOTENV=1 EXPO_PUBLIC_API_URL=http://127.0.0.1:9877 +export EXPO_NO_TELEMETRY=1 MAESTRO_CLI_NO_ANALYTICS=1 +export MAESTRO_DRIVER_STARTUP_TIMEOUT=120000 + +app_id=com.frc8033.lovatcollection +results="$PWD/.maestro/results/ios" +fixture_pid="" +simulator="" +mkdir -p "$results" +printf '%s\n' "$LOVAT_EXPECTED_SOURCE_SHA" > "$results/source-sha.txt" +printf '%s\n' 'Simulator endpoint outage and process restart; not airplane mode, LAN consent, physical camera, QR or signed-device acceptance.' > "$results/scope.txt" +: > "$results/ledger.jsonl" + +stop_fixture() { + if [[ -n "$fixture_pid" ]]; then + kill "$fixture_pid" 2>/dev/null || true + wait "$fixture_pid" || true + fixture_pid="" + fi +} + +cleanup() { + local result=$? + trap - EXIT + stop_fixture + printf '%s\n' "$result" > "$results/exit-code.txt" + if [[ -n "$simulator" ]]; then + xcrun simctl io "$simulator" screenshot "$results/screenshot.png" || true + xcrun simctl spawn "$simulator" log show --last 5m --style compact \ + --predicate 'process == "Collection"' > "$results/simulator-app.log" 2>&1 || true + xcrun simctl shutdown "$simulator" || true + xcrun simctl delete "$simulator" || true + fi + exit "$result" +} +trap cleanup EXIT + +xcodebuild -version | tee "$results/xcode.txt" +grep -Eq '^Xcode 27\.' "$results/xcode.txt" +xcrun simctl list runtimes available | tee "$results/runtimes.txt" +maestro --version | tee "$results/maestro.txt" +simulator="$(xcrun simctl create 'Lovat CI iOS' \ + com.apple.CoreSimulator.SimDeviceType.iPhone-18-Pro com.apple.CoreSimulator.SimRuntime.iOS-27-0)" +xcrun simctl list devices available > "$results/devices.txt" +printf '%s\n' "$simulator" > "$results/device-udid.txt" + +# Generate and patch only the disposable Simulator project, never EAS or app.json. +npx expo prebuild --platform ios --no-install 2>&1 | tee "$results/prebuild.log" +python3 - <<'PY' +import pathlib +import plistlib + +plist, = pathlib.Path("ios").glob("*/Info.plist") +info = plistlib.loads(plist.read_bytes()) +# iOS 17+ supports explicit numeric IP entries in NSExceptionDomains. +info["NSAppTransportSecurity"] = { + "NSAllowsArbitraryLoads": False, + "NSExceptionDomains": { + "127.0.0.1": {"NSExceptionAllowsInsecureHTTPLoads": True}, + }, +} +plist.write_bytes(plistlib.dumps(info)) +PY +(cd ios && pod install) 2>&1 | tee "$results/pods.log" +derived="${RUNNER_TEMP:?Actions temporary directory required}/lovat-collection-ios" +xcodebuild -workspace ios/Collection.xcworkspace -scheme Collection -configuration Release \ + -sdk iphonesimulator -destination 'generic/platform=iOS Simulator' \ + -derivedDataPath "$derived" CODE_SIGNING_ALLOWED=NO ARCHS=arm64 build \ + 2>&1 | tee "$results/build.log" + +app="$derived/Build/Products/Release-iphonesimulator/Collection.app" +test "$(plutil -extract CFBundleIdentifier raw -o - "$app/Info.plist")" = "$app_id" +test -s "$app/main.jsbundle" +grep -aFq "$EXPO_PUBLIC_API_URL" "$app/main.jsbundle" +if grep -aFq 'https://api.lovat.app' "$app/main.jsbundle"; then + echo 'Refusing to launch: the synthetic bundle contains the production API.' >&2 + exit 1 +fi +plutil -extract NSAppTransportSecurity xml1 -o "$results/ats.plist" "$app/Info.plist" +executable="$(plutil -extract CFBundleExecutable raw -o - "$app/Info.plist")" +shasum -a 256 "$app/$executable" "$app/main.jsbundle" > "$results/executable-and-bundle.sha256" +{ + plutil -extract CFBundleShortVersionString raw -o - "$app/Info.plist" + plutil -extract CFBundleVersion raw -o - "$app/Info.plist" +} > "$results/version.txt" + +xcrun simctl boot "$simulator" +xcrun simctl bootstatus "$simulator" -b +xcrun simctl install "$simulator" "$app" + +health() { + curl --noproxy '*' --fail --silent --max-time 2 "$EXPO_PUBLIC_API_URL/healthz" >/dev/null +} + +start_fixture() { + NATIVE_LEDGER="$results/ledger.jsonl" node test/native/fixture-api.mjs >> "$results/fixture.log" 2>&1 & + fixture_pid=$! + for attempt in {1..30}; do + if kill -0 "$fixture_pid" 2>/dev/null && health; then return; fi + sleep 1 + done + echo 'Synthetic fixture failed to start.' >&2 + return 1 +} + +stage() { + local name="$1" + maestro --device "$simulator" test --debug-output "$results/$name-debug" \ + --test-output-dir "$results/$name-debug" --format junit --output "$results/$name.xml" ".maestro/$name.yaml" +} + +if health; then + echo 'Refusing to reuse a service on the synthetic fixture port.' >&2 + exit 1 +fi +start_fixture +stage bootstrap +stage enter-game +# Capture the real app's report UUID while only the initial load is online. +for attempt in {1..20}; do + if grep -q '"path":"/collection/load"' "$results/ledger.jsonl"; then break; fi + sleep 1 +done +node scripts/check-native-ios-ledger.mjs before "$results/ledger.jsonl" > "$results/report-uuid.txt" +stop_fixture +if health; then + echo 'The fixture is still reachable; endpoint outage was not established.' >&2 + exit 1 +fi +stage record-match +stage end-match +stage offline-restart +start_fixture +stage reconnect +node scripts/check-native-ios-ledger.mjs after "$results/ledger.jsonl" "$(cat "$results/report-uuid.txt")" diff --git a/apps/collection/test/native/fixture-api.mjs b/apps/collection/test/native/fixture-api.mjs index 9d8053b91..05f45a860 100644 --- a/apps/collection/test/native/fixture-api.mjs +++ b/apps/collection/test/native/fixture-api.mjs @@ -3,6 +3,13 @@ import process from "node:process"; import { createServer } from "node:http"; import { appendFile } from "node:fs/promises"; const scout = "22222222-2222-4222-8222-222222222222"; +const match = { + tournamentKey: "2026test", + teamNumber: 1234, + matchNumber: 1, + matchType: "QUALIFICATION", +}; +const alliance = "red"; const server = createServer(async (req, res) => { const url = new URL(req.url, "http://localhost"); let body = ""; @@ -44,7 +51,7 @@ const server = createServer(async (req, res) => { JSON.stringify({ tournaments: [ { - key: "2026test", + key: match.tournamentKey, name: "Synthetic Event", location: "Local fixture", date: "2026-01-01", @@ -54,36 +61,51 @@ const server = createServer(async (req, res) => { ); return; } - if (url.pathname === "/collection/schedules/2026test") { + if (url.pathname === `/collection/schedules/${match.tournamentKey}`) { res.end( JSON.stringify({ hash: "synthetic", data: [ { matchType: 0, - matchNumber: 1, - scouters: { [scout]: { team: 1234, alliance: "red" } }, + matchNumber: match.matchNumber, + scouters: { [scout]: { team: match.teamNumber, alliance } }, }, ], }), ); return; } - if (url.pathname === "/v1/manager/matchschedule/2026test") { + if (url.pathname === `/v1/manager/matchschedule/${match.tournamentKey}`) { res.end( JSON.stringify({ - tournamentKey: "2026test", + tournamentKey: match.tournamentKey, matches: [ { matchType: 0, - matchNumber: 1, - teams: [{ number: 1234, alliance: "red" }], + matchNumber: match.matchNumber, + teams: [{ number: match.teamNumber, alliance }], }, ], }), ); return; } + if (req.method === "GET" && url.pathname === "/v1/manager/checkmatch") { + if ( + url.searchParams.get("tournamentKey") === match.tournamentKey && + url.searchParams.get("teamNumber") === String(match.teamNumber) && + url.searchParams.get("matchNumber") === String(match.matchNumber) && + url.searchParams.get("isElim") === "false" && + url.searchParams.get("matchType") === match.matchType + ) { + res.end(JSON.stringify({ match, alliance })); + return; + } + res.statusCode = 404; + res.end(JSON.stringify({ code: "MATCH_NOT_FOUND" })); + return; + } if ( req.method === "POST" && [ diff --git a/apps/collection/test/native/ios-ledger.test.mjs b/apps/collection/test/native/ios-ledger.test.mjs new file mode 100644 index 000000000..a2826fdbb --- /dev/null +++ b/apps/collection/test/native/ios-ledger.test.mjs @@ -0,0 +1,40 @@ +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { checkIosLedger } from "../../scripts/check-native-ios-ledger.mjs"; + +const uuid = "22222222-2222-4222-8222-222222222222"; +const other = "33333333-3333-4333-8333-333333333333"; +const row = (path, id = uuid) => JSON.stringify({ path, uuid: id }); +const load = row("/collection/load"); +const submit = row("/collection/submit"); +const replay = [ + load, + row("/collection/start"), + row("/collection/end"), + submit, +].join("\n"); + +test("accepts the initial load and a single complete same-UUID replay", () => { + assert.equal(checkIosLedger("before", load), uuid); + assert.equal(checkIosLedger("after", `${load}\n${replay}\n`, uuid), uuid); +}); + +test("rejects missing or premature pre-outage evidence", () => { + assert.throws(() => checkIosLedger("before", ""), /load a report/); + assert.throws(() => checkIosLedger("before", replay), /initial report load/); +}); + +test("rejects a replaced report, duplicate submission and missing lifecycle", () => { + assert.throws( + () => checkIosLedger("after", `${load}\n${replay}`, other), + /pre-outage record/, + ); + assert.throws( + () => checkIosLedger("after", `${load}\n${replay}\n${submit}`, uuid), + /exactly one successful/, + ); + assert.throws( + () => checkIosLedger("after", `${load}\n${submit}`, uuid), + /replay the lifecycle/, + ); +});