File size: 9,469 Bytes
633f9ef |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
#!/usr/bin/env python3
"""
GPT-ENGINEER統合テストスクリプト
プロンプト管理システムとGPT-ENGINEERの連携テスト
"""
import os
import sys
import subprocess
import tempfile
import shutil
from pathlib import Path
from datetime import datetime
# GPT-ENGINEERのパスを追加
sys.path.append('/workspaces/fastapi_django_main_live/gpt-engineer')
class GPTEngineerIntegrationTest:
"""GPT-ENGINEER統合テストクラス"""
def __init__(self):
self.base_dir = Path('/workspaces/fastapi_django_main_live')
self.gpt_engineer_dir = self.base_dir / 'gpt-engineer'
self.test_output_dir = self.base_dir / 'test_generated_systems'
# テスト出力ディレクトリ作成
self.test_output_dir.mkdir(exist_ok=True)
def create_test_prompt(self):
"""テスト用のシンプルなプロンプトを作成"""
return {
"title": "Simple FastAPI Hello World",
"content": """
Create a simple FastAPI application with the following features:
1. A main.py file with FastAPI app
2. A single endpoint that returns "Hello, World!"
3. A GET endpoint /health that returns {"status": "ok"}
4. Include requirements.txt with fastapi and uvicorn
5. Add a simple README.md with usage instructions
The application should be simple and ready to run with:
- pip install -r requirements.txt
- uvicorn main:app --reload
Keep it minimal and functional.
""".strip()
}
def simulate_gpt_engineer_execution(self, prompt_data):
"""GPT-ENGINEER実行のシミュレーション"""
print(f"🤖 GPT-ENGINEER実行シミュレーション開始")
print(f"📝 プロンプト: {prompt_data['title']}")
# 出力ディレクトリ作成
project_name = "test_fastapi_hello"
project_dir = self.test_output_dir / project_name
if project_dir.exists():
shutil.rmtree(project_dir)
project_dir.mkdir(parents=True)
# シミュレートしたファイル生成
files_to_create = {
"main.py": '''
from fastapi import FastAPI
app = FastAPI(title="Hello World API", version="1.0.0")
@app.get("/")
async def hello_world():
return {"message": "Hello, World!"}
@app.get("/health")
async def health_check():
return {"status": "ok"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
'''.strip(),
"requirements.txt": '''
fastapi==0.104.1
uvicorn[standard]==0.24.0
'''.strip(),
"README.md": '''
# Simple FastAPI Hello World
A minimal FastAPI application demonstrating basic API endpoints.
## Features
- Hello World endpoint (`/`)
- Health check endpoint (`/health`)
- Automatic API documentation
## Installation
```bash
pip install -r requirements.txt
```
## Usage
```bash
uvicorn main:app --reload
```
Then visit:
- API: http://localhost:8000
- Docs: http://localhost:8000/docs
- Health: http://localhost:8000/health
## Generated by GPT-ENGINEER
This application was automatically generated using GPT-ENGINEER integration system.
'''.strip(),
"Dockerfile": '''
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
'''.strip(),
".gitignore": '''
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
venv/
.venv
.env
'''.strip()
}
# ファイル作成
for filename, content in files_to_create.items():
file_path = project_dir / filename
file_path.write_text(content)
print(f"✅ Created: {filename}")
return {
"project_dir": str(project_dir),
"files_created": list(files_to_create.keys()),
"status": "success"
}
def test_generated_system(self, result):
"""生成されたシステムのテスト"""
print(f"\n🧪 生成システムテスト開始")
project_dir = Path(result["project_dir"])
# ファイル存在確認
required_files = ["main.py", "requirements.txt", "README.md"]
for filename in required_files:
file_path = project_dir / filename
if file_path.exists():
print(f"✅ {filename} - 存在確認")
else:
print(f"❌ {filename} - ファイルなし")
return False
# main.pyの構文チェック
main_py = project_dir / "main.py"
try:
with open(main_py, 'r') as f:
code = f.read()
compile(code, main_py, 'exec')
print(f"✅ main.py - 構文チェック通過")
except SyntaxError as e:
print(f"❌ main.py - 構文エラー: {e}")
return False
# requirements.txtの内容確認
req_file = project_dir / "requirements.txt"
with open(req_file, 'r') as f:
requirements = f.read()
if "fastapi" in requirements and "uvicorn" in requirements:
print(f"✅ requirements.txt - 必要パッケージ確認")
else:
print(f"❌ requirements.txt - 必要パッケージ不足")
return False
print(f"✅ 全テスト通過")
return True
def simulate_github_upload(self, result):
"""GitHub アップロードのシミュレーション"""
print(f"\n🔗 GitHub連携シミュレーション")
project_dir = Path(result["project_dir"])
repo_name = f"generated-{project_dir.name}-{datetime.now().strftime('%Y%m%d-%H%M%S')}"
repo_url = f"https://github.com/your-username/{repo_name}"
# Git初期化のシミュレーション
commands = [
"git init",
"git add .",
'git commit -m "Initial commit - Generated by GPT-ENGINEER"',
f"git remote add origin {repo_url}",
"git push -u origin main"
]
print(f"📁 プロジェクト: {project_dir.name}")
print(f"🔗 リポジトリURL: {repo_url}")
print(f"📋 実行予定コマンド:")
for cmd in commands:
print(f" $ {cmd}")
return {
"repo_url": repo_url,
"repo_name": repo_name,
"commands": commands,
"status": "simulated"
}
def run_full_integration_test(self):
"""完全統合テストの実行"""
print("🚀 GPT-ENGINEER統合テスト開始")
print("=" * 60)
# 1. テストプロンプト作成
print("\n1️⃣ テストプロンプト作成")
prompt_data = self.create_test_prompt()
print(f" タイトル: {prompt_data['title']}")
# 2. GPT-ENGINEER実行
print("\n2️⃣ GPT-ENGINEER実行")
result = self.simulate_gpt_engineer_execution(prompt_data)
print(f" プロジェクトディレクトリ: {result['project_dir']}")
print(f" 生成ファイル数: {len(result['files_created'])}")
# 3. システムテスト
print("\n3️⃣ 生成システムテスト")
test_passed = self.test_generated_system(result)
# 4. GitHub連携
print("\n4️⃣ GitHub連携")
github_result = self.simulate_github_upload(result)
# 5. 結果サマリー
print("\n" + "=" * 60)
print("📊 統合テスト結果")
print("=" * 60)
status_items = [
("プロンプト処理", "✅ 成功"),
("システム生成", "✅ 成功" if result['status'] == 'success' else "❌ 失敗"),
("品質テスト", "✅ 通過" if test_passed else "❌ 失敗"),
("GitHub連携", "✅ 準備完了"),
("総合評価", "✅ 成功" if all([result['status'] == 'success', test_passed]) else "❌ 要改善")
]
for item, status in status_items:
print(f"{status} {item}")
# 6. 次のステップ
print(f"\n📈 次のステップ:")
print(f"1. 実際のGPT-ENGINEER API呼び出し実装")
print(f"2. GitHub API認証とリポジトリ作成")
print(f"3. エラーハンドリングの強化")
print(f"4. 品質チェックの自動化")
print(f"5. 通知システムの実装")
return {
"overall_status": "success" if all([result['status'] == 'success', test_passed]) else "failed",
"prompt_data": prompt_data,
"generation_result": result,
"test_result": test_passed,
"github_result": github_result
}
def main():
"""メイン実行"""
tester = GPTEngineerIntegrationTest()
result = tester.run_full_integration_test()
if result["overall_status"] == "success":
print(f"\n🎉 統合テスト完了!システムは正常に動作しています。")
else:
print(f"\n⚠️ 統合テストで問題が発見されました。詳細を確認してください。")
if __name__ == "__main__":
main()
|