mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 14:25:02 +00:00
195 lines
6.1 KiB
TypeScript
195 lines
6.1 KiB
TypeScript
#!/usr/bin/env tsx
|
|
/**
|
|
* Test for Auto Code Extractor 3000™
|
|
*
|
|
* Tests the basic functionality of the automated code extractor
|
|
*/
|
|
|
|
import { describe, it, expect, beforeAll, afterAll } from '@jest/globals'
|
|
import { AutoCodeExtractor3000, FileToExtract } from './auto-code-extractor-3000'
|
|
import * as fs from 'fs/promises'
|
|
import * as path from 'path'
|
|
|
|
describe('AutoCodeExtractor3000', () => {
|
|
describe('initialization', () => {
|
|
it('should initialize with default options', () => {
|
|
const extractor = new AutoCodeExtractor3000()
|
|
expect(extractor).toBeDefined()
|
|
})
|
|
|
|
it('should initialize with custom options', () => {
|
|
const extractor = new AutoCodeExtractor3000({
|
|
dryRun: true,
|
|
priority: 'high',
|
|
limit: 5,
|
|
batchSize: 2,
|
|
skipLint: true,
|
|
skipTest: true,
|
|
autoConfirm: true,
|
|
verbose: true,
|
|
})
|
|
expect(extractor).toBeDefined()
|
|
})
|
|
|
|
it('should handle partial options', () => {
|
|
const extractor = new AutoCodeExtractor3000({
|
|
dryRun: true,
|
|
limit: 3,
|
|
})
|
|
expect(extractor).toBeDefined()
|
|
})
|
|
})
|
|
|
|
describe('priority filtering', () => {
|
|
it.each([
|
|
{ priority: 'high', expectedCount: 3 },
|
|
{ priority: 'medium', expectedCount: 2 },
|
|
{ priority: 'low', expectedCount: 1 },
|
|
{ priority: 'all', expectedCount: 6 },
|
|
])('should filter by priority: $priority', ({ priority, expectedCount }) => {
|
|
const mockFiles: FileToExtract[] = [
|
|
{ path: 'a.ts', lines: 200, priority: 'high', category: 'library', status: 'pending' },
|
|
{ path: 'b.ts', lines: 180, priority: 'high', category: 'library', status: 'pending' },
|
|
{ path: 'c.ts', lines: 160, priority: 'high', category: 'library', status: 'pending' },
|
|
{ path: 'd.ts', lines: 250, priority: 'medium', category: 'component', status: 'pending' },
|
|
{ path: 'e.ts', lines: 220, priority: 'medium', category: 'component', status: 'pending' },
|
|
{ path: 'f.ts', lines: 300, priority: 'low', category: 'other', status: 'pending' },
|
|
]
|
|
|
|
const extractor = new AutoCodeExtractor3000({
|
|
priority: priority as 'high' | 'medium' | 'low' | 'all',
|
|
limit: 100
|
|
})
|
|
|
|
// We can't directly access the private filterFiles method,
|
|
// but we can verify the initialization works
|
|
expect(extractor).toBeDefined()
|
|
})
|
|
})
|
|
|
|
describe('limit handling', () => {
|
|
it.each([
|
|
{ limit: 1, expectedMax: 1 },
|
|
{ limit: 5, expectedMax: 5 },
|
|
{ limit: 10, expectedMax: 10 },
|
|
{ limit: 100, expectedMax: 6 }, // Only 6 files available
|
|
])('should respect limit: $limit', ({ limit, expectedMax }) => {
|
|
const extractor = new AutoCodeExtractor3000({ limit })
|
|
expect(extractor).toBeDefined()
|
|
})
|
|
})
|
|
|
|
describe('batch size handling', () => {
|
|
it.each([
|
|
{ batchSize: 1 },
|
|
{ batchSize: 5 },
|
|
{ batchSize: 10 },
|
|
])('should handle batch size: $batchSize', ({ batchSize }) => {
|
|
const extractor = new AutoCodeExtractor3000({ batchSize })
|
|
expect(extractor).toBeDefined()
|
|
})
|
|
})
|
|
|
|
describe('options validation', () => {
|
|
it('should handle dry-run mode', () => {
|
|
const extractor = new AutoCodeExtractor3000({ dryRun: true })
|
|
expect(extractor).toBeDefined()
|
|
})
|
|
|
|
it('should handle skip flags', () => {
|
|
const extractor = new AutoCodeExtractor3000({
|
|
skipLint: true,
|
|
skipTest: true
|
|
})
|
|
expect(extractor).toBeDefined()
|
|
})
|
|
|
|
it('should handle auto-confirm flag', () => {
|
|
const extractor = new AutoCodeExtractor3000({ autoConfirm: true })
|
|
expect(extractor).toBeDefined()
|
|
})
|
|
|
|
it('should handle verbose flag', () => {
|
|
const extractor = new AutoCodeExtractor3000({ verbose: true })
|
|
expect(extractor).toBeDefined()
|
|
})
|
|
})
|
|
|
|
describe('error handling', () => {
|
|
it('should handle invalid priority gracefully', () => {
|
|
// TypeScript will catch this at compile time, but test runtime behavior
|
|
const extractor = new AutoCodeExtractor3000({
|
|
priority: 'invalid' as any
|
|
})
|
|
expect(extractor).toBeDefined()
|
|
})
|
|
|
|
it('should handle negative limit', () => {
|
|
const extractor = new AutoCodeExtractor3000({ limit: -1 })
|
|
expect(extractor).toBeDefined()
|
|
})
|
|
|
|
it('should handle zero batch size', () => {
|
|
const extractor = new AutoCodeExtractor3000({ batchSize: 0 })
|
|
expect(extractor).toBeDefined()
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('FileToExtract type', () => {
|
|
it('should have required fields', () => {
|
|
const file: FileToExtract = {
|
|
path: 'test.ts',
|
|
lines: 200,
|
|
priority: 'high',
|
|
category: 'library',
|
|
status: 'pending',
|
|
}
|
|
expect(file.path).toBe('test.ts')
|
|
expect(file.lines).toBe(200)
|
|
expect(file.priority).toBe('high')
|
|
expect(file.category).toBe('library')
|
|
expect(file.status).toBe('pending')
|
|
})
|
|
|
|
it('should allow optional error field', () => {
|
|
const file: FileToExtract = {
|
|
path: 'test.ts',
|
|
lines: 200,
|
|
priority: 'high',
|
|
category: 'library',
|
|
status: 'failed',
|
|
error: 'Parse error',
|
|
}
|
|
expect(file.error).toBe('Parse error')
|
|
})
|
|
|
|
it('should handle different statuses', () => {
|
|
const statuses: FileToExtract['status'][] = ['pending', 'completed', 'failed', 'skipped']
|
|
statuses.forEach(status => {
|
|
const file: FileToExtract = {
|
|
path: 'test.ts',
|
|
lines: 200,
|
|
priority: 'high',
|
|
category: 'library',
|
|
status,
|
|
}
|
|
expect(file.status).toBe(status)
|
|
})
|
|
})
|
|
|
|
it('should handle different priorities', () => {
|
|
const priorities: FileToExtract['priority'][] = ['high', 'medium', 'low']
|
|
priorities.forEach(priority => {
|
|
const file: FileToExtract = {
|
|
path: 'test.ts',
|
|
lines: 200,
|
|
priority,
|
|
category: 'library',
|
|
status: 'pending',
|
|
}
|
|
expect(file.priority).toBe(priority)
|
|
})
|
|
})
|
|
})
|