mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 20:17:45 +00:00
- Split types.ts (331 LOC) into 4 concern-based files under types/: platform-types, binary-types, provider-types, config-types - Preserve backward compat via barrel re-export (types.ts → types/index) - Reorganize 53 root-level files into 8 subdirectories: accounts/, ai-providers/, auth/, binary/, config/, executor/, management/, proxy/, quota/, routing/, services/, sync/ - Reduce src/cliproxy/ root from 65 to 8 files (target: ≤10) - Colocate 87 unit tests from tests/unit/cliproxy/ into src/cliproxy/*/__tests__/ (13 colocated test directories) - Update import paths across 40+ consumer files - Add TDD backward-compat test for types split Refs #1135
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, spyOn } from 'bun:test';
|
|
import * as fs from 'fs';
|
|
import * as os from 'os';
|
|
import * as path from 'path';
|
|
import { handleCleanupCommand } from '../../../src/commands/cleanup-command';
|
|
import { getCliproxyDir } from '../../../src/cliproxy/config/config-generator';
|
|
import { getLogArchiveDir, getNativeLogsDir } from '../../../src/services/logging';
|
|
|
|
describe('cleanup command', () => {
|
|
let tempHome = '';
|
|
let originalCcsHome: string | undefined;
|
|
|
|
beforeEach(() => {
|
|
originalCcsHome = process.env.CCS_HOME;
|
|
tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'ccs-cleanup-command-'));
|
|
process.env.CCS_HOME = tempHome;
|
|
});
|
|
|
|
afterEach(() => {
|
|
if (originalCcsHome !== undefined) {
|
|
process.env.CCS_HOME = originalCcsHome;
|
|
} else {
|
|
delete process.env.CCS_HOME;
|
|
}
|
|
|
|
fs.rmSync(tempHome, { recursive: true, force: true });
|
|
tempHome = '';
|
|
});
|
|
|
|
it('reports CCS archives alongside current logs in dry-run mode', async () => {
|
|
const ccsLogsDir = getNativeLogsDir();
|
|
const archiveDir = getLogArchiveDir();
|
|
const cliproxyLogsDir = path.join(getCliproxyDir(), 'logs');
|
|
|
|
fs.mkdirSync(archiveDir, { recursive: true });
|
|
fs.mkdirSync(cliproxyLogsDir, { recursive: true });
|
|
fs.writeFileSync(path.join(ccsLogsDir, 'current.jsonl'), 'x'.repeat(100));
|
|
fs.writeFileSync(path.join(archiveDir, 'archived.jsonl.gz'), 'y'.repeat(2_000));
|
|
|
|
const logSpy = spyOn(console, 'log').mockImplementation(() => {});
|
|
|
|
try {
|
|
await handleCleanupCommand(['--dry-run']);
|
|
|
|
const output = logSpy.mock.calls
|
|
.flatMap((call) => call.map((value) => String(value)))
|
|
.join('\n');
|
|
|
|
expect(output).toContain('CCS Logs: 1 files (100.00 B)');
|
|
expect(output).toContain('CCS Log Archives: 1 files (1.95 KB)');
|
|
expect(output).toContain('Would delete 2 files (2.05 KB)');
|
|
} finally {
|
|
logSpy.mockRestore();
|
|
}
|
|
});
|
|
});
|