lazyscout 0.3.4 → 0.3.7

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/index.js CHANGED
@@ -260,6 +260,9 @@ function isSessionEndingLabel(...labels) {
260
260
  return false;
261
261
  return SESSION_ENDING_KEYWORDS.some((keyword) => haystack.includes(keyword.toLowerCase()));
262
262
  }
263
+ function isUnsafeAutoClick(...labels) {
264
+ return isSessionEndingLabel(...labels);
265
+ }
263
266
  var MAX_BLOCK_KEYWORDS = 100;
264
267
  var MAX_KEYWORD_LENGTH = 80;
265
268
  function normalizeBlockedKeywords(value) {
@@ -522,13 +525,6 @@ function collectPageData() {
522
525
  };
523
526
  }
524
527
 
525
- // ../../packages/explorer/dist/safety.js
526
- function canFollowLink(href, accessibleName, keywords = []) {
527
- if (!href)
528
- return false;
529
- return !isBlockedLabel(keywords, accessibleName, href);
530
- }
531
-
532
528
  // ../../packages/explorer/dist/mapToPageModel.js
533
529
  function toUIElement(raw, keywords) {
534
530
  return {
@@ -682,341 +678,6 @@ async function launchBrowser(options = {}) {
682
678
  throw new ExplorerError("browser-error", `unable to launch a browser (tried: ${failures.join(", ")})`, options.userDataDir ? "Close any other LazyScout browser for this Project \u2014 the login browser and a recording both hold its profile \u2014 and try again" : 'Please install Google Chrome or Microsoft Edge or run "npx playwright install chromium" and try again');
683
679
  }
684
680
 
685
- // ../../packages/explorer/dist/exploreWebsite.js
686
- var DEFAULT_EXPLORE_OPTIONS = {
687
- maxPages: 20,
688
- maxDepth: 3,
689
- pageTimeoutMs: 2e4,
690
- totalTimeoutMs: 12e4,
691
- waitAfterNavigationMs: 750,
692
- maxStatesPerPage: 8,
693
- maxActionsPerState: 8,
694
- maxTotalStates: 80,
695
- actionTimeoutMs: 2e3,
696
- stateDiscoveryTimeoutMs: 350,
697
- blockedKeywords: [],
698
- maxNavigationProbesPerPage: 6
699
- };
700
- async function exploreWebsite(startUrl, options = {}, policy = LOCAL_QA_POLICY) {
701
- const config2 = { ...DEFAULT_EXPLORE_OPTIONS, ...options };
702
- const startedAt = Date.now();
703
- const check = checkTargetUrl(startUrl, policy);
704
- if (!check.ok)
705
- throw new ExplorerError(check.code, check.message);
706
- const origin = check.url.origin;
707
- const entryUrl = normalizeUrl(check.url.toString());
708
- const pages = [];
709
- const issues = [];
710
- const visited = /* @__PURE__ */ new Set();
711
- const queue = [{ url: entryUrl, depth: 0 }];
712
- const actionGraph = {
713
- states: [],
714
- edges: [],
715
- visitedStateIds: [],
716
- visitedActionKeys: [],
717
- failedActionKeys: [],
718
- blockedActionKeys: []
719
- };
720
- let urlsSkipped = 0;
721
- let limitReached = "none";
722
- const launched = await launchBrowser(config2.browserProfileDir ? { userDataDir: config2.browserProfileDir } : {});
723
- const { context, label: browserLabel } = launched;
724
- try {
725
- context.setDefaultTimeout(config2.pageTimeoutMs);
726
- const page = await context.newPage();
727
- while (queue.length > 0) {
728
- if (pages.length >= config2.maxPages) {
729
- limitReached = "max-pages-reached";
730
- urlsSkipped += queue.length;
731
- break;
732
- }
733
- if (Date.now() - startedAt > config2.totalTimeoutMs) {
734
- limitReached = "timeout-reached";
735
- urlsSkipped += queue.length;
736
- break;
737
- }
738
- const item = queue.shift();
739
- if (visited.has(item.url))
740
- continue;
741
- visited.add(item.url);
742
- const result = await visitPage(page, item, config2, config2.blockedKeywords);
743
- if (result.kind === "issue") {
744
- issues.push(result.issue);
745
- continue;
746
- }
747
- const finalKey = normalizeUrl(result.page.finalUrl);
748
- if (finalKey !== item.url && visited.has(finalKey)) {
749
- urlsSkipped++;
750
- continue;
751
- }
752
- visited.add(finalKey);
753
- pages.push(result.page);
754
- addState(actionGraph, result.page.state);
755
- await discoverSafeStates(page, result.page, config2, origin, actionGraph);
756
- if (item.depth >= config2.maxDepth) {
757
- if (result.page.links.length > 0)
758
- limitReached = limitReached === "none" ? "max-depth-reached" : limitReached;
759
- continue;
760
- }
761
- const enqueue = (href) => {
762
- if (!href)
763
- return;
764
- if (!isSameOrigin(href, origin) || !isCrawlableUrl(href)) {
765
- urlsSkipped++;
766
- return;
767
- }
768
- const next = normalizeUrl(href);
769
- if (visited.has(next) || queue.some((queued) => queued.url === next))
770
- return;
771
- queue.push({ url: next, depth: item.depth + 1 });
772
- };
773
- for (const link of result.page.links) {
774
- if (!canFollowLink(link.href, link.accessibleName, config2.blockedKeywords))
775
- continue;
776
- enqueue(link.href);
777
- }
778
- await probeNavigationControls(page, result.page, config2, origin, actionGraph, enqueue, () => Date.now() - startedAt > config2.totalTimeoutMs);
779
- }
780
- } finally {
781
- await launched.close().catch(() => void 0);
782
- }
783
- addNavigationEdges(pages, actionGraph, config2.blockedKeywords);
784
- return {
785
- startUrl: entryUrl,
786
- origin,
787
- pages,
788
- issues,
789
- stats: {
790
- browser: browserLabel,
791
- pagesVisited: pages.length,
792
- urlsSkipped,
793
- durationMs: Date.now() - startedAt,
794
- limitReached
795
- },
796
- actionGraph
797
- };
798
- }
799
- function addNavigationEdges(pages, graph, keywords) {
800
- for (const page of pages) {
801
- const source = page.state;
802
- if (!source)
803
- continue;
804
- for (const link of page.links) {
805
- if (!link.href || !link.accessibleName)
806
- continue;
807
- const safe = canFollowLink(link.href, link.accessibleName, keywords);
808
- const target = pages.find((candidate) => candidate.finalUrl === link.href || candidate.url === link.href)?.state;
809
- const action = {
810
- id: `${source.id}|navigate|${link.cssSelector}`,
811
- type: "navigate",
812
- description: `Navigate to \u201C${link.accessibleName}\u201D`,
813
- target: link.accessibleName,
814
- selector: link.cssSelector,
815
- locator: { role: link.role, name: link.accessibleName },
816
- safe,
817
- reason: safe ? void 0 : "Link matched the Project click filter and was not opened"
818
- };
819
- addEdge(graph, source.id, target?.id, action, safe && target ? "visited" : safe ? "discovered" : "blocked");
820
- if (!safe)
821
- graph.blockedActionKeys.push(action.id);
822
- }
823
- }
824
- }
825
- function addState(graph, state) {
826
- if (!state || graph.states.some((candidate) => candidate.id === state.id))
827
- return;
828
- graph.states.push(state);
829
- graph.visitedStateIds.push(state.id);
830
- }
831
- async function discoverSafeStates(page, source, config2, origin, graph) {
832
- const initial = source.state;
833
- if (!initial || graph.states.length >= config2.maxTotalStates)
834
- return;
835
- const sourceUrl = source.finalUrl;
836
- const interactions = initial.interactions.slice(0, config2.maxActionsPerState);
837
- let statesForPage = 1;
838
- for (const interaction of interactions) {
839
- if (statesForPage >= config2.maxStatesPerPage || graph.states.length >= config2.maxTotalStates)
840
- break;
841
- const action = actionFromInteraction(initial.id, interaction, config2.blockedKeywords);
842
- const actionKey = action.id;
843
- if (graph.visitedActionKeys.includes(actionKey) || graph.failedActionKeys.includes(actionKey))
844
- continue;
845
- if (!action.safe) {
846
- addEdge(graph, initial.id, void 0, action, "blocked");
847
- graph.blockedActionKeys.push(actionKey);
848
- continue;
849
- }
850
- try {
851
- await page.locator(interaction.cssSelector).click({ timeout: config2.actionTimeoutMs });
852
- await page.waitForTimeout(config2.stateDiscoveryTimeoutMs);
853
- if (!isSameOrigin(page.url(), origin)) {
854
- addEdge(graph, initial.id, void 0, { ...action, safe: false, reason: "Action left the approved origin" }, "blocked");
855
- graph.blockedActionKeys.push(actionKey);
856
- continue;
857
- }
858
- const raw = await page.evaluate(collectPageData);
859
- const observed = mapToPageModel(raw, {
860
- url: page.url(),
861
- finalUrl: page.url(),
862
- depth: source.depth,
863
- statusCode: source.statusCode
864
- }, config2.blockedKeywords).state;
865
- if (!observed)
866
- continue;
867
- addState(graph, observed);
868
- addEdge(graph, initial.id, observed.id, action, "visited");
869
- graph.visitedActionKeys.push(actionKey);
870
- if (observed.id !== initial.id)
871
- statesForPage += 1;
872
- } catch (error) {
873
- addEdge(graph, initial.id, void 0, action, "failed");
874
- graph.failedActionKeys.push(actionKey);
875
- } finally {
876
- await page.goto(sourceUrl, { waitUntil: "domcontentloaded", timeout: config2.pageTimeoutMs }).catch(() => void 0);
877
- await page.waitForTimeout(Math.min(config2.waitAfterNavigationMs, 300));
878
- }
879
- }
880
- }
881
- async function probeNavigationControls(page, source, config2, origin, graph, enqueue, outOfTime) {
882
- if (config2.maxNavigationProbesPerPage <= 0)
883
- return;
884
- const sourceUrl = source.finalUrl;
885
- const sourceKey = normalizeUrl(sourceUrl);
886
- const stateId2 = source.state?.id;
887
- const candidates = source.buttons.filter((button) => button.accessibleName && !button.destructive && !button.disabled).slice(0, config2.maxNavigationProbesPerPage);
888
- for (const candidate of candidates) {
889
- if (outOfTime())
890
- break;
891
- const action = {
892
- id: `${stateId2 ?? sourceKey}|navigate|${candidate.cssSelector}`,
893
- type: "navigate",
894
- description: `Navigate by clicking \u201C${candidate.accessibleName}\u201D`,
895
- target: candidate.accessibleName,
896
- selector: candidate.cssSelector,
897
- locator: { role: candidate.role, name: candidate.accessibleName },
898
- safe: true
899
- };
900
- if (graph.visitedActionKeys.includes(action.id) || graph.failedActionKeys.includes(action.id))
901
- continue;
902
- try {
903
- if (normalizeUrl(page.url()) !== sourceKey) {
904
- await page.goto(sourceUrl, { waitUntil: "domcontentloaded", timeout: config2.pageTimeoutMs });
905
- }
906
- await page.locator(candidate.cssSelector).click({ timeout: config2.actionTimeoutMs });
907
- await page.waitForTimeout(config2.stateDiscoveryTimeoutMs);
908
- const reached = page.url();
909
- if (normalizeUrl(reached) === sourceKey)
910
- continue;
911
- if (!isSameOrigin(reached, origin)) {
912
- if (stateId2)
913
- addEdge(graph, stateId2, void 0, { ...action, safe: false, reason: "Action left the approved origin" }, "blocked");
914
- graph.blockedActionKeys.push(action.id);
915
- continue;
916
- }
917
- enqueue(reached);
918
- if (stateId2)
919
- addEdge(graph, stateId2, void 0, action, "discovered");
920
- graph.visitedActionKeys.push(action.id);
921
- } catch {
922
- if (stateId2)
923
- addEdge(graph, stateId2, void 0, action, "failed");
924
- graph.failedActionKeys.push(action.id);
925
- }
926
- }
927
- if (normalizeUrl(page.url()) !== sourceKey) {
928
- await page.goto(sourceUrl, { waitUntil: "domcontentloaded", timeout: config2.pageTimeoutMs }).catch(() => void 0);
929
- }
930
- }
931
- function actionFromInteraction(stateId2, interaction, keywords) {
932
- const type = interaction.kind === "tab" ? "selectTab" : interaction.kind === "accordion" ? "expandAccordion" : interaction.kind === "dropdown" ? "openDropdown" : interaction.expanded ? "closeDialog" : "openModal";
933
- const blocked = isBlockedLabel(keywords, interaction.name);
934
- const description = `${type === "selectTab" ? "Select" : type === "expandAccordion" ? "Expand" : "Open"} \u201C${interaction.name}\u201D`;
935
- return {
936
- id: `${stateId2}|${type}|${interaction.cssSelector}`,
937
- type,
938
- description,
939
- target: interaction.name,
940
- selector: interaction.cssSelector,
941
- locator: { role: interaction.role, name: interaction.name },
942
- safe: !blocked,
943
- reason: blocked ? "Action matched the Project click filter and was not executed" : void 0
944
- };
945
- }
946
- function addEdge(graph, fromStateId, toStateId, action, status) {
947
- const id = `${fromStateId}|${action.id}|${toStateId ?? status}`;
948
- if (graph.edges.some((edge) => edge.id === id))
949
- return;
950
- graph.edges.push({ id, fromStateId, toStateId, action, status });
951
- }
952
- async function visitPage(page, item, config2, keywords) {
953
- try {
954
- const apiRequests = [];
955
- const requestStarted = /* @__PURE__ */ new Map();
956
- const onRequest = (request) => {
957
- if (request.resourceType() === "xhr" || request.resourceType() === "fetch")
958
- requestStarted.set(request.url(), Date.now());
959
- };
960
- const onResponse = (response2) => {
961
- const request = response2.request();
962
- if (request.resourceType() !== "xhr" && request.resourceType() !== "fetch")
963
- return;
964
- apiRequests.push({
965
- id: `api-${apiRequests.length + 1}`,
966
- method: request.method(),
967
- url: redactUrl(request.url()),
968
- status: response2.status(),
969
- durationMs: Date.now() - (requestStarted.get(request.url()) ?? Date.now()),
970
- resourceType: request.resourceType(),
971
- sourceUrl: redactUrl(item.url),
972
- contentType: response2.headers()["content-type"]
973
- });
974
- };
975
- page.on("request", onRequest);
976
- page.on("response", onResponse);
977
- const response = await page.goto(item.url, {
978
- waitUntil: "domcontentloaded",
979
- timeout: config2.pageTimeoutMs
980
- });
981
- const status = response?.status();
982
- if (status !== void 0 && status >= 400) {
983
- return {
984
- kind: "issue",
985
- issue: { url: item.url, code: "http-error", message: `The server returned HTTP ${status}.` }
986
- };
987
- }
988
- await page.waitForLoadState("networkidle", { timeout: Math.min(config2.pageTimeoutMs, 5e3) }).catch(() => void 0);
989
- await page.waitForTimeout(config2.waitAfterNavigationMs);
990
- const challengeText = `${await page.title()} ${await page.locator("body").innerText().catch(() => "")}`.toLowerCase();
991
- if (challengeText.includes("cloudflare") || challengeText.includes("checking your browser") || challengeText.includes("verify you are human") || challengeText.includes("just a moment")) {
992
- return {
993
- kind: "issue",
994
- issue: {
995
- url: item.url,
996
- code: "cloudflare",
997
- message: "Cloudflare/browser challenge \u2014 self check the website in a browser and try again"
998
- }
999
- };
1000
- }
1001
- const finalUrl = page.url();
1002
- const raw = await page.evaluate(collectPageData);
1003
- page.off("request", onRequest);
1004
- page.off("response", onResponse);
1005
- return {
1006
- kind: "page",
1007
- page: mapToPageModel(raw, {
1008
- url: item.url,
1009
- finalUrl,
1010
- depth: item.depth,
1011
- statusCode: status,
1012
- apiRequests
1013
- }, keywords)
1014
- };
1015
- } catch (error) {
1016
- return { kind: "issue", issue: toExploreIssue(item.url, error) };
1017
- }
1018
- }
1019
-
1020
681
  // ../../packages/explorer/dist/scopedExplorer.js
1021
682
  var DEFAULT_LIMITS = {
1022
683
  maxPages: 20,
@@ -1039,6 +700,10 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
1039
700
  ...explorationConfig,
1040
701
  limits: { ...DEFAULT_LIMITS, ...explorationConfig.limits }
1041
702
  };
703
+ const abortIfRequested = () => {
704
+ if (exploreOptions.signal?.aborted)
705
+ throw new ExplorerError("browser-error", "Scout stopped because the client disconnected.");
706
+ };
1042
707
  const legacyOptions = {
1043
708
  maxPages: config2.limits.maxPages,
1044
709
  maxDepth: config2.limits.maxDepth,
@@ -1472,7 +1137,7 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
1472
1137
  if (visitedStates.has(modalState.id))
1473
1138
  return { candidates: [] };
1474
1139
  visitedStates.add(modalState.id);
1475
- addState2(actionGraph, modalState);
1140
+ addState(actionGraph, modalState);
1476
1141
  debug(`State discovered: ${modalState.name} (modal)`, { stateId: modalState.id, url: page.url() });
1477
1142
  const modalCandidates = await discoverSafeCandidates(page, modalState);
1478
1143
  const safeCandidates = modalCandidates.filter((c) => c.action.safe).slice(0, legacyOptions.maxActionsPerState);
@@ -1480,7 +1145,7 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
1480
1145
  if (actionGraph.visitedActionKeys.includes(mc.action.id) || actionGraph.failedActionKeys.includes(mc.action.id))
1481
1146
  continue;
1482
1147
  if (!mc.action.safe) {
1483
- addEdge2(actionGraph, modalState.id, void 0, mc.action, "blocked");
1148
+ addEdge(actionGraph, modalState.id, void 0, mc.action, "blocked");
1484
1149
  actionGraph.blockedActionKeys.push(mc.action.id);
1485
1150
  totalActionsBlocked++;
1486
1151
  debug(`Blocked: ${mc.action.target} (${mc.action.reason || "unsafe"})`, {
@@ -1493,7 +1158,7 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
1493
1158
  totalActionsExecuted++;
1494
1159
  if (!result.success) {
1495
1160
  totalActionsFailed++;
1496
- addEdge2(actionGraph, modalState.id, void 0, mc.action, "failed");
1161
+ addEdge(actionGraph, modalState.id, void 0, mc.action, "failed");
1497
1162
  actionGraph.failedActionKeys.push(mc.action.id);
1498
1163
  debug(`Failed: ${mc.action.target}`, { actionId: mc.action.id, stateId: modalState.id });
1499
1164
  continue;
@@ -1504,8 +1169,8 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
1504
1169
  const newState = newModel.state;
1505
1170
  if (newState && !visitedStates.has(newState.id)) {
1506
1171
  visitedStates.add(newState.id);
1507
- addState2(actionGraph, newState);
1508
- addEdge2(actionGraph, modalState.id, newState.id, mc.action, "visited");
1172
+ addState(actionGraph, newState);
1173
+ addEdge(actionGraph, modalState.id, newState.id, mc.action, "visited");
1509
1174
  debug(`New state in modal: ${newState.name}`, { stateId: newState.id });
1510
1175
  }
1511
1176
  }
@@ -1557,7 +1222,7 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
1557
1222
  visitedUrls.add(normalizeUrl(initialPage.finalUrl));
1558
1223
  if (initialPage.state) {
1559
1224
  visitedStates.add(initialPage.state.id);
1560
- addState2(actionGraph, initialPage.state);
1225
+ addState(actionGraph, initialPage.state);
1561
1226
  debug(`State discovered: ${initialPage.state.name}`, {
1562
1227
  stateId: initialPage.state.id,
1563
1228
  url: redactUrl(initialPage.finalUrl)
@@ -1584,6 +1249,7 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
1584
1249
  entryFlow
1585
1250
  });
1586
1251
  while (stateQueue.length > 0) {
1252
+ abortIfRequested();
1587
1253
  if (pages.length >= config2.limits.maxPages) {
1588
1254
  endReason = "max-pages-reached";
1589
1255
  debug(`Limit reached: max pages (${config2.limits.maxPages})`);
@@ -1646,7 +1312,7 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
1646
1312
  continue;
1647
1313
  if (!visitedStates.has(currentState.id)) {
1648
1314
  visitedStates.add(currentState.id);
1649
- addState2(actionGraph, currentState);
1315
+ addState(actionGraph, currentState);
1650
1316
  }
1651
1317
  if (config2.mode === "current-page")
1652
1318
  continue;
@@ -1660,7 +1326,7 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
1660
1326
  for (const candidate of candidates) {
1661
1327
  if (!candidate.action.safe && candidate.action.reason) {
1662
1328
  totalActionsBlocked++;
1663
- addEdge2(actionGraph, currentState.id, void 0, candidate.action, "blocked");
1329
+ addEdge(actionGraph, currentState.id, void 0, candidate.action, "blocked");
1664
1330
  actionGraph.blockedActionKeys.push(candidate.action.id);
1665
1331
  const blockReason = isSessionEnding(candidate.action.target, void 0) ? "session-ending action" : candidate.action.reason;
1666
1332
  debug(`Blocked: ${candidate.action.target} (${blockReason})`, {
@@ -1691,7 +1357,7 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
1691
1357
  totalActionsExecuted++;
1692
1358
  if (!result.success) {
1693
1359
  totalActionsFailed++;
1694
- addEdge2(actionGraph, currentState.id, void 0, candidate.action, "failed");
1360
+ addEdge(actionGraph, currentState.id, void 0, candidate.action, "failed");
1695
1361
  actionGraph.failedActionKeys.push(candidate.action.id);
1696
1362
  debug(`Failed: ${candidate.action.target}`, { actionId: candidate.action.id });
1697
1363
  await restoreState(page, beforeUrl, candidate.restoreStrategy, item.entryFlow);
@@ -1718,8 +1384,8 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
1718
1384
  const newState = newModel.state;
1719
1385
  if (newState && !visitedStates.has(newState.id)) {
1720
1386
  visitedStates.add(newState.id);
1721
- addState2(actionGraph, newState);
1722
- addEdge2(actionGraph, currentState.id, newState.id, candidate.action, "visited");
1387
+ addState(actionGraph, newState);
1388
+ addEdge(actionGraph, currentState.id, newState.id, candidate.action, "visited");
1723
1389
  debug(`New state: ${newState.name}`, { stateId: newState.id, url: redactUrl(afterUrl) });
1724
1390
  if (!visitedUrls.has(normalizedAfter)) {
1725
1391
  visitedUrls.add(normalizedAfter);
@@ -1736,9 +1402,9 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
1736
1402
  entryFlow: newEntryFlow
1737
1403
  });
1738
1404
  } else if (newState) {
1739
- addEdge2(actionGraph, currentState.id, newState.id, candidate.action, "visited");
1405
+ addEdge(actionGraph, currentState.id, newState.id, candidate.action, "visited");
1740
1406
  } else {
1741
- addEdge2(actionGraph, currentState.id, void 0, candidate.action, "visited");
1407
+ addEdge(actionGraph, currentState.id, void 0, candidate.action, "visited");
1742
1408
  }
1743
1409
  if (normalizedAfter !== normalizeUrl(beforeUrl)) {
1744
1410
  await restoreState(page, beforeUrl, candidate.restoreStrategy, item.entryFlow);
@@ -1784,13 +1450,13 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
1784
1450
  actionGraph
1785
1451
  };
1786
1452
  }
1787
- function addState2(graph, state) {
1453
+ function addState(graph, state) {
1788
1454
  if (!state || graph.states.some((s) => s.id === state.id))
1789
1455
  return;
1790
1456
  graph.states.push(state);
1791
1457
  graph.visitedStateIds.push(state.id);
1792
1458
  }
1793
- function addEdge2(graph, fromStateId, toStateId, action, status) {
1459
+ function addEdge(graph, fromStateId, toStateId, action, status) {
1794
1460
  const id = `${fromStateId}|${action.id}|${toStateId ?? status}`;
1795
1461
  if (graph.edges.some((edge) => edge.id === id))
1796
1462
  return;
@@ -2219,7 +1885,17 @@ function fillFieldStep(field) {
2219
1885
  const option = field.options?.[1] ?? field.options?.[0] ?? "";
2220
1886
  return { type: "select", target: toTargetRef(field), option };
2221
1887
  }
2222
- return { type: "fill", target: toTargetRef(field), value: sampleValueFor(field) };
1888
+ return { type: "fill", target: toTargetRef(field), value: automationValueFor(field) };
1889
+ }
1890
+ function automationValueFor(field) {
1891
+ const hint = `${field.inputType ?? ""} ${field.name ?? ""} ${field.accessibleName ?? ""} ${field.placeholder ?? ""}`.toLowerCase();
1892
+ if (field.inputType === "password" || hint.includes("password") || hint.includes("\u0E23\u0E2B\u0E31\u0E2A\u0E1C\u0E48\u0E32\u0E19"))
1893
+ return "{{TEST_PASSWORD}}";
1894
+ if (field.inputType === "email" || hint.includes("email") || hint.includes("\u0E2D\u0E35\u0E40\u0E21\u0E25"))
1895
+ return "{{TEST_EMAIL}}";
1896
+ if (hint.includes("username") || hint.includes("user name") || hint.includes("\u0E0A\u0E37\u0E48\u0E2D\u0E1C\u0E39\u0E49\u0E43\u0E0A\u0E49"))
1897
+ return "{{TEST_USERNAME}}";
1898
+ return sampleValueFor(field);
2223
1899
  }
2224
1900
  function pageStructureRule(ctx) {
2225
1901
  const { page } = ctx;
@@ -2252,6 +1928,40 @@ function pageStructureRule(ctx) {
2252
1928
  })
2253
1929
  ];
2254
1930
  }
1931
+ function interactionRule(ctx) {
1932
+ const interactions = ctx.page.state?.interactions ?? [];
1933
+ return interactions.slice(0, 12).map((interaction) => {
1934
+ const target = interactionTarget(interaction);
1935
+ return build(ctx, {
1936
+ title: (interaction.name || interaction.kind) + " interaction works",
1937
+ preconditions: precondition(ctx.page),
1938
+ steps: [
1939
+ navigateStep(ctx.page),
1940
+ { type: "click", target, description: interactionAction(interaction) },
1941
+ { type: "assertVisible", target }
1942
+ ],
1943
+ expectedResult: interaction.kind + ' "' + (interaction.name || "control") + '" opens and is usable.',
1944
+ type: "positive",
1945
+ priority: "medium",
1946
+ automationStatus: "needs-review",
1947
+ notes: "Generated from the observed " + interaction.kind + " interaction."
1948
+ });
1949
+ });
1950
+ }
1951
+ function interactionTarget(interaction) {
1952
+ return { role: interaction.role, name: interaction.name || void 0, cssSelector: interaction.cssSelector };
1953
+ }
1954
+ function interactionAction(interaction) {
1955
+ const labels = {
1956
+ dialog: "Open modal or dialog",
1957
+ tab: "Select tab",
1958
+ accordion: "Expand accordion",
1959
+ dropdown: "Open dropdown",
1960
+ drawer: "Open drawer",
1961
+ popover: "Open popover"
1962
+ };
1963
+ return labels[interaction.kind];
1964
+ }
2255
1965
  function requiredFieldRule(ctx, form) {
2256
1966
  const submit = form.submitButtons.find((button) => !button.disabled);
2257
1967
  const fields = form.fields.filter(isUsable);
@@ -2293,19 +2003,34 @@ function formSubmitRule(ctx, form) {
2293
2003
  }
2294
2004
  steps.push({ type: "click", target: toTargetRef(submit) });
2295
2005
  const formName = form.accessibleName || labelOf(submit);
2006
+ const loginForm = isLoginForm(ctx.page, form, fields, submit);
2007
+ const expectedPath = form.action ? pathFromAction(ctx.page.finalUrl, form.action) : void 0;
2008
+ if (loginForm && expectedPath)
2009
+ steps.push({ type: "assertUrl", urlContains: expectedPath });
2296
2010
  return [
2297
2011
  build(ctx, {
2298
- title: `Submit ${formName} with valid data`,
2012
+ title: loginForm ? `Login with valid credentials via ${formName}` : `Submit ${formName} with valid data`,
2299
2013
  preconditions: [...precondition(ctx.page), "Valid test data is prepared"],
2300
2014
  steps,
2301
- expectedResult: UNKNOWN_BEHAVIOUR,
2015
+ expectedResult: loginForm && expectedPath ? `The form is submitted and the browser navigates to ${expectedPath}.` : UNKNOWN_BEHAVIOUR,
2302
2016
  type: "positive",
2303
2017
  priority: "high",
2304
- automationStatus: "needs-data",
2018
+ automationStatus: loginForm ? "ready" : "needs-data",
2305
2019
  notes: "Sample values are placeholders \u2014 replace them with real test data before running."
2306
2020
  })
2307
2021
  ];
2308
2022
  }
2023
+ function isLoginForm(page, form, fields, submit) {
2024
+ const text = [page.finalUrl, page.title, form.name, form.accessibleName, labelOf(submit), ...fields.map(labelOf)].filter(Boolean).join(" ").toLowerCase();
2025
+ return /login|log in|sign in|signin|password/.test(text) && fields.some((field) => field.inputType === "password");
2026
+ }
2027
+ function pathFromAction(pageUrl, action) {
2028
+ try {
2029
+ return new URL(action, pageUrl).pathname;
2030
+ } catch {
2031
+ return void 0;
2032
+ }
2033
+ }
2309
2034
  function navigationRule(ctx) {
2310
2035
  const { page } = ctx;
2311
2036
  const seen = /* @__PURE__ */ new Set();
@@ -2399,6 +2124,7 @@ function generateTestCases(pages, options = {}) {
2399
2124
  ...pageStructureRule(context),
2400
2125
  ...page.forms.flatMap((form) => requiredFieldRule(context, form)),
2401
2126
  ...page.forms.flatMap((form) => formSubmitRule(context, form)),
2127
+ ...interactionRule(context),
2402
2128
  ...navigationRule(context),
2403
2129
  ...destructiveActionRule(context)
2404
2130
  ].slice(0, config2.maxTestCasesPerPage);
@@ -2441,7 +2167,7 @@ function translateStep(step) {
2441
2167
  }
2442
2168
  }
2443
2169
  function translate(value) {
2444
- return value.replace(/^(.+) page displays required controls$/, "$1 \u0E41\u0E2A\u0E14\u0E07 controls \u0E17\u0E35\u0E48\u0E08\u0E33\u0E40\u0E1B\u0E47\u0E19").replace(/^(.+) is required$/, "$1 \u0E40\u0E1B\u0E47\u0E19\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E35\u0E48\u0E08\u0E33\u0E40\u0E1B\u0E47\u0E19").replace(/^Submit (.+) with valid data$/, "\u0E2A\u0E48\u0E07 $1 \u0E14\u0E49\u0E27\u0E22\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E35\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07").replace(/^Navigate to (.+)$/, "\u0E44\u0E1B\u0E22\u0E31\u0E07 $1").replace(/^Verify "(.+)" action \(manual\)$/, '\u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A action "$1" \u0E14\u0E49\u0E27\u0E22\u0E15\u0E19\u0E40\u0E2D\u0E07').replace(/^Open (.+)$/, "\u0E40\u0E1B\u0E34\u0E14 $1").replace(/^The page is reachable and rendered$/, "\u0E2B\u0E19\u0E49\u0E32\u0E40\u0E27\u0E47\u0E1A\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E40\u0E1B\u0E34\u0E14\u0E41\u0E25\u0E30\u0E41\u0E2A\u0E14\u0E07\u0E1C\u0E25\u0E44\u0E14\u0E49").replace(/^Expected behavior is not known from static exploration; review manually\.$/, "\u0E44\u0E21\u0E48\u0E17\u0E23\u0E32\u0E1A behavior \u0E08\u0E32\u0E01\u0E01\u0E32\u0E23\u0E2A\u0E33\u0E23\u0E27\u0E08\u0E41\u0E1A\u0E1A static \u0E01\u0E23\u0E38\u0E13\u0E32\u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A\u0E14\u0E49\u0E27\u0E22\u0E15\u0E19\u0E40\u0E2D\u0E07");
2170
+ return value.replace(/^Login with valid credentials via (.+)$/, "\u0E40\u0E02\u0E49\u0E32\u0E2A\u0E39\u0E48\u0E23\u0E30\u0E1A\u0E1A\u0E14\u0E49\u0E27\u0E22\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E35\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07\u0E1C\u0E48\u0E32\u0E19 $1").replace(/^The form is submitted and the browser navigates to (.+?)[.]?$/, "\u0E1F\u0E2D\u0E23\u0E4C\u0E21\u0E16\u0E39\u0E01\u0E2A\u0E48\u0E07\u0E41\u0E25\u0E30\u0E40\u0E1A\u0E23\u0E32\u0E27\u0E4C\u0E40\u0E0B\u0E2D\u0E23\u0E4C\u0E44\u0E1B\u0E22\u0E31\u0E07 $1").replace(/^(.+) interaction works$/, "\u0E01\u0E32\u0E23\u0E17\u0E33\u0E07\u0E32\u0E19\u0E02\u0E2D\u0E07 $1 \u0E17\u0E33\u0E07\u0E32\u0E19\u0E44\u0E14\u0E49\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07").replace(/^(.+) "(.+)" opens and is usable\.$/, '$1 "$2" \u0E40\u0E1B\u0E34\u0E14\u0E41\u0E25\u0E30\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19\u0E44\u0E14\u0E49').replace(/^Generated from the observed (.+) interaction\.$/, "\u0E2A\u0E23\u0E49\u0E32\u0E07\u0E08\u0E32\u0E01\u0E01\u0E32\u0E23\u0E15\u0E23\u0E27\u0E08\u0E1E\u0E1A interaction \u0E1B\u0E23\u0E30\u0E40\u0E20\u0E17 $1").replace(/^Login with valid credentials via (.+)$/, "\u0E40\u0E02\u0E49\u0E32\u0E2A\u0E39\u0E48\u0E23\u0E30\u0E1A\u0E1A\u0E14\u0E49\u0E27\u0E22\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E35\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07\u0E1C\u0E48\u0E32\u0E19 $1").replace(/^(.+) page displays required controls$/, "$1 \u0E41\u0E2A\u0E14\u0E07\u0E2D\u0E07\u0E04\u0E4C\u0E1B\u0E23\u0E30\u0E01\u0E2D\u0E1A\u0E17\u0E35\u0E48\u0E08\u0E33\u0E40\u0E1B\u0E47\u0E19").replace(/^All (\d+) controls detected on the page are visible\.$/, "\u0E1E\u0E1A\u0E2D\u0E07\u0E04\u0E4C\u0E1B\u0E23\u0E30\u0E01\u0E2D\u0E1A\u0E1A\u0E19\u0E2B\u0E19\u0E49\u0E32\u0E40\u0E27\u0E47\u0E1A\u0E17\u0E31\u0E49\u0E07\u0E2B\u0E21\u0E14 $1 \u0E23\u0E32\u0E22\u0E01\u0E32\u0E23\u0E41\u0E25\u0E30\u0E41\u0E2A\u0E14\u0E07\u0E1C\u0E25\u0E2D\u0E22\u0E39\u0E48").replace(/^(.+) is required$/, "$1 \u0E40\u0E1B\u0E47\u0E19\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E35\u0E48\u0E08\u0E33\u0E40\u0E1B\u0E47\u0E19").replace(/^Submit (.+) with valid data$/, "\u0E2A\u0E48\u0E07 $1 \u0E14\u0E49\u0E27\u0E22\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E35\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07").replace(/^Navigate to (.+)$/, "\u0E44\u0E1B\u0E22\u0E31\u0E07 $1").replace(/^The application is available at (.+)$/, "\u0E23\u0E30\u0E1A\u0E1A\u0E1E\u0E23\u0E49\u0E2D\u0E21\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19\u0E17\u0E35\u0E48 $1").replace(/^The application is available$/, "\u0E23\u0E30\u0E1A\u0E1A\u0E1E\u0E23\u0E49\u0E2D\u0E21\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19").replace(/^Valid test data is prepared$/, "\u0E40\u0E15\u0E23\u0E35\u0E22\u0E21\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E14\u0E2A\u0E2D\u0E1A\u0E17\u0E35\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07\u0E41\u0E25\u0E49\u0E27").replace(/^Disposable test data is prepared$/, "\u0E40\u0E15\u0E23\u0E35\u0E22\u0E21\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E14\u0E2A\u0E2D\u0E1A\u0E17\u0E35\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E25\u0E1A\u0E44\u0E14\u0E49\u0E41\u0E25\u0E49\u0E27").replace(/^Leave "(.+)" empty$/, '\u0E40\u0E27\u0E49\u0E19\u0E0A\u0E48\u0E2D\u0E07 "$1" \u0E27\u0E48\u0E32\u0E07\u0E44\u0E27\u0E49').replace(/^Select "(.+)"$/, '\u0E40\u0E25\u0E37\u0E2D\u0E01 "$1"').replace(/^Verify that a validation message is displayed for the empty required field, and the form is not submitted\.$/, "\u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A\u0E27\u0E48\u0E32\u0E21\u0E35\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21\u0E41\u0E08\u0E49\u0E07\u0E40\u0E15\u0E37\u0E2D\u0E19\u0E2A\u0E33\u0E2B\u0E23\u0E31\u0E1A\u0E0A\u0E48\u0E2D\u0E07\u0E17\u0E35\u0E48\u0E08\u0E33\u0E40\u0E1B\u0E47\u0E19\u0E0B\u0E36\u0E48\u0E07\u0E40\u0E27\u0E49\u0E19\u0E27\u0E48\u0E32\u0E07 \u0E41\u0E25\u0E30\u0E1F\u0E2D\u0E23\u0E4C\u0E21\u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E2A\u0E48\u0E07").replace(/^The browser navigates to (.+) and the page "(.+)" is displayed\.$/, '\u0E40\u0E1A\u0E23\u0E32\u0E27\u0E4C\u0E40\u0E0B\u0E2D\u0E23\u0E4C\u0E44\u0E1B\u0E22\u0E31\u0E07 $1 \u0E41\u0E25\u0E30\u0E41\u0E2A\u0E14\u0E07\u0E2B\u0E19\u0E49\u0E32 "$2"').replace(/^The browser navigates to (.+)\.$/, "\u0E40\u0E1A\u0E23\u0E32\u0E27\u0E4C\u0E40\u0E0B\u0E2D\u0E23\u0E4C\u0E44\u0E1B\u0E22\u0E31\u0E07 $1").replace(/^Dialog "(.+)" is visible\.$/, '\u0E01\u0E25\u0E48\u0E2D\u0E07\u0E42\u0E15\u0E49\u0E15\u0E2D\u0E1A "$1" \u0E41\u0E2A\u0E14\u0E07\u0E2D\u0E22\u0E39\u0E48').replace(/^Validation message "(.+)" is visible\.$/, '\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21\u0E41\u0E08\u0E49\u0E07\u0E40\u0E15\u0E37\u0E2D\u0E19 "$1" \u0E41\u0E2A\u0E14\u0E07\u0E2D\u0E22\u0E39\u0E48').replace(/^Heading "(.+)" is visible\.$/, '\u0E2B\u0E31\u0E27\u0E02\u0E49\u0E2D "$1" \u0E41\u0E2A\u0E14\u0E07\u0E2D\u0E22\u0E39\u0E48').replace(/^Observed state requires tester review before automation\.$/, "\u0E2A\u0E16\u0E32\u0E19\u0E30\u0E17\u0E35\u0E48\u0E1E\u0E1A\u0E15\u0E49\u0E2D\u0E07\u0E43\u0E2B\u0E49\u0E1C\u0E39\u0E49\u0E17\u0E14\u0E2A\u0E2D\u0E1A\u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A\u0E01\u0E48\u0E2D\u0E19\u0E17\u0E33 Automation").replace(/^Verify "(.+)" action \(manual\)$/, '\u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A action "$1" \u0E14\u0E49\u0E27\u0E22\u0E15\u0E19\u0E40\u0E2D\u0E07').replace(/^Open (.+)$/, "\u0E40\u0E1B\u0E34\u0E14 $1").replace(/^The page is reachable and rendered$/, "\u0E2B\u0E19\u0E49\u0E32\u0E40\u0E27\u0E47\u0E1A\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E40\u0E1B\u0E34\u0E14\u0E41\u0E25\u0E30\u0E41\u0E2A\u0E14\u0E07\u0E1C\u0E25\u0E44\u0E14\u0E49").replace(/^Expected behavior is not known from static exploration; review manually\.$/, "\u0E44\u0E21\u0E48\u0E17\u0E23\u0E32\u0E1A\u0E1E\u0E24\u0E15\u0E34\u0E01\u0E23\u0E23\u0E21\u0E08\u0E32\u0E01\u0E01\u0E32\u0E23\u0E2A\u0E33\u0E23\u0E27\u0E08\u0E41\u0E1A\u0E1A static \u0E01\u0E23\u0E38\u0E13\u0E32\u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A\u0E14\u0E49\u0E27\u0E22\u0E15\u0E19\u0E40\u0E2D\u0E07").replace(/^Verify that the result is displayed according to application requirements \(needs review by tester\)\.$/, "\u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A\u0E27\u0E48\u0E32\u0E1C\u0E25\u0E25\u0E31\u0E1E\u0E18\u0E4C\u0E41\u0E2A\u0E14\u0E07\u0E15\u0E32\u0E21\u0E02\u0E49\u0E2D\u0E01\u0E33\u0E2B\u0E19\u0E14\u0E02\u0E2D\u0E07\u0E23\u0E30\u0E1A\u0E1A (\u0E15\u0E49\u0E2D\u0E07\u0E43\u0E2B\u0E49\u0E1C\u0E39\u0E49\u0E17\u0E14\u0E2A\u0E2D\u0E1A\u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A)").replace(/^Generated from elements detected on the page\.$/, "\u0E2A\u0E23\u0E49\u0E32\u0E07\u0E08\u0E32\u0E01\u0E2D\u0E07\u0E04\u0E4C\u0E1B\u0E23\u0E30\u0E01\u0E2D\u0E1A\u0E17\u0E35\u0E48\u0E15\u0E23\u0E27\u0E08\u0E1E\u0E1A\u0E1A\u0E19\u0E2B\u0E19\u0E49\u0E32\u0E40\u0E27\u0E47\u0E1A").replace(/^Evidence: the field has the HTML "required" attribute\.$/, '\u0E2B\u0E25\u0E31\u0E01\u0E10\u0E32\u0E19: \u0E0A\u0E48\u0E2D\u0E07\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E21\u0E35\u0E41\u0E2D\u0E15\u0E17\u0E23\u0E34\u0E1A\u0E34\u0E27\u0E15\u0E4C HTML "required"').replace(/^No "required" attribute found — confirm with the specification whether this field is mandatory\.$/, '\u0E44\u0E21\u0E48\u0E1E\u0E1A\u0E41\u0E2D\u0E15\u0E17\u0E23\u0E34\u0E1A\u0E34\u0E27\u0E15\u0E4C "required" \u2014 \u0E42\u0E1B\u0E23\u0E14\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E01\u0E31\u0E1A\u0E02\u0E49\u0E2D\u0E01\u0E33\u0E2B\u0E19\u0E14\u0E27\u0E48\u0E32\u0E0A\u0E48\u0E2D\u0E07\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E19\u0E35\u0E49\u0E1A\u0E31\u0E07\u0E04\u0E31\u0E1A\u0E01\u0E23\u0E2D\u0E01\u0E2B\u0E23\u0E37\u0E2D\u0E44\u0E21\u0E48').replace(/^Sample values are placeholders — replace them with real test data before running\.$/, "\u0E04\u0E48\u0E32\u0E15\u0E31\u0E27\u0E2D\u0E22\u0E48\u0E32\u0E07\u0E40\u0E1B\u0E47\u0E19\u0E40\u0E1E\u0E35\u0E22\u0E07\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E41\u0E17\u0E19\u0E17\u0E35\u0E48 \u2014 \u0E40\u0E1B\u0E25\u0E35\u0E48\u0E22\u0E19\u0E40\u0E1B\u0E47\u0E19\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E14\u0E2A\u0E2D\u0E1A\u0E08\u0E23\u0E34\u0E07\u0E01\u0E48\u0E2D\u0E19\u0E40\u0E23\u0E34\u0E48\u0E21\u0E17\u0E14\u0E2A\u0E2D\u0E1A").replace(/^Explorer did not open this page — expected result needs review\.$/, "Explorer \u0E44\u0E21\u0E48\u0E44\u0E14\u0E49\u0E40\u0E1B\u0E34\u0E14\u0E2B\u0E19\u0E49\u0E32\u0E19\u0E35\u0E49 \u2014 \u0E1C\u0E25\u0E25\u0E31\u0E1E\u0E18\u0E4C\u0E17\u0E35\u0E48\u0E04\u0E32\u0E14\u0E2B\u0E27\u0E31\u0E07\u0E15\u0E49\u0E2D\u0E07\u0E44\u0E14\u0E49\u0E23\u0E31\u0E1A\u0E01\u0E32\u0E23\u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A").replace(/^Detected as a potentially destructive action — Explorer did not click it\.$/, "\u0E15\u0E23\u0E27\u0E08\u0E1E\u0E1A\u0E27\u0E48\u0E32\u0E2D\u0E32\u0E08\u0E40\u0E1B\u0E47\u0E19\u0E01\u0E32\u0E23\u0E01\u0E23\u0E30\u0E17\u0E33\u0E17\u0E35\u0E48\u0E17\u0E33\u0E25\u0E32\u0E22\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25 \u2014 Explorer \u0E08\u0E36\u0E07\u0E44\u0E21\u0E48\u0E44\u0E14\u0E49\u0E04\u0E25\u0E34\u0E01").replace(/^Manually trigger (.+) "(.+)" in a safe test environment$/, '\u0E2A\u0E31\u0E48\u0E07\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19 $1 "$2" \u0E14\u0E49\u0E27\u0E22\u0E15\u0E19\u0E40\u0E2D\u0E07\u0E43\u0E19\u0E2A\u0E20\u0E32\u0E1E\u0E41\u0E27\u0E14\u0E25\u0E49\u0E2D\u0E21\u0E17\u0E14\u0E2A\u0E2D\u0E1A\u0E17\u0E35\u0E48\u0E1B\u0E25\u0E2D\u0E14\u0E20\u0E31\u0E22');
2445
2171
  }
2446
2172
  function safeNormalize(url) {
2447
2173
  try {
@@ -2529,17 +2255,19 @@ function generateTestData(pages) {
2529
2255
  var UTF8_BOM = "\uFEFF";
2530
2256
  var CSV_COLUMNS = [
2531
2257
  "TC_ID",
2532
- "Module",
2533
2258
  "Folder",
2534
- "Tags",
2535
- "Requirements",
2536
2259
  "Title",
2537
- "Preconditions",
2538
- "Test_Steps",
2539
- "Expected_Result",
2540
2260
  "Type",
2541
2261
  "Priority",
2262
+ "Test_Steps",
2263
+ "Expected_Result",
2542
2264
  "Automation_Status",
2265
+ "Preconditions",
2266
+ "Notes",
2267
+ "Tags",
2268
+ // Canonical fields are retained after the visible table columns so exported suites can be imported losslessly.
2269
+ "Module",
2270
+ "Requirements",
2543
2271
  "Source_URL"
2544
2272
  ];
2545
2273
  var TEST_DATA_CSV_COLUMNS = [
@@ -2562,17 +2290,18 @@ function toRow(values) {
2562
2290
  function testCaseRow(testCase) {
2563
2291
  return toRow([
2564
2292
  testCase.id,
2565
- testCase.module,
2566
- testCase.folder ?? "",
2567
- (testCase.tags ?? []).join(", "),
2568
- (testCase.requirements ?? []).join(", "),
2293
+ testCase.folder ?? testCase.module,
2569
2294
  testCase.title,
2570
- testCase.preconditions.join("\n"),
2571
- describeSteps(testCase.steps),
2572
- testCase.expectedResult,
2573
2295
  testCase.type,
2574
2296
  testCase.priority,
2297
+ describeSteps(testCase.steps),
2298
+ testCase.expectedResult,
2575
2299
  testCase.automationStatus,
2300
+ testCase.preconditions.join("\n"),
2301
+ testCase.notes ?? "",
2302
+ (testCase.tags ?? []).join(", "),
2303
+ testCase.module,
2304
+ (testCase.requirements ?? []).join(", "),
2576
2305
  testCase.sourceUrl
2577
2306
  ]);
2578
2307
  }
@@ -2600,8 +2329,7 @@ function exportTestCasesToCsv(testCases, testData = []) {
2600
2329
  // src/commands/scan.ts
2601
2330
  async function runScan(options) {
2602
2331
  console.log(`checking scan ${redactUrl(options.url)} ...`);
2603
- const useScoped = options.startPath || options.scopePath || options.mode || options.debug;
2604
- const result = useScoped ? await exploreWithScope(options.url, {
2332
+ const result = await exploreWithScope(options.url, {
2605
2333
  startPath: options.startPath,
2606
2334
  scopePath: options.scopePath,
2607
2335
  mode: options.mode ?? "site",
@@ -2615,9 +2343,6 @@ async function runScan(options) {
2615
2343
  maxActionRetries: 2,
2616
2344
  explorationTimeoutMs: 3e5
2617
2345
  }
2618
- }) : await exploreWebsite(options.url, {
2619
- ...options.maxPages !== void 0 ? { maxPages: options.maxPages } : {},
2620
- ...options.maxDepth !== void 0 ? { maxDepth: options.maxDepth } : {}
2621
2346
  });
2622
2347
  const testCases = generateTestCases(result.pages);
2623
2348
  const testData = generateTestData(result.pages);
@@ -3011,20 +2736,39 @@ function registerAnalyzeRoute(app, workspaceRoot) {
3011
2736
  }
3012
2737
  const browserProfileDir = body.projectId ? await browserProfileDirectory(workspaceRoot, body.projectId).catch(() => void 0) : void 0;
3013
2738
  try {
3014
- const result = await exploreWebsite(check.url.toString(), {
3015
- maxPages: clamp(body.maxPages, 1, config.limits.maxPages, config.limits.maxPages),
3016
- maxDepth: clamp(body.maxDepth, 0, config.limits.maxDepth, config.limits.maxDepth),
2739
+ const abortController = new AbortController();
2740
+ let completed = false;
2741
+ request.raw.once("close", () => {
2742
+ if (!completed)
2743
+ abortController.abort();
2744
+ });
2745
+ const result = await exploreWithScope(check.url.toString(), {
2746
+ startPath: body.startPath,
2747
+ scopePath: body.scopePath,
2748
+ mode: body.mode ?? "site",
2749
+ debug: body.debug ?? false,
2750
+ limits: {
2751
+ maxPages: clamp(body.maxPages, 1, config.limits.maxPages, config.limits.maxPages),
2752
+ maxDepth: clamp(body.maxDepth, 0, config.limits.maxDepth, config.limits.maxDepth),
2753
+ maxStates: 80,
2754
+ maxActionsPerState: 8,
2755
+ maxTotalActions: 200,
2756
+ maxActionRetries: 2,
2757
+ explorationTimeoutMs: 3e5
2758
+ }
2759
+ }, {
3017
2760
  waitAfterNavigationMs: clamp(body.waitAfterNavigationMs, 0, 5e3, 750),
3018
2761
  blockedKeywords: normalizeBlockedKeywords(body.blockedKeywords),
2762
+ signal: abortController.signal,
3019
2763
  ...browserProfileDir ? { browserProfileDir } : {}
3020
- }, config.urlPolicy);
2764
+ });
3021
2765
  if (result.pages.length === 0) {
3022
2766
  const firstIssue = result.issues[0];
3023
2767
  throw new ExplorerError(firstIssue?.code ?? "navigation-failed", firstIssue?.message ?? "Could not open the website.", "Check that the URL is correct and the website is available.");
3024
2768
  }
3025
2769
  const testCases = [
3026
2770
  ...generateTestCases(result.pages, { language: body.language ?? "en" }),
3027
- ...generateStateFlowTestCases(result.actionGraph)
2771
+ ...body.language === "th" ? localizeThai(generateStateFlowTestCases(result.actionGraph)) : generateStateFlowTestCases(result.actionGraph)
3028
2772
  ];
3029
2773
  const runEvents = [
3030
2774
  {
@@ -3096,6 +2840,7 @@ function registerAnalyzeRoute(app, workspaceRoot) {
3096
2840
  runEvents,
3097
2841
  apiChecks: body.includeApiChecks ? buildApiChecks(result.pages) : []
3098
2842
  };
2843
+ completed = true;
3099
2844
  return reply.send(response);
3100
2845
  } catch (error) {
3101
2846
  request.log.error({ message: redactSensitiveText(error instanceof Error ? error.message : String(error)) }, "analyze failed");
@@ -3695,8 +3440,6 @@ function debugLocator(stage, detail) {
3695
3440
  console.log(`[LazyScout:${stage}]`, safe);
3696
3441
  }
3697
3442
  async function ensureSafeClick(target, fallbackLabel, blockedKeywords) {
3698
- if (blockedKeywords.length === 0)
3699
- return;
3700
3443
  const labels = await Promise.all([
3701
3444
  target.getAttribute("aria-label").catch(() => null),
3702
3445
  target.getAttribute("title").catch(() => null),
@@ -3704,7 +3447,10 @@ async function ensureSafeClick(target, fallbackLabel, blockedKeywords) {
3704
3447
  target.getAttribute("id").catch(() => null),
3705
3448
  target.innerText().catch(() => "")
3706
3449
  ]);
3707
- if (isBlockedLabel(blockedKeywords, fallbackLabel, ...labels.map((value) => value ?? void 0))) {
3450
+ const values = [fallbackLabel, ...labels.map((value) => value ?? void 0)];
3451
+ if (isUnsafeAutoClick(...values))
3452
+ throw new Error(`Blocked by mandatory safety policy: ${fallbackLabel}`);
3453
+ if (isBlockedLabel(blockedKeywords, ...values)) {
3708
3454
  throw new Error(`Blocked by the Project click filter: ${fallbackLabel}`);
3709
3455
  }
3710
3456
  }
@@ -3721,11 +3467,11 @@ function registerApiCheckRunRoute(app) {
3721
3467
  if (!target.ok)
3722
3468
  return reply.status(400).send({ error: { code: target.code, message: target.message } });
3723
3469
  const method = check.method.toUpperCase();
3724
- if (!SAFE_API_METHODS.has(method))
3470
+ if (!SAFE_API_METHODS.has(method) && !body.allowUnsafe)
3725
3471
  return reply.status(400).send({
3726
3472
  error: {
3727
3473
  code: "unsafe-api-method",
3728
- message: `${method} API checks are observation-only. LazyScout runs only GET, HEAD and OPTIONS automatically.`
3474
+ message: `${method} API checks are protected. Confirm allowUnsafe to run this endpoint once.`
3729
3475
  }
3730
3476
  });
3731
3477
  const token = body.secrets?.apiToken ?? process.env.LAZYSCOUT_API_TOKEN;
@@ -4246,7 +3992,7 @@ async function openInBrowser(url) {
4246
3992
  }
4247
3993
 
4248
3994
  // src/version.ts
4249
- var VERSION = true ? "0.3.4" : "0.0.0-dev";
3995
+ var VERSION = true ? "0.3.7" : "0.0.0-dev";
4250
3996
 
4251
3997
  // src/commands/serve.ts
4252
3998
  var DEFAULT_PORT = 4321;