From bd1a894f0615ad6264beffecdacdf37e6c865bfb Mon Sep 17 00:00:00 2001 From: abose Date: Wed, 18 Jun 2025 17:01:11 +0530 Subject: [PATCH 1/2] chore: add metrics for login --- src/services/login.js | 30 ++++++++++++++++++++++++------ src/utils/Metrics.js | 3 ++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/services/login.js b/src/services/login.js index b80e01b24c..d37a780f2f 100644 --- a/src/services/login.js +++ b/src/services/login.js @@ -16,10 +16,12 @@ * */ +/*global logger*/ define(function (require, exports, module) { const EventDispatcher = require("utils/EventDispatcher"), PreferencesManager = require("preferences/PreferencesManager"), + Metrics = require("utils/Metrics"), Dialogs = require("widgets/Dialogs"), DefaultDialogs = require("widgets/DefaultDialogs"), Strings = require("strings"), @@ -164,10 +166,16 @@ define(function (require, exports, module) { return localAutoAuthURL.replace("http://localhost:", ""); } + const PLATFORM_STRINGS = { + "win": "Windows", + "mac": "mac", + "linux": "Linux" + }; // never rejects. async function _getAppAuthSession() { const authPortURL = _getAutoAuthPortURL(); - const appName = encodeURIComponent(`${Strings.APP_NAME} Desktop on ${Phoenix.platform}`); + const platformStr = PLATFORM_STRINGS[Phoenix.platform] || Phoenix.platform; + const appName = encodeURIComponent(`${Strings.APP_NAME} Desktop on ${platformStr}`); const resolveURL = `${Phoenix.config.account_url}getAppAuthSession?autoAuthPort=${authPortURL}&appName=${appName}`; // {"isSuccess":true,"appSessionID":"a uuid...","validationCode":"SWXP07"} try { @@ -182,7 +190,8 @@ define(function (require, exports, module) { return null; } catch (e) { console.error(e, "Failed to call getAppAuthSession API endpoint", resolveURL); - // todo raise metrics/log + Metrics.countEvent(Metrics.EVENT_TYPE.AUTH, 'getAppAuth', Phoenix.platform); + logger.reportError(e, "Failed to call getAppAuthSession API endpoint" + resolveURL); return null; } } @@ -197,7 +206,7 @@ define(function (require, exports, module) { } catch (e) { console.error("failed to send auth login verification code to node", e); // we ignore this and continue for manual verification - // todo raise metrics + Metrics.countEvent(Metrics.EVENT_TYPE.AUTH, 'autoFail', Phoenix.platform); } } @@ -290,8 +299,10 @@ define(function (require, exports, module) { setTimeout(checkLoginStatus, 100); } } + let isAutoSignedIn = false; exports.on(_EVT_PAGE_FOCUSED, checkLoginStatus); async function _AutoSignedIn() { + isAutoSignedIn = true; await checkLoginStatus(); } authNodeConnector.one(EVENT_CONNECTED, _AutoSignedIn); @@ -301,13 +312,18 @@ define(function (require, exports, module) { exports.off(_EVT_PAGE_FOCUSED, checkLoginStatus); authNodeConnector.off(EVENT_CONNECTED, _AutoSignedIn); clearTimeout(closeTimeout); + Metrics.countEvent(Metrics.EVENT_TYPE.AUTH, + isAutoSignedIn ? 'autoLogin' : 'manLogin' + , Phoenix.platform); + Metrics.countEvent(Metrics.EVENT_TYPE.AUTH, "login", + isAutoSignedIn ? 'auto' : 'man'); }); NativeApp.openURLInDefaultBrowser(appSignInURL); } async function signOutAccount() { + const resolveURL = `${Phoenix.config.account_url}logoutSession`; try { - const resolveURL = `${Phoenix.config.account_url}logoutSession`; let input = { appSessionID: userProfile.apiKey }; @@ -329,8 +345,8 @@ define(function (require, exports, module) { Strings.SIGNED_OUT_FAILED_TITLE, Strings.SIGNED_OUT_FAILED_MESSAGE ); + Metrics.countEvent(Metrics.EVENT_TYPE.AUTH, 'logoutFail', Phoenix.platform); return; - // todo raise metrics } await _resetAccountLogin(); Dialogs.showModalDialog( @@ -338,6 +354,7 @@ define(function (require, exports, module) { Strings.SIGNED_OUT, Strings.SIGNED_OUT_MESSAGE_FRIENDLY ); + Metrics.countEvent(Metrics.EVENT_TYPE.AUTH, 'logoutOK', Phoenix.platform); } catch (error) { console.error("Network error. Could not log out session.", error); Dialogs.showModalDialog( @@ -345,7 +362,8 @@ define(function (require, exports, module) { Strings.SIGNED_OUT_FAILED_TITLE, Strings.SIGNED_OUT_FAILED_MESSAGE ); - // todo raise metrics + Metrics.countEvent(Metrics.EVENT_TYPE.AUTH, 'getAppAuth', Phoenix.platform); + logger.reportError(error, "Failed to call logout calling" + resolveURL); } } diff --git a/src/utils/Metrics.js b/src/utils/Metrics.js index d502892d2a..8108cc79fd 100644 --- a/src/utils/Metrics.js +++ b/src/utils/Metrics.js @@ -119,7 +119,8 @@ define(function (require, exports, module) { USER: "user", NODEJS: "node", LINT: "lint", - GIT: "git" + GIT: "git", + AUTH: "auth" }; /** From 4349d65e8afef9e9dde5f74369df5b828b14dc23 Mon Sep 17 00:00:00 2001 From: abose Date: Wed, 18 Jun 2025 20:18:27 +0530 Subject: [PATCH 2/2] test: run desktop tests in pull requests to completion even with some suites fails --- .../workflows/desktop-linux-prod-test-pull.yml | 16 ++++++++++++++++ .github/workflows/desktop-linux-test-pull.yml | 16 ++++++++++++++++ .github/workflows/desktop-mac-m1-test-pull.yml | 16 ++++++++++++++++ .github/workflows/desktop-mac-test-pull.yml | 16 ++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/.github/workflows/desktop-linux-prod-test-pull.yml b/.github/workflows/desktop-linux-prod-test-pull.yml index 57e41d7e3f..47005a3142 100644 --- a/.github/workflows/desktop-linux-prod-test-pull.yml +++ b/.github/workflows/desktop-linux-prod-test-pull.yml @@ -48,6 +48,8 @@ jobs: - name: Run tauri unit tests uses: nick-fields/retry@v2 + id: linuxRunUnit + continue-on-error: true with: timeout_minutes: 12 max_attempts: 3 @@ -55,6 +57,8 @@ jobs: - name: Run tauri integration tests uses: nick-fields/retry@v2 + id: linuxRunIntegration + continue-on-error: true with: timeout_minutes: 12 max_attempts: 3 @@ -62,6 +66,8 @@ jobs: - name: Run tauri mainview tests uses: nick-fields/retry@v2 + id: linuxRunMainview + continue-on-error: true with: timeout_minutes: 12 max_attempts: 3 @@ -69,6 +75,8 @@ jobs: - name: Run tauri livepreview tests uses: nick-fields/retry@v2 + id: linuxRunLivepreview + continue-on-error: true with: timeout_minutes: 12 max_attempts: 3 @@ -76,7 +84,15 @@ jobs: - name: Run tauri LegacyInteg tests uses: nick-fields/retry@v2 + id: linuxRunLegacyInteg + continue-on-error: true with: timeout_minutes: 20 max_attempts: 3 command: xvfb-run ../phoenix-desktop/src-tauri/target/debug/phoenix-test --run-tests=LegacyInteg -q + + - name: Fail on test runs failed in Linux + if: steps.linuxRunUnit.outcome == 'failure' || steps.linuxRunIntegration.outcome == 'failure' || steps.linuxRunMainview.outcome == 'failure' || steps.linuxRunLivepreview.outcome == 'failure' || steps.linuxRunLegacyInteg.outcome == 'failure' + run: | + echo "Linux tests failed, marking step as failed" + exit 1 diff --git a/.github/workflows/desktop-linux-test-pull.yml b/.github/workflows/desktop-linux-test-pull.yml index ac734955cf..018e8508b8 100644 --- a/.github/workflows/desktop-linux-test-pull.yml +++ b/.github/workflows/desktop-linux-test-pull.yml @@ -47,6 +47,8 @@ jobs: - name: Run tauri unit tests uses: nick-fields/retry@v2 + id: linuxRunUnit + continue-on-error: true with: timeout_minutes: 12 max_attempts: 3 @@ -54,6 +56,8 @@ jobs: - name: Run tauri integration tests uses: nick-fields/retry@v2 + id: linuxRunIntegration + continue-on-error: true with: timeout_minutes: 12 max_attempts: 3 @@ -61,6 +65,8 @@ jobs: - name: Run tauri mainview tests uses: nick-fields/retry@v2 + id: linuxRunMainview + continue-on-error: true with: timeout_minutes: 12 max_attempts: 3 @@ -68,6 +74,8 @@ jobs: - name: Run tauri livepreview tests uses: nick-fields/retry@v2 + id: linuxRunLivepreview + continue-on-error: true with: timeout_minutes: 12 max_attempts: 3 @@ -75,7 +83,15 @@ jobs: - name: Run tauri LegacyInteg tests uses: nick-fields/retry@v2 + id: linuxRunLegacyInteg + continue-on-error: true with: timeout_minutes: 20 max_attempts: 3 command: xvfb-run ../phoenix-desktop/src-tauri/target/debug/phoenix-test --run-tests=LegacyInteg -q + + - name: Fail on test runs failed in Linux + if: steps.linuxRunUnit.outcome == 'failure' || steps.linuxRunIntegration.outcome == 'failure' || steps.linuxRunMainview.outcome == 'failure' || steps.linuxRunLivepreview.outcome == 'failure' || steps.linuxRunLegacyInteg.outcome == 'failure' + run: | + echo "Linux tests failed, marking step as failed" + exit 1 diff --git a/.github/workflows/desktop-mac-m1-test-pull.yml b/.github/workflows/desktop-mac-m1-test-pull.yml index 15993c36d8..df7493e06a 100644 --- a/.github/workflows/desktop-mac-m1-test-pull.yml +++ b/.github/workflows/desktop-mac-m1-test-pull.yml @@ -40,6 +40,8 @@ jobs: - name: Run tauri unit tests uses: nick-fields/retry@v2 + id: macM1RunUnit + continue-on-error: true with: timeout_minutes: 12 max_attempts: 3 @@ -47,6 +49,8 @@ jobs: - name: Run tauri integration tests uses: nick-fields/retry@v2 + id: macM1RunIntegration + continue-on-error: true with: timeout_minutes: 12 max_attempts: 3 @@ -54,6 +58,8 @@ jobs: - name: Run tauri mainview tests uses: nick-fields/retry@v2 + id: macM1RunMainview + continue-on-error: true with: timeout_minutes: 12 max_attempts: 3 @@ -61,6 +67,8 @@ jobs: - name: Run tauri livepreview tests uses: nick-fields/retry@v2 + id: macM1RunLivepreview + continue-on-error: true with: timeout_minutes: 12 max_attempts: 3 @@ -68,7 +76,15 @@ jobs: - name: Run tauri LegacyInteg tests uses: nick-fields/retry@v2 + id: macM1RunLegacyInteg + continue-on-error: true with: timeout_minutes: 30 max_attempts: 3 command: ../phoenix-desktop/src-tauri/target/debug/phoenix-test --run-tests=LegacyInteg -q + + - name: Fail on test runs failed in Mac M1 + if: steps.macM1RunUnit.outcome == 'failure' || steps.macM1RunIntegration.outcome == 'failure' || steps.macM1RunMainview.outcome == 'failure' || steps.macM1RunLivepreview.outcome == 'failure' || steps.macM1RunLegacyInteg.outcome == 'failure' + run: | + echo "Mac M1 tests failed, marking step as failed" + exit 1 diff --git a/.github/workflows/desktop-mac-test-pull.yml b/.github/workflows/desktop-mac-test-pull.yml index a4b3fc8bc1..b625298a83 100644 --- a/.github/workflows/desktop-mac-test-pull.yml +++ b/.github/workflows/desktop-mac-test-pull.yml @@ -40,6 +40,8 @@ jobs: - name: Run tauri unit tests uses: nick-fields/retry@v2 + id: macRunUnit + continue-on-error: true with: timeout_minutes: 12 max_attempts: 3 @@ -47,6 +49,8 @@ jobs: - name: Run tauri integration tests uses: nick-fields/retry@v2 + id: macRunIntegration + continue-on-error: true with: timeout_minutes: 12 max_attempts: 3 @@ -54,6 +58,8 @@ jobs: - name: Run tauri mainview tests uses: nick-fields/retry@v2 + id: macRunMainview + continue-on-error: true with: timeout_minutes: 12 max_attempts: 3 @@ -61,6 +67,8 @@ jobs: - name: Run tauri livepreview tests uses: nick-fields/retry@v2 + id: macRunLivepreview + continue-on-error: true with: timeout_minutes: 12 max_attempts: 3 @@ -68,7 +76,15 @@ jobs: - name: Run tauri LegacyInteg tests uses: nick-fields/retry@v2 + id: macRunLegacyInteg + continue-on-error: true with: timeout_minutes: 30 max_attempts: 3 command: ../phoenix-desktop/src-tauri/target/debug/phoenix-test --run-tests=LegacyInteg -q + + - name: Fail on test runs failed in Mac + if: steps.macRunUnit.outcome == 'failure' || steps.macRunIntegration.outcome == 'failure' || steps.macRunMainview.outcome == 'failure' || steps.macRunLivepreview.outcome == 'failure' || steps.macRunLegacyInteg.outcome == 'failure' + run: | + echo "Mac tests failed, marking step as failed" + exit 1