runcloud 0.1.105 → 0.1.106

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/README.md CHANGED
@@ -64,6 +64,8 @@ runcloud ios create --model iphone --install ./MyApp.app # boot a simulator an
64
64
  runcloud ios list # list active sessions
65
65
  runcloud ios get <id> # inspect a session (viewer URL, status)
66
66
  runcloud ios open-url myapp://path --id <id> # open a URL or deep link
67
+ runcloud ios logs <id> --tail 200 # read logs from this lease
68
+ runcloud ios logs <id> --follow # follow new log entries
67
69
  runcloud ios delete <id> # release the session
68
70
 
69
71
  # Android works the same under `runcloud android …`
@@ -74,6 +76,10 @@ Useful `create` flags: `--region`, `--display-name`, `--inactivity-timeout 3m`,
74
76
  `--hard-timeout 1h`, `--install-asset <name-or-id>`, `--rm` (release when the
75
77
  command exits), `--json`.
76
78
 
79
+ The same `logs` commands work for Android. Snapshots are limited to the active
80
+ lease and accept 1 to 1,000 lines. In follow mode, `--json` emits one JSON object
81
+ per line.
82
+
77
83
  ### Tunnel a local dev server into a simulator
78
84
 
79
85
  ```bash
@@ -65,6 +65,40 @@ function formatRecord(value) {
65
65
  .map(([k, v]) => `${k}: ${typeof v === 'object' ? JSON.stringify(v) : String(v)}`)
66
66
  .join('\n');
67
67
  }
68
+ export function consumeSimulatorLogSse(raw) {
69
+ const entries = [];
70
+ let offset = 0;
71
+ let separator = /\r?\n\r?\n/.exec(raw.slice(offset));
72
+ while (separator) {
73
+ const frameEnd = offset + separator.index;
74
+ const frame = raw.slice(offset, frameEnd);
75
+ offset = frameEnd + separator[0].length;
76
+ const data = frame
77
+ .split(/\r?\n/)
78
+ .filter((line) => line.startsWith('data:'))
79
+ .map((line) => line.slice('data:'.length).trimStart())
80
+ .join('\n');
81
+ if (data) {
82
+ let value;
83
+ try {
84
+ value = JSON.parse(data);
85
+ }
86
+ catch {
87
+ throw new Error('Simulator log stream returned invalid JSON');
88
+ }
89
+ const entry = value;
90
+ if (!entry || typeof entry.timestamp !== 'string' || typeof entry.message !== 'string') {
91
+ throw new Error('Simulator log stream returned an invalid entry');
92
+ }
93
+ entries.push({ timestamp: entry.timestamp, message: entry.message });
94
+ }
95
+ separator = /\r?\n\r?\n/.exec(raw.slice(offset));
96
+ }
97
+ return { entries, remainder: raw.slice(offset) };
98
+ }
99
+ function writeSimulatorLogEntry(entry, json) {
100
+ console.log(json ? JSON.stringify(entry) : entry.message);
101
+ }
68
102
  function parseLabels(labels) {
69
103
  const out = {};
70
104
  for (const raw of labels ?? []) {
@@ -338,6 +372,46 @@ function registerSimulatorCommands(program, platform) {
338
372
  .action((url, opts) => action(async () => {
339
373
  print(await client().post(`/run-cloud/${platform}/${encodeURIComponent(opts.id)}/open-url`, { url }), opts);
340
374
  }));
375
+ simulator
376
+ .command('logs')
377
+ .description(`Read or follow logs from ${article} active ${label} session`)
378
+ .argument('<id>')
379
+ .option('--tail <lines>', 'number of retained lines to return (1-1000)')
380
+ .option('-f, --follow', 'follow new log entries', false)
381
+ .option('--json', 'output JSON; follow mode emits one object per line', false)
382
+ .action((id, opts) => action(async () => {
383
+ if (opts.follow && opts.tail !== undefined) {
384
+ throw new Error('--tail cannot be combined with --follow');
385
+ }
386
+ const path = `/run-cloud/${platform}/${encodeURIComponent(id)}/logs`;
387
+ if (!opts.follow) {
388
+ const tail = opts.tail === undefined ? 200 : Number(opts.tail);
389
+ if (!Number.isInteger(tail) || tail < 1 || tail > 1_000) {
390
+ throw new Error('--tail must be an integer from 1 to 1000');
391
+ }
392
+ const snapshot = await client().get(`${path}?tail=${tail}`);
393
+ if (opts.json) {
394
+ print(snapshot, opts);
395
+ return;
396
+ }
397
+ const entries = Array.isArray(snapshot.entries) ? snapshot.entries : [];
398
+ for (const entry of entries)
399
+ writeSimulatorLogEntry(entry, false);
400
+ if (entries.length === 0)
401
+ console.error('No simulator logs captured for this lease.');
402
+ return;
403
+ }
404
+ let pending = '';
405
+ for await (const chunk of client().stream(`${path}?follow=1`)) {
406
+ const parsed = consumeSimulatorLogSse(`${pending}${chunk}`);
407
+ pending = parsed.remainder;
408
+ if (pending.length > 1024 * 1024) {
409
+ throw new Error('Simulator log stream returned an oversized incomplete event');
410
+ }
411
+ for (const entry of parsed.entries)
412
+ writeSimulatorLogEntry(entry, opts.json === true);
413
+ }
414
+ }));
341
415
  return simulator;
342
416
  }
343
417
  async function action(fn) {
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = '0.1.105';
1
+ export const CLI_VERSION = '0.1.106';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runcloud",
3
- "version": "0.1.105",
3
+ "version": "0.1.106",
4
4
  "description": "Create and control run.cloud remote mobile simulators and cloud sandboxes",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: run-cloud-ios-simulator
3
- description: Operate run.cloud iOS simulator and Android emulator sessions with the CLI or TypeScript SDK. Use for creating, installing, inspecting, embedding, smoke-testing, connecting local Metro, capturing iOS screenshots, injecting iOS media, or releasing remote mobile sessions.
3
+ description: Operate run.cloud iOS simulator and Android emulator sessions with the CLI or TypeScript SDK. Use for creating, installing, inspecting, reading device logs, embedding, smoke-testing, connecting local Metro, capturing iOS screenshots, injecting iOS media, or releasing remote mobile sessions.
4
4
  ---
5
5
 
6
6
  # Operate run.cloud Mobile Sessions
@@ -61,6 +61,7 @@ The shared mobile lifecycle is:
61
61
  - `runcloud ios|android list [--all]`
62
62
  - `runcloud ios|android get <id>`
63
63
  - `runcloud ios|android open-url <url> --id <id>`
64
+ - `runcloud ios|android logs <id> [--tail N|--follow]`
64
65
  - `runcloud ios|android delete <id>`
65
66
 
66
67
  Create accepts `--model`, `--region`, `--display-name`, repeatable `--label`,
@@ -84,6 +85,21 @@ iOS needs an Apple Silicon simulator-compatible `.app`, `.zip`, `.tar.gz`, or
84
85
  `.ipa` artifact. A device-signed App Store IPA is not a substitute. Android
85
86
  needs an emulator-compatible artifact such as an APK.
86
87
 
88
+ ## Diagnose App Failures
89
+
90
+ Read up to 1,000 retained entries from the current lease:
91
+
92
+ ```bash
93
+ runcloud ios logs "$SESSION_ID" --tail 1000
94
+ runcloud android logs "$SESSION_ID" --tail 1000
95
+ ```
96
+
97
+ Use `--follow` while reproducing an issue, and add `--json` when another tool
98
+ will consume the entries. `--tail` and `--follow` are mutually exclusive.
99
+ Before releasing a failed session, always capture a bounded snapshot and keep
100
+ the relevant entries with the test evidence. A follow stream contains only new
101
+ entries and is not a substitute for the retained snapshot.
102
+
87
103
  ## Connect Local Development
88
104
 
89
105
  Connect a local Metro or mock server to an active iOS session:
@@ -136,9 +152,9 @@ try {
136
152
  The mobile SDK surface is:
137
153
 
138
154
  - `cloud.account()` and `cloud.usage({ orgId? })`
139
- - `cloud.ios`: `create`, `list`, `get`, `openUrl`, `screenshot`,
155
+ - `cloud.ios`: `create`, `list`, `get`, `openUrl`, `logs`, `followLogs`, `screenshot`,
140
156
  `uploadVideo`, `uploadMicrophoneAudio`, `delete`
141
- - `cloud.android`: `create`, `list`, `get`, `openUrl`, `delete`
157
+ - `cloud.android`: `create`, `list`, `get`, `openUrl`, `logs`, `followLogs`, `delete`
142
158
  - `cloud.simulators`: runtime-platform `create`, `list`, `get`, `openUrl`,
143
159
  `delete`
144
160
  - `cloud.assets`: `upload`, `list`, `delete`