Skip to content
Draft
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
7 changes: 2 additions & 5 deletions airbyte/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
49 changes: 49 additions & 0 deletions tests/unit_tests/test_documents.py
Original file line number Diff line number Diff line change
@@ -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"]
Loading