Files
docling/tests/test_backend_vtt.py
geoHeil eb4724ee4c ci: prototype tach-based modular skipping (#3333)
* ci: prototype tach-based modular skipping

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: modularize ubuntu setup and refine gating

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: adopt metaxy-inspired governance helpers

- replace custom aggregate check with re-actors/alls-green

- set FORCE_JAVASCRIPT_ACTIONS_TO_NODE24 on every workflow

- keep PR concurrency alive when the graphite:merge label is present

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: tune checks and pin action versions

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: split CI suites and heavy examples

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* DCO Remediation Commit for Georg Heiler <georg.kf.heiler@gmail.com>

I, Georg Heiler <georg.kf.heiler@gmail.com>, hereby add my Signed-off-by to this commit: ecaa4777886157d5c2a7b3893c3a820983089dbf
I, Georg Heiler <georg.kf.heiler@gmail.com>, hereby add my Signed-off-by to this commit: d15416f3ca94ac97af2a8317cd6404208db9d896

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: sharpen tach graph and per-suite path filters

- Split docling.pipeline into per-pipeline tach modules
  (asr, vlm, standard_pdf, threaded_standard_pdf, legacy_standard_pdf,
  extraction_vlm, base, base_extraction, simple) so pytest --tach-base
  impact analysis can attribute changes to a specific pipeline rather
  than the whole package.
- Split the asr- and vlm-specific docling.datamodel option files
  (asr_model_specs, pipeline_options_asr_model, vlm_engine_options,
  vlm_model_specs, pipeline_options_vlm_model, layout_model_specs,
  stage_model_specs, backend_options) into their own tach modules so
  a narrow spec/options change no longer marks the full datamodel as
  impacted.
- Narrow the per-suite pipeline path filters in checks.yml to the
  concrete pipeline files relevant to each suite, so editing
  vlm_pipeline.py only triggers the vlm matrix cell and editing
  asr_pipeline.py only the asr one.
- Rekey the model cache in setup-ubuntu-ci to include runner.os and
  hashFiles(uv.lock, pyproject.toml), with ordered restore-keys
  fallbacks so a lockfile bump no longer silently stales the cache.

Metaxy parity note: layered tach enforcement (layer = "...") is
blocked by existing backend<->datamodel and utils<->stages cycles;
depot runners, nox dynamic matrices, devenv/nix, dprint and ty are
not applicable to docling's stack. All pinned action SHAs are on
their latest release as of this commit.

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: introduce pipeline and orchestration tach layers

Earlier notes claimed layers were blocked. That was only true for the
cyclic core (backend<->datamodel, utils<->stages). The boundary
*above* core is clean:

- No module under docling/backend, docling/datamodel, docling/models,
  docling/utils, docling/exceptions, or docling/chunking imports
  anything from docling.pipeline (verified by grep).
- No module anywhere in docling/ imports from docling.cli,
  docling.document_converter, docling.document_extractor, or
  docling.service_client (also verified).

So we can introduce two real layers on top of the cyclic core:

- "pipeline"      — docling.pipeline and all nine concrete pipelines
                     (base, simple, base_extraction, asr, vlm,
                     extraction_vlm, standard_pdf,
                     threaded_standard_pdf, legacy_standard_pdf).
- "orchestration" — docling.cli, docling.document_converter,
                     docling.document_extractor, and
                     docling.experimental.pipeline.

Unlayered modules stay "below" both layers (tach allows them to be
depended on freely) and continue to carry the declared-but-cyclic
backend<->datamodel and utils<->stages edges.

A VLM-only layer was explored but rejected: only
docling.pipeline.vlm_pipeline and docling.pipeline.extraction_vlm_pipeline
could be cleanly layered as "vlm", because the matching datamodel
options (pipeline_options_vlm_model, vlm_engine_options,
vlm_model_specs) and model stages (vlm_convert, vlm_pipeline_models)
sit inside the datamodel/models cycle and cannot be promoted to a
higher layer without first breaking that cycle. Layering only the
two pipeline files is not worth the extra config.

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: expand tach layers to entrypoints/pipeline/models/core

Follow-up to the two-layer attempt. After verifying via grep that
nothing in datamodel/utils/backend imports from
docling.models.{extraction,factories,plugins,vlm_pipeline_models}
or from the "upper" stages (page_assemble, page_preprocessing,
reading_order, picture_description, vlm_convert), those nine
modules can be promoted out of the cyclic core into a dedicated
"models" layer.

The resulting order (highest first):

- entrypoints — cli, document_converter, document_extractor,
                experimental.pipeline
- pipeline    — docling.pipeline + the nine concrete pipelines
- models      — model factories, extraction, plugins,
                vlm_pipeline_models, and the five "upper" stages
- core        — datamodel*, backend*, utils, exceptions, chunking,
                models (base), models.utils, inference_engines.*,
                the six "core stages" that utils cycles with
                (chart_extraction, code_formula, layout, ocr,
                picture_classifier, table_structure), and the
                experimental.* and service_client modules

Rename the previous "orchestration" layer to "entrypoints" to
match the common docling vocabulary. Every module now carries an
explicit layer tag instead of relying on implicit unlayered
behaviour, so future additions must pick a layer deliberately.

A VLM layer, a stand-alone inference-engines layer, and separating
datamodel from backend all remain blocked by the bidirectional
backend<->datamodel and utils<->core-stages edges; those need a
code-level refactor first.

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: refine tach client and foundation layers

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: add optional windows and macos smoke lanes

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: normalize reusable workflow boolean inputs

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: replace external all-green action

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: use org-allowed setup-uv action

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: install compiler toolchain for ML tests

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* DCO Remediation Commit for Georg Heiler <georg.kf.heiler@gmail.com>

I, Georg Heiler <georg.kf.heiler@gmail.com>, hereby add my Signed-off-by to this commit: bb714afb42cd1b29ab073a7f59cc72874ff2fdcd

I, Georg Heiler <georg.kf.heiler@gmail.com>, hereby add my Signed-off-by to this commit: a1f2761da8f72bfed636bd571ebf77b42c8771b6

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* DCO Remediation Commit for Georg Heiler <georg.kf.heiler@gmail.com>

I, Georg Heiler <georg.kf.heiler@gmail.com>, hereby add my Signed-off-by to this commit: cc6551b54c5bf4815ae9cd57cf43a98928a74be0

I, Georg Heiler <georg.kf.heiler@gmail.com>, hereby add my Signed-off-by to this commit: b21b0e7ca12b552dbdd54fac1bda113719c286f1

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: simplify ML pytest suite patterns

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: gate heavy examples on label, add job timeouts

- ci-heavy-examples: run only on main push, schedule, workflow_dispatch,
  or when a PR is labeled tests:full / tests:heavy-examples. Drops the
  path-based auto-trigger so that common edits to pyproject.toml,
  uv.lock, or .github/actions do not kick off the 45-60min matrix on
  every PR push. Collapses the changes job into a job-level if gate and
  adds timeout-minutes: 90.
- checks.yml: add timeout-minutes to every job so stuck runners cannot
  burn the full 6h default.

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: tolerate cancelled allowed-skip jobs in check aggregator

Intentional cancellations (manual cancel, concurrency replacement) on
jobs that are already in ALLOWED_SKIPS should not mark the overall
workflow red. Treat `cancelled` the same as `skipped` when the job is
listed as an allowed skip; any unexpected cancellation of a required
job still fails.

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* docs: make minimal vlm example portable

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* DCO Remediation Commit for Georg Heiler <georg.kf.heiler@gmail.com>

I, Georg Heiler <georg.kf.heiler@gmail.com>, hereby add my Signed-off-by to this commit: 2135051da3ed73d4b8a9130f584f40b56155af1a

I, Georg Heiler <georg.kf.heiler@gmail.com>, hereby add my Signed-off-by to this commit: 4f6d1d7960f7418d0cde6425ae61538da84fda40

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: install workspace packages in CI syncs

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* DCO Remediation Commit for Georg Heiler <georg.kf.heiler@gmail.com>

I, Georg Heiler <georg.kf.heiler@gmail.com>, hereby add my Signed-off-by to this commit: 492fa9883d4de6d98ebcb40fa863eafe2facff3c

I, Georg Heiler <georg.kf.heiler@gmail.com>, hereby add my Signed-off-by to this commit: 3eefae71643f9ca3df0264690c0c6eb1f67f06f1

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* DCO Remediation Commit for Georg Heiler <georg.kf.heiler@gmail.com>

I, Georg Heiler <georg.kf.heiler@gmail.com>, hereby add my Signed-off-by to this commit: fe8c9689a0ee94f36eb826da8e2177ef87404f5e

I, Georg Heiler <georg.kf.heiler@gmail.com>, hereby add my Signed-off-by to this commit: eabdd24a6734ec873cdaac857718aef2473677e7

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: remove unused graphite concurrency exception

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: document test labels and gate cross-platform lanes

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: select ml tests with pytest markers

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: fix marker selector typing

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: simplify ml suite scheduling

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: mark cross-platform smoke tests

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: reuse test trigger for ml matrix

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: tighten full ci aggregation

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

* ci: share required job result check

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>

---------

Signed-off-by: Georg Heiler <georg.kf.heiler@gmail.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 14:15:35 +02:00

293 lines
7.2 KiB
Python

import warnings
from io import BytesIO
from pathlib import Path
import pytest
from docling_core.types.doc import DoclingDocument, GroupItem, TextItem
from docling.datamodel.base_models import DocumentStream, InputFormat
from docling.datamodel.document import ConversionResult, _DocumentConversionInput
from docling.document_converter import DocumentConverter
from .test_data_gen_flag import GEN_TEST_DATA
from .verify_utils import verify_document, verify_export
GENERATE = GEN_TEST_DATA
pytestmark = pytest.mark.cross_platform
def test_e2e_vtt_conversions():
directory = Path("./tests/data/webvtt/")
vtt_paths = sorted(directory.rglob("*.vtt"))
converter = DocumentConverter(allowed_formats=[InputFormat.VTT])
for vtt in vtt_paths:
gt_path = vtt.parent.parent / "groundtruth" / "docling_v2" / vtt.name
conv_result: ConversionResult = converter.convert(vtt)
doc: DoclingDocument = conv_result.document
pred_md: str = doc.export_to_markdown(escape_html=False)
assert verify_export(pred_md, str(gt_path) + ".md", generate=GENERATE), (
"export to md"
)
pred_itxt: str = doc._export_to_indented_text(
max_text_len=70, explicit_tables=False
)
assert verify_export(pred_itxt, str(gt_path) + ".itxt", generate=GENERATE), (
"export to indented-text"
)
assert verify_document(doc, str(gt_path) + ".json", GENERATE)
def _create_vtt_stream(content: str) -> DocumentStream:
stream = DocumentStream(name="test.vtt", stream=BytesIO(content.strip().encode()))
dci = _DocumentConversionInput(path_or_stream_iterator=[])
assert dci._guess_format(stream) == InputFormat.VTT
return stream
def _process_vtt_doc(doc: DoclingDocument) -> str:
text: str = ""
for item in doc.texts:
if (
isinstance(item, TextItem)
and item.source
and item.source[0].kind == "track"
):
parent = item.parent.resolve(doc)
if parent and isinstance(parent, GroupItem):
text += " "
text += item.text
return text.strip()
@pytest.fixture(scope="module")
def converter() -> DocumentConverter:
return DocumentConverter()
def test_simple_two_cues_basic(converter):
vtt = """
WEBVTT
00:00:00.000 --> 00:00:02.000
Hello world!
00:00:02.500 --> 00:00:04.000
Second cue.
"""
stream = _create_vtt_stream(vtt)
doc = converter.convert(stream).document
expected = "Hello world! Second cue."
assert _process_vtt_doc(doc) == expected
def test_cue_ids_present_are_ignored_in_output(converter):
vtt = """
WEBVTT
1
00:00:00.000 --> 00:00:01.000
First with ID.
2
00:00:01.250 --> 00:00:02.000
Second with ID.
"""
stream = _create_vtt_stream(vtt)
doc = converter.convert(stream).document
expected = "First with ID. Second with ID."
assert _process_vtt_doc(doc) == expected
def test_multi_line_cue_text_preserved(converter):
vtt = """
WEBVTT
00:00:00.000 --> 00:00:03.000
This is line one.
This is line two.
00:00:03.500 --> 00:00:05.000
Another cue line one.
Another cue line two.
"""
stream = _create_vtt_stream(vtt)
doc = converter.convert(stream).document
expected = "This is line one. This is line two. Another cue line one. Another cue line two."
assert _process_vtt_doc(doc) == expected
def test_styling_and_voice_tags_stripped(converter):
vtt = """
WEBVTT
00:00:00.000 --> 00:00:02.000
<v Roger><b>Hello</b> <i>there</i><u>!</u></v>
00:00:02.200 --> 00:00:04.000
<c.red>Styled</c> and <v Ann>voiced</v> text.
"""
stream = _create_vtt_stream(vtt)
doc = converter.convert(stream).document
# Expect tags removed but inner text retained, spacing preserved.
# expected = "Hello there! Styled and voiced text."
# TODO: temporary ground truth (issue docling-project/docling-core/#371)
expected = "Hello there ! Styled and voiced text."
assert _process_vtt_doc(doc) == expected
def test_blank_cue_contributes_no_text(converter):
# First cue has text; second cue is intentionally blank (zero transcript lines).
vtt = """
WEBVTT
00:00:00.000 --> 00:00:02.000
Visible text.
00:00:02.500 --> 00:00:04.000
"""
stream = _create_vtt_stream(vtt)
doc = converter.convert(stream).document
expected = "Visible text."
assert _process_vtt_doc(doc) == expected
def test_note_blocks_are_ignored(converter):
vtt = """
WEBVTT
NOTE This is a file-level note
It can span multiple lines.
00:00:00.000 --> 00:00:02.000
First cue text.
NOTE Another note between cues
00:00:02.500 --> 00:00:04.000
Second cue text.
"""
stream = _create_vtt_stream(vtt)
doc = converter.convert(stream).document
expected = "First cue text. Second cue text."
assert _process_vtt_doc(doc) == expected
def test_region_block_ignored_but_region_reference_ok(converter):
vtt = """
WEBVTT
REGION
id:top
width:40%
lines:3
00:00:00.000 --> 00:00:02.000 region:top line:90% position:50% size:35% align:start
Top region text.
00:00:02.500 --> 00:00:04.000
Normal region text.
"""
stream = _create_vtt_stream(vtt)
doc = converter.convert(stream).document
expected = "Top region text. Normal region text."
assert _process_vtt_doc(doc) == expected
def test_varied_timestamp_formats_and_settings_ignored(converter):
# First cue uses MM:SS.mmm; second uses HH:MM:SS.mmm and includes settings.
vtt = """
WEBVTT
00:01.000 --> 00:03.000
Under one minute format.
01:00:00.000 --> 01:00:02.000 line:0 position:10% align:end
Hour format with settings.
"""
stream = _create_vtt_stream(vtt)
doc = converter.convert(stream).document
expected = "Under one minute format. Hour format with settings."
assert _process_vtt_doc(doc) == expected
def test_cue_ids_plus_multiline_with_voice_and_style(converter):
# Mix multiple concepts: cue IDs, multi-line text, voice tags, style tags.
vtt = """
WEBVTT
intro
00:00:00.000 --> 00:00:02.000
<v Narrator><i>Welcome</i> to the show.</v>
<b>Enjoy</b> your time.
outro
00:00:02.500 --> 00:00:04.000
<v Host>Goodbye</v>, see you <u>soon</u>.
"""
stream = _create_vtt_stream(vtt)
doc = converter.convert(stream).document
# expected = "Welcome to the show. Enjoy your time. Goodbye, see you soon."
# TODO: temporary ground truth (issue docling-project/docling-core/#371)
expected = "Welcome to the show. Enjoy your time. Goodbye , see you soon ."
assert _process_vtt_doc(doc) == expected
def test_style_blocks_and_note_between_styles_are_ignored(converter):
vtt = """
WEBVTT
STYLE
::cue {
background-image: linear-gradient(to bottom, dimgray, lightgray);
color: papayawhip;
}
/* Style blocks cannot use blank lines nor "dash dash greater than" */
NOTE comment blocks can be used between style blocks.
STYLE
::cue(b) {
color: peachpuff;
}
hello
00:00:00.000 --> 00:00:10.000
Hello <b>world</b>.
"""
stream = _create_vtt_stream(vtt)
with warnings.catch_warnings():
# STYLE and NOTE blocks should be ignored without warnings
warnings.simplefilter("error")
doc = converter.convert(stream).document
# expected = "Hello world."
# TODO: temporary ground truth (issue docling-project/docling-core/#371)
expected = "Hello world ."
assert _process_vtt_doc(doc) == expected