@devicecloud.dev/dcd 5.13.0-beta.1 → 5.13.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/dist/commands/cloud.js +3 -3
- package/dist/commands/device.js +12 -7
- package/dist/commands/login.js +4 -28
- package/dist/commands/logout.js +3 -4
- package/dist/config/environments.d.ts +16 -2
- package/dist/config/environments.js +17 -5
- package/dist/gateways/cli-auth-gateway.d.ts +0 -1
- package/dist/gateways/cli-auth-gateway.js +0 -18
- package/dist/services/results-polling.service.d.ts +8 -11
- package/dist/services/results-polling.service.js +28 -111
- package/dist/types/domain/auth.types.d.ts +2 -2
- package/dist/types/domain/device-session.types.d.ts +3 -2
- package/package.json +2 -2
- package/dist/gateways/realtime-gateway.d.ts +0 -39
- package/dist/gateways/realtime-gateway.js +0 -128
package/dist/commands/cloud.js
CHANGED
|
@@ -237,10 +237,10 @@ export const cloudCommand = defineCommand({
|
|
|
237
237
|
tempFiles.push(flows);
|
|
238
238
|
}
|
|
239
239
|
const auth = await resolveAuth({ apiKeyFlag });
|
|
240
|
-
// Nudge interactive api-key users toward `dcd login
|
|
241
|
-
//
|
|
240
|
+
// Nudge interactive api-key users toward `dcd login`. Suppressed in CI and
|
|
241
|
+
// non-interactive output.
|
|
242
242
|
if (auth.mode === 'apiKey' && !json && !quiet && !isCI()) {
|
|
243
|
-
out(colors.dim('Tip: run `dcd login` for
|
|
243
|
+
out(colors.dim('Tip: run `dcd login` for a smoother experience than passing --api-key.'));
|
|
244
244
|
}
|
|
245
245
|
const ciContext = detectCiContext();
|
|
246
246
|
let compatibilityData;
|
package/dist/commands/device.js
CHANGED
|
@@ -580,11 +580,15 @@ const launchSub = defineCommand({
|
|
|
580
580
|
});
|
|
581
581
|
},
|
|
582
582
|
});
|
|
583
|
-
/**
|
|
583
|
+
/**
|
|
584
|
+
* Shared by the typed-action subcommands. It chose Maestro over the device's
|
|
585
|
+
* direct path when a device session had two engines. It has one now, so the
|
|
586
|
+
* flag is still taken, for scripts that pass it, and does nothing.
|
|
587
|
+
*/
|
|
584
588
|
const maestroArg = {
|
|
585
589
|
type: 'boolean',
|
|
586
590
|
default: false,
|
|
587
|
-
description: '
|
|
591
|
+
description: 'Deprecated: has no effect. Device sessions have a single engine',
|
|
588
592
|
};
|
|
589
593
|
/** A percentage of the screen from a flag value, or a usage error. */
|
|
590
594
|
function percentArg(value, flag) {
|
|
@@ -609,10 +613,7 @@ function pointArg(value, flag) {
|
|
|
609
613
|
async function performAction(args, id, body, labels) {
|
|
610
614
|
const ctx = await context(args);
|
|
611
615
|
const sessionId = await resolveSessionId(ctx.apiUrl, ctx.auth, id);
|
|
612
|
-
const { result, session } = await DeviceGateway.action(ctx.apiUrl, ctx.auth, sessionId,
|
|
613
|
-
...body,
|
|
614
|
-
...(args.maestro ? { mode: 'maestro' } : {}),
|
|
615
|
-
});
|
|
616
|
+
const { result, session } = await DeviceGateway.action(ctx.apiUrl, ctx.auth, sessionId, body);
|
|
616
617
|
return {
|
|
617
618
|
session,
|
|
618
619
|
data: { result },
|
|
@@ -922,7 +923,11 @@ async function waitForCommand(ctx, id, commandId) {
|
|
|
922
923
|
}
|
|
923
924
|
}
|
|
924
925
|
const runSub = defineCommand({
|
|
925
|
-
meta: {
|
|
926
|
+
meta: {
|
|
927
|
+
name: 'run',
|
|
928
|
+
description: 'Run a Maestro flow (or a directory of flows) on the device, and wait for the result. ' +
|
|
929
|
+
'A device session runs the common Maestro commands and no flow scripts (runScript, evalScript)',
|
|
930
|
+
},
|
|
926
931
|
args: {
|
|
927
932
|
...commonArgs,
|
|
928
933
|
id: idArg,
|
package/dist/commands/login.js
CHANGED
|
@@ -35,7 +35,6 @@ import * as p from '@clack/prompts';
|
|
|
35
35
|
import { defineCommand } from 'citty';
|
|
36
36
|
import { createHash, randomBytes } from 'node:crypto';
|
|
37
37
|
import { ENVIRONMENTS, inferEnvFromApiUrl, resolveFrontendUrl, } from '../config/environments.js';
|
|
38
|
-
import { getSupabaseKey } from '../config/supabase-key.js';
|
|
39
38
|
import { jsonFlag } from '../config/flags/output.flags.js';
|
|
40
39
|
import { openBrowser } from '../utils/browser.js';
|
|
41
40
|
import { canPrompt } from '../utils/ci.js';
|
|
@@ -175,17 +174,11 @@ export const loginCommand = defineCommand({
|
|
|
175
174
|
orgs = await fetchOrgs(apiUrl, bearerHeaders);
|
|
176
175
|
}
|
|
177
176
|
catch (err) {
|
|
178
|
-
// The api rejected the JWT
|
|
179
|
-
//
|
|
180
|
-
// rejects it, the token itself is bad; if Supabase accepts, the
|
|
181
|
-
// api's JwtService is misconfigured.
|
|
177
|
+
// The api rejected the JWT it just minted. Name the token's issuer, so
|
|
178
|
+
// a token from the wrong environment is plain from the error.
|
|
182
179
|
const iss = decodeJwtIssuer(payload.access_token);
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
iss ? `token iss: ${iss}` : null,
|
|
186
|
-
`supabase /auth/v1/user: ${supabaseUser}`,
|
|
187
|
-
].filter(Boolean);
|
|
188
|
-
throw new CliError(`${err.message} [${parts.join(' | ')}]`);
|
|
180
|
+
const message = err.message;
|
|
181
|
+
throw new CliError(iss ? `${message} [token iss: ${iss}]` : message);
|
|
189
182
|
}
|
|
190
183
|
const { org: chosen, fromLastLogin } = await selectOrg(orgs, {
|
|
191
184
|
requested: requestedOrg,
|
|
@@ -273,23 +266,6 @@ async function pollForClaim(apiUrl, state, codeVerifier) {
|
|
|
273
266
|
function base64url(buf) {
|
|
274
267
|
return buf.toString('base64').replaceAll('+', '-').replaceAll('/', '_').replace(/=+$/, '');
|
|
275
268
|
}
|
|
276
|
-
async function probeSupabaseUser(iss, env, token) {
|
|
277
|
-
if (!iss)
|
|
278
|
-
return 'skipped (no iss)';
|
|
279
|
-
try {
|
|
280
|
-
const res = await fetch(`${iss}/user`, {
|
|
281
|
-
headers: {
|
|
282
|
-
authorization: `Bearer ${token}`,
|
|
283
|
-
apikey: await getSupabaseKey(env),
|
|
284
|
-
},
|
|
285
|
-
});
|
|
286
|
-
const bodyText = await res.text().catch(() => '');
|
|
287
|
-
return `HTTP ${res.status}${bodyText ? ` — ${bodyText.slice(0, 200)}` : ''}`;
|
|
288
|
-
}
|
|
289
|
-
catch (err) {
|
|
290
|
-
return `network error: ${err.message}`;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
269
|
function decodeJwtIssuer(token) {
|
|
294
270
|
try {
|
|
295
271
|
const [, payloadB64] = token.split('.');
|
package/dist/commands/logout.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `dcd logout` —
|
|
3
|
-
*
|
|
2
|
+
* `dcd logout` — deletes the stored session. Local only: nothing is revoked
|
|
3
|
+
* server-side, so the user stays signed in to the web app and any other CLI.
|
|
4
|
+
* Leaves DEVICE_CLOUD_API_KEY (env/flag) untouched.
|
|
4
5
|
*/
|
|
5
6
|
import { defineCommand } from 'citty';
|
|
6
7
|
import { jsonFlag } from '../config/flags/output.flags.js';
|
|
7
|
-
import { CliAuthGateway } from '../gateways/cli-auth-gateway.js';
|
|
8
8
|
import { logger } from '../utils/cli.js';
|
|
9
9
|
import { clearConfig, getConfigPath, readConfig } from '../utils/config-store.js';
|
|
10
10
|
import { colors } from '../utils/styling.js';
|
|
@@ -30,7 +30,6 @@ export const logoutCommand = defineCommand({
|
|
|
30
30
|
}
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
await CliAuthGateway.signOut(config.supabase_url, config.env, config.session);
|
|
34
33
|
clearConfig();
|
|
35
34
|
if (json) {
|
|
36
35
|
logger.json({ status: 'SUCCESS', loggedOut: true, user: config.session.user_email });
|
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
export type DcdEnvName = 'dev' | 'prod';
|
|
12
12
|
export interface DcdEnvironment {
|
|
13
13
|
apiUrl: string;
|
|
14
|
+
/**
|
|
15
|
+
* Older API URLs that still reach this environment. A config saved by an
|
|
16
|
+
* earlier `dcd login`, or a `--api-url` in someone's CI, may still name one,
|
|
17
|
+
* so it must keep resolving to this environment.
|
|
18
|
+
*/
|
|
19
|
+
legacyApiUrls?: string[];
|
|
14
20
|
frontendUrl: string;
|
|
15
21
|
supabase: {
|
|
16
22
|
url: string;
|
|
@@ -18,9 +24,17 @@ export interface DcdEnvironment {
|
|
|
18
24
|
};
|
|
19
25
|
}
|
|
20
26
|
export declare const ENVIRONMENTS: Record<DcdEnvName, DcdEnvironment>;
|
|
21
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Exact-match lookup of a known environment by API URL, current or legacy
|
|
29
|
+
* (trailing slashes ignored).
|
|
30
|
+
*/
|
|
22
31
|
export declare function findEnvByApiUrl(apiUrl: string): DcdEnvironment | undefined;
|
|
23
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Map a caller-supplied API URL to one of the known environments. This picks
|
|
34
|
+
* the Supabase project uploads go to, so a dev URL must never fall through to
|
|
35
|
+
* prod: both dev hostnames (`dev-api.` and the older `api.dev.`) and
|
|
36
|
+
* localhost are dev.
|
|
37
|
+
*/
|
|
24
38
|
export declare function inferEnvFromApiUrl(apiUrl: string): DcdEnvName;
|
|
25
39
|
/**
|
|
26
40
|
* Frontend URL to open for a given API URL. Same as
|
|
@@ -18,7 +18,8 @@ export const ENVIRONMENTS = {
|
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
20
|
dev: {
|
|
21
|
-
apiUrl: 'https://api.
|
|
21
|
+
apiUrl: 'https://dev-api.devicecloud.dev',
|
|
22
|
+
legacyApiUrls: ['https://api.dev.devicecloud.dev'],
|
|
22
23
|
frontendUrl: 'https://dev.console.devicecloud.dev',
|
|
23
24
|
supabase: {
|
|
24
25
|
url: 'https://lbmsowehtjwnqlurpemb.supabase.co',
|
|
@@ -26,16 +27,27 @@ export const ENVIRONMENTS = {
|
|
|
26
27
|
},
|
|
27
28
|
},
|
|
28
29
|
};
|
|
29
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Exact-match lookup of a known environment by API URL, current or legacy
|
|
32
|
+
* (trailing slashes ignored).
|
|
33
|
+
*/
|
|
30
34
|
export function findEnvByApiUrl(apiUrl) {
|
|
31
35
|
const normalize = (u) => u.replace(/\/+$/, '');
|
|
32
36
|
const needle = normalize(apiUrl);
|
|
33
|
-
return Object.values(ENVIRONMENTS).find((env) =>
|
|
37
|
+
return Object.values(ENVIRONMENTS).find((env) => [env.apiUrl, ...(env.legacyApiUrls ?? [])].some((u) => normalize(u) === needle));
|
|
34
38
|
}
|
|
35
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Map a caller-supplied API URL to one of the known environments. This picks
|
|
41
|
+
* the Supabase project uploads go to, so a dev URL must never fall through to
|
|
42
|
+
* prod: both dev hostnames (`dev-api.` and the older `api.dev.`) and
|
|
43
|
+
* localhost are dev.
|
|
44
|
+
*/
|
|
36
45
|
export function inferEnvFromApiUrl(apiUrl) {
|
|
37
|
-
if (apiUrl.includes('api.
|
|
46
|
+
if (apiUrl.includes('dev-api.') ||
|
|
47
|
+
apiUrl.includes('api.dev.') ||
|
|
48
|
+
apiUrl.includes('localhost')) {
|
|
38
49
|
return 'dev';
|
|
50
|
+
}
|
|
39
51
|
return 'prod';
|
|
40
52
|
}
|
|
41
53
|
/**
|
|
@@ -24,5 +24,4 @@ export interface RefreshedSession {
|
|
|
24
24
|
}
|
|
25
25
|
export declare const CliAuthGateway: {
|
|
26
26
|
refresh(supabaseUrl: string, env: DcdEnvName, session: StoredSession): Promise<RefreshedSession>;
|
|
27
|
-
signOut(supabaseUrl: string, env: DcdEnvName, session: StoredSession): Promise<void>;
|
|
28
27
|
};
|
|
@@ -87,22 +87,4 @@ export const CliAuthGateway = {
|
|
|
87
87
|
user_id: u.id,
|
|
88
88
|
};
|
|
89
89
|
},
|
|
90
|
-
async signOut(supabaseUrl, env, session) {
|
|
91
|
-
// `scope: 'local'` clears this client's SDK state only — no server call,
|
|
92
|
-
// no revocation. supabase-js defaults to `scope: 'global'`, which revokes
|
|
93
|
-
// EVERY session for the user (browser, mobile, other CLIs), so
|
|
94
|
-
// `dcd logout` would kick the user out of the web app. We don't want
|
|
95
|
-
// that — logging out locally should be local.
|
|
96
|
-
try {
|
|
97
|
-
const sb = client(supabaseUrl, await getSupabaseKey(env));
|
|
98
|
-
await sb.auth.setSession({
|
|
99
|
-
access_token: session.access_token,
|
|
100
|
-
refresh_token: session.refresh_token,
|
|
101
|
-
});
|
|
102
|
-
await sb.auth.signOut({ scope: 'local' });
|
|
103
|
-
}
|
|
104
|
-
catch {
|
|
105
|
-
// Best effort — the local config will be wiped regardless.
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
90
|
};
|
|
@@ -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);
|
|
@@ -453,13 +386,8 @@ export class ResultsPollingService {
|
|
|
453
386
|
}
|
|
454
387
|
throw error;
|
|
455
388
|
}
|
|
456
|
-
if (next !== auth) {
|
|
457
|
-
|
|
458
|
-
logger('[DEBUG] Refreshed the dcd login session for polling');
|
|
459
|
-
}
|
|
460
|
-
if (next.accessToken && next.accessToken !== auth.accessToken) {
|
|
461
|
-
subscription?.updateAccessToken(next.accessToken);
|
|
462
|
-
}
|
|
389
|
+
if (next !== auth && debug && logger) {
|
|
390
|
+
logger('[DEBUG] Refreshed the dcd login session for polling');
|
|
463
391
|
}
|
|
464
392
|
return next;
|
|
465
393
|
}
|
|
@@ -601,7 +529,7 @@ export class ResultsPollingService {
|
|
|
601
529
|
}
|
|
602
530
|
/**
|
|
603
531
|
* Build the body of the live status display (the per-test table, or just the
|
|
604
|
-
* one-line summary in quiet mode). The footer (countdown
|
|
532
|
+
* one-line summary in quiet mode). The footer (the countdown) is
|
|
605
533
|
* appended separately by {@link buildStatusFooter} so it can re-render on a
|
|
606
534
|
* timer without re-fetching.
|
|
607
535
|
*/
|
|
@@ -617,29 +545,18 @@ export class ResultsPollingService {
|
|
|
617
545
|
return `\n${ui.branch(ui.fields(rows))}`;
|
|
618
546
|
}
|
|
619
547
|
/**
|
|
620
|
-
* Build the live footer shown under the status display:
|
|
621
|
-
*
|
|
622
|
-
*
|
|
623
|
-
* 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.
|
|
624
551
|
*/
|
|
625
|
-
buildStatusFooter(
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
parts.push(realtimeConnected
|
|
629
|
-
? colors.success('● realtime connected')
|
|
630
|
-
: colors.warning('○ realtime connecting…'));
|
|
552
|
+
buildStatusFooter(nextPollAt, quiet) {
|
|
553
|
+
if (quiet) {
|
|
554
|
+
return '';
|
|
631
555
|
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
if (!quiet) {
|
|
635
|
-
if (nextPollAt === null) {
|
|
636
|
-
parts.push(colors.dim('refreshing…'));
|
|
637
|
-
}
|
|
638
|
-
else {
|
|
639
|
-
const secondsLeft = Math.max(0, Math.ceil((nextPollAt - Date.now()) / 1000));
|
|
640
|
-
parts.push(colors.dim(`next refresh in ${secondsLeft}s`));
|
|
641
|
-
}
|
|
556
|
+
if (nextPollAt === null) {
|
|
557
|
+
return colors.dim('refreshing…');
|
|
642
558
|
}
|
|
643
|
-
|
|
559
|
+
const secondsLeft = Math.max(0, Math.ceil((nextPollAt - Date.now()) / 1000));
|
|
560
|
+
return colors.dim(`next refresh in ${secondsLeft}s`);
|
|
644
561
|
}
|
|
645
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'. */
|
|
@@ -106,8 +106,9 @@ export interface DevicePoint {
|
|
|
106
106
|
y: number;
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
|
-
* One typed action for POST /device/sessions/:id/actions. `mode
|
|
110
|
-
*
|
|
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.
|
|
111
112
|
*/
|
|
112
113
|
export type DeviceActionRequest = {
|
|
113
114
|
id?: string;
|
package/package.json
CHANGED
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"test:unit": "node scripts/test-runner.mjs --unit",
|
|
69
69
|
"typecheck": "tsc --noEmit -p tsconfig.test.json"
|
|
70
70
|
},
|
|
71
|
-
"version": "5.13.0
|
|
71
|
+
"version": "5.13.0",
|
|
72
72
|
"bugs": {
|
|
73
73
|
"url": "https://discord.gg/gm3mJwcNw8"
|
|
74
74
|
},
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"esbuild@<0.28.1": ">=0.28.1",
|
|
112
112
|
"qs@<6.16.1": "6.16.1",
|
|
113
113
|
"fast-uri@>=3.0.0 <3.1.9": "3.1.9",
|
|
114
|
-
"hono@>=4.0.0 <4.13.
|
|
114
|
+
"hono@>=4.0.0 <4.13.16": "4.13.16",
|
|
115
115
|
"source-map-js@<1.2.2": "1.2.2",
|
|
116
116
|
"micromatch>picomatch": "^2.3.2",
|
|
117
117
|
"tinyglobby>picomatch": "^4.0.4"
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { type DcdEnvName } from '../config/environments.js';
|
|
2
|
-
export interface RealtimeResultsSubscription {
|
|
3
|
-
/**
|
|
4
|
-
* Whether the channel is currently subscribed and receiving pushes. False
|
|
5
|
-
* until the socket subscribes, and again if it errors/closes — the backstop
|
|
6
|
-
* poll always covers the gap.
|
|
7
|
-
*/
|
|
8
|
-
isConnected(): boolean;
|
|
9
|
-
/** Tear down the channel and close the socket. Best-effort, never throws. */
|
|
10
|
-
unsubscribe(): Promise<void>;
|
|
11
|
-
/**
|
|
12
|
-
* Hand the socket a refreshed JWT. RLS authorises the channel with the token
|
|
13
|
-
* it joined with, and the server drops the channel once that expires — so a
|
|
14
|
-
* poll that outlives the token passes the new one on. Best-effort, never
|
|
15
|
-
* throws.
|
|
16
|
-
*/
|
|
17
|
-
updateAccessToken(accessToken: string): void;
|
|
18
|
-
}
|
|
19
|
-
export interface RealtimeSubscribeOptions {
|
|
20
|
-
/** Supabase JWT (AuthContext.accessToken) — authorises the socket for RLS. */
|
|
21
|
-
accessToken: string;
|
|
22
|
-
debug?: boolean;
|
|
23
|
-
env: DcdEnvName;
|
|
24
|
-
/** Stderr-safe logger; stdout is reserved by some callers (MCP). */
|
|
25
|
-
log?: (message: string) => void;
|
|
26
|
-
/** Fired when a result row for this upload changes. */
|
|
27
|
-
onChange: () => void;
|
|
28
|
-
/** Fired whenever the connection state flips (subscribed ↔ disconnected). */
|
|
29
|
-
onConnectionChange?: (connected: boolean) => void;
|
|
30
|
-
orgId: string;
|
|
31
|
-
uploadId: string;
|
|
32
|
-
}
|
|
33
|
-
export declare class RealtimeResultsGateway {
|
|
34
|
-
/**
|
|
35
|
-
* Open a realtime subscription to `results` changes for the given upload.
|
|
36
|
-
* Construction never throws — on any failure the caller simply keeps polling.
|
|
37
|
-
*/
|
|
38
|
-
static subscribe(options: RealtimeSubscribeOptions): RealtimeResultsSubscription;
|
|
39
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Supabase Realtime subscription to test-result status changes.
|
|
3
|
-
*
|
|
4
|
-
* This is a *latency optimisation* layered on top of HTTP polling, not a
|
|
5
|
-
* replacement for it. A logged-in (bearer) user's JWT authorises a
|
|
6
|
-
* `postgres_changes` subscription on the `results` table (RLS scopes rows to
|
|
7
|
-
* the user's org via `app_metadata.org_ids`). Each relevant change fires
|
|
8
|
-
* `onChange`, which the polling loop uses to fetch immediately instead of
|
|
9
|
-
* waiting out the full backstop interval.
|
|
10
|
-
*
|
|
11
|
-
* We deliberately only read the `new` row's `test_upload_id` — Postgres always
|
|
12
|
-
* ships the full new tuple on INSERT/UPDATE regardless of REPLICA IDENTITY, so
|
|
13
|
-
* no DB change is required. Mirrors the frontend pattern in
|
|
14
|
-
* dcd/frontend/app/stores/Results.store.ts.
|
|
15
|
-
*/
|
|
16
|
-
import { createClient, REALTIME_SUBSCRIBE_STATES, } from '@supabase/supabase-js';
|
|
17
|
-
import { ENVIRONMENTS } from '../config/environments.js';
|
|
18
|
-
import { getSupabaseKey } from '../config/supabase-key.js';
|
|
19
|
-
export class RealtimeResultsGateway {
|
|
20
|
-
/**
|
|
21
|
-
* Open a realtime subscription to `results` changes for the given upload.
|
|
22
|
-
* Construction never throws — on any failure the caller simply keeps polling.
|
|
23
|
-
*/
|
|
24
|
-
static subscribe(options) {
|
|
25
|
-
const { accessToken, debug, env, log, onChange, onConnectionChange, orgId, uploadId } = options;
|
|
26
|
-
const dbg = (message) => {
|
|
27
|
-
if (debug && log)
|
|
28
|
-
log(`[DEBUG] [realtime] ${message}`);
|
|
29
|
-
};
|
|
30
|
-
let connected = false;
|
|
31
|
-
const setConnected = (next) => {
|
|
32
|
-
if (next === connected)
|
|
33
|
-
return;
|
|
34
|
-
connected = next;
|
|
35
|
-
onConnectionChange?.(next);
|
|
36
|
-
};
|
|
37
|
-
let client;
|
|
38
|
-
let channel;
|
|
39
|
-
let closed = false;
|
|
40
|
-
// The latest JWT, so a refresh that lands while the key is still being
|
|
41
|
-
// fetched is the one the socket joins with.
|
|
42
|
-
let token = accessToken;
|
|
43
|
-
// The publishable key comes from the API (dcd#1112), so the socket opens
|
|
44
|
-
// asynchronously. `subscribe` stays synchronous for the caller: until it
|
|
45
|
-
// connects, `isConnected` is false and the backstop poll covers the gap.
|
|
46
|
-
const ready = getSupabaseKey(env)
|
|
47
|
-
.then((supabaseKey) => {
|
|
48
|
-
if (closed)
|
|
49
|
-
return;
|
|
50
|
-
const sb = createClient(ENVIRONMENTS[env].supabase.url, supabaseKey, {
|
|
51
|
-
// Match SupabaseClientGateway / the frontend; no session persistence —
|
|
52
|
-
// we set the token explicitly below.
|
|
53
|
-
auth: { autoRefreshToken: false, persistSession: false },
|
|
54
|
-
realtime: { params: { eventsPerSecond: 10 } },
|
|
55
|
-
});
|
|
56
|
-
client = sb;
|
|
57
|
-
// Attach the user's JWT to the socket so RLS is enforced on the channel.
|
|
58
|
-
sb.realtime.setAuth(token);
|
|
59
|
-
channel = sb
|
|
60
|
-
.channel(`results-cli-${uploadId}`)
|
|
61
|
-
.on(
|
|
62
|
-
// The typings don't cover the postgres_changes overload cleanly.
|
|
63
|
-
'postgres_changes', {
|
|
64
|
-
event: '*',
|
|
65
|
-
schema: 'public',
|
|
66
|
-
table: 'results',
|
|
67
|
-
filter: `org_id=eq.${orgId}`,
|
|
68
|
-
}, (payload) => {
|
|
69
|
-
if (payload.new?.test_upload_id === uploadId) {
|
|
70
|
-
dbg(`change for upload ${uploadId}`);
|
|
71
|
-
onChange();
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
.subscribe((status) => {
|
|
75
|
-
if (status === REALTIME_SUBSCRIBE_STATES.SUBSCRIBED) {
|
|
76
|
-
dbg('subscribed');
|
|
77
|
-
setConnected(true);
|
|
78
|
-
}
|
|
79
|
-
else if (status === REALTIME_SUBSCRIBE_STATES.CHANNEL_ERROR ||
|
|
80
|
-
status === REALTIME_SUBSCRIBE_STATES.TIMED_OUT ||
|
|
81
|
-
status === REALTIME_SUBSCRIBE_STATES.CLOSED) {
|
|
82
|
-
// Don't try to recover — the backstop poll covers us. Surface in
|
|
83
|
-
// debug so a network-blocked websocket is diagnosable.
|
|
84
|
-
dbg(`channel ${status}; relying on backstop poll`);
|
|
85
|
-
setConnected(false);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
})
|
|
89
|
-
.catch((error) => {
|
|
90
|
-
dbg(`failed to subscribe: ${error instanceof Error ? error.message : String(error)}`);
|
|
91
|
-
// Best-effort cleanup of a half-built client, then degrade to polling.
|
|
92
|
-
try {
|
|
93
|
-
client?.realtime.disconnect();
|
|
94
|
-
}
|
|
95
|
-
catch {
|
|
96
|
-
/* ignore */
|
|
97
|
-
}
|
|
98
|
-
client = undefined;
|
|
99
|
-
channel = undefined;
|
|
100
|
-
});
|
|
101
|
-
return {
|
|
102
|
-
isConnected: () => connected,
|
|
103
|
-
async unsubscribe() {
|
|
104
|
-
closed = true;
|
|
105
|
-
setConnected(false);
|
|
106
|
-
await ready;
|
|
107
|
-
if (!client)
|
|
108
|
-
return;
|
|
109
|
-
try {
|
|
110
|
-
if (channel)
|
|
111
|
-
await client.removeChannel(channel);
|
|
112
|
-
await client.realtime.disconnect();
|
|
113
|
-
}
|
|
114
|
-
catch {
|
|
115
|
-
/* best effort — process is exiting anyway */
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
updateAccessToken(nextToken) {
|
|
119
|
-
token = nextToken;
|
|
120
|
-
// setAuth updates the join payload and pushes the token to joined
|
|
121
|
-
// channels. A failure only costs realtime; the backstop poll stays.
|
|
122
|
-
client?.realtime.setAuth(nextToken).catch((error) => {
|
|
123
|
-
dbg(`failed to update the socket's token: ${error instanceof Error ? error.message : String(error)}`);
|
|
124
|
-
});
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
}
|