mobile-automator 0.38.1 → 0.38.2
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/README.md +1 -1
- package/package.json +1 -1
- package/src/cli.js +2 -2
- package/src/device/action-catalog.js +35 -10
- package/src/guide/content/execute.agnostic.md +4 -4
- package/src/guide/content/execute.aware.md +5 -5
- package/src/guide/content/generate.agnostic.md +1 -1
- package/src/guide/content/generate.aware.md +2 -2
- package/src/scenario/references.js +160 -0
- package/src/scenario/replayability.js +49 -41
- package/src/scenario/steps.js +27 -0
package/README.md
CHANGED
|
@@ -148,7 +148,7 @@ Most low-level verbs are called **by the agent**, not by you. The ones you'll ru
|
|
|
148
148
|
| `mauto memory show [--kind <k>] [--scenario <id>]` | Print cross-session memory (run history auto-harvested from results) as raw markdown for the agent to read at run start |
|
|
149
149
|
| `mauto memory add <text> --kind <app-knowledge\|preferences>` | Record a durable agent-learned app fact or user preference (`[asserted]`, de-duped) |
|
|
150
150
|
| `mauto memory forget --kind <k> --match <substr>` | Remove agent-authored memory entries matching a substring (the correction path) |
|
|
151
|
-
| `mauto validate <file> [--strict]` | Validate a scenario JSON against the schema; warns on actions that cannot replay (`--strict` fails) |
|
|
151
|
+
| `mauto validate <file> [--strict]` | Validate a scenario JSON against the schema; warns on actions that cannot replay and on broken step/variable references (`--strict` fails) |
|
|
152
152
|
| `mauto config get\|set <key> [value]` | Read / update workspace config |
|
|
153
153
|
| **Agent-driven verbs** | `elements`, `tap`, `type`, `swipe`, `press`, `screenshot`, `assert`, `result`, `schema` |
|
|
154
154
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobile-automator",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.2",
|
|
4
4
|
"description": "Host-agnostic mauto CLI for AI-driven mobile QA automation — analyzes a mobile project and drives devices through mobile-mcp.",
|
|
5
5
|
"homepage": "https://github.com/sh3lan93/mobile-automator#readme",
|
|
6
6
|
"repository": {
|
package/src/cli.js
CHANGED
|
@@ -258,7 +258,7 @@ function handleValidate({ validator }, file, opts = {}) {
|
|
|
258
258
|
}
|
|
259
259
|
const { blocking, hint } = summarize(warnings);
|
|
260
260
|
if (opts.strict && blocking.length > 0) {
|
|
261
|
-
const env = fail('invalid_input', 'scenario
|
|
261
|
+
const env = fail('invalid_input', 'scenario cannot replay unattended; see data.warnings', hint);
|
|
262
262
|
env.data = { valid: false, errors: [], warnings };
|
|
263
263
|
return { envelope: env, exitKind: 'invalid_input' };
|
|
264
264
|
}
|
|
@@ -2019,7 +2019,7 @@ function buildProgram(deps = {}) {
|
|
|
2019
2019
|
program
|
|
2020
2020
|
.command('validate <file>')
|
|
2021
2021
|
.description('Validate a scenario JSON file against the scenario schema')
|
|
2022
|
-
.option('--strict', 'fail (instead of warn) when the scenario
|
|
2022
|
+
.option('--strict', 'fail (instead of warn) when the scenario cannot replay unattended')
|
|
2023
2023
|
.action(withEnvelope((file, opts) => {
|
|
2024
2024
|
const r = handleValidate({ validator }, file, { strict: Boolean(opts && opts.strict) });
|
|
2025
2025
|
emit(r, humanFlag());
|
|
@@ -27,6 +27,11 @@
|
|
|
27
27
|
// method must pass — deliberately explicit because the keys are inconsistent
|
|
28
28
|
// across the engine (launch=packageName, uninstall=packageName, install=path).
|
|
29
29
|
//
|
|
30
|
+
// `requiresTarget` (every step-enum action; precondition-only actions omit it)
|
|
31
|
+
// says whether the step locates an element, so needs a `target` or
|
|
32
|
+
// `target_pattern`. `waitAction: true` marks the actions the schema's
|
|
33
|
+
// `wait_config` configures. targetActions()/waitActions() derive both sets.
|
|
34
|
+
//
|
|
30
35
|
// `stepFlags` records a scenario step field that changes how the verb runs:
|
|
31
36
|
// `{ field, value, flag }` means "when step[field] === value, pass flag". This
|
|
32
37
|
// is the one place the mapping lives; the E2E harness derives the flags via
|
|
@@ -42,31 +47,38 @@
|
|
|
42
47
|
const ACTION_CATALOG = {
|
|
43
48
|
// --- direct verbs (engine-backed) --------------------------------------
|
|
44
49
|
tap: {
|
|
50
|
+
requiresTarget: true,
|
|
45
51
|
resolution: 'verb', verb: 'tap', bridge: 'tap',
|
|
46
52
|
primitive: 'mobile_click_on_screen_at_coordinates', args: ['x', 'y'],
|
|
47
53
|
},
|
|
48
54
|
long_press: {
|
|
55
|
+
requiresTarget: true,
|
|
49
56
|
resolution: 'verb', verb: 'long-press', bridge: 'longPress',
|
|
50
57
|
primitive: 'mobile_long_press_on_screen_at_coordinates', args: ['x', 'y', 'duration?'],
|
|
51
58
|
},
|
|
52
59
|
double_tap: {
|
|
60
|
+
requiresTarget: true,
|
|
53
61
|
resolution: 'verb', verb: 'double-tap', bridge: 'doubleTap',
|
|
54
62
|
primitive: 'mobile_double_tap_on_screen', args: ['x', 'y'],
|
|
55
63
|
},
|
|
56
64
|
type: {
|
|
65
|
+
requiresTarget: false,
|
|
57
66
|
resolution: 'verb', verb: 'type', bridge: 'type',
|
|
58
67
|
primitive: 'mobile_type_keys', args: ['text', 'submit'],
|
|
59
68
|
},
|
|
60
69
|
swipe: {
|
|
70
|
+
requiresTarget: false,
|
|
61
71
|
resolution: 'verb', verb: 'swipe', bridge: 'swipe',
|
|
62
72
|
primitive: 'mobile_swipe_on_screen', args: ['direction'],
|
|
63
73
|
},
|
|
64
74
|
press_button: {
|
|
75
|
+
requiresTarget: false,
|
|
65
76
|
resolution: 'verb', verb: 'press', bridge: 'pressButton',
|
|
66
77
|
primitive: 'mobile_press_button', args: ['button'],
|
|
67
78
|
},
|
|
68
79
|
launch_app: {
|
|
69
80
|
// Cold start (#255): restartApp terminates, then launches.
|
|
81
|
+
requiresTarget: false,
|
|
70
82
|
resolution: 'verb', verb: 'launch', bridge: 'restartApp',
|
|
71
83
|
primitives: ['mobile_terminate_app', 'mobile_launch_app'], args: ['packageName'],
|
|
72
84
|
// `cold: false` opts out of the restart (#255).
|
|
@@ -81,6 +93,7 @@ const ACTION_CATALOG = {
|
|
|
81
93
|
primitive: 'mobile_uninstall_app', args: ['packageName'],
|
|
82
94
|
},
|
|
83
95
|
open_url: {
|
|
96
|
+
requiresTarget: false,
|
|
84
97
|
resolution: 'verb', verb: 'open-url', bridge: 'openUrl',
|
|
85
98
|
primitive: 'mobile_open_url', args: ['url'],
|
|
86
99
|
},
|
|
@@ -90,24 +103,35 @@ const ACTION_CATALOG = {
|
|
|
90
103
|
},
|
|
91
104
|
|
|
92
105
|
// --- semantic (mauto press <action>, platform-resolved) ----------------
|
|
93
|
-
press_back: { resolution: 'semantic', verb: 'press' },
|
|
94
|
-
dismiss_keyboard: { resolution: 'semantic', verb: 'press' },
|
|
95
|
-
grant_permission: { resolution: 'semantic', verb: 'press' },
|
|
96
|
-
deny_permission: { resolution: 'semantic', verb: 'press' },
|
|
106
|
+
press_back: { requiresTarget: false, resolution: 'semantic', verb: 'press' },
|
|
107
|
+
dismiss_keyboard: { requiresTarget: false, resolution: 'semantic', verb: 'press' },
|
|
108
|
+
grant_permission: { requiresTarget: false, resolution: 'semantic', verb: 'press' },
|
|
109
|
+
deny_permission: { requiresTarget: false, resolution: 'semantic', verb: 'press' },
|
|
97
110
|
|
|
98
111
|
// --- composed (agent builds from existing verbs; no dedicated verb) -----
|
|
99
|
-
scroll_to_element: { resolution: 'composed' },
|
|
100
|
-
wait_for_element: { resolution: 'composed' },
|
|
101
|
-
wait_for_element_gone: { resolution: 'composed' },
|
|
102
|
-
wait_for_loading_complete: { resolution: 'composed' },
|
|
103
|
-
capture_value: { resolution: 'composed' },
|
|
112
|
+
scroll_to_element: { requiresTarget: true, resolution: 'composed' },
|
|
113
|
+
wait_for_element: { requiresTarget: true, waitAction: true, resolution: 'composed' },
|
|
114
|
+
wait_for_element_gone: { requiresTarget: true, waitAction: true, resolution: 'composed' },
|
|
115
|
+
wait_for_loading_complete: { requiresTarget: false, waitAction: true, resolution: 'composed' },
|
|
116
|
+
capture_value: { requiresTarget: true, resolution: 'composed' },
|
|
104
117
|
|
|
105
118
|
// --- unsupported (no mobile-mcp 1.0.5 primitive) -----------------------
|
|
106
|
-
clear_app_data: { resolution: 'unsupported' },
|
|
119
|
+
clear_app_data: { requiresTarget: false, resolution: 'unsupported' },
|
|
107
120
|
enable_wifi: { resolution: 'unsupported' },
|
|
108
121
|
disable_wifi: { resolution: 'unsupported' },
|
|
109
122
|
};
|
|
110
123
|
|
|
124
|
+
// Steps that locate an element on screen (tap, waits, scroll, capture) need a
|
|
125
|
+
// `target` or `target_pattern`; the scenario referential checks read this set.
|
|
126
|
+
function targetActions() {
|
|
127
|
+
return Object.keys(ACTION_CATALOG).filter((a) => ACTION_CATALOG[a].requiresTarget === true);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Steps the schema's `wait_config` configures.
|
|
131
|
+
function waitActions() {
|
|
132
|
+
return Object.keys(ACTION_CATALOG).filter((a) => ACTION_CATALOG[a].waitAction === true);
|
|
133
|
+
}
|
|
134
|
+
|
|
111
135
|
const RESOLUTIONS = ['verb', 'semantic', 'composed', 'unsupported'];
|
|
112
136
|
|
|
113
137
|
function actionsByResolution(resolution) {
|
|
@@ -141,4 +165,5 @@ function implicitStepFlags(action, step) {
|
|
|
141
165
|
|
|
142
166
|
module.exports = {
|
|
143
167
|
ACTION_CATALOG, RESOLUTIONS, actionsByResolution, primitivesOf, stepFlagsFor, implicitStepFlags,
|
|
168
|
+
targetActions, waitActions,
|
|
144
169
|
};
|
|
@@ -54,15 +54,15 @@ Record each observation with `mauto result add-step --observation <type>:<messag
|
|
|
54
54
|
|
|
55
55
|
1. **Name the run first.** Choose the run identifier for this execution (format `run_YYYYMMDD_HHMMSS`) and export it as `MAUTO_RUN_ID` before running any other verb — `export MAUTO_RUN_ID=run_20260905_141500`. Every verb then records into a trace for that run, and `mauto result finalize --run-id <the same id>` measures the run's duration from it instead of taking your word for it. Use the *same* id in both places; a different one means no trace to measure.
|
|
56
56
|
2. Read the scenario JSON.
|
|
57
|
-
3.
|
|
58
|
-
4.
|
|
57
|
+
3. **Validate schema version:** read the `$schema_version` field; it must be `"2.1"`. If absent or unrecognized, report an error and halt.
|
|
58
|
+
4. Validate the scenario with `mauto validate <path>` against `mauto schema scenario`. If `validate` itself fails (`ok: false`), stop and report its errors, and run no device verbs. If the result lists `data.warnings`, branch on each entry's `code` (its `path` names the step or precondition): `unsupported_action` means it uses an action that is unsupported on this run: report it as unsupported in the result (see "Not mechanically executable" under step execution) and do not substitute a gesture for it. `launch_cold_implicit` is advisory: replay that step exactly as written (a step that does not set `"cold": false` is a cold start, per the step table below) and do not substitute your own reading of what the author meant; record the warning's `message` as a `state_context` observation on that step (`mauto result add-step ... --observation state_context:<message>`). `duplicate_step_id`, `dangling_after_step`, `missing_target`, `undeclared_capture_variable` and `dangling_condition_step` mean the scenario itself is broken (a step id used twice, a reference to a step or variable that does not exist, a step with no element to resolve): run no further verbs against the device and do not guess the missing reference; finalize the run with `mauto result finalize --run-id <the run id> --scenario-id <scenario_id> --status error --summary "<each warning's path and message>"`, and ask the user to fix the scenario. `missing_wait_config` is advisory: replay that wait step with the default timeout and record the warning's `message` as a `state_context` observation on that step.
|
|
59
|
+
5. Verify a device is available with `mauto devices`. Read the device's `platform` field — store it for the duration of execution.
|
|
60
|
+
6. **App under test.**
|
|
59
61
|
- If the user pointed you at a prebuilt app artifact, install it with `mauto install <path>`.
|
|
60
62
|
- Otherwise verify the app is already installed; if it is not, halt and ask the user to install it. This guide never builds.
|
|
61
63
|
- **Fresh install.** If the scenario's `preconditions.app_state` is `fresh_install` and the user pointed you at a prebuilt app artifact, uninstall the app first with `mauto uninstall <appId>` (the app identifier from `.mobile-automator/config.json` — `android_package` / `ios_bundle_id`) and only then install that artifact, so the run starts with no app data. Without an artifact, do not uninstall — you could not reinstall the app. Leave it in place and report that the app state was not reset, so a failure that depends on existing app data is not mistaken for a regression.
|
|
62
64
|
- If the install fails because a different build is already on the device, uninstall it with `mauto uninstall <appId>` (the app identifier from `.mobile-automator/config.json` — `android_package` / `ios_bundle_id`), install again, and report that app data was wiped — a scenario whose preconditions assume existing app state may now fail for that reason.
|
|
63
65
|
- State which path you took before continuing.
|
|
64
|
-
5. **Validate schema version:** read the `$schema_version` field; it must be `"2.1"`. If absent or unrecognized, report an error and halt.
|
|
65
|
-
6. Validate the scenario with `mauto validate <path>` against `mauto schema scenario`. If the result lists `data.warnings`, branch on each entry's `code` (its `path` names the step or precondition): `unsupported_action` means it uses an action that is unsupported on this run: report it as unsupported in the result (see "Not mechanically executable" under step execution) and do not substitute a gesture for it. `launch_cold_implicit` is advisory: replay that step exactly as written (a step that does not set `"cold": false` is a cold start, per the step table below) and do not substitute your own reading of what the author meant; record the warning's `message` as a `state_context` observation on that step (`mauto result add-step ... --observation state_context:<message>`).
|
|
66
66
|
|
|
67
67
|
**Precondition `device_actions`** (from the scenario's `preconditions`, run before step replay):
|
|
68
68
|
|
|
@@ -52,18 +52,18 @@ Record each observation with `mauto result add-step --observation <type>:<messag
|
|
|
52
52
|
### 1. Pre-flight
|
|
53
53
|
|
|
54
54
|
- **Name the run first.** Choose the run identifier for this execution (format `run_YYYYMMDD_HHMMSS`) and export it as `MAUTO_RUN_ID` before running any other verb — `export MAUTO_RUN_ID=run_20260905_141500`. Every verb then records into a trace for that run, and `mauto result finalize --run-id <the same id>` measures the run's duration from it instead of taking your word for it. Use the *same* id in both places; a different one means no trace to measure.
|
|
55
|
+
- Read the JSON scenario file from `.mobile-automator/scenarios/`.
|
|
56
|
+
- **Validate schema version:** Read the `$schema_version` field. It must be `"2.1"`. If absent or unrecognized, report an error and halt.
|
|
57
|
+
- Validate the scenario with `mauto validate <path>` against `mauto schema scenario`. If `validate` itself fails (`ok: false`), stop and report its errors, and run no device verbs. If the result lists `data.warnings`, branch on each entry's `code` (its `path` names the step or precondition): `unsupported_action` means it uses an action that is unsupported on this run: report it as unsupported in the result, as described under "Not mechanically executable" below, and do not substitute a gesture for it. `launch_cold_implicit` is advisory: replay that step exactly as written (a step that does not set `"cold": false` is a cold start, per the step table below) and do not substitute your own reading of what the author meant; record the warning's `message` as a `state_context` observation on that step (`mauto result add-step ... --observation state_context:<message>`). `duplicate_step_id`, `dangling_after_step`, `missing_target`, `undeclared_capture_variable` and `dangling_condition_step` mean the scenario itself is broken (a step id used twice, a reference to a step or variable that does not exist, a step with no element to resolve): run no further verbs against the device and do not guess the missing reference; finalize the run with `mauto result finalize --run-id <the run id> --scenario-id <scenario_id> --status error --summary "<each warning's path and message>"`, and ask the user to fix the scenario. `missing_wait_config` is advisory: replay that wait step with the default timeout and record the warning's `message` as a `state_context` observation on that step.
|
|
55
58
|
- Verify a device is available with `mauto devices`.
|
|
56
59
|
- **App under test.** If the user pointed you at a prebuilt artifact, install it with `mauto install <path>` and do NOT build — reusing a ready artifact is the point.
|
|
57
60
|
- If no artifact was named: check whether the app is already installed. If it is, say so and ask whether to rebuild before running the build command ({{build_command}}) — a previous run may have just built it. If it is not installed, build and install with the build command ({{build_command}}).
|
|
58
61
|
- If that install fails because a different build of the app is already on the device, uninstall it — run `mauto uninstall` with the app package ({{app_package}}) — then install again, and report that app data was wiped — a scenario whose preconditions assume existing app state may now fail for that reason.
|
|
59
|
-
- **Fresh install.** If the scenario's `preconditions.app_state` is `fresh_install` (
|
|
62
|
+
- **Fresh install.** If the scenario's `preconditions.app_state` is `fresh_install` (from the scenario you read above), uninstall the app first — `mauto uninstall` with the app package ({{app_package}}) — and only then install, so the run starts with no app data.
|
|
60
63
|
- State which path you took — installed a supplied artifact, or built — before continuing.
|
|
61
64
|
|
|
62
|
-
### 2.
|
|
65
|
+
### 2. Compare Environment
|
|
63
66
|
|
|
64
|
-
- Read the JSON scenario file from `.mobile-automator/scenarios/`.
|
|
65
|
-
- **Validate schema version:** Read the `$schema_version` field. It must be `"2.1"`. If absent or unrecognized, report an error and halt.
|
|
66
|
-
- Validate the scenario with `mauto validate <path>` against `mauto schema scenario`. If the result lists `data.warnings`, branch on each entry's `code` (its `path` names the step or precondition): `unsupported_action` means it uses an action that is unsupported on this run: report it as unsupported in the result, as described under "Not mechanically executable" below, and do not substitute a gesture for it. `launch_cold_implicit` is advisory: replay that step exactly as written (a step that does not set `"cold": false` is a cold start, per the step table below) and do not substitute your own reading of what the author meant; record the warning's `message` as a `state_context` observation on that step (`mauto result add-step ... --observation state_context:<message>`).
|
|
67
67
|
- Read the `metadata` to compare the recording environment against the current execution environment. Note any differences (different device, API level, environment).
|
|
68
68
|
|
|
69
69
|
### 3. Verify Preconditions
|
|
@@ -203,7 +203,7 @@ After all steps are executed and recorded:
|
|
|
203
203
|
2. Obtain the scenario schema by running `mauto schema scenario`, and assemble the JSON scenario to match it. Include the `tags` array.
|
|
204
204
|
3. **Always include `"$schema_version": "2.1"` as the first field** in agnostic-mode scenarios.
|
|
205
205
|
4. **Use named string IDs** for all steps and assertions (snake_case, e.g., `"id": "tap_login"`).
|
|
206
|
-
5. Validate the assembled scenario with `mauto validate <path>` against `mauto schema scenario`. If it returns `data.warnings`, revise the scenario to drop each `unsupported_action` step, or tell the user the step needs manual handling; for a `launch_cold_implicit` entry, set the step's `cold` explicitly (`false` when it means returning to the already-open app, `true` when it means a restart).
|
|
206
|
+
5. Validate the assembled scenario with `mauto validate <path>` against `mauto schema scenario`. If it returns `data.warnings`, revise the scenario to drop each `unsupported_action` step, or tell the user the step needs manual handling; for a `launch_cold_implicit` entry, set the step's `cold` explicitly (`false` when it means returning to the already-open app, `true` when it means a restart). Fix every reference finding before you save, using its `path`: `duplicate_step_id` — rename the step so every id is unique; `dangling_after_step` — point the assertion's `after_step` at a step that exists; `missing_target` — give the step the `target` it acts on; `undeclared_capture_variable` — declare the variable in the root `variables` block; `dangling_condition_step` — point the `previous_step_skipped` condition's `step_id` at an earlier step; `missing_wait_config` — add a `wait_config` with an explicit `timeout_ms`.
|
|
207
207
|
6. Save to `.mobile-automator/scenarios/<scenario_id>.json`.
|
|
208
208
|
7. Present summary:
|
|
209
209
|
> "Scenario saved: `.mobile-automator/scenarios/<scenario_id>.json`
|
|
@@ -217,7 +217,7 @@ After all steps are executed and recorded:
|
|
|
217
217
|
- `app_version` — from the installed app
|
|
218
218
|
- `environment` — ask the user or use `default_environment` from `.mobile-automator/config.json`
|
|
219
219
|
- Do NOT include `device_model`, `api_level`, or `timestamp` in metadata — these belong in the result schema, not the scenario.
|
|
220
|
-
7. Validate the assembled scenario with `mauto validate <path>` against `mauto schema scenario`. If it returns `data.warnings`, revise the scenario to drop each `unsupported_action` step, or tell the user the step needs manual handling; for a `launch_cold_implicit` entry, set the step's `cold` explicitly (`false` when it means returning to the already-open app, `true` when it means a restart).
|
|
220
|
+
7. Validate the assembled scenario with `mauto validate <path>` against `mauto schema scenario`. If it returns `data.warnings`, revise the scenario to drop each `unsupported_action` step, or tell the user the step needs manual handling; for a `launch_cold_implicit` entry, set the step's `cold` explicitly (`false` when it means returning to the already-open app, `true` when it means a restart). Fix every reference finding before you save, using its `path`: `duplicate_step_id` — rename the step so every id is unique; `dangling_after_step` — point the assertion's `after_step` at a step that exists; `missing_target` — give the step the `target` it acts on; `undeclared_capture_variable` — declare the variable in the root `variables` block; `dangling_condition_step` — point the `previous_step_skipped` condition's `step_id` at an earlier step; `missing_wait_config` — add a `wait_config` with an explicit `timeout_ms`.
|
|
221
221
|
8. Save to `.mobile-automator/scenarios/<scenario_id>.json`.
|
|
222
222
|
9. Present summary:
|
|
223
223
|
> "Scenario saved: `.mobile-automator/scenarios/<scenario_id>.json`
|
|
@@ -269,7 +269,7 @@ Translate user language to `mauto` verbs and schema actions:
|
|
|
269
269
|
- Create assertion step using mapped type from Pass 2b
|
|
270
270
|
- Evaluate via `mauto assert <type> ...` and record with appropriate fields
|
|
271
271
|
6. Combine steps and assertions into ordered scenario
|
|
272
|
-
7. Generate scenario JSON, then `mauto validate <path>` (if it returns `data.warnings`, revise the scenario to drop each `unsupported_action` step, or tell the user the step needs manual handling; for a `launch_cold_implicit` entry, set the step's `cold` explicitly)
|
|
272
|
+
7. Generate scenario JSON, then `mauto validate <path>` (if it returns `data.warnings`, revise the scenario to drop each `unsupported_action` step, or tell the user the step needs manual handling; for a `launch_cold_implicit` entry, set the step's `cold` explicitly; fix each `duplicate_step_id`, `dangling_after_step`, `missing_target`, `undeclared_capture_variable`, `dangling_condition_step` and `missing_wait_config` entry as "Save Scenario" describes)
|
|
273
273
|
```
|
|
274
274
|
|
|
275
275
|
### Detecting and Encoding Patterns
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { targetActions, waitActions } = require('../device/action-catalog');
|
|
4
|
+
|
|
5
|
+
// Referential checks for scenarios (#272). The schema types every reference as
|
|
6
|
+
// a bare string, so a scenario whose ids, targets and variables do not line up
|
|
7
|
+
// still validates -- and the gap surfaces mid-run, on a device. This module
|
|
8
|
+
// reports those gaps as finding descriptors -- `{ code, fields }`, plus `path`
|
|
9
|
+
// and `ids` for assertions -- and `replayability.js` turns them into warnings
|
|
10
|
+
// with its one constructor, during its one walk over the steps, so `validate`
|
|
11
|
+
// sees one finding list in one shape.
|
|
12
|
+
//
|
|
13
|
+
// Every code but `missing_wait_config` is blocking: the step or assertion has
|
|
14
|
+
// nothing to resolve against, so it cannot replay unattended. A wait without
|
|
15
|
+
// `wait_config` still runs on the default timeout, so that one is advisory.
|
|
16
|
+
|
|
17
|
+
// Which step actions need a target, and which take `wait_config`, are catalog
|
|
18
|
+
// facts (src/device/action-catalog.js), not restated here.
|
|
19
|
+
const TARGET_ACTIONS = new Set(targetActions());
|
|
20
|
+
const WAIT_ACTIONS = new Set(waitActions());
|
|
21
|
+
|
|
22
|
+
// A condition or assertion of these types reads a variable, so it must name one.
|
|
23
|
+
const CONDITION_TYPES_NEEDING_VARIABLE = new Set(['variable_value']);
|
|
24
|
+
const ASSERTION_TYPES_NEEDING_VARIABLE = new Set(['value_matches_variable']);
|
|
25
|
+
|
|
26
|
+
// Finding fields for a variable name that is undeclared, or absent where its
|
|
27
|
+
// type requires one (an empty name counts as absent there); null when fine.
|
|
28
|
+
function variableFields(field, name, required, index) {
|
|
29
|
+
const ref = required && name === '' ? undefined : name;
|
|
30
|
+
if (ref === undefined ? !required : index.variables.has(ref)) return null;
|
|
31
|
+
return { field, ref };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const REFERENCE_CODES = {
|
|
35
|
+
duplicate_step_id: {
|
|
36
|
+
blocking: true,
|
|
37
|
+
clause: (n) => `${n} step id(s) are declared more than once`,
|
|
38
|
+
message: (f) => `step id "${f.ref}" is already used by ${f.firstPath}; `
|
|
39
|
+
+ 'step ids must be unique so assertions and conditions can name one step',
|
|
40
|
+
},
|
|
41
|
+
dangling_after_step: {
|
|
42
|
+
blocking: true,
|
|
43
|
+
clause: (n) => `${n} assertion(s) run after a step that does not exist`,
|
|
44
|
+
message: (f) => (f.ref === undefined
|
|
45
|
+
? 'assertion has no "after_step"; name the step it runs after'
|
|
46
|
+
: `assertion runs after step "${f.ref}", which no step declares`),
|
|
47
|
+
},
|
|
48
|
+
missing_target: {
|
|
49
|
+
blocking: true,
|
|
50
|
+
clause: (n) => `${n} step(s) have no target to resolve`,
|
|
51
|
+
message: (f) => `${f.action} has no "target" (or "target_pattern"), so there is no element to resolve`,
|
|
52
|
+
},
|
|
53
|
+
undeclared_capture_variable: {
|
|
54
|
+
blocking: true,
|
|
55
|
+
clause: (n) => `${n} variable reference(s) are not declared in "variables"`,
|
|
56
|
+
message: (f) => (f.ref === undefined
|
|
57
|
+
? `"${f.field}" is required here but has no variable name`
|
|
58
|
+
: `"${f.field}" names variable "${f.ref}", which the root "variables" block does not declare`),
|
|
59
|
+
},
|
|
60
|
+
dangling_condition_step: {
|
|
61
|
+
blocking: true,
|
|
62
|
+
clause: (n) => `${n} condition(s) refer to a step that has not run`,
|
|
63
|
+
message: (f) => (f.ref === undefined
|
|
64
|
+
? 'previous_step_skipped condition has no "step_id"; name an earlier step'
|
|
65
|
+
: `previous_step_skipped condition names step "${f.ref}", which is not an earlier step`),
|
|
66
|
+
},
|
|
67
|
+
missing_wait_config: {
|
|
68
|
+
blocking: false,
|
|
69
|
+
clause: (n) => `${n} wait step(s) have no wait_config; the default timeout applies`,
|
|
70
|
+
message: (f) => `${f.action} has no "wait_config", so it waits for the default timeout; `
|
|
71
|
+
+ 'set "wait_config" to make the wait explicit',
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const isNonEmptyString = (v) => typeof v === 'string' && v.length > 0;
|
|
76
|
+
|
|
77
|
+
// Indexes the flattened step list (see `steps.js`): `after_step` and duplicate
|
|
78
|
+
// detection need every step, and a condition's step must come earlier, i.e.
|
|
79
|
+
// at a lower position in `entries`.
|
|
80
|
+
function referenceIndex(scenario, entries) {
|
|
81
|
+
const firstPathById = new Map();
|
|
82
|
+
const orderById = new Map();
|
|
83
|
+
entries.forEach(({ step, path }, position) => {
|
|
84
|
+
if (typeof step.id === 'string' && !firstPathById.has(step.id)) {
|
|
85
|
+
firstPathById.set(step.id, path);
|
|
86
|
+
orderById.set(step.id, position);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const vars = scenario && scenario.variables;
|
|
91
|
+
const variables = new Set(vars && typeof vars === 'object' && !Array.isArray(vars) ? Object.keys(vars) : []);
|
|
92
|
+
return { firstPathById, orderById, variables };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Descriptors for one step; the caller supplies its path, action and id.
|
|
96
|
+
// `position` is its index in the flattened step list, the same numbering
|
|
97
|
+
// `orderById` uses.
|
|
98
|
+
function stepReferences(step, position, index) {
|
|
99
|
+
const findings = [];
|
|
100
|
+
const add = (code, fields) => findings.push({ code, fields });
|
|
101
|
+
|
|
102
|
+
const firstPath = index.firstPathById.get(step.id);
|
|
103
|
+
if (firstPath !== undefined && index.orderById.get(step.id) !== position) {
|
|
104
|
+
add('duplicate_step_id', { ref: step.id, firstPath });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (TARGET_ACTIONS.has(step.action) && !isNonEmptyString(step.target) && !isNonEmptyString(step.target_pattern)) {
|
|
108
|
+
add('missing_target', {});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (WAIT_ACTIONS.has(step.action) && !step.wait_config) {
|
|
112
|
+
add('missing_wait_config', {});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (step.capture_to !== undefined && !index.variables.has(step.capture_to)) {
|
|
116
|
+
add('undeclared_capture_variable', { field: 'capture_to', ref: step.capture_to });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const cond = step.condition;
|
|
120
|
+
if (cond && typeof cond === 'object') {
|
|
121
|
+
const fields = variableFields('condition.variable_name', cond.variable_name,
|
|
122
|
+
CONDITION_TYPES_NEEDING_VARIABLE.has(cond.type), index);
|
|
123
|
+
if (fields) add('undeclared_capture_variable', fields);
|
|
124
|
+
if (cond.type === 'previous_step_skipped') {
|
|
125
|
+
const order = index.orderById.get(cond.step_id);
|
|
126
|
+
if (order === undefined || order >= position) {
|
|
127
|
+
add('dangling_condition_step', { ref: cond.step_id });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return findings;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Descriptors for the root `assertions` array, in order, each with its path
|
|
136
|
+
// and `assertion_id`.
|
|
137
|
+
function assertionReferences(scenario, index) {
|
|
138
|
+
const assertions = scenario && scenario.assertions;
|
|
139
|
+
if (!Array.isArray(assertions)) return [];
|
|
140
|
+
const findings = [];
|
|
141
|
+
assertions.forEach((a, i) => {
|
|
142
|
+
if (!a) return;
|
|
143
|
+
const path = `assertions[${i}]`;
|
|
144
|
+
const ids = a.id !== undefined ? { assertion_id: a.id } : {};
|
|
145
|
+
if (!index.firstPathById.has(a.after_step)) {
|
|
146
|
+
findings.push({ code: 'dangling_after_step', fields: { ref: a.after_step }, path, ids });
|
|
147
|
+
}
|
|
148
|
+
const fields = variableFields('variable_name', a.variable_name,
|
|
149
|
+
ASSERTION_TYPES_NEEDING_VARIABLE.has(a.type), index);
|
|
150
|
+
if (fields) findings.push({ code: 'undeclared_capture_variable', fields, path, ids });
|
|
151
|
+
});
|
|
152
|
+
return findings;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
module.exports = {
|
|
156
|
+
REFERENCE_CODES,
|
|
157
|
+
referenceIndex,
|
|
158
|
+
stepReferences,
|
|
159
|
+
assertionReferences,
|
|
160
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// Replayability check for scenarios. Schema validity alone overstates what a
|
|
4
|
-
// scenario will do on replay; this module reports
|
|
4
|
+
// scenario will do on replay; this module reports three kinds of gap:
|
|
5
5
|
//
|
|
6
6
|
// - `unsupported_action` (#166): the schema accepts every action in its enum,
|
|
7
7
|
// but the action catalog marks some `unsupported`. no `mauto` verb reaches
|
|
@@ -11,17 +11,31 @@
|
|
|
11
11
|
// `warnWhenUnset`. A step after the first that leaves the marked field to its
|
|
12
12
|
// schema default is ambiguous about the author's intent. Advisory: it never
|
|
13
13
|
// fails `--strict`.
|
|
14
|
+
// - Referential gaps (#272): duplicate step ids, dangling references, steps
|
|
15
|
+
// with no target, undeclared variables, waits with no `wait_config`. The
|
|
16
|
+
// `references` module owns those codes; this one merges its findings into
|
|
17
|
+
// the single walk over `flattenSteps`, so `CODES` stays the one table
|
|
18
|
+
// every consumer reads.
|
|
14
19
|
//
|
|
15
20
|
// The unsupported set is derived from the catalog, never restated here, so it
|
|
16
21
|
// moves when an action gains (or loses) a device primitive.
|
|
17
22
|
|
|
18
23
|
const { actionsByResolution, implicitStepFlags } = require('../device/action-catalog');
|
|
24
|
+
const {
|
|
25
|
+
REFERENCE_CODES,
|
|
26
|
+
referenceIndex,
|
|
27
|
+
stepReferences,
|
|
28
|
+
assertionReferences,
|
|
29
|
+
} = require('./references');
|
|
30
|
+
const { flattenSteps } = require('./steps');
|
|
19
31
|
|
|
20
|
-
// Severity and wording for every finding code
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
// `
|
|
24
|
-
//
|
|
32
|
+
// Severity and wording for every finding code: the replay codes are defined
|
|
33
|
+
// here, the referential ones in `references.js`, and `CODES` assembles both, so
|
|
34
|
+
// it is the one table every consumer reads.
|
|
35
|
+
// `blocking` is the `--strict` policy: a blocking finding means the scenario
|
|
36
|
+
// cannot replay unattended as written: a step that cannot run or a broken
|
|
37
|
+
// reference. `clause(n)` is the hint fragment for n findings of the code;
|
|
38
|
+
// `message(f)` is the per-finding text.
|
|
25
39
|
const CODES = {
|
|
26
40
|
unsupported_action: {
|
|
27
41
|
blocking: true,
|
|
@@ -35,61 +49,55 @@ const CODES = {
|
|
|
35
49
|
+ `set "${f.field}" explicitly (${JSON.stringify(f.value)} to return to the running app, `
|
|
36
50
|
+ `${JSON.stringify(!f.value)} to confirm the restart)`,
|
|
37
51
|
},
|
|
52
|
+
...REFERENCE_CODES,
|
|
38
53
|
};
|
|
39
54
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
55
|
+
// The one constructor for a `data.warnings` entry: `{ code, action, path,
|
|
56
|
+
// message }` plus `step_id` or `assertion_id` from `ids`. `action` is omitted
|
|
57
|
+
// when the finding has none (an assertion).
|
|
58
|
+
function makeFinding(code, fields, path, ids = {}) {
|
|
59
|
+
const f = { code };
|
|
60
|
+
if (fields.action !== undefined) f.action = fields.action;
|
|
61
|
+
f.path = path;
|
|
62
|
+
f.message = CODES[code].message(fields);
|
|
63
|
+
return Object.assign(f, ids);
|
|
44
64
|
}
|
|
45
65
|
|
|
46
|
-
|
|
47
|
-
return makeFinding('unsupported_action', { action }, path, stepId);
|
|
48
|
-
}
|
|
66
|
+
const stepIds = (step) => (step.id !== undefined ? { step_id: step.id } : {});
|
|
49
67
|
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
function
|
|
53
|
-
|
|
54
|
-
|
|
68
|
+
// Returns every finding in document order: steps first (including nested
|
|
69
|
+
// sub_steps, depth-first), then precondition device actions, then assertions.
|
|
70
|
+
function findReplayWarnings(scenario) {
|
|
71
|
+
const unsupported = new Set(actionsByResolution('unsupported'));
|
|
72
|
+
const entries = flattenSteps(scenario);
|
|
73
|
+
const index = referenceIndex(scenario, entries);
|
|
74
|
+
const findings = [];
|
|
55
75
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
steps.forEach((step, i) => {
|
|
61
|
-
if (!step) return;
|
|
62
|
-
const path = `${basePath}[${i}]`;
|
|
63
|
-
if (unsupported.has(step.action)) {
|
|
64
|
-
findings.push(unsupportedFinding(step.action, path, step.id));
|
|
65
|
-
}
|
|
76
|
+
entries.forEach(({ step, path, isFirstTopLevel }, position) => {
|
|
77
|
+
const ids = stepIds(step);
|
|
78
|
+
const add = (code, fields) => findings.push(makeFinding(code, { action: step.action, ...fields }, path, ids));
|
|
79
|
+
if (unsupported.has(step.action)) add('unsupported_action', {});
|
|
66
80
|
// Only the scenario's first top-level step is unambiguously a fresh
|
|
67
81
|
// start; any other step that leaves a marked field unset is worth a look.
|
|
68
|
-
|
|
82
|
+
// The catalog owns the marker's code, field and default value.
|
|
83
|
+
if (!isFirstTopLevel) {
|
|
69
84
|
for (const sf of implicitStepFlags(step.action, step)) {
|
|
70
|
-
|
|
85
|
+
add(sf.warnWhenUnset, { field: sf.field, value: sf.value });
|
|
71
86
|
}
|
|
72
87
|
}
|
|
73
|
-
|
|
88
|
+
for (const r of stepReferences(step, position, index)) add(r.code, r.fields);
|
|
74
89
|
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Returns every finding in document order: steps first (including nested
|
|
78
|
-
// sub_steps, depth-first), then precondition device actions.
|
|
79
|
-
function findReplayWarnings(scenario) {
|
|
80
|
-
const unsupported = new Set(actionsByResolution('unsupported'));
|
|
81
|
-
const findings = [];
|
|
82
|
-
|
|
83
|
-
scanSteps(scenario && scenario.steps, 'steps', unsupported, findings, true);
|
|
84
90
|
|
|
85
91
|
const pre = scenario && scenario.preconditions;
|
|
86
92
|
const deviceActions = pre && Array.isArray(pre.device_actions) ? pre.device_actions : [];
|
|
87
93
|
deviceActions.forEach((da, i) => {
|
|
88
94
|
if (da && unsupported.has(da.action)) {
|
|
89
|
-
findings.push(
|
|
95
|
+
findings.push(makeFinding('unsupported_action', { action: da.action }, `preconditions.device_actions[${i}]`));
|
|
90
96
|
}
|
|
91
97
|
});
|
|
92
98
|
|
|
99
|
+
for (const r of assertionReferences(scenario, index)) findings.push(makeFinding(r.code, r.fields, r.path, r.ids));
|
|
100
|
+
|
|
93
101
|
return findings;
|
|
94
102
|
}
|
|
95
103
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// The one walk over a scenario's step tree. Steps nest freely through
|
|
4
|
+
// `sub_steps` (the schema types them as steps), and every check that cares
|
|
5
|
+
// about step order reads it from this list: an entry's index is its position
|
|
6
|
+
// in depth-first document order, so "earlier step" means a lower index.
|
|
7
|
+
|
|
8
|
+
// Returns `[{ step, path, isFirstTopLevel }]`, parents before their sub_steps.
|
|
9
|
+
// Null steps and non-array step lists are skipped; a skipped step keeps its
|
|
10
|
+
// slot in the paths of its siblings. Only the scenario's first top-level step
|
|
11
|
+
// is `isFirstTopLevel`.
|
|
12
|
+
function flattenSteps(scenario) {
|
|
13
|
+
const entries = [];
|
|
14
|
+
const walk = (steps, basePath, topLevel) => {
|
|
15
|
+
if (!Array.isArray(steps)) return;
|
|
16
|
+
steps.forEach((step, i) => {
|
|
17
|
+
if (!step) return;
|
|
18
|
+
const path = `${basePath}[${i}]`;
|
|
19
|
+
entries.push({ step, path, isFirstTopLevel: topLevel && i === 0 });
|
|
20
|
+
walk(step.sub_steps, `${path}.sub_steps`, false);
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
walk(scenario && scenario.steps, 'steps', true);
|
|
24
|
+
return entries;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = { flattenSteps };
|