lazyscout 0.2.0 → 0.3.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/README.md +90 -89
- package/dist/index.js +550 -69
- package/dist/web/assets/index-2zh7L5nF.js +39 -0
- package/dist/web/assets/index-mxlNJ1dB.css +1 -0
- package/dist/web/index.html +2 -2
- package/package.json +62 -62
- package/dist/web/assets/index-CEFa_ZLm.js +0 -39
- package/dist/web/assets/index-Chzk3JL8.css +0 -1
package/dist/index.js
CHANGED
|
@@ -592,31 +592,31 @@ function toExploreIssue(url, error) {
|
|
|
592
592
|
const raw = error instanceof Error ? error.message : String(error);
|
|
593
593
|
const text = raw.toLowerCase();
|
|
594
594
|
let code = "navigation-failed";
|
|
595
|
-
let message = "\
|
|
595
|
+
let message = "could not open the page \u2014 navigation failed";
|
|
596
596
|
if (text.includes("err_connection_refused") || text.includes("econnrefused")) {
|
|
597
597
|
code = "connection-refused";
|
|
598
|
-
message = "
|
|
598
|
+
message = "could not connect \u2014 connection refused";
|
|
599
599
|
} else if (text.includes("err_name_not_resolved") || text.includes("enotfound")) {
|
|
600
600
|
code = "dns-error";
|
|
601
|
-
message = "
|
|
601
|
+
message = "could not resolve domain name \u2014 check the URL";
|
|
602
602
|
} else if (text.includes("err_cert") || text.includes("ssl") || text.includes("err_bad_ssl")) {
|
|
603
603
|
code = "ssl-error";
|
|
604
|
-
message = "
|
|
604
|
+
message = "the SSL certificate of the website is invalid";
|
|
605
605
|
} else if (text.includes("timeout") || text.includes("timed out")) {
|
|
606
606
|
code = "timeout";
|
|
607
|
-
message = "\
|
|
607
|
+
message = "could not open the page \u2014 timeout";
|
|
608
608
|
} else if (text.includes("crash")) {
|
|
609
609
|
code = "page-crash";
|
|
610
|
-
message = "
|
|
610
|
+
message = "could not open the page \u2014 page crash";
|
|
611
611
|
} else if (text.includes("err_connection_timed_out")) {
|
|
612
612
|
code = "timeout";
|
|
613
|
-
message = "\
|
|
613
|
+
message = "could not connect \u2014 connection timeout";
|
|
614
614
|
} else if (text.includes("err_aborted")) {
|
|
615
615
|
code = "navigation-failed";
|
|
616
|
-
message = "\
|
|
616
|
+
message = "could not open the page \u2014 navigation aborted";
|
|
617
617
|
} else if (text.includes("executable doesn") || text.includes("browsertype.launch")) {
|
|
618
618
|
code = "browser-error";
|
|
619
|
-
message = '
|
|
619
|
+
message = 'could not open the browser \u2014 run "npx playwright install chromium" first';
|
|
620
620
|
}
|
|
621
621
|
return { url, code, message };
|
|
622
622
|
}
|
|
@@ -652,7 +652,7 @@ async function launchBrowser() {
|
|
|
652
652
|
void error;
|
|
653
653
|
}
|
|
654
654
|
}
|
|
655
|
-
throw new ExplorerError("browser-error",
|
|
655
|
+
throw new ExplorerError("browser-error", `unable to launch a browser (tried: ${failures.join(", ")})`, 'Please install Google Chrome or Microsoft Edge or run "npx playwright install chromium" and try again');
|
|
656
656
|
}
|
|
657
657
|
|
|
658
658
|
// ../../packages/explorer/dist/exploreWebsite.js
|
|
@@ -844,7 +844,7 @@ async function visitPage(page, item, config2) {
|
|
|
844
844
|
issue: {
|
|
845
845
|
url: item.url,
|
|
846
846
|
code: "cloudflare",
|
|
847
|
-
message: "
|
|
847
|
+
message: "Cloudflare/browser challenge \u2014 self check the website in a browser and try again"
|
|
848
848
|
}
|
|
849
849
|
};
|
|
850
850
|
}
|
|
@@ -1330,7 +1330,7 @@ function exportTestCasesToCsv(testCases, testData = []) {
|
|
|
1330
1330
|
|
|
1331
1331
|
// src/commands/scan.ts
|
|
1332
1332
|
async function runScan(options) {
|
|
1333
|
-
console.log(
|
|
1333
|
+
console.log(`checking scan ${redactUrl(options.url)} ...`);
|
|
1334
1334
|
const result = await exploreWebsite(options.url, {
|
|
1335
1335
|
...options.maxPages !== void 0 ? { maxPages: options.maxPages } : {},
|
|
1336
1336
|
...options.maxDepth !== void 0 ? { maxDepth: options.maxDepth } : {}
|
|
@@ -1345,25 +1345,25 @@ async function runScan(options) {
|
|
|
1345
1345
|
}
|
|
1346
1346
|
console.log(
|
|
1347
1347
|
`
|
|
1348
|
-
|
|
1348
|
+
Summary: ${result.pages.length} pages \xB7 ${testCases.length} test cases \xB7 ${testData.length} test data \xB7 ${(result.stats.durationMs / 1e3).toFixed(1)} seconds \xB7 Using ${result.stats.browser}`
|
|
1349
1349
|
);
|
|
1350
1350
|
if (result.pages.length === 0) {
|
|
1351
|
-
console.error("
|
|
1351
|
+
console.error("Failed to open the website, no data to save");
|
|
1352
1352
|
process.exitCode = 1;
|
|
1353
1353
|
return;
|
|
1354
1354
|
}
|
|
1355
1355
|
const csvPath = resolve(options.csvPath ?? "lazyscout-testcases.csv");
|
|
1356
1356
|
await writeFile(csvPath, exportTestCasesToCsv(testCases, testData), "utf8");
|
|
1357
|
-
console.log(
|
|
1357
|
+
console.log(`Saved CSV: ${csvPath}`);
|
|
1358
1358
|
if (options.jsonPath) {
|
|
1359
1359
|
const jsonPath = resolve(options.jsonPath);
|
|
1360
1360
|
await writeFile(jsonPath, JSON.stringify({ ...result, testCases, testData }, null, 2), "utf8");
|
|
1361
|
-
console.log(
|
|
1361
|
+
console.log(`Saved JSON: ${jsonPath}`);
|
|
1362
1362
|
}
|
|
1363
1363
|
}
|
|
1364
1364
|
|
|
1365
1365
|
// src/commands/serve.ts
|
|
1366
|
-
import { dirname as
|
|
1366
|
+
import { dirname as dirname3, join as join3 } from "node:path";
|
|
1367
1367
|
import { fileURLToPath } from "node:url";
|
|
1368
1368
|
|
|
1369
1369
|
// ../server/dist/app.js
|
|
@@ -1539,13 +1539,287 @@ function registerExportCsvRoute(app) {
|
|
|
1539
1539
|
});
|
|
1540
1540
|
}
|
|
1541
1541
|
|
|
1542
|
+
// ../server/dist/workspace.js
|
|
1543
|
+
import { execFile } from "node:child_process";
|
|
1544
|
+
import { randomUUID } from "node:crypto";
|
|
1545
|
+
import { homedir, platform } from "node:os";
|
|
1546
|
+
import { basename, dirname, extname, isAbsolute, join, relative, resolve as resolve2 } from "node:path";
|
|
1547
|
+
import { mkdir, readFile, readdir, rename, rm, stat, writeFile as writeFile2 } from "node:fs/promises";
|
|
1548
|
+
import { promisify } from "node:util";
|
|
1549
|
+
var execFileAsync = promisify(execFile);
|
|
1550
|
+
var PROJECT_ID = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/;
|
|
1551
|
+
var FILE_NAME = /^[^\\/:*?"<>|]{1,160}$/;
|
|
1552
|
+
var mutationQueues = /* @__PURE__ */ new Map();
|
|
1553
|
+
function defaultWorkspaceRoot() {
|
|
1554
|
+
return join(homedir(), "LazyScout");
|
|
1555
|
+
}
|
|
1556
|
+
function resolveWorkspaceRoot(value) {
|
|
1557
|
+
return resolve2(value?.trim() || process.env.LAZYSCOUT_WORKSPACE || defaultWorkspaceRoot());
|
|
1558
|
+
}
|
|
1559
|
+
async function ensureWorkspace(root) {
|
|
1560
|
+
await Promise.all([
|
|
1561
|
+
mkdir(join(root, "projects"), { recursive: true }),
|
|
1562
|
+
mkdir(join(root, "backups"), { recursive: true })
|
|
1563
|
+
]);
|
|
1564
|
+
const settingsPath = join(root, "settings.json");
|
|
1565
|
+
try {
|
|
1566
|
+
await stat(settingsPath);
|
|
1567
|
+
} catch {
|
|
1568
|
+
await writeJson(settingsPath, { version: 1, workspaceRoot: root, createdAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
async function listProjects(root) {
|
|
1572
|
+
await ensureWorkspace(root);
|
|
1573
|
+
const entries = await readdir(join(root, "projects"), { withFileTypes: true });
|
|
1574
|
+
const projects = await Promise.all(entries.filter((entry) => entry.isDirectory() && PROJECT_ID.test(entry.name)).map((entry) => readProject(root, entry.name)));
|
|
1575
|
+
return projects.filter((project) => Boolean(project)).sort((left, right) => right.updatedAt.localeCompare(left.updatedAt));
|
|
1576
|
+
}
|
|
1577
|
+
async function saveProject(root, project) {
|
|
1578
|
+
return enqueueMutation(`project:${project.id}`, async () => {
|
|
1579
|
+
const directory = await ensureProject(root, project.id);
|
|
1580
|
+
const normalized = normalizeResult(project.result);
|
|
1581
|
+
const { testCases, ...result } = normalized;
|
|
1582
|
+
const testData = normalized.testData;
|
|
1583
|
+
await Promise.all([
|
|
1584
|
+
writeJson(join(directory, "project.json"), { ...project, result }),
|
|
1585
|
+
writeJson(join(directory, "test-cases.json"), testCases),
|
|
1586
|
+
writeFileAtomic(join(directory, "test-cases.csv"), exportTestCasesToCsv(testCases, testData)),
|
|
1587
|
+
writeFileAtomic(join(directory, "test-data.csv"), testDataCsv(testData))
|
|
1588
|
+
]);
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
async function deleteProject(root, projectId) {
|
|
1592
|
+
return enqueueMutation(`project:${projectId}`, async () => {
|
|
1593
|
+
const source = projectDirectory(root, projectId);
|
|
1594
|
+
try {
|
|
1595
|
+
await stat(source);
|
|
1596
|
+
} catch {
|
|
1597
|
+
return;
|
|
1598
|
+
}
|
|
1599
|
+
await ensureWorkspace(root);
|
|
1600
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
1601
|
+
await rename(source, join(root, "backups", `${projectId}-${timestamp}`));
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
async function readScreenshots(root, projectId) {
|
|
1605
|
+
const directory = await ensureProject(root, projectId);
|
|
1606
|
+
return readJson(join(directory, "screenshots", "index.json"), []);
|
|
1607
|
+
}
|
|
1608
|
+
async function saveScreenshot(root, projectId, screenshot) {
|
|
1609
|
+
return enqueueMutation(`screenshots:${projectId}`, async () => {
|
|
1610
|
+
const directory = join(await ensureProject(root, projectId), "screenshots");
|
|
1611
|
+
const match = screenshot.dataUrl.match(/^data:image\/(png|jpeg);base64,([a-zA-Z0-9+/=]+)$/);
|
|
1612
|
+
if (!match)
|
|
1613
|
+
throw new Error("Screenshot must be a PNG or JPEG data URL");
|
|
1614
|
+
const image = Buffer.from(match[2], "base64");
|
|
1615
|
+
if (image.byteLength > 6 * 1024 * 1024)
|
|
1616
|
+
throw new Error("Screenshot exceeds the 6 MB limit");
|
|
1617
|
+
const extension = match[1] === "jpeg" ? ".jpg" : ".png";
|
|
1618
|
+
const requested = safeFileName(screenshot.name, `screenshot-${Date.now()}${extension}`);
|
|
1619
|
+
const name = extname(requested) ? `${basename(requested, extname(requested))}${extension}` : `${requested}${extension}`;
|
|
1620
|
+
await writeFileAtomic(join(directory, name), image);
|
|
1621
|
+
const current = await readScreenshots(root, projectId);
|
|
1622
|
+
const stored = { ...screenshot, name, dataUrl: screenshotUrl(projectId, name) };
|
|
1623
|
+
const next = [stored, ...current.filter((item) => item.name !== name)].slice(0, 50);
|
|
1624
|
+
await writeJson(join(directory, "index.json"), next);
|
|
1625
|
+
return stored;
|
|
1626
|
+
});
|
|
1627
|
+
}
|
|
1628
|
+
async function deleteScreenshot(root, projectId, name) {
|
|
1629
|
+
const safeName = assertFileName(name);
|
|
1630
|
+
const directory = join(await ensureProject(root, projectId), "screenshots");
|
|
1631
|
+
await rm(join(directory, safeName), { force: true });
|
|
1632
|
+
const current = await readScreenshots(root, projectId);
|
|
1633
|
+
await writeJson(join(directory, "index.json"), current.filter((item) => item.name !== safeName));
|
|
1634
|
+
}
|
|
1635
|
+
async function screenshotFile(root, projectId, name) {
|
|
1636
|
+
return readFile(join(await ensureProject(root, projectId), "screenshots", assertFileName(name)));
|
|
1637
|
+
}
|
|
1638
|
+
async function listBugReports(root, projectId) {
|
|
1639
|
+
const directory = join(await ensureProject(root, projectId), "bugs");
|
|
1640
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
1641
|
+
const reports = await Promise.all(entries.filter((entry) => entry.isFile() && entry.name.endsWith(".json") && entry.name !== "index.json").map((entry) => readJson(join(directory, entry.name), null)));
|
|
1642
|
+
return reports.filter((report) => Boolean(report));
|
|
1643
|
+
}
|
|
1644
|
+
async function saveBugReport(root, projectId, report) {
|
|
1645
|
+
const directory = join(await ensureProject(root, projectId), "bugs");
|
|
1646
|
+
await writeJson(join(directory, `${safeFileName(report.id, `BUG-${Date.now()}`)}.json`), report);
|
|
1647
|
+
}
|
|
1648
|
+
async function deleteBugReport(root, projectId, bugId) {
|
|
1649
|
+
const directory = join(await ensureProject(root, projectId), "bugs");
|
|
1650
|
+
await rm(join(directory, `${safeFileName(bugId, "bug")}.json`), { force: true });
|
|
1651
|
+
}
|
|
1652
|
+
async function readAutomation(root, projectId) {
|
|
1653
|
+
const directory = join(await ensureProject(root, projectId), "automation");
|
|
1654
|
+
const index = await readJson(join(directory, "index.json"), {});
|
|
1655
|
+
const entries = await Promise.all(Object.entries(index).map(async ([key, name]) => {
|
|
1656
|
+
try {
|
|
1657
|
+
return [key, await readFile(join(directory, assertFileName(name)), "utf8")];
|
|
1658
|
+
} catch {
|
|
1659
|
+
return void 0;
|
|
1660
|
+
}
|
|
1661
|
+
}));
|
|
1662
|
+
return Object.fromEntries(entries.filter((entry) => Boolean(entry)));
|
|
1663
|
+
}
|
|
1664
|
+
async function saveAutomation(root, projectId, overrides) {
|
|
1665
|
+
const directory = join(await ensureProject(root, projectId), "automation");
|
|
1666
|
+
const previous = await readJson(join(directory, "index.json"), {});
|
|
1667
|
+
const next = {};
|
|
1668
|
+
for (const [key, source] of Object.entries(overrides)) {
|
|
1669
|
+
if (typeof source !== "string" || source.length > 2e5)
|
|
1670
|
+
throw new Error("Automation source exceeds the limit");
|
|
1671
|
+
const [framework, caseId] = key.split(":", 2);
|
|
1672
|
+
if (framework !== "playwright" && framework !== "cypress" || !caseId)
|
|
1673
|
+
continue;
|
|
1674
|
+
const extension = framework === "playwright" ? ".spec.ts" : ".cy.ts";
|
|
1675
|
+
const name = `${framework}-${safeFileName(caseId, "test-case")}${extension}`;
|
|
1676
|
+
next[key] = name;
|
|
1677
|
+
await writeFileAtomic(join(directory, name), source);
|
|
1678
|
+
}
|
|
1679
|
+
for (const name of Object.values(previous))
|
|
1680
|
+
if (!Object.values(next).includes(name))
|
|
1681
|
+
await rm(join(directory, assertFileName(name)), { force: true });
|
|
1682
|
+
await writeJson(join(directory, "index.json"), next);
|
|
1683
|
+
}
|
|
1684
|
+
async function saveRunLog(root, projectId, testCaseId, status, logs) {
|
|
1685
|
+
const directory = join(await ensureProject(root, projectId), "logs");
|
|
1686
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
1687
|
+
const name = `${timestamp}-${safeFileName(testCaseId, "test-case")}.json`;
|
|
1688
|
+
await writeJson(join(directory, name), { testCaseId, status, createdAt: (/* @__PURE__ */ new Date()).toISOString(), logs });
|
|
1689
|
+
}
|
|
1690
|
+
async function saveReport(root, projectId, name, html) {
|
|
1691
|
+
if (typeof html !== "string" || html.length > 2e6)
|
|
1692
|
+
throw new Error("Report exceeds the 2 MB limit");
|
|
1693
|
+
const directory = join(await ensureProject(root, projectId), "reports");
|
|
1694
|
+
const fileName = `${safeFileName(name, `quality-report-${Date.now()}.html`).replace(/\.[^.]+$/, "")}.html`;
|
|
1695
|
+
await writeFileAtomic(join(directory, fileName), html);
|
|
1696
|
+
return fileName;
|
|
1697
|
+
}
|
|
1698
|
+
async function openWorkspace(root) {
|
|
1699
|
+
await ensureWorkspace(root);
|
|
1700
|
+
if (platform() === "win32")
|
|
1701
|
+
await execFileAsync("explorer.exe", [root], { windowsHide: true });
|
|
1702
|
+
else if (platform() === "darwin")
|
|
1703
|
+
await execFileAsync("open", [root]);
|
|
1704
|
+
else
|
|
1705
|
+
await execFileAsync("xdg-open", [root]);
|
|
1706
|
+
}
|
|
1707
|
+
async function readProject(root, projectId) {
|
|
1708
|
+
try {
|
|
1709
|
+
const directory = projectDirectory(root, projectId);
|
|
1710
|
+
const project = await readJson(join(directory, "project.json"), void 0);
|
|
1711
|
+
if (!project)
|
|
1712
|
+
return void 0;
|
|
1713
|
+
const testCases = await readJson(join(directory, "test-cases.json"), []);
|
|
1714
|
+
return { ...project, result: normalizeResult({ ...project.result, testCases }) };
|
|
1715
|
+
} catch {
|
|
1716
|
+
return void 0;
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
async function ensureProject(root, projectId) {
|
|
1720
|
+
await ensureWorkspace(root);
|
|
1721
|
+
const directory = projectDirectory(root, projectId);
|
|
1722
|
+
await Promise.all(["automation", "screenshots", "bugs", "reports", "logs"].map((name) => mkdir(join(directory, name), { recursive: true })));
|
|
1723
|
+
return directory;
|
|
1724
|
+
}
|
|
1725
|
+
function projectDirectory(root, projectId) {
|
|
1726
|
+
if (!PROJECT_ID.test(projectId))
|
|
1727
|
+
throw new Error("Invalid project ID");
|
|
1728
|
+
return containedPath(join(root, "projects"), projectId);
|
|
1729
|
+
}
|
|
1730
|
+
function containedPath(root, value) {
|
|
1731
|
+
const target = resolve2(root, value);
|
|
1732
|
+
const relation = relative(resolve2(root), target);
|
|
1733
|
+
if (!relation || relation.startsWith("..") || isAbsolute(relation))
|
|
1734
|
+
throw new Error("Path is outside the workspace");
|
|
1735
|
+
return target;
|
|
1736
|
+
}
|
|
1737
|
+
function assertFileName(value) {
|
|
1738
|
+
if (!FILE_NAME.test(value) || value === "." || value === "..")
|
|
1739
|
+
throw new Error("Invalid file name");
|
|
1740
|
+
return value;
|
|
1741
|
+
}
|
|
1742
|
+
function safeFileName(value, fallback) {
|
|
1743
|
+
const safe = basename(value).replace(/[^\p{L}\p{N}._-]+/gu, "-").replace(/^[-.]+|[-.]+$/g, "").slice(0, 120);
|
|
1744
|
+
return safe || fallback;
|
|
1745
|
+
}
|
|
1746
|
+
function screenshotUrl(projectId, name) {
|
|
1747
|
+
return `/api/workspace/projects/${encodeURIComponent(projectId)}/screenshots/${encodeURIComponent(name)}`;
|
|
1748
|
+
}
|
|
1749
|
+
async function readJson(path, fallback) {
|
|
1750
|
+
try {
|
|
1751
|
+
return JSON.parse(await readFile(path, "utf8"));
|
|
1752
|
+
} catch {
|
|
1753
|
+
return fallback;
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
async function writeJson(path, value) {
|
|
1757
|
+
await writeFileAtomic(path, `${JSON.stringify(value, null, 2)}
|
|
1758
|
+
`);
|
|
1759
|
+
}
|
|
1760
|
+
async function writeFileAtomic(path, value) {
|
|
1761
|
+
await mkdir(dirname(path), { recursive: true });
|
|
1762
|
+
const temporary = `${path}.${process.pid}.${randomUUID()}.tmp`;
|
|
1763
|
+
await writeFile2(temporary, value);
|
|
1764
|
+
await rm(path, { force: true });
|
|
1765
|
+
await rename(temporary, path);
|
|
1766
|
+
}
|
|
1767
|
+
function testDataCsv(rows) {
|
|
1768
|
+
const toRow2 = (values) => values.map(escapeCsvValue).join(",");
|
|
1769
|
+
return UTF8_BOM + [
|
|
1770
|
+
toRow2([...TEST_DATA_CSV_COLUMNS]),
|
|
1771
|
+
...rows.map((row) => toRow2([
|
|
1772
|
+
row.id,
|
|
1773
|
+
row.module,
|
|
1774
|
+
row.field,
|
|
1775
|
+
row.inputType,
|
|
1776
|
+
row.required ? "yes" : "no",
|
|
1777
|
+
row.validValue,
|
|
1778
|
+
row.invalidValue,
|
|
1779
|
+
row.note ?? "",
|
|
1780
|
+
row.sourceUrl
|
|
1781
|
+
]))
|
|
1782
|
+
].join("\r\n") + "\r\n";
|
|
1783
|
+
}
|
|
1784
|
+
function normalizeResult(value) {
|
|
1785
|
+
const actionGraph = value?.actionGraph;
|
|
1786
|
+
return {
|
|
1787
|
+
startUrl: value?.startUrl ?? "",
|
|
1788
|
+
origin: value?.origin ?? "Manual test suite",
|
|
1789
|
+
pages: Array.isArray(value?.pages) ? value.pages : [],
|
|
1790
|
+
testCases: Array.isArray(value?.testCases) ? value.testCases : [],
|
|
1791
|
+
testData: Array.isArray(value?.testData) ? value.testData : [],
|
|
1792
|
+
issues: Array.isArray(value?.issues) ? value.issues : [],
|
|
1793
|
+
stats: value?.stats ?? { pagesVisited: 0, urlsSkipped: 0, durationMs: 0, limitReached: "none" },
|
|
1794
|
+
actionGraph: {
|
|
1795
|
+
states: Array.isArray(actionGraph?.states) ? actionGraph.states : [],
|
|
1796
|
+
edges: Array.isArray(actionGraph?.edges) ? actionGraph.edges : [],
|
|
1797
|
+
visitedStateIds: Array.isArray(actionGraph?.visitedStateIds) ? actionGraph.visitedStateIds : [],
|
|
1798
|
+
visitedActionKeys: Array.isArray(actionGraph?.visitedActionKeys) ? actionGraph.visitedActionKeys : [],
|
|
1799
|
+
failedActionKeys: Array.isArray(actionGraph?.failedActionKeys) ? actionGraph.failedActionKeys : [],
|
|
1800
|
+
blockedActionKeys: Array.isArray(actionGraph?.blockedActionKeys) ? actionGraph.blockedActionKeys : []
|
|
1801
|
+
},
|
|
1802
|
+
runEvents: Array.isArray(value?.runEvents) ? value.runEvents : [],
|
|
1803
|
+
apiChecks: Array.isArray(value?.apiChecks) ? value.apiChecks : []
|
|
1804
|
+
};
|
|
1805
|
+
}
|
|
1806
|
+
function enqueueMutation(key, action) {
|
|
1807
|
+
const previous = mutationQueues.get(key) ?? Promise.resolve();
|
|
1808
|
+
const next = previous.catch(() => void 0).then(action);
|
|
1809
|
+
mutationQueues.set(key, next);
|
|
1810
|
+
return next.finally(() => {
|
|
1811
|
+
if (mutationQueues.get(key) === next)
|
|
1812
|
+
mutationQueues.delete(key);
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1542
1816
|
// ../server/dist/routes/automationRun.js
|
|
1543
1817
|
var MAX_STEPS = 100;
|
|
1544
1818
|
var MAX_LOGS = 250;
|
|
1545
1819
|
var MAX_SOURCE_LENGTH = 2e5;
|
|
1546
1820
|
var STEP_TIMEOUT_MS = 2e4;
|
|
1547
1821
|
var activeRuns = /* @__PURE__ */ new Map();
|
|
1548
|
-
function registerAutomationRunRoute(app) {
|
|
1822
|
+
function registerAutomationRunRoute(app, workspaceRoot) {
|
|
1549
1823
|
app.post("/api/automation/stop", async (request, reply) => {
|
|
1550
1824
|
const runId = request.body?.runId;
|
|
1551
1825
|
if (!runId)
|
|
@@ -1589,22 +1863,30 @@ function registerAutomationRunRoute(app) {
|
|
|
1589
1863
|
...durationMs === void 0 ? {} : { durationMs }
|
|
1590
1864
|
});
|
|
1591
1865
|
};
|
|
1866
|
+
const persistLog = async (runStatus) => {
|
|
1867
|
+
if (!body.projectId)
|
|
1868
|
+
return;
|
|
1869
|
+
await saveRunLog(workspaceRoot, body.projectId, testCase.id, runStatus, logs).catch((error) => addLog("warn", `Could not save run log: ${error instanceof Error ? error.message : String(error)}`));
|
|
1870
|
+
};
|
|
1592
1871
|
const started = Date.now();
|
|
1593
1872
|
addLog("info", "$ lazyscout test --case " + testCase.id);
|
|
1594
1873
|
addLog("info", "Starting Playwright runner: " + testCase.title);
|
|
1595
1874
|
addLog("info", "Test budget: " + MAX_STEPS + " steps \xB7 " + STEP_TIMEOUT_MS / 1e3 + "s per action \xB7 " + MAX_LOGS + " log lines");
|
|
1596
1875
|
if (testCase.automationStatus === "manual") {
|
|
1597
1876
|
addLog("warn", "Blocked: this case is marked manual and cannot be automated");
|
|
1877
|
+
await persistLog("blocked");
|
|
1598
1878
|
return reply.send({ status: "blocked", framework, logs });
|
|
1599
1879
|
}
|
|
1600
1880
|
if (framework === "cypress") {
|
|
1601
1881
|
addLog("warn", "Cypress code generation is available; local runner uses Playwright only.");
|
|
1882
|
+
await persistLog("unsupported");
|
|
1602
1883
|
return reply.send({ status: "unsupported", framework, logs });
|
|
1603
1884
|
}
|
|
1604
1885
|
const active = { stopped: false };
|
|
1605
1886
|
activeRuns.set(runId, active);
|
|
1606
1887
|
let browser;
|
|
1607
1888
|
let page;
|
|
1889
|
+
const capturedScreenshots = [];
|
|
1608
1890
|
try {
|
|
1609
1891
|
const launched = await launchBrowser();
|
|
1610
1892
|
browser = launched.browser;
|
|
@@ -1616,7 +1898,7 @@ function registerAutomationRunRoute(app) {
|
|
|
1616
1898
|
page = await context.newPage();
|
|
1617
1899
|
if (typeof body.code === "string" && body.code.trim()) {
|
|
1618
1900
|
addLog("info", "Running edited automation source");
|
|
1619
|
-
await executeEditedCode(page, body.code, addLog, secrets);
|
|
1901
|
+
await executeEditedCode(page, body.code, testCase.id, capturedScreenshots, addLog, secrets);
|
|
1620
1902
|
if (active.stopped)
|
|
1621
1903
|
throw new Error("Run stopped by user");
|
|
1622
1904
|
addLog("pass", "\u2713 edited source completed");
|
|
@@ -1631,25 +1913,32 @@ function registerAutomationRunRoute(app) {
|
|
|
1631
1913
|
addLog("pass", `\u2713 ${step.type}`, Date.now() - stepStarted);
|
|
1632
1914
|
}
|
|
1633
1915
|
addLog("pass", `Completed ${testCase.id}`, Date.now() - started);
|
|
1916
|
+
const screenshots = withScreenshotStatus(capturedScreenshots, "passed");
|
|
1917
|
+
await persistLog("passed");
|
|
1634
1918
|
return reply.send({
|
|
1635
1919
|
status: "passed",
|
|
1636
1920
|
framework,
|
|
1637
1921
|
logs,
|
|
1638
|
-
|
|
1922
|
+
screenshots,
|
|
1923
|
+
screenshot: screenshots.at(-1)
|
|
1639
1924
|
});
|
|
1640
1925
|
} catch (error) {
|
|
1641
1926
|
const message = redactSensitiveText(error instanceof Error ? error.message : String(error), secretValues);
|
|
1642
1927
|
if (active.stopped) {
|
|
1643
1928
|
addLog("warn", "Run stopped by user", Date.now() - started);
|
|
1929
|
+
await persistLog("stopped");
|
|
1644
1930
|
return reply.send({ status: "stopped", framework, logs });
|
|
1645
1931
|
}
|
|
1646
1932
|
addLog("fail", `\u2715 ${message}`, Date.now() - started);
|
|
1933
|
+
const screenshots = withScreenshotStatus(capturedScreenshots, "failed");
|
|
1934
|
+
await persistLog("failed");
|
|
1647
1935
|
return reply.send({
|
|
1648
1936
|
status: "failed",
|
|
1649
1937
|
framework,
|
|
1650
1938
|
logs,
|
|
1651
1939
|
error: message,
|
|
1652
|
-
|
|
1940
|
+
screenshots,
|
|
1941
|
+
screenshot: screenshots.at(-1)
|
|
1653
1942
|
});
|
|
1654
1943
|
} finally {
|
|
1655
1944
|
activeRuns.delete(runId);
|
|
@@ -1657,23 +1946,10 @@ function registerAutomationRunRoute(app) {
|
|
|
1657
1946
|
}
|
|
1658
1947
|
});
|
|
1659
1948
|
}
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
return void 0;
|
|
1663
|
-
try {
|
|
1664
|
-
const image = await page.screenshot({ type: "jpeg", quality: 65, fullPage: false });
|
|
1665
|
-
return {
|
|
1666
|
-
name: `${testCaseId}-${status}-${Date.now()}.jpg`,
|
|
1667
|
-
dataUrl: `data:image/jpeg;base64,${image.toString("base64")}`,
|
|
1668
|
-
capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1669
|
-
testCaseId,
|
|
1670
|
-
status
|
|
1671
|
-
};
|
|
1672
|
-
} catch {
|
|
1673
|
-
return void 0;
|
|
1674
|
-
}
|
|
1949
|
+
function withScreenshotStatus(screenshots, status) {
|
|
1950
|
+
return screenshots.map((screenshot) => ({ ...screenshot, status }));
|
|
1675
1951
|
}
|
|
1676
|
-
async function executeEditedCode(page, source, addLog, projectSecrets) {
|
|
1952
|
+
async function executeEditedCode(page, source, testCaseId, capturedScreenshots, addLog, projectSecrets) {
|
|
1677
1953
|
const lines = source.split(/\r?\n/);
|
|
1678
1954
|
let executed = 0;
|
|
1679
1955
|
for (const rawLine of lines) {
|
|
@@ -1701,6 +1977,13 @@ async function executeEditedCode(page, source, addLog, projectSecrets) {
|
|
|
1701
1977
|
await page.waitForTimeout(waitMs);
|
|
1702
1978
|
continue;
|
|
1703
1979
|
}
|
|
1980
|
+
const screenshotMatch = line.match(/^await page\.screenshot\((.*)\)$/);
|
|
1981
|
+
if (screenshotMatch) {
|
|
1982
|
+
const screenshot = await captureRequestedScreenshot(page, screenshotMatch[1], testCaseId);
|
|
1983
|
+
capturedScreenshots.push(screenshot);
|
|
1984
|
+
addLog("pass", `Screenshot captured: ${screenshot.name}`);
|
|
1985
|
+
continue;
|
|
1986
|
+
}
|
|
1704
1987
|
const clickMatch = line.match(/^await (page\..+)\.click\(\)$/);
|
|
1705
1988
|
if (clickMatch) {
|
|
1706
1989
|
const target = parseEditedLocator(page, clickMatch[1]);
|
|
@@ -1754,6 +2037,119 @@ async function executeEditedCode(page, source, addLog, projectSecrets) {
|
|
|
1754
2037
|
if (executed === 0)
|
|
1755
2038
|
throw new Error("Edited source does not contain a supported Playwright action");
|
|
1756
2039
|
}
|
|
2040
|
+
function parseScreenshotOptions(source) {
|
|
2041
|
+
const value = source.trim();
|
|
2042
|
+
if (!value)
|
|
2043
|
+
return { fullPage: false, type: "png" };
|
|
2044
|
+
const objectMatch = value.match(/^\{([\s\S]*)\}$/);
|
|
2045
|
+
if (!objectMatch)
|
|
2046
|
+
throw new Error("page.screenshot() accepts an options object only");
|
|
2047
|
+
let path;
|
|
2048
|
+
let fullPage = false;
|
|
2049
|
+
let type;
|
|
2050
|
+
let quality;
|
|
2051
|
+
for (const entry of splitOptionList(objectMatch[1])) {
|
|
2052
|
+
const separator = entry.indexOf(":");
|
|
2053
|
+
if (separator < 1)
|
|
2054
|
+
throw new Error(`Unsupported screenshot option: ${entry.slice(0, 80)}`);
|
|
2055
|
+
const key = entry.slice(0, separator).trim();
|
|
2056
|
+
const raw = entry.slice(separator + 1).trim();
|
|
2057
|
+
if (key === "path")
|
|
2058
|
+
path = parseSourceString(raw);
|
|
2059
|
+
else if (key === "fullPage" && /^(true|false)$/.test(raw))
|
|
2060
|
+
fullPage = raw === "true";
|
|
2061
|
+
else if (key === "type") {
|
|
2062
|
+
const parsedType = parseSourceString(raw);
|
|
2063
|
+
if (parsedType !== "png" && parsedType !== "jpeg")
|
|
2064
|
+
throw new Error("Screenshot type must be png or jpeg");
|
|
2065
|
+
type = parsedType;
|
|
2066
|
+
} else if (key === "quality" && /^\d{1,3}$/.test(raw))
|
|
2067
|
+
quality = Math.min(100, Math.max(1, Number(raw)));
|
|
2068
|
+
else
|
|
2069
|
+
throw new Error(`Unsupported screenshot option: ${key.slice(0, 40)}`);
|
|
2070
|
+
}
|
|
2071
|
+
const inferredType = path && /\.jpe?g$/i.test(path) ? "jpeg" : "png";
|
|
2072
|
+
return { path, fullPage, type: type ?? inferredType, quality };
|
|
2073
|
+
}
|
|
2074
|
+
function splitOptionList(value) {
|
|
2075
|
+
const entries = [];
|
|
2076
|
+
let current = "";
|
|
2077
|
+
let quote = "";
|
|
2078
|
+
let escaped = false;
|
|
2079
|
+
for (const character of value) {
|
|
2080
|
+
if (escaped) {
|
|
2081
|
+
current += character;
|
|
2082
|
+
escaped = false;
|
|
2083
|
+
continue;
|
|
2084
|
+
}
|
|
2085
|
+
if (character === "\\") {
|
|
2086
|
+
current += character;
|
|
2087
|
+
escaped = true;
|
|
2088
|
+
continue;
|
|
2089
|
+
}
|
|
2090
|
+
if (quote) {
|
|
2091
|
+
current += character;
|
|
2092
|
+
if (character === quote)
|
|
2093
|
+
quote = "";
|
|
2094
|
+
continue;
|
|
2095
|
+
}
|
|
2096
|
+
if (character === '"' || character === "'") {
|
|
2097
|
+
quote = character;
|
|
2098
|
+
current += character;
|
|
2099
|
+
continue;
|
|
2100
|
+
}
|
|
2101
|
+
if (character === ",") {
|
|
2102
|
+
if (current.trim())
|
|
2103
|
+
entries.push(current.trim());
|
|
2104
|
+
current = "";
|
|
2105
|
+
continue;
|
|
2106
|
+
}
|
|
2107
|
+
current += character;
|
|
2108
|
+
}
|
|
2109
|
+
if (quote || escaped)
|
|
2110
|
+
throw new Error("Screenshot options contain an incomplete string");
|
|
2111
|
+
if (current.trim())
|
|
2112
|
+
entries.push(current.trim());
|
|
2113
|
+
return entries;
|
|
2114
|
+
}
|
|
2115
|
+
function parseSourceString(value) {
|
|
2116
|
+
if (value.startsWith('"'))
|
|
2117
|
+
return parseStringLiteral(value);
|
|
2118
|
+
if (!value.startsWith("'") || !value.endsWith("'"))
|
|
2119
|
+
throw new Error("Screenshot strings must use quotes");
|
|
2120
|
+
const inner = value.slice(1, -1);
|
|
2121
|
+
let parsed = "";
|
|
2122
|
+
for (let index = 0; index < inner.length; index++) {
|
|
2123
|
+
const character = inner[index];
|
|
2124
|
+
if (character !== "\\") {
|
|
2125
|
+
parsed += character;
|
|
2126
|
+
continue;
|
|
2127
|
+
}
|
|
2128
|
+
const next = inner[++index];
|
|
2129
|
+
if (next === void 0)
|
|
2130
|
+
throw new Error("Screenshot string contains an incomplete escape");
|
|
2131
|
+
parsed += next === "n" ? "\n" : next === "r" ? "\r" : next === "t" ? " " : next;
|
|
2132
|
+
}
|
|
2133
|
+
return parsed;
|
|
2134
|
+
}
|
|
2135
|
+
async function captureRequestedScreenshot(page, source, testCaseId) {
|
|
2136
|
+
const options = parseScreenshotOptions(source);
|
|
2137
|
+
const image = await page.screenshot({
|
|
2138
|
+
type: options.type,
|
|
2139
|
+
fullPage: options.fullPage,
|
|
2140
|
+
...options.type === "jpeg" && options.quality ? { quality: options.quality } : {}
|
|
2141
|
+
});
|
|
2142
|
+
const extension = options.type === "jpeg" ? "jpg" : "png";
|
|
2143
|
+
const requestedName = options.path?.split(/[\\/]/).pop()?.replace(/\.[^.]+$/, "");
|
|
2144
|
+
const safeName = (requestedName || `${testCaseId}-${Date.now()}`).replace(/[^\p{L}\p{N}._-]+/gu, "-").replace(/^-+|-+$/g, "").slice(0, 100);
|
|
2145
|
+
return {
|
|
2146
|
+
name: `${safeName || `screenshot-${Date.now()}`}.${extension}`,
|
|
2147
|
+
dataUrl: `data:image/${options.type};base64,${image.toString("base64")}`,
|
|
2148
|
+
capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2149
|
+
testCaseId,
|
|
2150
|
+
status: "passed"
|
|
2151
|
+
};
|
|
2152
|
+
}
|
|
1757
2153
|
var STRING_LITERAL = '"(?:\\\\.|[^"\\\\])*"';
|
|
1758
2154
|
function parseStringLiteral(value) {
|
|
1759
2155
|
const parsed = JSON.parse(value);
|
|
@@ -1993,7 +2389,7 @@ function registerLoadTestRoute(app) {
|
|
|
1993
2389
|
});
|
|
1994
2390
|
}
|
|
1995
2391
|
if (intervalMs && count < requestsPerUser - 1)
|
|
1996
|
-
await new Promise((
|
|
2392
|
+
await new Promise((resolve3) => setTimeout(resolve3, intervalMs));
|
|
1997
2393
|
}
|
|
1998
2394
|
}
|
|
1999
2395
|
await Promise.all(Array.from({ length: virtualUsers }, (_, index) => worker(index + 1)));
|
|
@@ -2018,7 +2414,7 @@ function registerLoadTestRoute(app) {
|
|
|
2018
2414
|
// ../server/dist/routes/versions.js
|
|
2019
2415
|
import { spawn } from "node:child_process";
|
|
2020
2416
|
import { access } from "node:fs/promises";
|
|
2021
|
-
import { dirname, join } from "node:path";
|
|
2417
|
+
import { dirname as dirname2, join as join2 } from "node:path";
|
|
2022
2418
|
var PACKAGE_NAME = "lazyscout";
|
|
2023
2419
|
var REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}`;
|
|
2024
2420
|
var VERSION_PATTERN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
|
@@ -2064,8 +2460,8 @@ async function fetchPublishedVersions(force = false) {
|
|
|
2064
2460
|
async function findNpmCli() {
|
|
2065
2461
|
const candidates = [
|
|
2066
2462
|
process.env.npm_execpath,
|
|
2067
|
-
|
|
2068
|
-
process.env.APPDATA ?
|
|
2463
|
+
join2(dirname2(process.execPath), "node_modules", "npm", "bin", "npm-cli.js"),
|
|
2464
|
+
process.env.APPDATA ? join2(process.env.APPDATA, "npm", "node_modules", "npm", "bin", "npm-cli.js") : void 0,
|
|
2069
2465
|
"/usr/lib/node_modules/npm/bin/npm-cli.js",
|
|
2070
2466
|
"/usr/local/lib/node_modules/npm/bin/npm-cli.js"
|
|
2071
2467
|
].filter((value) => Boolean(value?.endsWith(".js")));
|
|
@@ -2080,7 +2476,7 @@ async function findNpmCli() {
|
|
|
2080
2476
|
}
|
|
2081
2477
|
async function runNpmInstall(version) {
|
|
2082
2478
|
const npmCli = await findNpmCli();
|
|
2083
|
-
return new Promise((
|
|
2479
|
+
return new Promise((resolve3, reject) => {
|
|
2084
2480
|
const commandArgs = [npmCli, "install", "--global", `${PACKAGE_NAME}@${version}`, "--no-audit", "--no-fund"];
|
|
2085
2481
|
const child = spawn(process.execPath, commandArgs, {
|
|
2086
2482
|
windowsHide: true,
|
|
@@ -2113,7 +2509,7 @@ async function runNpmInstall(version) {
|
|
|
2113
2509
|
settled = true;
|
|
2114
2510
|
clearTimeout(timeout);
|
|
2115
2511
|
if (code === 0)
|
|
2116
|
-
|
|
2512
|
+
resolve3(output.trim());
|
|
2117
2513
|
else
|
|
2118
2514
|
reject(new Error(output.trim() || `npm exited with code ${code ?? "unknown"}.`));
|
|
2119
2515
|
});
|
|
@@ -2183,6 +2579,61 @@ function registerVersionRoutes(app, currentVersion) {
|
|
|
2183
2579
|
});
|
|
2184
2580
|
}
|
|
2185
2581
|
|
|
2582
|
+
// ../server/dist/routes/workspace.js
|
|
2583
|
+
function registerWorkspaceRoutes(app, root) {
|
|
2584
|
+
app.get("/api/workspace", async () => ({ root, projects: await listProjects(root) }));
|
|
2585
|
+
app.post("/api/workspace/open", async (_request, reply) => {
|
|
2586
|
+
await openWorkspace(root);
|
|
2587
|
+
return reply.send({ opened: true, root });
|
|
2588
|
+
});
|
|
2589
|
+
app.put("/api/workspace/projects/:projectId", async (request, reply) => {
|
|
2590
|
+
const project = request.body;
|
|
2591
|
+
if (!project || project.id !== request.params.projectId)
|
|
2592
|
+
return reply.status(400).send({ error: { code: "invalid-project", message: "Project ID does not match." } });
|
|
2593
|
+
await saveProject(root, project);
|
|
2594
|
+
return reply.send({ saved: true });
|
|
2595
|
+
});
|
|
2596
|
+
app.delete("/api/workspace/projects/:projectId", async (request, reply) => {
|
|
2597
|
+
await deleteProject(root, request.params.projectId);
|
|
2598
|
+
return reply.send({ deleted: true });
|
|
2599
|
+
});
|
|
2600
|
+
app.get("/api/workspace/projects/:projectId/screenshots", async (request) => readScreenshots(root, request.params.projectId));
|
|
2601
|
+
app.post("/api/workspace/projects/:projectId/screenshots", async (request) => saveScreenshot(root, request.params.projectId, request.body));
|
|
2602
|
+
app.get("/api/workspace/projects/:projectId/screenshots/:name", async (request, reply) => {
|
|
2603
|
+
const image = await screenshotFile(root, request.params.projectId, request.params.name);
|
|
2604
|
+
const contentType = request.params.name.toLowerCase().endsWith(".png") ? "image/png" : "image/jpeg";
|
|
2605
|
+
return reply.header("Content-Type", contentType).header("Cache-Control", "no-store").send(image);
|
|
2606
|
+
});
|
|
2607
|
+
app.delete("/api/workspace/projects/:projectId/screenshots/:name", async (request, reply) => {
|
|
2608
|
+
await deleteScreenshot(root, request.params.projectId, request.params.name);
|
|
2609
|
+
return reply.send({ deleted: true });
|
|
2610
|
+
});
|
|
2611
|
+
app.get("/api/workspace/projects/:projectId/bugs", async (request) => listBugReports(root, request.params.projectId));
|
|
2612
|
+
app.put("/api/workspace/projects/:projectId/bugs/:bugId", async (request, reply) => {
|
|
2613
|
+
const report = request.body;
|
|
2614
|
+
if (!report || report.id !== request.params.bugId)
|
|
2615
|
+
return reply.status(400).send({ error: { code: "invalid-bug", message: "Bug ID does not match." } });
|
|
2616
|
+
await saveBugReport(root, request.params.projectId, report);
|
|
2617
|
+
return reply.send({ saved: true });
|
|
2618
|
+
});
|
|
2619
|
+
app.delete("/api/workspace/projects/:projectId/bugs/:bugId", async (request, reply) => {
|
|
2620
|
+
await deleteBugReport(root, request.params.projectId, request.params.bugId);
|
|
2621
|
+
return reply.send({ deleted: true });
|
|
2622
|
+
});
|
|
2623
|
+
app.get("/api/workspace/projects/:projectId/automation", async (request) => readAutomation(root, request.params.projectId));
|
|
2624
|
+
app.put("/api/workspace/projects/:projectId/automation", async (request, reply) => {
|
|
2625
|
+
await saveAutomation(root, request.params.projectId, request.body);
|
|
2626
|
+
return reply.send({ saved: true });
|
|
2627
|
+
});
|
|
2628
|
+
app.post("/api/workspace/projects/:projectId/reports", async (request, reply) => {
|
|
2629
|
+
const body = request.body;
|
|
2630
|
+
if (!body?.html)
|
|
2631
|
+
return reply.status(400).send({ error: { code: "invalid-report", message: "Report HTML is required." } });
|
|
2632
|
+
const name = await saveReport(root, request.params.projectId, body.name ?? "quality-report.html", body.html);
|
|
2633
|
+
return reply.send({ saved: true, name });
|
|
2634
|
+
});
|
|
2635
|
+
}
|
|
2636
|
+
|
|
2186
2637
|
// ../server/dist/app.js
|
|
2187
2638
|
function buildApp(options = {}) {
|
|
2188
2639
|
const app = Fastify({
|
|
@@ -2191,13 +2642,15 @@ function buildApp(options = {}) {
|
|
|
2191
2642
|
bodyLimit: 10 * 1024 * 1024
|
|
2192
2643
|
});
|
|
2193
2644
|
const appVersion = options.appVersion ?? process.env.npm_package_version ?? "0.0.0-dev";
|
|
2194
|
-
|
|
2645
|
+
const workspaceRoot = resolveWorkspaceRoot(options.workspaceRoot);
|
|
2646
|
+
app.get("/api/health", async () => ({ status: "ok", version: appVersion, workspaceRoot }));
|
|
2195
2647
|
registerAnalyzeRoute(app);
|
|
2196
2648
|
registerExportCsvRoute(app);
|
|
2197
|
-
registerAutomationRunRoute(app);
|
|
2649
|
+
registerAutomationRunRoute(app, workspaceRoot);
|
|
2198
2650
|
registerApiCheckRunRoute(app);
|
|
2199
2651
|
registerLoadTestRoute(app);
|
|
2200
2652
|
registerVersionRoutes(app, appVersion);
|
|
2653
|
+
registerWorkspaceRoutes(app, workspaceRoot);
|
|
2201
2654
|
if (options.staticDir) {
|
|
2202
2655
|
app.register(fastifyStatic, { root: options.staticDir });
|
|
2203
2656
|
app.setNotFoundHandler(async (request, reply) => {
|
|
@@ -2225,18 +2678,21 @@ async function openInBrowser(url) {
|
|
|
2225
2678
|
}
|
|
2226
2679
|
|
|
2227
2680
|
// src/version.ts
|
|
2228
|
-
var VERSION = true ? "0.
|
|
2681
|
+
var VERSION = true ? "0.3.0" : "0.0.0-dev";
|
|
2229
2682
|
|
|
2230
2683
|
// src/commands/serve.ts
|
|
2231
2684
|
var DEFAULT_PORT = 4321;
|
|
2232
|
-
var WEB_DIR =
|
|
2685
|
+
var WEB_DIR = join3(dirname3(fileURLToPath(import.meta.url)), "web");
|
|
2233
2686
|
async function runServe(options) {
|
|
2234
|
-
const
|
|
2687
|
+
const workspaceRoot = resolveWorkspaceRoot(options.workspace);
|
|
2688
|
+
await ensureWorkspace(workspaceRoot);
|
|
2689
|
+
const app = buildApp({ staticDir: WEB_DIR, logLevel: "warn", appVersion: VERSION, workspaceRoot });
|
|
2235
2690
|
const port = await listenOnFreePort(app, options.port ?? DEFAULT_PORT);
|
|
2236
2691
|
const url = `http://localhost:${port}`;
|
|
2237
2692
|
console.log(`
|
|
2238
|
-
LazyScout
|
|
2239
|
-
console.log(
|
|
2693
|
+
\u{1F680} LazyScout is now available. ${url}`);
|
|
2694
|
+
console.log(` \u{1F4C1} Workspace: ${workspaceRoot}`);
|
|
2695
|
+
console.log(" Press Ctrl+C to exit \n");
|
|
2240
2696
|
if (options.open) await openInBrowser(url);
|
|
2241
2697
|
}
|
|
2242
2698
|
async function listenOnFreePort(app, startPort) {
|
|
@@ -2249,33 +2705,53 @@ async function listenOnFreePort(app, startPort) {
|
|
|
2249
2705
|
if (code !== "EADDRINUSE") throw error;
|
|
2250
2706
|
}
|
|
2251
2707
|
}
|
|
2252
|
-
throw new Error(
|
|
2708
|
+
throw new Error(`No free port found in the specified range ${startPort}-${startPort + 19}`);
|
|
2253
2709
|
}
|
|
2254
2710
|
|
|
2255
2711
|
// src/index.ts
|
|
2256
2712
|
var HELP = `
|
|
2257
|
-
LazyScout ${VERSION} \u2014
|
|
2713
|
+
LazyScout ${VERSION} \u2014 Analyze websites and generate draft test cases for software testers.
|
|
2714
|
+
|
|
2715
|
+
Usage
|
|
2716
|
+
npx lazyscout
|
|
2717
|
+
Open the LazyScout web interface. Recommended.
|
|
2718
|
+
|
|
2719
|
+
npx lazyscout scan <url>
|
|
2720
|
+
Scan a website and save the results to files without opening the LazyScout interface.
|
|
2721
|
+
|
|
2722
|
+
Scan Options
|
|
2723
|
+
--csv <file> Save test cases and test data as CSV.
|
|
2724
|
+
Default: lazyscout-testcases.csv
|
|
2725
|
+
|
|
2726
|
+
--json <file> Save all raw scan results as JSON.
|
|
2258
2727
|
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
npx lazyscout scan <url> \u0E2A\u0E41\u0E01\u0E19\u0E41\u0E25\u0E49\u0E27\u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01\u0E1C\u0E25\u0E40\u0E1B\u0E47\u0E19\u0E44\u0E1F\u0E25\u0E4C \u0E44\u0E21\u0E48\u0E15\u0E49\u0E2D\u0E07\u0E40\u0E1B\u0E34\u0E14\u0E40\u0E1A\u0E23\u0E32\u0E27\u0E4C\u0E40\u0E0B\u0E2D\u0E23\u0E4C
|
|
2728
|
+
--max-pages <n> Maximum number of pages to scan.
|
|
2729
|
+
Default: 20
|
|
2262
2730
|
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
--json <\u0E44\u0E1F\u0E25\u0E4C> \u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01\u0E1C\u0E25\u0E14\u0E34\u0E1A\u0E17\u0E31\u0E49\u0E07\u0E2B\u0E21\u0E14\u0E40\u0E1B\u0E47\u0E19 JSON
|
|
2266
|
-
--max-pages <n> \u0E08\u0E33\u0E19\u0E27\u0E19\u0E2B\u0E19\u0E49\u0E32\u0E2A\u0E39\u0E07\u0E2A\u0E38\u0E14 (\u0E04\u0E48\u0E32\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19 20)
|
|
2267
|
-
--max-depth <n> \u0E04\u0E27\u0E32\u0E21\u0E25\u0E36\u0E01\u0E2A\u0E39\u0E07\u0E2A\u0E38\u0E14 (\u0E04\u0E48\u0E32\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19 3)
|
|
2731
|
+
--max-depth <n> Maximum crawl depth.
|
|
2732
|
+
Default: 3
|
|
2268
2733
|
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2734
|
+
Web Interface Options
|
|
2735
|
+
--port <port> Port used by the LazyScout web interface.
|
|
2736
|
+
Default: 4321
|
|
2272
2737
|
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
npx lazyscout scan http://localhost:5173
|
|
2276
|
-
npx lazyscout scan https://example.com --max-pages 10 --csv report.csv
|
|
2738
|
+
--workspace <path> Workspace used for projects and evidence.
|
|
2739
|
+
Default: ~/LazyScout
|
|
2277
2740
|
|
|
2278
|
-
|
|
2741
|
+
--no-open Do not open the browser automatically.
|
|
2742
|
+
|
|
2743
|
+
Examples
|
|
2744
|
+
npx lazyscout
|
|
2745
|
+
|
|
2746
|
+
npx lazyscout --workspace D:\\QA\\LazyScout
|
|
2747
|
+
|
|
2748
|
+
npx lazyscout scan http://localhost:5173
|
|
2749
|
+
|
|
2750
|
+
npx lazyscout scan https://example.com --max-pages 10 --csv report.csv
|
|
2751
|
+
|
|
2752
|
+
Explorer Behavior
|
|
2753
|
+
LazyScout only explores URLs within the same origin.
|
|
2754
|
+
It currently follows links only and does not click buttons or submit forms.
|
|
2279
2755
|
`;
|
|
2280
2756
|
async function main() {
|
|
2281
2757
|
const { values, positionals } = parseArgs({
|
|
@@ -2288,6 +2764,7 @@ async function main() {
|
|
|
2288
2764
|
"max-pages": { type: "string" },
|
|
2289
2765
|
"max-depth": { type: "string" },
|
|
2290
2766
|
port: { type: "string" },
|
|
2767
|
+
workspace: { type: "string" },
|
|
2291
2768
|
"no-open": { type: "boolean", default: false }
|
|
2292
2769
|
}
|
|
2293
2770
|
});
|
|
@@ -2303,7 +2780,11 @@ async function main() {
|
|
|
2303
2780
|
switch (command) {
|
|
2304
2781
|
case void 0:
|
|
2305
2782
|
case "serve":
|
|
2306
|
-
await runServe({
|
|
2783
|
+
await runServe({
|
|
2784
|
+
port: values.port ? Number(values.port) : void 0,
|
|
2785
|
+
open: !values["no-open"],
|
|
2786
|
+
workspace: values.workspace
|
|
2787
|
+
});
|
|
2307
2788
|
return;
|
|
2308
2789
|
case "scan": {
|
|
2309
2790
|
const url = positionals[1];
|