@silasfmartins/testhub 1.0.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.
Files changed (296) hide show
  1. package/.github/copilot-instructions.md +520 -0
  2. package/biome.json +37 -0
  3. package/dist/index.d.ts +45 -0
  4. package/dist/index.js +169 -0
  5. package/dist/scripts/consumer-postinstall.d.ts +15 -0
  6. package/dist/scripts/consumer-postinstall.js +785 -0
  7. package/dist/scripts/generate-docs.d.ts +16 -0
  8. package/dist/scripts/generate-docs.js +1363 -0
  9. package/dist/scripts/generate-index.d.ts +2 -0
  10. package/dist/scripts/generate-index.js +314 -0
  11. package/dist/scripts/init-api.d.ts +2 -0
  12. package/dist/scripts/init-api.js +525 -0
  13. package/dist/scripts/init-banco.d.ts +2 -0
  14. package/dist/scripts/init-banco.js +347 -0
  15. package/dist/scripts/init-frontend.d.ts +2 -0
  16. package/dist/scripts/init-frontend.js +627 -0
  17. package/dist/scripts/init-mobile.d.ts +2 -0
  18. package/dist/scripts/init-mobile.js +481 -0
  19. package/dist/scripts/init-scenarios.d.ts +2 -0
  20. package/dist/scripts/init-scenarios.js +846 -0
  21. package/dist/scripts/init-ssh.d.ts +2 -0
  22. package/dist/scripts/init-ssh.js +639 -0
  23. package/dist/scripts/package-versions.d.ts +57 -0
  24. package/dist/scripts/package-versions.js +768 -0
  25. package/dist/scripts/postinstall.d.ts +1 -0
  26. package/dist/scripts/postinstall.js +527 -0
  27. package/dist/scripts/robust-build.d.ts +7 -0
  28. package/dist/scripts/robust-build.js +88 -0
  29. package/dist/scripts/setup-local-packages.d.ts +31 -0
  30. package/dist/scripts/setup-local-packages.js +237 -0
  31. package/dist/scripts/smart-override.d.ts +2 -0
  32. package/dist/scripts/smart-override.js +1360 -0
  33. package/dist/scripts/sync-configs.d.ts +27 -0
  34. package/dist/scripts/sync-configs.js +248 -0
  35. package/dist/scripts/test-biome-parse.d.ts +5 -0
  36. package/dist/scripts/test-biome-parse.js +84 -0
  37. package/dist/scripts/ultracite-setup.d.ts +4 -0
  38. package/dist/scripts/ultracite-setup.js +310 -0
  39. package/dist/scripts/update-all-init-scripts.d.ts +2 -0
  40. package/dist/scripts/update-all-init-scripts.js +52 -0
  41. package/dist/scripts/update-biome-schema.d.ts +15 -0
  42. package/dist/scripts/update-biome-schema.js +124 -0
  43. package/dist/src/AutoCoreFacade.d.ts +145 -0
  44. package/dist/src/AutoCoreFacade.js +217 -0
  45. package/dist/src/api/ApiActions.d.ts +297 -0
  46. package/dist/src/api/ApiActions.js +1905 -0
  47. package/dist/src/api/Certificate.d.ts +60 -0
  48. package/dist/src/api/Certificate.js +79 -0
  49. package/dist/src/api/JsonResponse.d.ts +116 -0
  50. package/dist/src/api/JsonResponse.js +206 -0
  51. package/dist/src/appium/DeviceFarmViewer.d.ts +79 -0
  52. package/dist/src/appium/DeviceFarmViewer.js +1083 -0
  53. package/dist/src/appium/MobileActions.d.ts +347 -0
  54. package/dist/src/appium/MobileActions.js +1632 -0
  55. package/dist/src/appium/MobileConnection.d.ts +160 -0
  56. package/dist/src/appium/MobileConnection.js +772 -0
  57. package/dist/src/config/envLoader.d.ts +123 -0
  58. package/dist/src/config/envLoader.js +361 -0
  59. package/dist/src/config/jest-safe-setup.d.ts +19 -0
  60. package/dist/src/config/jest-safe-setup.js +369 -0
  61. package/dist/src/config/timeouts.d.ts +32 -0
  62. package/dist/src/config/timeouts.js +38 -0
  63. package/dist/src/desktop/DesktopActions.d.ts +46 -0
  64. package/dist/src/desktop/DesktopActions.js +398 -0
  65. package/dist/src/desktop/DesktopConnection.d.ts +32 -0
  66. package/dist/src/desktop/DesktopConnection.js +84 -0
  67. package/dist/src/domain/entities/TestExecution.d.ts +117 -0
  68. package/dist/src/domain/entities/TestExecution.js +150 -0
  69. package/dist/src/domain/entities/TestReport.d.ts +114 -0
  70. package/dist/src/domain/entities/TestReport.js +179 -0
  71. package/dist/src/domain/repositories/ITestRepository.d.ts +196 -0
  72. package/dist/src/domain/repositories/ITestRepository.js +14 -0
  73. package/dist/src/domain/schemas/ValidationSchemas.d.ts +159 -0
  74. package/dist/src/domain/schemas/ValidationSchemas.js +181 -0
  75. package/dist/src/functions/errors/BaseError.d.ts +78 -0
  76. package/dist/src/functions/errors/BaseError.js +245 -0
  77. package/dist/src/functions/errors/ConfigurationError.d.ts +16 -0
  78. package/dist/src/functions/errors/ConfigurationError.js +48 -0
  79. package/dist/src/functions/errors/ErrorCatalog.d.ts +148 -0
  80. package/dist/src/functions/errors/ErrorCatalog.js +157 -0
  81. package/dist/src/functions/errors/GlobalErrorHandler.d.ts +101 -0
  82. package/dist/src/functions/errors/GlobalErrorHandler.js +281 -0
  83. package/dist/src/functions/errors/IntegrationError.d.ts +17 -0
  84. package/dist/src/functions/errors/IntegrationError.js +51 -0
  85. package/dist/src/functions/errors/SecurityError.d.ts +14 -0
  86. package/dist/src/functions/errors/SecurityError.js +42 -0
  87. package/dist/src/functions/errors/SystemError.d.ts +12 -0
  88. package/dist/src/functions/errors/SystemError.js +36 -0
  89. package/dist/src/functions/errors/ValidationError.d.ts +14 -0
  90. package/dist/src/functions/errors/ValidationError.js +61 -0
  91. package/dist/src/functions/errors/index.d.ts +12 -0
  92. package/dist/src/functions/errors/index.js +13 -0
  93. package/dist/src/global-setup.d.ts +1 -0
  94. package/dist/src/global-setup.js +1037 -0
  95. package/dist/src/helpers/BancoActions.d.ts +188 -0
  96. package/dist/src/helpers/BancoActions.js +581 -0
  97. package/dist/src/helpers/EnviromentHelper.d.ts +17 -0
  98. package/dist/src/helpers/EnviromentHelper.js +66 -0
  99. package/dist/src/helpers/ParallelExecutionHelper.d.ts +183 -0
  100. package/dist/src/helpers/ParallelExecutionHelper.js +375 -0
  101. package/dist/src/helpers/SyncSignal.d.ts +15 -0
  102. package/dist/src/helpers/SyncSignal.js +44 -0
  103. package/dist/src/hubdocs/CategoryDetector.d.ts +83 -0
  104. package/dist/src/hubdocs/CategoryDetector.js +401 -0
  105. package/dist/src/hubdocs/DirectStatementInterceptor.d.ts +54 -0
  106. package/dist/src/hubdocs/DirectStatementInterceptor.js +243 -0
  107. package/dist/src/hubdocs/ExecutionTracker.d.ts +107 -0
  108. package/dist/src/hubdocs/ExecutionTracker.js +702 -0
  109. package/dist/src/hubdocs/HubDocs.d.ts +395 -0
  110. package/dist/src/hubdocs/HubDocs.js +3586 -0
  111. package/dist/src/hubdocs/StatementMethodFilter.d.ts +71 -0
  112. package/dist/src/hubdocs/StatementMethodFilter.js +618 -0
  113. package/dist/src/hubdocs/StatementTracker.d.ts +417 -0
  114. package/dist/src/hubdocs/StatementTracker.js +2419 -0
  115. package/dist/src/hubdocs/SwaggerGenerator.d.ts +59 -0
  116. package/dist/src/hubdocs/SwaggerGenerator.js +405 -0
  117. package/dist/src/hubdocs/index.d.ts +9 -0
  118. package/dist/src/hubdocs/index.js +9 -0
  119. package/dist/src/hubdocs/types.d.ts +114 -0
  120. package/dist/src/hubdocs/types.js +5 -0
  121. package/dist/src/infrastructure/DependencyContainer.d.ts +142 -0
  122. package/dist/src/infrastructure/DependencyContainer.js +250 -0
  123. package/dist/src/infrastructure/adapters/AppiumAdapter.d.ts +168 -0
  124. package/dist/src/infrastructure/adapters/AppiumAdapter.js +468 -0
  125. package/dist/src/infrastructure/adapters/OracleAdapter.d.ts +150 -0
  126. package/dist/src/infrastructure/adapters/OracleAdapter.js +388 -0
  127. package/dist/src/infrastructure/adapters/PlaywrightAdapter.d.ts +192 -0
  128. package/dist/src/infrastructure/adapters/PlaywrightAdapter.js +382 -0
  129. package/dist/src/infrastructure/adapters/SSHAdapter.d.ts +141 -0
  130. package/dist/src/infrastructure/adapters/SSHAdapter.js +428 -0
  131. package/dist/src/interfaces.d.ts +501 -0
  132. package/dist/src/interfaces.js +25 -0
  133. package/dist/src/internal/fakes/__fake-actions__.d.ts +17 -0
  134. package/dist/src/internal/fakes/__fake-actions__.js +21 -0
  135. package/dist/src/internal/fakes/__forbidden__.d.ts +10 -0
  136. package/dist/src/internal/fakes/__forbidden__.js +18 -0
  137. package/dist/src/internal/fakes/__honeypot__.d.ts +15 -0
  138. package/dist/src/internal/fakes/__honeypot__.js +24 -0
  139. package/dist/src/octane/OctaneReporter.d.ts +13 -0
  140. package/dist/src/octane/OctaneReporter.js +61 -0
  141. package/dist/src/playwright/CryptoActions.d.ts +20 -0
  142. package/dist/src/playwright/CryptoActions.js +75 -0
  143. package/dist/src/playwright/EnhancedWebActions.d.ts +7 -0
  144. package/dist/src/playwright/EnhancedWebActions.js +65 -0
  145. package/dist/src/playwright/WebActions.d.ts +1599 -0
  146. package/dist/src/playwright/WebActions.js +11788 -0
  147. package/dist/src/playwright/actions/ActionTimeline.d.ts +36 -0
  148. package/dist/src/playwright/actions/ActionTimeline.js +101 -0
  149. package/dist/src/playwright/actions/RecoveryQueue.d.ts +82 -0
  150. package/dist/src/playwright/actions/RecoveryQueue.js +130 -0
  151. package/dist/src/playwright/actions/SelectorCache.d.ts +53 -0
  152. package/dist/src/playwright/actions/SelectorCache.js +96 -0
  153. package/dist/src/playwright/actions/index.d.ts +13 -0
  154. package/dist/src/playwright/actions/index.js +14 -0
  155. package/dist/src/playwright/actions/types.d.ts +147 -0
  156. package/dist/src/playwright/actions/types.js +5 -0
  157. package/dist/src/playwright/fixtures.d.ts +112 -0
  158. package/dist/src/playwright/fixtures.js +718 -0
  159. package/dist/src/playwright/network-logs-reporter.d.ts +7 -0
  160. package/dist/src/playwright/network-logs-reporter.js +66 -0
  161. package/dist/src/playwright/registerRecoveryWrappers.d.ts +1 -0
  162. package/dist/src/playwright/registerRecoveryWrappers.js +54 -0
  163. package/dist/src/security/BuildSecurity.d.ts +12 -0
  164. package/dist/src/security/BuildSecurity.js +138 -0
  165. package/dist/src/security/EulaProtection.d.ts +70 -0
  166. package/dist/src/security/EulaProtection.js +155 -0
  167. package/dist/src/security/HoneypotManager.d.ts +46 -0
  168. package/dist/src/security/HoneypotManager.js +234 -0
  169. package/dist/src/security/KeysManager.d.ts +36 -0
  170. package/dist/src/security/KeysManager.js +158 -0
  171. package/dist/src/security/ProofOfWorkIntegration.d.ts +64 -0
  172. package/dist/src/security/ProofOfWorkIntegration.js +206 -0
  173. package/dist/src/security/SecurityValidation.d.ts +21 -0
  174. package/dist/src/security/SecurityValidation.js +163 -0
  175. package/dist/src/security/SourceMapProtection.d.ts +55 -0
  176. package/dist/src/security/SourceMapProtection.js +220 -0
  177. package/dist/src/security/protector.d.ts +1 -0
  178. package/dist/src/security/protector.js +97 -0
  179. package/dist/src/ssh/SSHActions.d.ts +262 -0
  180. package/dist/src/ssh/SSHActions.js +790 -0
  181. package/dist/src/ssh/SSHClient.d.ts +99 -0
  182. package/dist/src/ssh/SSHClient.js +409 -0
  183. package/dist/src/statements/BaseStatement.d.ts +38 -0
  184. package/dist/src/statements/BaseStatement.js +78 -0
  185. package/dist/src/testContext/AuthStateManager.d.ts +93 -0
  186. package/dist/src/testContext/AuthStateManager.js +256 -0
  187. package/dist/src/testContext/CoverageManager.d.ts +198 -0
  188. package/dist/src/testContext/CoverageManager.js +917 -0
  189. package/dist/src/testContext/TestAnnotations.d.ts +476 -0
  190. package/dist/src/testContext/TestAnnotations.js +2647 -0
  191. package/dist/src/testContext/TestContext.d.ts +138 -0
  192. package/dist/src/testContext/TestContext.js +369 -0
  193. package/dist/src/testContext/UnifiedHtmlGenerator.d.ts +7 -0
  194. package/dist/src/testContext/UnifiedHtmlGenerator.js +264 -0
  195. package/dist/src/testContext/UnifiedReportManager.d.ts +211 -0
  196. package/dist/src/testContext/UnifiedReportManager.js +1206 -0
  197. package/dist/src/testhub/DynamicConfigManager.d.ts +121 -0
  198. package/dist/src/testhub/DynamicConfigManager.js +320 -0
  199. package/dist/src/testhub/SystemsManager.d.ts +119 -0
  200. package/dist/src/testhub/SystemsManager.js +365 -0
  201. package/dist/src/testhub/TestHubClient.d.ts +335 -0
  202. package/dist/src/testhub/TestHubClient.js +1215 -0
  203. package/dist/src/testhub/TestHubReporter.d.ts +62 -0
  204. package/dist/src/testhub/TestHubReporter.js +576 -0
  205. package/dist/src/testhub/TestHubVars.d.ts +116 -0
  206. package/dist/src/testhub/TestHubVars.js +273 -0
  207. package/dist/src/utils/ActionInterceptor.d.ts +59 -0
  208. package/dist/src/utils/ActionInterceptor.js +741 -0
  209. package/dist/src/utils/ArtifactsCompressor.d.ts +43 -0
  210. package/dist/src/utils/ArtifactsCompressor.js +181 -0
  211. package/dist/src/utils/AutoLogsFinal.d.ts +47 -0
  212. package/dist/src/utils/AutoLogsFinal.js +148 -0
  213. package/dist/src/utils/CodeGenSession.d.ts +114 -0
  214. package/dist/src/utils/CodeGenSession.js +264 -0
  215. package/dist/src/utils/ConfigLogger.d.ts +133 -0
  216. package/dist/src/utils/ConfigLogger.js +611 -0
  217. package/dist/src/utils/CustomReporter.d.ts +22 -0
  218. package/dist/src/utils/CustomReporter.js +352 -0
  219. package/dist/src/utils/DataStore.d.ts +171 -0
  220. package/dist/src/utils/DataStore.js +484 -0
  221. package/dist/src/utils/DatabaseInterceptor.d.ts +19 -0
  222. package/dist/src/utils/DatabaseInterceptor.js +295 -0
  223. package/dist/src/utils/DateHelper.d.ts +16 -0
  224. package/dist/src/utils/DateHelper.js +120 -0
  225. package/dist/src/utils/DateValidator.d.ts +4 -0
  226. package/dist/src/utils/DateValidator.js +51 -0
  227. package/dist/src/utils/DocumentGenerator.d.ts +35 -0
  228. package/dist/src/utils/DocumentGenerator.js +129 -0
  229. package/dist/src/utils/EvidenceCapture.d.ts +90 -0
  230. package/dist/src/utils/EvidenceCapture.js +600 -0
  231. package/dist/src/utils/EvidenceReportGenerator.d.ts +70 -0
  232. package/dist/src/utils/EvidenceReportGenerator.js +799 -0
  233. package/dist/src/utils/FrameManagementUtil.d.ts +42 -0
  234. package/dist/src/utils/FrameManagementUtil.js +75 -0
  235. package/dist/src/utils/GlobalStatementsInterceptor.d.ts +1 -0
  236. package/dist/src/utils/GlobalStatementsInterceptor.js +1 -0
  237. package/dist/src/utils/HTMLTemplate.d.ts +1 -0
  238. package/dist/src/utils/HTMLTemplate.js +1034 -0
  239. package/dist/src/utils/InterceptacaoMagica.d.ts +23 -0
  240. package/dist/src/utils/InterceptacaoMagica.js +365 -0
  241. package/dist/src/utils/LogSanitizer.d.ts +35 -0
  242. package/dist/src/utils/LogSanitizer.js +110 -0
  243. package/dist/src/utils/Logger.d.ts +65 -0
  244. package/dist/src/utils/Logger.js +284 -0
  245. package/dist/src/utils/McpLocalClient.d.ts +141 -0
  246. package/dist/src/utils/McpLocalClient.js +871 -0
  247. package/dist/src/utils/PDFEvidenceGenerator.d.ts +20 -0
  248. package/dist/src/utils/PDFEvidenceGenerator.js +156 -0
  249. package/dist/src/utils/SpecFileAnalyzer.d.ts +35 -0
  250. package/dist/src/utils/SpecFileAnalyzer.js +209 -0
  251. package/dist/src/utils/StatementInterceptor.d.ts +18 -0
  252. package/dist/src/utils/StatementInterceptor.js +87 -0
  253. package/dist/src/utils/StatementLogger.d.ts +33 -0
  254. package/dist/src/utils/StatementLogger.js +113 -0
  255. package/dist/src/utils/StatementsInterceptor.d.ts +1 -0
  256. package/dist/src/utils/StatementsInterceptor.js +1 -0
  257. package/dist/src/utils/TeamsFlushHook.d.ts +17 -0
  258. package/dist/src/utils/TeamsFlushHook.js +168 -0
  259. package/dist/src/utils/TerminalLogCapture.d.ts +158 -0
  260. package/dist/src/utils/TerminalLogCapture.js +531 -0
  261. package/dist/src/utils/TestMethodLogger.d.ts +70 -0
  262. package/dist/src/utils/TestMethodLogger.js +95 -0
  263. package/dist/src/utils/UnifiedTeardown.d.ts +4 -0
  264. package/dist/src/utils/UnifiedTeardown.js +400 -0
  265. package/dist/src/utils/XPathCatalog.d.ts +152 -0
  266. package/dist/src/utils/XPathCatalog.js +350 -0
  267. package/dist/src/utils/generators.d.ts +90 -0
  268. package/dist/src/utils/generators.js +167 -0
  269. package/dist/src/utils/testRecovery/ResilientPlaywright.d.ts +152 -0
  270. package/dist/src/utils/testRecovery/ResilientPlaywright.js +715 -0
  271. package/dist/src/utils/testRecovery/TestRecoveryClient.d.ts +801 -0
  272. package/dist/src/utils/testRecovery/TestRecoveryClient.js +1415 -0
  273. package/dist/src/utils/testRecovery/autoFixCode.d.ts +65 -0
  274. package/dist/src/utils/testRecovery/autoFixCode.js +32 -0
  275. package/dist/vitest.config.d.ts +2 -0
  276. package/dist/vitest.config.js +59 -0
  277. package/dist/wdio.conf.d.ts +1 -0
  278. package/dist/wdio.conf.js +420 -0
  279. package/package.json +137 -0
  280. package/protect-loader.mjs +643 -0
  281. package/scripts/consumer-postinstall.ts +975 -0
  282. package/scripts/generate-index.ts +343 -0
  283. package/scripts/init-api.ts +613 -0
  284. package/scripts/init-banco.ts +437 -0
  285. package/scripts/init-frontend.ts +727 -0
  286. package/scripts/init-mobile.ts +558 -0
  287. package/scripts/init-scenarios.ts +925 -0
  288. package/scripts/init-ssh.ts +734 -0
  289. package/scripts/package-versions.ts +978 -0
  290. package/scripts/postinstall.ts +605 -0
  291. package/scripts/smart-override.ts +1675 -0
  292. package/scripts/sync-configs.ts +302 -0
  293. package/scripts/ultracite-setup.ts +370 -0
  294. package/src/types/globals.d.ts +48 -0
  295. package/tsconfig.json +29 -0
  296. package/types/autocore-sync-signal.d.ts +10 -0
@@ -0,0 +1,21 @@
1
+ /**
2
+ * AutoCore Security: Proof-of-Work e validações por método
3
+ * Sistema de desafios leves para detectar uso automatizado em massa
4
+ */
5
+ /**
6
+ * Validação principal de segurança por método
7
+ */
8
+ export declare function validateMethodSecurity(methodName: string): boolean;
9
+ /**
10
+ * Wrapper para proteção de métodos
11
+ */
12
+ export declare function protectMethod<T extends unknown[], R>(methodName: string, originalMethod: (...args: T) => R, fallback?: (...args: T) => R): (...args: T) => R;
13
+ /**
14
+ * Estado atual da segurança
15
+ */
16
+ export declare function getSecurityState(): {
17
+ degraded: boolean;
18
+ reason: string;
19
+ callCounts: Record<string, number>;
20
+ powSolved: string[];
21
+ };
@@ -0,0 +1,163 @@
1
+ /**
2
+ * AutoCore Security: Proof-of-Work e validações por método
3
+ * Sistema de desafios leves para detectar uso automatizado em massa
4
+ */
5
+ import { createHash, randomBytes } from 'node:crypto';
6
+ const state = {
7
+ initialized: false,
8
+ degraded: false,
9
+ powSolved: new Map(),
10
+ callCounts: new Map(),
11
+ lastCall: new Map(),
12
+ startTime: Date.now(),
13
+ };
14
+ /**
15
+ * Prova de trabalho leve: encontrar hash com N zeros à esquerda
16
+ */
17
+ function solveProofOfWork(difficulty, context) {
18
+ if (difficulty <= 0 || difficulty > 4)
19
+ return true;
20
+ const nonce = randomBytes(4).toString('hex');
21
+ const target = '0'.repeat(difficulty);
22
+ const maxAttempts = difficulty === 1 ? 1000 : difficulty === 2 ? 5000 : 10_000;
23
+ for (let i = 0; i < maxAttempts; i++) {
24
+ const hash = createHash('sha256')
25
+ .update(`${context}:${nonce}:${i}`)
26
+ .digest('hex');
27
+ if (hash.startsWith(target)) {
28
+ return true;
29
+ }
30
+ }
31
+ return false;
32
+ }
33
+ /**
34
+ * Detecta padrões de uso automatizado
35
+ */
36
+ function detectAutomationPatterns(methodName) {
37
+ const now = Date.now();
38
+ // Rate limiting: máximo 10 calls por segundo por método
39
+ const count = state.callCounts.get(methodName) || 0;
40
+ const lastCall = state.lastCall.get(methodName) || 0;
41
+ if (now - lastCall < 100) {
42
+ // < 100ms entre calls
43
+ state.callCounts.set(methodName, count + 1);
44
+ if (count > 10) {
45
+ return true; // Muito rápido, suspeito
46
+ }
47
+ }
48
+ else {
49
+ state.callCounts.set(methodName, 1);
50
+ }
51
+ state.lastCall.set(methodName, now);
52
+ // Detectar startup muito rápido (possível automação)
53
+ if (now - state.startTime < 1000 && count > 5) {
54
+ return true;
55
+ }
56
+ return false;
57
+ }
58
+ /**
59
+ * Verificar ambiente de execução
60
+ */
61
+ function detectExecutionEnvironment() {
62
+ // Verificar variáveis típicas de desenvolvimento
63
+ const devVars = [
64
+ 'VSCODE_PID',
65
+ 'VSCODE_HANDLES_UNCAUGHT_ERRORS',
66
+ 'PLAYWRIGHT_BROWSERS_PATH',
67
+ 'APPIUM_HOME',
68
+ 'NODE_ENV',
69
+ 'DEBUG',
70
+ ];
71
+ const hasDevEnv = devVars.some((v) => process.env[v]);
72
+ // Verificar se está em ambiente interativo
73
+ const isInteractive = process.stdout.isTTY || Boolean(process.env.TERM);
74
+ // Suspeito se não tem ambiente dev e não é interativo
75
+ return !(hasDevEnv || isInteractive);
76
+ }
77
+ /**
78
+ * Validação principal de segurança por método
79
+ */
80
+ export function validateMethodSecurity(methodName) {
81
+ if (!state.initialized) {
82
+ state.initialized = true;
83
+ // Verificar modo degradado global
84
+ if (process.env.AUTOCORE_DEGRADED_MODE === 'true') {
85
+ state.degraded = true;
86
+ return false;
87
+ }
88
+ // Verificar honeypot
89
+ if (process.env.AUTOCORE_HONEYPOT_TRIPPED === 'true') {
90
+ state.degraded = true;
91
+ return false;
92
+ }
93
+ // Verificar ambiente
94
+ if (detectExecutionEnvironment()) {
95
+ state.degraded = true;
96
+ process.env.AUTOCORE_DEGRADED_MODE = 'true';
97
+ process.env.AUTOCORE_DEGRADED_REASON = 'suspicious_environment';
98
+ return false;
99
+ }
100
+ }
101
+ if (state.degraded)
102
+ return false;
103
+ // Detectar padrões de automação
104
+ if (detectAutomationPatterns(methodName)) {
105
+ state.degraded = true;
106
+ process.env.AUTOCORE_DEGRADED_MODE = 'true';
107
+ process.env.AUTOCORE_DEGRADED_REASON = 'automation_pattern_detected';
108
+ return false;
109
+ }
110
+ // Proof-of-work para métodos críticos
111
+ const criticalMethods = [
112
+ 'validateDashboardLoaded',
113
+ 'navigateToSection',
114
+ 'executeApiRequest',
115
+ 'connectToDatabase',
116
+ 'executeSSHCommand',
117
+ 'takeScreenshot',
118
+ ];
119
+ if (criticalMethods.includes(methodName)) {
120
+ const powDifficulty = Number(process.env.AUTOCORE_POW_DIFFICULTY || '1');
121
+ const solved = state.powSolved.get(methodName) || 0;
122
+ if (solved < 1 && powDifficulty > 0) {
123
+ const success = solveProofOfWork(powDifficulty, methodName);
124
+ if (!success) {
125
+ state.degraded = true;
126
+ process.env.AUTOCORE_DEGRADED_MODE = 'true';
127
+ process.env.AUTOCORE_DEGRADED_REASON = 'pow_failed';
128
+ return false;
129
+ }
130
+ state.powSolved.set(methodName, 1);
131
+ }
132
+ }
133
+ return true;
134
+ }
135
+ /**
136
+ * Wrapper para proteção de métodos
137
+ */
138
+ export function protectMethod(methodName, originalMethod, fallback) {
139
+ return (...args) => {
140
+ if (process.env.AUTOCORE_SECURITY_DISABLED === 'true') {
141
+ return originalMethod(...args);
142
+ }
143
+ if (!validateMethodSecurity(methodName)) {
144
+ if (fallback) {
145
+ return fallback(...args);
146
+ }
147
+ // Retorno seguro sem quebrar o código do usuário
148
+ return undefined;
149
+ }
150
+ return originalMethod(...args);
151
+ };
152
+ }
153
+ /**
154
+ * Estado atual da segurança
155
+ */
156
+ export function getSecurityState() {
157
+ return {
158
+ degraded: state.degraded,
159
+ reason: process.env.AUTOCORE_DEGRADED_REASON || '',
160
+ callCounts: Object.fromEntries(state.callCounts),
161
+ powSolved: Array.from(state.powSolved.keys()),
162
+ };
163
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * SourceMapProtection: Injeção de metadados de proteção em source maps
3
+ * Detecta alterações e manipulações através de checksums e tokens
4
+ */
5
+ export declare class SourceMapProtection {
6
+ private static readonly RBQA_TOKEN_PREFIX;
7
+ private static readonly CHECKSUM_LENGTH;
8
+ /**
9
+ * Processa todos os source maps em um diretório
10
+ */
11
+ static processDirectory(buildDir: string): void;
12
+ /**
13
+ * Injeta proteção em um source map específico
14
+ */
15
+ static injectProtection(sourceMapPath: string): boolean;
16
+ /**
17
+ * Verifica integridade de um source map
18
+ */
19
+ static verifyIntegrity(sourceMapPath: string): boolean;
20
+ /**
21
+ * Encontra todos os source maps em um diretório
22
+ */
23
+ private static findSourceMaps;
24
+ /**
25
+ * Gera token único para source map
26
+ */
27
+ private static generateToken;
28
+ /**
29
+ * Gera checksum para conteúdo
30
+ */
31
+ private static generateChecksum;
32
+ /**
33
+ * Cria arquivo de integridade associado
34
+ */
35
+ private static createIntegrityFile;
36
+ /**
37
+ * Hook para build tools (webpack, rollup, etc.)
38
+ */
39
+ static createWebpackPlugin(): {
40
+ name: string;
41
+ apply(compiler: any): void;
42
+ };
43
+ /**
44
+ * Hook para Rollup
45
+ */
46
+ static createRollupPlugin(): {
47
+ name: string;
48
+ writeBundle(options: any): void;
49
+ };
50
+ /**
51
+ * Verificação automática na inicialização
52
+ */
53
+ static autoVerifyOnLoad(): void;
54
+ }
55
+ export default SourceMapProtection;
@@ -0,0 +1,220 @@
1
+ /**
2
+ * SourceMapProtection: Injeção de metadados de proteção em source maps
3
+ * Detecta alterações e manipulações através de checksums e tokens
4
+ */
5
+ import { createHash, randomBytes } from 'node:crypto';
6
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
7
+ import { basename, dirname } from 'node:path';
8
+ import { HoneypotManager } from './HoneypotManager.js';
9
+ import { Logger } from '../utils/Logger.js';
10
+ export class SourceMapProtection {
11
+ static RBQA_TOKEN_PREFIX = 'rbqa_';
12
+ static CHECKSUM_LENGTH = 16;
13
+ /**
14
+ * Processa todos os source maps em um diretório
15
+ */
16
+ static processDirectory(buildDir) {
17
+ try {
18
+ const fs = require('node:fs');
19
+ const path = require('node:path');
20
+ // Buscar arquivos .js.map recursivamente
21
+ SourceMapProtection.findSourceMaps(buildDir).forEach((mapFile) => {
22
+ SourceMapProtection.injectProtection(mapFile);
23
+ });
24
+ Logger.info(`AutoCore: Source maps protegidos em ${buildDir}`);
25
+ }
26
+ catch (error) {
27
+ Logger.warning(`AutoCore: Erro ao proteger source maps: ${error}`);
28
+ }
29
+ }
30
+ /**
31
+ * Injeta proteção em um source map específico
32
+ */
33
+ static injectProtection(sourceMapPath) {
34
+ try {
35
+ if (!existsSync(sourceMapPath))
36
+ return false;
37
+ const content = readFileSync(sourceMapPath, 'utf8');
38
+ const sourceMap = JSON.parse(content);
39
+ // Verificar se já está protegido
40
+ if (sourceMap['x-rbqa-token']) {
41
+ return true; // já protegido
42
+ }
43
+ // Injetar metadados de proteção
44
+ const token = SourceMapProtection.generateToken();
45
+ const checksum = SourceMapProtection.generateChecksum(content);
46
+ const timestamp = Date.now();
47
+ sourceMap['x-rbqa-token'] = token;
48
+ sourceMap['x-rbqa-checksum'] = checksum;
49
+ sourceMap['x-rbqa-timestamp'] = timestamp;
50
+ sourceMap['x-rbqa-version'] = '1.0.0';
51
+ // Marcar source map com caracteres invisíveis
52
+ const protectedContent = HoneypotManager.injectInvisibleMarkers(JSON.stringify(sourceMap, null, 2), `sourcemap_${basename(sourceMapPath)}`);
53
+ writeFileSync(sourceMapPath, protectedContent);
54
+ // Criar arquivo de integridade associado
55
+ SourceMapProtection.createIntegrityFile(sourceMapPath, token, checksum);
56
+ return true;
57
+ }
58
+ catch (error) {
59
+ Logger.warning(`AutoCore: Erro ao proteger ${sourceMapPath}: ${error}`);
60
+ return false;
61
+ }
62
+ }
63
+ /**
64
+ * Verifica integridade de um source map
65
+ */
66
+ static verifyIntegrity(sourceMapPath) {
67
+ try {
68
+ if (!existsSync(sourceMapPath))
69
+ return false;
70
+ const content = readFileSync(sourceMapPath, 'utf8');
71
+ const sourceMap = JSON.parse(content);
72
+ // Verificar se tem metadados de proteção
73
+ const token = sourceMap['x-rbqa-token'];
74
+ const storedChecksum = sourceMap['x-rbqa-checksum'];
75
+ if (!(token && storedChecksum)) {
76
+ HoneypotManager.tripHoneypot(`sourcemap_unprotected_${basename(sourceMapPath)}`);
77
+ return false;
78
+ }
79
+ // Calcular checksum atual (removendo metadados)
80
+ const originalMap = { ...sourceMap };
81
+ delete originalMap['x-rbqa-token'];
82
+ delete originalMap['x-rbqa-checksum'];
83
+ delete originalMap['x-rbqa-timestamp'];
84
+ delete originalMap['x-rbqa-version'];
85
+ const currentChecksum = SourceMapProtection.generateChecksum(JSON.stringify(originalMap));
86
+ if (currentChecksum !== storedChecksum) {
87
+ HoneypotManager.tripHoneypot(`sourcemap_tampered_${basename(sourceMapPath)}`);
88
+ return false;
89
+ }
90
+ // Verificar arquivo de integridade
91
+ const integrityFile = sourceMapPath + '.rbqa';
92
+ if (existsSync(integrityFile)) {
93
+ const integrityData = JSON.parse(readFileSync(integrityFile, 'utf8'));
94
+ if (integrityData.token !== token) {
95
+ HoneypotManager.tripHoneypot(`sourcemap_integrity_mismatch_${basename(sourceMapPath)}`);
96
+ return false;
97
+ }
98
+ }
99
+ return true;
100
+ }
101
+ catch (error) {
102
+ HoneypotManager.tripHoneypot(`sourcemap_verify_error_${basename(sourceMapPath)}`);
103
+ return false;
104
+ }
105
+ }
106
+ /**
107
+ * Encontra todos os source maps em um diretório
108
+ */
109
+ static findSourceMaps(dir, maps = []) {
110
+ try {
111
+ const fs = require('node:fs');
112
+ const path = require('node:path');
113
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
114
+ for (const entry of entries) {
115
+ const fullPath = path.join(dir, entry.name);
116
+ if (entry.isDirectory() && !entry.name.startsWith('.')) {
117
+ SourceMapProtection.findSourceMaps(fullPath, maps);
118
+ }
119
+ else if (entry.isFile() && entry.name.endsWith('.js.map')) {
120
+ maps.push(fullPath);
121
+ }
122
+ }
123
+ return maps;
124
+ }
125
+ catch {
126
+ return maps;
127
+ }
128
+ }
129
+ /**
130
+ * Gera token único para source map
131
+ */
132
+ static generateToken() {
133
+ const timestamp = Date.now().toString(36);
134
+ const random = randomBytes(8).toString('hex');
135
+ return `${SourceMapProtection.RBQA_TOKEN_PREFIX}${timestamp}_${random}`;
136
+ }
137
+ /**
138
+ * Gera checksum para conteúdo
139
+ */
140
+ static generateChecksum(content) {
141
+ return createHash('sha256')
142
+ .update(content)
143
+ .digest('hex')
144
+ .substring(0, SourceMapProtection.CHECKSUM_LENGTH);
145
+ }
146
+ /**
147
+ * Cria arquivo de integridade associado
148
+ */
149
+ static createIntegrityFile(sourceMapPath, token, checksum) {
150
+ try {
151
+ const integrityPath = sourceMapPath + '.rbqa';
152
+ const integrityData = {
153
+ token,
154
+ checksum,
155
+ timestamp: Date.now(),
156
+ sourceMap: basename(sourceMapPath),
157
+ version: '1.0.0',
158
+ };
159
+ writeFileSync(integrityPath, JSON.stringify(integrityData, null, 2));
160
+ }
161
+ catch {
162
+ // falha silenciosa
163
+ }
164
+ }
165
+ /**
166
+ * Hook para build tools (webpack, rollup, etc.)
167
+ */
168
+ static createWebpackPlugin() {
169
+ return {
170
+ name: 'autocore-sourcemap-protection',
171
+ apply(compiler) {
172
+ compiler.hooks.afterEmit.tap('AutoCoreProtection', () => {
173
+ const outputPath = compiler.options.output?.path;
174
+ if (outputPath) {
175
+ SourceMapProtection.processDirectory(outputPath);
176
+ }
177
+ });
178
+ },
179
+ };
180
+ }
181
+ /**
182
+ * Hook para Rollup
183
+ */
184
+ static createRollupPlugin() {
185
+ return {
186
+ name: 'autocore-sourcemap-protection',
187
+ writeBundle(options) {
188
+ const outputDir = options.dir || dirname(options.file || '');
189
+ if (outputDir) {
190
+ SourceMapProtection.processDirectory(outputDir);
191
+ }
192
+ },
193
+ };
194
+ }
195
+ /**
196
+ * Verificação automática na inicialização
197
+ */
198
+ static autoVerifyOnLoad() {
199
+ try {
200
+ // Verificar source maps em diretórios comuns
201
+ const commonDirs = ['dist', 'build', 'lib', 'out'];
202
+ for (const dir of commonDirs) {
203
+ if (existsSync(dir)) {
204
+ const maps = SourceMapProtection.findSourceMaps(dir);
205
+ maps.forEach((map) => {
206
+ if (!SourceMapProtection.verifyIntegrity(map)) {
207
+ Logger.warning(`⚠️ AutoCore: Source map ${map} pode ter sido modificado`);
208
+ }
209
+ });
210
+ }
211
+ }
212
+ }
213
+ catch {
214
+ // falha silenciosa
215
+ }
216
+ }
217
+ }
218
+ // Auto-verificação na importação
219
+ SourceMapProtection.autoVerifyOnLoad();
220
+ export default SourceMapProtection;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,97 @@
1
+ /*
2
+ AutoCore Security Protector (Zero-Touch, Offline)
3
+ - Side-effect only. Safe, lightweight, and fully offline.
4
+ - Does NOT change user test code behavior.
5
+ - Can be disabled via env: AUTOCORE_SECURITY_DISABLED=true
6
+
7
+ Features (minimal bootstrap):
8
+ - Watermark & integrity hints (best-effort)
9
+ - Basic runtime heuristics (anti-automation toggles)
10
+ - Degraded mode flagging when tampering is suspected
11
+ - EULA reminder gate (informational only)
12
+ - Honeypot management and verification
13
+ */
14
+ import { HoneypotManager } from './HoneypotManager.js';
15
+ import fs from 'node:fs';
16
+ import path from 'node:path';
17
+ import { Logger } from '../utils/Logger.js';
18
+ (async () => {
19
+ try {
20
+ if (process.env.AUTOCORE_SECURITY_DISABLED === 'true')
21
+ return;
22
+ const startedAt = Date.now();
23
+ const ctx = {
24
+ degraded: false,
25
+ reason: '',
26
+ };
27
+ // 1) Attempt to read package.json watermark (best-effort, no throw)
28
+ try {
29
+ const pkgPath = path.resolve(process.cwd(), 'package.json');
30
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
31
+ if (fs.existsSync(pkgPath)) {
32
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
33
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
34
+ ctx.pkgName = pkg?.name;
35
+ ctx.watermark = (pkg?.autocoreWatermark || pkg?._autocore?.watermark);
36
+ }
37
+ }
38
+ catch {
39
+ // no-op
40
+ }
41
+ // 2) Lightweight heuristic: detect extremely slow startup (possible hook/tamper)
42
+ const bootMs = Date.now() - startedAt;
43
+ if (bootMs > 3000) {
44
+ ctx.degraded = true;
45
+ ctx.reason = 'slow_boot';
46
+ }
47
+ // 3) Check for honeypot activation
48
+ if (HoneypotManager.isTripped()) {
49
+ ctx.degraded = true;
50
+ ctx.reason = 'honeypot_triggered';
51
+ Logger.warning('⚠️ AutoCore: Honeypot ativado - modo degradado ativado');
52
+ }
53
+ // 4) Verificar integridade de arquivos críticos (somente em produção)
54
+ if (process.env.NODE_ENV === 'production' &&
55
+ !process.env.CI &&
56
+ !process.env.VSCODE_PID) {
57
+ try {
58
+ const criticalFiles = ['package.json', 'tsconfig.json', '.gitignore'];
59
+ for (const file of criticalFiles) {
60
+ if (!HoneypotManager.verifyFileIntegrity(file) &&
61
+ process.env.AUTOCORE_DEBUG_LOGS) {
62
+ Logger.warning(`⚠️ AutoCore: Arquivo ${file} pode ter sido modificado`);
63
+ }
64
+ }
65
+ }
66
+ catch {
67
+ // no-op
68
+ }
69
+ }
70
+ // 5) Optional EULA notice (informational only)
71
+ if (process.env.AUTOCORE_EULA_REQUIRED === 'true' &&
72
+ process.env.AUTOCORE_EULA_ACCEPTED !== 'true') {
73
+ ctx.degraded = true;
74
+ ctx.reason = ctx.reason || 'eula_not_accepted';
75
+ }
76
+ // 6) Expose state for internal consumers (without globals pollution)
77
+ if (ctx.degraded) {
78
+ process.env.AUTOCORE_DEGRADED_MODE = 'true';
79
+ if (!process.env.AUTOCORE_DEGRADED_REASON) {
80
+ process.env.AUTOCORE_DEGRADED_REASON = ctx.reason || 'unknown';
81
+ }
82
+ }
83
+ // 5) Minimal telemetry-free breadcrumb (local only, no I/O)
84
+ process.env.AUTOCORE_SECURITY_LOADED = 'true';
85
+ // Optional: very small delay to desync simplistic automation (configurable)
86
+ const jitter = Number(process.env.AUTOCORE_SECURITY_JITTER_MS || '0');
87
+ if (jitter > 0 && jitter < 200) {
88
+ const stop = Date.now() + jitter;
89
+ while (Date.now() < stop) {
90
+ // no-op
91
+ }
92
+ }
93
+ }
94
+ catch {
95
+ // Never break consumer code
96
+ }
97
+ })();