-
Notifications
You must be signed in to change notification settings - Fork 69
Add CI and tests for chat app templates #22
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
Open
smurching
wants to merge
4
commits into
databricks:main
Choose a base branch
from
smurching:smurching/update-chat-templates-ci
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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,18 @@ | ||
| name: Test All Apps | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| test-all: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Run tests script | ||
| run: ./scripts/test_apps.sh |
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 |
|---|---|---|
|
|
@@ -139,3 +139,4 @@ ml-models.ipr | |
|
|
||
| .DS_Store | ||
| .databricks | ||
| .venv* | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [pytest] | ||
| pythonpath = . |
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,24 @@ | ||
| from unittest.mock import patch | ||
| import sys | ||
| from model_serving_utils import query_endpoint | ||
|
|
||
| @patch("model_serving_utils.get_deploy_client") | ||
| def test_query_endpoint_chat_format(mock_get_client): | ||
| # Arrange | ||
| mock_client = mock_get_client.return_value | ||
| mock_client.predict.return_value = { | ||
| "choices": [{"message": {"role": "assistant", "content": "Hello there!"}}] | ||
| } | ||
|
|
||
| result = query_endpoint("dummy-endpoint", [{"role": "user", "content": "Hi"}], 400) | ||
| assert result == {"role": "assistant", "content": "Hello there!"} | ||
|
|
||
| @patch("model_serving_utils.get_deploy_client") | ||
| def test_query_endpoint_agent_format(mock_get_client): | ||
| mock_client = mock_get_client.return_value | ||
| mock_client.predict.return_value = { | ||
| "messages": [{"role": "tool", "content": "some tool call res"}, {"role": "assistant", "content": "Agent response."}] | ||
| } | ||
|
|
||
| result = query_endpoint("dummy-endpoint", [{"role": "user", "content": "Hi"}], 400) | ||
| assert result == {"role": "assistant", "content": "Agent response."} |
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,2 @@ | ||
| [pytest] | ||
| pythonpath = . |
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,24 @@ | ||
| from unittest.mock import patch | ||
| import sys | ||
| from model_serving_utils import query_endpoint | ||
|
|
||
| @patch("model_serving_utils.get_deploy_client") | ||
| def test_query_endpoint_chat_format(mock_get_client): | ||
| # Arrange | ||
| mock_client = mock_get_client.return_value | ||
| mock_client.predict.return_value = { | ||
| "choices": [{"message": {"role": "assistant", "content": "Hello there!"}}] | ||
| } | ||
|
|
||
| result = query_endpoint("dummy-endpoint", [{"role": "user", "content": "Hi"}], 400) | ||
| assert result == {"role": "assistant", "content": "Hello there!"} | ||
|
|
||
| @patch("model_serving_utils.get_deploy_client") | ||
| def test_query_endpoint_agent_format(mock_get_client): | ||
| mock_client = mock_get_client.return_value | ||
| mock_client.predict.return_value = { | ||
| "messages": [{"role": "tool", "content": "some tool call res"}, {"role": "assistant", "content": "Agent response."}] | ||
| } | ||
|
|
||
| result = query_endpoint("dummy-endpoint", [{"role": "user", "content": "Hi"}], 400) | ||
| assert result == {"role": "assistant", "content": "Agent response."} |
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 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| GLOBAL_TEST_REQS="test-requirements.txt" | ||
|
|
||
| UNTESTED_APPS=( | ||
| dash-data-app-obo-user | ||
| dash-data-app | ||
| dash-hello-world-app | ||
| flask-hello-world-app | ||
| gradio-data-app-obo-user | ||
| gradio-data-app | ||
| gradio-hello-world-app | ||
| shiny-data-app-obo-user | ||
| shiny-data-app | ||
| shiny-hello-world-app | ||
| streamlit-data-app-obo-user | ||
| streamlit-data-app | ||
| streamlit-hello-world-app | ||
| shiny-chatbot-app | ||
| gradio-chatbot-app | ||
| dash-chatbot-app | ||
| ) | ||
|
|
||
| is_untested() { | ||
| for app in "${UNTESTED_APPS[@]}"; do | ||
| [[ "$1" == "$app" ]] && return 0 | ||
| done | ||
| return 1 | ||
| } | ||
|
|
||
| echo "🔍 Checking for test coverage..." | ||
|
|
||
| missing_tests=() | ||
| for dir in */; do | ||
| base=$(basename "$dir") | ||
|
|
||
| if is_untested "$base"; then | ||
| continue | ||
| fi | ||
|
|
||
| if [[ -f "$dir/app.yaml" ]]; then | ||
| test_dir="${base}/tests" | ||
| if [[ ! -d "$test_dir" ]]; then | ||
| missing_tests+=("$base") | ||
| fi | ||
| fi | ||
| done | ||
|
|
||
| if (( ${#missing_tests[@]} > 0 )); then | ||
| echo "❌ The following apps have app.yaml but no tests:" | ||
| for app in "${missing_tests[@]}"; do | ||
| echo " - $app" | ||
| done | ||
| echo "Please add tests under tests/<app-name>/ or add to UNTESTED_APPS." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "✅ All testable apps have test coverage. Running tests..." | ||
|
|
||
| for dir in */; do | ||
| base=$(basename "$dir") | ||
|
|
||
| if is_untested "$base"; then | ||
| echo "🟡 Skipping $base (allowlisted as an untested app)" | ||
| continue | ||
| fi | ||
|
|
||
| if [[ ! -f "$dir/app.yaml" ]]; then | ||
| echo "⚠️ Skipping $base (no app.yaml)" | ||
| continue | ||
| fi | ||
|
|
||
| echo "🔧 Testing $base..." | ||
|
|
||
| VENV_DIR=".venv-${base}" | ||
| python3 -m venv "$VENV_DIR" | ||
| source "$VENV_DIR/bin/activate" | ||
|
|
||
| pip install -U pip | ||
| pip install -r "$GLOBAL_TEST_REQS" | ||
| pip install -r "$dir/requirements.txt" | ||
|
|
||
| test_dir="${base}/tests" | ||
| echo "🧪 Running tests in $test_dir from $dir" | ||
| pytest --cov="$dir" "$test_dir" --rootdir="$dir" | ||
|
|
||
| deactivate | ||
| rm -rf "$VENV_DIR" | ||
| done |
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,2 @@ | ||
| [pytest] | ||
| pythonpath = . |
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,24 @@ | ||
| from unittest.mock import patch | ||
| import sys | ||
| from model_serving_utils import query_endpoint | ||
|
|
||
| @patch("model_serving_utils.get_deploy_client") | ||
| def test_query_endpoint_chat_format(mock_get_client): | ||
| # Arrange | ||
| mock_client = mock_get_client.return_value | ||
| mock_client.predict.return_value = { | ||
| "choices": [{"message": {"role": "assistant", "content": "Hello there!"}}] | ||
| } | ||
|
|
||
| result = query_endpoint("dummy-endpoint", [{"role": "user", "content": "Hi"}], 400) | ||
| assert result == {"role": "assistant", "content": "Hello there!"} | ||
|
|
||
| @patch("model_serving_utils.get_deploy_client") | ||
| def test_query_endpoint_agent_format(mock_get_client): | ||
| mock_client = mock_get_client.return_value | ||
| mock_client.predict.return_value = { | ||
| "messages": [{"role": "tool", "content": "some tool call res"}, {"role": "assistant", "content": "Agent response."}] | ||
| } | ||
|
|
||
| result = query_endpoint("dummy-endpoint", [{"role": "user", "content": "Hi"}], 400) | ||
| assert result == {"role": "assistant", "content": "Agent response."} |
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,2 @@ | ||
| [pytest] | ||
| pythonpath = . |
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,18 @@ | ||
| import os | ||
| from unittest.mock import patch | ||
| import streamlit.testing.v1 as st_test | ||
| from pathlib import Path | ||
|
|
||
| @patch("model_serving_utils.query_endpoint") | ||
| def test_app_renders_and_responds(mock_query): | ||
| mock_query.return_value = {"role": "assistant", "content": "Mock response"} | ||
| os.environ["SERVING_ENDPOINT"] = "dummy-endpoint" | ||
| # Initial render | ||
| test_dir = Path(__file__).resolve().parent | ||
| app_path = test_dir.parent / "app.py" | ||
| app = st_test.AppTest.from_file(str(app_path)) | ||
| app.run() | ||
| # Set chat input and rerender | ||
| app.chat_input[0].set_value("Hi there!") | ||
| app.run() | ||
| assert "Mock response" in set([md.value for md in app.markdown]) |
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,24 @@ | ||
| from unittest.mock import patch | ||
| import sys | ||
| from model_serving_utils import query_endpoint | ||
|
|
||
| @patch("model_serving_utils.get_deploy_client") | ||
| def test_query_endpoint_chat_format(mock_get_client): | ||
| # Arrange | ||
| mock_client = mock_get_client.return_value | ||
| mock_client.predict.return_value = { | ||
| "choices": [{"message": {"role": "assistant", "content": "Hello there!"}}] | ||
| } | ||
|
|
||
| result = query_endpoint("dummy-endpoint", [{"role": "user", "content": "Hi"}], 400) | ||
| assert result == {"role": "assistant", "content": "Hello there!"} | ||
|
|
||
| @patch("model_serving_utils.get_deploy_client") | ||
| def test_query_endpoint_agent_format(mock_get_client): | ||
| mock_client = mock_get_client.return_value | ||
| mock_client.predict.return_value = { | ||
| "messages": [{"role": "tool", "content": "some tool call res"}, {"role": "assistant", "content": "Agent response."}] | ||
| } | ||
|
|
||
| result = query_endpoint("dummy-endpoint", [{"role": "user", "content": "Hi"}], 400) | ||
| assert result == {"role": "assistant", "content": "Agent response."} |
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,3 @@ | ||
| pytest>=8.3.2 | ||
| pytest-cov | ||
| dash[testing]==3.0.2 | ||
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.
Wondering if we can align the environment version with our current app runtime python packages for high fidelity testing https://src.dev.databricks.com/databricks-eng/universe@3cfd7ba4da9b32c458c0812898a482e03b127910/-/blob/apps/runtime/Dockerfile?L25-35