Skip to content

Commit 0d8d805

Browse files
authored
ci: ensure backwards/forward compatibility of the API (#306)
1 parent 1cd8362 commit 0d8d805

7 files changed

Lines changed: 375 additions & 7 deletions

File tree

.github/workflows/test.yml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,4 +1084,52 @@ jobs:
10841084
git diff --stat
10851085
exit 1
10861086
fi
1087-
echo "✓ All generated files are up to date"
1087+
echo "✓ All generated files are up to date"
1088+
1089+
check-openapi-compatibility:
1090+
runs-on: ubuntu-latest
1091+
env:
1092+
UV_INDEX: pytorch=https://download.pytorch.org/whl/cpu
1093+
1094+
steps:
1095+
- uses: actions/checkout@v4
1096+
with:
1097+
fetch-depth: 0 # Fetch full git history to access base branch
1098+
1099+
- name: Install uv
1100+
uses: astral-sh/setup-uv@v5
1101+
with:
1102+
enable-cache: true
1103+
1104+
- name: Set up Python
1105+
uses: actions/setup-python@v5
1106+
with:
1107+
python-version-file: ".python-version"
1108+
1109+
- name: Install hindsight-dev dependencies
1110+
run: |
1111+
cd hindsight-dev && uv sync --frozen --index-strategy unsafe-best-match
1112+
1113+
- name: Check OpenAPI compatibility with base branch
1114+
run: |
1115+
# Get the base branch (usually main)
1116+
BASE_BRANCH="${{ github.base_ref }}"
1117+
1118+
if [ -z "$BASE_BRANCH" ]; then
1119+
echo "⚠️ Warning: No base branch found (not a PR?). Skipping compatibility check."
1120+
exit 0
1121+
fi
1122+
1123+
echo "Checking OpenAPI compatibility against base branch: $BASE_BRANCH"
1124+
1125+
# Extract the old OpenAPI spec from base branch
1126+
git show "origin/$BASE_BRANCH:hindsight-docs/static/openapi.json" > /tmp/old-openapi.json
1127+
1128+
if [ ! -s /tmp/old-openapi.json ]; then
1129+
echo "⚠️ Warning: Could not find OpenAPI spec in base branch. Skipping compatibility check."
1130+
exit 0
1131+
fi
1132+
1133+
# Check compatibility using our tool
1134+
cd hindsight-dev
1135+
uv run check-openapi-compatibility /tmp/old-openapi.json ../hindsight-docs/static/openapi.json

hindsight-api/hindsight_api/api/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ class CreateMentalModelRequest(BaseModel):
11611161
class CreateMentalModelResponse(BaseModel):
11621162
"""Response model for mental model creation."""
11631163

1164-
mental_model_id: str = Field(description="ID of the created mental model")
1164+
mental_model_id: str | None = Field(None, description="ID of the created mental model")
11651165
operation_id: str = Field(description="Operation ID to track refresh progress")
11661166

11671167

hindsight-clients/python/hindsight_client_api/models/create_mental_model_response.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
import json
1919

2020
from pydantic import BaseModel, ConfigDict, Field, StrictStr
21-
from typing import Any, ClassVar, Dict, List
21+
from typing import Any, ClassVar, Dict, List, Optional
2222
from typing import Optional, Set
2323
from typing_extensions import Self
2424

2525
class CreateMentalModelResponse(BaseModel):
2626
"""
2727
Response model for mental model creation.
2828
""" # noqa: E501
29-
mental_model_id: StrictStr = Field(description="ID of the created mental model")
29+
mental_model_id: Optional[StrictStr] = None
3030
operation_id: StrictStr = Field(description="Operation ID to track refresh progress")
3131
__properties: ClassVar[List[str]] = ["mental_model_id", "operation_id"]
3232

@@ -69,6 +69,11 @@ def to_dict(self) -> Dict[str, Any]:
6969
exclude=excluded_fields,
7070
exclude_none=True,
7171
)
72+
# set to None if mental_model_id (nullable) is None
73+
# and model_fields_set contains the field
74+
if self.mental_model_id is None and "mental_model_id" in self.model_fields_set:
75+
_dict['mental_model_id'] = None
76+
7277
return _dict
7378

7479
@classmethod

hindsight-clients/typescript/generated/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ export type CreateMentalModelResponse = {
440440
*
441441
* ID of the created mental model
442442
*/
443-
mental_model_id: string;
443+
mental_model_id?: string | null;
444444
/**
445445
* Operation Id
446446
*

0 commit comments

Comments
 (0)