mobile-automator 0.38.4 → 0.39.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobile-automator",
3
- "version": "0.38.4",
3
+ "version": "0.39.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": {
package/src/cli.js CHANGED
@@ -12,7 +12,7 @@ const { engineHint } = require('./device/engine-hints');
12
12
  const { ScenarioValidator } = require('./scenario/validator');
13
13
  const { findReplayWarnings, summarize } = require('./scenario/replayability');
14
14
  const { evaluate, MECHANICAL_TYPES } = require('./assertion/evaluator');
15
- const { ResultStore, readFinalizedResult } = require('./result/store');
15
+ const { ResultStore, readFinalizedResult, InvalidRunIdError } = require('./result/store');
16
16
  const { OBSERVATION_TYPES, parseObservation, parseCapture, parseBool, parseRunStatus, parseStepStatus } = require('./result/flags');
17
17
  const { toJUnit } = require('./result/junit');
18
18
  const { atomicWrite } = require('./util/atomic');
@@ -130,6 +130,7 @@ function usageLine(cmd) {
130
130
  // is the single boundary that guarantees a calling agent always receives one
131
131
  // JSON line + a meaningful exit code instead of a raw stack trace on stderr.
132
132
  // CommanderError (parse failure) -> invalid_input, with the usage line as hint
133
+ // InvalidRunIdError -> invalid_input, with the store's hint
133
134
  // SyntaxError -> invalid_input (a malformed JSON file)
134
135
  // fs EACCES/ENOENT/EROFS/... -> environment, with a filesystem hint
135
136
  // anything else -> internal
@@ -144,6 +145,11 @@ function toEnvelope(err) {
144
145
  exitKind: 'invalid_input',
145
146
  };
146
147
  }
148
+ // A --run-id the ResultStore refuses (#295): the store owns the rule and
149
+ // the wording, so every result verb reports it identically.
150
+ if (err instanceof InvalidRunIdError) {
151
+ return { envelope: fail(err.kind, err.message, err.hint), exitKind: err.kind };
152
+ }
147
153
  if (err instanceof SyntaxError) {
148
154
  return {
149
155
  envelope: fail(
@@ -58,8 +58,14 @@ function assertionStatus(pass) {
58
58
 
59
59
  class ResultStore {
60
60
  constructor({ runId, scenarioId, projectRoot, metadata } = {}) {
61
- if (!runId) throw new Error('ResultStore requires a runId');
62
61
  if (!projectRoot) throw new Error('ResultStore requires a projectRoot');
62
+ // The one gate for every writer (#295): the id becomes `<runId>.json` and
63
+ // `<runId>.lock` below, and atomicWrite creates parent directories, so an
64
+ // id with a separator would write outside results/. Same rule as the
65
+ // reader, readFinalizedResult, so the two cannot disagree on valid ids.
66
+ // Thrown before anything is read or written; the CLI's toEnvelope maps it
67
+ // to invalid_input (exit 3).
68
+ if (!isResultRunId(runId)) throw new InvalidRunIdError(projectRoot, runId);
63
69
 
64
70
  this.runId = runId;
65
71
  this.scenarioId = scenarioId || null;
@@ -396,8 +402,9 @@ function isInProgress(parsed) {
396
402
  // path segment: a non-empty string with no separator and no NUL. `.` and `..`
397
403
  // pass, harmlessly: the appended `.json` keeps them inside results/. This is
398
404
  // deliberately NOT the result schema's run_id pattern nor observe/paths.js's
399
- // isValidRunId: the writer (add-step / finalize) accepts any id, so a stricter
400
- // reader would refuse runs finalize wrote successfully.
405
+ // isValidRunId: it is the one rule shared by the writers (the ResultStore
406
+ // constructor and the `result` write verbs, #295) and the reader
407
+ // (readFinalizedResult), so an id finalize accepted is always exportable.
401
408
  function isResultRunId(runId) {
402
409
  return (
403
410
  typeof runId === 'string' &&
@@ -407,6 +414,18 @@ function isResultRunId(runId) {
407
414
  );
408
415
  }
409
416
 
417
+ // Typed error for a run id isResultRunId refuses, carrying the envelope's kind
418
+ // and hint (the DeviceResolutionError pattern). Thrown by the ResultStore
419
+ // constructor, returned as data by readFinalizedResult — one wording for both.
420
+ class InvalidRunIdError extends Error {
421
+ constructor(projectRoot, runId) {
422
+ super(`invalid run id "${runId}"`);
423
+ this.name = 'InvalidRunIdError';
424
+ this.kind = 'invalid_input';
425
+ this.hint = `A run id names a file in ${resultsDir(projectRoot)}; it cannot contain a path separator.`;
426
+ }
427
+ }
428
+
410
429
  // Read a finalized result file for a report, WITHOUT going through the
411
430
  // ResultStore constructor: that constructor renames a corrupt file aside as a
412
431
  // `.corrupt.<ts>` sidecar, and a reader must never mutate the workspace it
@@ -425,10 +444,8 @@ function isResultRunId(runId) {
425
444
  function readFinalizedResult(projectRoot, runId) {
426
445
  const invalid = (message, hint) => ({ error: { kind: 'invalid_input', message, hint } });
427
446
  if (!isResultRunId(runId)) {
428
- return invalid(
429
- `invalid run id "${runId}"`,
430
- `A run id names a file in ${resultsDir(projectRoot)}; it cannot contain a path separator.`
431
- );
447
+ const { kind, message, hint } = new InvalidRunIdError(projectRoot, runId);
448
+ return { error: { kind, message, hint } };
432
449
  }
433
450
  const file = resultFile(projectRoot, runId);
434
451
  let raw;
@@ -464,4 +481,4 @@ function readFinalizedResult(projectRoot, runId) {
464
481
  return { result: parsed };
465
482
  }
466
483
 
467
- module.exports = { ResultStore, readFinalizedResult, resultFile, isResultRunId };
484
+ module.exports = { ResultStore, readFinalizedResult, resultFile, isResultRunId, InvalidRunIdError };