mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-02 20:43:36 +00:00
fix(server): Fix unit tests and increase coverage
- Skip platform-specific tests on Windows (CI runs on Linux) - Add tests for json-extractor.ts (96% coverage) - Add tests for cursor-config-manager.ts (100% coverage) - Add tests for cursor-config-service.ts (98.8% coverage) - Exclude CLI integration code from coverage (needs integration tests) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -563,27 +563,31 @@ describe('settings-service.ts', () => {
|
||||
expect(result.errors.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should handle migration errors gracefully', async () => {
|
||||
// Create a read-only directory to cause write errors
|
||||
const readOnlyDir = path.join(os.tmpdir(), `readonly-${Date.now()}`);
|
||||
await fs.mkdir(readOnlyDir, { recursive: true });
|
||||
await fs.chmod(readOnlyDir, 0o444);
|
||||
// Skip on Windows as chmod doesn't work the same way (CI runs on Linux)
|
||||
it.skipIf(process.platform === 'win32')(
|
||||
'should handle migration errors gracefully',
|
||||
async () => {
|
||||
// Create a read-only directory to cause write errors
|
||||
const readOnlyDir = path.join(os.tmpdir(), `readonly-${Date.now()}`);
|
||||
await fs.mkdir(readOnlyDir, { recursive: true });
|
||||
await fs.chmod(readOnlyDir, 0o444);
|
||||
|
||||
const readOnlyService = new SettingsService(readOnlyDir);
|
||||
const localStorageData = {
|
||||
'automaker-storage': JSON.stringify({
|
||||
state: { theme: 'light' },
|
||||
}),
|
||||
};
|
||||
const readOnlyService = new SettingsService(readOnlyDir);
|
||||
const localStorageData = {
|
||||
'automaker-storage': JSON.stringify({
|
||||
state: { theme: 'light' },
|
||||
}),
|
||||
};
|
||||
|
||||
const result = await readOnlyService.migrateFromLocalStorage(localStorageData);
|
||||
const result = await readOnlyService.migrateFromLocalStorage(localStorageData);
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.errors.length).toBeGreaterThan(0);
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.errors.length).toBeGreaterThan(0);
|
||||
|
||||
await fs.chmod(readOnlyDir, 0o755);
|
||||
await fs.rm(readOnlyDir, { recursive: true, force: true });
|
||||
});
|
||||
await fs.chmod(readOnlyDir, 0o755);
|
||||
await fs.rm(readOnlyDir, { recursive: true, force: true });
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('getDataDir', () => {
|
||||
@@ -594,18 +598,22 @@ describe('settings-service.ts', () => {
|
||||
});
|
||||
|
||||
describe('atomicWriteJson', () => {
|
||||
it('should handle write errors and clean up temp file', async () => {
|
||||
// Create a read-only directory to cause write errors
|
||||
const readOnlyDir = path.join(os.tmpdir(), `readonly-${Date.now()}`);
|
||||
await fs.mkdir(readOnlyDir, { recursive: true });
|
||||
await fs.chmod(readOnlyDir, 0o444);
|
||||
// Skip on Windows as chmod doesn't work the same way (CI runs on Linux)
|
||||
it.skipIf(process.platform === 'win32')(
|
||||
'should handle write errors and clean up temp file',
|
||||
async () => {
|
||||
// Create a read-only directory to cause write errors
|
||||
const readOnlyDir = path.join(os.tmpdir(), `readonly-${Date.now()}`);
|
||||
await fs.mkdir(readOnlyDir, { recursive: true });
|
||||
await fs.chmod(readOnlyDir, 0o444);
|
||||
|
||||
const readOnlyService = new SettingsService(readOnlyDir);
|
||||
const readOnlyService = new SettingsService(readOnlyDir);
|
||||
|
||||
await expect(readOnlyService.updateGlobalSettings({ theme: 'light' })).rejects.toThrow();
|
||||
await expect(readOnlyService.updateGlobalSettings({ theme: 'light' })).rejects.toThrow();
|
||||
|
||||
await fs.chmod(readOnlyDir, 0o755);
|
||||
await fs.rm(readOnlyDir, { recursive: true, force: true });
|
||||
});
|
||||
await fs.chmod(readOnlyDir, 0o755);
|
||||
await fs.rm(readOnlyDir, { recursive: true, force: true });
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user