@silasfmartins/testhub 1.0.3 → 1.0.5

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.
@@ -172,9 +172,8 @@ export declare class WebActions {
172
172
  }>;
173
173
  /** Timestamp do último refreshDOM (debounce para evitar múltiplas chamadas consecutivas) */
174
174
  private static _lastDOMRefreshTime;
175
- /** Guard contra recursão infinita em withRecovery (click_other/navigateTo/switchTo dentro de recovery) */
176
- private static _recoveryDepth;
177
- private static readonly _maxRecoveryDepth;
175
+ /** Lock global: quando true, withRecovery executa fn direto sem entrar em recovery */
176
+ private static _inRecovery;
178
177
  /**
179
178
  * 🔄 Força atualização/estabilização do DOM antes de localizar/interagir com elementos.
180
179
  * Essencial para SPAs (ex.: Salesforce Lightning/Vlocity) que recriam Shadow DOM a cada interação.
@@ -873,9 +873,8 @@ export class WebActions {
873
873
  }
874
874
  /** Timestamp do último refreshDOM (debounce para evitar múltiplas chamadas consecutivas) */
875
875
  static _lastDOMRefreshTime = 0;
876
- /** Guard contra recursão infinita em withRecovery (click_other/navigateTo/switchTo dentro de recovery) */
877
- static _recoveryDepth = 0;
878
- static _maxRecoveryDepth = 1;
876
+ /** Lock global: quando true, withRecovery executa fn direto sem entrar em recovery */
877
+ static _inRecovery = false;
879
878
  /**
880
879
  * 🔄 Força atualização/estabilização do DOM antes de localizar/interagir com elementos.
881
880
  * Essencial para SPAs (ex.: Salesforce Lightning/Vlocity) que recriam Shadow DOM a cada interação.
@@ -978,21 +977,15 @@ export class WebActions {
978
977
  }
979
978
  }
980
979
  static async withRecovery(originalElement, actionName, fn, valueForContext) {
981
- // 🛡️ Guard contra recursão infinita: recovery actions (click_other, navigateTo, switchTo)
982
- // chamam WebActions.click/navigateTo/switchTo que passam por withRecovery novamente.
983
- // Se já estiver dentro de recovery, executar direto sem novo ciclo de recovery.
984
- if (WebActions._recoveryDepth >= WebActions._maxRecoveryDepth) {
980
+ // 🛡️ Guard: se estiver em recovery, executar fn direto sem novo ciclo.
981
+ // Impede a cadeia click→recovery→click_other→click→recovery→... (stack overflow)
982
+ if (WebActions._inRecovery) {
985
983
  const initialCandidate = await WebActions.resolveCandidateForRecovery(originalElement);
986
984
  return await fn(initialCandidate);
987
985
  }
988
- // 🔄 Refresh DOM antes da primeira tentativa — garantir DOM fresco para SPAs/Shadow DOM
989
- // 🛡️ Pular refreshDOM se estiver em contexto de recovery (evitar overhead desnecessário)
990
- if (WebActions._recoveryDepth <= 0) {
991
- await WebActions.refreshDOM(150).catch(() => { });
992
- }
993
- // 🎯 Catalog pre-resolve + lazy auto-refresh (Item 18/20 v2.7.44)
994
- // Se o target for texto/label (não XPath explícito), tentar resolver via catálogo local.
995
- // Na primeira ação de cada URL, popular o catálogo automaticamente.
986
+ // 🔄 Refresh DOM antes da primeira tentativa
987
+ await WebActions.refreshDOM(150).catch(() => { });
988
+ // 🎯 Catalog pre-resolve + lazy auto-refresh
996
989
  if (typeof originalElement === "string") {
997
990
  try {
998
991
  WebActions.ensureCatalogExtractor();
@@ -1011,20 +1004,19 @@ export class WebActions {
1011
1004
  }
1012
1005
  catch { }
1013
1006
  }
1014
- // 🛡️ Flag para rastrear se entramos no bloco de recovery (catch).
1015
- // Sem essa flag, o finally decrementa _recoveryDepth mesmo em chamadas bem-sucedidas,
1016
- // fazendo depth ficar negativo e desabilitando o guard de recursão em falhas futuras.
1017
- let enteredRecovery = false;
1007
+ // 🛡️ Capturar estado do lock ANTES de entrar no try/catch.
1008
+ // Somente quem mudou _inRecovery de false→true pode resetar no finally.
1009
+ const wasAlreadyInRecovery = WebActions._inRecovery;
1018
1010
  try {
1019
1011
  const initialCandidate = await WebActions.resolveCandidateForRecovery(originalElement);
1020
1012
  return await fn(initialCandidate);
1021
1013
  }
1022
1014
  catch (error) {
1023
- enteredRecovery = true;
1024
- // 🔄 Refresh DOM imediato após falha — capturar estado mais recente do Shadow DOM
1015
+ // 🔄 Refresh DOM imediato após falha
1025
1016
  await WebActions.refreshDOM(200).catch(() => { });
1026
- // 🛡️ Incrementar profundidade de recovery para evitar recursão infinita
1027
- WebActions._recoveryDepth++;
1017
+ // 🛡️ Ativar lock click_other/navigateTo/switchTo dentro deste recovery
1018
+ // vão cair no guard acima e executar fn direto, sem nova recovery.
1019
+ WebActions._inRecovery = true;
1028
1020
  try {
1029
1021
  const MIN_CONF = Number(process.env.AUTOCORE_RECOVERY_MIN_CONFIDENCE || "0.7");
1030
1022
  const maxRetries = Number(process.env.AUTOCORE_RECOVERY_MAX_RETRIES || "8");
@@ -1353,11 +1345,10 @@ export class WebActions {
1353
1345
  throw error;
1354
1346
  }
1355
1347
  finally {
1356
- // 🛡️ Decrementar profundidade de recovery SOMENTE se entramos no bloco de recovery.
1357
- // Sem essa condição, chamadas bem-sucedidas decrementam sem ter incrementado,
1358
- // fazendo _recoveryDepth ficar negativo e desabilitando o guard de recursão.
1359
- if (enteredRecovery) {
1360
- WebActions._recoveryDepth--;
1348
+ // 🛡️ resetar o lock se ESTE withRecovery foi quem ativou.
1349
+ // Se estava em recovery antes (wasAlreadyInRecovery), não tocar no lock.
1350
+ if (!wasAlreadyInRecovery) {
1351
+ WebActions._inRecovery = false;
1361
1352
  }
1362
1353
  }
1363
1354
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@silasfmartins/testhub",
3
3
  "description": "Biblioteca de utilitários para automação de testes",
4
- "version": "1.0.3",
4
+ "version": "1.0.5",
5
5
  "author": "Silas Martins Feliciano da Silva <silas.martins2041@gmail.com>",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",