mobile-automator 0.35.1 → 0.35.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobile-automator",
3
- "version": "0.35.1",
3
+ "version": "0.35.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": {
@@ -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-handle');
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 — plus the
4
- // generator for the session id it carries. resolve-connection.js's
5
- // readHandleDevice() is a projection onto the `device` field and delegates here;
6
- // it used to parse the file itself, which meant two readers of one artifact.
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('../observe/event');
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 = { newSessionId, readHandle, readSessionId };
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 };
@@ -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-handle.newSessionId()
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-handle.test.js and on the read
97
- // side by readSessionId() checking SESSION_ID_PATTERN — and at the wire by
98
- // the same pattern, so a stale or hand-edited handle file cannot ship text.
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,