summaryrefslogtreecommitdiff
path: root/packages/core/src/utils
diff options
context:
space:
mode:
authorBryan Morgan <[email protected]>2025-07-03 16:54:35 -0400
committerGitHub <[email protected]>2025-07-03 20:54:35 +0000
commit654f8aeb614c3e5129f33d93aa9cfa06d347e3a0 (patch)
tree74cb69c5b282d245e275ea1fd8e8c8434bf2a4c1 /packages/core/src/utils
parentab63a5f183ca6f787971219190db326043f6a502 (diff)
Fixed Google User Id pass to Clearcut (#3147)
Diffstat (limited to 'packages/core/src/utils')
-rw-r--r--packages/core/src/utils/user_id.test.ts27
-rw-r--r--packages/core/src/utils/user_id.ts12
2 files changed, 23 insertions, 16 deletions
diff --git a/packages/core/src/utils/user_id.test.ts b/packages/core/src/utils/user_id.test.ts
index 5d9c72e4..185d6c95 100644
--- a/packages/core/src/utils/user_id.test.ts
+++ b/packages/core/src/utils/user_id.test.ts
@@ -5,7 +5,7 @@
*/
import { describe, it, expect } from 'vitest';
-import { getInstallationId, getObfuscatedGoogleAccountId } from './user_id.js';
+import { getInstallationId, getGoogleAccountId } from './user_id.js';
describe('user_id', () => {
describe('getInstallationId', () => {
@@ -22,25 +22,30 @@ describe('user_id', () => {
});
});
- describe('getObfuscatedGoogleAccountId', () => {
- it('should return a non-empty string', () => {
- const result = getObfuscatedGoogleAccountId();
+ describe('getGoogleAccountId', () => {
+ it('should return a non-empty string', async () => {
+ const result = await getGoogleAccountId();
expect(result).toBeDefined();
expect(typeof result).toBe('string');
// Should be consistent on subsequent calls
- const secondCall = getObfuscatedGoogleAccountId();
+ const secondCall = await getGoogleAccountId();
expect(secondCall).toBe(result);
});
- it('should return empty string when no Google Account ID is cached', () => {
- // In a clean test environment, there should be no cached Google Account ID
- // so getObfuscatedGoogleAccountId should fall back to installation ID
- const googleAccountIdResult = getObfuscatedGoogleAccountId();
+ it('should return empty string when no Google Account ID is cached, or a valid ID when cached', async () => {
+ // The function can return either an empty string (if no cached ID) or a valid Google Account ID (if cached)
+ const googleAccountIdResult = await getGoogleAccountId();
- // They should be the same when no Google Account ID is cached
- expect(googleAccountIdResult).toBe('');
+ expect(googleAccountIdResult).toBeDefined();
+ expect(typeof googleAccountIdResult).toBe('string');
+
+ // Should be either empty string or a numeric string (Google Account ID)
+ if (googleAccountIdResult !== '') {
+ // If we have a cached ID, it should be a numeric string
+ expect(googleAccountIdResult).toMatch(/^\d+$/);
+ }
});
});
});
diff --git a/packages/core/src/utils/user_id.ts b/packages/core/src/utils/user_id.ts
index 5238fc3c..42bbee35 100644
--- a/packages/core/src/utils/user_id.ts
+++ b/packages/core/src/utils/user_id.ts
@@ -62,18 +62,20 @@ export function getInstallationId(): string {
* When OAuth is available, returns the user's cached Google Account ID. Otherwise, returns the installation ID.
* @returns A string ID for the user (Google Account ID if available, otherwise installation ID).
*/
-export function getObfuscatedGoogleAccountId(): string {
+export async function getGoogleAccountId(): Promise<string> {
// Try to get cached Google Account ID first
try {
- // Dynamically import to avoid circular dependencies
- // eslint-disable-next-line @typescript-eslint/no-require-imports, no-restricted-syntax
- const { getCachedGoogleAccountId } = require('../code_assist/oauth2.js');
+ // Dynamic import to avoid circular dependencies
+ const { getCachedGoogleAccountId } = await import(
+ '../code_assist/oauth2.js'
+ );
const googleAccountId = getCachedGoogleAccountId();
if (googleAccountId) {
return googleAccountId;
}
- } catch (_error) {
+ } catch (error) {
// If there's any error accessing Google Account ID, just return empty string
+ console.debug('Could not get cached Google Account ID:', error);
}
return '';