# store-ready: the three gates, input flags and Gate 2 detail

<!-- toc -->
- [Why three gates, and why the same three on both platforms](#why-three-gates-and-why-the-same-three-on-both-platforms)
- [Gate matrix](#gate-matrix)
- [Input](#input)
- [Step A: why the sweep belongs here](#step-a-why-the-sweep-belongs-here)
- [Gate 1: severity](#gate-1-severity)
- [Gate 2](#gate-2)
- [Gate 3: scope](#gate-3-scope)
<!-- /toc -->

Read by `/multi-agent:store-ready` before Step 0. The command file keeps the step
order, the skip and never-ship rules; this file holds the gate model, the input
table and the Gate 2 procedure per platform.

## Why three gates, and why the same three on both platforms

Each gate sees what the others cannot, so no single one is "the check". The
failure modes are the same on both platforms: a malformed package, a package the
store refuses, a policy a human enforces.

| Gate | Sees | Blind to |
|---|---|---|
| **1. Static** | package structure, manifests, signing, declared APIs and SDKs | anything depending on the store account |
| **2. Authoritative** | what the store's own validator says about this exact binary | written policy  -  no validator reads it |
| **3. Policy** | consent flows, deletion paths, purchase routing, disclosures | anything not visible in source |

A validation run must not be able to ship a build by accident: iOS runs
`--validate-app`, never `--upload-app`; when Google Play is onboarded, Android Gate 2
uploads the bundle into a throwaway edit that is validated and deleted, only after
the user approves that plan.

## Gate matrix

| Gate | iOS | Android |
|---|---|---|
| 1 Static | `ios_app_store_audit({archive_path, rules: "all"})`  -  18 rules with real ITMS codes. Needs an `.xcarchive`. Reference: `apple-archive-compliance` skill | `android_apk_audit` plus the `google-play-compliance` skill's 21 rules: `bundletool validate` + manifest dump, `aapt2 dump badging`, `apksigner verify`, ABI / native scan. Needs an `.aab` (an `.apk` narrows it, see Step 3) |
| 2 Authoritative | `ios_testflight_validate({ipa_path, platform: "ios", <credentials>})` → `xcrun altool --validate-app`, plus `store_asc_next_build_number` for whether the build number is already used. Needs an `.ipa` + credentials | With `google_play` onboarded: `store_play_validate_bundle({package_name, bundle_path})`  -  Google validates the `.aab` in a throwaway Publishing API edit that is then deleted, never committed. Without it, Play's check exists only server-side and nothing local reproduces it, so this gate reports `SKIPPED (no local Play validator)` with the reason `Google Play not onboarded`. Do not substitute `bundletool validate`  -  that is Gate 1 |
| 3 Policy | `ai-ios-toolkit:app-store-review` skill vs repo source | `ai-android-toolkit:play-store-review` skill vs repo source |

Gate 2's asymmetry is reported, not smoothed over. On iOS it is the only gate that
catches a version+build pair already used. On Android it runs only with Google Play
onboarded and the throwaway-edit upload approved; without both, an Android run
clears at most 2 of 3 gates and never prints `passed`.

The `store_*` tools need `@mmerterden/multi-agent-mcp` ≥ v3.17.0. On an
older server they are absent, and each branch that uses one falls back to the
behaviour it has without the credential.

## Input

| Input | Meaning |
|---|---|
| (empty) | ask which repo (Step 1) |
| `my-app` or a path | that repo |
| `--archive=<path>` | iOS, build supplied; all three gates can run |
| `--ipa=<path>` | iOS, build supplied; Gate 1 reports `SKIPPED (needs .xcarchive)` |
| `--aab=<path>` | Android, build supplied; Gate 1 + 3 run |
| `--apk=<path>` | Android; Gate 1 runs the subset that does not need a bundle, and says which rules it could not apply |
| `--previous=<path>` | the earlier build of the same platform; adds the `Release diff` block from `binary_compare_versions` (`features/build-facts.md`). Ignored when the toolkit does not list the tool |
| `--skip-sweep` | skip Step A, when no simulator / emulator is available or only the package matters |
| `--resume` | continue the last run from its state file |

Platform detection when no build flag is given:

```
cwd or repo contains .xcodeproj / .xcworkspace / Package.swift   -> iOS
cwd or repo contains build.gradle / build.gradle.kts             -> Android
both                                                            -> ask which
neither -> halt: "store-ready needs an iOS or Android project"
```

Branch picker options after the fetch: the current branch, the default branch, and
any `release/*` / `tkdevelop/*` heads. Mode B (supply a
build) is fastest and needs no signing in-run; Mode A (build from the branch) needs a
distribution certificate and profile in the keychain on iOS, the release signing
config on Android, and takes as long as a real release build.

## Step A: why the sweep belongs here

The gates read a package; the sweep reads the app. A build can be structurally
perfect and still ship an unreadable screen, so the sweep stays part of store
readiness rather than being a separate errand. It delegates the mechanics to the UI
Bug Hunter flow and merges its findings into the single Step 7 report,
severity-grouped alongside the gate findings.

## Gate 1: severity

`error` findings are blocking; `warning` is advisory. Group by severity and keep
each finding's ITMS / Play policy code  -  Gate 2 may return the same code on iOS,
and seeing it in both places tells the user it is real rather than a heuristic. The
iOS direct-package fallback runs only when the audit tool is genuinely absent, and
the report says which path ran.

## Gate 2

**iOS**: `ios_testflight_validate({ipa_path, platform: "ios", <credential args>})`.
Render the verdict exactly as returned:

- `PASS`  -  Apple accepted the binary for delivery.
- `FAIL`  -  list each issue with its ITMS code, the mapped guideline, and the hint.
- `SKIPPED`  -  print the reason. **Never render this as a pass.**

Gate 2 is the only gate that catches a build number already used  -  so when it
fails on that, say so plainly and name the next free build number.

**Build number** (App Store Connect onboarded, `store_status` reports
`appStoreConnect.configured`): find the app with `store_asc_apps` by the archive's
bundle id, then `store_asc_next_build_number({app_id, version: <CFBundleShortVersionString>})`.
Report the archive's `CFBundleVersion` as `already used` (not above the highest
uploaded one, with the suggested next) or `free`. Read-only; it never changes the
project. Without the credential, skip this line and say why.

**Android, Google Play onboarded, attended run.** Call
`store_play_validate_bundle({package_name: <applicationId>, bundle_path: <.aab>})`
without `confirm`. It returns the plan only: it would open an edit, upload the
bundle, validate the edit, then delete it, committing nothing and changing no
track. Show that plan to the user and ask (picker, `question` / `description` in
`outputLanguage`, `header` `Play check`, labels `Validate on Play` / `Skip`).
Only on **Validate on Play**, call it again with `confirm: true`. Render the
verdict from `valid`: `true` → `PASS`, `false` → `FAIL` with the returned
`error`. On **Skip**, report `SKIPPED (no local Play validator)` with the reason
`user declined the upload`.

**Android otherwise** (unattended, or not onboarded): do not call the tool; report
`SKIPPED (no local Play validator)` with the reason from the Step 2 states.

`bundletool validate` is Gate 1 in every case; reporting it here would fake a
cleared gate.

Google does not document whether an upload into a discarded edit reserves its
`versionCode`; fastlane's `validate_only` runs the same sequence as a pre-release
check. If the real upload is later refused as "already used", raise `versionCode`.

## Gate 3: scope

This is the gate that catches what a human reviewer rejects, so it reads source,
not the binary. Both review skills cover a `Crash symbolication` row (dSYM upload
step / `mapping.txt` upload).
