Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cog_safe_push/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def lint(model: Model, train: bool):
schema = get_openapi_schema(model)
properties = schema["components"]["schemas"][input_name]["properties"]
for name, spec in properties.items():
if spec.get("deprecated", False):
continue
description = spec.get("description")
if not description:
errors.append(f"{name}: Missing description")
Expand Down
65 changes: 64 additions & 1 deletion test/test_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from unittest.mock import Mock

import pytest

from cog_safe_push.schema import IncompatibleSchemaError, check_backwards_compatible
from cog_safe_push.schema import (
IncompatibleSchemaError,
SchemaLintError,
check_backwards_compatible,
lint,
)


def test_identical_schemas():
Expand Down Expand Up @@ -193,3 +200,59 @@ def test_multiple_incompatibilities():
assert "Input choice is missing choices: 'C'" in error_message
assert "Input new_required is new and is required" in error_message
assert "Output has changed type" in error_message


def test_lint_deprecated_input_without_description():
mock_model = Mock()
mock_model.versions.list.return_value = [
Mock(
openapi_schema={
"components": {
"schemas": {
"Input": {
"properties": {
"steps": {
"type": "integer",
"minimum": 1,
"maximum": 50,
"default": 25,
"deprecated": True,
},
"prompt": {
"type": "string",
"description": "The prompt to use",
},
}
}
}
}
}
)
]
lint(mock_model, train=False)


def test_lint_non_deprecated_input_without_description():
mock_model = Mock()
mock_model.versions.list.return_value = [
Mock(
openapi_schema={
"components": {
"schemas": {
"Input": {
"properties": {
"steps": {
"type": "integer",
"minimum": 1,
"maximum": 50,
"default": 25,
},
}
}
}
}
}
)
]
with pytest.raises(SchemaLintError, match="steps: Missing description"):
lint(mock_model, train=False)