@devicecloud.dev/dcd 5.12.1 → 5.13.0-beta.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/README.md +39 -40
- package/dist/commands/cloud.d.ts +1 -1
- package/dist/commands/cloud.js +8 -5
- package/dist/commands/device.js +189 -2
- package/dist/commands/login.js +4 -28
- package/dist/commands/logout.js +3 -4
- package/dist/commands/mcp.js +26 -5
- package/dist/config/flags/execution.flags.d.ts +9 -1
- package/dist/config/flags/execution.flags.js +9 -1
- package/dist/constants.d.ts +1 -1
- package/dist/gateways/cli-auth-gateway.d.ts +5 -2
- package/dist/gateways/cli-auth-gateway.js +32 -26
- package/dist/gateways/device-gateway.d.ts +6 -1
- package/dist/gateways/device-gateway.js +4 -0
- package/dist/mcp/bridge.js +21 -6
- package/dist/mcp/tools/run-cloud-test.js +7 -2
- package/dist/services/results-polling.service.d.ts +8 -11
- package/dist/services/results-polling.service.js +32 -113
- package/dist/types/domain/auth.types.d.ts +2 -2
- package/dist/types/domain/device-session.types.d.ts +37 -0
- package/dist/types/domain/device-session.types.js +13 -0
- package/dist/types/domain/device.types.d.ts +0 -1
- package/dist/types/domain/device.types.js +0 -1
- package/dist/utils/cli.d.ts +4 -1
- package/dist/utils/cli.js +5 -2
- package/dist/utils/mcp-install.d.ts +9 -2
- package/dist/utils/mcp-install.js +12 -2
- package/dist/utils/tool-spawn.d.ts +21 -0
- package/dist/utils/tool-spawn.js +65 -0
- package/package.json +1 -1
- package/dist/gateways/realtime-gateway.d.ts +0 -39
- package/dist/gateways/realtime-gateway.js +0 -128
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Does not talk to the dcd API — the dcd-side session exchange lives in the
|
|
6
6
|
* login command's PKCE rendezvous flow (see src/commands/login.ts).
|
|
7
7
|
*/
|
|
8
|
-
import { createClient, isAuthApiError } from '@supabase/supabase-js';
|
|
8
|
+
import { createClient, isAuthApiError, isAuthSessionMissingError } from '@supabase/supabase-js';
|
|
9
9
|
import { getSupabaseKey } from '../config/supabase-key.js';
|
|
10
10
|
/**
|
|
11
11
|
* Thrown when a session refresh fails. `definitive` distinguishes "Supabase
|
|
@@ -15,12 +15,30 @@ import { getSupabaseKey } from '../config/supabase-key.js';
|
|
|
15
15
|
*/
|
|
16
16
|
export class SessionRefreshError extends Error {
|
|
17
17
|
definitive;
|
|
18
|
-
|
|
18
|
+
code;
|
|
19
|
+
constructor(message, definitive,
|
|
20
|
+
/** Supabase Auth's error code (`session_expired`, …), when it sent one. */
|
|
21
|
+
code) {
|
|
19
22
|
super(message);
|
|
20
23
|
this.definitive = definitive;
|
|
24
|
+
this.code = code;
|
|
21
25
|
this.name = 'SessionRefreshError';
|
|
22
26
|
}
|
|
23
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* What to tell the user for the refusals that have a plain cause. Supabase
|
|
30
|
+
* Auth answers `session_expired` once a session passes the project's maximum
|
|
31
|
+
* length or inactivity timeout, and `session_not_found` /
|
|
32
|
+
* `refresh_token_not_found` once the session has been ended (signed out
|
|
33
|
+
* elsewhere, revoked, or removed after expiring). Any other refusal keeps
|
|
34
|
+
* Supabase's own message.
|
|
35
|
+
*/
|
|
36
|
+
const SIGNED_OUT = 'Your session was signed out. Run `dcd login` to sign in again.';
|
|
37
|
+
const REFRESH_REFUSAL_MESSAGES = new Map([
|
|
38
|
+
['session_expired', 'Your session expired. Run `dcd login` to sign in again.'],
|
|
39
|
+
['session_not_found', SIGNED_OUT],
|
|
40
|
+
['refresh_token_not_found', SIGNED_OUT],
|
|
41
|
+
]);
|
|
24
42
|
function client(supabaseUrl, supabaseKey) {
|
|
25
43
|
return createClient(supabaseUrl, supabaseKey, {
|
|
26
44
|
auth: { persistSession: false, autoRefreshToken: false, detectSessionInUrl: false },
|
|
@@ -44,12 +62,18 @@ export const CliAuthGateway = {
|
|
|
44
62
|
if (error || !data.session || !data.user) {
|
|
45
63
|
// 4xx from GoTrue means the token itself was rejected; anything else
|
|
46
64
|
// (fetch failure, 5xx) could succeed on retry with the same token.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
65
|
+
// supabase-js turns GoTrue's `session_not_found` into an
|
|
66
|
+
// AuthSessionMissingError rather than an AuthApiError (it throws the same
|
|
67
|
+
// for an empty refresh token); only `dcd login` fixes either.
|
|
68
|
+
const apiError = error != null && isAuthApiError(error) ? error : undefined;
|
|
69
|
+
const sessionMissing = error != null && isAuthSessionMissingError(error);
|
|
70
|
+
const definitive = sessionMissing ||
|
|
71
|
+
(apiError !== undefined && apiError.status >= 400 && apiError.status < 500);
|
|
72
|
+
const code = apiError?.code ?? (sessionMissing ? 'session_not_found' : undefined);
|
|
73
|
+
const known = definitive && code ? REFRESH_REFUSAL_MESSAGES.get(code) : undefined;
|
|
74
|
+
throw new SessionRefreshError(known ??
|
|
75
|
+
`Failed to refresh session: ${error?.message ?? 'no session returned'}. ` +
|
|
76
|
+
`Run \`dcd login\` again.`, definitive, code);
|
|
53
77
|
}
|
|
54
78
|
const s = data.session;
|
|
55
79
|
const u = data.user;
|
|
@@ -63,22 +87,4 @@ export const CliAuthGateway = {
|
|
|
63
87
|
user_id: u.id,
|
|
64
88
|
};
|
|
65
89
|
},
|
|
66
|
-
async signOut(supabaseUrl, env, session) {
|
|
67
|
-
// `scope: 'local'` clears this client's SDK state only — no server call,
|
|
68
|
-
// no revocation. supabase-js defaults to `scope: 'global'`, which revokes
|
|
69
|
-
// EVERY session for the user (browser, mobile, other CLIs), so
|
|
70
|
-
// `dcd logout` would kick the user out of the web app. We don't want
|
|
71
|
-
// that — logging out locally should be local.
|
|
72
|
-
try {
|
|
73
|
-
const sb = client(supabaseUrl, await getSupabaseKey(env));
|
|
74
|
-
await sb.auth.setSession({
|
|
75
|
-
access_token: session.access_token,
|
|
76
|
-
refresh_token: session.refresh_token,
|
|
77
|
-
});
|
|
78
|
-
await sb.auth.signOut({ scope: 'local' });
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
// Best effort — the local config will be wiped regardless.
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
90
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AuthContext } from '../types/domain/auth.types.js';
|
|
2
|
-
import type { DeviceArtifactsPage, DeviceBundleUploadUrls,
|
|
2
|
+
import type { DeviceActionRequest, DeviceArtifactsPage, DeviceBundleUploadUrls, DeviceCatalogue, DeviceCommandResult, DeviceFlowBundle, DeviceHumanStatus, DeviceInstalledApp, DeviceLogs, DeviceRunResponse, DeviceScreen, DeviceScreenshot, DeviceSession, StartDeviceSessionRequest } from '../types/domain/device-session.types.js';
|
|
3
3
|
/**
|
|
4
4
|
* An error answer from /device/sessions. Unlike ApiError it keeps the API's
|
|
5
5
|
* machine code (`LIVE_NOT_FOUND`, `LIVE_SPEND_CAP`, …) and the `session`
|
|
@@ -83,6 +83,11 @@ export declare const DeviceGateway: {
|
|
|
83
83
|
human: DeviceHumanStatus;
|
|
84
84
|
session: DeviceSession;
|
|
85
85
|
}>;
|
|
86
|
+
/** One typed action: tap, type, swipe or press_key. Synchronous: answers with the outcome. */
|
|
87
|
+
action(baseUrl: string, auth: AuthContext, id: string, body: DeviceActionRequest): Promise<{
|
|
88
|
+
result: DeviceCommandResult;
|
|
89
|
+
session: DeviceSession;
|
|
90
|
+
}>;
|
|
86
91
|
run(baseUrl: string, auth: AuthContext, id: string, body: {
|
|
87
92
|
env?: Record<string, string>;
|
|
88
93
|
flow?: string;
|
|
@@ -157,6 +157,10 @@ export const DeviceGateway = {
|
|
|
157
157
|
requestHuman(baseUrl, auth, id, reason) {
|
|
158
158
|
return request(baseUrl, auth, 'POST', `${sessionPath(id)}/request-human`, { reason });
|
|
159
159
|
},
|
|
160
|
+
/** One typed action: tap, type, swipe or press_key. Synchronous: answers with the outcome. */
|
|
161
|
+
action(baseUrl, auth, id, body) {
|
|
162
|
+
return request(baseUrl, auth, 'POST', `${sessionPath(id)}/actions`, body);
|
|
163
|
+
},
|
|
160
164
|
run(baseUrl, auth, id, body) {
|
|
161
165
|
return request(baseUrl, auth, 'POST', `${sessionPath(id)}/run`, body);
|
|
162
166
|
},
|
package/dist/mcp/bridge.js
CHANGED
|
@@ -31,14 +31,20 @@ import { uploadFlowBundle } from '../utils/device-bundle.js';
|
|
|
31
31
|
import { getContext, isReadOnly, logStderr } from './context.js';
|
|
32
32
|
import { errorResult, runTool } from './helpers.js';
|
|
33
33
|
import { createServer } from './server.js';
|
|
34
|
-
|
|
34
|
+
/*
|
|
35
|
+
* Sent at initialize, before this server knows which hosted tools the
|
|
36
|
+
* account has: the hosted server only serves its tools to organizations that
|
|
37
|
+
* have them. So these name only the dcd_* tools, and the hosted tools explain
|
|
38
|
+
* themselves in their own descriptions.
|
|
39
|
+
*/
|
|
40
|
+
const INSTRUCTIONS = 'DeviceCloud tools. dcd_* tools run Maestro test suites in the cloud: dcd_list_devices shows what you can test on, dcd_run_cloud_test submits flows (billable), and dcd_get_status follows a run. Any other tools describe their own use. Where a tool takes a path to a local file (an app build, a flow file or a directory), this server uploads it for you.';
|
|
35
41
|
/**
|
|
36
42
|
* How long one forwarded call may take. Longer than dcd_run_cloud_test's
|
|
37
43
|
* longest wait (3600s) plus an upload. The MCP client calling this server
|
|
38
44
|
* still applies its own timeout, and its cancel is passed through.
|
|
39
45
|
*/
|
|
40
46
|
export const CALL_TIMEOUT_MS = 2 * 60 * 60 * 1000;
|
|
41
|
-
const READ_ONLY_INSTRUCTIONS = 'DeviceCloud tools, read-only: nothing here
|
|
47
|
+
const READ_ONLY_INSTRUCTIONS = 'DeviceCloud tools, read-only: nothing here runs a test or changes anything. dcd_* tools read cloud test runs and their results. Any other tools describe their own use.';
|
|
42
48
|
/** The inputs this bridge adds to hosted tools, and what they say. */
|
|
43
49
|
const LOCAL_INPUTS = {
|
|
44
50
|
install_app: {
|
|
@@ -187,7 +193,11 @@ class RemoteDevices {
|
|
|
187
193
|
async open() {
|
|
188
194
|
const { apiUrl } = await getContext();
|
|
189
195
|
const client = new Client({ name: 'dcd-mcp-bridge', version: getCliVersion() });
|
|
190
|
-
|
|
196
|
+
// In read-only mode, ask the hosted server for its read-only tools too, so
|
|
197
|
+
// it refuses the rest as well. The filter here stays for an API without
|
|
198
|
+
// the flag, which ignores it and lists every tool.
|
|
199
|
+
const url = new URL(`${apiUrl}/mcp${isReadOnly() ? '?read_only=true' : ''}`);
|
|
200
|
+
await client.connect(new StreamableHTTPClientTransport(url, {
|
|
191
201
|
fetch: async (url, init) => {
|
|
192
202
|
const { auth } = await getContext();
|
|
193
203
|
const headers = new Headers(init?.headers);
|
|
@@ -257,9 +267,14 @@ export async function createBridgeServer(opts = {}) {
|
|
|
257
267
|
}
|
|
258
268
|
return runTool(`device ${name}`, async () => {
|
|
259
269
|
await remote.list();
|
|
260
|
-
if (!remote.has(name))
|
|
261
|
-
|
|
262
|
-
|
|
270
|
+
if (!remote.has(name)) {
|
|
271
|
+
// In read-only mode the hosted server lists only its read-only tools,
|
|
272
|
+
// so a device tool that changes something is unknown here as well.
|
|
273
|
+
return errorResult(readOnly
|
|
274
|
+
? `Unknown tool: ${name}. In read-only mode this server offers only the tools that change nothing.`
|
|
275
|
+
: `Unknown tool: ${name}`);
|
|
276
|
+
}
|
|
277
|
+
// An API without the read-only flag lists every tool; refuse these here.
|
|
263
278
|
if (readOnly && !remote.isReadOnly(name)) {
|
|
264
279
|
return errorResult(`${name} is not available in read-only mode.`);
|
|
265
280
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
import { RETIRED_RUNNER_TYPES, RUNNER_TYPE_OPTIONS, } from '../../config/flags/execution.flags.js';
|
|
3
4
|
import { ApiGateway } from '../../gateways/api-gateway.js';
|
|
4
5
|
import { plan } from '../../services/execution-plan.service.js';
|
|
5
6
|
import { isSubmitEndpointMissing, submitWithRetry, } from '../../services/flow-submit.service.js';
|
|
@@ -81,10 +82,14 @@ export function registerRunCloudTest(server) {
|
|
|
81
82
|
excludeFlows: z.array(z.string()).optional().describe('Flow paths/patterns to exclude'),
|
|
82
83
|
maestroVersion: z.string().optional().describe('Pin a specific Maestro version'),
|
|
83
84
|
retry: z.number().int().min(0).max(2).optional().describe('Auto-retry failed tests (max 2)'),
|
|
85
|
+
// A retired runner type still validates, so an agent configured with
|
|
86
|
+
// one keeps working (the API runs gpu1 on cpu1), but the schema's
|
|
87
|
+
// `enum` lists only the current ones: zod metadata overrides it.
|
|
84
88
|
runnerType: z
|
|
85
|
-
.enum([
|
|
89
|
+
.enum([...RUNNER_TYPE_OPTIONS, ...RETIRED_RUNNER_TYPES])
|
|
90
|
+
.meta({ enum: [...RUNNER_TYPE_OPTIONS] })
|
|
86
91
|
.optional()
|
|
87
|
-
.describe('Runner type (default "default").
|
|
92
|
+
.describe('Runner type (default "default").'),
|
|
88
93
|
priority: z
|
|
89
94
|
.enum(['low', 'normal', 'high'])
|
|
90
95
|
.optional()
|
|
@@ -98,8 +98,7 @@ export interface PollingResult {
|
|
|
98
98
|
*/
|
|
99
99
|
export declare class ResultsPollingService {
|
|
100
100
|
private readonly MAX_SEQUENTIAL_FAILURES;
|
|
101
|
-
private readonly
|
|
102
|
-
private readonly APIKEY_POLL_INTERVAL_MS;
|
|
101
|
+
private readonly POLL_INTERVAL_MS;
|
|
103
102
|
private readonly ERROR_BACKOFF_BASE_MS;
|
|
104
103
|
private readonly MAX_ERROR_BACKOFF_MS;
|
|
105
104
|
/**
|
|
@@ -126,12 +125,11 @@ export declare class ResultsPollingService {
|
|
|
126
125
|
private fetchAndLogResults;
|
|
127
126
|
/**
|
|
128
127
|
* Swap in a fresh `dcd login` token when the current one is about to
|
|
129
|
-
* expire
|
|
130
|
-
* as-is
|
|
131
|
-
*
|
|
128
|
+
* expire; API-key auth comes back as-is. A transient refresh failure is
|
|
129
|
+
* thrown as-is, to be retried like any failed poll; one only `dcd login`
|
|
130
|
+
* can fix becomes a PollingAuthError.
|
|
132
131
|
* @param auth The credential the previous poll used
|
|
133
132
|
* @param uploadId Upload being polled, for the reconnect hint
|
|
134
|
-
* @param subscription Realtime subscription to pass a new token to
|
|
135
133
|
* @param debug Whether debug logging is enabled
|
|
136
134
|
* @param logger Optional logger function
|
|
137
135
|
* @returns The credential for the next poll
|
|
@@ -161,16 +159,15 @@ export declare class ResultsPollingService {
|
|
|
161
159
|
private sleep;
|
|
162
160
|
/**
|
|
163
161
|
* Build the body of the live status display (the per-test table, or just the
|
|
164
|
-
* one-line summary in quiet mode). The footer (countdown
|
|
162
|
+
* one-line summary in quiet mode). The footer (the countdown) is
|
|
165
163
|
* appended separately by {@link buildStatusFooter} so it can re-render on a
|
|
166
164
|
* timer without re-fetching.
|
|
167
165
|
*/
|
|
168
166
|
private buildStatusBody;
|
|
169
167
|
/**
|
|
170
|
-
* Build the live footer shown under the status display:
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
* countdown reads "refreshing…". In quiet mode the countdown is omitted.
|
|
168
|
+
* Build the live footer shown under the status display: how long until the
|
|
169
|
+
* next poll. While a fetch is in flight (`nextPollAt` is null) it reads
|
|
170
|
+
* "refreshing…". In quiet mode (geared at CI) the footer is omitted.
|
|
174
171
|
*/
|
|
175
172
|
private buildStatusFooter;
|
|
176
173
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import { ApiGateway } from '../gateways/api-gateway.js';
|
|
3
|
-
import { RealtimeResultsGateway, } from '../gateways/realtime-gateway.js';
|
|
4
3
|
import { formatDurationSeconds } from '../methods.js';
|
|
5
4
|
import { isDefinitiveAuthFailure, refreshAuth } from '../utils/auth.js';
|
|
6
5
|
import { checkInternetConnectivity } from '../utils/connectivity.js';
|
|
@@ -98,11 +97,9 @@ export class ResultsPollingService {
|
|
|
98
97
|
// giving up. Losing a run to a brief hiccup is far more costly than waiting a
|
|
99
98
|
// bit longer.
|
|
100
99
|
MAX_SEQUENTIAL_FAILURES = 30;
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
BEARER_POLL_INTERVAL_MS = 60_000;
|
|
105
|
-
APIKEY_POLL_INTERVAL_MS = 20_000;
|
|
100
|
+
// Poll cadence, the same for API-key and `dcd login` auth. A poll that finds
|
|
101
|
+
// nothing changed costs an empty 304 (see ResultsPollCache).
|
|
102
|
+
POLL_INTERVAL_MS = 20_000;
|
|
106
103
|
// Base unit for the backoff applied between *failed* polls, and its cap.
|
|
107
104
|
ERROR_BACKOFF_BASE_MS = 10_000;
|
|
108
105
|
MAX_ERROR_BACKOFF_MS = 30_000;
|
|
@@ -136,46 +133,11 @@ export class ResultsPollingService {
|
|
|
136
133
|
// The last result set and its ETag, so a poll that finds nothing changed
|
|
137
134
|
// gets an empty 304 instead of the whole set again.
|
|
138
135
|
const resultsCache = {};
|
|
139
|
-
const pollIntervalMs =
|
|
140
|
-
? this.BEARER_POLL_INTERVAL_MS
|
|
141
|
-
: this.APIKEY_POLL_INTERVAL_MS;
|
|
142
|
-
// "Poke" mechanism: a realtime change resolves the current inter-poll wait
|
|
143
|
-
// early. If a poke lands while we're mid-fetch (not waiting) it's latched
|
|
144
|
-
// and consumed by the next wait, so events are never silently dropped.
|
|
145
|
-
let resolveWake = null;
|
|
146
|
-
let pendingPoke = false;
|
|
147
|
-
const poke = () => {
|
|
148
|
-
if (resolveWake) {
|
|
149
|
-
const r = resolveWake;
|
|
150
|
-
resolveWake = null;
|
|
151
|
-
r();
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
pendingPoke = true;
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
const waitForNextPoll = (ms) => {
|
|
158
|
-
if (pendingPoke) {
|
|
159
|
-
pendingPoke = false;
|
|
160
|
-
return Promise.resolve();
|
|
161
|
-
}
|
|
162
|
-
return new Promise((resolve) => {
|
|
163
|
-
const timer = setTimeout(() => {
|
|
164
|
-
resolveWake = null;
|
|
165
|
-
resolve();
|
|
166
|
-
}, ms);
|
|
167
|
-
resolveWake = () => {
|
|
168
|
-
clearTimeout(timer);
|
|
169
|
-
resolve();
|
|
170
|
-
};
|
|
171
|
-
});
|
|
172
|
-
};
|
|
136
|
+
const pollIntervalMs = this.POLL_INTERVAL_MS;
|
|
173
137
|
// Live display state, recomposed by renderStatus() so the footer (countdown
|
|
174
|
-
// to the next
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
let subscription;
|
|
178
|
-
let realtimeEnabled = false;
|
|
138
|
+
// to the next poll) stays current between polls without re-fetching.
|
|
139
|
+
// `nextPollAt` is an epoch-ms deadline while waiting, or null while a
|
|
140
|
+
// fetch is in flight.
|
|
179
141
|
let statusBody = '';
|
|
180
142
|
let nextPollAt = null;
|
|
181
143
|
// The animated footer/countdown only makes sense on a TTY. In CI/pipes it
|
|
@@ -189,30 +151,9 @@ export class ResultsPollingService {
|
|
|
189
151
|
ux.action.status = statusBody;
|
|
190
152
|
return;
|
|
191
153
|
}
|
|
192
|
-
const footer = this.buildStatusFooter(
|
|
154
|
+
const footer = this.buildStatusFooter(nextPollAt, quiet);
|
|
193
155
|
ux.action.status = footer ? `${statusBody}\n${footer}` : statusBody;
|
|
194
156
|
};
|
|
195
|
-
// Realtime is a latency optimisation over the backstop poll; only logged-in
|
|
196
|
-
// (bearer) users can authenticate the socket under RLS. Any failure inside
|
|
197
|
-
// the gateway degrades silently to pure polling.
|
|
198
|
-
if (auth.mode === 'bearer' && auth.accessToken && auth.orgId && auth.env) {
|
|
199
|
-
realtimeEnabled = true;
|
|
200
|
-
subscription = RealtimeResultsGateway.subscribe({
|
|
201
|
-
accessToken: auth.accessToken,
|
|
202
|
-
debug,
|
|
203
|
-
env: auth.env,
|
|
204
|
-
log: logger,
|
|
205
|
-
onChange: poke,
|
|
206
|
-
// Reflect connect/disconnect in the live footer immediately rather than
|
|
207
|
-
// waiting for the next ticker frame.
|
|
208
|
-
onConnectionChange: renderStatus,
|
|
209
|
-
orgId: auth.orgId,
|
|
210
|
-
uploadId,
|
|
211
|
-
});
|
|
212
|
-
if (debug && logger) {
|
|
213
|
-
logger(`[DEBUG] Realtime enabled; backstop poll every ${pollIntervalMs / 1000}s`);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
157
|
if (debug && logger) {
|
|
217
158
|
logger(`[DEBUG] Starting polling loop for results`);
|
|
218
159
|
}
|
|
@@ -231,7 +172,7 @@ export class ResultsPollingService {
|
|
|
231
172
|
try {
|
|
232
173
|
nextPollAt = null;
|
|
233
174
|
renderStatus();
|
|
234
|
-
auth = await this.refreshPollingAuth(auth, uploadId,
|
|
175
|
+
auth = await this.refreshPollingAuth(auth, uploadId, debug, logger);
|
|
235
176
|
const updatedResults = await this.fetchAndLogResults(apiUrl, auth, uploadId, resultsCache, debug, logger);
|
|
236
177
|
const { summary } = this.calculateStatusSummary(updatedResults);
|
|
237
178
|
if (!json) {
|
|
@@ -250,11 +191,10 @@ export class ResultsPollingService {
|
|
|
250
191
|
}
|
|
251
192
|
// Reset failure counter on successful poll
|
|
252
193
|
sequentialPollFailures = 0;
|
|
253
|
-
// Wait for the next
|
|
254
|
-
// first, while the footer counts down to the deadline.
|
|
194
|
+
// Wait for the next poll while the footer counts down to it.
|
|
255
195
|
nextPollAt = Date.now() + pollIntervalMs;
|
|
256
196
|
renderStatus();
|
|
257
|
-
await
|
|
197
|
+
await this.sleep(pollIntervalMs);
|
|
258
198
|
}
|
|
259
199
|
catch (error) {
|
|
260
200
|
// Re-throw RunFailedError immediately (test failures, not polling
|
|
@@ -275,12 +215,6 @@ export class ResultsPollingService {
|
|
|
275
215
|
if (ticker) {
|
|
276
216
|
clearInterval(ticker);
|
|
277
217
|
}
|
|
278
|
-
if (subscription) {
|
|
279
|
-
if (debug && logger) {
|
|
280
|
-
logger('[DEBUG] Closing realtime subscription');
|
|
281
|
-
}
|
|
282
|
-
await subscription.unsubscribe();
|
|
283
|
-
}
|
|
284
218
|
}
|
|
285
219
|
}
|
|
286
220
|
buildPollingResult(results, uploadId, consoleUrl, testMetadata) {
|
|
@@ -428,17 +362,16 @@ export class ResultsPollingService {
|
|
|
428
362
|
}
|
|
429
363
|
/**
|
|
430
364
|
* Swap in a fresh `dcd login` token when the current one is about to
|
|
431
|
-
* expire
|
|
432
|
-
* as-is
|
|
433
|
-
*
|
|
365
|
+
* expire; API-key auth comes back as-is. A transient refresh failure is
|
|
366
|
+
* thrown as-is, to be retried like any failed poll; one only `dcd login`
|
|
367
|
+
* can fix becomes a PollingAuthError.
|
|
434
368
|
* @param auth The credential the previous poll used
|
|
435
369
|
* @param uploadId Upload being polled, for the reconnect hint
|
|
436
|
-
* @param subscription Realtime subscription to pass a new token to
|
|
437
370
|
* @param debug Whether debug logging is enabled
|
|
438
371
|
* @param logger Optional logger function
|
|
439
372
|
* @returns The credential for the next poll
|
|
440
373
|
*/
|
|
441
|
-
async refreshPollingAuth(auth, uploadId,
|
|
374
|
+
async refreshPollingAuth(auth, uploadId, debug, logger) {
|
|
442
375
|
let next;
|
|
443
376
|
try {
|
|
444
377
|
next = await refreshAuth(auth);
|
|
@@ -446,18 +379,15 @@ export class ResultsPollingService {
|
|
|
446
379
|
catch (error) {
|
|
447
380
|
if (isDefinitiveAuthFailure(error)) {
|
|
448
381
|
const reason = error instanceof Error ? error.message : String(error);
|
|
449
|
-
throw new PollingAuthError(
|
|
450
|
-
|
|
382
|
+
throw new PollingAuthError(
|
|
383
|
+
// The reason already says to run `dcd login`, so don't repeat it.
|
|
384
|
+
`${reason}\n\n` +
|
|
385
|
+
`The test is still running in the cloud. Once you've signed in again, reconnect with:\n dcd status --upload-id ${uploadId}`);
|
|
451
386
|
}
|
|
452
387
|
throw error;
|
|
453
388
|
}
|
|
454
|
-
if (next !== auth) {
|
|
455
|
-
|
|
456
|
-
logger('[DEBUG] Refreshed the dcd login session for polling');
|
|
457
|
-
}
|
|
458
|
-
if (next.accessToken && next.accessToken !== auth.accessToken) {
|
|
459
|
-
subscription?.updateAccessToken(next.accessToken);
|
|
460
|
-
}
|
|
389
|
+
if (next !== auth && debug && logger) {
|
|
390
|
+
logger('[DEBUG] Refreshed the dcd login session for polling');
|
|
461
391
|
}
|
|
462
392
|
return next;
|
|
463
393
|
}
|
|
@@ -599,7 +529,7 @@ export class ResultsPollingService {
|
|
|
599
529
|
}
|
|
600
530
|
/**
|
|
601
531
|
* Build the body of the live status display (the per-test table, or just the
|
|
602
|
-
* one-line summary in quiet mode). The footer (countdown
|
|
532
|
+
* one-line summary in quiet mode). The footer (the countdown) is
|
|
603
533
|
* appended separately by {@link buildStatusFooter} so it can re-render on a
|
|
604
534
|
* timer without re-fetching.
|
|
605
535
|
*/
|
|
@@ -615,29 +545,18 @@ export class ResultsPollingService {
|
|
|
615
545
|
return `\n${ui.branch(ui.fields(rows))}`;
|
|
616
546
|
}
|
|
617
547
|
/**
|
|
618
|
-
* Build the live footer shown under the status display:
|
|
619
|
-
*
|
|
620
|
-
*
|
|
621
|
-
* countdown reads "refreshing…". In quiet mode the countdown is omitted.
|
|
548
|
+
* Build the live footer shown under the status display: how long until the
|
|
549
|
+
* next poll. While a fetch is in flight (`nextPollAt` is null) it reads
|
|
550
|
+
* "refreshing…". In quiet mode (geared at CI) the footer is omitted.
|
|
622
551
|
*/
|
|
623
|
-
buildStatusFooter(
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
parts.push(realtimeConnected
|
|
627
|
-
? colors.success('● realtime connected')
|
|
628
|
-
: colors.warning('○ realtime connecting…'));
|
|
552
|
+
buildStatusFooter(nextPollAt, quiet) {
|
|
553
|
+
if (quiet) {
|
|
554
|
+
return '';
|
|
629
555
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
if (!quiet) {
|
|
633
|
-
if (nextPollAt === null) {
|
|
634
|
-
parts.push(colors.dim('refreshing…'));
|
|
635
|
-
}
|
|
636
|
-
else {
|
|
637
|
-
const secondsLeft = Math.max(0, Math.ceil((nextPollAt - Date.now()) / 1000));
|
|
638
|
-
parts.push(colors.dim(`next refresh in ${secondsLeft}s`));
|
|
639
|
-
}
|
|
556
|
+
if (nextPollAt === null) {
|
|
557
|
+
return colors.dim('refreshing…');
|
|
640
558
|
}
|
|
641
|
-
|
|
559
|
+
const secondsLeft = Math.max(0, Math.ceil((nextPollAt - Date.now()) / 1000));
|
|
560
|
+
return colors.dim(`next refresh in ${secondsLeft}s`);
|
|
642
561
|
}
|
|
643
562
|
}
|
|
@@ -7,8 +7,8 @@ export interface AuthContext {
|
|
|
7
7
|
headers: Record<string, string>;
|
|
8
8
|
mode: 'apiKey' | 'bearer';
|
|
9
9
|
/**
|
|
10
|
-
* Supabase JWT — present when mode === 'bearer'.
|
|
11
|
-
*
|
|
10
|
+
* Supabase JWT — present when mode === 'bearer'. Kept beside the headers so
|
|
11
|
+
* a refresh can swap it without re-reading the session from disk.
|
|
12
12
|
*/
|
|
13
13
|
accessToken?: string;
|
|
14
14
|
/** Environment the session belongs to — present when mode === 'bearer'. */
|
|
@@ -99,6 +99,43 @@ export interface DeviceFlowResult {
|
|
|
99
99
|
file: null | string;
|
|
100
100
|
success: boolean;
|
|
101
101
|
}
|
|
102
|
+
export type DeviceSwipeDirection = 'down' | 'left' | 'right' | 'up';
|
|
103
|
+
export interface DevicePoint {
|
|
104
|
+
/** Percentages of the screen's width and height, 0 to 100. */
|
|
105
|
+
x: number;
|
|
106
|
+
y: number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* One typed action for POST /device/sessions/:id/actions. `mode` is
|
|
110
|
+
* deprecated: the API still accepts `'maestro'` and ignores it, and the CLI
|
|
111
|
+
* no longer sends it.
|
|
112
|
+
*/
|
|
113
|
+
export type DeviceActionRequest = {
|
|
114
|
+
id?: string;
|
|
115
|
+
mode?: 'maestro';
|
|
116
|
+
text?: string;
|
|
117
|
+
type: 'tap';
|
|
118
|
+
x?: number;
|
|
119
|
+
y?: number;
|
|
120
|
+
} | {
|
|
121
|
+
key: string;
|
|
122
|
+
mode?: 'maestro';
|
|
123
|
+
type: 'press_key';
|
|
124
|
+
} | {
|
|
125
|
+
mode?: 'maestro';
|
|
126
|
+
sensitive?: boolean;
|
|
127
|
+
text: string;
|
|
128
|
+
type: 'type';
|
|
129
|
+
} | {
|
|
130
|
+
direction?: DeviceSwipeDirection;
|
|
131
|
+
from?: DevicePoint;
|
|
132
|
+
mode?: 'maestro';
|
|
133
|
+
to?: DevicePoint;
|
|
134
|
+
type: 'swipe';
|
|
135
|
+
};
|
|
136
|
+
/** The keys press_key takes, as the API names them. */
|
|
137
|
+
export declare const DEVICE_KEYS: readonly ["back", "home", "enter", "backspace", "tab", "volume_up", "volume_down", "lock", "power"];
|
|
138
|
+
export declare const SWIPE_DIRECTIONS: readonly DeviceSwipeDirection[];
|
|
102
139
|
/** The result of a typed action, a launch or a run. */
|
|
103
140
|
export interface DeviceCommandResult {
|
|
104
141
|
error?: string;
|
|
@@ -3,3 +3,16 @@
|
|
|
3
3
|
// dcd/api/src/apps/live/live.types.ts and device-sessions.controller.ts.
|
|
4
4
|
/** States a session can no longer leave. */
|
|
5
5
|
export const ENDED_STATES = ['released', 'expired', 'failed'];
|
|
6
|
+
/** The keys press_key takes, as the API names them. */
|
|
7
|
+
export const DEVICE_KEYS = [
|
|
8
|
+
'back',
|
|
9
|
+
'home',
|
|
10
|
+
'enter',
|
|
11
|
+
'backspace',
|
|
12
|
+
'tab',
|
|
13
|
+
'volume_up',
|
|
14
|
+
'volume_down',
|
|
15
|
+
'lock',
|
|
16
|
+
'power',
|
|
17
|
+
];
|
|
18
|
+
export const SWIPE_DIRECTIONS = ['up', 'down', 'left', 'right'];
|
|
@@ -18,7 +18,6 @@ export declare enum EiOSDevices {
|
|
|
18
18
|
'iphone-14' = "iphone-14",
|
|
19
19
|
'iphone-16' = "iphone-16",
|
|
20
20
|
'iphone-16-pro' = "iphone-16-pro",
|
|
21
|
-
'iphone-16-pro-max' = "iphone-16-pro-max",
|
|
22
21
|
'iphone-17' = "iphone-17",
|
|
23
22
|
'iphone-18-pro' = "iphone-18-pro",
|
|
24
23
|
'iphone-18-pro-max' = "iphone-18-pro-max",
|
|
@@ -19,7 +19,6 @@ export var EiOSDevices;
|
|
|
19
19
|
EiOSDevices["iphone-14"] = "iphone-14";
|
|
20
20
|
EiOSDevices["iphone-16"] = "iphone-16";
|
|
21
21
|
EiOSDevices["iphone-16-pro"] = "iphone-16-pro";
|
|
22
|
-
EiOSDevices["iphone-16-pro-max"] = "iphone-16-pro-max";
|
|
23
22
|
EiOSDevices["iphone-17"] = "iphone-17";
|
|
24
23
|
EiOSDevices["iphone-18-pro"] = "iphone-18-pro";
|
|
25
24
|
EiOSDevices["iphone-18-pro-max"] = "iphone-18-pro-max";
|
package/dist/utils/cli.d.ts
CHANGED
|
@@ -26,8 +26,11 @@ export declare function wantsJson(rawArgs: string[]): boolean;
|
|
|
26
26
|
/**
|
|
27
27
|
* Validate that a string flag value is one of the allowed options.
|
|
28
28
|
* Returns the value untouched on success; throws CliError otherwise.
|
|
29
|
+
*
|
|
30
|
+
* `unlisted` values are accepted too but left out of the error message: a
|
|
31
|
+
* retired option that old scripts may still pass, which nobody should pick.
|
|
29
32
|
*/
|
|
30
|
-
export declare function validateEnum<T extends string>(value: string | undefined, allowed: readonly T[], flagName: string): T | undefined;
|
|
33
|
+
export declare function validateEnum<T extends string, U extends string = never>(value: string | undefined, allowed: readonly T[], flagName: string, unlisted?: readonly U[]): T | U | undefined;
|
|
31
34
|
/**
|
|
32
35
|
* Coerce a flag value (possibly a single string, array, or undefined) into a
|
|
33
36
|
* flat string array. Comma-separated values inside each entry are split out.
|
package/dist/utils/cli.js
CHANGED
|
@@ -103,11 +103,14 @@ export function wantsJson(rawArgs) {
|
|
|
103
103
|
/**
|
|
104
104
|
* Validate that a string flag value is one of the allowed options.
|
|
105
105
|
* Returns the value untouched on success; throws CliError otherwise.
|
|
106
|
+
*
|
|
107
|
+
* `unlisted` values are accepted too but left out of the error message: a
|
|
108
|
+
* retired option that old scripts may still pass, which nobody should pick.
|
|
106
109
|
*/
|
|
107
|
-
export function validateEnum(value, allowed, flagName) {
|
|
110
|
+
export function validateEnum(value, allowed, flagName, unlisted = []) {
|
|
108
111
|
if (value === undefined || value === null || value === '')
|
|
109
112
|
return undefined;
|
|
110
|
-
if (!allowed.includes(value)) {
|
|
113
|
+
if (!allowed.includes(value) && !unlisted.includes(value)) {
|
|
111
114
|
throw new CliError(`Invalid value for --${flagName}: "${value}". Expected one of: ${allowed.join(', ')}`);
|
|
112
115
|
}
|
|
113
116
|
return value;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type InstallMethod } from './cli.js';
|
|
2
2
|
/** The server's name in every client's config. */
|
|
3
3
|
export declare const SERVER_NAME = "devicecloud";
|
|
4
|
-
export declare const MCP_CLIENTS: readonly ["claude-code", "claude-desktop", "cursor", "vscode"];
|
|
4
|
+
export declare const MCP_CLIENTS: readonly ["claude-code", "claude-desktop", "codex", "cursor", "vscode"];
|
|
5
5
|
export type McpClient = (typeof MCP_CLIENTS)[number];
|
|
6
6
|
export declare const CLIENT_LABELS: Record<McpClient, string>;
|
|
7
7
|
export interface ServerLaunch {
|
|
@@ -27,7 +27,8 @@ export declare function serverLaunch(opts: {
|
|
|
27
27
|
export declare function stableNodePath(execPath: string, pathEnv?: string | undefined, platform?: NodeJS.Platform): string;
|
|
28
28
|
/**
|
|
29
29
|
* The JSON config file a client reads, or undefined when it is configured
|
|
30
|
-
* through its own CLI (Claude Code, VS Code) or has no known location
|
|
30
|
+
* through its own CLI (Claude Code, Codex, VS Code) or has no known location
|
|
31
|
+
* here.
|
|
31
32
|
*/
|
|
32
33
|
export declare function clientConfigPath(client: McpClient, platform?: NodeJS.Platform, home?: string, env?: NodeJS.ProcessEnv): string | undefined;
|
|
33
34
|
/** The `mcpServers` block Claude Desktop and Cursor read, with ours in it. */
|
|
@@ -44,6 +45,12 @@ export declare function writeClientConfig(file: string, launch: ServerLaunch): {
|
|
|
44
45
|
};
|
|
45
46
|
/** `claude mcp add` arguments, at user scope so it works in every project. */
|
|
46
47
|
export declare function claudeCodeAddArgs(launch: ServerLaunch): string[];
|
|
48
|
+
/**
|
|
49
|
+
* `codex mcp add` arguments. Codex keeps MCP servers in ~/.codex/config.toml,
|
|
50
|
+
* which its CLI, IDE extension and desktop app share, so its own CLI writes
|
|
51
|
+
* the entry rather than this one parsing TOML.
|
|
52
|
+
*/
|
|
53
|
+
export declare function codexAddArgs(launch: ServerLaunch): string[];
|
|
47
54
|
/** `code --add-mcp` arguments, which add the server to the VS Code user profile. */
|
|
48
55
|
export declare function vscodeAddArgs(launch: ServerLaunch): string[];
|
|
49
56
|
/** A command line to show a person, quoting the parts that need it. */
|