codebridge-ai
Version:
Complete fullstack AI coding platform with AST-based code integration and local LLM support. Now with comprehensive web technology support (HTML/CSS/JS) plus JavaScript, Python, Rust, and C++.
450 lines (382 loc) • 10.3 kB
Markdown
# LLM을 위한 CodeBridge 테스트 전략
## 현재 테스트 상황 분석
### 문제점
1. **테스트 부재**: 현재 자동화된 테스트가 전혀 없음
2. **검증 부족**: 코드 병합 결과의 정확성 검증 메커니즘 없음
3. **LLM 특화 테스트 없음**: 다양한 LLM 출력 형식에 대한 대응 부족
### LLM 사용 시나리오
- Claude, GPT-4, Gemini 등 다양한 LLM이 생성하는 코드 스니펫
- 주석 기반 명령어의 다양한 변형
- 부분 코드와 전체 코드의 혼재
## LLM 친화적 테스트 프레임워크 설계
### 1. 테스트 구조
```javascript
// test/llm-compatibility-test.js
class LLMCompatibilityTestSuite {
constructor() {
this.testCases = {
claude: [],
gpt4: [],
gemini: [],
generic: []
};
}
// LLM별 출력 패턴 테스트
testLLMOutputPatterns() {
return {
// Claude 스타일
claude: {
commentStyle: "// @command value",
codeBlockFormat: "```javascript\n{code}\n```",
explanationPattern: "주석으로 설명 포함"
},
// GPT-4 스타일
gpt4: {
commentStyle: "// @command: value",
codeBlockFormat: "```js\n{code}\n```",
explanationPattern: "인라인 주석 선호"
},
// Gemini 스타일
gemini: {
commentStyle: "/* @command value */",
codeBlockFormat: "```\n{code}\n```",
explanationPattern: "블록 주석 사용"
}
};
}
}
```
### 2. 핵심 테스트 케이스
```javascript
// test/core-functionality.test.js
describe('CodeBridge Core Functionality', () => {
describe('JavaScript 병합', () => {
test('메서드 추가', async () => {
const original = `
class Example {
method1() { return 1; }
}
`;
const snippet = `
// @add
method2() { return 2; }
`;
const result = processor.process(original, snippet, 'js');
expect(result).toContain('method1');
expect(result).toContain('method2');
});
test('메서드 수정 with 데코레이터', async () => {
const snippet = `
// @decorator log
// @access private
method1() { return 10; }
`;
const result = processor.process(original, snippet, 'js');
expect(result).toContain('@log');
expect(result).toContain('private method1');
});
});
});
```
### 3. LLM 출력 변형 테스트
```javascript
// test/llm-variations.test.js
describe('LLM 출력 변형 처리', () => {
const variations = [
// 주석 스타일 변형
{
name: 'Single line comment',
snippet: '// @decorator cache\nmethod() {}'
},
{
name: 'Block comment',
snippet: '/* @decorator cache */\nmethod() {}'
},
{
name: 'JSDoc style',
snippet: '/** @decorator cache */\nmethod() {}'
},
{
name: 'Multiple decorators',
snippet: '// @decorator cache\n// @decorator log\nmethod() {}'
},
// 코드 블록 변형
{
name: 'Partial method only',
snippet: 'method() { return modified; }'
},
{
name: 'With explanation comments',
snippet: `
// 이 메서드는 개선된 버전입니다
// @decorator memoize
method() {
// 캐싱 로직 추가
return improved;
}
`
}
];
variations.forEach(({ name, snippet }) => {
test(`should handle ${name}`, () => {
expect(() => processor.process(original, snippet, 'js'))
.not.toThrow();
});
});
});
```
### 4. 언어별 LLM 패턴 테스트
```javascript
// test/language-specific-llm.test.js
describe('언어별 LLM 패턴', () => {
describe('Python', () => {
test('데코레이터와 타입 힌트', () => {
const pythonSnippet = `
# @decorator lru_cache(maxsize=128)
# @type_hints List[str] -> Dict[str, Any]
def process_data(self, items: List[str]) -> Dict[str, Any]:
"""LLM이 생성한 개선된 메서드"""
return {item: self.transform(item) for item in items}
`;
// 테스트 구현
});
});
describe('Rust', () => {
test('속성과 제네릭', () => {
const rustSnippet = `
// @visibility pub
// @attributes #[derive(Debug, Clone)]
// @generic <T: Display + Send>
fn process<T: Display + Send>(&self, item: T) -> Result<String, Error> {
// LLM이 생성한 안전한 처리 로직
Ok(format!("{}", item))
}
`;
// 테스트 구현
});
});
});
```
### 5. 엣지 케이스 및 오류 처리
```javascript
// test/edge-cases.test.js
describe('엣지 케이스 처리', () => {
test('잘못된 문법의 스니펫', () => {
const malformedSnippet = `
// @decorator async
method() {
// 중괄호 누락
return value
`;
expect(() => processor.process(original, malformedSnippet, 'js'))
.toThrow(/Parsing error/);
});
test('충돌하는 명령어', () => {
const conflictingSnippet = `
// @delete
// @rename newName
method() {}
`;
// 우선순위에 따른 처리 확인
});
test('빈 스니펫', () => {
expect(processor.process(original, '', 'js'))
.toBe(original);
});
});
```
## 테스트 실행 및 검증
### 1. 테스트 환경 설정
```json
// package.json 업데이트
{
"scripts": {
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"test:llm": "jest test/llm-*.test.js",
"test:integration": "jest test/integration/*.test.js"
},
"devDependencies": {
"jest": "^29.7.0",
"@types/jest": "^29.5.0",
"babel-jest": "^29.7.0"
}
}
```
### 2. Jest 설정
```javascript
// jest.config.js
module.exports = {
testEnvironment: 'node',
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80
}
},
testMatch: [
'**/test/**/*.test.js',
'**/test/**/*.spec.js'
],
collectCoverageFrom: [
'code-bridge.js',
'enhanced-code-bridge.js',
'src/**/*.js'
]
};
```
### 3. LLM 통합 테스트
```javascript
// test/integration/llm-integration.test.js
describe('실제 LLM 출력 통합 테스트', () => {
// 실제 LLM 출력 샘플
const realLLMOutputs = {
claude: `
\`\`\`javascript
// 메서드를 개선했습니다. 다음과 같은 변경사항이 있습니다:
// 1. 에러 처리 추가
// 2. 타입 검증
// 3. 성능 최적화
// @decorator memoize
// @decorator validateInput
async processData(input) {
// 입력 검증
if (!input || typeof input !== 'object') {
throw new TypeError('Invalid input');
}
try {
const result = await this.transform(input);
return result;
} catch (error) {
console.error('Processing failed:', error);
throw error;
}
}
\`\`\`
`,
gpt4: `
Here's the improved method with better error handling:
\`\`\`js
// @access: private
// @decorator: async
// @decorator: logged
_processDataInternal(data) {
/* Validation logic */
if (!this.validate(data)) {
return null;
}
/* Processing logic */
return data.map(item => this.transform(item));
}
\`\`\`
`
};
Object.entries(realLLMOutputs).forEach(([llm, output]) => {
test(`should handle ${llm} output format`, () => {
// 코드 블록 추출
const codeMatch = output.match(/```(?:javascript|js)?\n([\s\S]*?)```/);
expect(codeMatch).toBeTruthy();
const extractedCode = codeMatch[1];
expect(() => processor.process(original, extractedCode, 'js'))
.not.toThrow();
});
});
});
```
### 4. 성능 및 신뢰성 테스트
```javascript
// test/performance.test.js
describe('성능 및 신뢰성', () => {
test('대용량 파일 처리', () => {
const largeFile = generateLargeFile(1000); // 1000개 메서드
const startTime = Date.now();
const result = processor.process(largeFile, snippet, 'js');
const duration = Date.now() - startTime;
expect(duration).toBeLessThan(1000); // 1초 이내
});
test('동시 다발적 병합', async () => {
const promises = Array(10).fill(null).map((_, i) =>
processor.process(original, `method${i}() {}`, 'js')
);
const results = await Promise.all(promises);
expect(results).toHaveLength(10);
expect(results.every(r => r !== null)).toBe(true);
});
});
```
## LLM별 가이드라인
### Claude
```markdown
CodeBridge 사용 시:
- 주석 명령어는 // @command value 형식 사용
- 코드 블록은 ```javascript로 명시
- 메서드 단위로 스니펫 제공 가능
```
### GPT-4
```markdown
CodeBridge integration:
- Use // @command: value format
- Wrap code in ```js blocks
- Include explanatory comments
```
### Gemini
```markdown
CodeBridge 호환:
- /* @command value */ 블록 주석 지원
- 다중 명령어는 별도 줄에 작성
- 부분 코드 자동 감지
```
## 테스트 커버리지 목표
```yaml
coverage_targets:
statements: 90%
branches: 85%
functions: 90%
lines: 90%
priority_areas:
- 코드 병합 로직
- 주석 명령어 파싱
- AST 변환
- 오류 처리
- LLM 출력 정규화
```
## CI/CD 통합
```yaml
# .github/workflows/test.yml
name: Test Suite
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm test
- run: npm run test:llm
- run: npm run test:coverage
- name: Upload coverage
uses: codecov/codecov-action@v3
```
## 권장사항
1. **즉시 구현 필요**
- 기본 단위 테스트
- 주요 기능 통합 테스트
- LLM 출력 정규화 테스트
2. **단계적 개선**
- 언어별 특화 테스트
- 성능 벤치마크
- 보안 취약점 테스트
3. **LLM 가이드라인**
- 각 LLM별 최적 사용법 문서화
- 예제 코드 제공
- 일반적인 오류 및 해결법