From 08d3720f92aeb60a8455788ac2b421b2bc855ba7 Mon Sep 17 00:00:00 2001 From: Ralph Khreish <35776126+Crunchyman-ralph@users.noreply.github.com> Date: Mon, 13 Oct 2025 21:38:41 +0200 Subject: [PATCH] chore: fix integration test --- packages/tm-core/src/auth/auth-manager.ts | 5 +++- .../integration/auth-token-refresh.test.ts | 26 +++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/tm-core/src/auth/auth-manager.ts b/packages/tm-core/src/auth/auth-manager.ts index 7af80230..2acd301b 100644 --- a/packages/tm-core/src/auth/auth-manager.ts +++ b/packages/tm-core/src/auth/auth-manager.ts @@ -38,7 +38,10 @@ export class AuthManager { this.oauthService = new OAuthService(this.credentialStore, config); // Initialize Supabase client with session restoration - this.initializeSupabaseSession(); + // Fire-and-forget with catch handler to prevent unhandled rejections + this.initializeSupabaseSession().catch(() => { + // Errors are already logged in initializeSupabaseSession + }); } /** diff --git a/packages/tm-core/tests/integration/auth-token-refresh.test.ts b/packages/tm-core/tests/integration/auth-token-refresh.test.ts index aedd5db0..b6103de5 100644 --- a/packages/tm-core/tests/integration/auth-token-refresh.test.ts +++ b/packages/tm-core/tests/integration/auth-token-refresh.test.ts @@ -6,6 +6,9 @@ */ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import fs from 'fs'; +import os from 'os'; +import path from 'path'; import type { Session } from '@supabase/supabase-js'; import { AuthManager } from '../../src/auth/auth-manager'; import { CredentialStore } from '../../src/auth/credential-store'; @@ -14,6 +17,8 @@ import type { AuthCredentials } from '../../src/auth/types'; describe('AuthManager - Token Auto-Refresh Integration', () => { let authManager: AuthManager; let credentialStore: CredentialStore; + let tmpDir: string; + let authFile: string; // Mock Supabase session that will be returned on refresh const mockRefreshedSession: Session = { @@ -34,10 +39,21 @@ describe('AuthManager - Token Auto-Refresh Integration', () => { }; beforeEach(() => { - // Reset AuthManager singleton + // Reset singletons AuthManager.resetInstance(); + CredentialStore.resetInstance(); - // Clear any existing credentials + // Create temporary directory for test isolation + tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'tm-auth-integration-')); + authFile = path.join(tmpDir, 'auth.json'); + + // Initialize AuthManager with test config (this will create CredentialStore internally) + authManager = AuthManager.getInstance({ + configDir: tmpDir, + configFile: authFile + }); + + // Get the CredentialStore instance that AuthManager created credentialStore = CredentialStore.getInstance(); credentialStore.clearCredentials(); }); @@ -50,7 +66,13 @@ describe('AuthManager - Token Auto-Refresh Integration', () => { // Ignore cleanup errors } AuthManager.resetInstance(); + CredentialStore.resetInstance(); vi.restoreAllMocks(); + + // Remove temporary directory + if (tmpDir && fs.existsSync(tmpDir)) { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } }); describe('Expired Token Detection', () => {