don't return empty profile, instead throw
This commit is contained in:
parent
6bd1593e13
commit
cae54c39fb
32
orchestrator/src/server/services/profile.test.ts
Normal file
32
orchestrator/src/server/services/profile.test.ts
Normal file
@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -28,7 +28,7 @@ export async function getProfile(profilePath?: string, forceRefresh = false): Pr
|
|||||||
return cachedProfile;
|
return cachedProfile;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`❌ Failed to load profile from ${targetPath}:`, error);
|
console.error(`❌ Failed to load profile from ${targetPath}:`, error);
|
||||||
return {};
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user