|
|
|
"""
|
|
GPT-ENGINEER統合テストスクリプト
|
|
プロンプト管理システムとGPT-ENGINEERの連携テスト
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import tempfile
|
|
import shutil
|
|
from pathlib import Path
|
|
from datetime import datetime
|
|
|
|
|
|
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 = 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
|
|
|
|
|
|
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}"
|
|
|
|
|
|
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)
|
|
|
|
|
|
print("\n1️⃣ テストプロンプト作成")
|
|
prompt_data = self.create_test_prompt()
|
|
print(f" タイトル: {prompt_data['title']}")
|
|
|
|
|
|
print("\n2️⃣ GPT-ENGINEER実行")
|
|
result = self.simulate_gpt_engineer_execution(prompt_data)
|
|
print(f" プロジェクトディレクトリ: {result['project_dir']}")
|
|
print(f" 生成ファイル数: {len(result['files_created'])}")
|
|
|
|
|
|
print("\n3️⃣ 生成システムテスト")
|
|
test_passed = self.test_generated_system(result)
|
|
|
|
|
|
print("\n4️⃣ GitHub連携")
|
|
github_result = self.simulate_github_upload(result)
|
|
|
|
|
|
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}")
|
|
|
|
|
|
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()
|
|
|