agentic-mobile-kit 0.7.7 → 0.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/doctor.js CHANGED
@@ -5,6 +5,7 @@ const os = require('os');
5
5
  const path = require('path');
6
6
  const { spawnSync } = require('child_process');
7
7
  const { tool, hookManager, hooksWired, checkProject, emptyFolder } = require('./init');
8
+ const screens = require('../stacks/react-native/template/scripts/amk/screens.js');
8
9
 
9
10
  const RULESYNC = 'rulesync@27.0.0';
10
11
 
@@ -104,8 +105,19 @@ function projectChecks(cwd, opts) {
104
105
  return out;
105
106
  }
106
107
 
108
+ // an Android emulator's smallest screen width in dp, from its config.ini: 600 and up is a tablet
109
+ function avdWidth(name) {
110
+ const home = process.env.ANDROID_AVD_HOME || path.join(process.env.ANDROID_USER_HOME || path.join(os.homedir(), '.android'), 'avd');
111
+ const ini = Object.fromEntries((read(home, `${name}.avd/config.ini`) || '').split('\n').map(l => l.split('=').map(s => s.trim())));
112
+ const [w, h, d] = ['hw.lcd.width', 'hw.lcd.height', 'hw.lcd.density'].map(k => Number(ini[k]));
113
+ return d ? Math.min(w, h) * 160 / d : 0;
114
+ }
115
+
107
116
  function machineChecks(cwd) {
108
117
  const out = [];
118
+ // verify.sh checks tablets for apps that run on them, so they need an iPad simulator and a tablet emulator
119
+ const s = screens.screens(cwd);
120
+ const tablets = Boolean(s.ios && s.ios.tablet);
109
121
  const node = version(process.versions.node);
110
122
  out.push(node[0] >= 20 ? ok('Node', process.versions.node) : fail(`Node ${process.versions.node}`, 'install Node 20 or newer'));
111
123
 
@@ -126,6 +138,7 @@ function machineChecks(cwd) {
126
138
  }
127
139
  const sims = run('xcrun', ['simctl', 'list', 'devices', 'available']);
128
140
  out.push(sims && /iPhone/.test(sims) ? ok('iPhone simulator available') : warn('No iPhone simulator', 'add one in Xcode > Settings > Components / Window > Devices and Simulators'));
141
+ if (tablets) out.push(sims && /iPad/.test(sims) ? ok('iPad simulator available') : warn('No iPad simulator: the app runs on iPad, so verify.sh checks iPads', 'add one in Xcode > Window > Devices and Simulators'));
129
142
  }
130
143
 
131
144
  // Android
@@ -134,6 +147,8 @@ function machineChecks(cwd) {
134
147
  out.push(fs.existsSync(adb) ? ok('Android SDK', sdk) : fail('Android SDK not found', 'install Android Studio, or set ANDROID_HOME'));
135
148
  const avds = run(path.join(sdk, 'emulator/emulator'), ['-list-avds']);
136
149
  out.push(avds ? ok('Android emulator', avds.split('\n')[0]) : warn('No Android emulator', 'create one in Android Studio > Device Manager'));
150
+ const tabletAvd = (avds || '').split('\n').find(a => a && avdWidth(a) >= 600);
151
+ if (tablets) out.push(tabletAvd ? ok('Android tablet emulator', tabletAvd) : warn('No Android tablet emulator: the app runs on tablets, so verify.sh checks them', 'create one in Android Studio > Device Manager > Tablet'));
137
152
  const java = spawnSync('java', ['-version'], { encoding: 'utf8' });
138
153
  const jv = version((java.stderr || '').match(/version "([^"]+)"/)?.[1]);
139
154
  out.push(jv[0] >= 17 ? ok('Java', jv.join('.')) : fail(java.error ? 'Java not found' : `Java ${jv.join('.')}`, 'install JDK 17 (e.g. the one bundled with Android Studio)'));
package/lib/init.js CHANGED
@@ -9,6 +9,7 @@ const { execFileSync, spawnSync } = require('child_process');
9
9
 
10
10
  const KIT_VERSION = require('../package.json').version;
11
11
  const TEMPLATE = path.join(__dirname, '..', 'stacks', 'react-native', 'template');
12
+ const screens = require(path.join(TEMPLATE, 'scripts', 'amk', 'screens.js'));
12
13
  const RULESYNC = 'rulesync@27.0.0';
13
14
  const MARKERS = /<!-- KIT:START[\s\S]*?<!-- KIT:END[^>]*-->\n?/;
14
15
  // files with {{PLACEHOLDERS}} filled in from the project
@@ -169,6 +170,8 @@ function createApp(cwd, kind, { run = tool, log = console.log, pods = process.pl
169
170
  try {
170
171
  // the tools commit only in a repository they create; init needs everything committed
171
172
  commit(own ? 'Initial commit' : 'Add the files that were already in the folder');
173
+ newAppDefaults(cwd, kind, { run, log });
174
+ commit('Support tablets and landscape; stricter TypeScript with @/ imports');
172
175
  // the first pod install changes the Xcode project and Info.plist: a commit of its own keeps that out of the first feature
173
176
  if (kind === 'bare' && pods) {
174
177
  log('Installing the iOS pods\n');
@@ -180,6 +183,66 @@ function createApp(cwd, kind, { run = tool, log = console.log, pods = process.pl
180
183
  }
181
184
  }
182
185
 
186
+ // What a new app starts with beyond the tool's template: iPad and every orientation (the React Native template locks
187
+ // iPhones to portrait; Expo's locks everything to portrait and leaves iPad out), and stricter TypeScript with "@/"
188
+ // imports for src/. Expo's template has the "@/" paths already, and Metro reads them; bare apps need a Babel plugin.
189
+ const STRICTER = { noUncheckedIndexedAccess: true, noImplicitOverride: true, noImplicitReturns: true, noFallthroughCasesInSwitch: true };
190
+ const ALIAS_PLUGIN = 'babel-plugin-module-resolver@5';
191
+ const ADD_DEV = { npm: ['npm', 'install', '--save-dev'], Yarn: ['yarn', 'add', '--dev'], pnpm: ['pnpm', 'add', '--save-dev'], Bun: ['bun', 'add', '--dev'] };
192
+ function newAppDefaults(cwd, kind, { run, log }) {
193
+ const edit = (rel, change) => {
194
+ const text = readIf(path.join(cwd, rel));
195
+ const next = text === null ? null : change(text);
196
+ if (next !== null && next !== text) fs.writeFileSync(path.join(cwd, rel), next);
197
+ };
198
+ const json = text => { try { return JSON.parse(text); } catch { return null; } };
199
+ // short lists stay on one line, as the templates write them
200
+ const format = j => `${JSON.stringify(j, null, 2).replace(/\[\n\s*([^[\]{}]*?)\n\s*\]/g, (m, items) => `[${items.split(/,\n\s*/).join(', ')}]`)}\n`;
201
+ const stricter = paths => text => {
202
+ const j = json(text);
203
+ if (!j) { log('! tsconfig.json isn\'t plain JSON, so the stricter TypeScript settings weren\'t added'); return null; }
204
+ const { extends: base, compilerOptions, ...rest } = j;
205
+ return format({ ...(base ? { extends: base } : {}), compilerOptions: { ...compilerOptions, ...STRICTER, ...(paths ? { paths: { '@/*': ['./src/*'] } } : {}) }, ...rest });
206
+ };
207
+ if (kind === 'expo') {
208
+ edit('app.json', text => {
209
+ const j = json(text);
210
+ if (!j || !j.expo) return null;
211
+ j.expo = { ...j.expo, orientation: 'default', ios: { ...j.expo.ios, supportsTablet: true } };
212
+ return `${JSON.stringify(j, null, 2)}\n`;
213
+ });
214
+ edit('tsconfig.json', stricter(false));
215
+ // Expo's types (CSS modules, assets) come from expo-env.d.ts, which `expo start` generates and git ignores: in a
216
+ // fresh clone or CI the template's own typecheck fails without them
217
+ if ((readIf(path.join(cwd, '.gitignore')) || '').split('\n').includes('expo-env.d.ts') && !fs.existsSync(path.join(cwd, 'expo-types.d.ts'))) {
218
+ fs.writeFileSync(path.join(cwd, 'expo-types.d.ts'), '// Expo\'s types, as expo-env.d.ts has them: that file is generated by `expo start` and not in git,\n// so type checks in a fresh clone or in CI need this one\n/// <reference types="expo/types" />\n');
219
+ }
220
+ return;
221
+ }
222
+ // bare: iPhones turn too; iPads already do, and Android doesn't lock
223
+ const plist = (fs.existsSync(path.join(cwd, 'ios')) ? fs.readdirSync(path.join(cwd, 'ios')) : [])
224
+ .map(d => `ios/${d}/Info.plist`).find(f => !/Tests\//.test(f) && fs.existsSync(path.join(cwd, f)));
225
+ if (plist) {
226
+ edit(plist, text => text.replace(/(<key>UISupportedInterfaceOrientations<\/key>\s*<array>)([\s\S]*?)(\s*<\/array>)/, (m, open, items, close) => {
227
+ if (items.includes('Landscape')) return m;
228
+ const indent = (items.match(/\n[ \t]*(?=<string>)/) || ['\n\t\t'])[0];
229
+ return `${open}${items}${indent}<string>UIInterfaceOrientationLandscapeLeft</string>${indent}<string>UIInterfaceOrientationLandscapeRight</string>${close}`;
230
+ }));
231
+ }
232
+ // "@/" imports: the Babel plugin rewrites them for Metro and Jest, tsconfig's paths for the type checker
233
+ const babel = readIf(path.join(cwd, 'babel.config.js'));
234
+ let alias = false;
235
+ if (babel !== null && !babel.includes('plugins') && /\n(\s*)presets: \[[^\]]*\],\n/.test(babel)) {
236
+ const [bin, ...args] = ADD_DEV[detectPm(cwd).name];
237
+ log(`Adding ${ALIAS_PLUGIN} for "@/" imports\n`);
238
+ if (run(bin, [...args, ALIAS_PLUGIN], { cwd, stdio: 'inherit', env: cleanEnv() }).status === 0) {
239
+ edit('babel.config.js', text => text.replace(/\n(\s*)presets: \[[^\]]*\],\n/, (m, indent) => `${m}${indent}plugins: [['module-resolver', { alias: { '^@/(.+)': './src/\\\\1' } }]],\n`));
240
+ alias = true;
241
+ } else log('! Couldn\'t install the Babel plugin for "@/" imports (see above), so the app uses relative imports.');
242
+ }
243
+ edit('tsconfig.json', stricter(alias));
244
+ }
245
+
183
246
  // Expo apps whose ios/ and android/ come from `expo prebuild` (Continuous Native Generation, not in git) get the
184
247
  // Expo overlay. Expo apps that keep the native folders in git are set up like bare apps.
185
248
  function detectStack(cwd, deps) {
@@ -259,6 +322,7 @@ function projectValues(cwd, pkg, deps, pm, ci, stack) {
259
322
  NODE_VERSION: (pkg.engines && pkg.engines.node) || `${process.versions.node.split('.')[0]}`,
260
323
  PM: pm.name,
261
324
  PM_RUN: pm.run,
325
+ SCREENS: screens.describe(screens.screens(cwd)),
262
326
  IOS_BUNDLE_ID: stack === 'expo' ? (expoConfig(cwd).ios || {}).bundleIdentifier || 'com.example.app' : iosBundleId(cwd),
263
327
  };
264
328
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentic-mobile-kit",
3
- "version": "0.7.7",
3
+ "version": "0.7.9",
4
4
  "description": "One setup for AI-assisted development of React Native apps, bare or Expo: shared rules and workflows for Claude Code, Codex and Antigravity, git hooks, device checks with screenshots, and release tooling for the App Store and Google Play.",
5
5
  "license": "MIT",
6
6
  "author": "prakashpro1",
@@ -9,6 +9,7 @@ This project may also use other AI workflow frameworks (for example Superpowers,
9
9
 
10
10
  - Expo SDK {{EXPO_SDK}}, React Native {{RN_VERSION}} ({{RN_ARCH}}), React {{REACT_VERSION}}, {{LANGUAGE}}, Node {{NODE_VERSION}}. Package manager: {{PM}}.
11
11
  - `ios/` and `android/` are generated by `npx expo prebuild` and aren't in git (Continuous Native Generation). The kit's scripts generate them when they need them.
12
+ - Screens: {{SCREENS}}. Build every screen for each of them (`docs/amk/expo.md`, Tablets and landscape); `verify.sh` checks each one.
12
13
  - What the app does: `docs/amk/product.md`, and requirement by requirement, as it works now: `specs/current/`. Stack and services: `docs/amk/tech.md`. Folders and layers: `docs/amk/structure.md`. Code style: `docs/amk/conventions.md`.
13
14
 
14
15
  ## Commands
@@ -19,7 +20,8 @@ This project may also use other AI workflow frameworks (for example Superpowers,
19
20
  | Add a library (ask first) | `npx expo install <package>`: the version that matches the SDK |
20
21
  | Lint, typecheck, test (each skips what the app doesn't have yet) | `sh scripts/amk/pm-run.sh lint`, `sh scripts/amk/pm-run.sh typecheck`, `sh scripts/amk/pm-run.sh test` |
21
22
  | Check dependency versions and the app config | `npx expo install --check`, `npx expo-doctor` |
22
- | Check on devices (release builds, Maestro flows, screenshots) | `sh scripts/amk/verify.sh all --spec <id>`; another iOS scheme: `--scheme <name>` |
23
+ | Check on devices (release builds, Maestro flows, screenshots) | `sh scripts/amk/verify.sh all --spec <id>`; another iOS scheme: `--scheme <name>`; only some screens: `--screens phone` (or `tablet`, `landscape`, …) |
24
+ | Check every device at the same time, on a machine with room for it | `sh scripts/amk/verify.sh plan --spec <id>` says whether, and prints the commands: one per device, each for an `m-device-checker` subagent |
23
25
  | Specs: progress, format check, fold a finished feature into the living spec | `node scripts/amk/specs.js status`, `node scripts/amk/specs.js check`, `node scripts/amk/specs.js merge <id>` |
24
26
  | Check a release before tagging it (versions, permission texts, debug leftovers) | `node scripts/amk/release-check.js` |
25
27
  | Signed release builds (a person runs them: they use the signing keys) | `sh scripts/amk/release-build.sh android`, `sh scripts/amk/release-build.sh ios` |
@@ -28,7 +30,7 @@ This project may also use other AI workflow frameworks (for example Superpowers,
28
30
 
29
31
  A task is done only when:
30
32
  1. `sh scripts/amk/verify.sh quick` passes (lint, typecheck, tests) and you show its output from this session. In an app whose base branch already fails some of them, it passes when your change adds no new failure, and lists the old ones: leave those alone unless the task is to fix them;
31
- 2. UI changes were checked with `sh scripts/amk/verify.sh all --spec <id>` on both iOS and Android, and you looked at the screenshots. On Windows or Linux, that covers Android only: write in `progress.md` and the PR that iOS still needs checking on a Mac, and the PR isn't merged until a teammate with a Mac has done it;
33
+ 2. UI changes were checked with `sh scripts/amk/verify.sh all --spec <id>` on both iOS and Android, on each screen listed above, and you looked at the screenshots. On Windows or Linux, that covers Android only: write in `progress.md` and the PR that iOS still needs checking on a Mac, and the PR isn't merged until a teammate with a Mac has done it;
32
34
  3. the change stays inside the task's scope;
33
35
  4. `specs/<id>/progress.md` is updated, when working from a spec.
34
36
 
@@ -34,6 +34,24 @@ Rules for things AI agents commonly get wrong in Expo apps. Each one comes from
34
34
  - Give every interactive element a `testID` (kebab-case, for example `dark-mode-switch`). End-to-end tools tap by `testID`. On iOS, React Native exposes a label and its control as duplicate accessibility elements, so tapping by text can hit the label: nothing happens, yet the tool reports success.
35
35
  - Give every interactive element an `accessibilityLabel` that says what it does and an `accessibilityRole` (`button`, `link`, `switch`, …), so screen readers can use it. Icon-only buttons need it most; screen readers don't read `testID`.
36
36
 
37
+ ## Tablets and landscape
38
+
39
+ `AGENTS.md` lists the screens this app supports: phones and tablets, portrait and landscape. Build every screen for each of them, and skip what isn't listed. `verify.sh` checks each one.
40
+
41
+ - One set of screens for every device: layouts adapt to the window. No separate tablet copies of screens, and no phone-width column centered on a tablet.
42
+ - Read the window size with `useWindowDimensions()`, which updates on rotation, split view and resizable windows. `Dimensions.get` read once at startup goes stale.
43
+ - Lay out by window width: under 600 points (dp on Android), the phone layout; from 600, the tablet layout, with more columns, and a list beside its detail where that helps. Text-heavy content and forms keep a readable width (about 600 to 700 points) instead of stretching edge to edge.
44
+ - Sizes: when the app already has a way to size things (a scaling helper, or sizes in its theme), use it everywhere and don't mix in another. A new app takes sizes from its theme: spacing and a few text sizes step up from 600 points, and text follows the system font size. Judge the tablet and landscape screenshots like the phone's: each should look made for that screen, not stretched or tiny.
45
+ - Landscape leaves little height: screens scroll, the keyboard covers more, and the safe-area insets include the left and right edges (the notch or Dynamic Island side).
46
+ - Apps targeting Android 16 (API 36) can't lock the orientation or size on tablets and foldables (600 dp wide and up): the system ignores the lock there. So on Android tablets every screen has to work turned, whatever the app's settings say.
47
+ - Don't lock the orientation in code to avoid layout work. Which orientations the app supports is a product decision, set in `app.json`: `orientation` (`default` turns, `portrait` or `landscape` locks) and `ios.supportsTablet` for the iPad app.
48
+
49
+ ## TypeScript
50
+
51
+ - Keep the checks `tsconfig.json` has. Don't loosen them, or get past one with `any`, `@ts-ignore` or a non-null `!`.
52
+ - New apps from `init --new` also turn on `noUncheckedIndexedAccess`, `noImplicitOverride`, `noImplicitReturns` and `noFallthroughCasesInSwitch`. In an existing app, turning these on is a change of its own (`m-change`), since they flag code that already exists.
53
+ - Import with the app's path alias when `tsconfig.json` has one (`@/` for `src/` in new apps) instead of long relative paths. Expo's Metro reads the alias from `tsconfig.json` by itself.
54
+
37
55
  ## Performance and libraries
38
56
 
39
57
  - Prefer Expo's own modules (`expo-image`, `expo-file-system`, `expo-secure-store`, …) when one fits.
@@ -19,7 +19,7 @@ Input: $ARGUMENTS (what's wrong, steps to reproduce, error text, screenshots, ta
19
19
  - Form one hypothesis, test it, and confirm or reject it. One at a time.
20
20
  - Fix the cause, not the symptom: no try/catch that hides the error, no special case for the failing input.
21
21
  5. **Make the smallest fix.** Don't refactor or touch unrelated code.
22
- 6. **Verify.** The new test passes, and lint, typecheck and all tests pass. Paste the output. For UI or native bugs, run `sh scripts/amk/verify.sh ios` and/or `android` and look at the screenshots.
22
+ 6. **Verify.** The new test passes, and lint, typecheck and all tests pass. Paste the output. For UI or native bugs, run `sh scripts/amk/verify.sh ios` and/or `android` and look at the screenshots; `--screens` limits it to the screens the bug is on (for example `--screens tablet-landscape`).
23
23
  7. **Two attempts at most.** If two fixes didn't work, stop. Report what you tried, what you learned and what you suspect next.
24
24
  8. **Record it.** If this kind of error could come back, add an entry to `docs/amk/known-issues.md` (error, cause, fix, prevention). If the fix changes what the app is meant to do, not just makes it work as specified, update that requirement in `specs/current/<area>.md` in the same format, and run `node scripts/amk/specs.js check`.
25
25
  9. **Commit** with a clear message. Ask the user before pushing, then open a PR with the evidence.
@@ -37,7 +37,7 @@ If no requirement changes, as with a pure style change, skip the spec files (ste
37
37
  1. Pick an ID: the task's ID if it has one, otherwise `YYYYMMDD-<slug>`. Write `specs/<id>/requirements.md` with a title, a one-line goal and only the requirements that change, under `## MODIFIED Requirements: <area>` (or ADDED or REMOVED; the format is in `specs/current/README.md`). Run `node scripts/amk/specs.js check specs/<id>/requirements.md`.
38
38
  2. Change the code, and add or update a test where logic changed.
39
39
  3. Run `sh scripts/amk/verify.sh quick` and show its output.
40
- 4. For a visible change, write `.maestro/<id>.yaml` from `specs/_templates/flow.yaml`: open the changed screen and take a screenshot. Run `sh scripts/amk/verify.sh all --spec <id>` and open the screenshots in `.amk/evidence/<id>/`. Off a Mac it checks Android only: say that iOS still needs checking on a Mac.
40
+ 4. For a visible change, write `.maestro/<id>.yaml` from `specs/_templates/flow.yaml`: open the changed screen and take a screenshot. Check it on the devices as `sh scripts/amk/verify.sh plan --spec <id>` says (one command, or each device in its own `m-device-checker` subagent at the same time, as in `m-feature`'s step 5), and open the screenshots in `.amk/evidence/<id>/`. Off a Mac it checks Android only: say that iOS still needs checking on a Mac.
41
41
  5. Run `node scripts/amk/specs.js merge <id>` to update the living spec, and change the doc lines from step 3.
42
42
  6. Copy `specs/_templates/progress.md` to `specs/<id>/progress.md`, set `Status: done`, and write down the checks and their results.
43
43
 
@@ -37,7 +37,7 @@ If the input describes a bug rather than new behavior, suggest `m-bugfix` and st
37
37
 
38
38
  1. **Search the codebase before designing.** List the components, hooks, API clients and helpers you'll reuse in `design.md` under "Existing code to reuse". Read `docs/amk/structure.md` and `docs/amk/conventions.md`.
39
39
  2. Fill `design.md`: approach, files to change, risks (native changes, pod install, migrations).
40
- 3. Fill `tasks.md`: small tasks (about an hour, under ~300 changed lines each). Each task names the requirement it serves and how it's checked, and its tests are written in the same task, not left for the end. The last task writes `.maestro/<id>.yaml` (from `specs/_templates/flow.yaml`): a Maestro flow with one step and screenshot per scenario, tapping elements by `testID`.
40
+ 3. Fill `tasks.md`: small tasks (about an hour, under ~300 changed lines each). Each task names the requirement it serves and how it's checked, and its tests are written in the same task, not left for the end. The last task writes `.maestro/<id>.yaml` (from `specs/_templates/flow.yaml`): a Maestro flow with one step and screenshot per scenario, tapping elements by `testID` and scrolling to the ones further down a screen first (`scrollUntilVisible`): turned screens are short.
41
41
  4. Show design and tasks and **stop until the user approves them**. Ask them to check that every task serves an approved requirement and nothing goes beyond the agreed scope.
42
42
 
43
43
  From here the plan lives in files, so the building can also run in a fresh session or another tool with `m-continue <id>`.
@@ -45,7 +45,7 @@ From here the plan lives in files, so the building can also run in a fresh sessi
45
45
  ## 4. Build, one task at a time
46
46
 
47
47
  For each task:
48
- 1. Implement only that task. Write tests first for logic (state, data, utils); UI can be tested after. Build screens to the screen rules in the React Native rules file `AGENTS.md` names (keyboard, system bars, scrolling, large text, announced messages): they're the bugs device checks and reviews find most.
48
+ 1. Implement only that task. Write tests first for logic (state, data, utils); UI can be tested after. Build screens to the screen rules in the React Native rules file `AGENTS.md` names (keyboard, system bars, scrolling, large text, announced messages), for every phone, tablet and orientation `AGENTS.md` lists: they're the bugs device checks and reviews find most.
49
49
  2. Run `lint`, `typecheck` and `test` (see AGENTS.md). Paste the real output. If something fails, fix it; after 2 failed attempts, stop and report.
50
50
  3. Commit with a clear message ending in `Spec: specs/<id>`.
51
51
  4. Tick the task in `tasks.md` and update the handoff block and log in `progress.md`.
@@ -55,7 +55,11 @@ If building shows the plan is wrong: when the intent is the same, update `requir
55
55
  ## 5. Check against the spec
56
56
 
57
57
  When all tasks are done:
58
- 1. Run `sh scripts/amk/verify.sh all --spec <id>`. Off a Mac it checks Android only: record in `progress.md` that iOS still needs `verify.sh ios --spec <id>` on a Mac, and say so in the PR. Then **open the screenshots** in `.amk/evidence/<id>/` and check each one against its scenario. Maestro can report a tap as passed when nothing happened, so the screenshots are the evidence, not the log.
58
+ 1. Run `sh scripts/amk/verify.sh plan --spec <id>`. It says whether this machine has room to check the devices at the same time, and prints the commands.
59
+ - **One command** (`verify.sh all --spec <id>`): run it. Then **open the screenshots** in `.amk/evidence/<id>/` and check each one against its scenario, in every screen's folder (phone, landscape, tablet).
60
+ - **A plan, and your tool has subagents:** run its `quick` and `build` commands as printed (nothing added: the plain commands are the ones people allow), then start one `m-device-checker` subagent per device command, all at once; each runs its device, checks its screenshots and hands back a report. When all are back, check them yourself: every flow passed, every screen has screenshots in its folder (list them), and open every screenshot a report flags plus at least one per screen. A report alone isn't evidence. Without subagents, run `verify.sh all --spec <id>` instead.
61
+
62
+ Off a Mac it checks Android only: record in `progress.md` that iOS still needs `verify.sh ios --spec <id>` on a Mac, and say so in the PR. A turned screen's screenshots are landscape; a portrait one means the app didn't turn. Maestro can report a tap as passed when nothing happened, so the screenshots are the evidence, not the log.
59
63
  2. Go through every scenario and note its evidence: a test name, command output, or the screen checked. Where the code and the spec disagree, fix whichever is wrong, asking first if it's the spec. The spec must describe what ships.
60
64
 
61
65
  ## 6. Update the living spec and the docs
@@ -20,8 +20,10 @@ If your tool has subagents, hand the review to the `m-reviewer` subagent, so it
20
20
  - *Coherent:* the decisions in `design.md` show up in the code, and `specs/current/` was updated (`node scripts/amk/specs.js merge <id>`) if behavior changed.
21
21
  - **No spec:** does the diff do what was asked, and nothing unrelated?
22
22
  - **Tests:** were tests added for new logic? Were any tests deleted, skipped or weakened?
23
+ - **TypeScript:** any new `any`, `@ts-ignore` or non-null `!` to get past a check, or a loosened `tsconfig.json`?
23
24
  - **Both platforms:** anything iOS-only or Android-only (insets, back button, permissions, keyboard)?
24
25
  - **Screens:** with the keyboard open, do the field and its button stay visible? Does anything sit under the status bar, home indicator or gesture bar? Do lists that grow with the user's data scroll? Does text wrap at the largest text size?
26
+ - **Tablets and landscape** (the screens `AGENTS.md` lists): does each layout adapt to the window width (`useWindowDimensions`), rather than stretching or centering the phone layout? Do turned screens scroll, with the left and right insets handled? Are sizes done the app's existing way?
25
27
  - **Accessibility:** does every new button or other touchable have an `accessibilityLabel` and an `accessibilityRole`? Are messages that appear after an action, such as form errors, announced to screen readers?
26
28
  - **Errors and states:** offline, server errors, empty and loading states.
27
29
  - **Security:** secrets, tokens, `.env` contents, logging of personal data.
@@ -0,0 +1,18 @@
1
+ ---
2
+ name: m-device-checker
3
+ targets: ["*"]
4
+ description: Checks the app on one device and reports the evidence. Use when `verify.sh plan` says to check the devices at the same time, one m-device-checker per device command, all started together.
5
+ claudecode:
6
+ tools: ["Read", "Grep", "Glob", "Bash"]
7
+ ---
8
+
9
+ You check the app on one device with fresh eyes, and hand the evidence back. You never edit files.
10
+
11
+ 1. Run the one command you were given exactly as it is, for example `sh scripts/amk/verify.sh ios --no-build --screens tablet --spec <id>`: no pipes, redirects or other commands added. Its output is short, and the plain command is the one people allow, so you don't wait on a permission prompt while the other checkers run. It installs the build that's there, runs the feature's Maestro flows on that device's screens (upright and turned), and saves screenshots in `.amk/evidence/<id>/<screen>/`. Don't build, and don't run anything else on a device: other checkers are using the other devices.
12
+ 2. If a flow failed, read its log and Maestro's own log (the output names both) and say why, and whether the app or the flow is wrong: on a turned screen, a flow often checks or taps something further down without scrolling to it first. Don't fix anything.
13
+ 3. Open every screenshot in your screens' folders and check each against its scenario in `specs/<id>/requirements.md`, and against the screen rules in the React Native rules file that `AGENTS.md` names: the right content, nothing cut off or covered, a layout made for that screen. A turned screen's screenshots are landscape; a portrait one means the app didn't turn.
14
+ 4. Report, and say only what you saw in this run:
15
+ - the command, and its last lines of output;
16
+ - per screen: flows passed out of total, and the evidence folder;
17
+ - per screenshot: its path, and "matches" or the problem;
18
+ - anything you couldn't check, and why.
@@ -9,7 +9,7 @@ claudecode:
9
9
  You review code changes with fresh eyes. You never edit files. Use the shell only for read-only commands such as `git diff`, `git log` and `git show`.
10
10
 
11
11
  1. Get the changes: `git diff main...HEAD`. If a spec exists in `specs/<id>/`, read its `requirements.md`.
12
- 2. Check scope, tests (added, deleted, weakened), iOS vs Android differences, screens (the keyboard covering a field or button, content under the system bars, lists that don't scroll, text cut off at large sizes), accessibility (labels and roles, messages announced to screen readers), error and empty states, secrets, native file changes, and performance.
12
+ 2. Check scope, tests (added, deleted, weakened), iOS vs Android differences, screens (the keyboard covering a field or button, content under the system bars, lists that don't scroll, text cut off at large sizes), tablets and landscape for the screens AGENTS.md lists (layouts that adapt to the window width, turned screens that scroll), accessibility (labels and roles, messages announced to screen readers), TypeScript (new `any` or `@ts-ignore`, a loosened tsconfig), error and empty states, secrets, native file changes, and performance.
13
13
  3. Confirm each finding in the code before reporting it.
14
14
  4. Report each finding as: severity (blocker or should fix), file:line, the problem, and a suggested fix. No style nits.
15
15
  5. End with "Ready for PR" or "Not ready: N blockers".
@@ -8,6 +8,7 @@ This project may also use other AI workflow frameworks (for example Superpowers,
8
8
  ## Project
9
9
 
10
10
  - Bare React Native {{RN_VERSION}} ({{RN_ARCH}}), React {{REACT_VERSION}}, {{LANGUAGE}}, Node {{NODE_VERSION}}. Package manager: {{PM}}.
11
+ - Screens: {{SCREENS}}. Build every screen for each of them (`docs/amk/react-native.md`, Tablets and landscape); `verify.sh` checks each one.
11
12
  - What the app does: `docs/amk/product.md`, and requirement by requirement, as it works now: `specs/current/`. Stack and services: `docs/amk/tech.md`. Folders and layers: `docs/amk/structure.md`. Code style: `docs/amk/conventions.md`.
12
13
 
13
14
  ## Commands
@@ -19,7 +20,8 @@ This project may also use other AI workflow frameworks (for example Superpowers,
19
20
  | iOS pods (after native dependency changes) | `sh scripts/amk/pod-install.sh` |
20
21
  | iOS build (simulator, no signing) | `sh scripts/amk/ios-build.sh` |
21
22
  | Android build | `cd android && ./gradlew assembleDebug` |
22
- | Check on devices (release builds, Maestro flows, screenshots) | `sh scripts/amk/verify.sh all --spec <id>`; with product flavors it checks the first unless `--flavor <name>`; another iOS scheme: `--scheme <name>` |
23
+ | Check on devices (release builds, Maestro flows, screenshots) | `sh scripts/amk/verify.sh all --spec <id>`; with product flavors it checks the first unless `--flavor <name>`; another iOS scheme: `--scheme <name>`; only some screens: `--screens phone` (or `tablet`, `landscape`, …) |
24
+ | Check every device at the same time, on a machine with room for it | `sh scripts/amk/verify.sh plan --spec <id>` says whether, and prints the commands: one per device, each for an `m-device-checker` subagent |
23
25
  | Specs: progress, format check, fold a finished feature into the living spec | `node scripts/amk/specs.js status`, `node scripts/amk/specs.js check`, `node scripts/amk/specs.js merge <id>` |
24
26
  | Check a release before tagging it (versions, permission texts, debug leftovers) | `node scripts/amk/release-check.js` |
25
27
  | Signed release builds (a person runs them: they use the signing keys) | `sh scripts/amk/release-build.sh android [flavor]`, `sh scripts/amk/release-build.sh ios [scheme]` |
@@ -28,7 +30,7 @@ This project may also use other AI workflow frameworks (for example Superpowers,
28
30
 
29
31
  A task is done only when:
30
32
  1. `sh scripts/amk/verify.sh quick` passes (lint, typecheck, tests) and you show its output from this session. In an app whose base branch already fails some of them, it passes when your change adds no new failure, and lists the old ones: leave those alone unless the task is to fix them;
31
- 2. UI changes were checked with `sh scripts/amk/verify.sh all --spec <id>` on both iOS and Android, and you looked at the screenshots. On Windows or Linux, that covers Android only: write in `progress.md` and the PR that iOS still needs checking on a Mac, and the PR isn't merged until a teammate with a Mac has done it;
33
+ 2. UI changes were checked with `sh scripts/amk/verify.sh all --spec <id>` on both iOS and Android, on each screen listed above, and you looked at the screenshots. On Windows or Linux, that covers Android only: write in `progress.md` and the PR that iOS still needs checking on a Mac, and the PR isn't merged until a teammate with a Mac has done it;
32
34
  3. the change stays inside the task's scope;
33
35
  4. `specs/<id>/progress.md` is updated, when working from a spec.
34
36
 
@@ -21,6 +21,24 @@ Rules for things AI agents commonly get wrong in current React Native. Each one
21
21
  - Give every interactive element a `testID` (kebab-case, for example `dark-mode-switch`). End-to-end tools tap by `testID`. On iOS, React Native exposes a label and its control as duplicate accessibility elements, so tapping by text can hit the label: nothing happens, yet the tool reports success.
22
22
  - Give every interactive element an `accessibilityLabel` that says what it does and an `accessibilityRole` (`button`, `link`, `switch`, …), so screen readers can use it. Icon-only buttons need it most; screen readers don't read `testID`.
23
23
 
24
+ ## Tablets and landscape
25
+
26
+ `AGENTS.md` lists the screens this app supports: phones and tablets, portrait and landscape. Build every screen for each of them, and skip what isn't listed. `verify.sh` checks each one.
27
+
28
+ - One set of screens for every device: layouts adapt to the window. No separate tablet copies of screens, and no phone-width column centered on a tablet.
29
+ - Read the window size with `useWindowDimensions()`, which updates on rotation, split view and resizable windows. `Dimensions.get` read once at startup goes stale.
30
+ - Lay out by window width: under 600 points (dp on Android), the phone layout; from 600, the tablet layout, with more columns, and a list beside its detail where that helps. Text-heavy content and forms keep a readable width (about 600 to 700 points) instead of stretching edge to edge.
31
+ - Sizes: when the app already has a way to size things (a scaling helper, or sizes in its theme), use it everywhere and don't mix in another. A new app takes sizes from its theme: spacing and a few text sizes step up from 600 points, and text follows the system font size. Judge the tablet and landscape screenshots like the phone's: each should look made for that screen, not stretched or tiny.
32
+ - Landscape leaves little height: screens scroll, the keyboard covers more, and the safe-area insets include the left and right edges (the notch or Dynamic Island side).
33
+ - Apps targeting Android 16 (API 36) can't lock the orientation or size on tablets and foldables (600 dp wide and up): the system ignores the lock there. So on Android tablets every screen has to work turned, whatever the app's settings say.
34
+ - Don't lock the orientation in code to avoid layout work. Which orientations the app supports is a product decision, set in `Info.plist` (`UISupportedInterfaceOrientations`, and `~ipad` for iPads) and the Android manifest (`android:screenOrientation`); the iPad app itself is the Xcode target's device family.
35
+
36
+ ## TypeScript
37
+
38
+ - Keep the checks `tsconfig.json` has. Don't loosen them, or get past one with `any`, `@ts-ignore` or a non-null `!`.
39
+ - New apps from `init --new` also turn on `noUncheckedIndexedAccess`, `noImplicitOverride`, `noImplicitReturns` and `noFallthroughCasesInSwitch`. In an existing app, turning these on is a change of its own (`m-change`), since they flag code that already exists.
40
+ - Import with the app's path alias when `tsconfig.json` has one (`@/` for `src/` in new apps) instead of long relative paths. In a bare app the alias also needs `babel-plugin-module-resolver` with the same mapping in `babel.config.js`, or Metro and Jest won't find the files.
41
+
24
42
  ## Native changes
25
43
 
26
44
  - After adding or removing a native dependency: `sh scripts/amk/pod-install.sh`, then rebuild both apps. Restart Metro with `--reset-cache` if the bundle looks stale.
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env node
2
+ // The screens the app supports: phones and tablets, portrait and landscape, on iOS and Android. Read from the native
3
+ // projects (app.json in an Expo app that doesn't have them yet), so agents build for them and verify.sh checks them.
4
+ // The app runs on tablets when its iOS app runs on iPad; Android runs every app on tablets, but the kit checks
5
+ // Android tablets only for apps made for tablets.
6
+ // Usage: node scripts/amk/screens.js one sentence, as AGENTS.md says it
7
+ // node scripts/amk/screens.js ios|android the screens to check, one per line: phone-portrait, tablet-landscape, …
8
+ 'use strict';
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+
12
+ const BOTH = ['portrait', 'landscape'];
13
+ const read = f => { try { return fs.readFileSync(f, 'utf8'); } catch { return null; } };
14
+
15
+ // an Info.plist array's orientations, or null without the key (upside down counts as portrait)
16
+ function plistOrientations(plist, key) {
17
+ const m = plist.match(new RegExp(`<key>${key}</key>\\s*<array>([\\s\\S]*?)</array>`));
18
+ if (!m) return null;
19
+ const found = BOTH.filter(o => m[1].includes(`UIInterfaceOrientation${o === 'portrait' ? 'Portrait' : 'Landscape'}`));
20
+ return found.length ? found : null;
21
+ }
22
+
23
+ function ios(cwd) {
24
+ const dir = path.join(cwd, 'ios');
25
+ const proj = (fs.existsSync(dir) ? fs.readdirSync(dir) : []).find(f => f.endsWith('.xcodeproj'));
26
+ if (!proj) return null;
27
+ const pbx = read(path.join(dir, proj, 'project.pbxproj')) || '';
28
+ // the app target's Info.plist, not a test target's
29
+ const plistFile = [...pbx.matchAll(/INFOPLIST_FILE = "?([^";]+)"?;/g)].map(m => m[1].replace(/^\$\(SRCROOT\)\//, ''))
30
+ .find(f => !/Tests?\//.test(f)) || `${proj.replace(/\.xcodeproj$/, '')}/Info.plist`;
31
+ const plist = read(path.join(dir, plistFile)) || '';
32
+ // without the key, iOS lets the app turn both ways
33
+ const phone = plistOrientations(plist, 'UISupportedInterfaceOrientations') || BOTH;
34
+ const ipad = /TARGETED_DEVICE_FAMILY = "?[\d,]*2/.test(pbx);
35
+ return { phone, tablet: ipad ? plistOrientations(plist, 'UISupportedInterfaceOrientations~ipad') || phone : null };
36
+ }
37
+
38
+ const lockOf = value => (/portrait/i.test(value) ? ['portrait'] : /landscape/i.test(value) ? ['landscape'] : BOTH);
39
+
40
+ function android(cwd) {
41
+ const manifest = read(path.join(cwd, 'android/app/src/main/AndroidManifest.xml'));
42
+ if (manifest === null) return null;
43
+ // the launcher activity's orientation lock, if it has one
44
+ const at = manifest.lastIndexOf('<activity', manifest.indexOf('android.intent.action.MAIN'));
45
+ const tag = at < 0 ? '' : manifest.slice(at, manifest.indexOf('>', at) + 1);
46
+ const phone = lockOf((tag.match(/android:screenOrientation="([^"]+)"/) || [])[1] || '');
47
+ // apps targeting Android 16 (API 36) can't lock the orientation on tablets: the system ignores it there
48
+ const gradle = ['build.gradle', 'app/build.gradle', 'gradle.properties'].map(f => read(path.join(cwd, 'android', f)) || '').join('\n');
49
+ const target = Number((gradle.match(/targetSdk(?:Version)?\s*[=:]?\s*(\d+)/) || [])[1]) || 36;
50
+ return { phone, tablet: target >= 36 ? BOTH : phone };
51
+ }
52
+
53
+ // app.json's expo section: "orientation" (no lock unless it says portrait or landscape) and ios.supportsTablet
54
+ function expo(cwd) {
55
+ let config;
56
+ try { config = JSON.parse(read(path.join(cwd, 'app.json'))).expo; } catch { return null; }
57
+ if (!config) return null;
58
+ const phone = lockOf(config.orientation || '');
59
+ return { ios: { phone, tablet: config.ios && config.ios.supportsTablet ? phone : null }, android: { phone, tablet: BOTH } };
60
+ }
61
+
62
+ function screens(cwd) {
63
+ const fromExpo = expo(cwd);
64
+ const i = ios(cwd) || (fromExpo && fromExpo.ios);
65
+ const a = android(cwd) || (fromExpo && fromExpo.android);
66
+ const tablets = Boolean(i && i.tablet);
67
+ return {
68
+ ios: i && { phone: i.phone, tablet: tablets ? i.tablet : null },
69
+ android: a && { phone: a.phone, tablet: tablets ? a.tablet : null },
70
+ };
71
+ }
72
+
73
+ // the screens to check on a platform, phone portrait first
74
+ function list(s, platform) {
75
+ const p = s[platform] || { phone: ['portrait'], tablet: null };
76
+ return [...p.phone.map(o => `phone-${o}`), ...(p.tablet || []).map(o => `tablet-${o}`)];
77
+ }
78
+
79
+ function describe(s) {
80
+ const say = o => (o.length === 2 ? 'portrait and landscape' : `${o[0]} only`);
81
+ const part = (kind, apple) => {
82
+ const i = s.ios && s.ios[kind];
83
+ const a = s.android && s.android[kind];
84
+ if (i && a && say(i) !== say(a)) return `${say(i)} on ${apple}, ${say(a)} on Android`;
85
+ return say(i || a || ['portrait']);
86
+ };
87
+ const tablets = (s.ios && s.ios.tablet) || (s.android && s.android.tablet);
88
+ return tablets
89
+ ? `phones (${part('phone', 'iPhone')}) and tablets (${part('tablet', 'iPad')})`
90
+ : `phones only (${part('phone', 'iPhone')}), no iPad app`;
91
+ }
92
+
93
+ if (require.main === module) {
94
+ const s = screens(process.cwd());
95
+ const platform = process.argv[2];
96
+ console.log(platform ? list(s, platform).join('\n') : describe(s));
97
+ }
98
+
99
+ module.exports = { screens, list, describe };
@@ -1,29 +1,42 @@
1
1
  #!/bin/sh
2
2
  # Checks the app the way a user would: lint, typecheck and tests, then release builds on the iOS simulator
3
- # and Android emulator, running Maestro flows and saving screenshots as evidence.
3
+ # and Android emulator, running Maestro flows and saving screenshots as evidence. Apps that support tablets or
4
+ # landscape (scripts/amk/screens.js) are checked on each: an iPad simulator and a tablet emulator, and turned.
4
5
  #
5
- # Usage: sh scripts/amk/verify.sh [quick|ios|android|all] [--spec <id>] [--flow <file>] [--label <name>]
6
- # [--flavor <name>] [--scheme <name>]
6
+ # Usage: sh scripts/amk/verify.sh [quick|ios|android|all|build|plan] [--spec <id>] [--flow <file>] [--label <name>]
7
+ # [--flavor <name>] [--scheme <name>] [--screens <list>] [--no-build]
7
8
  # quick lint, typecheck, tests
8
9
  # ios|android release build, install, run flows, screenshots
9
10
  # all everything (default)
11
+ # build the release builds only, iOS and Android at the same time, for --no-build checks after it
12
+ # plan whether this machine can check the devices at the same time, and the commands to run
10
13
  # --spec <id> run .maestro/<id>*.yaml and save evidence in .amk/evidence/<id>/
11
14
  # --label <n> evidence folder name (default: the spec id, or a timestamp)
12
15
  # --flavor <name> Android product flavor to check (default: the first one in build.gradle)
13
16
  # --scheme <name> iOS scheme to check (default: the one named like the workspace)
17
+ # --screens <l> only these of the screens the app supports, comma-separated: phone, tablet, portrait,
18
+ # landscape, or one such as tablet-landscape
19
+ # --no-build check the last build instead of building again (after `build`)
14
20
  # (no flows found: a smoke check that launches the app and takes a screenshot)
15
- # Env: AMK_ANDROID_FLAVOR, AMK_IOS_SCHEME (defaults for the two options), AMK_IOS_DEVICE (simulator name
21
+ # Evidence per screen: ios/ and android/ (phone, portrait), then -landscape/, -tablet/ and -tablet-landscape/
22
+ # Env: AMK_ANDROID_FLAVOR, AMK_IOS_SCHEME, AMK_SCREENS (defaults for the options), AMK_IOS_DEVICE (simulator name
16
23
  # or UDID), AMK_ANDROID_DEVICE (adb serial: the only way to check on a phone, whose app data the flows clear),
17
- # AMK_ANDROID_AVD (the emulator to use, started if it isn't running; other devices are left alone)
24
+ # AMK_ANDROID_AVD (the emulator to use, started if it isn't running; other devices are left alone),
25
+ # AMK_IOS_TABLET (iPad simulator name or UDID), AMK_ANDROID_TABLET_AVD (tablet emulator), AMK_ANDROID_TABLET (serial),
26
+ # AMK_PARALLEL (1 or 0: overrides plan's choice)
18
27
  # Flows that log in read ${MAESTRO_EMAIL} and the like from a local, gitignored .maestro/.env.local (never committed).
19
28
  set -eu
20
29
 
21
30
  mode=${1:-all}
22
31
  [ $# -gt 0 ] && shift
32
+ args=$* # for the commands plan prints
23
33
  spec=""
24
34
  flow=""
25
35
  label=""
26
36
  flavor=${AMK_ANDROID_FLAVOR:-}
37
+ only=${AMK_SCREENS:-}
38
+ no_build=0
39
+ build_only=0
27
40
  while [ $# -gt 0 ]; do
28
41
  case $1 in
29
42
  --spec) spec=$2; shift 2 ;;
@@ -31,6 +44,8 @@ while [ $# -gt 0 ]; do
31
44
  --label) label=$2; shift 2 ;;
32
45
  --flavor) flavor=$2; shift 2 ;;
33
46
  --scheme) AMK_IOS_SCHEME=$2; export AMK_IOS_SCHEME; shift 2 ;;
47
+ --screens) only=$2; shift 2 ;;
48
+ --no-build) no_build=1; shift ;;
34
49
  *) echo "verify: unknown option $1"; exit 2 ;;
35
50
  esac
36
51
  done
@@ -48,16 +63,44 @@ flow_files() {
48
63
  fi
49
64
  }
50
65
 
51
- run_flow() { # platform device app_id file name
66
+ # the screens to check on a platform: the ones the app supports, narrowed by --screens
67
+ screens_for() {
68
+ for s in $(node scripts/amk/screens.js "$1"); do
69
+ [ -n "$only" ] || { echo "$s"; continue; }
70
+ for w in $(echo "$only" | tr ',' ' '); do
71
+ case $s in "$w" | "$w"-* | *-"$w") echo "$s"; break ;; esac
72
+ done
73
+ done
74
+ }
75
+
76
+ # Maestro's version (the first lines may be an update notice), and whether it's at least $1
77
+ maestro_version() { maestro --version 2> /dev/null | tail -n 1 | tr -d '\r '; }
78
+ maestro_at_least() { [ "$(printf '%s\n%s\n' "$1" "$(maestro_version)" | sort -V | head -n 1)" = "$1" ]; }
79
+
80
+ run_flow() { # screen device app_id file name orientation
52
81
  # Maestro's own log, which has errors its output leaves out; it adds to the file, so one run's log at a time
53
82
  debug="$evidence/maestro-logs/$1-$5"
83
+ mkdir -p "$debug" "$out/screenshots"
54
84
  rm -f "$debug/maestro.log"
55
- # screenshots use relative names: older Maestro saves them in the current folder, newer in --test-output-dir
85
+ find "$debug" -path '*/takeScreenshot/*.png' -exec rm -f {} + # an earlier run's, which aren't this run's evidence
86
+ target=$4
87
+ if [ "$6" != PORTRAIT ]; then
88
+ # a turned screen: the flow runs inside one that turns the device first and back to portrait after. Maestro
89
+ # reads the path in it itself, so it's a native path (a Windows path in Git Bash)
90
+ native=$(cd "$(dirname "$4")" && { pwd -W 2> /dev/null || pwd; })/$(basename "$4")
91
+ printf "appId: %s\nonFlowComplete:\n - setOrientation: PORTRAIT\n---\n- setOrientation: %s\n- runFlow: '%s'\n" "$3" "$6" "$native" > "$debug/screen.yaml"
92
+ target=$debug/screen.yaml
93
+ fi
94
+ # screenshots use relative names: older Maestro saves them in the current folder, then in --test-output-dir, and
95
+ # from 2.7 in the debug output under <flow>/takeScreenshot/, from where they join the screen's evidence
96
+ rc=0
56
97
  (cd "$out" && maestro --device "$2" test --test-output-dir "$out" --debug-output "$debug" --flatten-debug-output \
57
- -e APP_ID="$3" "$4" > "$out/$5.log" 2>&1)
98
+ -e APP_ID="$3" "$target" > "$out/$5.log" 2>&1) || rc=$?
99
+ find "$debug" -path '*/takeScreenshot/*.png' -exec cp {} "$out/screenshots/" \;
100
+ return $rc
58
101
  }
59
102
 
60
- run_flows() { # platform device app_id
103
+ run_flows() { # screen device app_id orientation (PORTRAIT, or LANDSCAPE_LEFT to turn it)
61
104
  out="$evidence/$1"
62
105
  mkdir -p "$out"
63
106
  files=$(flow_files)
@@ -73,14 +116,14 @@ run_flows() { # platform device app_id
73
116
  total=$((total + 1))
74
117
  name=$(basename "$f" .yaml)
75
118
  ok=0
76
- run_flow "$@" "$f" "$name" || ok=$?
119
+ run_flow "$1" "$2" "$3" "$f" "$name" "$4" || ok=$?
77
120
  # an emulator sometimes drops its adb connection for a moment: reconnect, then run the flow once more
78
- if [ "$ok" != 0 ] && [ "$1" = android ] && grep -qs 'device offline' "$debug/maestro.log"; then
79
- echo " android: the device went offline during flow $name; running it once more"
121
+ if [ "$ok" != 0 ] && [ "${1%%-*}" = android ] && grep -qs 'device offline' "$debug/maestro.log"; then
122
+ echo " $1: the device went offline during flow $name; running it once more"
80
123
  "$adb" reconnect offline > /dev/null 2>&1 || true
81
124
  android_ready "$2" || true
82
125
  ok=0
83
- run_flow "$@" "$f" "$name" || ok=$?
126
+ run_flow "$1" "$2" "$3" "$f" "$name" "$4" || ok=$?
84
127
  fi
85
128
  if [ "$ok" = 0 ]; then
86
129
  passed=$((passed + 1))
@@ -89,6 +132,14 @@ run_flows() { # platform device app_id
89
132
  status=1
90
133
  fi
91
134
  done
135
+ # iOS saves a turned screen's screenshots at the device's upright size, with a tag that tells viewers to turn them,
136
+ # and some viewers ignore it: save them turned (through BMP, which keeps no tag), so every viewer shows the screen
137
+ case $1 in
138
+ ios*-landscape) find "$out" -name '*.png' | while read -r png; do
139
+ sips -s format bmp "$png" --out "$png.bmp" > /dev/null && sips -s format png "$png.bmp" --out "$png" > /dev/null
140
+ rm -f "$png.bmp"
141
+ done ;;
142
+ esac
92
143
  shots=$(find "$out" -name '*.png' | wc -l | tr -d ' ')
93
144
  echo "$1: flows $passed/$total passed, $shots screenshots in ${out#"$root"/}"
94
145
  if [ "$shots" = 0 ]; then
@@ -97,6 +148,34 @@ run_flows() { # platform device app_id
97
148
  fi
98
149
  }
99
150
 
151
+ # runs the flows on each screen given: the phone upright into <platform>/, then <platform>-landscape/,
152
+ # <platform>-tablet/ and <platform>-tablet-landscape/
153
+ check_screens() { # platform phone tablet app_id screens…
154
+ p=$1 phone=$2 tab=$3 id=$4
155
+ shift 4
156
+ for screen in "$@"; do
157
+ case $screen in
158
+ tablet-*) [ -n "$tab" ] || continue; on=$tab where=$p-tablet ;;
159
+ *) [ -n "$phone" ] || continue; on=$phone where=$p ;;
160
+ esac
161
+ # Maestro turns an Android device from its natural orientation, which on most tablets is landscape
162
+ upright=PORTRAIT turned=LANDSCAPE_LEFT
163
+ if [ "$p" = android ] && "$adb" -s "$on" shell wm size 2> /dev/null |
164
+ awk -F'[: x]+' '/Physical size/ { found = 1; wide = $3 + 0 > $4 + 0 } END { exit !(found && wide) }'; then
165
+ upright=LANDSCAPE_LEFT turned=PORTRAIT
166
+ fi
167
+ case $screen in *-landscape) turn=$turned where=$where-landscape ;; *) turn=$upright ;; esac
168
+ # Maestro turns devices from 2.0 on, and taps the right place on a turned iPad from 2.3
169
+ need=2.0.0
170
+ case $where in ios-tablet*) need=2.3.0 ;; esac
171
+ if [ "$turn" != PORTRAIT ] && ! maestro_at_least $need; then
172
+ echo "$where: not checked: turning the device needs Maestro ${need%.0} or later (this is $(maestro_version))"
173
+ continue
174
+ fi
175
+ run_flows "$where" "$on" "$id" "$turn"
176
+ done
177
+ }
178
+
100
179
  quick() {
101
180
  # each one passes when the app's script passes, or when all its failures were already on the base branch
102
181
  if node scripts/amk/baseline.js lint > "$evidence/lint.log" 2>&1 &&
@@ -120,47 +199,109 @@ ios() {
120
199
  [ "$mode" = ios ] && status=1
121
200
  return
122
201
  fi
123
- command -v maestro > /dev/null || { echo "ios: Maestro isn't installed (https://maestro.dev)"; status=1; return; }
124
- # Expo apps without native folders in git: generate ios/ first
125
- if ! sh scripts/amk/prebuild.sh ios > "$evidence/prebuild-ios.log" 2>&1; then
126
- echo "ios: expo prebuild FAILED, see ${evidence#"$root"/}/prebuild-ios.log"; status=1; return
202
+ [ "$build_only" = 1 ] || command -v maestro > /dev/null || { echo "ios: Maestro isn't installed (https://maestro.dev)"; status=1; return; }
203
+ if [ "$no_build" = 0 ]; then
204
+ # Expo apps without native folders in git: generate ios/ first
205
+ if ! sh scripts/amk/prebuild.sh ios > "$evidence/prebuild-ios.log" 2>&1; then
206
+ echo "ios: expo prebuild FAILED, see ${evidence#"$root"/}/prebuild-ios.log"; status=1; return
207
+ fi
208
+ # pod install also generates React Native codegen files into ios/build/generated; a newer Podfile needs it again
209
+ if [ ! -d ios/Pods ] || [ ! -d ios/build/generated ] || [ ios/Podfile -nt ios/Pods/Manifest.lock ]; then
210
+ sh scripts/amk/pod-install.sh > "$evidence/pod-install.log" 2>&1
211
+ fi
127
212
  fi
128
- # pod install also generates React Native codegen files into ios/build/generated; a newer Podfile needs it again
129
- if [ ! -d ios/Pods ] || [ ! -d ios/build/generated ] || [ ios/Podfile -nt ios/Pods/Manifest.lock ]; then
130
- sh scripts/amk/pod-install.sh > "$evidence/pod-install.log" 2>&1
213
+ # the simulators first, so they boot while Xcode builds
214
+ device="" tablet=""
215
+ if [ "$build_only" = 0 ]; then
216
+ screens=$(screens_for ios)
217
+ [ -n "$screens" ] || { echo "ios: none of the app's screens is $only"; return; }
218
+ if echo "$screens" | grep -q '^phone-'; then
219
+ device=$(simulator iPhone "${AMK_IOS_DEVICE:-}")
220
+ if [ -z "$device" ]; then
221
+ if [ -n "${AMK_IOS_DEVICE:-}" ]; then echo "ios: no simulator has the name or UDID \"$AMK_IOS_DEVICE\""; else echo "ios: no iPhone simulator found (set AMK_IOS_DEVICE)"; fi
222
+ status=1; return
223
+ fi
224
+ fi
225
+ if echo "$screens" | grep -q '^tablet-'; then
226
+ tablet=$(simulator iPad "${AMK_IOS_TABLET:-}")
227
+ if [ -z "$tablet" ] && [ -n "${AMK_IOS_TABLET:-}" ]; then echo "ios: no simulator has the name or UDID \"$AMK_IOS_TABLET\""; status=1; return; fi
228
+ [ -n "$tablet" ] || echo "ios: the app runs on iPad, but there's no iPad simulator, so iPads aren't checked (add one in Xcode, or set AMK_IOS_TABLET)"
229
+ fi
230
+ for d in $device $tablet; do xcrun simctl boot "$d" 2> /dev/null || true; done
131
231
  fi
132
- if ! CONFIGURATION=Release sh scripts/amk/ios-build.sh > "$evidence/ios-build.log" 2>&1; then
133
- echo "ios: release build FAILED, see ${evidence#"$root"/}/ios-build.log"; status=1; return
232
+ if [ "$no_build" = 0 ]; then
233
+ if ! CONFIGURATION=Release sh scripts/amk/ios-build.sh > "$evidence/ios-build.log" 2>&1; then
234
+ echo "ios: release build FAILED, see ${evidence#"$root"/}/ios-build.log"; status=1; return
235
+ fi
236
+ [ "$build_only" = 0 ] || { echo "ios: release build done"; return; }
134
237
  fi
135
238
  # the newest app: the scheme just built (another scheme's app may still be there from an earlier build)
136
- app=$(ls -dt ios/DerivedData/Build/Products/*-iphonesimulator/*.app | head -n 1)
239
+ app=$(ls -dt ios/DerivedData/Build/Products/*-iphonesimulator/*.app 2> /dev/null | head -n 1)
240
+ [ -n "$app" ] || { echo "ios: there's no build to check yet: run sh scripts/amk/verify.sh build first"; status=1; return; }
137
241
  app_id=$(/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' "$app/Info.plist")
138
- device=$(xcrun simctl list devices available -j | node -e '
242
+ for d in $device $tablet; do
243
+ xcrun simctl bootstatus "$d" -b > /dev/null
244
+ xcrun simctl install "$d" "$app"
245
+ done
246
+ check_screens ios "$device" "$tablet" "$app_id" $screens
247
+ }
248
+
249
+ # a simulator's UDID: the one named in $2 (name or UDID), else a booted $1 (iPhone or iPad), else one with the newest iOS
250
+ simulator() {
251
+ xcrun simctl list devices available -j | KIND=$1 WANT=$2 node -e '
139
252
  const all = Object.entries(JSON.parse(require("fs").readFileSync(0, "utf8")).devices)
140
253
  .flatMap(([rt, ds]) => ds.map(d => ({ ...d, v: (rt.match(/iOS-(\d+)-(\d+)/) || []).slice(1).map(Number) })))
141
254
  .filter(d => d.v.length);
142
- const want = process.env.AMK_IOS_DEVICE;
143
- // an iPhone by its device type: a simulator can have any name, such as a separate one kept for tests
144
- const iphones = all.filter(d => /iPhone/.test(d.deviceTypeIdentifier || d.name));
255
+ const want = process.env.WANT;
256
+ // by device type: a simulator can have any name, such as a separate one kept for tests
257
+ const kind = all.filter(d => (d.deviceTypeIdentifier || d.name).includes(process.env.KIND));
145
258
  const pick = want ? all.find(d => d.udid === want || d.name === want)
146
- : iphones.find(d => d.state === "Booted") || iphones.sort((a, b) => b.v[0] - a.v[0] || b.v[1] - a.v[1])[0];
147
- console.log(pick ? pick.udid : "");')
148
- if [ -z "$device" ]; then
149
- if [ -n "${AMK_IOS_DEVICE:-}" ]; then echo "ios: no simulator has the name or UDID \"$AMK_IOS_DEVICE\""; else echo "ios: no iPhone simulator found (set AMK_IOS_DEVICE)"; fi
150
- status=1; return
151
- fi
152
- xcrun simctl boot "$device" 2> /dev/null || true
153
- xcrun simctl bootstatus "$device" -b > /dev/null
154
- xcrun simctl install "$device" "$app"
155
- run_flows ios "$device" "$app_id"
259
+ : kind.find(d => d.state === "Booted") || kind.sort((a, b) => b.v[0] - a.v[0] || b.v[1] - a.v[1])[0];
260
+ console.log(pick ? pick.udid : "");'
156
261
  }
157
262
 
158
- # a running emulator's adb serial, of the AVD named in $1 if one is
263
+ # a running emulator's adb serial: of the AVD named in $1 if one is, else of the kind in $2 (phone or tablet) if given
159
264
  running_emulator() {
160
265
  for d in $("$adb" devices | awk 'NR > 1 && $2 == "device" && /^emulator-/ { print $1 }'); do
161
- if [ -z "$1" ] || [ "$("$adb" -s "$d" emu avd name 2> /dev/null | head -n 1 | tr -d '\r')" = "$1" ]; then echo "$d"; return; fi
266
+ if [ -n "$1" ]; then
267
+ [ "$("$adb" -s "$d" emu avd name 2> /dev/null | head -n 1 | tr -d '\r')" = "$1" ] || continue
268
+ elif [ -n "${2:-}" ]; then
269
+ [ "$(kind_of "$(device_width "$d")")" = "$2" ] || continue
270
+ fi
271
+ echo "$d"; return
272
+ done
273
+ }
274
+
275
+ # a screen's smallest width in dp: 600 and up is a tablet
276
+ kind_of() { if [ "${1:-0}" -ge 600 ]; then echo tablet; else echo phone; fi; }
277
+ device_width() {
278
+ "$adb" -s "$1" shell 'wm size; wm density' 2> /dev/null | tr -d '\r' | awk -F': ' '
279
+ /Physical size/ { split($2, s, "x"); w = s[1] + 0 < s[2] + 0 ? s[1] : s[2] } /Physical density/ { d = $2 }
280
+ END { if (d) print int(w * 160 / d) }'
281
+ }
282
+ # the same for an emulator that isn't running, from its config.ini
283
+ avd_width() {
284
+ awk -F' *= *' '$1 == "hw.lcd.width" { w = $2 } $1 == "hw.lcd.height" { h = $2 } $1 == "hw.lcd.density" { d = $2 }
285
+ END { if (d) print int((w + 0 < h + 0 ? w : h) * 160 / d) }' \
286
+ "${ANDROID_AVD_HOME:-${ANDROID_USER_HOME:-$HOME/.android}/avd}/$1.avd/config.ini" 2> /dev/null || true
287
+ }
288
+ # the first AVD of the kind $1 (phone or tablet)
289
+ first_avd() {
290
+ for a in $avds; do
291
+ if [ "$(kind_of "$(avd_width "$a")")" = "$1" ]; then echo "$a"; return; fi
162
292
  done
163
293
  }
294
+ # starts the AVD $1 and prints its serial once adb sees it (up to 5 minutes)
295
+ start_emulator() {
296
+ nohup "$sdk/emulator/emulator" -avd "$1" -no-snapshot-save -no-boot-anim > /dev/null 2>&1 &
297
+ tries=0
298
+ until serial=$(running_emulator "$1") && [ -n "$serial" ]; do
299
+ tries=$((tries + 1))
300
+ [ "$tries" -le 150 ] || return 1
301
+ sleep 2
302
+ done
303
+ echo "$serial"
304
+ }
164
305
 
165
306
  # waits for the Android device $1 to finish starting, for up to 5 minutes
166
307
  android_ready() {
@@ -173,7 +314,7 @@ android_ready() {
173
314
  }
174
315
 
175
316
  android() {
176
- command -v maestro > /dev/null || { echo "android: Maestro isn't installed (https://maestro.dev)"; status=1; return; }
317
+ [ "$build_only" = 1 ] || command -v maestro > /dev/null || { echo "android: Maestro isn't installed (https://maestro.dev)"; status=1; return; }
177
318
  case $(uname -s) in # where Android Studio puts the SDK by default
178
319
  Darwin) default_sdk=$HOME/Library/Android/sdk ;;
179
320
  MINGW* | MSYS* | CYGWIN*) default_sdk=${LOCALAPPDATA:-$HOME/AppData/Local}/Android/Sdk ;;
@@ -182,7 +323,7 @@ android() {
182
323
  sdk=${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$default_sdk}}
183
324
  adb="$sdk/platform-tools/adb"
184
325
  # Expo apps without native folders in git: generate android/ first
185
- if ! sh scripts/amk/prebuild.sh android > "$evidence/prebuild-android.log" 2>&1; then
326
+ if [ "$no_build" = 0 ] && ! sh scripts/amk/prebuild.sh android > "$evidence/prebuild-android.log" 2>&1; then
186
327
  echo "android: expo prebuild FAILED, see ${evidence#"$root"/}/prebuild-android.log"; status=1; return
187
328
  fi
188
329
  # apps with product flavors: check one, the first in build.gradle unless --flavor names another
@@ -198,47 +339,82 @@ android() {
198
339
  [ -z "$flavor" ] || echo "android: checking the \"$flavor\" flavor (the app has: $(echo $flavors)); --flavor <name> checks another"
199
340
  fi
200
341
  variant=$(printf %s "$flavor" | awk '{ print toupper(substr($0, 1, 1)) substr($0, 2) }')
201
- # the device first: the build only needs its CPU type, and an emulator boots while Gradle builds.
202
- # The flows clear the app's data, so a phone plugged in over USB is used only when AMK_ANDROID_DEVICE names it
203
- device=${AMK_ANDROID_DEVICE:-$(running_emulator "${AMK_ANDROID_AVD:-}")}
204
- if [ -z "$device" ]; then
342
+ device="" tablet=""
343
+ if [ "$build_only" = 1 ]; then
344
+ # no device to ask: emulators run this machine's CPU type
345
+ case $(uname -m) in arm64 | aarch64) abi=arm64-v8a ;; *) abi=x86_64 ;; esac
346
+ else
347
+ # the devices first: the build only needs the CPU type, and emulators boot while Gradle builds.
348
+ # The flows clear the app's data, so a phone plugged in over USB is used only when AMK_ANDROID_DEVICE names it
349
+ screens=$(screens_for android)
350
+ [ -n "$screens" ] || { echo "android: none of the app's screens is $only"; return; }
205
351
  avds=$("$sdk/emulator/emulator" -list-avds 2> /dev/null || true)
206
- avd=${AMK_ANDROID_AVD:-$(echo "$avds" | head -n 1)}
207
- if [ -n "$avd" ]; then
208
- echo "$avds" | grep -qxF "$avd" || { echo "android: there's no emulator named $avd (see: emulator -list-avds)"; status=1; return; }
209
- nohup "$sdk/emulator/emulator" -avd "$avd" -no-snapshot-save -no-boot-anim > /dev/null 2>&1 &
210
- tries=0
211
- until device=$(running_emulator "$avd") && [ -n "$device" ]; do
212
- tries=$((tries + 1))
213
- [ "$tries" -le 150 ] || { echo "android: emulator $avd didn't start"; status=1; return; }
214
- sleep 2
215
- done
216
- else
217
- phone=$("$adb" devices | awk 'NR > 1 && $2 == "device" { print $1; exit }')
218
- echo "android: no emulator found (create one in Android Studio)"
219
- [ -z "$phone" ] || echo " or check on the phone $phone, which clears the app's data on it: AMK_ANDROID_DEVICE=$phone sh scripts/amk/verify.sh android"
220
- status=1; return
352
+ if echo "$screens" | grep -q '^phone-'; then
353
+ device=${AMK_ANDROID_DEVICE:-$(running_emulator "${AMK_ANDROID_AVD:-}" phone)}
354
+ if [ -z "$device" ]; then
355
+ avd=${AMK_ANDROID_AVD:-$(first_avd phone)}
356
+ [ -n "$avd" ] || avd=$(echo "$avds" | head -n 1) # only tablet emulators: one of them
357
+ if [ -n "$avd" ]; then
358
+ echo "$avds" | grep -qxF "$avd" || { echo "android: there's no emulator named $avd (see: emulator -list-avds)"; status=1; return; }
359
+ device=$(start_emulator "$avd") || { echo "android: emulator $avd didn't start"; status=1; return; }
360
+ else
361
+ phone=$("$adb" devices | awk 'NR > 1 && $2 == "device" { print $1; exit }')
362
+ echo "android: no emulator found (create one in Android Studio)"
363
+ [ -z "$phone" ] || echo " or check on the phone $phone, which clears the app's data on it: AMK_ANDROID_DEVICE=$phone sh scripts/amk/verify.sh android"
364
+ status=1; return
365
+ fi
366
+ fi
367
+ case $device in
368
+ emulator-*) echo "android: checking on $device" ;;
369
+ *) echo "android: checking on the phone $device; the flows clear the app's data on it" ;;
370
+ esac
221
371
  fi
372
+ if echo "$screens" | grep -q '^tablet-'; then
373
+ tablet=${AMK_ANDROID_TABLET:-$(running_emulator "${AMK_ANDROID_TABLET_AVD:-}" tablet)}
374
+ if [ -z "$tablet" ]; then
375
+ tablet_avd=${AMK_ANDROID_TABLET_AVD:-$(first_avd tablet)}
376
+ if [ -z "$tablet_avd" ]; then
377
+ echo "android: the app runs on tablets, but there's no tablet emulator, so tablets aren't checked (create one in Android Studio: Device Manager > Tablet, or set AMK_ANDROID_TABLET_AVD)"
378
+ elif ! echo "$avds" | grep -qxF "$tablet_avd"; then
379
+ echo "android: there's no emulator named $tablet_avd (see: emulator -list-avds)"; status=1; return
380
+ else
381
+ tablet=$(start_emulator "$tablet_avd") || { echo "android: emulator $tablet_avd didn't start, so tablets aren't checked"; tablet=""; }
382
+ fi
383
+ fi
384
+ [ "$tablet" != "$device" ] || tablet="" # only tablet emulators: the one in use is checked as the phone
385
+ case $tablet in
386
+ "") ;;
387
+ emulator-*) echo "android: tablets on $tablet" ;;
388
+ *) echo "android: tablets on $tablet; the flows clear the app's data on it" ;;
389
+ esac
390
+ fi
391
+ [ -n "$device$tablet" ] || return
392
+ # an emulator that has just started (another one starting too) may not answer for a moment
393
+ first=${device:-$tablet}
394
+ tries=0
395
+ until abi=$("$adb" -s "$first" shell getprop ro.product.cpu.abi 2> /dev/null | tr -d '\r') && [ -n "$abi" ]; do
396
+ tries=$((tries + 1))
397
+ [ "$tries" -le 30 ] || { echo "android: device $first isn't connected (see: adb devices)"; status=1; return; }
398
+ sleep 2
399
+ done
222
400
  fi
223
- case $device in
224
- emulator-*) echo "android: checking on $device" ;;
225
- *) echo "android: checking on the phone $device; the flows clear the app's data on it" ;;
226
- esac
227
- abi=$("$adb" -s "$device" shell getprop ro.product.cpu.abi 2> /dev/null | tr -d '\r')
228
- [ -n "$abi" ] || { echo "android: device $device isn't connected (see: adb devices)"; status=1; return; }
229
- # native code for that CPU type only, as run-android --active-arch-only does: much faster than all four
230
- set -- -PreactNativeArchitectures="$abi"
231
- # signed with the project's debug key, so the check build installs whatever key its real release needs
232
- if [ -f android/app/debug.keystore ]; then
233
- keystore=$(cd android/app && { pwd -W 2> /dev/null || pwd; })/debug.keystore # pwd -W: a Windows path in Git Bash
234
- set -- "$@" -Pandroid.injected.signing.store.file="$keystore" -Pandroid.injected.signing.store.password=android \
235
- -Pandroid.injected.signing.key.alias=androiddebugkey -Pandroid.injected.signing.key.password=android
236
- fi
237
- if ! (cd android && ./gradlew "assemble${variant}Release" --no-daemon -q "$@") > "$evidence/android-build.log" 2>&1; then
238
- echo "android: release build FAILED, see ${evidence#"$root"/}/android-build.log"; status=1; return
401
+ if [ "$no_build" = 0 ]; then
402
+ # native code for that CPU type only, as run-android --active-arch-only does: much faster than all four
403
+ set -- -PreactNativeArchitectures="$abi"
404
+ # signed with the project's debug key, so the check build installs whatever key its real release needs
405
+ if [ -f android/app/debug.keystore ]; then
406
+ keystore=$(cd android/app && { pwd -W 2> /dev/null || pwd; })/debug.keystore # pwd -W: a Windows path in Git Bash
407
+ set -- "$@" -Pandroid.injected.signing.store.file="$keystore" -Pandroid.injected.signing.store.password=android \
408
+ -Pandroid.injected.signing.key.alias=androiddebugkey -Pandroid.injected.signing.key.password=android
409
+ fi
410
+ if ! (cd android && ./gradlew "assemble${variant}Release" --no-daemon -q "$@") > "$evidence/android-build.log" 2>&1; then
411
+ echo "android: release build FAILED, see ${evidence#"$root"/}/android-build.log"; status=1; return
412
+ fi
413
+ [ "$build_only" = 0 ] || { echo "android: release build done"; return; }
239
414
  fi
240
415
  # apps that split APKs by CPU type get one per type: take this device's, else the universal one
241
- apks=$(ls android/app/build/outputs/apk/${flavor:+$flavor/}release/*.apk)
416
+ apks=$(ls android/app/build/outputs/apk/${flavor:+$flavor/}release/*.apk 2> /dev/null || true)
417
+ [ -n "$apks" ] || { echo "android: there's no build to check yet: run sh scripts/amk/verify.sh build first"; status=1; return; }
242
418
  apk=$(echo "$apks" | grep -e "-$abi-" | head -n 1)
243
419
  [ -n "$apk" ] || apk=$(echo "$apks" | grep universal | head -n 1)
244
420
  [ -n "$apk" ] || apk=$(echo "$apks" | head -n 1)
@@ -246,13 +422,73 @@ android() {
246
422
  aapt2="$(ls -d "$sdk"/build-tools/*/ 2> /dev/null | sort -V | tail -n 1)aapt2"
247
423
  app_id=$("$aapt2" dump badging "$apk" 2> /dev/null | sed -n "s/^package: name='\([^']*\)'.*/\1/p")
248
424
  [ -n "$app_id" ] || app_id=$(sed -n 's/.*applicationId *=\{0,1\} *"\([^"]*\)".*/\1/p' android/app/build.gradle* | head -n 1)
249
- android_ready "$device" || { echo "android: $device didn't finish starting (see: adb devices)"; status=1; return; }
250
- "$adb" -s "$device" install -r "$apk" > /dev/null
251
- # system "isn't responding" pop-ups (common on busy emulators) cover the app and fail flows; app crashes still fail them.
252
- # Emulators only: the setting is device-wide and stays, so a phone keeps showing them
253
- case $device in emulator-*) "$adb" -s "$device" shell settings put global hide_error_dialogs 1 ;; esac
254
- "$adb" -s "$device" shell am broadcast -a android.intent.action.CLOSE_SYSTEM_DIALOGS > /dev/null 2>&1 || true
255
- run_flows android "$device" "$app_id"
425
+ if [ -n "$device" ]; then
426
+ android_ready "$device" || { echo "android: $device didn't finish starting (see: adb devices)"; status=1; return; }
427
+ "$adb" -s "$device" install -r "$apk" > /dev/null
428
+ fi
429
+ if [ -n "$tablet" ]; then
430
+ if ! android_ready "$tablet"; then echo "android: $tablet didn't finish starting, so tablets aren't checked"; tablet=""
431
+ elif ! "$adb" -s "$tablet" install -r "$apk" > /dev/null 2>&1; then
432
+ echo "android: the app didn't install on the tablet $tablet (a different CPU type?), so tablets aren't checked"; tablet=""
433
+ fi
434
+ fi
435
+ for d in $device $tablet; do
436
+ # system "isn't responding" pop-ups (common on busy emulators) cover the app and fail flows; app crashes still fail
437
+ # them. Emulators only: the setting is device-wide and stays, so a phone keeps showing them
438
+ case $d in emulator-*) "$adb" -s "$d" shell settings put global hide_error_dialogs 1 ;; esac
439
+ "$adb" -s "$d" shell am broadcast -a android.intent.action.CLOSE_SYSTEM_DIALOGS > /dev/null 2>&1 || true
440
+ done
441
+ check_screens android "$device" "$tablet" "$app_id" $screens
442
+ }
443
+
444
+ # both release builds at the same time, each in its own log; the --no-build checks on each device come after
445
+ build() {
446
+ build_only=1
447
+ ios_pid=""
448
+ if [ "$(uname -s)" = Darwin ]; then
449
+ (ios; exit $status) > "$evidence/build-ios.out" 2>&1 &
450
+ ios_pid=$!
451
+ fi
452
+ (android; exit $status) > "$evidence/build-android.out" 2>&1 &
453
+ android_pid=$!
454
+ [ -z "$ios_pid" ] || wait "$ios_pid" || status=1
455
+ wait "$android_pid" || status=1
456
+ cat "$evidence"/build-*.out
457
+ }
458
+
459
+ # Checking every device at the same time, one subagent each, is faster where the machine has room: about 20 GB of
460
+ # memory for four devices and both builds, and Maestro 2.6 or later, which runs several devices at once
461
+ plan() {
462
+ set -- $(node -e 'const os = require("os"), fs = require("fs"), s = fs.statfsSync(".");
463
+ console.log(Math.round(os.totalmem() / 2 ** 30), Math.round(s.bavail * s.bsize / 2 ** 30))')
464
+ have="$1 GB of memory, $2 GB free disk, Maestro $(maestro_version)"
465
+ checks=""
466
+ if [ "$(uname -s)" = Darwin ]; then
467
+ for kind in phone tablet; do screens_for ios | grep -q "^$kind-" && checks="$checks ios:$kind"; done
468
+ fi
469
+ for kind in phone tablet; do screens_for android | grep -q "^$kind-" && checks="$checks android:$kind"; done
470
+ n=$(echo $checks | wc -w | tr -d ' ')
471
+ why=""
472
+ case ${AMK_PARALLEL:-} in
473
+ 0) why="AMK_PARALLEL=0" ;;
474
+ 1) ;;
475
+ *)
476
+ [ "$1" -ge 32 ] || why="it needs 32 GB of memory"
477
+ [ "$2" -ge 20 ] || why="${why:+$why and }it needs 20 GB free disk"
478
+ maestro_at_least 2.6.0 || why="${why:+$why and }it needs Maestro 2.6 or later" ;;
479
+ esac
480
+ [ "$n" -ge 2 ] || why="there's one device to check"
481
+ if [ -n "$why" ]; then
482
+ echo "plan: $have: one device at a time ($why; AMK_PARALLEL=1 overrides)"
483
+ echo " sh scripts/amk/verify.sh all${args:+ $args}"
484
+ return
485
+ fi
486
+ echo "plan: $have: check the $n devices at the same time"
487
+ echo " 1. sh scripts/amk/verify.sh quick${args:+ $args}"
488
+ echo " 2. sh scripts/amk/verify.sh build${args:+ $args}"
489
+ echo " 3. at the same time, each in its own subagent (m-device-checker), which checks its screenshots and reports:"
490
+ for c in $checks; do echo " sh scripts/amk/verify.sh ${c%:*} --no-build --screens ${c#*:}${args:+ $args}"; done
491
+ [ "$(uname -s)" = Darwin ] || echo " iOS isn't checked here: it needs a Mac with Xcode"
256
492
  }
257
493
 
258
494
  case $mode in
@@ -260,7 +496,9 @@ case $mode in
260
496
  ios) ios ;;
261
497
  android) android ;;
262
498
  all) quick; ios; android ;;
263
- *) echo "verify: unknown mode $mode (quick, ios, android or all)"; exit 2 ;;
499
+ build) build ;;
500
+ plan) plan; exit 0 ;;
501
+ *) echo "verify: unknown mode $mode (quick, ios, android, all, build or plan)"; exit 2 ;;
264
502
  esac
265
503
 
266
504
  echo "Evidence: ${evidence#"$root"/}/ (open the screenshots: a tool saying 'passed' isn't proof)"
@@ -17,6 +17,10 @@ appId: ${APP_ID} # set by verify.sh
17
17
  id: "<testID of the element>"
18
18
  - takeScreenshot: <id>-1-<short-name>
19
19
  # Scenario 2: …
20
+ # Something further down a screen can be off screen, most of all when it's turned (short): scroll to it first
21
+ - scrollUntilVisible:
22
+ element:
23
+ id: "<testID>"
20
24
  - tapOn:
21
25
  id: "<testID>"
22
26
  - assertVisible: # what THEN expects, so the screenshot shows the result and not the screen before it