@resolveio/server-lib 22.3.70 → 22.3.72
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/methods/ai-terminal.d.ts +1 -0
- package/methods/ai-terminal.js +396 -12
- package/methods/ai-terminal.js.map +1 -1
- package/package.json +1 -1
- package/util/ai-qa-policy.js +1 -1
- package/util/ai-qa-policy.js.map +1 -1
- package/util/ai-runner-qa-auth.js +199 -34
- package/util/ai-runner-qa-auth.js.map +1 -1
|
@@ -63,6 +63,60 @@ function buildResolveIORunnerQaAuthBootstrapScript(options) {
|
|
|
63
63
|
' throw new Error("Unable to require mongodb from project/server node_modules or global resolution");',
|
|
64
64
|
'}',
|
|
65
65
|
'',
|
|
66
|
+
'function buildDefaultQaUserSettings() {',
|
|
67
|
+
' return {',
|
|
68
|
+
' table_color: "#3b3ee3",',
|
|
69
|
+
' table_font_color: "#ffffff",',
|
|
70
|
+
' secondary_table_color: "#87ceeb",',
|
|
71
|
+
' secondary_table_font_color: "#000000",',
|
|
72
|
+
' tertiary_table_color: "#ff4500",',
|
|
73
|
+
' tertiary_table_font_color: "#000000",',
|
|
74
|
+
' font_size: 12,',
|
|
75
|
+
' collapsable_menu: true,',
|
|
76
|
+
' entries_per_page: "25",',
|
|
77
|
+
' warning_color: "#ffc107",',
|
|
78
|
+
' warning_font_color: "#000000",',
|
|
79
|
+
' warning_hover_color: "#e0a800",',
|
|
80
|
+
' success_color: "#28a745",',
|
|
81
|
+
' success_font_color: "#ffffff",',
|
|
82
|
+
' success_hover_color: "#218838",',
|
|
83
|
+
' danger_color: "#dc3545",',
|
|
84
|
+
' danger_font_color: "#ffffff",',
|
|
85
|
+
' danger_hover_color: "#c82333",',
|
|
86
|
+
' info_color: "#17a2b8",',
|
|
87
|
+
' info_font_color: "#ffffff",',
|
|
88
|
+
' info_hover_color: "#138496",',
|
|
89
|
+
' primary_color: "#007bff",',
|
|
90
|
+
' primary_font_color: "#ffffff",',
|
|
91
|
+
' primary_hover_color: "#0069d9",',
|
|
92
|
+
' secondary_color: "#868e96",',
|
|
93
|
+
' secondary_font_color: "#ffffff",',
|
|
94
|
+
' secondary_hover_color: "#5a6268",',
|
|
95
|
+
' routing_preference: "",',
|
|
96
|
+
' opening_route: targetRoute',
|
|
97
|
+
' };',
|
|
98
|
+
'}',
|
|
99
|
+
'',
|
|
100
|
+
'function normalizeQaUserForBrowser(user) {',
|
|
101
|
+
' const normalized = { ...(user || {}) };',
|
|
102
|
+
' normalized.other = {',
|
|
103
|
+
' ...(normalized.other || {}),',
|
|
104
|
+
' yards: Array.isArray(normalized.other && normalized.other.yards) ? normalized.other.yards : [],',
|
|
105
|
+
' tour_completed: true,',
|
|
106
|
+
' took_tour: true,',
|
|
107
|
+
' core_tour_completed: true,',
|
|
108
|
+
' welcome_tour_completed: true,',
|
|
109
|
+
' top_navigation_tour_completed: true,',
|
|
110
|
+
' user_settings_tour_completed: true',
|
|
111
|
+
' };',
|
|
112
|
+
' normalized.settings = {',
|
|
113
|
+
' ...buildDefaultQaUserSettings(),',
|
|
114
|
+
' ...(normalized.settings || {}),',
|
|
115
|
+
' opening_route: targetRoute',
|
|
116
|
+
' };',
|
|
117
|
+
' return normalized;',
|
|
118
|
+
'}',
|
|
119
|
+
'',
|
|
66
120
|
'async function ensureLocalQaUser() {',
|
|
67
121
|
' if (!isLocalhostUrl(serverUrl) || process.env.RESOLVEIO_RUNNER_QA_DISABLE_LOCAL_USER_REPAIR === "true" || process.env.RESOLVEIO_SUPPORT_QA_DISABLE_LOCAL_USER_REPAIR === "true") {',
|
|
68
122
|
' return false;',
|
|
@@ -77,37 +131,7 @@ function buildResolveIORunnerQaAuthBootstrapScript(options) {
|
|
|
77
131
|
' const salt = crypto.randomBytes(32).toString("hex");',
|
|
78
132
|
' const hash = crypto.pbkdf2Sync(password, salt, 25000, 512, "sha256").toString("hex");',
|
|
79
133
|
' const existing = await users.findOne({ $or: [{ username }, { email: username }] }, { projection: { _id: 1 } });',
|
|
80
|
-
' const defaultSettings =
|
|
81
|
-
' table_color: "#3b3ee3",',
|
|
82
|
-
' table_font_color: "#ffffff",',
|
|
83
|
-
' secondary_table_color: "#87ceeb",',
|
|
84
|
-
' secondary_table_font_color: "#000000",',
|
|
85
|
-
' tertiary_table_color: "#ff4500",',
|
|
86
|
-
' tertiary_table_font_color: "#000000",',
|
|
87
|
-
' font_size: 12,',
|
|
88
|
-
' collapsable_menu: true,',
|
|
89
|
-
' entries_per_page: "25",',
|
|
90
|
-
' warning_color: "#ffc107",',
|
|
91
|
-
' warning_font_color: "#000000",',
|
|
92
|
-
' warning_hover_color: "#e0a800",',
|
|
93
|
-
' success_color: "#28a745",',
|
|
94
|
-
' success_font_color: "#ffffff",',
|
|
95
|
-
' success_hover_color: "#218838",',
|
|
96
|
-
' danger_color: "#dc3545",',
|
|
97
|
-
' danger_font_color: "#ffffff",',
|
|
98
|
-
' danger_hover_color: "#c82333",',
|
|
99
|
-
' info_color: "#17a2b8",',
|
|
100
|
-
' info_font_color: "#ffffff",',
|
|
101
|
-
' info_hover_color: "#138496",',
|
|
102
|
-
' primary_color: "#007bff",',
|
|
103
|
-
' primary_font_color: "#ffffff",',
|
|
104
|
-
' primary_hover_color: "#0069d9",',
|
|
105
|
-
' secondary_color: "#868e96",',
|
|
106
|
-
' secondary_font_color: "#ffffff",',
|
|
107
|
-
' secondary_hover_color: "#5a6268",',
|
|
108
|
-
' routing_preference: "",',
|
|
109
|
-
' opening_route: targetRoute',
|
|
110
|
-
' };',
|
|
134
|
+
' const defaultSettings = buildDefaultQaUserSettings();',
|
|
111
135
|
' const baseUser = {',
|
|
112
136
|
' __v: 0,',
|
|
113
137
|
' username,',
|
|
@@ -115,7 +139,7 @@ function buildResolveIORunnerQaAuthBootstrapScript(options) {
|
|
|
115
139
|
' fullname: "QA Admin",',
|
|
116
140
|
' roles: { super_admin: true, approvals: [], groups: [], notifications: [], miscs: [] },',
|
|
117
141
|
' active: true,',
|
|
118
|
-
' other: { yards: [], tour_completed: true, core_tour_completed: true, welcome_tour_completed: true },',
|
|
142
|
+
' other: { yards: [], tour_completed: true, took_tour: true, core_tour_completed: true, welcome_tour_completed: true, top_navigation_tour_completed: true, user_settings_tour_completed: true },',
|
|
119
143
|
' settings: defaultSettings,',
|
|
120
144
|
' phonenumber: "",',
|
|
121
145
|
' readonly: false,',
|
|
@@ -249,7 +273,7 @@ function buildResolveIORunnerQaAuthBootstrapScript(options) {
|
|
|
249
273
|
' if (accessJson.error || !accessToken || !user) {',
|
|
250
274
|
' throw new Error(`Access token failed: ${JSON.stringify(accessJson).slice(0, 800)}`);',
|
|
251
275
|
' }',
|
|
252
|
-
' return { refreshToken, accessToken, user };',
|
|
276
|
+
' return { refreshToken, accessToken, user: normalizeQaUserForBrowser(user) };',
|
|
253
277
|
'}',
|
|
254
278
|
'',
|
|
255
279
|
'async function launchBrowser(puppeteer) {',
|
|
@@ -299,6 +323,7 @@ function buildResolveIORunnerQaAuthBootstrapScript(options) {
|
|
|
299
323
|
'}',
|
|
300
324
|
'',
|
|
301
325
|
'async function seedAuth(page, auth) {',
|
|
326
|
+
' auth.user = normalizeQaUserForBrowser(auth.user);',
|
|
302
327
|
' await page.evaluate((payload) => {',
|
|
303
328
|
' localStorage.setItem("refreshToken", payload.refreshToken);',
|
|
304
329
|
' localStorage.setItem("accessToken", payload.accessToken);',
|
|
@@ -308,6 +333,102 @@ function buildResolveIORunnerQaAuthBootstrapScript(options) {
|
|
|
308
333
|
' }, { ...auth, lastURL: targetRoute, bootstrappedAt: new Date().toISOString() });',
|
|
309
334
|
'}',
|
|
310
335
|
'',
|
|
336
|
+
'async function patchBrowserQaUser(page) {',
|
|
337
|
+
' await page.evaluate((nextRoute) => {',
|
|
338
|
+
' let user = {};',
|
|
339
|
+
' try { user = JSON.parse(localStorage.getItem("user") || "{}"); } catch (error) { user = {}; }',
|
|
340
|
+
' const settings = {',
|
|
341
|
+
' table_color: "#3b3ee3",',
|
|
342
|
+
' table_font_color: "#ffffff",',
|
|
343
|
+
' secondary_table_color: "#87ceeb",',
|
|
344
|
+
' secondary_table_font_color: "#000000",',
|
|
345
|
+
' tertiary_table_color: "#ff4500",',
|
|
346
|
+
' tertiary_table_font_color: "#000000",',
|
|
347
|
+
' font_size: 12,',
|
|
348
|
+
' collapsable_menu: true,',
|
|
349
|
+
' entries_per_page: "25",',
|
|
350
|
+
' warning_color: "#ffc107",',
|
|
351
|
+
' warning_font_color: "#000000",',
|
|
352
|
+
' warning_hover_color: "#e0a800",',
|
|
353
|
+
' success_color: "#28a745",',
|
|
354
|
+
' success_font_color: "#ffffff",',
|
|
355
|
+
' success_hover_color: "#218838",',
|
|
356
|
+
' danger_color: "#dc3545",',
|
|
357
|
+
' danger_font_color: "#ffffff",',
|
|
358
|
+
' danger_hover_color: "#c82333",',
|
|
359
|
+
' info_color: "#17a2b8",',
|
|
360
|
+
' info_font_color: "#ffffff",',
|
|
361
|
+
' info_hover_color: "#138496",',
|
|
362
|
+
' primary_color: "#007bff",',
|
|
363
|
+
' primary_font_color: "#ffffff",',
|
|
364
|
+
' primary_hover_color: "#0069d9",',
|
|
365
|
+
' secondary_color: "#868e96",',
|
|
366
|
+
' secondary_font_color: "#ffffff",',
|
|
367
|
+
' secondary_hover_color: "#5a6268",',
|
|
368
|
+
' routing_preference: "",',
|
|
369
|
+
' opening_route: nextRoute',
|
|
370
|
+
' };',
|
|
371
|
+
' user = {',
|
|
372
|
+
' ...user,',
|
|
373
|
+
' other: {',
|
|
374
|
+
' ...(user.other || {}),',
|
|
375
|
+
' yards: Array.isArray(user.other && user.other.yards) ? user.other.yards : [],',
|
|
376
|
+
' tour_completed: true,',
|
|
377
|
+
' took_tour: true,',
|
|
378
|
+
' core_tour_completed: true,',
|
|
379
|
+
' welcome_tour_completed: true,',
|
|
380
|
+
' top_navigation_tour_completed: true,',
|
|
381
|
+
' user_settings_tour_completed: true',
|
|
382
|
+
' },',
|
|
383
|
+
' settings: { ...settings, ...(user.settings || {}), opening_route: nextRoute }',
|
|
384
|
+
' };',
|
|
385
|
+
' localStorage.setItem("user", JSON.stringify(user));',
|
|
386
|
+
' localStorage.setItem("lastURL", nextRoute);',
|
|
387
|
+
' localStorage.setItem("resolveio.runnerQaPostLoginGateRepairedAt", new Date().toISOString());',
|
|
388
|
+
' });',
|
|
389
|
+
'}',
|
|
390
|
+
'',
|
|
391
|
+
'async function dismissVisibleTourOrSetupGate(page) {',
|
|
392
|
+
' return page.evaluate(() => {',
|
|
393
|
+
' const controls = Array.from(document.querySelectorAll("button, a, [role=\'button\']"));',
|
|
394
|
+
' const control = controls.find((candidate) => {',
|
|
395
|
+
' const text = (candidate.textContent || "").replace(/\\s+/g, " ").trim();',
|
|
396
|
+
' return /^(skip|finish|done|close)$/i.test(text);',
|
|
397
|
+
' });',
|
|
398
|
+
' if (control && typeof control.click === "function") {',
|
|
399
|
+
' control.click();',
|
|
400
|
+
' return true;',
|
|
401
|
+
' }',
|
|
402
|
+
' return false;',
|
|
403
|
+
' });',
|
|
404
|
+
'}',
|
|
405
|
+
'',
|
|
406
|
+
'function isPostLoginSetupOrTourGate(currentRoute, summary) {',
|
|
407
|
+
' const text = String(summary && summary.bodyTextSnippet || "");',
|
|
408
|
+
' return currentRoute === "/user-settings/settings" || /Top Navigation Step \\d+ of \\d+|\\bSkip\\b|User Settings/i.test(text);',
|
|
409
|
+
'}',
|
|
410
|
+
'',
|
|
411
|
+
'async function repairPostLoginSetupOrTourGate(page, expectedRoute) {',
|
|
412
|
+
' if (process.env.RESOLVEIO_RUNNER_QA_DISABLE_POST_LOGIN_ROUTE_REPAIR === "true" || process.env.RESOLVEIO_SUPPORT_QA_DISABLE_POST_LOGIN_ROUTE_REPAIR === "true") {',
|
|
413
|
+
' return false;',
|
|
414
|
+
' }',
|
|
415
|
+
' const current = normalizeRoutePath(await page.evaluate(() => location.href));',
|
|
416
|
+
' const summary = await pageSummary(page).catch(() => ({}));',
|
|
417
|
+
' if (!isPostLoginSetupOrTourGate(current, summary)) {',
|
|
418
|
+
' return false;',
|
|
419
|
+
' }',
|
|
420
|
+
' await dismissVisibleTourOrSetupGate(page).catch(() => false);',
|
|
421
|
+
' await patchBrowserQaUser(page);',
|
|
422
|
+
' await ensureLocalQaUser().catch(() => false);',
|
|
423
|
+
' await page.goto(`${clientUrl}${expectedRoute}`, { waitUntil: "domcontentloaded", timeout: 60000 });',
|
|
424
|
+
' await delay(1500);',
|
|
425
|
+
' await dismissVisibleTourOrSetupGate(page).catch(() => false);',
|
|
426
|
+
' await patchBrowserQaUser(page);',
|
|
427
|
+
' await delay(500);',
|
|
428
|
+
' const repairedCurrent = normalizeRoutePath(await page.evaluate(() => location.href));',
|
|
429
|
+
' return repairedCurrent === expectedRoute;',
|
|
430
|
+
'}',
|
|
431
|
+
'',
|
|
311
432
|
'function delay(ms) {',
|
|
312
433
|
' return new Promise((resolve) => setTimeout(resolve, ms));',
|
|
313
434
|
'}',
|
|
@@ -331,11 +452,52 @@ function buildResolveIORunnerQaAuthBootstrapScript(options) {
|
|
|
331
452
|
' }',
|
|
332
453
|
' const current = normalizeRoutePath(await page.evaluate(() => location.href));',
|
|
333
454
|
' if (current !== expected) {',
|
|
455
|
+
' const repaired = await repairPostLoginSetupOrTourGate(page, expected);',
|
|
456
|
+
' if (repaired) {',
|
|
457
|
+
' return;',
|
|
458
|
+
' }',
|
|
334
459
|
' const summary = await pageSummary(page).catch(() => ({}));',
|
|
335
460
|
' throw new Error(`QA auth bootstrap reached ${current}, not requested target route ${expected}. This is a route blocker; do not continue browser QA until the runner/app can reach the requested screen. Page summary: ${JSON.stringify(summary).slice(0, 1200)}`);',
|
|
336
461
|
' }',
|
|
337
462
|
'}',
|
|
338
463
|
'',
|
|
464
|
+
'async function waitForStableTargetRoute(page) {',
|
|
465
|
+
' const expected = normalizeRoutePath(targetRoute);',
|
|
466
|
+
' if (expected === "/") {',
|
|
467
|
+
' return;',
|
|
468
|
+
' }',
|
|
469
|
+
' const deadline = Date.now() + Number(process.env.RESOLVEIO_RUNNER_QA_ROUTE_STABILITY_TIMEOUT_MS || process.env.RESOLVEIO_SUPPORT_QA_ROUTE_STABILITY_TIMEOUT_MS || 7000);',
|
|
470
|
+
' let stableSince = 0;',
|
|
471
|
+
' let lastCurrent = "";',
|
|
472
|
+
' while (Date.now() < deadline) {',
|
|
473
|
+
' const current = normalizeRoutePath(await page.evaluate(() => location.href));',
|
|
474
|
+
' lastCurrent = current;',
|
|
475
|
+
' if (current === expected) {',
|
|
476
|
+
' stableSince = stableSince || Date.now();',
|
|
477
|
+
' if (Date.now() - stableSince >= Number(process.env.RESOLVEIO_RUNNER_QA_ROUTE_STABLE_MS || process.env.RESOLVEIO_SUPPORT_QA_ROUTE_STABLE_MS || 2500)) {',
|
|
478
|
+
' return;',
|
|
479
|
+
' }',
|
|
480
|
+
' }',
|
|
481
|
+
' else {',
|
|
482
|
+
' stableSince = 0;',
|
|
483
|
+
' }',
|
|
484
|
+
' await delay(250);',
|
|
485
|
+
' }',
|
|
486
|
+
' const summary = await pageSummary(page).catch(() => ({}));',
|
|
487
|
+
' throw new Error(`QA auth bootstrap route was not stable on requested target ${expected}; last route was ${lastCurrent || "unknown"}. This is a route blocker; do not continue browser QA until the runner/app can remain on the requested screen. Page summary: ${JSON.stringify(summary).slice(0, 1200)}`);',
|
|
488
|
+
'}',
|
|
489
|
+
'',
|
|
490
|
+
'async function assertSummaryOnTargetRoute(summary) {',
|
|
491
|
+
' const expected = normalizeRoutePath(targetRoute);',
|
|
492
|
+
' if (expected === "/") {',
|
|
493
|
+
' return;',
|
|
494
|
+
' }',
|
|
495
|
+
' const current = normalizeRoutePath(summary && summary.url || "");',
|
|
496
|
+
' if (current !== expected) {',
|
|
497
|
+
' throw new Error(`QA auth bootstrap final summary is on ${current}, not requested target route ${expected}. This is a route blocker; refusing to write a false pass. Page summary: ${JSON.stringify(summary).slice(0, 1200)}`);',
|
|
498
|
+
' }',
|
|
499
|
+
'}',
|
|
500
|
+
'',
|
|
339
501
|
'async function logoutExistingBrowserSession(page) {',
|
|
340
502
|
' try {',
|
|
341
503
|
' await page.goto(clientUrl, { waitUntil: "domcontentloaded", timeout: 45000 });',
|
|
@@ -366,6 +528,7 @@ function buildResolveIORunnerQaAuthBootstrapScript(options) {
|
|
|
366
528
|
' }, { timeout: Number(process.env.RESOLVEIO_RUNNER_QA_AUTH_TIMEOUT_MS || process.env.RESOLVEIO_SUPPORT_QA_AUTH_TIMEOUT_MS || 60000) });',
|
|
367
529
|
' await delay(1000);',
|
|
368
530
|
' await assertTargetRoute(page);',
|
|
531
|
+
' await waitForStableTargetRoute(page);',
|
|
369
532
|
'}',
|
|
370
533
|
'',
|
|
371
534
|
'async function pageSummary(page) {',
|
|
@@ -408,6 +571,8 @@ function buildResolveIORunnerQaAuthBootstrapScript(options) {
|
|
|
408
571
|
' const auth = await login();',
|
|
409
572
|
' await seedAuth(page, auth);',
|
|
410
573
|
' await waitForAuthenticatedApp(page);',
|
|
574
|
+
' const finalPage = await pageSummary(page);',
|
|
575
|
+
' await assertSummaryOnTargetRoute(finalPage);',
|
|
411
576
|
' await page.screenshot({ path: readyScreenshotPath, fullPage: true });',
|
|
412
577
|
' const summary = {',
|
|
413
578
|
' status: "pass",',
|
|
@@ -416,7 +581,7 @@ function buildResolveIORunnerQaAuthBootstrapScript(options) {
|
|
|
416
581
|
' targetRoute,',
|
|
417
582
|
' screenshot: readyScreenshotPath,',
|
|
418
583
|
' user: { _id: auth.user && auth.user._id, username: auth.user && auth.user.username, fullname: auth.user && auth.user.fullname },',
|
|
419
|
-
' page:
|
|
584
|
+
' page: finalPage',
|
|
420
585
|
' };',
|
|
421
586
|
' writeResult(summary);',
|
|
422
587
|
' console.log(JSON.stringify(summary, null, 2));',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/ai-runner-qa-auth.ts"],"names":[],"mappings":";;AAKA,8FA0bC;AA1bD,SAAgB,yCAAyC,CAAC,OAAyD;IAAzD,wBAAA,EAAA,YAAyD;IAClH,IAAM,eAAe,G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AK;QACL,wCAAwC;QACxC,IAAI;QACJ,OAAO;QACP,EAAE;KACF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC","file":"ai-runner-qa-auth.js","sourcesContent":["export interface ResolveIORunnerQaAuthBootstrapScriptOptions {\n\tdefaultUsername?: string;\n\tdefaultPassword?: string;\n}\n\nexport function buildResolveIORunnerQaAuthBootstrapScript(options: ResolveIORunnerQaAuthBootstrapScriptOptions = {}): string {\n\tconst defaultUsername = options.defaultUsername || 'admin';\n\tconst defaultPassword = options.defaultPassword || '';\n\treturn [\n\t\t'#!/usr/bin/env node',\n\t\t\"'use strict';\",\n\t\t'',\n\t\t'const fs = require(\"fs\");',\n\t\t'const crypto = require(\"crypto\");',\n\t\t'const http = require(\"http\");',\n\t\t'const https = require(\"https\");',\n\t\t'const path = require(\"path\");',\n\t\t'',\n\t\t'const projectRoot = path.resolve(process.argv[2] || process.cwd());',\n\t\t'const routeArg = process.argv[3] || process.env.RESOLVEIO_RUNNER_QA_TARGET_ROUTE || process.env.RESOLVEIO_SUPPORT_QA_TARGET_ROUTE || process.env.RESOLVEIO_SUPPORT_QA_LAST_URL || \"/\";',\n\t\t'const targetRoute = routeArg.startsWith(\"/\") ? routeArg : `/${routeArg}`;',\n\t\t'const clientUrl = stripTrailingSlash(process.env.RESOLVEIO_RUNNER_QA_CLIENT_URL || process.env.RESOLVEIO_SUPPORT_QA_CLIENT_URL || `http://localhost:${process.env.RESOLVEIO_SUPPORT_QA_CLIENT_PORT || \"4200\"}`);',\n\t\t'const serverUrl = stripTrailingSlash(process.env.RESOLVEIO_RUNNER_QA_SERVER_URL || process.env.RESOLVEIO_SUPPORT_QA_SERVER_URL || \"http://localhost:8080\");',\n\t\t`const username = process.env.RESOLVEIO_RUNNER_QA_USERNAME || process.env.RESOLVEIO_SUPPORT_QA_USERNAME || ${JSON.stringify(defaultUsername)};`,\n\t\t`const password = process.env.RESOLVEIO_RUNNER_QA_PASSWORD || process.env.RESOLVEIO_SUPPORT_QA_PASSWORD || ${JSON.stringify(defaultPassword)};`,\n\t\t'const artifactDir = path.resolve(process.env.RESOLVEIO_RUNNER_QA_ARTIFACT_DIR || process.env.RESOLVEIO_SUPPORT_QA_ARTIFACT_DIR || path.join(projectRoot, \"qa-artifacts\"));',\n\t\t'const viewportWidth = Number(process.env.RESOLVEIO_RUNNER_QA_VIEWPORT_WIDTH || process.env.RESOLVEIO_SUPPORT_QA_VIEWPORT_WIDTH || 1920);',\n\t\t'const viewportHeight = Number(process.env.RESOLVEIO_RUNNER_QA_VIEWPORT_HEIGHT || process.env.RESOLVEIO_SUPPORT_QA_VIEWPORT_HEIGHT || 1080);',\n\t\t'const startupTimeoutMs = Math.max(1000, Number(process.env.RESOLVEIO_RUNNER_QA_ANGULAR_STARTUP_TIMEOUT_SECONDS || process.env.RESOLVEIO_SUPPORT_QA_ANGULAR_STARTUP_TIMEOUT_SECONDS || 900) * 1000);',\n\t\t'const resultPath = path.join(artifactDir, \"auth-bootstrap-result.json\");',\n\t\t'const readyScreenshotPath = path.join(artifactDir, \"auth-bootstrap-ready.png\");',\n\t\t'const failureScreenshotPath = path.join(artifactDir, \"auth-bootstrap-failed.png\");',\n\t\t'',\n\t\t'function stripTrailingSlash(value) {',\n\t\t'\treturn String(value || \"\").replace(/\\\\/+$/, \"\");',\n\t\t'}',\n\t\t'',\n\t\t'function isLocalhostUrl(value) {',\n\t\t'\ttry {',\n\t\t'\t\tconst parsed = new URL(value);',\n\t\t'\t\treturn [\"localhost\", \"127.0.0.1\", \"::1\"].includes(parsed.hostname);',\n\t\t'\t}',\n\t\t'\tcatch (error) {',\n\t\t'\t\treturn false;',\n\t\t'\t}',\n\t\t'}',\n\t\t'',\n\t\t'function resolveLocalMongoUrl() {',\n\t\t'\treturn process.env.MONGO_URL || process.env.RESOLVEIO_RUNNER_QA_MONGO_URL || process.env.RESOLVEIO_SUPPORT_QA_MONGO_URL || `mongodb://127.0.0.1:${process.env.RESOLVEIO_SUPPORT_QA_MONGO_PORT || \"3001\"}/resolveio?directConnection=true`;',\n\t\t'}',\n\t\t'',\n\t\t'function requireMongoClient() {',\n\t\t'\tconst candidates = [',\n\t\t'\t\tpath.join(projectRoot, \"server\", \"node_modules\", \"mongodb\"),',\n\t\t'\t\tpath.join(projectRoot, \"node_modules\", \"mongodb\"),',\n\t\t'\t\tpath.join(process.cwd(), \"server\", \"node_modules\", \"mongodb\"),',\n\t\t'\t\tpath.join(process.cwd(), \"node_modules\", \"mongodb\"),',\n\t\t'\t\t\"mongodb\"',\n\t\t'\t];',\n\t\t'\tfor (const candidate of candidates) {',\n\t\t'\t\ttry { return require(candidate).MongoClient; }',\n\t\t'\t\tcatch (error) {}',\n\t\t'\t}',\n\t\t'\tthrow new Error(\"Unable to require mongodb from project/server node_modules or global resolution\");',\n\t\t'}',\n\t\t'',\n\t\t'async function ensureLocalQaUser() {',\n\t\t'\tif (!isLocalhostUrl(serverUrl) || process.env.RESOLVEIO_RUNNER_QA_DISABLE_LOCAL_USER_REPAIR === \"true\" || process.env.RESOLVEIO_SUPPORT_QA_DISABLE_LOCAL_USER_REPAIR === \"true\") {',\n\t\t'\t\treturn false;',\n\t\t'\t}',\n\t\t'\tconst MongoClient = requireMongoClient();',\n\t\t'\tconst client = new MongoClient(resolveLocalMongoUrl());',\n\t\t'\tawait client.connect();',\n\t\t'\ttry {',\n\t\t'\t\tconst db = client.db();',\n\t\t'\t\tconst users = db.collection(\"users\");',\n\t\t'\t\tconst now = new Date();',\n\t\t'\t\tconst salt = crypto.randomBytes(32).toString(\"hex\");',\n\t\t'\t\tconst hash = crypto.pbkdf2Sync(password, salt, 25000, 512, \"sha256\").toString(\"hex\");',\n\t\t'\t\tconst existing = await users.findOne({ $or: [{ username }, { email: username }] }, { projection: { _id: 1 } });',\n\t\t'\t\tconst defaultSettings = {',\n\t\t'\t\t\ttable_color: \"#3b3ee3\",',\n\t\t'\t\t\ttable_font_color: \"#ffffff\",',\n\t\t'\t\t\tsecondary_table_color: \"#87ceeb\",',\n\t\t'\t\t\tsecondary_table_font_color: \"#000000\",',\n\t\t'\t\t\ttertiary_table_color: \"#ff4500\",',\n\t\t'\t\t\ttertiary_table_font_color: \"#000000\",',\n\t\t'\t\t\tfont_size: 12,',\n\t\t'\t\t\tcollapsable_menu: true,',\n\t\t'\t\t\tentries_per_page: \"25\",',\n\t\t'\t\t\twarning_color: \"#ffc107\",',\n\t\t'\t\t\twarning_font_color: \"#000000\",',\n\t\t'\t\t\twarning_hover_color: \"#e0a800\",',\n\t\t'\t\t\tsuccess_color: \"#28a745\",',\n\t\t'\t\t\tsuccess_font_color: \"#ffffff\",',\n\t\t'\t\t\tsuccess_hover_color: \"#218838\",',\n\t\t'\t\t\tdanger_color: \"#dc3545\",',\n\t\t'\t\t\tdanger_font_color: \"#ffffff\",',\n\t\t'\t\t\tdanger_hover_color: \"#c82333\",',\n\t\t'\t\t\tinfo_color: \"#17a2b8\",',\n\t\t'\t\t\tinfo_font_color: \"#ffffff\",',\n\t\t'\t\t\tinfo_hover_color: \"#138496\",',\n\t\t'\t\t\tprimary_color: \"#007bff\",',\n\t\t'\t\t\tprimary_font_color: \"#ffffff\",',\n\t\t'\t\t\tprimary_hover_color: \"#0069d9\",',\n\t\t'\t\t\tsecondary_color: \"#868e96\",',\n\t\t'\t\t\tsecondary_font_color: \"#ffffff\",',\n\t\t'\t\t\tsecondary_hover_color: \"#5a6268\",',\n\t\t'\t\t\trouting_preference: \"\",',\n\t\t'\t\t\topening_route: targetRoute',\n\t\t'\t\t};',\n\t\t'\t\tconst baseUser = {',\n\t\t'\t\t\t__v: 0,',\n\t\t'\t\t\tusername,',\n\t\t'\t\t\temail: username.includes(\"@\") ? username : \"dev@resolveio.com\",',\n\t\t'\t\t\tfullname: \"QA Admin\",',\n\t\t'\t\t\troles: { super_admin: true, approvals: [], groups: [], notifications: [], miscs: [] },',\n\t\t'\t\t\tactive: true,',\n\t\t'\t\t\tother: { yards: [], tour_completed: true, core_tour_completed: true, welcome_tour_completed: true },',\n\t\t'\t\t\tsettings: defaultSettings,',\n\t\t'\t\t\tphonenumber: \"\",',\n\t\t'\t\t\treadonly: false,',\n\t\t'\t\t\tis_customer: false,',\n\t\t'\t\t\thash,',\n\t\t'\t\t\tsalt,',\n\t\t'\t\t\tattempts: 0,',\n\t\t'\t\t\tservices: {},',\n\t\t'\t\t\tupdatedAt: now',\n\t\t'\t\t};',\n\t\t'\t\tif (existing && existing._id) {',\n\t\t'\t\t\tawait users.updateOne({ _id: existing._id }, { $set: baseUser });',\n\t\t'\t\t}',\n\t\t'\t\telse {',\n\t\t'\t\t\tawait users.insertOne({ _id: crypto.randomBytes(12).toString(\"hex\"), createdAt: now, ...baseUser });',\n\t\t'\t\t}',\n\t\t'\t\treturn true;',\n\t\t'\t}',\n\t\t'\tfinally {',\n\t\t'\t\tawait client.close().catch(() => undefined);',\n\t\t'\t}',\n\t\t'}',\n\t\t'',\n\t\t'function writeResult(payload) {',\n\t\t'\tfs.mkdirSync(artifactDir, { recursive: true });',\n\t\t'\tfs.writeFileSync(resultPath, JSON.stringify(payload, null, 2));',\n\t\t'}',\n\t\t'',\n\t\t'function requestJson(url, payload) {',\n\t\t'\treturn new Promise((resolve, reject) => {',\n\t\t'\t\tconst body = JSON.stringify(payload || {});',\n\t\t'\t\tconst parsed = new URL(url);',\n\t\t'\t\tconst mod = parsed.protocol === \"https:\" ? https : http;',\n\t\t'\t\tconst req = mod.request(parsed, {',\n\t\t'\t\t\tmethod: \"POST\",',\n\t\t'\t\t\ttimeout: 20000,',\n\t\t'\t\t\theaders: {',\n\t\t'\t\t\t\t\"content-type\": \"application/json\",',\n\t\t'\t\t\t\t\"content-length\": Buffer.byteLength(body),',\n\t\t'\t\t\t\t\"origin\": clientUrl',\n\t\t'\t\t\t}',\n\t\t'\t\t}, (res) => {',\n\t\t'\t\t\tlet raw = \"\";',\n\t\t'\t\t\tres.setEncoding(\"utf8\");',\n\t\t'\t\t\tres.on(\"data\", (chunk) => { raw += chunk; });',\n\t\t'\t\t\tres.on(\"end\", () => {',\n\t\t'\t\t\t\tlet json = null;',\n\t\t'\t\t\t\ttry { json = raw ? JSON.parse(raw) : {}; }',\n\t\t'\t\t\t\tcatch (error) {',\n\t\t'\t\t\t\t\treject(new Error(`${url} returned non-JSON HTTP ${res.statusCode}: ${raw.slice(0, 300)}`));',\n\t\t'\t\t\t\t\treturn;',\n\t\t'\t\t\t\t}',\n\t\t'\t\t\t\tif (!res.statusCode || res.statusCode >= 400) {',\n\t\t'\t\t\t\t\treject(new Error(`${url} returned HTTP ${res.statusCode}: ${JSON.stringify(json).slice(0, 500)}`));',\n\t\t'\t\t\t\t\treturn;',\n\t\t'\t\t\t\t}',\n\t\t'\t\t\t\tresolve(json);',\n\t\t'\t\t\t});',\n\t\t'\t\t});',\n\t\t'\t\treq.on(\"timeout\", () => req.destroy(new Error(`${url} timed out`)));',\n\t\t'\t\treq.on(\"error\", reject);',\n\t\t'\t\treq.write(body);',\n\t\t'\t\treq.end();',\n\t\t'\t});',\n\t\t'}',\n\t\t'',\n\t\t'function requestReady(url) {',\n\t\t'\treturn new Promise((resolve) => {',\n\t\t'\t\ttry {',\n\t\t'\t\t\tconst parsed = new URL(url);',\n\t\t'\t\t\tconst mod = parsed.protocol === \"https:\" ? https : http;',\n\t\t'\t\t\tconst req = mod.get(parsed, { timeout: 2500 }, (res) => {',\n\t\t'\t\t\t\tres.resume();',\n\t\t'\t\t\t\tresolve(Boolean(res.statusCode && res.statusCode < 500));',\n\t\t'\t\t\t});',\n\t\t'\t\t\treq.on(\"timeout\", () => req.destroy(new Error(\"timeout\")));',\n\t\t'\t\t\treq.on(\"error\", () => resolve(false));',\n\t\t'\t\t}',\n\t\t'\t\tcatch (error) {',\n\t\t'\t\t\tresolve(false);',\n\t\t'\t\t}',\n\t\t'\t});',\n\t\t'}',\n\t\t'',\n\t\t'async function waitForHttpReady(url, label) {',\n\t\t'\tconst deadline = Date.now() + startupTimeoutMs;',\n\t\t'\twhile (Date.now() < deadline) {',\n\t\t'\t\tif (await requestReady(url)) {',\n\t\t'\t\t\treturn;',\n\t\t'\t\t}',\n\t\t'\t\tawait delay(3000);',\n\t\t'\t}',\n\t\t'\tthrow new Error(`${label} did not become ready at ${url} within ${Math.round(startupTimeoutMs / 1000)}s`);',\n\t\t'}',\n\t\t'',\n\t\t'function requirePuppeteer() {',\n\t\t'\tconst candidates = [',\n\t\t'\t\tpath.join(projectRoot, \"server\", \"node_modules\", \"puppeteer\", \"lib\", \"cjs\", \"puppeteer\", \"puppeteer.js\"),',\n\t\t'\t\tpath.join(projectRoot, \"node_modules\", \"puppeteer\", \"lib\", \"cjs\", \"puppeteer\", \"puppeteer.js\"),',\n\t\t'\t\tpath.join(process.cwd(), \"server\", \"node_modules\", \"puppeteer\", \"lib\", \"cjs\", \"puppeteer\", \"puppeteer.js\"),',\n\t\t'\t\tpath.join(process.cwd(), \"node_modules\", \"puppeteer\", \"lib\", \"cjs\", \"puppeteer\", \"puppeteer.js\"),',\n\t\t'\t\t\"puppeteer\"',\n\t\t'\t];',\n\t\t'\tfor (const candidate of candidates) {',\n\t\t'\t\ttry { return require(candidate); }',\n\t\t'\t\tcatch (error) {}',\n\t\t'\t}',\n\t\t'\tthrow new Error(\"Unable to require puppeteer from project/server node_modules or global resolution\");',\n\t\t'}',\n\t\t'',\n\t\t'async function login() {',\n\t\t'\tif (!password) {',\n\t\t'\t\tthrow new Error(\"QA password is empty; source .resolveio-support-tools/env.sh or set RESOLVEIO_RUNNER_QA_PASSWORD before auth bootstrap\");',\n\t\t'\t}',\n\t\t'\tawait waitForHttpReady(serverUrl, \"QA server\");',\n\t\t'\tawait ensureLocalQaUser();',\n\t\t'\tlet loginJson = await requestJson(`${serverUrl}/login`, { username, password });',\n\t\t'\tif ((loginJson && loginJson.error) && /Invalid Username And Password|Too Many Attempts/i.test(String(loginJson.result || \"\"))) {',\n\t\t'\t\tconst repaired = await ensureLocalQaUser();',\n\t\t'\t\tif (repaired) {',\n\t\t'\t\t\tloginJson = await requestJson(`${serverUrl}/login`, { username, password });',\n\t\t'\t\t}',\n\t\t'\t}',\n\t\t'\tconst refreshToken = loginJson && loginJson.result && loginJson.result.token;',\n\t\t'\tif (loginJson.error || !refreshToken) {',\n\t\t'\t\tthrow new Error(`Login failed: ${JSON.stringify(loginJson).slice(0, 800)}`);',\n\t\t'\t}',\n\t\t'\tconst accessJson = await requestJson(`${serverUrl}/accessToken`, { refreshToken });',\n\t\t'\tconst accessToken = accessJson && accessJson.result && accessJson.result.token;',\n\t\t'\tconst user = accessJson && accessJson.result && accessJson.result.user;',\n\t\t'\tif (accessJson.error || !accessToken || !user) {',\n\t\t'\t\tthrow new Error(`Access token failed: ${JSON.stringify(accessJson).slice(0, 800)}`);',\n\t\t'\t}',\n\t\t'\treturn { refreshToken, accessToken, user };',\n\t\t'}',\n\t\t'',\n\t\t'async function launchBrowser(puppeteer) {',\n\t\t'\tconst browserUrl = process.env.RESOLVEIO_RUNNER_QA_BROWSER_URL || process.env.RESOLVEIO_SUPPORT_QA_BROWSER_URL || \"\";',\n\t\t'\tif (browserUrl) {',\n\t\t'\t\treturn puppeteer.connect({ browserURL: browserUrl, protocolTimeout: 30000, defaultViewport: null });',\n\t\t'\t}',\n\t\t'\tconst launchOptions = {',\n\t\t'\t\theadless: true,',\n\t\t'\t\tdefaultViewport: { width: viewportWidth, height: viewportHeight },',\n\t\t'\t\targs: [\"--no-sandbox\", \"--disable-setuid-sandbox\", \"--disable-dev-shm-usage\", `--window-size=${viewportWidth},${viewportHeight}`]',\n\t\t'\t};',\n\t\t'\tif (process.env.PUPPETEER_EXECUTABLE_PATH || process.env.CHROME_BIN) {',\n\t\t'\t\tlaunchOptions.executablePath = process.env.PUPPETEER_EXECUTABLE_PATH || process.env.CHROME_BIN;',\n\t\t'\t}',\n\t\t'\treturn puppeteer.launch(launchOptions);',\n\t\t'}',\n\t\t'',\n\t\t'async function resetBrowserState(page) {',\n\t\t'\tawait waitForHttpReady(clientUrl, \"QA client\");',\n\t\t'\tawait page.goto(clientUrl, { waitUntil: \"domcontentloaded\", timeout: 45000 });',\n\t\t'\tawait page.evaluate(async () => {',\n\t\t'\t\ttry {',\n\t\t'\t\t\tconst registrations = await navigator.serviceWorker.getRegistrations();',\n\t\t'\t\t\tawait Promise.all(registrations.map((registration) => registration.unregister().catch(() => false)));',\n\t\t'\t\t} catch (error) {}',\n\t\t'\t\ttry {',\n\t\t'\t\t\tif (window.caches && window.caches.keys) {',\n\t\t'\t\t\t\tconst keys = await window.caches.keys();',\n\t\t'\t\t\t\tawait Promise.all(keys.map((key) => window.caches.delete(key).catch(() => false)));',\n\t\t'\t\t\t}',\n\t\t'\t\t} catch (error) {}',\n\t\t'\t\ttry {',\n\t\t'\t\t\tif (window.indexedDB && window.indexedDB.databases) {',\n\t\t'\t\t\t\tconst databases = await window.indexedDB.databases();',\n\t\t'\t\t\t\tawait Promise.all(databases.filter((database) => database && database.name).map((database) => new Promise((resolve) => {',\n\t\t'\t\t\t\t\tconst request = window.indexedDB.deleteDatabase(database.name);',\n\t\t'\t\t\t\t\trequest.onsuccess = () => resolve(true);',\n\t\t'\t\t\t\t\trequest.onerror = () => resolve(false);',\n\t\t'\t\t\t\t\trequest.onblocked = () => resolve(false);',\n\t\t'\t\t\t\t})));',\n\t\t'\t\t\t}',\n\t\t'\t\t} catch (error) {}',\n\t\t'\t\tlocalStorage.clear();',\n\t\t'\t\tsessionStorage.clear();',\n\t\t'\t});',\n\t\t'}',\n\t\t'',\n\t\t'async function seedAuth(page, auth) {',\n\t\t'\tawait page.evaluate((payload) => {',\n\t\t'\t\tlocalStorage.setItem(\"refreshToken\", payload.refreshToken);',\n\t\t'\t\tlocalStorage.setItem(\"accessToken\", payload.accessToken);',\n\t\t'\t\tlocalStorage.setItem(\"user\", JSON.stringify(payload.user));',\n\t\t'\t\tlocalStorage.setItem(\"lastURL\", payload.lastURL);',\n\t\t'\t\tlocalStorage.setItem(\"resolveio.runnerQaAuthBootstrappedAt\", payload.bootstrappedAt);',\n\t\t'\t}, { ...auth, lastURL: targetRoute, bootstrappedAt: new Date().toISOString() });',\n\t\t'}',\n\t\t'',\n\t\t'function delay(ms) {',\n\t\t'\treturn new Promise((resolve) => setTimeout(resolve, ms));',\n\t\t'}',\n\t\t'',\n\t\t'function normalizeRoutePath(value) {',\n\t\t'\ttry {',\n\t\t'\t\t\tconst parsed = new URL(value, clientUrl);',\n\t\t'\t\t\tlet pathname = parsed.pathname || \"/\";',\n\t\t'\t\t\tpathname = pathname.replace(/\\\\/+$/, \"\") || \"/\";',\n\t\t'\t\t\treturn pathname;',\n\t\t'\t}',\n\t\t'\tcatch (error) {',\n\t\t'\t\t\treturn String(value || \"/\").split(\"?\")[0].replace(/\\\\/+$/, \"\") || \"/\";',\n\t\t'\t}',\n\t\t'}',\n\t\t'',\n\t\t'async function assertTargetRoute(page) {',\n\t\t'\tconst expected = normalizeRoutePath(targetRoute);',\n\t\t'\tif (expected === \"/\") {',\n\t\t'\t\treturn;',\n\t\t'\t}',\n\t\t'\tconst current = normalizeRoutePath(await page.evaluate(() => location.href));',\n\t\t'\tif (current !== expected) {',\n\t\t'\t\tconst summary = await pageSummary(page).catch(() => ({}));',\n\t\t'\t\tthrow new Error(`QA auth bootstrap reached ${current}, not requested target route ${expected}. This is a route blocker; do not continue browser QA until the runner/app can reach the requested screen. Page summary: ${JSON.stringify(summary).slice(0, 1200)}`);',\n\t\t'\t}',\n\t\t'}',\n\t\t'',\n\t\t'async function logoutExistingBrowserSession(page) {',\n\t\t'\ttry {',\n\t\t'\t\tawait page.goto(clientUrl, { waitUntil: \"domcontentloaded\", timeout: 45000 });',\n\t\t'\t\tawait delay(500);',\n\t\t'\t\tawait page.evaluate(() => {',\n\t\t'\t\t\tconst controls = Array.from(document.querySelectorAll(\"button, a, [role=\\'button\\']\"));',\n\t\t'\t\t\tconst logoutControl = controls.find((control) => /(^|\\\\s)logout(\\\\s|$)/i.test((control.textContent || \"\").trim()));',\n\t\t'\t\t\tif (logoutControl && typeof logoutControl.click === \"function\") {',\n\t\t'\t\t\t\tlogoutControl.click();',\n\t\t'\t\t\t\treturn true;',\n\t\t'\t\t\t}',\n\t\t'\t\t\treturn false;',\n\t\t'\t\t});',\n\t\t'\t\tawait delay(1000);',\n\t\t'\t}',\n\t\t'\tcatch (error) {}',\n\t\t'}',\n\t\t'',\n\t\t'async function waitForAuthenticatedApp(page) {',\n\t\t'\tconst url = `${clientUrl}${targetRoute}`;',\n\t\t'\tawait page.goto(url, { waitUntil: \"domcontentloaded\", timeout: 60000 });',\n\t\t'\tawait page.waitForFunction(() => {',\n\t\t'\t\tconst text = (document.body && document.body.innerText || \"\").replace(/\\\\s+/g, \" \").trim();',\n\t\t'\t\tconst hasTokens = !!localStorage.getItem(\"refreshToken\") && !!localStorage.getItem(\"accessToken\") && !!localStorage.getItem(\"user\");',\n\t\t'\t\tconst hasLogin = /Employee\\\\/Customer Login|Employee Sign In|Customer Access|Unable to sign in/i.test(text);',\n\t\t'\t\tconst hasOffline = text.includes(\"*** OFFLINE MODE ***\");',\n\t\t'\t\treturn hasTokens && !hasLogin && !hasOffline && text.length > 40;',\n\t\t'\t}, { timeout: Number(process.env.RESOLVEIO_RUNNER_QA_AUTH_TIMEOUT_MS || process.env.RESOLVEIO_SUPPORT_QA_AUTH_TIMEOUT_MS || 60000) });',\n\t\t'\tawait delay(1000);',\n\t\t'\tawait assertTargetRoute(page);',\n\t\t'}',\n\t\t'',\n\t\t'async function pageSummary(page) {',\n\t\t'\treturn page.evaluate(() => {',\n\t\t'\t\tconst bodyText = (document.body && document.body.innerText || \"\").replace(/\\\\s+/g, \" \").trim();',\n\t\t'\t\treturn {',\n\t\t'\t\t\turl: location.href,',\n\t\t'\t\t\ttitle: document.title,',\n\t\t'\t\t\thasAngularDebug: !!window.ng,',\n\t\t'\t\t\thasRefreshToken: !!localStorage.getItem(\"refreshToken\"),',\n\t\t'\t\t\thasAccessToken: !!localStorage.getItem(\"accessToken\"),',\n\t\t'\t\t\thasUser: !!localStorage.getItem(\"user\"),',\n\t\t'\t\t\thasOfflineModeText: bodyText.includes(\"*** OFFLINE MODE ***\"),',\n\t\t'\t\t\thasLoginText: /Employee\\\\/Customer Login|Employee Sign In|Customer Access|Unable to sign in/i.test(bodyText),',\n\t\t'\t\t\tbodyTextSnippet: bodyText.slice(0, 800),',\n\t\t'\t\t\tlocalStorageKeys: Object.keys(localStorage).sort()',\n\t\t'\t\t};',\n\t\t'\t});',\n\t\t'}',\n\t\t'',\n\t\t'(async () => {',\n\t\t'\tfs.mkdirSync(artifactDir, { recursive: true });',\n\t\t'\tconst puppeteer = requirePuppeteer();',\n\t\t'\tconst browser = await launchBrowser(puppeteer);',\n\t\t'\tlet page;',\n\t\t'\ttry {',\n\t\t'\t\tawait waitForHttpReady(clientUrl, \"QA client\");',\n\t\t'\t\tawait waitForHttpReady(serverUrl, \"QA server\");',\n\t\t'\t\tpage = await browser.newPage();',\n\t\t'\t\tawait page.setViewport({ width: viewportWidth, height: viewportHeight });',\n\t\t'\t\tpage.on(\"console\", (msg) => {',\n\t\t'\t\t\tconst text = msg.text();',\n\t\t'\t\t\tif ([\"error\", \"warning\"].includes(msg.type()) || /error/i.test(text)) {',\n\t\t'\t\t\t\tconsole.log(\"[browser console]\", msg.type(), text);',\n\t\t'\t\t\t}',\n\t\t'\t\t});',\n\t\t'\t\tpage.on(\"pageerror\", (error) => console.log(\"[pageerror]\", error.message));',\n\t\t'\t\tawait logoutExistingBrowserSession(page);',\n\t\t'\t\tawait resetBrowserState(page);',\n\t\t'\t\tconst auth = await login();',\n\t\t'\t\tawait seedAuth(page, auth);',\n\t\t'\t\tawait waitForAuthenticatedApp(page);',\n\t\t'\t\tawait page.screenshot({ path: readyScreenshotPath, fullPage: true });',\n\t\t'\t\tconst summary = {',\n\t\t'\t\t\tstatus: \"pass\",',\n\t\t'\t\t\tclientUrl,',\n\t\t'\t\t\tserverUrl,',\n\t\t'\t\t\ttargetRoute,',\n\t\t'\t\t\tscreenshot: readyScreenshotPath,',\n\t\t'\t\t\tuser: { _id: auth.user && auth.user._id, username: auth.user && auth.user.username, fullname: auth.user && auth.user.fullname },',\n\t\t'\t\t\tpage: await pageSummary(page)',\n\t\t'\t\t};',\n\t\t'\t\twriteResult(summary);',\n\t\t'\t\tconsole.log(JSON.stringify(summary, null, 2));',\n\t\t'\t}',\n\t\t'\tcatch (error) {',\n\t\t'\t\tlet summary = { status: \"fail\", clientUrl, serverUrl, targetRoute, screenshot: failureScreenshotPath, error: error && error.stack || String(error) };',\n\t\t'\t\ttry {',\n\t\t'\t\t\tif (page) {',\n\t\t'\t\t\t\tawait page.screenshot({ path: failureScreenshotPath, fullPage: true });',\n\t\t'\t\t\t\tsummary.page = await pageSummary(page);',\n\t\t'\t\t\t}',\n\t\t'\t\t} catch (screenshotError) {',\n\t\t'\t\t\tsummary.screenshotError = screenshotError && screenshotError.stack || String(screenshotError);',\n\t\t'\t\t}',\n\t\t'\t\twriteResult(summary);',\n\t\t'\t\tconsole.error(JSON.stringify(summary, null, 2));',\n\t\t'\t\tprocess.exitCode = 1;',\n\t\t'\t}',\n\t\t'\tfinally {',\n\t\t'\t\tif (browser && typeof browser.close === \"function\") {',\n\t\t'\t\t\tawait browser.close().catch(() => undefined);',\n\t\t'\t\t}',\n\t\t'\t\tprocess.exit(process.exitCode || 0);',\n\t\t'\t}',\n\t\t'})();',\n\t\t''\n\t].join('\\n');\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/util/ai-runner-qa-auth.ts"],"names":[],"mappings":";;AAKA,8FA+lBC;AA/lBD,SAAgB,yCAAyC,CAAC,OAAyD;IAAzD,wBAAA,EAAA,YAAyD;IAClH,IAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,OAAO,CAAC;IAC3D,IAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC;IACtD,OAAO;QACN,qBAAqB;QACrB,eAAe;QACf,EAAE;QACF,2BAA2B;QAC3B,mCAAmC;QACnC,+BAA+B;QAC/B,iCAAiC;QACjC,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ClH,6CAA6C;QAC7C,uDAAuD;QACvD,MAAM;QACN,MAAM;QACN,GAAG;QACH,EAAE;QACF,gBAAgB;QAChB,kDAAkD;QAClD,wCAAwC;QACxC,kDAAkD;QAClD,YAAY;QACZ,QAAQ;QACR,mDAAmD;QACnD,mDAAmD;QACnD,mCAAmC;QACnC,6EAA6E;QAC7E,iCAAiC;QACjC,6BAA6B;QAC7B,4EAA4E;QAC5E,yDAAyD;QACzD,MAAM;QACN,OAAO;QACP,+EAA+E;QAC/E,6CAA6C;QAC7C,kCAAkC;QAClC,+BAA+B;QAC/B,+BAA+B;QAC/B,wCAAwC;QACxC,8CAA8C;QAC9C,gDAAgD;QAChD,yEAAyE;QACzE,qBAAqB;QACrB,oBAAoB;QACpB,eAAe;QACf,eAAe;QACf,iBAAiB;QACjB,qCAAqC;QACrC,qIAAqI;QACrI,oBAAoB;QACpB,MAAM;QACN,yBAAyB;QACzB,kDAAkD;QAClD,IAAI;QACJ,kBAAkB;QAClB,yJAAyJ;QACzJ,SAAS;QACT,gBAAgB;QAChB,6EAA6E;QAC7E,6CAA6C;QAC7C,MAAM;QACN,+BAA+B;QAC/B,mGAAmG;QACnG,KAAK;QACL,yBAAyB;QACzB,oDAAoD;QACpD,yBAAyB;QACzB,IAAI;QACJ,YAAY;QACZ,yDAAyD;QACzD,kDAAkD;QAClD,KAAK;QACL,wCAAwC;QACxC,IAAI;QACJ,OAAO;QACP,EAAE;KACF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC","file":"ai-runner-qa-auth.js","sourcesContent":["export interface ResolveIORunnerQaAuthBootstrapScriptOptions {\n\tdefaultUsername?: string;\n\tdefaultPassword?: string;\n}\n\nexport function buildResolveIORunnerQaAuthBootstrapScript(options: ResolveIORunnerQaAuthBootstrapScriptOptions = {}): string {\n\tconst defaultUsername = options.defaultUsername || 'admin';\n\tconst defaultPassword = options.defaultPassword || '';\n\treturn [\n\t\t'#!/usr/bin/env node',\n\t\t\"'use strict';\",\n\t\t'',\n\t\t'const fs = require(\"fs\");',\n\t\t'const crypto = require(\"crypto\");',\n\t\t'const http = require(\"http\");',\n\t\t'const https = require(\"https\");',\n\t\t'const path = require(\"path\");',\n\t\t'',\n\t\t'const projectRoot = path.resolve(process.argv[2] || process.cwd());',\n\t\t'const routeArg = process.argv[3] || process.env.RESOLVEIO_RUNNER_QA_TARGET_ROUTE || process.env.RESOLVEIO_SUPPORT_QA_TARGET_ROUTE || process.env.RESOLVEIO_SUPPORT_QA_LAST_URL || \"/\";',\n\t\t'const targetRoute = routeArg.startsWith(\"/\") ? routeArg : `/${routeArg}`;',\n\t\t'const clientUrl = stripTrailingSlash(process.env.RESOLVEIO_RUNNER_QA_CLIENT_URL || process.env.RESOLVEIO_SUPPORT_QA_CLIENT_URL || `http://localhost:${process.env.RESOLVEIO_SUPPORT_QA_CLIENT_PORT || \"4200\"}`);',\n\t\t'const serverUrl = stripTrailingSlash(process.env.RESOLVEIO_RUNNER_QA_SERVER_URL || process.env.RESOLVEIO_SUPPORT_QA_SERVER_URL || \"http://localhost:8080\");',\n\t\t`const username = process.env.RESOLVEIO_RUNNER_QA_USERNAME || process.env.RESOLVEIO_SUPPORT_QA_USERNAME || ${JSON.stringify(defaultUsername)};`,\n\t\t`const password = process.env.RESOLVEIO_RUNNER_QA_PASSWORD || process.env.RESOLVEIO_SUPPORT_QA_PASSWORD || ${JSON.stringify(defaultPassword)};`,\n\t\t'const artifactDir = path.resolve(process.env.RESOLVEIO_RUNNER_QA_ARTIFACT_DIR || process.env.RESOLVEIO_SUPPORT_QA_ARTIFACT_DIR || path.join(projectRoot, \"qa-artifacts\"));',\n\t\t'const viewportWidth = Number(process.env.RESOLVEIO_RUNNER_QA_VIEWPORT_WIDTH || process.env.RESOLVEIO_SUPPORT_QA_VIEWPORT_WIDTH || 1920);',\n\t\t'const viewportHeight = Number(process.env.RESOLVEIO_RUNNER_QA_VIEWPORT_HEIGHT || process.env.RESOLVEIO_SUPPORT_QA_VIEWPORT_HEIGHT || 1080);',\n\t\t'const startupTimeoutMs = Math.max(1000, Number(process.env.RESOLVEIO_RUNNER_QA_ANGULAR_STARTUP_TIMEOUT_SECONDS || process.env.RESOLVEIO_SUPPORT_QA_ANGULAR_STARTUP_TIMEOUT_SECONDS || 900) * 1000);',\n\t\t'const resultPath = path.join(artifactDir, \"auth-bootstrap-result.json\");',\n\t\t'const readyScreenshotPath = path.join(artifactDir, \"auth-bootstrap-ready.png\");',\n\t\t'const failureScreenshotPath = path.join(artifactDir, \"auth-bootstrap-failed.png\");',\n\t\t'',\n\t\t'function stripTrailingSlash(value) {',\n\t\t'\treturn String(value || \"\").replace(/\\\\/+$/, \"\");',\n\t\t'}',\n\t\t'',\n\t\t'function isLocalhostUrl(value) {',\n\t\t'\ttry {',\n\t\t'\t\tconst parsed = new URL(value);',\n\t\t'\t\treturn [\"localhost\", \"127.0.0.1\", \"::1\"].includes(parsed.hostname);',\n\t\t'\t}',\n\t\t'\tcatch (error) {',\n\t\t'\t\treturn false;',\n\t\t'\t}',\n\t\t'}',\n\t\t'',\n\t\t'function resolveLocalMongoUrl() {',\n\t\t'\treturn process.env.MONGO_URL || process.env.RESOLVEIO_RUNNER_QA_MONGO_URL || process.env.RESOLVEIO_SUPPORT_QA_MONGO_URL || `mongodb://127.0.0.1:${process.env.RESOLVEIO_SUPPORT_QA_MONGO_PORT || \"3001\"}/resolveio?directConnection=true`;',\n\t\t'}',\n\t\t'',\n\t\t'function requireMongoClient() {',\n\t\t'\tconst candidates = [',\n\t\t'\t\tpath.join(projectRoot, \"server\", \"node_modules\", \"mongodb\"),',\n\t\t'\t\tpath.join(projectRoot, \"node_modules\", \"mongodb\"),',\n\t\t'\t\tpath.join(process.cwd(), \"server\", \"node_modules\", \"mongodb\"),',\n\t\t'\t\tpath.join(process.cwd(), \"node_modules\", \"mongodb\"),',\n\t\t'\t\t\"mongodb\"',\n\t\t'\t];',\n\t\t'\tfor (const candidate of candidates) {',\n\t\t'\t\ttry { return require(candidate).MongoClient; }',\n\t\t'\t\tcatch (error) {}',\n\t\t'\t}',\n\t\t'\tthrow new Error(\"Unable to require mongodb from project/server node_modules or global resolution\");',\n\t\t'}',\n\t\t'',\n\t\t'function buildDefaultQaUserSettings() {',\n\t\t'\treturn {',\n\t\t'\t\ttable_color: \"#3b3ee3\",',\n\t\t'\t\ttable_font_color: \"#ffffff\",',\n\t\t'\t\tsecondary_table_color: \"#87ceeb\",',\n\t\t'\t\tsecondary_table_font_color: \"#000000\",',\n\t\t'\t\ttertiary_table_color: \"#ff4500\",',\n\t\t'\t\ttertiary_table_font_color: \"#000000\",',\n\t\t'\t\tfont_size: 12,',\n\t\t'\t\tcollapsable_menu: true,',\n\t\t'\t\tentries_per_page: \"25\",',\n\t\t'\t\twarning_color: \"#ffc107\",',\n\t\t'\t\twarning_font_color: \"#000000\",',\n\t\t'\t\twarning_hover_color: \"#e0a800\",',\n\t\t'\t\tsuccess_color: \"#28a745\",',\n\t\t'\t\tsuccess_font_color: \"#ffffff\",',\n\t\t'\t\tsuccess_hover_color: \"#218838\",',\n\t\t'\t\tdanger_color: \"#dc3545\",',\n\t\t'\t\tdanger_font_color: \"#ffffff\",',\n\t\t'\t\tdanger_hover_color: \"#c82333\",',\n\t\t'\t\tinfo_color: \"#17a2b8\",',\n\t\t'\t\tinfo_font_color: \"#ffffff\",',\n\t\t'\t\tinfo_hover_color: \"#138496\",',\n\t\t'\t\tprimary_color: \"#007bff\",',\n\t\t'\t\tprimary_font_color: \"#ffffff\",',\n\t\t'\t\tprimary_hover_color: \"#0069d9\",',\n\t\t'\t\tsecondary_color: \"#868e96\",',\n\t\t'\t\tsecondary_font_color: \"#ffffff\",',\n\t\t'\t\tsecondary_hover_color: \"#5a6268\",',\n\t\t'\t\trouting_preference: \"\",',\n\t\t'\t\topening_route: targetRoute',\n\t\t'\t};',\n\t\t'}',\n\t\t'',\n\t\t'function normalizeQaUserForBrowser(user) {',\n\t\t'\tconst normalized = { ...(user || {}) };',\n\t\t'\tnormalized.other = {',\n\t\t'\t\t...(normalized.other || {}),',\n\t\t'\t\tyards: Array.isArray(normalized.other && normalized.other.yards) ? normalized.other.yards : [],',\n\t\t'\t\ttour_completed: true,',\n\t\t'\t\ttook_tour: true,',\n\t\t'\t\tcore_tour_completed: true,',\n\t\t'\t\twelcome_tour_completed: true,',\n\t\t'\t\ttop_navigation_tour_completed: true,',\n\t\t'\t\tuser_settings_tour_completed: true',\n\t\t'\t};',\n\t\t'\tnormalized.settings = {',\n\t\t'\t\t...buildDefaultQaUserSettings(),',\n\t\t'\t\t...(normalized.settings || {}),',\n\t\t'\t\topening_route: targetRoute',\n\t\t'\t};',\n\t\t'\treturn normalized;',\n\t\t'}',\n\t\t'',\n\t\t'async function ensureLocalQaUser() {',\n\t\t'\tif (!isLocalhostUrl(serverUrl) || process.env.RESOLVEIO_RUNNER_QA_DISABLE_LOCAL_USER_REPAIR === \"true\" || process.env.RESOLVEIO_SUPPORT_QA_DISABLE_LOCAL_USER_REPAIR === \"true\") {',\n\t\t'\t\treturn false;',\n\t\t'\t}',\n\t\t'\tconst MongoClient = requireMongoClient();',\n\t\t'\tconst client = new MongoClient(resolveLocalMongoUrl());',\n\t\t'\tawait client.connect();',\n\t\t'\ttry {',\n\t\t'\t\tconst db = client.db();',\n\t\t'\t\tconst users = db.collection(\"users\");',\n\t\t'\t\tconst now = new Date();',\n\t\t'\t\tconst salt = crypto.randomBytes(32).toString(\"hex\");',\n\t\t'\t\tconst hash = crypto.pbkdf2Sync(password, salt, 25000, 512, \"sha256\").toString(\"hex\");',\n\t\t'\t\tconst existing = await users.findOne({ $or: [{ username }, { email: username }] }, { projection: { _id: 1 } });',\n\t\t'\t\tconst defaultSettings = buildDefaultQaUserSettings();',\n\t\t'\t\tconst baseUser = {',\n\t\t'\t\t\t__v: 0,',\n\t\t'\t\t\tusername,',\n\t\t'\t\t\temail: username.includes(\"@\") ? username : \"dev@resolveio.com\",',\n\t\t'\t\t\tfullname: \"QA Admin\",',\n\t\t'\t\t\troles: { super_admin: true, approvals: [], groups: [], notifications: [], miscs: [] },',\n\t\t'\t\t\tactive: true,',\n\t\t'\t\t\tother: { yards: [], tour_completed: true, took_tour: true, core_tour_completed: true, welcome_tour_completed: true, top_navigation_tour_completed: true, user_settings_tour_completed: true },',\n\t\t'\t\t\tsettings: defaultSettings,',\n\t\t'\t\t\tphonenumber: \"\",',\n\t\t'\t\t\treadonly: false,',\n\t\t'\t\t\tis_customer: false,',\n\t\t'\t\t\thash,',\n\t\t'\t\t\tsalt,',\n\t\t'\t\t\tattempts: 0,',\n\t\t'\t\t\tservices: {},',\n\t\t'\t\t\tupdatedAt: now',\n\t\t'\t\t};',\n\t\t'\t\tif (existing && existing._id) {',\n\t\t'\t\t\tawait users.updateOne({ _id: existing._id }, { $set: baseUser });',\n\t\t'\t\t}',\n\t\t'\t\telse {',\n\t\t'\t\t\tawait users.insertOne({ _id: crypto.randomBytes(12).toString(\"hex\"), createdAt: now, ...baseUser });',\n\t\t'\t\t}',\n\t\t'\t\treturn true;',\n\t\t'\t}',\n\t\t'\tfinally {',\n\t\t'\t\tawait client.close().catch(() => undefined);',\n\t\t'\t}',\n\t\t'}',\n\t\t'',\n\t\t'function writeResult(payload) {',\n\t\t'\tfs.mkdirSync(artifactDir, { recursive: true });',\n\t\t'\tfs.writeFileSync(resultPath, JSON.stringify(payload, null, 2));',\n\t\t'}',\n\t\t'',\n\t\t'function requestJson(url, payload) {',\n\t\t'\treturn new Promise((resolve, reject) => {',\n\t\t'\t\tconst body = JSON.stringify(payload || {});',\n\t\t'\t\tconst parsed = new URL(url);',\n\t\t'\t\tconst mod = parsed.protocol === \"https:\" ? https : http;',\n\t\t'\t\tconst req = mod.request(parsed, {',\n\t\t'\t\t\tmethod: \"POST\",',\n\t\t'\t\t\ttimeout: 20000,',\n\t\t'\t\t\theaders: {',\n\t\t'\t\t\t\t\"content-type\": \"application/json\",',\n\t\t'\t\t\t\t\"content-length\": Buffer.byteLength(body),',\n\t\t'\t\t\t\t\"origin\": clientUrl',\n\t\t'\t\t\t}',\n\t\t'\t\t}, (res) => {',\n\t\t'\t\t\tlet raw = \"\";',\n\t\t'\t\t\tres.setEncoding(\"utf8\");',\n\t\t'\t\t\tres.on(\"data\", (chunk) => { raw += chunk; });',\n\t\t'\t\t\tres.on(\"end\", () => {',\n\t\t'\t\t\t\tlet json = null;',\n\t\t'\t\t\t\ttry { json = raw ? JSON.parse(raw) : {}; }',\n\t\t'\t\t\t\tcatch (error) {',\n\t\t'\t\t\t\t\treject(new Error(`${url} returned non-JSON HTTP ${res.statusCode}: ${raw.slice(0, 300)}`));',\n\t\t'\t\t\t\t\treturn;',\n\t\t'\t\t\t\t}',\n\t\t'\t\t\t\tif (!res.statusCode || res.statusCode >= 400) {',\n\t\t'\t\t\t\t\treject(new Error(`${url} returned HTTP ${res.statusCode}: ${JSON.stringify(json).slice(0, 500)}`));',\n\t\t'\t\t\t\t\treturn;',\n\t\t'\t\t\t\t}',\n\t\t'\t\t\t\tresolve(json);',\n\t\t'\t\t\t});',\n\t\t'\t\t});',\n\t\t'\t\treq.on(\"timeout\", () => req.destroy(new Error(`${url} timed out`)));',\n\t\t'\t\treq.on(\"error\", reject);',\n\t\t'\t\treq.write(body);',\n\t\t'\t\treq.end();',\n\t\t'\t});',\n\t\t'}',\n\t\t'',\n\t\t'function requestReady(url) {',\n\t\t'\treturn new Promise((resolve) => {',\n\t\t'\t\ttry {',\n\t\t'\t\t\tconst parsed = new URL(url);',\n\t\t'\t\t\tconst mod = parsed.protocol === \"https:\" ? https : http;',\n\t\t'\t\t\tconst req = mod.get(parsed, { timeout: 2500 }, (res) => {',\n\t\t'\t\t\t\tres.resume();',\n\t\t'\t\t\t\tresolve(Boolean(res.statusCode && res.statusCode < 500));',\n\t\t'\t\t\t});',\n\t\t'\t\t\treq.on(\"timeout\", () => req.destroy(new Error(\"timeout\")));',\n\t\t'\t\t\treq.on(\"error\", () => resolve(false));',\n\t\t'\t\t}',\n\t\t'\t\tcatch (error) {',\n\t\t'\t\t\tresolve(false);',\n\t\t'\t\t}',\n\t\t'\t});',\n\t\t'}',\n\t\t'',\n\t\t'async function waitForHttpReady(url, label) {',\n\t\t'\tconst deadline = Date.now() + startupTimeoutMs;',\n\t\t'\twhile (Date.now() < deadline) {',\n\t\t'\t\tif (await requestReady(url)) {',\n\t\t'\t\t\treturn;',\n\t\t'\t\t}',\n\t\t'\t\tawait delay(3000);',\n\t\t'\t}',\n\t\t'\tthrow new Error(`${label} did not become ready at ${url} within ${Math.round(startupTimeoutMs / 1000)}s`);',\n\t\t'}',\n\t\t'',\n\t\t'function requirePuppeteer() {',\n\t\t'\tconst candidates = [',\n\t\t'\t\tpath.join(projectRoot, \"server\", \"node_modules\", \"puppeteer\", \"lib\", \"cjs\", \"puppeteer\", \"puppeteer.js\"),',\n\t\t'\t\tpath.join(projectRoot, \"node_modules\", \"puppeteer\", \"lib\", \"cjs\", \"puppeteer\", \"puppeteer.js\"),',\n\t\t'\t\tpath.join(process.cwd(), \"server\", \"node_modules\", \"puppeteer\", \"lib\", \"cjs\", \"puppeteer\", \"puppeteer.js\"),',\n\t\t'\t\tpath.join(process.cwd(), \"node_modules\", \"puppeteer\", \"lib\", \"cjs\", \"puppeteer\", \"puppeteer.js\"),',\n\t\t'\t\t\"puppeteer\"',\n\t\t'\t];',\n\t\t'\tfor (const candidate of candidates) {',\n\t\t'\t\ttry { return require(candidate); }',\n\t\t'\t\tcatch (error) {}',\n\t\t'\t}',\n\t\t'\tthrow new Error(\"Unable to require puppeteer from project/server node_modules or global resolution\");',\n\t\t'}',\n\t\t'',\n\t\t'async function login() {',\n\t\t'\tif (!password) {',\n\t\t'\t\tthrow new Error(\"QA password is empty; source .resolveio-support-tools/env.sh or set RESOLVEIO_RUNNER_QA_PASSWORD before auth bootstrap\");',\n\t\t'\t}',\n\t\t'\tawait waitForHttpReady(serverUrl, \"QA server\");',\n\t\t'\tawait ensureLocalQaUser();',\n\t\t'\tlet loginJson = await requestJson(`${serverUrl}/login`, { username, password });',\n\t\t'\tif ((loginJson && loginJson.error) && /Invalid Username And Password|Too Many Attempts/i.test(String(loginJson.result || \"\"))) {',\n\t\t'\t\tconst repaired = await ensureLocalQaUser();',\n\t\t'\t\tif (repaired) {',\n\t\t'\t\t\tloginJson = await requestJson(`${serverUrl}/login`, { username, password });',\n\t\t'\t\t}',\n\t\t'\t}',\n\t\t'\tconst refreshToken = loginJson && loginJson.result && loginJson.result.token;',\n\t\t'\tif (loginJson.error || !refreshToken) {',\n\t\t'\t\tthrow new Error(`Login failed: ${JSON.stringify(loginJson).slice(0, 800)}`);',\n\t\t'\t}',\n\t\t'\tconst accessJson = await requestJson(`${serverUrl}/accessToken`, { refreshToken });',\n\t\t'\tconst accessToken = accessJson && accessJson.result && accessJson.result.token;',\n\t\t'\tconst user = accessJson && accessJson.result && accessJson.result.user;',\n\t\t'\tif (accessJson.error || !accessToken || !user) {',\n\t\t'\t\tthrow new Error(`Access token failed: ${JSON.stringify(accessJson).slice(0, 800)}`);',\n\t\t'\t}',\n\t\t'\treturn { refreshToken, accessToken, user: normalizeQaUserForBrowser(user) };',\n\t\t'}',\n\t\t'',\n\t\t'async function launchBrowser(puppeteer) {',\n\t\t'\tconst browserUrl = process.env.RESOLVEIO_RUNNER_QA_BROWSER_URL || process.env.RESOLVEIO_SUPPORT_QA_BROWSER_URL || \"\";',\n\t\t'\tif (browserUrl) {',\n\t\t'\t\treturn puppeteer.connect({ browserURL: browserUrl, protocolTimeout: 30000, defaultViewport: null });',\n\t\t'\t}',\n\t\t'\tconst launchOptions = {',\n\t\t'\t\theadless: true,',\n\t\t'\t\tdefaultViewport: { width: viewportWidth, height: viewportHeight },',\n\t\t'\t\targs: [\"--no-sandbox\", \"--disable-setuid-sandbox\", \"--disable-dev-shm-usage\", `--window-size=${viewportWidth},${viewportHeight}`]',\n\t\t'\t};',\n\t\t'\tif (process.env.PUPPETEER_EXECUTABLE_PATH || process.env.CHROME_BIN) {',\n\t\t'\t\tlaunchOptions.executablePath = process.env.PUPPETEER_EXECUTABLE_PATH || process.env.CHROME_BIN;',\n\t\t'\t}',\n\t\t'\treturn puppeteer.launch(launchOptions);',\n\t\t'}',\n\t\t'',\n\t\t'async function resetBrowserState(page) {',\n\t\t'\tawait waitForHttpReady(clientUrl, \"QA client\");',\n\t\t'\tawait page.goto(clientUrl, { waitUntil: \"domcontentloaded\", timeout: 45000 });',\n\t\t'\tawait page.evaluate(async () => {',\n\t\t'\t\ttry {',\n\t\t'\t\t\tconst registrations = await navigator.serviceWorker.getRegistrations();',\n\t\t'\t\t\tawait Promise.all(registrations.map((registration) => registration.unregister().catch(() => false)));',\n\t\t'\t\t} catch (error) {}',\n\t\t'\t\ttry {',\n\t\t'\t\t\tif (window.caches && window.caches.keys) {',\n\t\t'\t\t\t\tconst keys = await window.caches.keys();',\n\t\t'\t\t\t\tawait Promise.all(keys.map((key) => window.caches.delete(key).catch(() => false)));',\n\t\t'\t\t\t}',\n\t\t'\t\t} catch (error) {}',\n\t\t'\t\ttry {',\n\t\t'\t\t\tif (window.indexedDB && window.indexedDB.databases) {',\n\t\t'\t\t\t\tconst databases = await window.indexedDB.databases();',\n\t\t'\t\t\t\tawait Promise.all(databases.filter((database) => database && database.name).map((database) => new Promise((resolve) => {',\n\t\t'\t\t\t\t\tconst request = window.indexedDB.deleteDatabase(database.name);',\n\t\t'\t\t\t\t\trequest.onsuccess = () => resolve(true);',\n\t\t'\t\t\t\t\trequest.onerror = () => resolve(false);',\n\t\t'\t\t\t\t\trequest.onblocked = () => resolve(false);',\n\t\t'\t\t\t\t})));',\n\t\t'\t\t\t}',\n\t\t'\t\t} catch (error) {}',\n\t\t'\t\tlocalStorage.clear();',\n\t\t'\t\tsessionStorage.clear();',\n\t\t'\t});',\n\t\t'}',\n\t\t'',\n\t\t'async function seedAuth(page, auth) {',\n\t\t'\tauth.user = normalizeQaUserForBrowser(auth.user);',\n\t\t'\tawait page.evaluate((payload) => {',\n\t\t'\t\tlocalStorage.setItem(\"refreshToken\", payload.refreshToken);',\n\t\t'\t\tlocalStorage.setItem(\"accessToken\", payload.accessToken);',\n\t\t'\t\tlocalStorage.setItem(\"user\", JSON.stringify(payload.user));',\n\t\t'\t\tlocalStorage.setItem(\"lastURL\", payload.lastURL);',\n\t\t'\t\tlocalStorage.setItem(\"resolveio.runnerQaAuthBootstrappedAt\", payload.bootstrappedAt);',\n\t\t'\t}, { ...auth, lastURL: targetRoute, bootstrappedAt: new Date().toISOString() });',\n\t\t'}',\n\t\t'',\n\t\t'async function patchBrowserQaUser(page) {',\n\t\t'\tawait page.evaluate((nextRoute) => {',\n\t\t'\t\tlet user = {};',\n\t\t'\t\ttry { user = JSON.parse(localStorage.getItem(\"user\") || \"{}\"); } catch (error) { user = {}; }',\n\t\t'\t\tconst settings = {',\n\t\t'\t\t\ttable_color: \"#3b3ee3\",',\n\t\t'\t\t\ttable_font_color: \"#ffffff\",',\n\t\t'\t\t\tsecondary_table_color: \"#87ceeb\",',\n\t\t'\t\t\tsecondary_table_font_color: \"#000000\",',\n\t\t'\t\t\ttertiary_table_color: \"#ff4500\",',\n\t\t'\t\t\ttertiary_table_font_color: \"#000000\",',\n\t\t'\t\t\tfont_size: 12,',\n\t\t'\t\t\tcollapsable_menu: true,',\n\t\t'\t\t\tentries_per_page: \"25\",',\n\t\t'\t\t\twarning_color: \"#ffc107\",',\n\t\t'\t\t\twarning_font_color: \"#000000\",',\n\t\t'\t\t\twarning_hover_color: \"#e0a800\",',\n\t\t'\t\t\tsuccess_color: \"#28a745\",',\n\t\t'\t\t\tsuccess_font_color: \"#ffffff\",',\n\t\t'\t\t\tsuccess_hover_color: \"#218838\",',\n\t\t'\t\t\tdanger_color: \"#dc3545\",',\n\t\t'\t\t\tdanger_font_color: \"#ffffff\",',\n\t\t'\t\t\tdanger_hover_color: \"#c82333\",',\n\t\t'\t\t\tinfo_color: \"#17a2b8\",',\n\t\t'\t\t\tinfo_font_color: \"#ffffff\",',\n\t\t'\t\t\tinfo_hover_color: \"#138496\",',\n\t\t'\t\t\tprimary_color: \"#007bff\",',\n\t\t'\t\t\tprimary_font_color: \"#ffffff\",',\n\t\t'\t\t\tprimary_hover_color: \"#0069d9\",',\n\t\t'\t\t\tsecondary_color: \"#868e96\",',\n\t\t'\t\t\tsecondary_font_color: \"#ffffff\",',\n\t\t'\t\t\tsecondary_hover_color: \"#5a6268\",',\n\t\t'\t\t\trouting_preference: \"\",',\n\t\t'\t\t\topening_route: nextRoute',\n\t\t'\t\t};',\n\t\t'\t\tuser = {',\n\t\t'\t\t\t...user,',\n\t\t'\t\t\tother: {',\n\t\t'\t\t\t\t...(user.other || {}),',\n\t\t'\t\t\t\tyards: Array.isArray(user.other && user.other.yards) ? user.other.yards : [],',\n\t\t'\t\t\t\ttour_completed: true,',\n\t\t'\t\t\t\ttook_tour: true,',\n\t\t'\t\t\t\tcore_tour_completed: true,',\n\t\t'\t\t\t\twelcome_tour_completed: true,',\n\t\t'\t\t\t\ttop_navigation_tour_completed: true,',\n\t\t'\t\t\t\tuser_settings_tour_completed: true',\n\t\t'\t\t\t},',\n\t\t'\t\t\tsettings: { ...settings, ...(user.settings || {}), opening_route: nextRoute }',\n\t\t'\t\t};',\n\t\t'\t\tlocalStorage.setItem(\"user\", JSON.stringify(user));',\n\t\t'\t\tlocalStorage.setItem(\"lastURL\", nextRoute);',\n\t\t'\t\tlocalStorage.setItem(\"resolveio.runnerQaPostLoginGateRepairedAt\", new Date().toISOString());',\n\t\t'\t});',\n\t\t'}',\n\t\t'',\n\t\t'async function dismissVisibleTourOrSetupGate(page) {',\n\t\t'\treturn page.evaluate(() => {',\n\t\t'\t\tconst controls = Array.from(document.querySelectorAll(\"button, a, [role=\\'button\\']\"));',\n\t\t'\t\tconst control = controls.find((candidate) => {',\n\t\t'\t\t\tconst text = (candidate.textContent || \"\").replace(/\\\\s+/g, \" \").trim();',\n\t\t'\t\t\treturn /^(skip|finish|done|close)$/i.test(text);',\n\t\t'\t\t});',\n\t\t'\t\tif (control && typeof control.click === \"function\") {',\n\t\t'\t\t\tcontrol.click();',\n\t\t'\t\t\treturn true;',\n\t\t'\t\t}',\n\t\t'\t\treturn false;',\n\t\t'\t});',\n\t\t'}',\n\t\t'',\n\t\t'function isPostLoginSetupOrTourGate(currentRoute, summary) {',\n\t\t'\tconst text = String(summary && summary.bodyTextSnippet || \"\");',\n\t\t'\treturn currentRoute === \"/user-settings/settings\" || /Top Navigation Step \\\\d+ of \\\\d+|\\\\bSkip\\\\b|User Settings/i.test(text);',\n\t\t'}',\n\t\t'',\n\t\t'async function repairPostLoginSetupOrTourGate(page, expectedRoute) {',\n\t\t'\tif (process.env.RESOLVEIO_RUNNER_QA_DISABLE_POST_LOGIN_ROUTE_REPAIR === \"true\" || process.env.RESOLVEIO_SUPPORT_QA_DISABLE_POST_LOGIN_ROUTE_REPAIR === \"true\") {',\n\t\t'\t\treturn false;',\n\t\t'\t}',\n\t\t'\tconst current = normalizeRoutePath(await page.evaluate(() => location.href));',\n\t\t'\tconst summary = await pageSummary(page).catch(() => ({}));',\n\t\t'\tif (!isPostLoginSetupOrTourGate(current, summary)) {',\n\t\t'\t\treturn false;',\n\t\t'\t}',\n\t\t'\tawait dismissVisibleTourOrSetupGate(page).catch(() => false);',\n\t\t'\tawait patchBrowserQaUser(page);',\n\t\t'\tawait ensureLocalQaUser().catch(() => false);',\n\t\t'\tawait page.goto(`${clientUrl}${expectedRoute}`, { waitUntil: \"domcontentloaded\", timeout: 60000 });',\n\t\t'\tawait delay(1500);',\n\t\t'\tawait dismissVisibleTourOrSetupGate(page).catch(() => false);',\n\t\t'\tawait patchBrowserQaUser(page);',\n\t\t'\tawait delay(500);',\n\t\t'\tconst repairedCurrent = normalizeRoutePath(await page.evaluate(() => location.href));',\n\t\t'\treturn repairedCurrent === expectedRoute;',\n\t\t'}',\n\t\t'',\n\t\t'function delay(ms) {',\n\t\t'\treturn new Promise((resolve) => setTimeout(resolve, ms));',\n\t\t'}',\n\t\t'',\n\t\t'function normalizeRoutePath(value) {',\n\t\t'\ttry {',\n\t\t'\t\t\tconst parsed = new URL(value, clientUrl);',\n\t\t'\t\t\tlet pathname = parsed.pathname || \"/\";',\n\t\t'\t\t\tpathname = pathname.replace(/\\\\/+$/, \"\") || \"/\";',\n\t\t'\t\t\treturn pathname;',\n\t\t'\t}',\n\t\t'\tcatch (error) {',\n\t\t'\t\t\treturn String(value || \"/\").split(\"?\")[0].replace(/\\\\/+$/, \"\") || \"/\";',\n\t\t'\t}',\n\t\t'}',\n\t\t'',\n\t\t'async function assertTargetRoute(page) {',\n\t\t'\tconst expected = normalizeRoutePath(targetRoute);',\n\t\t'\tif (expected === \"/\") {',\n\t\t'\t\treturn;',\n\t\t'\t}',\n\t\t'\tconst current = normalizeRoutePath(await page.evaluate(() => location.href));',\n\t\t'\tif (current !== expected) {',\n\t\t'\t\tconst repaired = await repairPostLoginSetupOrTourGate(page, expected);',\n\t\t'\t\tif (repaired) {',\n\t\t'\t\t\treturn;',\n\t\t'\t\t}',\n\t\t'\t\tconst summary = await pageSummary(page).catch(() => ({}));',\n\t\t'\t\tthrow new Error(`QA auth bootstrap reached ${current}, not requested target route ${expected}. This is a route blocker; do not continue browser QA until the runner/app can reach the requested screen. Page summary: ${JSON.stringify(summary).slice(0, 1200)}`);',\n\t\t'\t}',\n\t\t'}',\n\t\t'',\n\t\t'async function waitForStableTargetRoute(page) {',\n\t\t'\tconst expected = normalizeRoutePath(targetRoute);',\n\t\t'\tif (expected === \"/\") {',\n\t\t'\t\treturn;',\n\t\t'\t}',\n\t\t'\tconst deadline = Date.now() + Number(process.env.RESOLVEIO_RUNNER_QA_ROUTE_STABILITY_TIMEOUT_MS || process.env.RESOLVEIO_SUPPORT_QA_ROUTE_STABILITY_TIMEOUT_MS || 7000);',\n\t\t'\tlet stableSince = 0;',\n\t\t'\tlet lastCurrent = \"\";',\n\t\t'\twhile (Date.now() < deadline) {',\n\t\t'\t\tconst current = normalizeRoutePath(await page.evaluate(() => location.href));',\n\t\t'\t\tlastCurrent = current;',\n\t\t'\t\tif (current === expected) {',\n\t\t'\t\t\tstableSince = stableSince || Date.now();',\n\t\t'\t\t\tif (Date.now() - stableSince >= Number(process.env.RESOLVEIO_RUNNER_QA_ROUTE_STABLE_MS || process.env.RESOLVEIO_SUPPORT_QA_ROUTE_STABLE_MS || 2500)) {',\n\t\t'\t\t\t\treturn;',\n\t\t'\t\t\t}',\n\t\t'\t\t}',\n\t\t'\t\telse {',\n\t\t'\t\t\tstableSince = 0;',\n\t\t'\t\t}',\n\t\t'\t\tawait delay(250);',\n\t\t'\t}',\n\t\t'\tconst summary = await pageSummary(page).catch(() => ({}));',\n\t\t'\tthrow new Error(`QA auth bootstrap route was not stable on requested target ${expected}; last route was ${lastCurrent || \"unknown\"}. This is a route blocker; do not continue browser QA until the runner/app can remain on the requested screen. Page summary: ${JSON.stringify(summary).slice(0, 1200)}`);',\n\t\t'}',\n\t\t'',\n\t\t'async function assertSummaryOnTargetRoute(summary) {',\n\t\t'\tconst expected = normalizeRoutePath(targetRoute);',\n\t\t'\tif (expected === \"/\") {',\n\t\t'\t\treturn;',\n\t\t'\t}',\n\t\t'\tconst current = normalizeRoutePath(summary && summary.url || \"\");',\n\t\t'\tif (current !== expected) {',\n\t\t'\t\tthrow new Error(`QA auth bootstrap final summary is on ${current}, not requested target route ${expected}. This is a route blocker; refusing to write a false pass. Page summary: ${JSON.stringify(summary).slice(0, 1200)}`);',\n\t\t'\t}',\n\t\t'}',\n\t\t'',\n\t\t'async function logoutExistingBrowserSession(page) {',\n\t\t'\ttry {',\n\t\t'\t\tawait page.goto(clientUrl, { waitUntil: \"domcontentloaded\", timeout: 45000 });',\n\t\t'\t\tawait delay(500);',\n\t\t'\t\tawait page.evaluate(() => {',\n\t\t'\t\t\tconst controls = Array.from(document.querySelectorAll(\"button, a, [role=\\'button\\']\"));',\n\t\t'\t\t\tconst logoutControl = controls.find((control) => /(^|\\\\s)logout(\\\\s|$)/i.test((control.textContent || \"\").trim()));',\n\t\t'\t\t\tif (logoutControl && typeof logoutControl.click === \"function\") {',\n\t\t'\t\t\t\tlogoutControl.click();',\n\t\t'\t\t\t\treturn true;',\n\t\t'\t\t\t}',\n\t\t'\t\t\treturn false;',\n\t\t'\t\t});',\n\t\t'\t\tawait delay(1000);',\n\t\t'\t}',\n\t\t'\tcatch (error) {}',\n\t\t'}',\n\t\t'',\n\t\t'async function waitForAuthenticatedApp(page) {',\n\t\t'\tconst url = `${clientUrl}${targetRoute}`;',\n\t\t'\tawait page.goto(url, { waitUntil: \"domcontentloaded\", timeout: 60000 });',\n\t\t'\tawait page.waitForFunction(() => {',\n\t\t'\t\tconst text = (document.body && document.body.innerText || \"\").replace(/\\\\s+/g, \" \").trim();',\n\t\t'\t\tconst hasTokens = !!localStorage.getItem(\"refreshToken\") && !!localStorage.getItem(\"accessToken\") && !!localStorage.getItem(\"user\");',\n\t\t'\t\tconst hasLogin = /Employee\\\\/Customer Login|Employee Sign In|Customer Access|Unable to sign in/i.test(text);',\n\t\t'\t\tconst hasOffline = text.includes(\"*** OFFLINE MODE ***\");',\n\t\t'\t\treturn hasTokens && !hasLogin && !hasOffline && text.length > 40;',\n\t\t'\t}, { timeout: Number(process.env.RESOLVEIO_RUNNER_QA_AUTH_TIMEOUT_MS || process.env.RESOLVEIO_SUPPORT_QA_AUTH_TIMEOUT_MS || 60000) });',\n\t\t'\tawait delay(1000);',\n\t\t'\tawait assertTargetRoute(page);',\n\t\t'\tawait waitForStableTargetRoute(page);',\n\t\t'}',\n\t\t'',\n\t\t'async function pageSummary(page) {',\n\t\t'\treturn page.evaluate(() => {',\n\t\t'\t\tconst bodyText = (document.body && document.body.innerText || \"\").replace(/\\\\s+/g, \" \").trim();',\n\t\t'\t\treturn {',\n\t\t'\t\t\turl: location.href,',\n\t\t'\t\t\ttitle: document.title,',\n\t\t'\t\t\thasAngularDebug: !!window.ng,',\n\t\t'\t\t\thasRefreshToken: !!localStorage.getItem(\"refreshToken\"),',\n\t\t'\t\t\thasAccessToken: !!localStorage.getItem(\"accessToken\"),',\n\t\t'\t\t\thasUser: !!localStorage.getItem(\"user\"),',\n\t\t'\t\t\thasOfflineModeText: bodyText.includes(\"*** OFFLINE MODE ***\"),',\n\t\t'\t\t\thasLoginText: /Employee\\\\/Customer Login|Employee Sign In|Customer Access|Unable to sign in/i.test(bodyText),',\n\t\t'\t\t\tbodyTextSnippet: bodyText.slice(0, 800),',\n\t\t'\t\t\tlocalStorageKeys: Object.keys(localStorage).sort()',\n\t\t'\t\t};',\n\t\t'\t});',\n\t\t'}',\n\t\t'',\n\t\t'(async () => {',\n\t\t'\tfs.mkdirSync(artifactDir, { recursive: true });',\n\t\t'\tconst puppeteer = requirePuppeteer();',\n\t\t'\tconst browser = await launchBrowser(puppeteer);',\n\t\t'\tlet page;',\n\t\t'\ttry {',\n\t\t'\t\tawait waitForHttpReady(clientUrl, \"QA client\");',\n\t\t'\t\tawait waitForHttpReady(serverUrl, \"QA server\");',\n\t\t'\t\tpage = await browser.newPage();',\n\t\t'\t\tawait page.setViewport({ width: viewportWidth, height: viewportHeight });',\n\t\t'\t\tpage.on(\"console\", (msg) => {',\n\t\t'\t\t\tconst text = msg.text();',\n\t\t'\t\t\tif ([\"error\", \"warning\"].includes(msg.type()) || /error/i.test(text)) {',\n\t\t'\t\t\t\tconsole.log(\"[browser console]\", msg.type(), text);',\n\t\t'\t\t\t}',\n\t\t'\t\t});',\n\t\t'\t\tpage.on(\"pageerror\", (error) => console.log(\"[pageerror]\", error.message));',\n\t\t'\t\tawait logoutExistingBrowserSession(page);',\n\t\t'\t\tawait resetBrowserState(page);',\n\t\t'\t\tconst auth = await login();',\n\t\t'\t\tawait seedAuth(page, auth);',\n\t\t'\t\tawait waitForAuthenticatedApp(page);',\n\t\t'\t\tconst finalPage = await pageSummary(page);',\n\t\t'\t\tawait assertSummaryOnTargetRoute(finalPage);',\n\t\t'\t\tawait page.screenshot({ path: readyScreenshotPath, fullPage: true });',\n\t\t'\t\tconst summary = {',\n\t\t'\t\t\tstatus: \"pass\",',\n\t\t'\t\t\tclientUrl,',\n\t\t'\t\t\tserverUrl,',\n\t\t'\t\t\ttargetRoute,',\n\t\t'\t\t\tscreenshot: readyScreenshotPath,',\n\t\t'\t\t\tuser: { _id: auth.user && auth.user._id, username: auth.user && auth.user.username, fullname: auth.user && auth.user.fullname },',\n\t\t'\t\t\tpage: finalPage',\n\t\t'\t\t};',\n\t\t'\t\twriteResult(summary);',\n\t\t'\t\tconsole.log(JSON.stringify(summary, null, 2));',\n\t\t'\t}',\n\t\t'\tcatch (error) {',\n\t\t'\t\tlet summary = { status: \"fail\", clientUrl, serverUrl, targetRoute, screenshot: failureScreenshotPath, error: error && error.stack || String(error) };',\n\t\t'\t\ttry {',\n\t\t'\t\t\tif (page) {',\n\t\t'\t\t\t\tawait page.screenshot({ path: failureScreenshotPath, fullPage: true });',\n\t\t'\t\t\t\tsummary.page = await pageSummary(page);',\n\t\t'\t\t\t}',\n\t\t'\t\t} catch (screenshotError) {',\n\t\t'\t\t\tsummary.screenshotError = screenshotError && screenshotError.stack || String(screenshotError);',\n\t\t'\t\t}',\n\t\t'\t\twriteResult(summary);',\n\t\t'\t\tconsole.error(JSON.stringify(summary, null, 2));',\n\t\t'\t\tprocess.exitCode = 1;',\n\t\t'\t}',\n\t\t'\tfinally {',\n\t\t'\t\tif (browser && typeof browser.close === \"function\") {',\n\t\t'\t\t\tawait browser.close().catch(() => undefined);',\n\t\t'\t\t}',\n\t\t'\t\tprocess.exit(process.exitCode || 0);',\n\t\t'\t}',\n\t\t'})();',\n\t\t''\n\t].join('\\n');\n}\n"]}
|