mobile-automator 0.35.1 → 0.36.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/package.json +2 -2
- package/src/device/action-catalog.js +2 -2
- package/src/device/bridge.js +44 -16
- package/src/device/crash-model.js +23 -1
- package/src/device/device-model.js +27 -5
- package/src/device/engine-hints.js +17 -18
- package/src/device/failure-probe.js +8 -1
- package/src/device/session-daemon.js +1 -1
- package/src/device/session-handle.js +7 -21
- package/src/device/session-id.js +40 -0
- package/src/observe/event.js +9 -12
- package/src/observe/vocab.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobile-automator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0",
|
|
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": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"test:all": "jest"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@mobilenext/mobile-mcp": "1.0.
|
|
37
|
+
"@mobilenext/mobile-mcp": "1.0.13",
|
|
38
38
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
39
39
|
"ajv": "^8.20.0",
|
|
40
40
|
"commander": "^12.1.0"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
//
|
|
25
25
|
// For 'verb' entries, `args` documents the mobile-mcp argument keys the bridge
|
|
26
26
|
// method must pass — deliberately explicit because the keys are inconsistent
|
|
27
|
-
// across the engine (launch=packageName, uninstall=
|
|
27
|
+
// across the engine (launch=packageName, uninstall=packageName, install=path).
|
|
28
28
|
//
|
|
29
29
|
// `stepFlags` records a scenario step field that changes how the verb runs:
|
|
30
30
|
// `{ field, value, flag }` means "when step[field] === value, pass flag". This
|
|
@@ -77,7 +77,7 @@ const ACTION_CATALOG = {
|
|
|
77
77
|
},
|
|
78
78
|
uninstall_app: {
|
|
79
79
|
resolution: 'verb', verb: 'uninstall', bridge: 'uninstallApp',
|
|
80
|
-
primitive: 'mobile_uninstall_app', args: ['
|
|
80
|
+
primitive: 'mobile_uninstall_app', args: ['packageName'],
|
|
81
81
|
},
|
|
82
82
|
open_url: {
|
|
83
83
|
resolution: 'verb', verb: 'open-url', bridge: 'openUrl',
|
package/src/device/bridge.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const { normalize, parseElements } = require('./element-model');
|
|
4
|
-
const { normalizeDevices } = require('./device-model');
|
|
5
|
-
const { normalizeCrashes } = require('./crash-model');
|
|
4
|
+
const { deviceRecords, normalizeDevices, isIosSimulator } = require('./device-model');
|
|
5
|
+
const { normalizeCrashes, CrashListUnverifiableError } = require('./crash-model');
|
|
6
6
|
const { resolveSingleDevice } = require('./device-resolver');
|
|
7
7
|
const { centredSwipe } = require('./swipe-geometry');
|
|
8
8
|
const { isAppNotRunning } = require('./app-not-running');
|
|
@@ -94,18 +94,28 @@ class DeviceBridge {
|
|
|
94
94
|
return this._call('mobile_swipe_on_screen', args);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
//
|
|
98
|
-
// one was provided, else the single auto-resolved device.
|
|
97
|
+
// The current device's record (id/name/platform/state/type): the pinned id
|
|
98
|
+
// when one was provided, else the single auto-resolved device. A pinned id
|
|
99
|
+
// that is not listed throws — callers treat that as "could not check".
|
|
100
|
+
async _currentDevice() {
|
|
101
|
+
const records = deviceRecords(await this._call('mobile_list_available_devices', {}));
|
|
102
|
+
const id = this._device || resolveSingleDevice(records); // throws DeviceResolutionError on 0/many
|
|
103
|
+
const match = records.find((d) => d.id === id);
|
|
104
|
+
if (!match) throw this._unknownPlatform(id);
|
|
105
|
+
return match;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
_unknownPlatform(id) {
|
|
109
|
+
const err = new Error(`Cannot determine the platform of device "${id}".`);
|
|
110
|
+
err.hint = 'Ensure the device is listed by `mauto devices`.';
|
|
111
|
+
return err;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Platform ('android'/'ios') of the current device.
|
|
99
115
|
async getPlatform() {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (!match || !match.platform) {
|
|
104
|
-
const err = new Error(`Cannot determine the platform of device "${id}".`);
|
|
105
|
-
err.hint = 'Ensure the device is listed by `mauto devices`.';
|
|
106
|
-
throw err;
|
|
107
|
-
}
|
|
108
|
-
return String(match.platform).toLowerCase();
|
|
116
|
+
const device = await this._currentDevice();
|
|
117
|
+
if (!device.platform) throw this._unknownPlatform(device.id);
|
|
118
|
+
return String(device.platform).toLowerCase();
|
|
109
119
|
}
|
|
110
120
|
|
|
111
121
|
// Physical screen size in pixels, for geometry-based gestures. mobile-mcp
|
|
@@ -176,7 +186,7 @@ class DeviceBridge {
|
|
|
176
186
|
|
|
177
187
|
// Uninstall an app by its bundle/package identifier.
|
|
178
188
|
async uninstallApp(appId) {
|
|
179
|
-
return await this._call('mobile_uninstall_app', {
|
|
189
|
+
return await this._call('mobile_uninstall_app', { packageName: appId });
|
|
180
190
|
}
|
|
181
191
|
|
|
182
192
|
// Open a URL (deep link or web) on the device.
|
|
@@ -201,9 +211,27 @@ class DeviceBridge {
|
|
|
201
211
|
// come from the device log and AGE OUT; iOS device/simulator reports are files
|
|
202
212
|
// that PERSIST and accumulate across runs. Same call, under-inclusive on one
|
|
203
213
|
// platform and over-inclusive on the other — hence the `since` scoping in
|
|
204
|
-
// src/device/failure-probe.js.
|
|
214
|
+
// src/device/failure-probe.js.
|
|
215
|
+
//
|
|
216
|
+
// ONE platform exception, and only for an EMPTY list: on an iOS simulator the
|
|
217
|
+
// pinned engine (mobilecli 1.0.21, since mobilecli#482) returns `[]` on
|
|
218
|
+
// macOS 27 hosts even right after the app crashed — its filter requires an
|
|
219
|
+
// `is_simulated` key that those simulator reports lack (mobilecli#539). There
|
|
220
|
+
// an empty list is not evidence of "no crash", so we throw the typed
|
|
221
|
+
// CrashListUnverifiableError instead: callers treat it as "could not check"
|
|
222
|
+
// (handleCrashList fails the verb; the failure probe records it at info and
|
|
223
|
+
// leaves `crashes` absent), never as "found none". A
|
|
224
|
+
// non-empty list is real evidence on every platform and is returned as-is,
|
|
225
|
+
// and the device lookup is paid only on an empty list. Remove this guard
|
|
226
|
+
// when the pinned mobilecli fixes #539: re-capture
|
|
227
|
+
// tests/fixtures/device/mobile-mcp-<ver>/ios-sim.crashes.txt with a real
|
|
228
|
+
// crash in it, then drop the guard and its tests.
|
|
205
229
|
async listCrashes() {
|
|
206
|
-
|
|
230
|
+
const crashes = normalizeCrashes(await this._call('mobile_list_crashes', {}));
|
|
231
|
+
if (crashes.length === 0 && isIosSimulator(await this._currentDevice())) {
|
|
232
|
+
throw new CrashListUnverifiableError();
|
|
233
|
+
}
|
|
234
|
+
return crashes;
|
|
207
235
|
}
|
|
208
236
|
|
|
209
237
|
// The full text of one crash report. The engine returns a bare string (its
|
|
@@ -107,4 +107,26 @@ function crashTimestampMs(crash) {
|
|
|
107
107
|
return parsed > 0 ? parsed : null;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
// The engine bug behind the one platform where an empty crash list is not
|
|
111
|
+
// evidence of "no crash": an iOS simulator on a macOS 27 host (mobilecli#539).
|
|
112
|
+
const MOBILECLI_ISSUE_539 = 'https://github.com/mobile-next/mobilecli/issues/539';
|
|
113
|
+
|
|
114
|
+
// Thrown by DeviceBridge#listCrashes when the engine's answer cannot be trusted.
|
|
115
|
+
// Typed (in the shape of device-resolver.js's DeviceResolutionError) so the
|
|
116
|
+
// failure probe can record it as the expected condition it is rather than as a
|
|
117
|
+
// broken engine, and so the `crash` verb maps it onto the `device` envelope.
|
|
118
|
+
class CrashListUnverifiableError extends Error {
|
|
119
|
+
constructor() {
|
|
120
|
+
super(
|
|
121
|
+
'The device engine cannot confirm the absence of crashes on an iOS simulator: it reports none even after a crash.'
|
|
122
|
+
);
|
|
123
|
+
this.name = 'CrashListUnverifiableError';
|
|
124
|
+
this.kind = 'device';
|
|
125
|
+
this.code = 'crash_list_unverifiable';
|
|
126
|
+
this.hint =
|
|
127
|
+
`On an iOS simulator an empty crash list is not evidence that the app did not crash (upstream bug ${MOBILECLI_ISSUE_539}). ` +
|
|
128
|
+
'Treat the crash status as unknown, and check that the app is still running by other means (e.g. `mauto elements` or a screenshot).';
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
module.exports = { normalizeCrashes, crashTimestampMs, CrashListUnverifiableError };
|
|
@@ -5,12 +5,16 @@
|
|
|
5
5
|
// — and drop every other raw mobile-mcp field (no resource-id, no OS-specific
|
|
6
6
|
// internals). `os` is mapped onto `platform` so the output reads the same way
|
|
7
7
|
// across the Android/iOS/simulator variants mobile-mcp returns.
|
|
8
|
+
//
|
|
9
|
+
// deviceRecords is the ONE parser of the raw list. Its records also carry
|
|
10
|
+
// `type` (simulator/emulator/real), which DeviceBridge needs internally;
|
|
11
|
+
// normalizeDevices is only the public 4-key view of those records.
|
|
8
12
|
|
|
9
13
|
function nullable(v) {
|
|
10
14
|
return v === undefined || v === null || v === '' ? null : v;
|
|
11
15
|
}
|
|
12
16
|
|
|
13
|
-
function
|
|
17
|
+
function recordOf(raw) {
|
|
14
18
|
if (!raw || typeof raw !== 'object') return null;
|
|
15
19
|
|
|
16
20
|
const id = nullable(
|
|
@@ -35,10 +39,12 @@ function normalizeOne(raw) {
|
|
|
35
39
|
|
|
36
40
|
const state = nullable(raw.state !== undefined ? raw.state : raw.status);
|
|
37
41
|
|
|
38
|
-
|
|
42
|
+
const type = nullable(raw.type);
|
|
43
|
+
|
|
44
|
+
return { id: String(id), name, platform, state, type };
|
|
39
45
|
}
|
|
40
46
|
|
|
41
|
-
function
|
|
47
|
+
function deviceRecords(raw) {
|
|
42
48
|
let list;
|
|
43
49
|
if (Array.isArray(raw)) {
|
|
44
50
|
list = raw;
|
|
@@ -50,10 +56,26 @@ function normalizeDevices(raw) {
|
|
|
50
56
|
|
|
51
57
|
const out = [];
|
|
52
58
|
for (const item of list) {
|
|
53
|
-
const d =
|
|
59
|
+
const d = recordOf(item);
|
|
54
60
|
if (d) out.push(d);
|
|
55
61
|
}
|
|
56
62
|
return out;
|
|
57
63
|
}
|
|
58
64
|
|
|
59
|
-
|
|
65
|
+
function publicView({ id, name, platform, state }) {
|
|
66
|
+
return { id, name, platform, state };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function normalizeDevices(raw) {
|
|
70
|
+
return deviceRecords(raw).map(publicView);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function isIosSimulator(record) {
|
|
74
|
+
if (!record) return false;
|
|
75
|
+
return (
|
|
76
|
+
String(record.platform || '').toLowerCase() === 'ios' &&
|
|
77
|
+
String(record.type || '').toLowerCase() === 'simulator'
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = { deviceRecords, normalizeDevices, isIosSimulator };
|
|
@@ -7,14 +7,14 @@ const path = require('path');
|
|
|
7
7
|
// tell the user what to do. Pure: message in, hint string (or null) out. It
|
|
8
8
|
// never throws — a hint classifier that crashes would turn a device failure
|
|
9
9
|
// into an internal one. Found by the #199 real-device run against mobile-mcp
|
|
10
|
-
// 1.0.5 / mobilecli 1.0.13
|
|
10
|
+
// 1.0.5 / mobilecli 1.0.13; the missing-agent case was re-captured against
|
|
11
|
+
// mobile-mcp 1.0.13 (#248), which installs the agent itself, so that hint now
|
|
12
|
+
// covers only a failed automatic install.
|
|
11
13
|
//
|
|
12
14
|
// mauto only TELLS the user which command to run; it never runs mobilecli
|
|
13
15
|
// itself (the device is driven only through mauto verbs, which wrap
|
|
14
16
|
// mobile-mcp).
|
|
15
17
|
|
|
16
|
-
const ISSUE_459 = 'https://github.com/mobile-next/mobile-mcp/issues/459';
|
|
17
|
-
|
|
18
18
|
// The mobilecli that the pinned mobile-mcp actually spawns — resolved from
|
|
19
19
|
// mobile-mcp's own directory, since that is the copy whose agent the device
|
|
20
20
|
// must match. Null when it cannot be resolved; the caller omits `@<version>`.
|
|
@@ -35,21 +35,21 @@ function safeVersion(resolver) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
// B1 (iOS):
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
|
|
38
|
+
// B1 (iOS): the simulator is missing the DeviceKit agent and the engine's
|
|
39
|
+
// automatic install of it failed (e.g. offline, or `simctl install` failing).
|
|
40
|
+
// The trigger is the shape captured against mobile-mcp 1.0.13 (#248,
|
|
41
|
+
// tests/fixtures/device/mobile-mcp-1.0.13/ios-sim.agent-install-failed.txt):
|
|
42
|
+
// execFileSync's `Command failed: <mobilecli> agent install --device <udid>`.
|
|
43
|
+
// The 1.0.5-era "Agent is not installed on the device" (#199) is unreachable
|
|
44
|
+
// from the pinned engine, which catches `agent status`'s exit itself.
|
|
45
|
+
const FAILED_AGENT_INSTALL = /Command failed:[^\n]*\bagent install --device\s+(\S+)/;
|
|
46
|
+
|
|
47
|
+
function missingAgentHint(udid, resolver) {
|
|
43
48
|
const version = safeVersion(resolver);
|
|
44
49
|
const pkg = version ? `mobilecli@${version}` : 'mobilecli';
|
|
45
|
-
const cmd = `npx -y ${pkg} agent install --device`;
|
|
46
|
-
const m = /--device\s+(\S+)/.exec(message);
|
|
47
|
-
const install = m
|
|
48
|
-
? `\`${cmd} ${m[1]}\``
|
|
49
|
-
: `\`${cmd}\` followed by the simulator's id from \`mauto devices\``;
|
|
50
50
|
return (
|
|
51
|
-
'The simulator is missing the device agent the engine needs
|
|
52
|
-
`
|
|
51
|
+
'The simulator is missing the device agent the engine needs. The engine normally installs it ' +
|
|
52
|
+
`automatically, but that install failed. Install it once by hand with \`npx -y ${pkg} agent install --device ${udid}\` ` +
|
|
53
53
|
'(needs network, takes a few seconds), then retry.'
|
|
54
54
|
);
|
|
55
55
|
}
|
|
@@ -80,9 +80,8 @@ const OUTSIDE_ALLOWED_DIRS_HINT =
|
|
|
80
80
|
function engineHint(message, { mobilecliVersion = resolveMobilecliVersion } = {}) {
|
|
81
81
|
try {
|
|
82
82
|
if (typeof message !== 'string' || !message) return null;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
83
|
+
const agentInstall = FAILED_AGENT_INSTALL.exec(message);
|
|
84
|
+
if (agentInstall) return missingAgentHint(agentInstall[1], mobilecliVersion);
|
|
86
85
|
const notFound = /Device "([^"]+)" not found/.exec(message);
|
|
87
86
|
if (notFound) return deviceNotFoundHint(notFound[1]);
|
|
88
87
|
if (/not in the list of allowed directories/.test(message)) return OUTSIDE_ALLOWED_DIRS_HINT;
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
// the genuinely undetermined case (skipped, failed, timed out, unscoped)
|
|
60
60
|
// leaves the envelope untouched.
|
|
61
61
|
|
|
62
|
-
const { crashTimestampMs } = require('./crash-model');
|
|
62
|
+
const { crashTimestampMs, CrashListUnverifiableError } = require('./crash-model');
|
|
63
63
|
const { record } = require('../observe/recorder');
|
|
64
64
|
|
|
65
65
|
// The probe's own budget, deliberately far below the daemon's per-call timeout
|
|
@@ -189,6 +189,13 @@ async function probeCrashes({
|
|
|
189
189
|
timeoutMs
|
|
190
190
|
);
|
|
191
191
|
} catch (err) {
|
|
192
|
+
// An iOS simulator's untrustworthy empty list (mobilecli#539) is an
|
|
193
|
+
// expected engine limitation, not a broken probe: info, not a warn on
|
|
194
|
+
// the user's stderr. Either way `crashes` stays absent ("unknown").
|
|
195
|
+
if (err instanceof CrashListUnverifiableError) {
|
|
196
|
+
record({ level: 'info', src: 'cli', event: 'crash.probe_unverifiable', verb }, recordOpts);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
192
199
|
record(
|
|
193
200
|
{
|
|
194
201
|
level: 'warn',
|
|
@@ -23,7 +23,7 @@ const net = require('net');
|
|
|
23
23
|
|
|
24
24
|
const paths = require('./session-paths');
|
|
25
25
|
const { FrameParser } = require('./session-protocol');
|
|
26
|
-
const { newSessionId } = require('./session-
|
|
26
|
+
const { newSessionId } = require('./session-id');
|
|
27
27
|
const { makeDeviceCall } = require('./device-call');
|
|
28
28
|
const { safeObserve: guardObserve } = require('../observe/recorder');
|
|
29
29
|
const { FLUSH_INTERVAL_MS } = require('../observe/flush');
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// Read side of mobile-automator/.session/session.json — the ONLY one
|
|
4
|
-
//
|
|
5
|
-
// readHandleDevice() is a projection onto the `device`
|
|
6
|
-
// it used to parse the file itself, which meant two
|
|
3
|
+
// Read side of mobile-automator/.session/session.json — the ONLY one. The
|
|
4
|
+
// session id it carries is minted, and its shape defined, in session-id.js.
|
|
5
|
+
// resolve-connection.js's readHandleDevice() is a projection onto the `device`
|
|
6
|
+
// field and delegates here; it used to parse the file itself, which meant two
|
|
7
|
+
// readers of one artifact.
|
|
7
8
|
//
|
|
8
9
|
// The handle is where session_id lives because it is a file that is ALREADY
|
|
9
10
|
// there, already written at exactly the right moment (once the daemon is
|
|
@@ -16,24 +17,9 @@
|
|
|
16
17
|
// session", which is a normal state, not an error.
|
|
17
18
|
|
|
18
19
|
const realFs = require('fs');
|
|
19
|
-
const crypto = require('crypto');
|
|
20
20
|
|
|
21
21
|
const { handlePath } = require('./session-paths');
|
|
22
|
-
const { SESSION_ID_PATTERN } = require('
|
|
23
|
-
|
|
24
|
-
// 16 hex chars from the CSPRNG, derived from NOTHING — not the project root,
|
|
25
|
-
// not the device, not the pid. That is what makes the event catalog's
|
|
26
|
-
// `sends: true` on session_id true rather than merely asserted, and
|
|
27
|
-
// tests/unit/device/session-handle.test.js is where the claim is enforced.
|
|
28
|
-
// readSessionId() holds the read side to the same shape (SESSION_ID_PATTERN).
|
|
29
|
-
//
|
|
30
|
-
// Deliberately NOT persisted across daemon restarts. A stable id would be a
|
|
31
|
-
// machine fingerprint; this one changes exactly when the daemon does, which is
|
|
32
|
-
// the fact it exists to report — run_id cannot express "the daemon died and
|
|
33
|
-
// respawned mid-run".
|
|
34
|
-
function newSessionId() {
|
|
35
|
-
return crypto.randomBytes(8).toString('hex');
|
|
36
|
-
}
|
|
22
|
+
const { SESSION_ID_PATTERN } = require('./session-id');
|
|
37
23
|
|
|
38
24
|
function readHandle(projectRoot, { fs = realFs } = {}) {
|
|
39
25
|
try {
|
|
@@ -50,4 +36,4 @@ function readSessionId(projectRoot, { fs = realFs } = {}) {
|
|
|
50
36
|
return typeof id === 'string' && SESSION_ID_PATTERN.test(id) ? id : null;
|
|
51
37
|
}
|
|
52
38
|
|
|
53
|
-
module.exports = {
|
|
39
|
+
module.exports = { readHandle, readSessionId };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// The session id: the function that mints it and the shape it is minted in.
|
|
4
|
+
//
|
|
5
|
+
// This is its own module, rather than living beside the handle reader in
|
|
6
|
+
// session-handle.js, because the event catalog (src/observe/event.js) imports
|
|
7
|
+
// the shape — and so this module must import nothing local. The device layer
|
|
8
|
+
// already imports observe/ (session-daemon.js, failure-probe.js,
|
|
9
|
+
// mobile-mcp-client.js); if anything on this module's require path ever
|
|
10
|
+
// reached back into observe/, the cycle could hand event.js a half-built
|
|
11
|
+
// exports object with SESSION_ID_PATTERN still undefined. The session_id check
|
|
12
|
+
// would then throw when telemetryPayload() runs it, and safeObserve
|
|
13
|
+
// (src/observe/recorder.js) swallows that — session_id telemetry would vanish
|
|
14
|
+
// with nothing failing. Requiring only `crypto` makes that impossible, and
|
|
15
|
+
// tests/lint/session-id-pure.test.js keeps it that way (#196).
|
|
16
|
+
|
|
17
|
+
const crypto = require('crypto');
|
|
18
|
+
|
|
19
|
+
// 16 hex chars from the CSPRNG, derived from NOTHING — not the project root,
|
|
20
|
+
// not the device, not the pid. That is what makes the event catalog's
|
|
21
|
+
// `sends: true` on session_id true rather than merely asserted, and
|
|
22
|
+
// tests/unit/device/session-id.test.js is where the claim is enforced.
|
|
23
|
+
// session-handle.readSessionId() holds the read side to the same shape
|
|
24
|
+
// (SESSION_ID_PATTERN).
|
|
25
|
+
//
|
|
26
|
+
// Deliberately NOT persisted across daemon restarts. A stable id would be a
|
|
27
|
+
// machine fingerprint; this one changes exactly when the daemon does, which is
|
|
28
|
+
// the fact it exists to report — run_id cannot express "the daemon died and
|
|
29
|
+
// respawned mid-run".
|
|
30
|
+
function newSessionId() {
|
|
31
|
+
return crypto.randomBytes(8).toString('hex');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// The shape of what newSessionId() mints (8 CSPRNG bytes as hex) and the only
|
|
35
|
+
// shape readSessionId() will return. The handle file is just a file, so the
|
|
36
|
+
// shape is what keeps `sends: true` true for a stale or hand-edited one. It
|
|
37
|
+
// lives here, with its minter; the event catalog imports it (#196).
|
|
38
|
+
const SESSION_ID_PATTERN = /^[0-9a-f]{16}$/;
|
|
39
|
+
|
|
40
|
+
module.exports = { SESSION_ID_PATTERN, newSessionId };
|
package/src/observe/event.js
CHANGED
|
@@ -40,16 +40,13 @@ const { ERROR_KINDS } = require('../output/envelope');
|
|
|
40
40
|
// Pure module with no requires, so this adds no cycle. It is THE closed set of
|
|
41
41
|
// mobile-mcp primitive names and must not be restated here.
|
|
42
42
|
const { MOBILE_MCP_TOOL_NAMES } = require('../device/mobile-mcp-tools');
|
|
43
|
+
// Pure: requires only crypto, so this adds no cycle — and
|
|
44
|
+
// tests/lint/session-id-pure.test.js keeps it that way. The shape is owned by
|
|
45
|
+
// its minter (#196).
|
|
46
|
+
const { SESSION_ID_PATTERN } = require('../device/session-id');
|
|
43
47
|
|
|
44
48
|
const EVENT_VERSION = 1;
|
|
45
49
|
|
|
46
|
-
// The shape of a session_id: what session-handle.newSessionId() mints (8 CSPRNG
|
|
47
|
-
// bytes as hex) and the only shape readSessionId() will return. session_id is
|
|
48
|
-
// sends:true on the grounds that it is random and carries no user content; the
|
|
49
|
-
// handle file it is read back from is just a file, so the shape is what keeps
|
|
50
|
-
// that true for a stale or hand-edited one.
|
|
51
|
-
const SESSION_ID_PATTERN = /^[0-9a-f]{16}$/;
|
|
52
|
-
|
|
53
50
|
// Ascending severity. Index order is the comparison order.
|
|
54
51
|
const LEVELS = ['debug', 'info', 'warn', 'error'];
|
|
55
52
|
|
|
@@ -88,14 +85,15 @@ const EVENT_FIELDS = {
|
|
|
88
85
|
dur_ms: sendable(integer({ min: 0 }), 'duration; carries no user content'),
|
|
89
86
|
|
|
90
87
|
// --- daemon ------------------------------------------------------------
|
|
91
|
-
// Random per-daemon-lifetime id, generated by session-
|
|
88
|
+
// Random per-daemon-lifetime id, generated by session-id.newSessionId()
|
|
92
89
|
// from crypto.randomBytes and derived from NOTHING — not the project root,
|
|
93
90
|
// not the device, not the pid. Deliberately NOT persisted across restarts: a
|
|
94
91
|
// stable id would be a machine fingerprint, whereas this one changes exactly
|
|
95
92
|
// when the daemon does, which is the fact it exists to report. Enforced on
|
|
96
|
-
// the mint side by tests/unit/device/session-
|
|
97
|
-
//
|
|
98
|
-
// the same pattern, so a stale or hand-edited
|
|
93
|
+
// the mint side by tests/unit/device/session-id.test.js, on the read side by
|
|
94
|
+
// session-handle.readSessionId() checking session-id's SESSION_ID_PATTERN,
|
|
95
|
+
// and at the wire by the same imported pattern, so a stale or hand-edited
|
|
96
|
+
// handle file cannot ship text.
|
|
99
97
|
session_id: sendable(matches(SESSION_ID_PATTERN, 'csprng'), 'random id scoped to one daemon lifetime; no user-derived content'),
|
|
100
98
|
// As with `verb`, the justification holds only because the value is enforced
|
|
101
99
|
// to be one: src/device/device-call.js records this field ONLY when
|
|
@@ -230,7 +228,6 @@ function telemetryPayload(event = {}) {
|
|
|
230
228
|
|
|
231
229
|
module.exports = {
|
|
232
230
|
EVENT_VERSION,
|
|
233
|
-
SESSION_ID_PATTERN,
|
|
234
231
|
LEVELS,
|
|
235
232
|
EVENT_FIELDS,
|
|
236
233
|
NEVER_SENDS,
|