Skip to content

Commit 2633ddb

Browse files
committed
feat(ci): test against multiple versions
1 parent e7d6190 commit 2633ddb

File tree

4 files changed

+116
-20
lines changed

4 files changed

+116
-20
lines changed

.github/sync-repo-settings.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ branchProtectionRules:
2727
requiredStatusCheckContexts:
2828
- "cla/google"
2929
- "lint"
30-
- "mssql-integration-test-pr (langchain-cloud-sql-testing)"
30+
- "mssql-integration-test-pr-py38 (langchain-cloud-sql-testing)"
31+
- "mssql-integration-test-pr-py39 (langchain-cloud-sql-testing)"
32+
- "mssql-integration-test-pr-py310 (langchain-cloud-sql-testing)"
33+
- "mssql-integration-test-pr-py311 (langchain-cloud-sql-testing)"
34+
- "mssql-integration-test-pr-py312 (langchain-cloud-sql-testing)"
3135
- "conventionalcommits.org"
3236
- "header-check"
3337
# - Add required status checks like presubmit tests

DEVELOPER.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# DEVELOPER.md
2+
3+
## Versioning
4+
5+
This library follows [Semantic Versioning](http://semver.org/).
6+
7+
## Processes
8+
9+
### Conventional Commit messages
10+
11+
This repository uses tool [Release Please](https://github.com/googleapis/release-please) to create GitHub and PyPi releases. It does so by parsing your
12+
git history, looking for [Conventional Commit messages](https://www.conventionalcommits.org/),
13+
and creating release PRs.
14+
15+
Learn more by reading [How should I write my commits?](https://github.com/googleapis/release-please?tab=readme-ov-file#how-should-i-write-my-commits)
16+
17+
## Testing
18+
19+
### Run tests locally
20+
21+
1. Set environment variables for `INSTANCE_ID`, `DB_NAME`, `TABLE_NAME`, `REGION`, `DB_USER`, `DB_PASSWORD`
22+
23+
1. Run pytest to automatically run all tests:
24+
25+
```bash
26+
pytest
27+
```
28+
29+
### CI Platform Setup
30+
31+
Cloud Build is used to run tests against Google Cloud resources in test project: langchain-alloydb-testing.
32+
Each test has a corresponding Cloud Build trigger, see [all triggers][triggers].
33+
These tests are registered as required tests in `.github/sync-repo-settings.yaml`.
34+
35+
#### Trigger Setup
36+
37+
Cloud Build triggers (for Python versions 3.8 to 3.11) were created with the following specs:
38+
39+
```YAML
40+
name: mssql-integration-test-pr-py38
41+
description: Run integration tests on PR for Python 3.8
42+
filename: integration.cloudbuild.yaml
43+
github:
44+
name: langchain-google-alloydb-mssql-python
45+
owner: googleapis
46+
pullRequest:
47+
branch: .*
48+
commentControl: COMMENTS_ENABLED_FOR_EXTERNAL_CONTRIBUTORS_ONLY
49+
ignoredFiles:
50+
- docs/**
51+
- .kokoro/**
52+
- .github/**
53+
- "*.md"
54+
substitutions:
55+
_CLUSTER_ID: <ADD_VALUE>
56+
_DATABASE_ID: <ADD_VALUE>
57+
_INSTANCE_ID: <ADD_VALUE>
58+
_REGION: us-central1
59+
_VERSION: "3.8"
60+
```
61+
62+
Use `gcloud builds triggers import --source=trigger.yaml` create triggers via the command line
63+
64+
#### Project Setup
65+
66+
1. Create an Cloud SQL for PostgreSQL instance and database
67+
1. Setup Cloud Build triggers (above)
68+
69+
#### Run tests with Cloud Build
70+
71+
* Run integration test:
72+
73+
```bash
74+
gcloud builds submit --config integration.cloudbuild.yaml --region us-central1 --substitutions=_INSTANCE_ID=$INSTANCE_ID,_DB_NAME=$DB_NAME,_REGION=$REGION
75+
```
76+
77+
#### Trigger
78+
79+
To run Cloud Build tests on GitHub from external contributors, ie RenovateBot, comment: `/gcbrun`.
80+
81+
82+
[triggers]: https://console.cloud.google.com/cloud-build/triggers?e=13802955&project=langchain-cloud-sql-testing

integration.cloudbuild.yaml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,39 @@
1414

1515
steps:
1616
- id: Install dependencies
17-
name: python:3.11
17+
name: python:${_VERSION}
1818
entrypoint: pip
1919
args: ["install", "--user", "-r", "requirements.txt"]
2020

2121
- id: Install module (and test requirements)
22-
name: python:3.11
22+
name: python:${_VERSION}
2323
entrypoint: pip
2424
args: ["install", ".[test]", "--user"]
2525

2626
- id: Run integration tests
27-
name: python:3.11
27+
name: python:${_VERSION}
2828
entrypoint: python
2929
args: ["-m", "pytest"]
3030
env:
31-
- 'PROJECT_ID=$PROJECT_ID'
32-
- 'INSTANCE_ID=$_INSTANCE_ID'
33-
- 'DB_NAME=$_DB_NAME'
34-
- 'TABLE_NAME=test-$BUILD_ID'
35-
- 'REGION=$_REGION'
36-
secretEnv: ['DB_USER', 'DB_PASSWORD']
31+
- "PROJECT_ID=$PROJECT_ID"
32+
- "INSTANCE_ID=$_INSTANCE_ID"
33+
- "DB_NAME=$_DB_NAME"
34+
- "TABLE_NAME=test-$BUILD_ID"
35+
- "REGION=$_REGION"
36+
secretEnv: ["DB_USER", "DB_PASSWORD"]
3737

3838
availableSecrets:
3939
secretManager:
40-
- versionName: projects/$PROJECT_ID/secrets/langchain-test-mssql-username/versions/1
41-
env: 'DB_USER'
42-
- versionName: projects/$PROJECT_ID/secrets/langchain-test-mssql-password/versions/1
43-
env: 'DB_PASSWORD'
40+
- versionName: projects/$PROJECT_ID/secrets/langchain-test-mssql-username/versions/1
41+
env: "DB_USER"
42+
- versionName: projects/$PROJECT_ID/secrets/langchain-test-mssql-password/versions/1
43+
env: "DB_PASSWORD"
4444

4545
substitutions:
4646
_INSTANCE_ID: test-mssql-instance
4747
_REGION: us-central1
4848
_DB_NAME: test
49+
_VERSION: "3.8"
50+
51+
options:
52+
dynamicSubstitutions: true

tests/integration/test_mssql_chat_message_history.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import os
15+
import uuid
1516
from typing import Generator
1617

1718
import pytest
@@ -27,7 +28,8 @@
2728
db_name = os.environ["DB_NAME"]
2829
db_user = os.environ["DB_USER"]
2930
db_password = os.environ["DB_PASSWORD"]
30-
table_name = "message_store"
31+
table_name = "message_store" + str(uuid.uuid4())
32+
malformed_table = "malformed_table" + str(uuid.uuid4())
3133

3234

3335
@pytest.fixture(name="memory_engine")
@@ -42,7 +44,7 @@ def setup() -> Generator:
4244
)
4345

4446
# create table with malformed schema (missing 'type')
45-
query = """CREATE TABLE malformed_table (
47+
query = """CREATE TABLE `{malformed_table}` (
4648
id INT IDENTITY(1,1) PRIMARY KEY,
4749
session_id NVARCHAR(MAX) NOT NULL,
4850
data NVARCHAR(MAX) NOT NULL,
@@ -53,8 +55,8 @@ def setup() -> Generator:
5355
yield engine
5456
# cleanup tables
5557
with engine.connect() as conn:
56-
conn.execute(sqlalchemy.text(f"DROP TABLE IF EXISTS {table_name}"))
57-
conn.execute(sqlalchemy.text(f"DROP TABLE IF EXISTS malformed_table"))
58+
conn.execute(sqlalchemy.text(f"DROP TABLE IF EXISTS `{table_name}`"))
59+
conn.execute(sqlalchemy.text(f"DROP TABLE IF EXISTS `{malformed_table}`"))
5860
conn.commit()
5961

6062

@@ -78,7 +80,9 @@ def test_chat_message_history(memory_engine: MSSQLEngine) -> None:
7880
assert len(history.messages) == 0
7981

8082

81-
def test_chat_message_history_table_does_not_exist(memory_engine: MSSQLEngine) -> None:
83+
def test_chat_message_history_table_does_not_exist(
84+
memory_engine: MSSQLEngine,
85+
) -> None:
8286
"""Test that MSSQLChatMessageHistory fails if table does not exist."""
8387
with pytest.raises(AttributeError) as exc_info:
8488
MSSQLChatMessageHistory(
@@ -97,5 +101,7 @@ def test_chat_message_history_table_malformed_schema(
97101
"""Test that MSSQLChatMessageHistory fails if schema is malformed."""
98102
with pytest.raises(IndexError):
99103
MSSQLChatMessageHistory(
100-
engine=memory_engine, session_id="test", table_name="malformed_table"
104+
engine=memory_engine,
105+
session_id="test",
106+
table_name=malformed_table,
101107
)

0 commit comments

Comments
 (0)