From cae54c39fb291b7e85eec8ccc38bde16c6004a05 Mon Sep 17 00:00:00 2001 From: DaKheera47 Date: Wed, 21 Jan 2026 16:14:30 +0000 Subject: [PATCH] don't return empty profile, instead throw --- .../src/server/services/profile.test.ts | 32 +++++++++++++++++++ orchestrator/src/server/services/profile.ts | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 orchestrator/src/server/services/profile.test.ts diff --git a/orchestrator/src/server/services/profile.test.ts b/orchestrator/src/server/services/profile.test.ts new file mode 100644 index 0000000..7d17a42 --- /dev/null +++ b/orchestrator/src/server/services/profile.test.ts @@ -0,0 +1,32 @@ + +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { readFile } from 'fs/promises'; +import { getProfile } from './profile.js'; + +vi.mock('fs/promises', async () => { + const fn = vi.fn(); + return { + readFile: fn, + default: { + readFile: fn + } + }; +}); + +describe('getProfile failure', () => { + beforeEach(() => { + vi.resetAllMocks(); + }); + + it('should throw an error if the profile file does not exist', async () => { + vi.mocked(readFile).mockRejectedValue(new Error('ENOENT: no such file or directory')); + + await expect(getProfile('/non/existent/path.json', true)).rejects.toThrow('ENOENT: no such file or directory'); + }); + + it('should throw an error if the profile file is invalid JSON', async () => { + vi.mocked(readFile).mockResolvedValue('invalid json'); + + await expect(getProfile('/invalid/json.json', true)).rejects.toThrow(); + }); +}); diff --git a/orchestrator/src/server/services/profile.ts b/orchestrator/src/server/services/profile.ts index 041a87e..f41fa67 100644 --- a/orchestrator/src/server/services/profile.ts +++ b/orchestrator/src/server/services/profile.ts @@ -28,7 +28,7 @@ export async function getProfile(profilePath?: string, forceRefresh = false): Pr return cachedProfile; } catch (error) { console.error(`❌ Failed to load profile from ${targetPath}:`, error); - return {}; + throw error; } }