mobile-automator 0.36.0 → 0.36.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/package.json +1 -1
- package/src/cli.js +8 -4
- package/src/device/process-identity.js +11 -5
- package/src/device/session-end.js +43 -13
- package/src/device/session-paths.js +14 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobile-automator",
|
|
3
|
-
"version": "0.36.
|
|
3
|
+
"version": "0.36.1",
|
|
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
|
@@ -1411,14 +1411,18 @@ async function handleSessionStatus(
|
|
|
1411
1411
|
}
|
|
1412
1412
|
|
|
1413
1413
|
// endSession's failure outcomes (#156), each with the hint that is true for it.
|
|
1414
|
-
//
|
|
1415
|
-
// differs is WHY, and so what the user should do about it. One vague hint
|
|
1416
|
-
// to cover all
|
|
1414
|
+
// Every one of them may leave a daemon alive and holding the workspace lock;
|
|
1415
|
+
// what differs is WHY, and so what the user should do about it. One vague hint
|
|
1416
|
+
// used to cover them all.
|
|
1417
1417
|
const SESSION_END_FAILURE_HINTS = {
|
|
1418
1418
|
survived: (pid, pidFile) =>
|
|
1419
1419
|
`It is still alive after SIGTERM and SIGKILL and may still hold the workspace lock. Check it with \`ps -p ${pid}\` and stop it with \`kill -9 ${pid}\` (pidfile: ${pidFile}).`,
|
|
1420
1420
|
foreign: (pid, pidFile) =>
|
|
1421
|
-
`
|
|
1421
|
+
`Something answered the shutdown, but this pid cannot be tied to this workspace, so it was not signalled: its command line names another workspace, or names none and the workspace lock does not name it. Check it with \`ps -p ${pid}\` and stop it manually (pidfile: ${pidFile}).`,
|
|
1422
|
+
// #237: a daemon started by mauto <= 0.27.x carries no workspace marker, and
|
|
1423
|
+
// without an ack nothing else proves it ours.
|
|
1424
|
+
unproven: (pid, pidFile) =>
|
|
1425
|
+
`It did not answer the shutdown and its command line carries no workspace marker (a daemon started by mauto < 0.28), so this workspace cannot prove it is its own and it was not signalled. It may still hold the workspace lock. Check it with \`ps -p ${pid}\` and stop it with \`kill -9 ${pid}\` if it is this workspace's daemon (pidfile: ${pidFile}).`,
|
|
1422
1426
|
unverified: (pid, pidFile) =>
|
|
1423
1427
|
`It could not be identified (\`ps\` failed), so it was not signalled. Check it with \`ps -p ${pid}\` and stop it manually if it is this workspace's mauto daemon (pidfile: ${pidFile}).`,
|
|
1424
1428
|
};
|
|
@@ -66,10 +66,15 @@ function isZombie(
|
|
|
66
66
|
// 'dead' - no such process (ESRCH or any non-EPERM kill error)
|
|
67
67
|
// 'ours' - alive AND its command line contains `mauto-session-daemon`
|
|
68
68
|
// (and, when `projectRoot` is given, names THAT workspace)
|
|
69
|
-
// 'foreign' - only with `projectRoot`: alive and a mauto daemon
|
|
70
|
-
// command line
|
|
71
|
-
// workspace's
|
|
72
|
-
//
|
|
69
|
+
// 'foreign' - only with `projectRoot`: alive and a mauto daemon whose
|
|
70
|
+
// command line carries a workspace marker naming ANOTHER
|
|
71
|
+
// workspace (#156) — or this one's under a salt we cannot read.
|
|
72
|
+
// Never ours to signal.
|
|
73
|
+
// 'unmarked'- only with `projectRoot`: alive and a mauto daemon whose command
|
|
74
|
+
// line carries no workspace marker at all (#237) — one started by
|
|
75
|
+
// mauto <= 0.27.x, or an editor open on the bin. Its line cannot
|
|
76
|
+
// prove whose it is either way; `session end` decides from the
|
|
77
|
+
// socket ack and the lock (src/device/session-end.js).
|
|
73
78
|
// 'other' - alive AND its command line does NOT (recycled pid)
|
|
74
79
|
// 'unknown' - alive but `ps` itself failed (e.g. no `ps` on the host) —
|
|
75
80
|
// treated as 'ours' by cleanStale: never clean when unsure.
|
|
@@ -112,7 +117,8 @@ function pidIdentity(
|
|
|
112
117
|
);
|
|
113
118
|
if (!/mauto-session-daemon/.test(out)) return 'other';
|
|
114
119
|
if (projectRoot == null) return 'ours';
|
|
115
|
-
|
|
120
|
+
if (paths.commandNamesWorkspace(out, projectRoot, readSalt(projectRoot))) return 'ours';
|
|
121
|
+
return paths.commandHasWorkspaceMarker(out) ? 'foreign' : 'unmarked';
|
|
116
122
|
} catch (_) {
|
|
117
123
|
return 'unknown';
|
|
118
124
|
}
|
|
@@ -31,11 +31,17 @@ const END_BUDGET_MS = sessionDaemon.DAEMON_CALL_TIMEOUT_MS + 10000;
|
|
|
31
31
|
// 'already_stopped' - nothing acked and nothing of ours was running
|
|
32
32
|
// 'forced' - ours, stuck in teardown, terminated by a group kill
|
|
33
33
|
// 'survived' - ours, stuck, and still alive after SIGTERM + SIGKILL
|
|
34
|
-
// 'foreign' - acked, but the live pid
|
|
35
|
-
//
|
|
34
|
+
// 'foreign' - acked, but the live pid cannot be tied to this
|
|
35
|
+
// workspace: its command line names another one, or it
|
|
36
|
+
// names none and the lock does not name the same pid —
|
|
37
|
+
// reported, never signalled
|
|
38
|
+
// 'unproven' - not acked, and the live pid is a mauto daemon whose
|
|
39
|
+
// command line names no workspace (mauto <= 0.27.x, #237):
|
|
40
|
+
// nothing proves it ours, so it was never signalled, and
|
|
41
|
+
// it may still hold this workspace's lock
|
|
36
42
|
// 'unverified' - the pid could not be identified (`ps` failed), so it
|
|
37
43
|
// was never signalled
|
|
38
|
-
// The last
|
|
44
|
+
// The last four are failures: a daemon may still be alive.
|
|
39
45
|
async function endSession(
|
|
40
46
|
projectRoot,
|
|
41
47
|
{
|
|
@@ -45,12 +51,16 @@ async function endSession(
|
|
|
45
51
|
// workspace's daemon through a copied or recycled pidfile.
|
|
46
52
|
identify = (pid) => processIdentity.pidIdentity(pid, { projectRoot }),
|
|
47
53
|
readPid = () => processIdentity.readPidFile(paths.pidFilePath(projectRoot)),
|
|
54
|
+
// The lock names the daemon that holds this workspace (#237). It is the
|
|
55
|
+
// second witness for a daemon whose command line carries no marker.
|
|
56
|
+
readLockPid = () => processIdentity.readPidFile(paths.lockPath(projectRoot)),
|
|
48
57
|
budgetMs = END_BUDGET_MS,
|
|
49
58
|
} = {}
|
|
50
59
|
) {
|
|
51
|
-
// Read BEFORE asking: a daemon that exits cleanly removes its pidfile
|
|
52
|
-
// need to know whom to watch.
|
|
60
|
+
// Read BEFORE asking: a daemon that exits cleanly removes its pidfile and its
|
|
61
|
+
// lock, and we need to know whom to watch — and who held the lock.
|
|
53
62
|
const pid = readPid();
|
|
63
|
+
const lockPid = readLockPid();
|
|
54
64
|
const acked = await client.requestShutdown(projectRoot);
|
|
55
65
|
const report = (outcome) => ({ outcome, pid: pid || null });
|
|
56
66
|
// The daemon is gone: it stopped because we asked, or was never running.
|
|
@@ -69,13 +79,32 @@ async function endSession(
|
|
|
69
79
|
case 'other': // the pid was recycled: our daemon is gone
|
|
70
80
|
return gone();
|
|
71
81
|
case 'foreign':
|
|
72
|
-
// A mauto daemon whose command line
|
|
73
|
-
//
|
|
74
|
-
// Never signalled. Without an ack nothing answered on
|
|
75
|
-
// of ours was running. With an ack
|
|
76
|
-
//
|
|
77
|
-
//
|
|
82
|
+
// A mauto daemon whose command line names ANOTHER workspace (or this
|
|
83
|
+
// one's under a salt we cannot read): reached through a copied or
|
|
84
|
+
// recycled pidfile. Never signalled. Without an ack nothing answered on
|
|
85
|
+
// OUR socket, so none of ours was running. With an ack something of ours
|
|
86
|
+
// answered, but this pid is provably not it, so it is reported rather
|
|
87
|
+
// than killed. (Marker-less daemons arrive as 'unmarked' below, #237.)
|
|
78
88
|
return report(acked ? 'foreign' : 'already_stopped');
|
|
89
|
+
case 'unmarked':
|
|
90
|
+
// A mauto daemon whose command line names no workspace at all: one
|
|
91
|
+
// started by mauto <= 0.27.x (#237). Its line proves nothing, so two
|
|
92
|
+
// other witnesses must agree before it is signalled:
|
|
93
|
+
// - the ack: the socket lives inside this workspace's .session/ and a
|
|
94
|
+
// Unix socket only accepts on the inode the daemon bound, so a
|
|
95
|
+
// `cp -R`'d workspace can never make the original's daemon answer;
|
|
96
|
+
// - the lock naming this same pid, read before the ack, so the daemon
|
|
97
|
+
// that answered is the one we are about to kill.
|
|
98
|
+
// 0.27.x spawned it detached, so it leads its own process group and the
|
|
99
|
+
// group kill reaches its engine too.
|
|
100
|
+
if (acked && lockPid === pid) {
|
|
101
|
+
return report((await reaper.terminate(pid, { group: true })) === 'dead' ? 'forced' : 'survived');
|
|
102
|
+
}
|
|
103
|
+
// Acked, but the lock does not tie the answer to this pid: report it.
|
|
104
|
+
// Not acked: nothing proves it ours — but nor is it proven gone, and
|
|
105
|
+
// cleanStale (which asks without a root) still respects its lock, so
|
|
106
|
+
// 'already_stopped' would be a lie the next spawn trips over.
|
|
107
|
+
return report(acked ? 'foreign' : 'unproven');
|
|
79
108
|
case 'ours':
|
|
80
109
|
return report((await reaper.terminate(pid, { group: true })) === 'dead' ? 'forced' : 'survived');
|
|
81
110
|
default: // 'unknown': never signal a process we cannot identify
|
|
@@ -84,8 +113,9 @@ async function endSession(
|
|
|
84
113
|
}
|
|
85
114
|
|
|
86
115
|
// Outcomes after which no daemon of ours is left holding the workspace.
|
|
87
|
-
// Anything else ('survived', 'foreign', 'unverified') may leave
|
|
88
|
-
// daemon alive — spawning then would just find it answering pings
|
|
116
|
+
// Anything else ('survived', 'foreign', 'unproven', 'unverified') may leave
|
|
117
|
+
// the stale daemon alive — spawning then would just find it answering pings,
|
|
118
|
+
// or (for 'unproven') find its lock still held. Lives beside
|
|
89
119
|
// the vocabulary it classifies so a new outcome can never drift from its
|
|
90
120
|
// classification (#251's restart path, resolve-connection.js, reads it).
|
|
91
121
|
const ENDED_OUTCOMES = new Set(['stopped', 'forced', 'already_stopped']);
|
|
@@ -137,6 +137,19 @@ function commandNamesWorkspace(command, projectRoot, salt = null) {
|
|
|
137
137
|
return line.endsWith(` ${LEGACY_DAEMON_ROOT_FLAG} ${path.resolve(projectRoot)}`);
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
// Does a `ps -o command=` line carry a workspace marker of EITHER kind, whatever
|
|
141
|
+
// workspace it names (#237)? Daemons started by mauto <= 0.27.x carry none, and
|
|
142
|
+
// "names no workspace" is a different fact from "names another workspace": the
|
|
143
|
+
// first cannot be told apart by its command line at all, so `session end`
|
|
144
|
+
// falls back to the socket and the lock; the second is proof it is not ours.
|
|
145
|
+
// Matched as a whole argv token (whitespace or line edge on both sides), so a
|
|
146
|
+
// path that merely contains the flag's text is not a marker.
|
|
147
|
+
const MARKER_FLAG_TOKEN = new RegExp(`(?:^|\\s)(?:${DAEMON_WORKSPACE_FLAG}|${LEGACY_DAEMON_ROOT_FLAG})(?=\\s|$)`);
|
|
148
|
+
|
|
149
|
+
function commandHasWorkspaceMarker(command) {
|
|
150
|
+
return MARKER_FLAG_TOKEN.test(String(command || ''));
|
|
151
|
+
}
|
|
152
|
+
|
|
140
153
|
// A path as it should appear in a child's argv (or an env var the child execs
|
|
141
154
|
// by) (#236). `ps` shows every process's argv to every user on the host, and
|
|
142
155
|
// when mobile-automator is installed inside the project (a devDependency, a
|
|
@@ -191,5 +204,6 @@ module.exports = {
|
|
|
191
204
|
LEGACY_DAEMON_ROOT_FLAG,
|
|
192
205
|
daemonArgv,
|
|
193
206
|
commandNamesWorkspace,
|
|
207
|
+
commandHasWorkspaceMarker,
|
|
194
208
|
argvPath,
|
|
195
209
|
};
|