[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -1,99 +1,312 @@
|
||||
---
|
||||
id: wiki-2026-0508-ai-생성-코드-검증-ai-code-assurance
|
||||
title: AI 생성 코드 검증(AI Code Assurance)
|
||||
title: AI Code Assurance (AI 생성 코드 검증)
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-254BE9]
|
||||
aliases: [AI Code Assurance, AI 생성 코드 검증, generated code review, vibe coding QA]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
tags: [auto-reinforced]
|
||||
source_trust_level: B
|
||||
confidence_score: 0.85
|
||||
verification_status: conceptual
|
||||
tags: [ai-code-quality, sast, code-review, generated-code, devsecops, copilot-review, hallucination-detection]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-20
|
||||
github_commit: "[P-Reinforce] Continuous Worker - AI 생성 코드 검증(AI Code Assurance)"
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
last_reinforced: 2026-05-09
|
||||
github_commit: pending
|
||||
inferred_by: Claude Opus 4.7 (manual cleanup 2026-05-09)
|
||||
---
|
||||
|
||||
# [[AI 생성 코드 검증(AI Code Assurance)|AI 생성 코드 검증(AI Code Assurance)]]
|
||||
# AI Code Assurance (AI 생성 코드 검증)
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> AI Code Assurance(AI 생성 코드 검증)는 AI가 생성하거나 지원한 코드로 인해 발생할 수 있는 고유한 품질 및 보안 위험을 해결하기 위해 설계된 워크플로우이자 검증 프로세스입니다 [1]. 이를 통해 조직은 AI가 작성한 코드가 프로덕션 환경에 배포되기 전에 엄격한 보안, 신뢰성 및 품질 표준을 충족하는지 확인할 수 있습니다 [1, 2]. 주로 정적 애플리케이션 보안 테스트([[SAST|SAST]])와 자동화된 코드 리뷰를 활용하여 결함과 취약점을 조기에 식별하고 일관된 표준을 강제합니다 [2, 3].
|
||||
## 📌 한 줄 통찰
|
||||
> **AI-generated code 의 inconsistent quality + hallucinated API + 매 unique vulnerability**. 매 PR 의 SAST + LLM-as-judge + human review 의 hybrid. **Vibe coding 의 trust ≠ verify**.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
- **목적 및 필요성**
|
||||
AI 어시스턴트가 생성한 코드는 스타일과 품질 측면에서 매우 일관성이 없고 변동성이 클 수 있습니다 [4, 5]. AI Code Assurance의 목적은 전체 소프트웨어 개발 수명 주기(SDLC)에서 AI 생성 코드의 비율이 증가하더라도 인간이 작성한 코드와 동일한 품질 게이트(Quality Gate) 표준을 적용하여, 유지보수성과 보안에 대한 일관된 규칙을 강제하는 것입니다 [1, 5].
|
||||
## 📖 핵심
|
||||
|
||||
- **주요 기능 및 작동 방식**
|
||||
- **AI 코드 감지 및 추적:** 시스템은 프로젝트 내에 AI 생성 코드가 존재함을 자동으로 감지하거나 개발자가 직접 태그를 지정할 수 있게 합니다 [3]. 이를 통해 명확한 라벨링과 배지를 부여하여 AI 코드의 관리, 유지보수 및 규정 준수 모니터링을 간소화합니다 [3].
|
||||
- **정적 코드 분석(SAST) 적용:** 결정론적(deterministic)이고 독립적인 코드 검증 방식인 정적 코드 분석과 오염 분석(Taint [[Analysis|Analysis]])을 사용하여 코드를 스캔합니다 [4, 6]. 이를 통해 보안 취약점, 유출된 비밀 정보, 코드 냄새(Code smells), 논리적 결함 및 성능 위험을 풀 리퀘스트(Pull Request) 단계에서 조기에 표면화합니다 [4, 6, 7].
|
||||
- **워크플로우 및 에이전트 통합:** IDE부터 CI/CD 파이프라인에 이르기까지 기존 개발 워크플로우에 원활하게 통합됩니다 [6, 8]. 특히, MCP(Model Context Protocol)를 통해 Cursor, Claude Code, Windsurf와 같은 AI 코딩 에이전트와 직접 연결되어, 코드가 생성되는 실시간 대화 흐름 속에서 보안 핫스팟 분석 및 피드백을 제공합니다 [4, 8, 9].
|
||||
### 매 AI generated code 의 risk
|
||||
|
||||
- **기대 효과**
|
||||
위험도가 가장 높은 문제를 자동으로 강조 표시하여 코드 리뷰어의 피로도를 크게 줄여주며, 배포 주기를 단축합니다 [4]. 또한 조직은 PCI, OWASP, CWE와 같은 널리 통용되는 규정 준수 및 보안 표준을 충족하면서 신뢰성 있게 AI 기여(contribution)를 수용할 수 있습니다 [10, 11].
|
||||
#### 1. Inconsistent style
|
||||
- 매 prompt 의 different output.
|
||||
- 매 codebase convention 의 ignore.
|
||||
- 매 mix of pattern.
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌:** 자동화 엔진에 의해 매핑된 지식으로, 추후 정밀 검증 필요.
|
||||
- **정책 변화:** AI 분야의 자동 자산화 수행.
|
||||
#### 2. Hallucinated API
|
||||
- 매 non-existent function.
|
||||
- 매 deprecated API.
|
||||
- 매 wrong package version.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics:** Static Application Security Testing (SAST), [[Model Context Protocol (MCP)|Model Context Protocol (MCP)]], Automated [[Code Review|Code Review]]
|
||||
- **Projects/Contexts:** [[SonarQube|SonarQube]] Server, SonarQube Cloud
|
||||
- **Contradictions/Notes:** 소스에 따르면 AI 어시스턴트가 생성하는 코드는 본질적으로 일관성이 없고 예측하기 어려울 수 있지만, 이에 적용되는 정적 코드 분석 기술은 '결정론적(deterministic)'이므로 AI 코드의 불확실성을 극복하고 신뢰할 수 있는 독립적인 검증을 제공할 수 있다고 강조합니다 [4].
|
||||
#### 3. Security vulnerability
|
||||
- 매 CWE / OWASP pattern.
|
||||
- 매 outdated security practice.
|
||||
- 매 prompt injection 의 reproduce.
|
||||
|
||||
---
|
||||
*Last updated: 2026-04-19*
|
||||
#### 4. Subtle bug
|
||||
- 매 off-by-one.
|
||||
- 매 race condition.
|
||||
- 매 null check 의 miss.
|
||||
|
||||
---
|
||||
#### 5. Over-engineered
|
||||
- 매 unnecessary abstraction.
|
||||
- 매 boilerplate.
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
#### 6. Under-tested
|
||||
- 매 happy path 만.
|
||||
- 매 edge case 의 miss.
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
### 매 verification layer
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
#### Layer 1: Compile / type check
|
||||
- 매 TypeScript / Rust / Go 의 strict.
|
||||
- 매 hallucination 의 catch.
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
#### Layer 2: Lint
|
||||
- 매 style 의 enforce.
|
||||
- 매 ESLint / clippy / Pylint.
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
#### Layer 3: SAST
|
||||
- 매 security pattern.
|
||||
- Snyk / Semgrep / Sonar.
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
#### Layer 4: Test
|
||||
- 매 unit / integration.
|
||||
- 매 generated code 의 coverage.
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
#### Layer 5: AI review (CodeRabbit)
|
||||
- 매 PR 의 first-pass.
|
||||
- 매 hallucination 의 detect.
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
#### Layer 6: Human review
|
||||
- 매 logic / architecture.
|
||||
- 매 critical path.
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
#### Layer 7: Production monitoring
|
||||
- 매 error rate.
|
||||
- 매 anomaly.
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
→ 매 layer 의 different defect class.
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
### Quality gate
|
||||
|
||||
```text
|
||||
# TODO
|
||||
#### Pre-commit
|
||||
- Type check + lint + format.
|
||||
- 매 dev 의 local.
|
||||
|
||||
#### CI / PR
|
||||
- Test pass.
|
||||
- SAST clean.
|
||||
- AI review approved.
|
||||
- Coverage threshold.
|
||||
|
||||
#### Pre-deploy
|
||||
- Integration test.
|
||||
- Performance regression.
|
||||
- Security scan.
|
||||
|
||||
#### Post-deploy
|
||||
- 매 alert / SLO.
|
||||
- Rollback plan.
|
||||
|
||||
### 매 specific check
|
||||
|
||||
#### Hallucination detection
|
||||
- 매 import 의 actual existence.
|
||||
- 매 function signature 의 real.
|
||||
- 매 documentation 의 cross-reference.
|
||||
|
||||
```python
|
||||
import ast
|
||||
import importlib
|
||||
|
||||
def check_imports(code: str):
|
||||
tree = ast.parse(code)
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.Import):
|
||||
for alias in node.names:
|
||||
try:
|
||||
importlib.import_module(alias.name)
|
||||
except ImportError:
|
||||
print(f"Hallucinated import: {alias.name}")
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
#### Security pattern
|
||||
- SQL injection (string concat).
|
||||
- XSS (HTML construction).
|
||||
- Hardcoded secret.
|
||||
- Unsafe deserialize.
|
||||
- Prompt injection (LLM call concatenation).
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
#### Test coverage
|
||||
- Required coverage threshold (80%+ for new code).
|
||||
- 매 generated code 의 test 도 generated → 매 review.
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### 매 organizational pattern
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
#### "AI-generated 의 명시"
|
||||
- PR description 의 disclose.
|
||||
- Commit message 의 tag.
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
#### Stricter review
|
||||
- 매 AI-generated PR 의 매 senior review.
|
||||
- 매 logic 의 deep verify.
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
#### Snippet 의 attribution
|
||||
- Copilot 의 license / source.
|
||||
- 매 code 의 origin track.
|
||||
|
||||
#### Prompts as code
|
||||
- 매 prompt 의 git commit.
|
||||
- 매 reproducibility.
|
||||
|
||||
### 매 metric (DORA-like)
|
||||
- AI-generated 의 PR 의 % .
|
||||
- AI-suggestion 의 accept rate.
|
||||
- AI 의 bug 의 production escape.
|
||||
- 매 reviewer 의 time-to-review.
|
||||
|
||||
## 💻 Code
|
||||
|
||||
### CI workflow (GitHub Actions)
|
||||
```yaml
|
||||
# .github/workflows/ai-code-check.yml
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize]
|
||||
|
||||
jobs:
|
||||
verify:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# Layer 1: type
|
||||
- run: npm run typecheck
|
||||
|
||||
# Layer 2: lint
|
||||
- run: npm run lint
|
||||
|
||||
# Layer 3: security
|
||||
- uses: snyk/actions/setup@master
|
||||
- run: snyk code test
|
||||
|
||||
# Layer 4: test
|
||||
- run: npm test -- --coverage
|
||||
- uses: codecov/codecov-action@v3
|
||||
|
||||
# Layer 5: AI review (CodeRabbit auto-runs)
|
||||
|
||||
# Quality gate
|
||||
- run: |
|
||||
if [[ $(jq -r '.coverage' coverage.json) -lt 80 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
```
|
||||
|
||||
### Hallucination check (TS / npm)
|
||||
```ts
|
||||
import { execSync } from 'child_process';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
function checkImports(filePath: string) {
|
||||
const program = ts.createProgram([filePath], {});
|
||||
const sourceFile = program.getSourceFile(filePath);
|
||||
const issues: string[] = [];
|
||||
|
||||
ts.forEachChild(sourceFile!, (node) => {
|
||||
if (ts.isImportDeclaration(node)) {
|
||||
const moduleName = (node.moduleSpecifier as ts.StringLiteral).text;
|
||||
try {
|
||||
require.resolve(moduleName, { paths: [process.cwd()] });
|
||||
} catch {
|
||||
issues.push(`Hallucinated: ${moduleName}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return issues;
|
||||
}
|
||||
```
|
||||
|
||||
### LLM-as-judge (verify generated code)
|
||||
```python
|
||||
def verify_generated(code: str, intent: str) -> dict:
|
||||
prompt = f"""
|
||||
You are a code reviewer. Verify the AI-generated code.
|
||||
|
||||
Intent: {intent}
|
||||
|
||||
Code:
|
||||
```
|
||||
{code}
|
||||
```
|
||||
|
||||
Check:
|
||||
1. Does it match intent?
|
||||
2. Any hallucinated API/import?
|
||||
3. Security issues?
|
||||
4. Edge cases missing?
|
||||
5. Style consistent?
|
||||
|
||||
Output JSON: {{"matches_intent": bool, "issues": [{{...}}]}}
|
||||
"""
|
||||
return json.loads(judge_llm.complete(prompt))
|
||||
```
|
||||
|
||||
### Disclosure 의 PR template
|
||||
```markdown
|
||||
## AI-Generated Code Disclosure
|
||||
|
||||
This PR includes AI-generated code from:
|
||||
- [ ] Cursor
|
||||
- [ ] Claude Code
|
||||
- [ ] Copilot
|
||||
- [ ] Other: ___
|
||||
|
||||
Tools used:
|
||||
- Prompts available at: [link]
|
||||
|
||||
I have reviewed:
|
||||
- [ ] Each generated section.
|
||||
- [ ] Tests pass + coverage.
|
||||
- [ ] No hallucinated APIs.
|
||||
- [ ] Security implications.
|
||||
```
|
||||
|
||||
## 🤔 결정 기준
|
||||
|
||||
| AI-generated portion | Review level |
|
||||
|---|---|
|
||||
| < 20% | Standard |
|
||||
| 20-50% | Enhanced (senior review) |
|
||||
| > 50% | Strict (multiple reviewer) |
|
||||
| Critical path | Always strict |
|
||||
| Generated test | Verify edge cases |
|
||||
|
||||
**기본값**: Type + lint + SAST + test + AI review + human review. 매 AI-heavy PR 의 enhanced.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[AI-Code-Review]] · [[DevSecOps]] · [[Code-Quality]]
|
||||
- 변형: [[Hallucination-Detection]] · [[SAST]] · [[LLM-as-Judge]]
|
||||
- 응용: [[CodeRabbit]] · [[Snyk-Code]] · [[Sonar]]
|
||||
- Adjacent: [[Vibe-Coding]] · [[AI-Code-Agent-Patterns]] · [[Cursor-Workflow-Patterns]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 team 의 AI tool 의 adoption + quality.
|
||||
**언제 X**: 매 individual hobby project. 매 throwaway script.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **AI-generated + skip review**: production bug.
|
||||
- **No disclosure**: hidden risk.
|
||||
- **AI 의 own test 의 trust**: 매 same blind spot.
|
||||
- **Hallucinated API 의 ship**: runtime error.
|
||||
- **AI 의 single-layer 의 verify**: 매 defect class miss.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (concept).
|
||||
- 신뢰도 B.
|
||||
- Related: [[AI-Code-Review]], [[AI-Powered-Code-Analysis-Tools]].
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-09 | Manual cleanup — 7 layer + code + 결정 + disclosure |
|
||||
|
||||
Reference in New Issue
Block a user