runcloud 0.1.105 → 0.1.107
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/commands/sandbox.js
CHANGED
|
@@ -263,6 +263,33 @@ function secretSelector(opts) {
|
|
|
263
263
|
function collectRepeatable(value, previous) {
|
|
264
264
|
return [...previous, value];
|
|
265
265
|
}
|
|
266
|
+
export function parseTagPairs(values) {
|
|
267
|
+
return values.map((raw) => {
|
|
268
|
+
const at = raw.indexOf('=');
|
|
269
|
+
if (at <= 0) {
|
|
270
|
+
throw new Error(`--tag must be key=value (got ${JSON.stringify(raw)})`);
|
|
271
|
+
}
|
|
272
|
+
return [raw.slice(0, at), raw.slice(at + 1)];
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
export async function resolveSandboxByTag(api, tags) {
|
|
276
|
+
if (tags.length === 0) {
|
|
277
|
+
throw new Error('Provide a sandbox id, or --tag key=value to find one.');
|
|
278
|
+
}
|
|
279
|
+
const query = new URLSearchParams();
|
|
280
|
+
for (const [key, value] of parseTagPairs(tags))
|
|
281
|
+
query.append('tag', `${key}:${value}`);
|
|
282
|
+
const data = await api.get(`/run-cloud/sandboxes?${query}`);
|
|
283
|
+
const items = data?.items ?? [];
|
|
284
|
+
if (items.length === 0) {
|
|
285
|
+
throw new Error(`No sandbox matches ${tags.join(' ')}.`);
|
|
286
|
+
}
|
|
287
|
+
if (items.length > 1) {
|
|
288
|
+
const listed = items.map((s) => ` ${s.id}${s.name ? ` ${s.name}` : ''}`).join('\n');
|
|
289
|
+
throw new Error(`${items.length} sandboxes match ${tags.join(' ')} — narrow it, or pass an id:\n${listed}`);
|
|
290
|
+
}
|
|
291
|
+
return items[0].id;
|
|
292
|
+
}
|
|
266
293
|
export function registerSandbox(program) {
|
|
267
294
|
const sandbox = program.command('sandbox').description('Spawn and control microVM sandboxes');
|
|
268
295
|
const defaultHelp = new Help();
|
|
@@ -362,12 +389,16 @@ export function registerSandbox(program) {
|
|
|
362
389
|
.command('list')
|
|
363
390
|
.description('List sandboxes')
|
|
364
391
|
.option('--state <state>', 'filter by state')
|
|
365
|
-
.option('--name <name>', 'filter by name (exact)')
|
|
392
|
+
.option('--name <name>', 'filter by name (exact)')
|
|
393
|
+
.option('--tag <key=value>', 'filter by tag; repeatable, and a sandbox must carry every one', collectRepeatable, [])).action((opts) => run(async () => {
|
|
366
394
|
const query = new URLSearchParams();
|
|
367
395
|
if (opts.state)
|
|
368
396
|
query.set('state', opts.state);
|
|
369
397
|
if (opts.name)
|
|
370
398
|
query.set('name', opts.name);
|
|
399
|
+
for (const [key, value] of parseTagPairs(opts.tag ?? [])) {
|
|
400
|
+
query.append('tag', `${key}:${value}`);
|
|
401
|
+
}
|
|
371
402
|
const qs = query.size ? `?${query}` : '';
|
|
372
403
|
const api = runCloudApi();
|
|
373
404
|
const [data, boxes] = await Promise.all([
|
|
@@ -384,6 +415,23 @@ export function registerSandbox(program) {
|
|
|
384
415
|
else
|
|
385
416
|
console.log(renderSandboxList(items));
|
|
386
417
|
}));
|
|
418
|
+
withOutput(sandbox
|
|
419
|
+
.command('tag')
|
|
420
|
+
.description('Set or remove tags on a sandbox')
|
|
421
|
+
.argument('<id>', 'sandbox id')
|
|
422
|
+
.argument('<pairs...>', 'key=value to set, or key= to remove')).action((id, pairs, opts) => run(async () => {
|
|
423
|
+
const tags = Object.fromEntries(parseTagPairs(pairs).map(([key, value]) => [key, value === '' ? null : value]));
|
|
424
|
+
const updated = await runCloudApi().patch(`/run-cloud/sandboxes/${encodeURIComponent(id)}/tags`, { tags });
|
|
425
|
+
if (opts.json)
|
|
426
|
+
printJson(updated);
|
|
427
|
+
else {
|
|
428
|
+
const applied = (updated?.tags ?? {});
|
|
429
|
+
const entries = Object.entries(applied);
|
|
430
|
+
console.log(entries.length === 0
|
|
431
|
+
? `${id} now has no tags`
|
|
432
|
+
: `${id}\n${entries.map(([k, v]) => ` ${k}=${v}`).join('\n')}`);
|
|
433
|
+
}
|
|
434
|
+
}));
|
|
387
435
|
withOutput(sandbox
|
|
388
436
|
.command('get')
|
|
389
437
|
.description('Inspect a sandbox, including its public hostname when exposed')
|
|
@@ -497,15 +545,17 @@ export function registerSandbox(program) {
|
|
|
497
545
|
sandbox
|
|
498
546
|
.command('shell')
|
|
499
547
|
.description('Open an interactive shell (resumes paused sandboxes)')
|
|
500
|
-
.argument('
|
|
501
|
-
.
|
|
548
|
+
.argument('[id]', 'sandbox id; omit when using --tag')
|
|
549
|
+
.option('--tag <key=value>', 'find the sandbox by tag instead of id; repeatable, must match exactly one', collectRepeatable, [])
|
|
550
|
+
.action((id, opts) => run(async () => {
|
|
502
551
|
const credentials = requireCredentials();
|
|
503
552
|
const api = new ApiClient(credentials.apiUrl, credentials.token);
|
|
504
|
-
await
|
|
553
|
+
const sandboxId = id ?? (await resolveSandboxByTag(api, opts.tag ?? []));
|
|
554
|
+
await prepareSandboxShell(api, sandboxId);
|
|
505
555
|
process.exitCode = await runSandboxShell({
|
|
506
556
|
apiUrl: credentials.apiUrl,
|
|
507
557
|
token: credentials.token,
|
|
508
|
-
sandboxId
|
|
558
|
+
sandboxId,
|
|
509
559
|
});
|
|
510
560
|
}));
|
|
511
561
|
for (const lifecycle of [
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = '0.1.
|
|
1
|
+
export const CLI_VERSION = '0.1.107';
|
package/package.json
CHANGED
|
@@ -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`
|
|
@@ -204,6 +204,76 @@ signed browser desktop. The CLI also provides `screenshot`, `click`, `type`,
|
|
|
204
204
|
and `key` subcommands for explicit pixel-coordinate automation. Keep signed
|
|
205
205
|
desktop URLs private and inspect each subcommand's help before automation.
|
|
206
206
|
|
|
207
|
+
## Tag Sandboxes, and Find Them Again
|
|
208
|
+
|
|
209
|
+
Tags are arbitrary `key=value` metadata on a lease. They are how an operator
|
|
210
|
+
gets from a symptom back to the machine that caused it, and they **outlive the
|
|
211
|
+
sandbox** — so "which sandbox ran this?" is still answerable after the VM is
|
|
212
|
+
gone, which is usually when you are asking.
|
|
213
|
+
|
|
214
|
+
Tag on create, or on an existing sandbox:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
runcloud sandbox create --image runcloud/agent-base # then:
|
|
218
|
+
runcloud sandbox tag sbx_123 newly.run=run-42 owner=qasim
|
|
219
|
+
runcloud sandbox tag sbx_123 owner= # empty value removes the key
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Find by tag — repeatable, and a sandbox must carry every one:
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
runcloud sandbox list --tag newly.run=run-42 --json
|
|
226
|
+
runcloud sandbox shell --tag newly.run=run-42 # resolves, then opens a shell
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
`shell --tag` refuses to guess: no match and several matches are both errors,
|
|
230
|
+
and the ambiguous case lists what it found. Opening a shell on the wrong
|
|
231
|
+
machine is worse than being told to be precise.
|
|
232
|
+
|
|
233
|
+
Reserved keys the platform sets itself — do not overwrite them:
|
|
234
|
+
|
|
235
|
+
| key | meaning |
|
|
236
|
+
| --- | --- |
|
|
237
|
+
| `newly.kind` | what created it (`ci`, …) |
|
|
238
|
+
| `newly.run` | the CI run id |
|
|
239
|
+
| `newly.environment` | the CI environment id |
|
|
240
|
+
| `newly.session` / `newly.role` | Newly session association, for simulators |
|
|
241
|
+
|
|
242
|
+
### Debugging when you have only a log line
|
|
243
|
+
|
|
244
|
+
The control plane logs a sandbox's tags on **create** and **destroy**, so the
|
|
245
|
+
first step needs no API token and no database access:
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
gcloud logging read \
|
|
249
|
+
'resource.labels.service_name="cp-api-dev" AND jsonPayload.message="run.cloud sandbox created"' \
|
|
250
|
+
--limit 20 --freshness=6h --format=json
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Then either query as a normal user (`runcloud sandbox list --tag …`), or use the
|
|
254
|
+
ops endpoint, which is org-agnostic and audited — the right tool when you do not
|
|
255
|
+
know whose org it was:
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
GET /diagnose/sandbox?tag=newly.run:run-42
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
It is gated by an ops OIDC token, not a user credential: mint one by
|
|
262
|
+
impersonating the `cp-diagnose-ops-<env>` service account, which every engineer
|
|
263
|
+
can do. Destroyed sandboxes are included on purpose.
|
|
264
|
+
|
|
265
|
+
**Credentials.** The CLI defaults to **prod**. For dev, set both:
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
export RUN_CLOUD_API_URL=https://cp-api-dev-97683904813.us-east4.run.app
|
|
269
|
+
export RUN_CLOUD_API_TOKEN=... # RUN_CLOUD_DEV_API_TOKEN in secrets/dev.yaml
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Key names do not match the env vars, and `sops` needs
|
|
273
|
+
`gcloud auth application-default login` rather than plain `gcloud auth login` —
|
|
274
|
+
see the Secrets section of the root `CLAUDE.md`/`AGENTS.md` before concluding
|
|
275
|
+
you lack access.
|
|
276
|
+
|
|
207
277
|
## Guardrails
|
|
208
278
|
|
|
209
279
|
- Destroy every sandbox created during a task unless the user explicitly asks
|
|
@@ -215,3 +285,5 @@ desktop URLs private and inspect each subcommand's help before automation.
|
|
|
215
285
|
URLs in logs, screenshots, PR comments, or chat output.
|
|
216
286
|
- Do not claim that CLI-only lifecycle, image, secret-group, desktop, or stable
|
|
217
287
|
hostname commands are TypeScript SDK methods.
|
|
288
|
+
- Do not overwrite a `newly.*` tag; the platform sets those and support reads
|
|
289
|
+
them. Add your own key instead.
|