simframe 0.14.2 → 0.15.0
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 +18 -6
- package/native/simframed/Sources/PrivateAPI/AccessibilityBridge.swift +66 -5
- package/native/simframed/Sources/PrivateAPI/CoreSimulatorPlatform.swift +4 -0
- package/native/simframed/Sources/PrivateAPI/PrivateAPI.swift +7 -0
- package/native/simframed/Sources/PrivateAPI/StubPlatform.swift +7 -0
- package/native/simframed/Sources/simframed/main.swift +10 -0
- package/package.json +1 -1
- package/scripts/check-published.mjs +121 -0
- package/scripts/ci-device-guard.mjs +1 -10
- package/scripts/classify-stray.mjs +63 -0
- package/scripts/device-state.mjs +62 -0
- package/scripts/eval-fingerprint.mjs +115 -13
- package/src/actions.js +225 -13
- package/src/baseline.js +16 -1
- package/src/cli.js +9 -0
- package/src/control.js +2 -0
- package/src/frontmost.js +171 -0
- package/src/metrics.js +19 -1
- package/src/platform/android.js +10 -0
- package/src/platform/ios.js +20 -1
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
import fs from 'node:fs';
|
|
21
21
|
import * as actions from '../src/actions.js';
|
|
22
22
|
import * as fingerprint from '../src/fingerprint.js';
|
|
23
|
+
import { classifyStray } from './classify-stray.mjs';
|
|
23
24
|
import * as graph from '../src/graph.js';
|
|
24
25
|
import * as api from '../src/index.js';
|
|
25
26
|
|
|
@@ -152,12 +153,24 @@ const STALE_READ_RETRIES = 3;
|
|
|
152
153
|
* Backed off rather than fixed, because the thing being waited for is a screen
|
|
153
154
|
* finishing its draw, and the runner that needs this is the slow one.
|
|
154
155
|
*/
|
|
156
|
+
/**
|
|
157
|
+
* How old a frame may be and still be a reading of NOW.
|
|
158
|
+
*
|
|
159
|
+
* `FRAME_IS_CURRENT_MS` in src/index.js is 2500 for the same question on the
|
|
160
|
+
* settle path. Doubled here because this harness deliberately reads cold and a
|
|
161
|
+
* hosted runner's capture p50 is 2.5x this laptop's — but bounded, because a
|
|
162
|
+
* 38-second-old frame is a different screen, not a slow one.
|
|
163
|
+
*/
|
|
164
|
+
const FRAME_TOO_OLD_MS = 5000;
|
|
165
|
+
|
|
155
166
|
const SPARSE_READ_RETRIES = 3;
|
|
156
167
|
const SPARSE_READ_WAIT_MS = 1500;
|
|
157
168
|
const STALE_READ_WAIT_MS = 1000;
|
|
158
169
|
|
|
159
170
|
/** When the steps that were supposed to change the screen finished. */
|
|
160
171
|
let navigatedAt = 0;
|
|
172
|
+
/** What the tour's own steps said, kept for the arrival report. */
|
|
173
|
+
let lastSteps = [];
|
|
161
174
|
/** Readings that never got a frame newer than their own navigation. */
|
|
162
175
|
const staleReadings = [];
|
|
163
176
|
|
|
@@ -222,7 +235,37 @@ for (let round = 1; round <= rounds; round += 1) {
|
|
|
222
235
|
// written out first, because a failing run is the one whose evidence
|
|
223
236
|
// matters.
|
|
224
237
|
try {
|
|
225
|
-
|
|
238
|
+
// Keep what the tour's own steps reported. On an arrival failure the
|
|
239
|
+
// decisive question is whether the last wait PASSED and on what — and
|
|
240
|
+
// that answer was being thrown away, so three CI failures in a row
|
|
241
|
+
// could only be reasoned about rather than read. A local reproduction
|
|
242
|
+
// ran the same sequence 14 times and landed correctly every time, so
|
|
243
|
+
// the runner is the only place this can be observed.
|
|
244
|
+
const run = await actions.runScript(device, { steps: screen.steps, verify: false });
|
|
245
|
+
lastSteps = (run?.results ?? []).map((r) => ({
|
|
246
|
+
action: r.action,
|
|
247
|
+
ok: r.ok !== false,
|
|
248
|
+
ms: r.ms,
|
|
249
|
+
detail: typeof r.detail === 'string' ? r.detail.slice(0, 200) : null,
|
|
250
|
+
}));
|
|
251
|
+
// **`runScript` does not throw on a failed step** — it returns
|
|
252
|
+
// `ok: !failed` — and this only ever caught throws. So a tour whose
|
|
253
|
+
// `waitFor` timed out was treated as having arrived: `navigatedAt` was
|
|
254
|
+
// set, the previous screen was read, and the arrival check then reported
|
|
255
|
+
// it as a fingerprint result. Three CI failures were that, and the
|
|
256
|
+
// diagnostic added one commit earlier is what showed it —
|
|
257
|
+
// `ok launch … / FAIL waitFor` sitting under a reading the harness had
|
|
258
|
+
// accepted.
|
|
259
|
+
//
|
|
260
|
+
// A tour that did not arrive is a precondition, not a measurement. It
|
|
261
|
+
// throws into the same handler as a step that threw, so the report is
|
|
262
|
+
// identical and the readings so far are still written out.
|
|
263
|
+
if (run && run.ok === false) {
|
|
264
|
+
const bad = (run.results ?? []).find((r) => r.ok === false);
|
|
265
|
+
throw new Error(
|
|
266
|
+
`step ${bad?.action ?? '?'} did not succeed: ${bad?.error ?? 'no reason given'}`,
|
|
267
|
+
);
|
|
268
|
+
}
|
|
226
269
|
navigatedAt = Date.now();
|
|
227
270
|
} catch (err) {
|
|
228
271
|
save({ abandonedAt: { screen: screen.name, round, error: err.message } });
|
|
@@ -275,18 +318,38 @@ for (let round = 1; round <= rounds; round += 1) {
|
|
|
275
318
|
// stale — an eval that scores a stale frame is measuring the runner, which
|
|
276
319
|
// is the one thing this harness says it is not doing.
|
|
277
320
|
if (navigatedAt) {
|
|
321
|
+
// TWO conditions, and the second was missing.
|
|
322
|
+
//
|
|
323
|
+
// Newer than the navigation is not the same as recent. Measured on a
|
|
324
|
+
// runner: a reading came off a frame **38,266 ms old** and passed this
|
|
325
|
+
// guard, because the navigation had also been more than 38 s earlier — so
|
|
326
|
+
// `capturedAt >= navigatedAt` held while the frame was half a minute
|
|
327
|
+
// stale and showed a screen two steps back. `settled: true` alongside it,
|
|
328
|
+
// because a starved capture looks exactly like a still one.
|
|
329
|
+
//
|
|
330
|
+
// A frame this old is capture starvation, not a slow screen, and no
|
|
331
|
+
// number of re-reads invents a frame the daemon is not producing. So it
|
|
332
|
+
// retries and then says which of the two it is, because "the frame
|
|
333
|
+
// predates the navigation" and "capture stopped producing frames" point
|
|
334
|
+
// at completely different things.
|
|
335
|
+
const tooOld = (r) => Date.now() - (r.state?.capturedAt ?? 0) > FRAME_TOO_OLD_MS;
|
|
336
|
+
const predatesNav = (r) => (r.state?.capturedAt ?? 0) < navigatedAt;
|
|
278
337
|
for (let attempt = 0; attempt < STALE_READ_RETRIES; attempt += 1) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
338
|
+
if (!predatesNav(id) && !tooOld(id)) break;
|
|
339
|
+
const age = Date.now() - (id.state?.capturedAt ?? 0);
|
|
340
|
+
console.log(` ("${screen.name}" read a frame from ${age}ms ago`
|
|
341
|
+
+ `${predatesNav(id) ? ', older than the navigation' : `, over the ${FRAME_TOO_OLD_MS}ms freshness bound`}`
|
|
283
342
|
+ ` — reading again ${attempt + 1}/${STALE_READ_RETRIES})`);
|
|
284
343
|
await new Promise((r) => setTimeout(r, STALE_READ_WAIT_MS));
|
|
285
344
|
id = await api.screenIdentity(device, { fresh: true, confirmNovel: false });
|
|
286
345
|
}
|
|
287
|
-
if ((id
|
|
346
|
+
if (predatesNav(id)) {
|
|
288
347
|
staleReadings.push(`${screen.name} round ${round}: frame still predates the navigation`
|
|
289
348
|
+ ` by ${navigatedAt - (id.state?.capturedAt ?? 0)}ms after ${STALE_READ_RETRIES} re-reads`);
|
|
349
|
+
} else if (tooOld(id)) {
|
|
350
|
+
staleReadings.push(`${screen.name} round ${round}: newest frame is`
|
|
351
|
+
+ ` ${Date.now() - (id.state?.capturedAt ?? 0)}ms old after ${STALE_READ_RETRIES} re-reads`
|
|
352
|
+
+ ' — capture is starved, not the screen still');
|
|
290
353
|
}
|
|
291
354
|
}
|
|
292
355
|
// A reading too sparse to be a screen is not a reading.
|
|
@@ -343,6 +406,7 @@ for (let round = 1; round <= rounds; round += 1) {
|
|
|
343
406
|
// taken, and every distribution below it is then measuring the tour rather
|
|
344
407
|
// than the fingerprint. The first version of this harness did exactly that
|
|
345
408
|
// and reported that the distributions overlapped completely.
|
|
409
|
+
id.steps = lastSteps;
|
|
346
410
|
const previous = readings[readings.length - 1];
|
|
347
411
|
if (previous && previous.name !== screen.name) {
|
|
348
412
|
// Not just an identical hash. Two readings of the same screen can differ
|
|
@@ -367,10 +431,20 @@ for (let round = 1; round <= rounds; round += 1) {
|
|
|
367
431
|
`${previous.name} -> ${screen.name}: similarity ${s.toFixed(2)} — the screen did not change`
|
|
368
432
|
+ `\n sensors: ${(id.entry?.sources ?? []).join('+') || 'none'}`
|
|
369
433
|
+ `, settled: ${id.settled}, frame ${Math.round(Date.now() - (id.state?.capturedAt ?? Date.now()))}ms old`
|
|
370
|
-
+ `\n on screen: ${labels.length ? labels.join(' · ') : '(nothing readable)'}`
|
|
434
|
+
+ `\n on screen: ${labels.length ? labels.join(' · ') : '(nothing readable)'}`
|
|
435
|
+
// The decisive line, and it was missing. Whether the tour's last wait
|
|
436
|
+
// PASSED, and what it said, separates "the wait matched something it
|
|
437
|
+
// should not have" from "the screen changed after the wait was
|
|
438
|
+
// satisfied" — the two causes this message has always named as having
|
|
439
|
+
// opposite fixes, while giving the reader nothing to tell them apart.
|
|
440
|
+
+ `\n the tour's own steps: ${
|
|
441
|
+
(lastSteps ?? []).length
|
|
442
|
+
? lastSteps.map((st) => `${st.ok ? 'ok' : 'FAIL'} ${st.action}${st.detail ? ` — ${st.detail}` : ''}`).join('\n ')
|
|
443
|
+
: '(not recorded)'}`);
|
|
371
444
|
}
|
|
372
445
|
}
|
|
373
446
|
readings.push({
|
|
447
|
+
steps: lastSteps,
|
|
374
448
|
name: screen.name,
|
|
375
449
|
round,
|
|
376
450
|
hash: id.hash,
|
|
@@ -506,6 +580,17 @@ function findStrays(all) {
|
|
|
506
580
|
}
|
|
507
581
|
|
|
508
582
|
const strays = findStrays(readings);
|
|
583
|
+
// Readings grouped by screen, for the classification below.
|
|
584
|
+
//
|
|
585
|
+
// `findStrays` builds this too and it is LOCAL to that function — so reaching
|
|
586
|
+
// for it here threw `byName is not defined` on a runner, in the middle of the
|
|
587
|
+
// report, after the strays had already been printed. I had validated the
|
|
588
|
+
// classification against a saved artifact in a standalone script, where I had
|
|
589
|
+
// declared it myself, and never once in place. The logic was right and the
|
|
590
|
+
// integration was never run: the unit tests do not reach this file at all.
|
|
591
|
+
const readingsByName = new Map();
|
|
592
|
+
for (const r of readings) readingsByName.set(r.name, [...(readingsByName.get(r.name) ?? []), r]);
|
|
593
|
+
|
|
509
594
|
if (strays.length) {
|
|
510
595
|
console.error(`\nFAIL ${strays.length} reading(s) do not resemble their own screen:`);
|
|
511
596
|
// Two causes wear the same symptom, and until now the report asserted the
|
|
@@ -516,10 +601,25 @@ if (strays.length) {
|
|
|
516
601
|
// label while matching one particular other screen almost exactly, and a
|
|
517
602
|
// wrong turn is one whose tokens name a screen the tour did not ask for.
|
|
518
603
|
let collisions = 0;
|
|
604
|
+
// Kept so the SUMMARY agrees with the lines above it. It did not: the summary
|
|
605
|
+
// tested `sparseAt` directly while each line used the classifier, so a stray
|
|
606
|
+
// correctly labelled WRONG SCREEN was followed by "every stray above was
|
|
607
|
+
// UNDER-READ". A report that contradicts itself in consecutive paragraphs is
|
|
608
|
+
// worse than either sentence alone.
|
|
609
|
+
const verdicts = [];
|
|
519
610
|
for (const { reading, bestSelf, bestOther, match } of strays) {
|
|
520
611
|
const named = namedTokens(reading.tokens);
|
|
521
612
|
const matchNamed = match ? namedTokens(match.tokens) : [];
|
|
522
|
-
|
|
613
|
+
// One classifier, one source of truth. `collided` was computed here as well
|
|
614
|
+
// and the two could drift — which is how this block came to have a third
|
|
615
|
+
// cause landing in the wrong bucket in the first place.
|
|
616
|
+
const verdict = classifyStray({
|
|
617
|
+
reading, match, bestOther, named, matchNamed,
|
|
618
|
+
siblings: readingsByName.get(reading.name) ?? [],
|
|
619
|
+
wasSparse: sparseAt.has(`${reading.name}|${reading.round}`),
|
|
620
|
+
});
|
|
621
|
+
const { collided, underRead, wrongScreen } = verdict;
|
|
622
|
+
verdicts.push(verdict);
|
|
523
623
|
if (collided) collisions += 1;
|
|
524
624
|
// The third cause, and the one that produced this report on 2026-09-15.
|
|
525
625
|
//
|
|
@@ -549,10 +649,6 @@ if (strays.length) {
|
|
|
549
649
|
// distinguishable and a round matching another screen exactly went
|
|
550
650
|
// somewhere else. Only when no round of this screen can tell itself apart
|
|
551
651
|
// is "we did not look long enough" the honest reading.
|
|
552
|
-
const distinguishable = (byName.get(reading.name) ?? [])
|
|
553
|
-
.some((o) => o !== reading && fingerprint.similarity(o.tokens, match?.tokens ?? []) < 0.99);
|
|
554
|
-
const underRead = sparseAt.has(`${reading.name}|${reading.round}`) && !distinguishable;
|
|
555
|
-
const wrongScreen = bestOther >= 0.99 && distinguishable;
|
|
556
652
|
console.error(` ${reading.name} r${reading.round}: own screen ${bestSelf.toFixed(2)}, `
|
|
557
653
|
+ `${match ? `${match.name} r${match.round}` : 'another screen'} ${bestOther.toFixed(2)} `
|
|
558
654
|
+ `(${reading.count} tokens, ${named.length} named, sources ${reading.sources.join('+') || 'none'})`);
|
|
@@ -576,10 +672,16 @@ if (strays.length) {
|
|
|
576
672
|
console.error(`\n${collisions} of ${strays.length} are fingerprint collisions. That is this harness's own subject,`);
|
|
577
673
|
console.error('not a tour fault: a reading whose chrome label went missing cannot establish');
|
|
578
674
|
console.error('identity, and comparing it as though it could is what produced the verdict above.');
|
|
579
|
-
} else if (
|
|
675
|
+
} else if (verdicts.length && verdicts.every((v) => v.underRead)) {
|
|
580
676
|
console.error('\nEvery stray above was UNDER-READ, so this says nothing about the tour or the');
|
|
581
677
|
console.error('fingerprint — the harness scored a look that was too short. The retries are in');
|
|
582
678
|
console.error('SPARSE_READ_RETRIES; a runner that needs more than they allow is the finding.');
|
|
679
|
+
} else if (verdicts.some((v) => v.wrongScreen)) {
|
|
680
|
+
const n = verdicts.filter((v) => v.wrongScreen).length;
|
|
681
|
+
console.error(`\n${n} stray(s) were read on the WRONG SCREEN — the tokens match another screen`);
|
|
682
|
+
console.error('exactly while this one reads differently in its other rounds, so it is');
|
|
683
|
+
console.error('distinguishable and the tour was somewhere else. Not a fingerprint result:');
|
|
684
|
+
console.error('a tap that missed, or a screen that went back before it was read.');
|
|
583
685
|
} else {
|
|
584
686
|
console.error('\nThat is the tour going somewhere unintended, not the fingerprint drifting, and');
|
|
585
687
|
console.error('measuring it as either distribution poisons both ends. Fix the tour — a tap that');
|
package/src/actions.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// Waiting uses a baseline captured BEFORE each action, which is the whole
|
|
4
4
|
// reason these scripts are reliable rather than racy.
|
|
5
5
|
import * as api from './index.js';
|
|
6
|
+
import * as frontmost from './frontmost.js';
|
|
6
7
|
import * as graph from './graph.js';
|
|
7
8
|
import * as input from './input.js';
|
|
8
9
|
import * as intent from './intent.js';
|
|
@@ -396,12 +397,15 @@ export async function runScript(
|
|
|
396
397
|
// its coordinates from the screen size. Reading them back off the step
|
|
397
398
|
// would diagnose a point nothing was ever aimed at.
|
|
398
399
|
const aim = { at: null };
|
|
400
|
+
// Carried out of the dispatch the way `aim` is, because the note that
|
|
401
|
+
// reads it is built after the step has returned a string.
|
|
402
|
+
const landing = { verdict: null };
|
|
399
403
|
let detail;
|
|
400
404
|
// A selector that did not resolve gets the step's own alternatives before
|
|
401
405
|
// the batch is abandoned. Anything else propagates: retrying from a screen
|
|
402
406
|
// we did not expect to be on is not a retry, it is a second guess.
|
|
403
407
|
try {
|
|
404
|
-
detail = await runStep(deviceQuery, udid, step, { screen, options, frames, focus, aim });
|
|
408
|
+
detail = await runStep(deviceQuery, udid, step, { screen, options, frames, focus, aim, landing });
|
|
405
409
|
} catch (thrown) {
|
|
406
410
|
let err = thrown;
|
|
407
411
|
// Ask the supervisor before anything is abandoned. It sits behind the
|
|
@@ -435,7 +439,7 @@ export async function runScript(
|
|
|
435
439
|
options,
|
|
436
440
|
}).catch(() => null);
|
|
437
441
|
try {
|
|
438
|
-
detail = await runStep(deviceQuery, udid, step, { screen, options, frames, focus, aim });
|
|
442
|
+
detail = await runStep(deviceQuery, udid, step, { screen, options, frames, focus, aim, landing });
|
|
439
443
|
detail += ` [the local supervisor said ${ruling.decision}; it worked on the second attempt]`;
|
|
440
444
|
ruled('recovered');
|
|
441
445
|
continue;
|
|
@@ -475,7 +479,7 @@ export async function runScript(
|
|
|
475
479
|
let last = err;
|
|
476
480
|
for (const label of allowed) {
|
|
477
481
|
try {
|
|
478
|
-
detail = await runStep(deviceQuery, udid, stepWithTarget(step, label), { screen, options, frames, focus, aim });
|
|
482
|
+
detail = await runStep(deviceQuery, udid, stepWithTarget(step, label), { screen, options, frames, focus, aim, landing });
|
|
479
483
|
detail += ` [after ${tried.map((t) => JSON.stringify(String(t))).join(', ')} did not resolve]`;
|
|
480
484
|
last = null;
|
|
481
485
|
break;
|
|
@@ -732,7 +736,10 @@ export async function runScript(
|
|
|
732
736
|
// eight times below its threshold, so it reads as no-visible-change and
|
|
733
737
|
// its edge is no longer recorded. That is the right trade while the
|
|
734
738
|
// detector cannot see it, and it comes back on its own once it can.
|
|
735
|
-
|
|
739
|
+
// A changed control IS evidence, whatever the frame hash says. Without
|
|
740
|
+
// this the edge is not recorded either, so a toggle that worked teaches
|
|
741
|
+
// the graph nothing and stays unpredictable forever.
|
|
742
|
+
const noEvidence = Boolean(settled?.noVisibleChange) && !stateDelta(beforeScreen?.entry, afterReading?.entry);
|
|
736
743
|
if (afterScreen.confirmed && afterScreen.hash && !noEvidence) {
|
|
737
744
|
// The observed cost of this transition, which is what makes the next
|
|
738
745
|
// one adaptive. Only from a settle that was actually satisfied: a
|
|
@@ -767,8 +774,14 @@ export async function runScript(
|
|
|
767
774
|
// front an already-running app, so the first reading is the likely one —
|
|
768
775
|
// but likely is not the same as said, and the step is the only place that
|
|
769
776
|
// can say it.
|
|
777
|
+
// Item 169 closed the ambiguity this comment describes, so the note no
|
|
778
|
+
// longer has to hedge when the pid answered. `fronted` with an unmoved
|
|
779
|
+
// screen is now a *fact* about which reading was right, not a guess:
|
|
780
|
+
// the app is confirmed in front, so it was already there.
|
|
770
781
|
const launchNote = step.action === 'launch' && settled?.noVisibleChange
|
|
771
|
-
?
|
|
782
|
+
? (landing.verdict === 'fronted'
|
|
783
|
+
? ' [the screen did not change and this app is confirmed frontmost — it was already in front]'
|
|
784
|
+
: ' [the screen did not change, so this app was already in front — or it did not come forward]')
|
|
772
785
|
: '';
|
|
773
786
|
const filling = stillFillingIn(afterReading?.entry);
|
|
774
787
|
// Item 120: when a gesture aimed at a coordinate does nothing, say what
|
|
@@ -788,7 +801,22 @@ export async function runScript(
|
|
|
788
801
|
// first — and six swipes reporting "no visible change" is what item 120
|
|
789
802
|
// was reported against. Keying on one of them would have shipped a fix
|
|
790
803
|
// that did not fire on its own bug report.
|
|
791
|
-
|
|
804
|
+
// Declared BEFORE `wentNowhere`, which reads it. It sat below and the
|
|
805
|
+
// unit tests were green because nothing without a device reaches this
|
|
806
|
+
// line — a `const` in the temporal dead zone throws on first use, which
|
|
807
|
+
// is the same trap the `afterReading` comment above records.
|
|
808
|
+
//
|
|
809
|
+
// Computed on EITHER signal, because they are two different sensors and
|
|
810
|
+
// the reported case came through the one this first version missed: the
|
|
811
|
+
// radio move settled in 2714ms with `sawChange` true, so
|
|
812
|
+
// `settled.noVisibleChange` was false and the verdict came from the
|
|
813
|
+
// fingerprint instead.
|
|
814
|
+
const changedState = (settled?.noVisibleChange || verification?.verdict === 'no-visible-change')
|
|
815
|
+
? stateDelta(beforeScreen?.entry, afterReading?.entry)
|
|
816
|
+
: null;
|
|
817
|
+
if (changedState) verification = stateChanged(verification, changedState);
|
|
818
|
+
const wentNowhere = !changedState
|
|
819
|
+
&& (Boolean(settled?.noVisibleChange) || verification?.verdict === 'no-visible-change');
|
|
792
820
|
const aimNote = wentNowhere && aim.at
|
|
793
821
|
? screenmap.describePoint(
|
|
794
822
|
// `beforeScreen` is null with verification off, and that is exactly
|
|
@@ -802,7 +830,9 @@ export async function runScript(
|
|
|
802
830
|
const note = launchNote
|
|
803
831
|
+ (filling ? ` [settled, but ${filling} — waitFor content, do not act on this yet]` : '')
|
|
804
832
|
+ (settled?.smallChange ? ' [a small change, in one region only]' : '')
|
|
805
|
-
+ (
|
|
833
|
+
+ (changedState
|
|
834
|
+
? ` [the screen did not move, but ${changedState.detail} — this worked, do not retry]`
|
|
835
|
+
: (settled?.noVisibleChange ? ' [no visible change]' : ''))
|
|
806
836
|
// After the symptom, because it is the explanation of it.
|
|
807
837
|
+ (aimNote ? ` [${aimNote}]` : '')
|
|
808
838
|
+ (settled?.staleBaseline ? ' [baseline had already settled; re-taken from the live screen]' : '')
|
|
@@ -1594,6 +1624,37 @@ async function confirmNoChange(deviceQuery, verification, { beforeScreen, option
|
|
|
1594
1624
|
};
|
|
1595
1625
|
}
|
|
1596
1626
|
|
|
1627
|
+
/**
|
|
1628
|
+
* A control that changed state is not a step that did nothing.
|
|
1629
|
+
*
|
|
1630
|
+
* The sibling of `belowThreshold` on the same verdict, for the other kind of
|
|
1631
|
+
* evidence. `no-visible-change` arrives by two routes — the pixel detector and
|
|
1632
|
+
* the fingerprint agreeing we are on the same screen — and a switch or a radio
|
|
1633
|
+
* satisfies both while having plainly worked. Measured on a device: a radio
|
|
1634
|
+
* moving from "Top" to "Inline" reported `(settled 2714ms)
|
|
1635
|
+
* [no-visible-change]` with `selected` moving between the two rows in the
|
|
1636
|
+
* element list either side of it.
|
|
1637
|
+
*
|
|
1638
|
+
* This is the verdict an agent reads to decide whether to retry, and after item
|
|
1639
|
+
* 148 made the tap actually land, a retry undoes the thing that worked. So the
|
|
1640
|
+
* verdict carries the evidence rather than contradicting it.
|
|
1641
|
+
*
|
|
1642
|
+
* Still not `ok`: the screen genuinely did not become a different screen, and
|
|
1643
|
+
* claiming a transition that did not happen would be the opposite error. It
|
|
1644
|
+
* becomes `unverified` — the verdict this project uses for "something happened
|
|
1645
|
+
* and nobody can vouch for what" — with the change named.
|
|
1646
|
+
*/
|
|
1647
|
+
export function stateChanged(verification, delta) {
|
|
1648
|
+
if (verification?.verdict !== 'no-visible-change' || !delta) return verification;
|
|
1649
|
+
return {
|
|
1650
|
+
...verification,
|
|
1651
|
+
verdict: 'unverified',
|
|
1652
|
+
detail: `the screen did not change, but ${delta.detail}`
|
|
1653
|
+
+ ' — the action worked; do not retry it, or you will undo it',
|
|
1654
|
+
stateDelta: delta,
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1597
1658
|
export function belowThreshold(verification, settled) {
|
|
1598
1659
|
if (verification?.verdict !== 'no-visible-change' || !settled?.smallChange) return verification;
|
|
1599
1660
|
return {
|
|
@@ -1641,6 +1702,37 @@ async function focusHint(deviceQuery, target, ctx) {
|
|
|
1641
1702
|
}
|
|
1642
1703
|
}
|
|
1643
1704
|
|
|
1705
|
+
/**
|
|
1706
|
+
* Is anything focused? Asked before typing blind.
|
|
1707
|
+
*
|
|
1708
|
+
* `{"type": "text"}` with no `into` types into whatever has focus, and reported
|
|
1709
|
+
* `ok … [unconfirmed — no field named, so nothing was read back]`. The note was
|
|
1710
|
+
* honest and it was attached to a **green step**, so a chained `sim_do`
|
|
1711
|
+
* continued on a premise that had never been checked — a field report lost text
|
|
1712
|
+
* that went nowhere exactly this way.
|
|
1713
|
+
*
|
|
1714
|
+
* If nothing has focus, the keystrokes are lost and there is no version of that
|
|
1715
|
+
* which is an `ok`. The tree already answers it: one accessibility read, no
|
|
1716
|
+
* OCR, which is the same cost `focusHint` pays on the `into` path.
|
|
1717
|
+
*
|
|
1718
|
+
* Advisory in one direction only. A tree that cannot answer — no targets, a
|
|
1719
|
+
* read that threw — returns `unknown`, and the step proceeds with its
|
|
1720
|
+
* unconfirmed note rather than failing on our inability to look. Refusing to
|
|
1721
|
+
* type because we could not read the screen would be a worse trade than the
|
|
1722
|
+
* bug.
|
|
1723
|
+
*/
|
|
1724
|
+
async function focusedSomewhere(deviceQuery, ctx) {
|
|
1725
|
+
try {
|
|
1726
|
+
const { entry } = await api.readScreenWith(deviceQuery, { useOcr: false, options: ctx.options });
|
|
1727
|
+
const targets = entry?.targets ?? [];
|
|
1728
|
+
if (!targets.length) return { known: false };
|
|
1729
|
+
const hit = targets.find((t) => t.focused === true);
|
|
1730
|
+
return { known: true, focused: Boolean(hit), where: hit?.label ?? hit?.identifier ?? null };
|
|
1731
|
+
} catch {
|
|
1732
|
+
return { known: false };
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1644
1736
|
/**
|
|
1645
1737
|
* How long to wait for the tap to become focus before inserting text.
|
|
1646
1738
|
*
|
|
@@ -2319,11 +2411,29 @@ async function runStep(deviceQuery, udid, step, ctx) {
|
|
|
2319
2411
|
journalWrite(udid, step, sent, back, ctx);
|
|
2320
2412
|
return `typed into ${field.where}${back.note}${back.landed ? '' : field.quiet}`;
|
|
2321
2413
|
}
|
|
2414
|
+
// **Refusing here was tried and reverted — see DEFERRED 161.** The idea
|
|
2415
|
+
// was that "nothing focused" is knowable before typing, so typing into
|
|
2416
|
+
// nothing should fail rather than report `ok`. On a device it produced a
|
|
2417
|
+
// FALSE REFUSAL on the legitimate case: after tapping Settings' own
|
|
2418
|
+
// search field, every element in the tree read `focused: false`. iOS does
|
|
2419
|
+
// not reliably publish AXFocused here, which `focusHint` above already
|
|
2420
|
+
// says in its own comment — *"with a hardware keyboard attached to the
|
|
2421
|
+
// simulator no software keyboard appears, so there is often nothing to
|
|
2422
|
+
// see"*. A gate on an unpublished signal blocks real work, which is worse
|
|
2423
|
+
// than the verdict it was fixing.
|
|
2424
|
+
//
|
|
2425
|
+
// So the focus reading stays advisory and goes into the note. What the
|
|
2426
|
+
// field report actually objected to was an honest caveat attached to a
|
|
2427
|
+
// GREEN step, and the note is where that has to be fixed until there is a
|
|
2428
|
+
// signal worth gating on.
|
|
2429
|
+
const focus = await focusedSomewhere(deviceQuery, ctx);
|
|
2322
2430
|
await input.typeText(udid, step.text ?? step.value);
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2431
|
+
return 'typed text [NOT CONFIRMED: no field named, so nothing was read back'
|
|
2432
|
+
+ (focus.known && !focus.focused
|
|
2433
|
+
? ' and nothing on this screen reports keyboard focus — the text may have gone nowhere'
|
|
2434
|
+
: '')
|
|
2435
|
+
+ '. Name the field — {"type": {"into": "<field>", "text": "..."}} — to have it tapped'
|
|
2436
|
+
+ ' first and read back]';
|
|
2327
2437
|
}
|
|
2328
2438
|
case 'paste': {
|
|
2329
2439
|
// Long strings are much faster on the pasteboard than through the
|
|
@@ -2383,12 +2493,54 @@ async function runStep(deviceQuery, udid, step, ctx) {
|
|
|
2383
2493
|
return `pressed key ${step.value ?? step.code}`;
|
|
2384
2494
|
case 'launch': {
|
|
2385
2495
|
const bundleId = step.value ?? step.bundleId;
|
|
2386
|
-
await launchApp(udid, bundleId, {
|
|
2496
|
+
const started = await launchApp(udid, bundleId, {
|
|
2387
2497
|
args: step.args ?? [],
|
|
2388
2498
|
env: step.env ?? {},
|
|
2389
2499
|
terminateFirst: step.relaunch === true,
|
|
2390
2500
|
});
|
|
2391
|
-
|
|
2501
|
+
// Item 169: simctl returning ok means the process started, not that the
|
|
2502
|
+
// app came forward, and the two came apart repeatedly on a loaded
|
|
2503
|
+
// runner — leaving the device on the previous app under a step that
|
|
2504
|
+
// reported success. The pid settles it; the screen cannot.
|
|
2505
|
+
let landed = await frontmost.check(udid, started?.pid ?? null);
|
|
2506
|
+
// One bounded retry, on a condition we have now *measured* rather than
|
|
2507
|
+
// guessed at. This was rejected in the first pass for a good reason —
|
|
2508
|
+
// retrying on "no visible change" papers over a signal that cannot tell
|
|
2509
|
+
// success from failure — and that objection does not apply to a known
|
|
2510
|
+
// `did-not-front`: the app is running, a second `launch` without a
|
|
2511
|
+
// terminate simply fronts it, and that is the 237ms path.
|
|
2512
|
+
//
|
|
2513
|
+
// It is deliberately NOT a terminate-and-relaunch. That is the gesture
|
|
2514
|
+
// this project already knows wedges the simulator's display pipeline
|
|
2515
|
+
// (README, "rapid app relaunch"), so the recovery must not be the thing
|
|
2516
|
+
// that causes the next failure.
|
|
2517
|
+
//
|
|
2518
|
+
// Reported, never silent: CI's own step vehicle has been doing this by
|
|
2519
|
+
// hand three times, invisibly, which is how the defect stayed at the
|
|
2520
|
+
// harness layer for so long. A retry that does not show up in the
|
|
2521
|
+
// summary is a rate nobody can argue with.
|
|
2522
|
+
let retried = null;
|
|
2523
|
+
if (landed.verdict === 'did-not-front') {
|
|
2524
|
+
retried = landed;
|
|
2525
|
+
await launchApp(udid, bundleId, { args: step.args ?? [], env: step.env ?? {} });
|
|
2526
|
+
landed = await frontmost.check(udid, started?.pid ?? null);
|
|
2527
|
+
}
|
|
2528
|
+
if (landed.verdict === 'did-not-front') {
|
|
2529
|
+
throw new Error(
|
|
2530
|
+
`launched ${bundleId} (pid ${started.pid}) but it never came to the front`
|
|
2531
|
+
+ ` within ${landed.ms}ms${retried ? ', on either of two attempts' : ''} — ${landed.frontmost === null
|
|
2532
|
+
? 'nothing is frontmost'
|
|
2533
|
+
: `${landed.holder} still is`}`
|
|
2534
|
+
+ `. ${frontmost.describeHeld(landed.held, started.pid)}.`,
|
|
2535
|
+
);
|
|
2536
|
+
}
|
|
2537
|
+
if (ctx.landing) ctx.landing.verdict = landed.verdict;
|
|
2538
|
+
return `launched ${bundleId}${step.relaunch ? ' (relaunched)' : ''}`
|
|
2539
|
+
+ (landed.verdict === 'fronted' ? ` (frontmost after ${landed.ms}ms)` : '')
|
|
2540
|
+
+ (retried
|
|
2541
|
+
? ` [it did not front on the first attempt — ${frontmost.describeHeld(retried.held, started.pid)}`
|
|
2542
|
+
+ `; a second launch fronted it. The launch is unreliable on this host.]`
|
|
2543
|
+
: '');
|
|
2392
2544
|
}
|
|
2393
2545
|
case 'terminate':
|
|
2394
2546
|
await terminateApp(udid, step.value ?? step.bundleId);
|
|
@@ -2850,6 +3002,66 @@ async function runStep(deviceQuery, udid, step, ctx) {
|
|
|
2850
3002
|
}
|
|
2851
3003
|
}
|
|
2852
3004
|
|
|
3005
|
+
/**
|
|
3006
|
+
* What changed in the controls, when the pixels say nothing did.
|
|
3007
|
+
*
|
|
3008
|
+
* `settle()` decides `noVisibleChange` from frame hashes alone, and a control
|
|
3009
|
+
* that flips is eight times below the change threshold (DEFERRED 4, measured on
|
|
3010
|
+
* a switch: 0.00049 peak against 0.004). So a switch that genuinely flipped is
|
|
3011
|
+
* reported as an action that did nothing — with the changed value printed in the
|
|
3012
|
+
* same response.
|
|
3013
|
+
*
|
|
3014
|
+
* **That verdict became dangerous the moment item 148 made the tap land.** While
|
|
3015
|
+
* the tap missed the frame centre, `no-visible-change` was true and harmless.
|
|
3016
|
+
* Now the tap actuates, and `no-visible-change` is what an agent reads to decide
|
|
3017
|
+
* whether to retry — so a retry silently un-flips the toggle. An external
|
|
3018
|
+
* tester made exactly that point about my own commit message, which had claimed
|
|
3019
|
+
* the verdict "was telling the truth".
|
|
3020
|
+
*
|
|
3021
|
+
* This is wiring, not calibration. The element values are already in hand on
|
|
3022
|
+
* both sides of the action — `beforeScreen.entry` and the after-reading are read
|
|
3023
|
+
* for verification anyway — so the comparison costs nothing on the device. A
|
|
3024
|
+
* control whose value or selected state changed did something, whatever the
|
|
3025
|
+
* frame hash says.
|
|
3026
|
+
*
|
|
3027
|
+
* Identity across the two readings goes by identifier, then label, then
|
|
3028
|
+
* type-and-place: a row that moved is not the same reading of the same control,
|
|
3029
|
+
* and pretending otherwise would invent changes.
|
|
3030
|
+
*/
|
|
3031
|
+
export function stateDelta(beforeEntry, afterEntry) {
|
|
3032
|
+
const keyOf = (t) => t.identifier || t.label || `${t.type ?? '?'}@${Math.round(t.x ?? 0)},${Math.round(t.y ?? 0)}`;
|
|
3033
|
+
const stateOf = (t) => `${t.value ?? ''}|${t.selected ?? ''}`;
|
|
3034
|
+
const before = new Map();
|
|
3035
|
+
for (const t of beforeEntry?.targets ?? []) {
|
|
3036
|
+
if (t.value == null && t.selected == null) continue;
|
|
3037
|
+
before.set(keyOf(t), { state: stateOf(t), target: t });
|
|
3038
|
+
}
|
|
3039
|
+
if (!before.size) return null;
|
|
3040
|
+
const changes = [];
|
|
3041
|
+
for (const t of afterEntry?.targets ?? []) {
|
|
3042
|
+
if (t.value == null && t.selected == null) continue;
|
|
3043
|
+
const was = before.get(keyOf(t));
|
|
3044
|
+
if (!was || was.state === stateOf(t)) continue;
|
|
3045
|
+
changes.push({
|
|
3046
|
+
name: t.label || t.identifier || keyOf(t),
|
|
3047
|
+
from: was.target.value ?? was.target.selected,
|
|
3048
|
+
to: t.value ?? t.selected,
|
|
3049
|
+
});
|
|
3050
|
+
}
|
|
3051
|
+
if (!changes.length) return null;
|
|
3052
|
+
// Name the control that turned ON, not the one that turned off. A radio move
|
|
3053
|
+
// changes two rows and reporting "Inline changed from true to false" is
|
|
3054
|
+
// accurate and reads like a loss — the useful half is what is selected now.
|
|
3055
|
+
const on = (v) => v === true || v === 'true' || v === '1';
|
|
3056
|
+
const first = changes.find((c) => on(c.to) && !on(c.from)) ?? changes[0];
|
|
3057
|
+
return {
|
|
3058
|
+
count: changes.length,
|
|
3059
|
+
detail: `${JSON.stringify(String(first.name).slice(0, 32))} changed from `
|
|
3060
|
+
+ `${JSON.stringify(String(first.from))} to ${JSON.stringify(String(first.to))}`
|
|
3061
|
+
+ (changes.length > 1 ? ` (and ${changes.length - 1} other control(s))` : ''),
|
|
3062
|
+
};
|
|
3063
|
+
}
|
|
3064
|
+
|
|
2853
3065
|
/**
|
|
2854
3066
|
* Why a settle gave up, in the numbers that decided it.
|
|
2855
3067
|
*
|
package/src/baseline.js
CHANGED
|
@@ -175,7 +175,22 @@ export async function resetFor(udid, flow) {
|
|
|
175
175
|
for (let attempt = 0; attempt <= (reset.maxBack ?? 4); attempt += 1) {
|
|
176
176
|
await api.waitFor(udid, { mode: 'stable', stableMs: 350, timeoutMs: 3000 });
|
|
177
177
|
try {
|
|
178
|
-
|
|
178
|
+
// **Fresh on every attempt, the first one included.** This read
|
|
179
|
+
// `refresh: attempt > 0`, which is the exact pattern `actions.js`
|
|
180
|
+
// has a test forbidding — and the test only ever read actions.js, so
|
|
181
|
+
// the same defect sat here unguarded. It is not theoretical: the
|
|
182
|
+
// reset ran immediately after a launch, resolved `Accessibility`
|
|
183
|
+
// against the map remembered from the PREVIOUS run's end screen,
|
|
184
|
+
// did not find it, and went looking for a "back" control on a
|
|
185
|
+
// Settings root that has none:
|
|
186
|
+
//
|
|
187
|
+
// (reset: could not return com.apple.Preferences to its root
|
|
188
|
+
// screen: "back" is not on this screen. Visible: Settings,
|
|
189
|
+
// Apple Account, …, Accessibility, …)
|
|
190
|
+
//
|
|
191
|
+
// Accessibility is right there in that list. A check has no second
|
|
192
|
+
// opinion, so it may not resolve its first look from memory.
|
|
193
|
+
await api.locate(udid, reset.rootMarker, { refresh: true });
|
|
179
194
|
break;
|
|
180
195
|
} catch {
|
|
181
196
|
const back = await api.locate(udid, 'back', { refresh: true });
|
package/src/cli.js
CHANGED
|
@@ -1704,6 +1704,15 @@ async function doctor({ json = false, strict = false, device, options = {} } = {
|
|
|
1704
1704
|
}
|
|
1705
1705
|
add(`text recognition (${d.name})`, 'ok',
|
|
1706
1706
|
daemon ? 'simframed (in-process, off the framebuffer)' : 'sips + helper binary');
|
|
1707
|
+
// Before the `ax` early-out, so a backend without a tree still reports
|
|
1708
|
+
// this one: "is a launch checked?" is a question the user needs answered
|
|
1709
|
+
// on every platform, and item 169 is what an unanswered launch cost.
|
|
1710
|
+
const front = caps.frontmost ?? { supported: false, note: 'this backend does not say' };
|
|
1711
|
+
add(`launch verification (${d.name})`, front.supported ? 'ok' : 'optional',
|
|
1712
|
+
front.supported
|
|
1713
|
+
? `${front.via} — a launch that never fronts is reported, not called success`
|
|
1714
|
+
: front.note,
|
|
1715
|
+
{ key: 'launch.frontmost', value: front.supported ? front.via ?? 'yes' : null });
|
|
1707
1716
|
if (!caps.ax.supported) {
|
|
1708
1717
|
add(`accessibility tree (${d.name})`, 'optional', caps.ax.note, { key: 'ax.driver', value: null });
|
|
1709
1718
|
continue;
|
package/src/control.js
CHANGED
|
@@ -72,6 +72,8 @@ export const longPress = (udid, x, y, opts = {}) => request(udid, { action: 'lon
|
|
|
72
72
|
export const drag = (udid, from, to, opts = {}) =>
|
|
73
73
|
request(udid, { action: 'drag', x1: from.x, y1: from.y, x2: to.x, y2: to.y, ...opts });
|
|
74
74
|
export const launch = (udid, bundleId, opts = {}) => request(udid, { action: 'launch', bundleId, ...opts });
|
|
75
|
+
/** Which app the device is showing, by pid — see src/frontmost.js. */
|
|
76
|
+
export const frontmost = (udid) => request(udid, { action: 'frontmost' });
|
|
75
77
|
export const terminate = (udid, bundleId) => request(udid, { action: 'terminate', bundleId });
|
|
76
78
|
export const openUrl = (udid, url) => request(udid, { action: 'openUrl', url });
|
|
77
79
|
export const permission = (udid, permissionAction, service, bundleId) =>
|