-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/(CI)GitHub ActionsによるCIワークフローの追加 #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9e74c37
feat(tests): backendにテストコードを作成
forwardOne 1db5ecb
feat: ローディングインジケーターにスピナーを追加
forwardOne dfe76f7
feat(test): frontendにテストコードを作成
forwardOne 1d2725a
feat(CI): GitHub ActionsのCIワークフローを追加
forwardOne ec64e23
feat(dev): .env.exampleテンプレートファイルを追加し、CI設定を修正
forwardOne 35a4460
feat(docs): READMEの環境変数設定をGEMINI_API_KEYに修正
forwardOne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main ] | ||
| pull_request: | ||
| branches: [ main ] | ||
|
|
||
| jobs: | ||
| backend-test: | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| working-directory: ./backend | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.10' | ||
| - name: Install dependencies | ||
| run: pip install -r requirements.txt | ||
| - name: Run tests | ||
| env: | ||
| GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} | ||
| run: pytest | ||
|
|
||
| frontend-test: | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| working-directory: ./frontend | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| - name: Install dependencies | ||
| run: npm install | ||
| - name: Run tests | ||
| run: npm test | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| # Python | ||
| backend/venv/ | ||
| backend/__pycache__/ | ||
| __pycache__/ | ||
| .pytest_cache/ | ||
| *.pyc | ||
|
|
||
| # Environment variables | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Google AI Studio (https://aistudio.google.com/app/apikey) から取得したAPIキーを | ||
| # 以下の"YOUR_API_KEY_HERE"を実際のAPIキーに置き換えてください。 | ||
|
|
||
| # GEMINI_API_KEY="YOUR_API_KEY_HERE" | ||
| # ファイル名を.envに変更して使用してください。 | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ユーザー向けに環境変数のテンプレートを追加。 |
||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import pytest | ||
| from fastapi.testclient import TestClient | ||
| from app.main import app | ||
|
|
||
| # TestClientインスタンスを作成 | ||
| client = TestClient(app) | ||
|
|
||
| # 正常系はGeminiが生成し、異常系は自分で書いてみた | ||
|
|
||
| # `send_chat_message` SDKでAPI呼び出しを行う | ||
| # `save_message` ユーザー入力とAI応答を保存する | ||
| CHAT_LOGIC_PATH = "app.main.send_chat_message" | ||
| STORAGE_LOGIC_PATH = "app.main.save_message" | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_chat_endpoint_success(mocker): | ||
| """ | ||
| /chat エンドポイントの正常系テスト | ||
| - 外部関数をモック化する | ||
| - 正常なリクエストを送信し、200 OKが返ることを確認する | ||
| - モック化した関数が正しく呼び出されることを確認する | ||
| """ | ||
| # --- モックの設定 --- | ||
| # send_chat_message をモック化し、固定の応答を返すように設定 | ||
| mock_send_chat = mocker.patch(CHAT_LOGIC_PATH, return_value="AIの応答メッセージ") | ||
|
|
||
| # save_message をモック化 | ||
| mock_save_message = mocker.patch(STORAGE_LOGIC_PATH) | ||
|
|
||
| # --- テストデータ --- | ||
| test_request_body = { | ||
| "message": "テストメッセージ", | ||
| "project": "test_project", | ||
| "phase": "test_phase", | ||
| "session_id": "test_session_123" | ||
| } | ||
|
|
||
| # --- リクエストの実行 --- | ||
| # /chat エンドポイントにPOSTリクエストを送信 | ||
| # TestClientは非同期エンドポイントも同期的に呼び出せる | ||
| response = client.post("/chat", json=test_request_body) | ||
|
|
||
| # --- 検証 --- | ||
| # ステータスコードが200 OKであることを確認 | ||
| assert response.status_code == 200 | ||
|
|
||
| # レスポンスボディが期待通りであることを確認 | ||
| assert response.json() == {"response": "AIの応答メッセージ"} | ||
|
|
||
| # --- モックの呼び出し検証 --- | ||
| # send_chat_message が1回、指定されたメッセージで呼び出されたことを確認 | ||
| mock_send_chat.assert_called_once_with(message="テストメッセージ") | ||
|
|
||
| # save_message が2回呼び出されたことを確認(ユーザーメッセージとAI応答) | ||
| assert mock_save_message.call_count == 2 | ||
|
|
||
| # 1回目の呼び出し(ユーザーメッセージ)の引数を確認 | ||
| mock_save_message.call_args_list[0].assert_called_with( | ||
| "test_project", "test_phase", "test_session_123", "user", "テストメッセージ" | ||
| ) | ||
| # 2回目の呼び出し(AI応答)の引数を確認 | ||
| mock_save_message.call_args_list[1].assert_called_with( | ||
| "test_project", "test_phase", "test_session_123", "model", "AIの応答メッセージ" | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_chat_endpoint_invalid_body(mocker): | ||
| """ | ||
| /chat エンドポイントの異常系テスト | ||
| - 不正なリクエストボディ | ||
| - messageフィールドが欠落している場合、400 Bad Requestが返ることを確認する | ||
| """ | ||
| # --- テストデータ --- | ||
| invalid_request_body = { | ||
| "project": "test_project", | ||
| "phase": "test_phase", | ||
| "session_id": "test_session_123" | ||
| # "message" フィールドが欠落 | ||
| } | ||
|
|
||
| # --- リクエストの実行 --- | ||
| response = client.post("/chat", json=invalid_request_body) | ||
|
|
||
| # --- 検証 --- | ||
| # ステータスコードが400 Bad Requestであることを確認 | ||
| assert response.status_code == 422 # FastAPIはバリデーションエラーで422を返す | ||
|
|
||
| # エラーメッセージに 'message' フィールドの欠落が含まれていることを確認 | ||
| assert "message" in response.json()["detail"][0]["loc"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
secrets を使ってAPIキーを渡すことで、CIでの認証エラーを解決。