diff --git a/airbyte/documents.py b/airbyte/documents.py index d77264be3..bf260ecac 100644 --- a/airbyte/documents.py +++ b/airbyte/documents.py @@ -10,15 +10,12 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any +import datetime # noqa: TC003 # Pydantic resolves this annotation at runtime. +from typing import Any from pydantic import BaseModel, Field -if TYPE_CHECKING: - import datetime - - MAX_SINGLE_LINE_LENGTH = 60 AIRBYTE_DOCUMENT_RENDERING = "airbyte_document_rendering" TITLE_PROPERTY = "title_property" diff --git a/tests/unit_tests/test_documents.py b/tests/unit_tests/test_documents.py new file mode 100644 index 000000000..07414b7b0 --- /dev/null +++ b/tests/unit_tests/test_documents.py @@ -0,0 +1,49 @@ +# Copyright (c) 2026 Airbyte, Inc., all rights reserved. +"""Regression coverage for document model construction and rendering.""" + +from __future__ import annotations + +from datetime import datetime as DateTime +from typing import Any + +import pytest + +from airbyte._util.document_rendering import DocumentRenderer +from airbyte.documents import Document + + +@pytest.mark.parametrize( + "fields", + [ + {}, + {"last_modified": None}, + {"last_modified": "2026-10-20T12:00:00Z"}, + ], +) +def test_document_construction(fields: dict[str, Any]) -> None: + """Documents validate without callers rebuilding the model's forward references.""" + document = Document(content="Example", metadata={"source": "test"}, **fields) + assert document.page_content == "Example" + assert document.metadata == {"source": "test"} + if fields.get("last_modified"): + assert document.last_modified == DateTime.fromisoformat( + "2026-10-20T12:00:00+00:00" + ) + else: + assert document.last_modified is None + + +def test_document_rendering() -> None: + """The record-to-document path constructs the document model successfully.""" + renderer = DocumentRenderer(content_properties=["body"], metadata_properties=["id"]) + document = renderer.render_document({"body": "Example", "id": "record-1"}) + assert document.page_content == "Example" + assert document.metadata == {"id": "record-1"} + + +def test_document_schema() -> None: + """The model's JSON schema resolves the optional timestamp at runtime.""" + schema = Document.model_json_schema() + assert {"type": "string", "format": "date-time"} in schema["properties"][ + "last_modified" + ]["anyOf"]