emd-agents 0.16.0 → 0.16.1
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/dist/core/check.js +22 -9
- package/dist/core/launch.js +3 -2
- package/dist/core/logs.js +16 -1
- package/dist/core/result.d.ts +2 -0
- package/dist/core/result.js +3 -0
- package/package.json +1 -1
package/dist/core/check.js
CHANGED
|
@@ -114,17 +114,31 @@ export async function check(options, report = () => { }, deps = realDeps) {
|
|
|
114
114
|
if (missing.length > 0) {
|
|
115
115
|
return error(`Check "${name}" first expected: ${missing.join("; ")}. Keep each of these unchanged; you can add more. For a different moment, use a new name. Only a person can clear this (emd check reset).`);
|
|
116
116
|
}
|
|
117
|
+
// Seconds each step took, like launch's phases. A step that runs again
|
|
118
|
+
// adds up.
|
|
119
|
+
const phases = {};
|
|
120
|
+
const timed = async (name, step) => {
|
|
121
|
+
const at = Date.now();
|
|
122
|
+
try {
|
|
123
|
+
return await step();
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
phases[name] =
|
|
127
|
+
Math.round(((phases[name] ?? 0) * 1000 + Date.now() - at) / 100) / 10;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
117
130
|
// The actions run first, in order. A failed one stops the rest and the
|
|
118
131
|
// read: the check could not run, so it does not count.
|
|
119
132
|
const actions = [];
|
|
120
133
|
for (const [i, action] of (options.actions ?? []).entries()) {
|
|
121
|
-
const done = await deps.act(action, { jobId: options.jobId });
|
|
134
|
+
const done = await timed("actions", () => deps.act(action, { jobId: options.jobId }));
|
|
122
135
|
actions.push(done);
|
|
123
136
|
if (done.verdict !== "ok") {
|
|
124
137
|
return {
|
|
125
138
|
verdict: "error",
|
|
126
139
|
reason: `Action ${i + 1} (${Object.keys(action)[0]}) failed: ${done.reason ?? "no reason given"}. Nothing was read.`,
|
|
127
140
|
actions,
|
|
141
|
+
phases,
|
|
128
142
|
};
|
|
129
143
|
}
|
|
130
144
|
}
|
|
@@ -169,13 +183,13 @@ export async function check(options, report = () => { }, deps = realDeps) {
|
|
|
169
183
|
const screenMissing = first || elementResults.some((r) => !r.found);
|
|
170
184
|
if (logSpecs.length > 0 && logsMissing) {
|
|
171
185
|
report(first ? "reading the logs" : "reading the logs again");
|
|
172
|
-
const failure = await readLogs
|
|
186
|
+
const failure = await timed("logs", readLogs);
|
|
173
187
|
if (failure)
|
|
174
188
|
return error(failure);
|
|
175
189
|
}
|
|
176
190
|
if (elementSpecs.length > 0 && screenMissing) {
|
|
177
191
|
report(first ? "reading the screen" : "reading the screen again");
|
|
178
|
-
const failure = await readTheScreen
|
|
192
|
+
const failure = await timed("screen", readTheScreen);
|
|
179
193
|
if (failure)
|
|
180
194
|
return error(failure);
|
|
181
195
|
}
|
|
@@ -183,7 +197,7 @@ export async function check(options, report = () => { }, deps = realDeps) {
|
|
|
183
197
|
const missing = [...logResults, ...elementResults].some((r) => !r.found);
|
|
184
198
|
if (!missing || Date.now() - started >= deps.recheckSeconds * 1000)
|
|
185
199
|
break;
|
|
186
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
200
|
+
await timed("wait", () => new Promise((resolve) => setTimeout(resolve, 1000)));
|
|
187
201
|
}
|
|
188
202
|
const waited = Math.round((Date.now() - started) / 1000);
|
|
189
203
|
const nodes = screen?.nodes ?? [];
|
|
@@ -191,7 +205,7 @@ export async function check(options, report = () => { }, deps = realDeps) {
|
|
|
191
205
|
report("taking a screenshot");
|
|
192
206
|
const stamp = Date.now();
|
|
193
207
|
const shotPath = join(logDir, `check-${stamp}.png`);
|
|
194
|
-
const shotError = await deps.screenshot(device, shotPath);
|
|
208
|
+
const shotError = await timed("screenshot", () => deps.screenshot(device, shotPath));
|
|
195
209
|
const shot = shotError === undefined ? shotPath : undefined;
|
|
196
210
|
// What the screen reader got, next to the screenshot, for when they disagree.
|
|
197
211
|
if (screen) {
|
|
@@ -228,15 +242,14 @@ export async function check(options, report = () => { }, deps = realDeps) {
|
|
|
228
242
|
[name]: { expected: first ?? expected, last: result.verdict },
|
|
229
243
|
},
|
|
230
244
|
});
|
|
231
|
-
const written = await deps
|
|
232
|
-
.evidence({ jobId: options.jobId })
|
|
233
|
-
.catch(() => undefined);
|
|
245
|
+
const written = await timed("evidence", () => deps.evidence({ jobId: options.jobId }).catch(() => undefined));
|
|
234
246
|
if (written?.verdict !== "written")
|
|
235
|
-
return result;
|
|
247
|
+
return { ...result, phases };
|
|
236
248
|
return {
|
|
237
249
|
...result,
|
|
238
250
|
evidenceDir: written.dir,
|
|
239
251
|
...(written.notPassed && { notPassed: written.notPassed }),
|
|
252
|
+
phases,
|
|
240
253
|
};
|
|
241
254
|
};
|
|
242
255
|
if (passed)
|
package/dist/core/launch.js
CHANGED
|
@@ -458,8 +458,9 @@ export async function launch(options = {}, report = () => { }) {
|
|
|
458
458
|
catch (error) {
|
|
459
459
|
if (!reused && !installedAgain)
|
|
460
460
|
return captureFailed(error);
|
|
461
|
-
// The reused or installed build's app cannot be read: build once and try
|
|
462
|
-
|
|
461
|
+
// The reused or installed build's app cannot be read: build once and try
|
|
462
|
+
// again. The reason keeps the error, so a rebuild says what caused it.
|
|
463
|
+
why = `installed app could not be read: ${String(error).split("\n")[0]}`;
|
|
463
464
|
installedAgain = false;
|
|
464
465
|
const failure = await buildApp();
|
|
465
466
|
if (failure)
|
package/dist/core/logs.js
CHANGED
|
@@ -47,8 +47,23 @@ export function parseTagged(ndjson, tag) {
|
|
|
47
47
|
}
|
|
48
48
|
return lines;
|
|
49
49
|
}
|
|
50
|
+
// simctl can fail to answer for a while after a boot, even after bootstatus:
|
|
51
|
+
// in the #14 pilot, a reused build fell back to a 194 s rebuild. So a few short
|
|
52
|
+
// tries, 2 s apart, as other simulator tools retry such calls.
|
|
50
53
|
async function appExecutable(device, appId) {
|
|
51
|
-
|
|
54
|
+
for (let attempt = 1;; attempt++) {
|
|
55
|
+
try {
|
|
56
|
+
return await readExecutable(device, appId);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (attempt >= 3)
|
|
60
|
+
throw error;
|
|
61
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function readExecutable(device, appId) {
|
|
66
|
+
const { stdout } = await runTool("simctl get_app_container", "xcrun", ["simctl", "get_app_container", device, appId], 20);
|
|
52
67
|
const { stdout: name } = await runTool("plutil", "plutil", [
|
|
53
68
|
"-extract",
|
|
54
69
|
"CFBundleExecutable",
|
package/dist/core/result.d.ts
CHANGED
|
@@ -117,6 +117,7 @@ export declare const checkResultSchema: z.ZodObject<{
|
|
|
117
117
|
attempt: z.ZodOptional<z.ZodNumber>;
|
|
118
118
|
retryLimit: z.ZodOptional<z.ZodNumber>;
|
|
119
119
|
waited: z.ZodOptional<z.ZodNumber>;
|
|
120
|
+
phases: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
120
121
|
logs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
121
122
|
tag: z.ZodString;
|
|
122
123
|
message: z.ZodOptional<z.ZodString>;
|
|
@@ -259,6 +260,7 @@ export declare const jobViewSchema: z.ZodObject<{
|
|
|
259
260
|
attempt: z.ZodOptional<z.ZodNumber>;
|
|
260
261
|
retryLimit: z.ZodOptional<z.ZodNumber>;
|
|
261
262
|
waited: z.ZodOptional<z.ZodNumber>;
|
|
263
|
+
phases: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
262
264
|
logs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
263
265
|
tag: z.ZodString;
|
|
264
266
|
message: z.ZodOptional<z.ZodString>;
|
package/dist/core/result.js
CHANGED
|
@@ -110,6 +110,9 @@ export const checkResultSchema = z.object({
|
|
|
110
110
|
// Seconds the check read again for what was missing; absent when the first
|
|
111
111
|
// read decided.
|
|
112
112
|
waited: z.number().optional(),
|
|
113
|
+
// Seconds each step took: actions, logs, screen, wait (between reads),
|
|
114
|
+
// screenshot, evidence. Only the steps that ran (#14 audit).
|
|
115
|
+
phases: z.record(z.string(), z.number()).optional(),
|
|
113
116
|
logs: z
|
|
114
117
|
.array(z.object({
|
|
115
118
|
tag: z.string(),
|