opencode-agent-harness 0.0.0-stage → 0.3.14
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/CHANGELOG.md +217 -0
- package/LICENSE +21 -0
- package/README.md +636 -2
- package/bin/agent-harness.js +3182 -0
- package/contrib/global-plugins/README.md +49 -0
- package/contrib/global-plugins/harness-freshness.ts +355 -0
- package/package.json +86 -4
- package/templates/.agents/AGENTS.md +148 -0
- package/templates/.agents/features/INDEX.md +10 -0
- package/templates/.agents/handoffs/README.md +87 -0
- package/templates/.agents/memory/dev-loop.md +59 -0
- package/templates/.agents/memory/domain-map.md +29 -0
- package/templates/.agents/memory/environments.md +35 -0
- package/templates/.agents/memory/flow-map.md +23 -0
- package/templates/.agents/memory/history.md +7 -0
- package/templates/.agents/memory/locations.md +14 -0
- package/templates/.agents/memory/model-routing.md +261 -0
- package/templates/.agents/memory/orchestration.md +183 -0
- package/templates/.agents/memory/owned-files.md +19 -0
- package/templates/.agents/memory/product-principles.md +37 -0
- package/templates/.agents/memory/quality-parameters.md +37 -0
- package/templates/.agents/memory/stack-versions.md +35 -0
- package/templates/.agents/memory/test-design-parameters.md +36 -0
- package/templates/.agents/nightly.json +17 -0
- package/templates/.agents/qa-plans/README.md +70 -0
- package/templates/.agents/qa-runs/README.md +21 -0
- package/templates/.agents/reviews/README.md +47 -0
- package/templates/.agents/rules/00-operating.md +199 -0
- package/templates/.agents/skills/data-engineer/SKILL.md +31 -0
- package/templates/.agents/skills/devops-engineer/SKILL.md +50 -0
- package/templates/.agents/skills/diagnostics-expert/SKILL.md +44 -0
- package/templates/.agents/skills/docs/SKILL.md +140 -0
- package/templates/.agents/skills/features/SKILL.md +187 -0
- package/templates/.agents/skills/frontend-engineer/SKILL.md +81 -0
- package/templates/.agents/skills/handoff/SKILL.md +85 -0
- package/templates/.agents/skills/mobile-engineer/SKILL.md +101 -0
- package/templates/.agents/skills/planner/SKILL.md +112 -0
- package/templates/.agents/skills/product-manager/SKILL.md +115 -0
- package/templates/.agents/skills/qa-architect/SKILL.md +224 -0
- package/templates/.agents/skills/qa-runner/SKILL.md +64 -0
- package/templates/.agents/skills/security-engineer/SKILL.md +53 -0
- package/templates/.agents/skills/system-architect/SKILL.md +42 -0
- package/templates/.agents/skills/ui-designer/SKILL.md +71 -0
- package/templates/.github/workflows/ci.yml +148 -0
- package/templates/.github/workflows/deploy-uat.yml +95 -0
- package/templates/.github/workflows/nightly.yml +83 -0
- package/templates/.github/workflows/uat-health.yml +41 -0
- package/templates/.husky/pre-push +23 -0
- package/templates/.ignore +28 -0
- package/templates/.opencode/agents/data-engineer.md +37 -0
- package/templates/.opencode/agents/devops-engineer.md +37 -0
- package/templates/.opencode/agents/diagnostics-expert.md +37 -0
- package/templates/.opencode/agents/docs.md +37 -0
- package/templates/.opencode/agents/features.md +21 -0
- package/templates/.opencode/agents/frontend-engineer.md +37 -0
- package/templates/.opencode/agents/handoff.md +21 -0
- package/templates/.opencode/agents/mobile-engineer.md +37 -0
- package/templates/.opencode/agents/planner.md +34 -0
- package/templates/.opencode/agents/product-manager.md +29 -0
- package/templates/.opencode/agents/qa-architect.md +27 -0
- package/templates/.opencode/agents/qa-runner.md +17 -0
- package/templates/.opencode/agents/security-engineer.md +37 -0
- package/templates/.opencode/agents/system-architect.md +37 -0
- package/templates/.opencode/agents/ui-designer.md +37 -0
- package/templates/.opencode/commands/board.md +15 -0
- package/templates/.opencode/commands/checkpoint.md +25 -0
- package/templates/.opencode/commands/feature.md +56 -0
- package/templates/.opencode/commands/finish.md +36 -0
- package/templates/.opencode/commands/next.md +49 -0
- package/templates/.opencode/commands/report.md +55 -0
- package/templates/.opencode/commands/resume.md +39 -0
- package/templates/.opencode/commands/switch-model.md +34 -0
- package/templates/.opencode/commands/tidy.md +49 -0
- package/templates/.opencode/plugins/backlog-notify.ts +57 -0
- package/templates/.opencode/plugins/backlog.ts +272 -0
- package/templates/.opencode/plugins/checkpoint.ts +160 -0
- package/templates/.opencode/plugins/context-guard.ts +1164 -0
- package/templates/.opencode/plugins/diff.ts +85 -0
- package/templates/.opencode/plugins/gates.ts +71 -0
- package/templates/.opencode/plugins/job-notify.ts +241 -0
- package/templates/.opencode/plugins/orient.ts +67 -0
- package/templates/.opencode/plugins/session.ts +89 -0
- package/templates/.opencode/plugins/wait.ts +101 -0
- package/templates/.opencode/plugins/where.ts +70 -0
- package/templates/.opencode/skills/bounded-explore/SKILL.md +38 -0
- package/templates/.opencode/skills/dev-loop/SKILL.md +87 -0
- package/templates/.vercelignore +16 -0
- package/templates/AGENTS.md +27 -0
- package/templates/BACKLOG.md +95 -0
- package/templates/docs/ci-cd-pipeline.md +81 -0
- package/templates/docs/gates.md +128 -0
- package/templates/docs/mcp-integrations.md +97 -0
- package/templates/docs/mobile-testing.md +555 -0
- package/templates/docs/nightly-testing.md +106 -0
- package/templates/docs/wsl-optimizations.md +290 -0
- package/templates/opencode.json +188 -0
- package/templates/scripts/agent-report.js +541 -0
- package/templates/scripts/agent-search.sh +117 -0
- package/templates/scripts/backlog.js +1924 -0
- package/templates/scripts/board-service.sh +214 -0
- package/templates/scripts/checkpoint.js +290 -0
- package/templates/scripts/finalize.js +416 -0
- package/templates/scripts/nightly.js +913 -0
- package/templates/scripts/orient.js +514 -0
- package/templates/scripts/qa/board-client.js +323 -0
- package/templates/scripts/qa/board-lib.js +96 -0
- package/templates/scripts/qa/board-sync.js +499 -0
- package/templates/scripts/qa/capacity-lib.js +916 -0
- package/templates/scripts/qa/check-backlog.js +434 -0
- package/templates/scripts/qa/check-capacity.js +85 -0
- package/templates/scripts/qa/check-ci-policy.js +164 -0
- package/templates/scripts/qa/check-concurrency.js +344 -0
- package/templates/scripts/qa/check-dispatch-config.js +296 -0
- package/templates/scripts/qa/check-docs.js +288 -0
- package/templates/scripts/qa/check-integrate.js +98 -0
- package/templates/scripts/qa/check-linger.js +160 -0
- package/templates/scripts/qa/check-prefix-stability.js +187 -0
- package/templates/scripts/qa/check-product.js +177 -0
- package/templates/scripts/qa/check-qa-plan.js +378 -0
- package/templates/scripts/qa/check-qa-scripts.js +85 -0
- package/templates/scripts/qa/check-quality.js +249 -0
- package/templates/scripts/qa/check-test-wiring.js +253 -0
- package/templates/scripts/qa/check-worktrees.js +93 -0
- package/templates/scripts/qa/ci-triage.js +346 -0
- package/templates/scripts/qa/ci-usage-lib.js +185 -0
- package/templates/scripts/qa/ci-wait-lib.js +294 -0
- package/templates/scripts/qa/command-classifier.js +552 -0
- package/templates/scripts/qa/context-guard-core.js +1618 -0
- package/templates/scripts/qa/diff.js +174 -0
- package/templates/scripts/qa/feature-scaffold.js +224 -0
- package/templates/scripts/qa/fixtures/backlog.md +104 -0
- package/templates/scripts/qa/governance.js +174 -0
- package/templates/scripts/qa/hash-file.js +32 -0
- package/templates/scripts/qa/lease-lib.js +263 -0
- package/templates/scripts/qa/merge-backlog.js +324 -0
- package/templates/scripts/qa/mobile-e2e/analyze-timings.js +300 -0
- package/templates/scripts/qa/mobile-e2e/apk-cache.js +420 -0
- package/templates/scripts/qa/mobile-e2e/backend-build-cache.js +203 -0
- package/templates/scripts/qa/mobile-e2e/boot-emulator.sh +432 -0
- package/templates/scripts/qa/mobile-e2e/build-apk.sh +210 -0
- package/templates/scripts/qa/mobile-e2e/check-flows.js +568 -0
- package/templates/scripts/qa/mobile-e2e/config.yaml +18 -0
- package/templates/scripts/qa/mobile-e2e/device-down.sh +88 -0
- package/templates/scripts/qa/mobile-e2e/device-up.sh +258 -0
- package/templates/scripts/qa/mobile-e2e/ios-simulator-down.sh +72 -0
- package/templates/scripts/qa/mobile-e2e/ios-simulator-up.sh +153 -0
- package/templates/scripts/qa/mobile-e2e/job-events.js +181 -0
- package/templates/scripts/qa/mobile-e2e/prewarm.sh +56 -0
- package/templates/scripts/qa/mobile-e2e/run-detached.sh +222 -0
- package/templates/scripts/qa/mobile-e2e/run-maestro.js +1543 -0
- package/templates/scripts/qa/mobile-e2e/ui-dump.js +327 -0
- package/templates/scripts/qa/models.allowlist.txt +32 -0
- package/templates/scripts/qa/provider-stats.js +878 -0
- package/templates/scripts/qa/run-clean.js +83 -0
- package/templates/scripts/qa/run-gates.js +213 -0
- package/templates/scripts/qa/run-loop.js +220 -0
- package/templates/scripts/qa/session-recon.js +512 -0
- package/templates/scripts/qa/store-lib.js +324 -0
- package/templates/scripts/qa/tool-lib.js +134 -0
- package/templates/scripts/qa/where.js +214 -0
- package/templates/scripts/qa/worktree-hygiene.js +217 -0
- package/templates/scripts/qa/wslconfig-merge.js +157 -0
- package/templates/scripts/serve.js +1328 -0
- package/templates/scripts/setup-nightly.sh +185 -0
- package/templates/scripts/setup-tmpfs.sh +374 -0
- package/templates/scripts/ship.js +586 -0
- package/templates/scripts/switch-reasoning-model.ps1 +101 -0
- package/templates/scripts/switch-reasoning-model.sh +104 -0
- package/templates/scripts/wait-for.js +342 -0
- package/templates/scripts/wsl-gpu.sh +180 -0
- package/templates/scripts/wsl-tune.sh +319 -0
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* F-285 slice 1 — mobile E2E flow-coverage validator (dependency-free).
|
|
6
|
+
*
|
|
7
|
+
* Proves, without a device, adb, Java, Maestro, or any npm dependency, that the
|
|
8
|
+
* journey manifest and its Maestro flows are wired and self-consistent:
|
|
9
|
+
*
|
|
10
|
+
* a. `flows/matrix.yaml` parses (bounded line parser, no YAML dep);
|
|
11
|
+
* b. every journey's flow file exists and is non-empty; every `flows/*.yaml`
|
|
12
|
+
* (excluding `matrix.yaml`) is referenced by some journey (no orphan);
|
|
13
|
+
* c. every flow is structurally well-formed: starts with `appId:`, contains at
|
|
14
|
+
* least one `tapOn`/`assertVisible` command, and uses only known Maestro
|
|
15
|
+
* command verbs at the top level; every `runFlow: file:` include resolves
|
|
16
|
+
* (relative to the including file, recursively) with no missing path, no
|
|
17
|
+
* escape outside `flows/`, and no cycle;
|
|
18
|
+
* d. every referenced screen resolves to a file under `mobile/`, and every
|
|
19
|
+
* referenced testID resolves to a static `testID=` occurrence, an allowed
|
|
20
|
+
* dynamic template literal (`testID={`prefix-${expr}`}`) in `mobile/`, or a
|
|
21
|
+
* `prefix-{id}` placeholder selector matching such a template;
|
|
22
|
+
* e. exits 0 with a per-check report, or 1 with the exact violation(s).
|
|
23
|
+
*
|
|
24
|
+
* Usage:
|
|
25
|
+
* node scripts/qa/mobile-e2e/check-flows.js [--root <dir>]
|
|
26
|
+
*
|
|
27
|
+
* `--root` defaults to the repository root and exists so the validator can be
|
|
28
|
+
* pointed at temporary fixture trees by its own negative-case test.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const fs = require('fs');
|
|
32
|
+
const path = require('path');
|
|
33
|
+
|
|
34
|
+
const REPO_ROOT = path.resolve(__dirname, '..', '..', '..');
|
|
35
|
+
const FLOWS_SUBPATH = path.join('scripts', 'qa', 'mobile-e2e', 'flows');
|
|
36
|
+
|
|
37
|
+
// Maestro command verbs accepted at the top level of a flow. Keeping this list
|
|
38
|
+
// explicit is the point: an unknown verb is a typo/drift the validator must fail
|
|
39
|
+
// on rather than silently ignore.
|
|
40
|
+
const ALLOWED_VERBS = new Set([
|
|
41
|
+
'addMedia',
|
|
42
|
+
'assertNoDefectsWithAI',
|
|
43
|
+
'assertNotVisible',
|
|
44
|
+
'assertTrue',
|
|
45
|
+
'assertVisible',
|
|
46
|
+
'assertWithAI',
|
|
47
|
+
'back',
|
|
48
|
+
'clearKeychain',
|
|
49
|
+
'clearState',
|
|
50
|
+
'copyTextFrom',
|
|
51
|
+
'eraseText',
|
|
52
|
+
'evalScript',
|
|
53
|
+
'extendedWaitUntil',
|
|
54
|
+
'hideKeyboard',
|
|
55
|
+
'inputText',
|
|
56
|
+
'killApp',
|
|
57
|
+
'launchApp',
|
|
58
|
+
'openLink',
|
|
59
|
+
'pasteText',
|
|
60
|
+
'pressKey',
|
|
61
|
+
'repeat',
|
|
62
|
+
'runFlow',
|
|
63
|
+
'scroll',
|
|
64
|
+
'scrollUntilVisible',
|
|
65
|
+
'setLocation',
|
|
66
|
+
'setOrientation',
|
|
67
|
+
'stopApp',
|
|
68
|
+
'swipe',
|
|
69
|
+
'takeScreenshot',
|
|
70
|
+
'tapOn',
|
|
71
|
+
'toggleAirplaneMode',
|
|
72
|
+
'travel',
|
|
73
|
+
'waitForAnimationToEnd',
|
|
74
|
+
]);
|
|
75
|
+
|
|
76
|
+
function parseRootArg(argv) {
|
|
77
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
78
|
+
const arg = argv[i];
|
|
79
|
+
if (arg === '--root' && argv[i + 1]) return path.resolve(argv[i + 1]);
|
|
80
|
+
if (arg.startsWith('--root=')) return path.resolve(arg.slice('--root='.length));
|
|
81
|
+
}
|
|
82
|
+
return REPO_ROOT;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Split an inline YAML sequence `[a, b, c]` without a YAML dependency. */
|
|
86
|
+
function parseInlineList(raw) {
|
|
87
|
+
const text = String(raw).trim();
|
|
88
|
+
const start = text.indexOf('[');
|
|
89
|
+
const end = text.lastIndexOf(']');
|
|
90
|
+
if (start === -1 || end === -1 || end < start) return [];
|
|
91
|
+
return text
|
|
92
|
+
.slice(start + 1, end)
|
|
93
|
+
.split(',')
|
|
94
|
+
.map((entry) => entry.trim().replace(/^['"]|['"]$/g, ''))
|
|
95
|
+
.filter((entry) => entry.length > 0);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Bounded, line-oriented parser for the manifest schema documented in
|
|
100
|
+
* `flows/matrix.yaml`. It deliberately understands only the handful of keys the
|
|
101
|
+
* contract defines; anything else is a violation, not a silent skip.
|
|
102
|
+
*/
|
|
103
|
+
function parseMatrix(content) {
|
|
104
|
+
const violations = [];
|
|
105
|
+
const journeys = [];
|
|
106
|
+
let seenHeader = false;
|
|
107
|
+
let current = null;
|
|
108
|
+
|
|
109
|
+
const lines = content.split(/\r?\n/);
|
|
110
|
+
lines.forEach((line, index) => {
|
|
111
|
+
const lineNo = index + 1;
|
|
112
|
+
const trimmed = line.trim();
|
|
113
|
+
if (trimmed === '' || trimmed.startsWith('#')) return;
|
|
114
|
+
|
|
115
|
+
if (!seenHeader) {
|
|
116
|
+
if (trimmed !== 'journeys:') {
|
|
117
|
+
violations.push(`matrix.yaml:${lineNo}: expected top-level "journeys:" but found "${trimmed}"`);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
seenHeader = true;
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const itemMatch = trimmed.match(/^-\s+id:\s*(.+)$/);
|
|
125
|
+
if (itemMatch) {
|
|
126
|
+
current = {
|
|
127
|
+
id: itemMatch[1].trim(),
|
|
128
|
+
flow: '',
|
|
129
|
+
entry: '',
|
|
130
|
+
actor: null,
|
|
131
|
+
endsAs: null,
|
|
132
|
+
screens: [],
|
|
133
|
+
testids: [],
|
|
134
|
+
states: [],
|
|
135
|
+
setup: null,
|
|
136
|
+
oracle: null,
|
|
137
|
+
firstLogin: null,
|
|
138
|
+
batchSetup: null,
|
|
139
|
+
line: lineNo,
|
|
140
|
+
};
|
|
141
|
+
journeys.push(current);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const kvMatch = trimmed.match(/^([A-Za-z]+):\s*(.*)$/);
|
|
146
|
+
if (kvMatch) {
|
|
147
|
+
if (!current) {
|
|
148
|
+
violations.push(`matrix.yaml:${lineNo}: "${kvMatch[1]}" appears before any "- id:"`);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const [, key, rawValue] = kvMatch;
|
|
152
|
+
if (key === 'flow') current.flow = rawValue.trim();
|
|
153
|
+
else if (key === 'entry') current.entry = rawValue.trim();
|
|
154
|
+
else if (key === 'actor') current.actor = rawValue.trim().replace(/^["']|["']$/g, '');
|
|
155
|
+
else if (key === 'endsAs') current.endsAs = rawValue.trim().replace(/^["']|["']$/g, '');
|
|
156
|
+
else if (key === 'screens') current.screens = parseInlineList(rawValue);
|
|
157
|
+
else if (key === 'testids') current.testids = parseInlineList(rawValue);
|
|
158
|
+
else if (key === 'states') current.states = parseInlineList(rawValue);
|
|
159
|
+
else if (key === 'setup') current.setup = rawValue.trim();
|
|
160
|
+
else if (key === 'oracle') current.oracle = rawValue.trim();
|
|
161
|
+
else if (key === 'firstLogin') current.firstLogin = rawValue.trim();
|
|
162
|
+
else if (key === 'batchSetup') current.batchSetup = rawValue.trim();
|
|
163
|
+
else violations.push(`matrix.yaml:${lineNo}: unknown journey key "${key}"`);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
violations.push(`matrix.yaml:${lineNo}: unparseable line "${trimmed}"`);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
if (!seenHeader) violations.push('matrix.yaml: missing top-level "journeys:" header');
|
|
171
|
+
if (journeys.length === 0) violations.push('matrix.yaml: no journeys declared');
|
|
172
|
+
|
|
173
|
+
journeys.forEach((journey) => {
|
|
174
|
+
if (!journey.id) violations.push(`matrix.yaml:${journey.line}: journey is missing an id`);
|
|
175
|
+
if (!journey.flow) violations.push(`matrix.yaml:${journey.line}: journey "${journey.id}" is missing "flow"`);
|
|
176
|
+
if (!journey.entry) violations.push(`matrix.yaml:${journey.line}: journey "${journey.id}" is missing "entry"`);
|
|
177
|
+
if (journey.screens.length === 0) violations.push(`matrix.yaml:${journey.line}: journey "${journey.id}" declares no screens`);
|
|
178
|
+
if (journey.states.length === 0) violations.push(`matrix.yaml:${journey.line}: journey "${journey.id}" declares no states`);
|
|
179
|
+
// `actor:` is optional (run-maestro defaults to 0502000001); when declared
|
|
180
|
+
// it must be non-empty — it is the phone the shared session signs in as.
|
|
181
|
+
if (journey.actor === '') {
|
|
182
|
+
violations.push(`matrix.yaml:${journey.line}: journey "${journey.id}" declares an empty "actor"`);
|
|
183
|
+
}
|
|
184
|
+
// `endsAs:` is optional; when declared it must name the actor the flow
|
|
185
|
+
// leaves signed in (an empty declaration is meaningless).
|
|
186
|
+
if (journey.endsAs === '') {
|
|
187
|
+
violations.push(`matrix.yaml:${journey.line}: journey "${journey.id}" declares an empty "endsAs"`);
|
|
188
|
+
}
|
|
189
|
+
// `setup:`/`oracle:` are optional; when a journey declares one it must carry
|
|
190
|
+
// the invocation (an empty declaration is a declaration without a step).
|
|
191
|
+
if (journey.setup === '') {
|
|
192
|
+
violations.push(`matrix.yaml:${journey.line}: journey "${journey.id}" declares an empty "setup"`);
|
|
193
|
+
}
|
|
194
|
+
if (journey.oracle === '') {
|
|
195
|
+
violations.push(`matrix.yaml:${journey.line}: journey "${journey.id}" declares an empty "oracle"`);
|
|
196
|
+
}
|
|
197
|
+
// `firstLogin:` is optional; when declared it must be the literal boolean
|
|
198
|
+
// `true`/`false` (the runner only recognises `true`).
|
|
199
|
+
if (journey.firstLogin != null && journey.firstLogin !== '' && !/^(true|false)$/.test(journey.firstLogin)) {
|
|
200
|
+
violations.push(`matrix.yaml:${journey.line}: journey "${journey.id}" has a non-boolean "firstLogin" ("${journey.firstLogin}")`);
|
|
201
|
+
}
|
|
202
|
+
if (journey.firstLogin === '') {
|
|
203
|
+
violations.push(`matrix.yaml:${journey.line}: journey "${journey.id}" declares an empty "firstLogin"`);
|
|
204
|
+
}
|
|
205
|
+
// `batchSetup:` is optional; when declared it must be the literal boolean
|
|
206
|
+
// `true`/`false`. It opts a setup-bearing journey into the setup-batching
|
|
207
|
+
// group (the runner runs its setup before a shared warm invocation).
|
|
208
|
+
if (journey.batchSetup != null && journey.batchSetup !== '' && !/^(true|false)$/.test(journey.batchSetup)) {
|
|
209
|
+
violations.push(
|
|
210
|
+
`matrix.yaml:${journey.line}: journey "${journey.id}" has a non-boolean "batchSetup" ("${journey.batchSetup}")`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
if (journey.batchSetup === '') {
|
|
214
|
+
violations.push(`matrix.yaml:${journey.line}: journey "${journey.id}" declares an empty "batchSetup"`);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
return { journeys, violations };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function readText(file) {
|
|
222
|
+
try {
|
|
223
|
+
return fs.readFileSync(file, 'utf8');
|
|
224
|
+
} catch {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function walkFiles(dir, predicate, out) {
|
|
230
|
+
let entries;
|
|
231
|
+
try {
|
|
232
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
233
|
+
} catch {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
entries.forEach((entry) => {
|
|
237
|
+
const full = path.join(dir, entry.name);
|
|
238
|
+
if (entry.isDirectory()) {
|
|
239
|
+
if (entry.name === 'node_modules' || entry.name.startsWith('.')) return;
|
|
240
|
+
walkFiles(full, predicate, out);
|
|
241
|
+
} else if (predicate(full)) {
|
|
242
|
+
out.push(full);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Collect the testIDs declared in `mobile/` source:
|
|
249
|
+
*
|
|
250
|
+
* - static: `testID="x"`, `testID={'x'}`, `testID={`x`}` → exact ids;
|
|
251
|
+
* - forwarded props: `phoneTestID="x"` / `submitTestID="x"` — this codebase
|
|
252
|
+
* passes the id into a shared field/button component as a `*TestID` prop,
|
|
253
|
+
* which lands on the element as `testID` at runtime (F-348; the shared
|
|
254
|
+
* session/subflow selectors live on these);
|
|
255
|
+
* - dynamic: `testID={`prefix-${expr}`}` → the static prefix up to the first
|
|
256
|
+
* interpolation (`prefix-`), so a flow may reference it either literally
|
|
257
|
+
* (`prefix-…`) or with an `{id}` placeholder (`prefix-{id}`).
|
|
258
|
+
*
|
|
259
|
+
* Dynamic templates that begin with an interpolation (`testID={`${x}-tail`}`)
|
|
260
|
+
* contribute no stable prefix and are ignored — a selector for them cannot be
|
|
261
|
+
* resolved and must be treated as dangling.
|
|
262
|
+
*/
|
|
263
|
+
function collectMobileTestIds(mobileDir) {
|
|
264
|
+
const ids = new Set();
|
|
265
|
+
const dynamicPrefixes = new Set();
|
|
266
|
+
const sources = [];
|
|
267
|
+
walkFiles(mobileDir, (file) => /\.(ts|tsx)$/.test(file), sources);
|
|
268
|
+
const staticPattern = /(?:testID|[A-Za-z]+TestID)=\{?["'`]([^"'`${}]+)["'`]/g;
|
|
269
|
+
const dynamicPattern = /testID=\{\s*`([^`]*?)\$\{/g;
|
|
270
|
+
sources.forEach((file) => {
|
|
271
|
+
const content = readText(file);
|
|
272
|
+
if (content === null) return;
|
|
273
|
+
let match;
|
|
274
|
+
while ((match = staticPattern.exec(content)) !== null) ids.add(match[1]);
|
|
275
|
+
while ((match = dynamicPattern.exec(content)) !== null) {
|
|
276
|
+
const prefix = match[1];
|
|
277
|
+
if (prefix.length > 0) dynamicPrefixes.add(prefix);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
return { ids, dynamicPrefixes };
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Resolve a flow `id:` selector against the declared mobile testIDs.
|
|
285
|
+
*
|
|
286
|
+
* A selector resolves when it is a static id, when it starts with a dynamic
|
|
287
|
+
* template's static prefix (`home-carousel-book-123`), or when it uses the
|
|
288
|
+
* `{id}` placeholder form whose stripped prefix is a dynamic prefix
|
|
289
|
+
* (`home-carousel-book-{id}` → `home-carousel-book-`).
|
|
290
|
+
*/
|
|
291
|
+
function resolveMobileTestId(selector, declared) {
|
|
292
|
+
if (declared.ids.has(selector)) return true;
|
|
293
|
+
if (selector.endsWith('{id}')) {
|
|
294
|
+
const stripped = selector.slice(0, -'{id}'.length);
|
|
295
|
+
if (declared.dynamicPrefixes.has(stripped)) return true;
|
|
296
|
+
}
|
|
297
|
+
// Maestro treats an `id:` value as a regex, so a device flow uses `prefix-.*`
|
|
298
|
+
// rather than the literal `prefix-{id}` placeholder. Resolve it the same way:
|
|
299
|
+
// strip the trailing `.*` and require the remaining prefix to be a declared
|
|
300
|
+
// dynamic template prefix.
|
|
301
|
+
if (selector.endsWith('.*')) {
|
|
302
|
+
const stripped = selector.slice(0, -'.*'.length);
|
|
303
|
+
if (declared.dynamicPrefixes.has(stripped)) return true;
|
|
304
|
+
}
|
|
305
|
+
for (const prefix of declared.dynamicPrefixes) {
|
|
306
|
+
if (selector.startsWith(prefix)) return true;
|
|
307
|
+
}
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function validateFlowStructure(flowName, content) {
|
|
312
|
+
const violations = [];
|
|
313
|
+
const lines = content.split(/\r?\n/);
|
|
314
|
+
const significant = [];
|
|
315
|
+
lines.forEach((line, index) => {
|
|
316
|
+
const trimmed = line.trim();
|
|
317
|
+
if (trimmed === '' || trimmed.startsWith('#')) return;
|
|
318
|
+
significant.push({ raw: line, trimmed, lineNo: index + 1 });
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
if (significant.length === 0) {
|
|
322
|
+
violations.push(`${flowName}: flow is empty`);
|
|
323
|
+
return violations;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (!/^appId:\s*\S+/.test(significant[0].trimmed)) {
|
|
327
|
+
violations.push(`${flowName}: first non-comment line must be "appId: <id>" but was "${significant[0].trimmed}"`);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const commandLines = significant.filter((entry) => /^(\s*)-\s+([A-Za-z][A-Za-z0-9_]*)/.test(entry.raw));
|
|
331
|
+
if (commandLines.length === 0) {
|
|
332
|
+
violations.push(`${flowName}: no top-level commands found`);
|
|
333
|
+
return violations;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const baseIndent = commandLines[0].raw.match(/^(\s*)/)[1].length;
|
|
337
|
+
const verbs = new Set();
|
|
338
|
+
commandLines.forEach((entry) => {
|
|
339
|
+
const indent = entry.raw.match(/^(\s*)/)[1].length;
|
|
340
|
+
if (indent !== baseIndent) return;
|
|
341
|
+
const verb = entry.raw.match(/^\s*-\s+([A-Za-z][A-Za-z0-9_]*)/)[1];
|
|
342
|
+
if (!ALLOWED_VERBS.has(verb)) {
|
|
343
|
+
violations.push(`${flowName}:${entry.lineNo}: unknown top-level command "${verb}"`);
|
|
344
|
+
}
|
|
345
|
+
verbs.add(verb);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
if (!verbs.has('tapOn') && !verbs.has('assertVisible')) {
|
|
349
|
+
violations.push(`${flowName}: must contain at least one "- tapOn:" or "- assertVisible:" command`);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return violations;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Test-ID references inside a flow (Maestro `id:` selectors). Captures static
|
|
357
|
+
* ids, `{id}` placeholders, and Maestro regex selectors ending in `.*`
|
|
358
|
+
* (`prefix-.*`), which is how a dynamic template id is matched on device.
|
|
359
|
+
*/
|
|
360
|
+
function extractFlowTestIds(content) {
|
|
361
|
+
const ids = new Set();
|
|
362
|
+
const pattern = /^\s*id:\s*["']?([A-Za-z0-9_{}.*-]+)["']?\s*$/gm;
|
|
363
|
+
let match;
|
|
364
|
+
while ((match = pattern.exec(content)) !== null) ids.add(match[1]);
|
|
365
|
+
return ids;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function stripInlineComment(value) {
|
|
369
|
+
const text = String(value).trim();
|
|
370
|
+
const commentAt = text.search(/\s+#/);
|
|
371
|
+
return (commentAt === -1 ? text : text.slice(0, commentAt)).trim();
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function unquote(value) {
|
|
375
|
+
return value.replace(/^["']|["']$/g, '');
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Extract every `runFlow: file:` reference from a flow (F-348).
|
|
380
|
+
*
|
|
381
|
+
* Supports both Maestro shapes:
|
|
382
|
+
*
|
|
383
|
+
* - runFlow: _shared/session.yaml
|
|
384
|
+
* - runFlow:
|
|
385
|
+
* file: _shared/session.yaml
|
|
386
|
+
*
|
|
387
|
+
* Only the `file:` key that is a DIRECT child of `runFlow:` counts; a `file:`
|
|
388
|
+
* inside a `when:`/inline `commands:` block is a different command property and
|
|
389
|
+
* is ignored. A `runFlow:` with inline `commands:` (no `file:`) is not an
|
|
390
|
+
* include and yields nothing.
|
|
391
|
+
*/
|
|
392
|
+
function extractRunFlowIncludes(content) {
|
|
393
|
+
const lines = content.split(/\r?\n/);
|
|
394
|
+
const includes = [];
|
|
395
|
+
lines.forEach((line, index) => {
|
|
396
|
+
const trimmed = line.trim();
|
|
397
|
+
if (trimmed === '' || trimmed.startsWith('#')) return;
|
|
398
|
+
const match = line.match(/^(\s*)-\s+runFlow:\s*(.*)$/);
|
|
399
|
+
if (!match) return;
|
|
400
|
+
const baseIndent = match[1].length;
|
|
401
|
+
const inlineValue = stripInlineComment(match[2]);
|
|
402
|
+
if (inlineValue && !inlineValue.startsWith('{') && !inlineValue.startsWith('|')) {
|
|
403
|
+
includes.push({ file: unquote(inlineValue), line: index + 1 });
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// Block form: the `file:` key is a direct child (first indentation level
|
|
408
|
+
// below the command), never a property of a nested `when:`/`commands:` map.
|
|
409
|
+
let childIndent = null;
|
|
410
|
+
for (let i = index + 1; i < lines.length; i += 1) {
|
|
411
|
+
const candidate = lines[i];
|
|
412
|
+
const candidateTrimmed = candidate.trim();
|
|
413
|
+
if (candidateTrimmed === '' || candidateTrimmed.startsWith('#')) continue;
|
|
414
|
+
const indent = candidate.match(/^(\s*)/)[1].length;
|
|
415
|
+
if (indent <= baseIndent) return;
|
|
416
|
+
if (childIndent === null) childIndent = indent;
|
|
417
|
+
if (indent !== childIndent) continue;
|
|
418
|
+
const fileMatch = candidate.match(/^\s*file:\s*(.*)$/);
|
|
419
|
+
if (fileMatch) {
|
|
420
|
+
const value = unquote(stripInlineComment(fileMatch[1]));
|
|
421
|
+
if (value) includes.push({ file: value, line: i + 1 });
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
return includes;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function validate() {
|
|
430
|
+
const root = parseRootArg(process.argv.slice(2));
|
|
431
|
+
const flowsDir = path.join(root, FLOWS_SUBPATH);
|
|
432
|
+
const mobileDir = path.join(root, 'mobile');
|
|
433
|
+
const matrixFile = path.join(flowsDir, 'matrix.yaml');
|
|
434
|
+
const violations = [];
|
|
435
|
+
const report = [];
|
|
436
|
+
|
|
437
|
+
if (!fs.existsSync(flowsDir)) {
|
|
438
|
+
return { violations: [`flows directory not found: ${path.relative(root, flowsDir) || flowsDir}`], report };
|
|
439
|
+
}
|
|
440
|
+
if (!fs.existsSync(mobileDir)) {
|
|
441
|
+
return { violations: [`mobile directory not found: ${path.relative(root, mobileDir) || mobileDir}`], report };
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const matrixContent = readText(matrixFile);
|
|
445
|
+
if (matrixContent === null) {
|
|
446
|
+
return { violations: ['flows/matrix.yaml is missing'], report };
|
|
447
|
+
}
|
|
448
|
+
const parsed = parseMatrix(matrixContent);
|
|
449
|
+
violations.push(...parsed.violations);
|
|
450
|
+
report.push(`matrix: ${parsed.journeys.length} journey(s) declared`);
|
|
451
|
+
|
|
452
|
+
const referencedFlows = new Set();
|
|
453
|
+
const mobileTestIds = collectMobileTestIds(mobileDir);
|
|
454
|
+
|
|
455
|
+
// F-348 — `runFlow: file:` includes are part of the flow graph: their paths
|
|
456
|
+
// must resolve (relative to the including file, as Maestro does), they may
|
|
457
|
+
// nest, and their selectors are real coverage. Resolve the whole include graph
|
|
458
|
+
// once; a missing path, an escape outside `flows/`, a cycle, or a dangling
|
|
459
|
+
// testID inside a shared subflow is a violation, never a silent skip.
|
|
460
|
+
const flowTestIdsCache = new Map();
|
|
461
|
+
const includeStack = [];
|
|
462
|
+
|
|
463
|
+
function resolveFlowTestIds(flowAbs, displayName) {
|
|
464
|
+
if (flowTestIdsCache.has(flowAbs)) return flowTestIdsCache.get(flowAbs);
|
|
465
|
+
if (includeStack.includes(flowAbs)) {
|
|
466
|
+
const cycle = [...includeStack.slice(includeStack.indexOf(flowAbs)), flowAbs]
|
|
467
|
+
.map((entry) => path.relative(flowsDir, entry))
|
|
468
|
+
.join(' -> ');
|
|
469
|
+
violations.push(`flow "${displayName}": runFlow include cycle ${cycle}`);
|
|
470
|
+
return new Set();
|
|
471
|
+
}
|
|
472
|
+
const content = readText(flowAbs);
|
|
473
|
+
if (content === null) return new Set();
|
|
474
|
+
|
|
475
|
+
includeStack.push(flowAbs);
|
|
476
|
+
const ids = extractFlowTestIds(content);
|
|
477
|
+
extractRunFlowIncludes(content).forEach((include) => {
|
|
478
|
+
const label = `flow "${displayName}":${include.line}`;
|
|
479
|
+
const includeAbs = path.resolve(path.dirname(flowAbs), include.file);
|
|
480
|
+
if (includeAbs !== flowsDir && !includeAbs.startsWith(`${flowsDir}${path.sep}`)) {
|
|
481
|
+
violations.push(`${label}: runFlow file "${include.file}" escapes the flows directory`);
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
if (!fs.existsSync(includeAbs)) {
|
|
485
|
+
violations.push(
|
|
486
|
+
`${label}: runFlow file "${include.file}" is missing (resolved to ${path.relative(root, includeAbs)})`
|
|
487
|
+
);
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
const nested = readText(includeAbs);
|
|
491
|
+
if (nested === null || nested.trim() === '') {
|
|
492
|
+
violations.push(`${label}: runFlow file "${include.file}" is empty`);
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
resolveFlowTestIds(includeAbs, path.relative(flowsDir, includeAbs)).forEach((id) => ids.add(id));
|
|
496
|
+
});
|
|
497
|
+
includeStack.pop();
|
|
498
|
+
|
|
499
|
+
flowTestIdsCache.set(flowAbs, ids);
|
|
500
|
+
return ids;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
parsed.journeys.forEach((journey) => {
|
|
504
|
+
if (!journey.flow) return;
|
|
505
|
+
referencedFlows.add(journey.flow);
|
|
506
|
+
const flowFile = path.join(flowsDir, journey.flow);
|
|
507
|
+
if (!fs.existsSync(flowFile)) {
|
|
508
|
+
violations.push(`journey "${journey.id}": flow file "${journey.flow}" is missing`);
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
const content = readText(flowFile) || '';
|
|
512
|
+
if (content.trim() === '') {
|
|
513
|
+
violations.push(`journey "${journey.id}": flow file "${journey.flow}" is empty`);
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
violations.push(...validateFlowStructure(journey.flow, content));
|
|
518
|
+
|
|
519
|
+
const flowTestIds = resolveFlowTestIds(flowFile, journey.flow);
|
|
520
|
+
const declaredTestIds = new Set([...journey.testids, ...flowTestIds]);
|
|
521
|
+
declaredTestIds.forEach((testId) => {
|
|
522
|
+
if (!resolveMobileTestId(testId, mobileTestIds)) {
|
|
523
|
+
violations.push(`journey "${journey.id}": testID "${testId}" has no static or dynamic testID= in mobile/`);
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
journey.screens.forEach((screen) => {
|
|
528
|
+
const screenFile = path.join(root, screen);
|
|
529
|
+
if (!fs.existsSync(screenFile)) {
|
|
530
|
+
violations.push(`journey "${journey.id}": screen "${screen}" does not resolve under mobile/`);
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
report.push(`journey "${journey.id}": flow ${journey.flow}, ${journey.screens.length} screen(s), ${declaredTestIds.size} testID(s)`);
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
// Orphan check: every flow on disk (except the manifest) must be referenced.
|
|
538
|
+
let flowFiles = [];
|
|
539
|
+
try {
|
|
540
|
+
flowFiles = fs.readdirSync(flowsDir).filter((name) => name.endsWith('.yaml') && name !== 'matrix.yaml');
|
|
541
|
+
} catch {
|
|
542
|
+
flowFiles = [];
|
|
543
|
+
}
|
|
544
|
+
flowFiles.forEach((name) => {
|
|
545
|
+
if (!referencedFlows.has(name)) {
|
|
546
|
+
violations.push(`orphan flow: "${name}" is not referenced by any journey in matrix.yaml`);
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
report.push(`flows on disk: ${flowFiles.length}, referenced: ${referencedFlows.size}`);
|
|
550
|
+
|
|
551
|
+
return { violations, report };
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function main() {
|
|
555
|
+
const { violations, report } = validate();
|
|
556
|
+
report.forEach((line) => console.log(` · ${line}`));
|
|
557
|
+
if (violations.length > 0) {
|
|
558
|
+
console.error(`\nFAIL — ${violations.length} flow-coverage violation(s):`);
|
|
559
|
+
violations.forEach((violation) => console.error(` ✗ ${violation}`));
|
|
560
|
+
process.exit(1);
|
|
561
|
+
}
|
|
562
|
+
console.log('\nPASS — mobile E2E flow coverage is structurally valid.');
|
|
563
|
+
process.exit(0);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
if (require.main === module) main();
|
|
567
|
+
|
|
568
|
+
module.exports = { parseInlineList, parseMatrix, extractRunFlowIncludes, validate };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# F-291 performance — Maestro workspace config.
|
|
2
|
+
#
|
|
3
|
+
# `disableAnimations: true` makes Maestro set the device's window/transition/
|
|
4
|
+
# animator animation scales to 0 for the run (and restores them afterwards).
|
|
5
|
+
# Every command's `waitForAnimationToEnd` settle then returns almost
|
|
6
|
+
# immediately, which is the single biggest per-command cost on the
|
|
7
|
+
# software-rendered WSL2 emulator (run4 measured ~2.5 s/command, ~3.6 s/tap).
|
|
8
|
+
# Assertions, selectors, and coverage are unchanged — only the dead wait time.
|
|
9
|
+
#
|
|
10
|
+
# run-maestro.js passes this file explicitly with `maestro test --config`.
|
|
11
|
+
# Both platforms get `disableAnimations: true`; Maestro applies only the entry
|
|
12
|
+
# for the target device's platform, so keeping the Android block does not affect
|
|
13
|
+
# an iOS run (and vice versa).
|
|
14
|
+
platform:
|
|
15
|
+
android:
|
|
16
|
+
disableAnimations: true
|
|
17
|
+
ios:
|
|
18
|
+
disableAnimations: true
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
#
|
|
3
|
+
# mobile E2E — bring the device tier DOWN cleanly: stop the dev server, optionally
|
|
4
|
+
# the emulator, and prune dead `.serve/` records so a stopped emulator is never
|
|
5
|
+
# misreported as live (and its RAM is actually freed).
|
|
6
|
+
#
|
|
7
|
+
# Pairs with `device-up.sh`. The rule is: stop a dev server as soon as its tier
|
|
8
|
+
# passes; reuse an emulator WITHIN a session but stop it at session end. This
|
|
9
|
+
# makes that one command instead of a hand-typed `serve.js stop` per process.
|
|
10
|
+
#
|
|
11
|
+
# Usage:
|
|
12
|
+
# scripts/qa/mobile-e2e/device-down.sh # stop dev server + prune
|
|
13
|
+
# scripts/qa/mobile-e2e/device-down.sh --emulator # also stop the emulator (or iOS Simulator)
|
|
14
|
+
# scripts/qa/mobile-e2e/device-down.sh --all # stop-all heavy tiers
|
|
15
|
+
#
|
|
16
|
+
# Platform: android (default) or ios from `MOBILE_E2E_PLATFORM` / local.json
|
|
17
|
+
# `platform`. On ios the simulator is stopped via ios-simulator-down.sh.
|
|
18
|
+
set -euo pipefail
|
|
19
|
+
|
|
20
|
+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
|
|
21
|
+
cd "$ROOT"
|
|
22
|
+
LOCAL_CONFIG="$ROOT/scripts/qa/mobile-e2e/local.json"
|
|
23
|
+
|
|
24
|
+
DEV_NAME="${MOBILE_E2E_DEV_NAME:-$(node -e "try{const c=require('$LOCAL_CONFIG');process.stdout.write(c.devName||'')}catch(e){}" 2>/dev/null || true)}"
|
|
25
|
+
[ -z "$DEV_NAME" ] && DEV_NAME="app-dev"
|
|
26
|
+
|
|
27
|
+
# Platform selection: env MOBILE_E2E_PLATFORM > local.json `platform` > android.
|
|
28
|
+
# On ios the simulator is stopped via the sibling ios-simulator-down.sh instead
|
|
29
|
+
# of the adb/emulator teardown (which is Android-only).
|
|
30
|
+
PLATFORM="${MOBILE_E2E_PLATFORM:-$(node -e "try{const c=require('$LOCAL_CONFIG');process.stdout.write(c.platform||'')}catch(e){}" 2>/dev/null || true)}"
|
|
31
|
+
case "$PLATFORM" in ios|iOS|IOS) PLATFORM=ios ;; *) PLATFORM=android ;; esac
|
|
32
|
+
|
|
33
|
+
MODE="dev"
|
|
34
|
+
for arg in "$@"; do
|
|
35
|
+
case "$arg" in
|
|
36
|
+
--emulator) MODE="emulator" ;;
|
|
37
|
+
--all) MODE="all" ;;
|
|
38
|
+
-h|--help) sed -n '2,20p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; exit 0 ;;
|
|
39
|
+
*) echo "unknown argument: $arg" >&2; exit 2 ;;
|
|
40
|
+
esac
|
|
41
|
+
done
|
|
42
|
+
|
|
43
|
+
# Persist a quickboot snapshot before the emulator goes away, so the next
|
|
44
|
+
# device-up boots in seconds. Best-effort: a device that is already gone (or a
|
|
45
|
+
# save the emulator refuses) must never fail the teardown — but the failure is
|
|
46
|
+
# SURFACED (to stderr + `.serve/snapshot-save.log`), because a silent save
|
|
47
|
+
# failure is what made every bring-up cold-boot while the runbook claimed warm
|
|
48
|
+
# booting.
|
|
49
|
+
save_snapshot() {
|
|
50
|
+
[ "${MOBILE_E2E_SNAPSHOT:-1}" = "0" ] && return 0
|
|
51
|
+
local sdk="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$HOME/android-sdk}}"
|
|
52
|
+
local adb="$sdk/platform-tools/adb"
|
|
53
|
+
local name="${MOBILE_E2E_SNAPSHOT_NAME:-agent-e2e}"
|
|
54
|
+
local log="$ROOT/.serve/snapshot-save.log"
|
|
55
|
+
[ -x "$adb" ] || return 0
|
|
56
|
+
timeout 10 "$adb" get-state >/dev/null 2>&1 || return 0
|
|
57
|
+
echo "device-down: saving quickboot snapshot ($name)"
|
|
58
|
+
mkdir -p "$ROOT/.serve"
|
|
59
|
+
if timeout 120 "$adb" emu avd snapshot save "$name" >"$log" 2>&1; then
|
|
60
|
+
echo "device-down: snapshot saved ($name)"
|
|
61
|
+
else
|
|
62
|
+
echo "device-down: ! snapshot save failed — next device-up will cold boot (see $log)" >&2
|
|
63
|
+
fi
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if [ "$MODE" = "all" ]; then
|
|
67
|
+
echo "device-down: stop-all + prune"
|
|
68
|
+
if [ "$PLATFORM" = "android" ]; then save_snapshot; fi
|
|
69
|
+
node scripts/serve.js stop-all || true
|
|
70
|
+
if [ "$PLATFORM" = "ios" ]; then bash scripts/qa/mobile-e2e/ios-simulator-down.sh || true; fi
|
|
71
|
+
else
|
|
72
|
+
echo "device-down: stop dev server ($DEV_NAME)"
|
|
73
|
+
node scripts/serve.js stop --name "$DEV_NAME" || true
|
|
74
|
+
if [ "$MODE" = "emulator" ]; then
|
|
75
|
+
if [ "$PLATFORM" = "ios" ]; then
|
|
76
|
+
echo "device-down: stop iOS Simulator"
|
|
77
|
+
bash scripts/qa/mobile-e2e/ios-simulator-down.sh || true
|
|
78
|
+
else
|
|
79
|
+
save_snapshot
|
|
80
|
+
echo "device-down: stop emulator"
|
|
81
|
+
node scripts/serve.js stop --name emulator || true
|
|
82
|
+
node scripts/serve.js stop --name adb-server || true
|
|
83
|
+
fi
|
|
84
|
+
fi
|
|
85
|
+
fi
|
|
86
|
+
|
|
87
|
+
node scripts/serve.js prune --worktrees || true
|
|
88
|
+
node scripts/serve.js list || true
|