qualty 0.1.15 → 0.1.16

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.
@@ -9,6 +9,36 @@ function safePathSegment(value, fallback) {
9
9
  return normalized || fallback;
10
10
  }
11
11
 
12
+ /**
13
+ * Rewrite a dashboard/production test URL to localhost for local CLI runs.
14
+ * Keeps pathname, search, and hash; swaps origin to http://localhost:<port>.
15
+ */
16
+ export function rewriteUrlForLocalRun(rawUrl, port) {
17
+ const portNum = Number(port);
18
+ if (!Number.isFinite(portNum) || portNum < 1 || portNum > 65535) {
19
+ return String(rawUrl || "").trim();
20
+ }
21
+ const trimmed = String(rawUrl || "").trim();
22
+ if (!trimmed) return trimmed;
23
+
24
+ let parsed;
25
+ try {
26
+ const withProtocol = /^https?:\/\//i.test(trimmed) ? trimmed : `https://${trimmed}`;
27
+ parsed = new URL(withProtocol);
28
+ } catch {
29
+ return trimmed;
30
+ }
31
+
32
+ const suffix = `${parsed.pathname}${parsed.search}${parsed.hash}`;
33
+ return `http://localhost:${portNum}${suffix}`;
34
+ }
35
+
36
+ function resolveLocalPort(rawPort, fallback = 3000) {
37
+ const portNum = Number(rawPort);
38
+ if (Number.isFinite(portNum) && portNum >= 1 && portNum <= 65535) return portNum;
39
+ return fallback;
40
+ }
41
+
12
42
  function localAuthStatePath({ orgId, projectId, profile }) {
13
43
  const orgSeg = safePathSegment(orgId || "default-org", "default-org");
14
44
  const projectSeg = safePathSegment(projectId || "default-project", "default-project");
@@ -177,6 +207,7 @@ async function preflightMissingLocalBindings({
177
207
  savedJobs,
178
208
  explicitAuthProfile,
179
209
  noAuthState,
210
+ localPort = 3000,
180
211
  }) {
181
212
  if (noAuthState) return;
182
213
  if (explicitAuthProfile) return;
@@ -195,14 +226,16 @@ async function preflightMissingLocalBindings({
195
226
  const entry = missingByProfile.get(profileName) || {
196
227
  localProfileName: profileName,
197
228
  projectId: String(job?.project_id || projectId || "").trim(),
198
- startUrl: String(job?.url || "").trim(),
229
+ startUrl: rewriteUrlForLocalRun(String(job?.url || "").trim(), localPort),
199
230
  tests: [],
200
231
  };
201
232
  entry.tests.push({
202
233
  id: String(job?.id || "").trim(),
203
234
  name: String(job?.name || job?.id || "Unnamed test").trim(),
204
235
  });
205
- if (!entry.startUrl) entry.startUrl = String(job?.url || "").trim();
236
+ if (!entry.startUrl) {
237
+ entry.startUrl = rewriteUrlForLocalRun(String(job?.url || "").trim(), localPort);
238
+ }
206
239
  missingByProfile.set(profileName, entry);
207
240
  }
208
241
  if (missingByProfile.size === 0) return;
@@ -1016,7 +1049,14 @@ export async function runLocalExecution({
1016
1049
  body: { device },
1017
1050
  });
1018
1051
 
1019
- const url = claim.url;
1052
+ const originalUrl = String(claim.url || "").trim();
1053
+ const localPort = resolveLocalPort(claim.local_port);
1054
+ const url = rewriteUrlForLocalRun(originalUrl, localPort);
1055
+ if (url !== originalUrl) {
1056
+ // eslint-disable-next-line no-console
1057
+ console.log(`[qualty] Local URL rewrite: ${originalUrl} -> ${url}`);
1058
+ }
1059
+ claim.url = url;
1020
1060
  const viewport = claim.viewport || { width: 1440, height: 900 };
1021
1061
  const steps = Array.isArray(claim.steps) ? claim.steps : [];
1022
1062
  const totalSteps = claim.total_steps || steps.length;
@@ -1279,6 +1319,21 @@ export async function runLocalExecution({
1279
1319
  return { success: runSuccess, stepsJson, error: runError };
1280
1320
  }
1281
1321
 
1322
+ async function fetchProjectLocalPort({ apiRequest, apiUrl, token, orgId, projectId }) {
1323
+ if (!projectId) return 3000;
1324
+ try {
1325
+ const project = await apiRequest({
1326
+ apiUrl,
1327
+ token,
1328
+ orgId,
1329
+ path: `/api/v1/projects/${encodeURIComponent(String(projectId))}`,
1330
+ });
1331
+ return resolveLocalPort(project?.localhost?.port);
1332
+ } catch {
1333
+ return 3000;
1334
+ }
1335
+ }
1336
+
1282
1337
  export async function runLocalCi({
1283
1338
  apiUrl,
1284
1339
  token,
@@ -1301,6 +1356,8 @@ export async function runLocalCi({
1301
1356
  throw new Error("No saved tests matched your selector.");
1302
1357
  }
1303
1358
 
1359
+ const localPort = await fetchProjectLocalPort({ apiRequest, apiUrl, token, orgId, projectId });
1360
+
1304
1361
  const startResp = await apiRequest({
1305
1362
  apiUrl,
1306
1363
  token,
@@ -1328,6 +1385,7 @@ export async function runLocalCi({
1328
1385
  savedJobs,
1329
1386
  explicitAuthProfile: String(authProfile || "").trim(),
1330
1387
  noAuthState: Boolean(noAuthState),
1388
+ localPort,
1331
1389
  });
1332
1390
 
1333
1391
  const concurrency = Math.max(1, Number(localConcurrency) || 4);
package/bin/qualty.js CHANGED
@@ -6,11 +6,12 @@ import { homedir, hostname } from "node:os";
6
6
  import { join } from "node:path";
7
7
  import { createInterface } from "node:readline/promises";
8
8
  import process from "node:process";
9
- import { runLocalCi } from "./local-runner.js";
9
+ import { rewriteUrlForLocalRun, runLocalCi } from "./local-runner.js";
10
10
 
11
11
  /** CLI backend URL is fixed by Qualty distribution. */
12
12
  const DEFAULT_QUALTY_API_URL = "https://qualty-api-production.up.railway.app";
13
13
 
14
+
14
15
  const QUALTY_CONFIG_DIR = join(homedir(), ".config", "qualty");
15
16
  const QUALTY_CONFIG_PATH = join(QUALTY_CONFIG_DIR, "config.json");
16
17
  const QUALTY_SHARED_CREDS_DIR = join(homedir(), ".qualty");
@@ -1426,6 +1427,7 @@ async function runAuthSetup(args) {
1426
1427
  id: String(p?.id || "").trim(),
1427
1428
  name: String(p?.name || "").trim() || "Unnamed project",
1428
1429
  url: String(p?.url || "").trim(),
1430
+ localPort: Number(p?.localhost?.port) || 3000,
1429
1431
  }))
1430
1432
  .filter((p) => p.id);
1431
1433
  if (projects.length === 0) {
@@ -1537,7 +1539,15 @@ async function runAuthSetup(args) {
1537
1539
  }
1538
1540
  const context = await browser.newContext();
1539
1541
  const page = await context.newPage();
1540
- const startUrl = project.url || "about:blank";
1542
+ const rawStartUrl = project.url || "about:blank";
1543
+ const startUrl =
1544
+ rawStartUrl === "about:blank"
1545
+ ? rawStartUrl
1546
+ : rewriteUrlForLocalRun(rawStartUrl, project.localPort);
1547
+ if (startUrl !== rawStartUrl) {
1548
+ // eslint-disable-next-line no-console
1549
+ console.log(`[qualty][auth] Local URL rewrite: ${rawStartUrl} -> ${startUrl}`);
1550
+ }
1541
1551
  await page.goto(startUrl, { waitUntil: "domcontentloaded", timeout: 60000 }).catch(() => {});
1542
1552
  // eslint-disable-next-line no-console
1543
1553
  console.log(`[qualty][auth] Browser opened for project "${project.name}".`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qualty",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "Qualty CLI for localhost and CI test runs",
5
5
  "bin": {
6
6
  "qualty": "bin/qualty.js"