Skip to content

Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.

chore: remove the unused DocumentFormat enum (#1172)

Thomas Hebrard921ddf389fe7
diff --git a/.test_durations b/.test_durations
index a0e3f2abe..2e814b0c4 100644
--- a/.test_durations
+++ b/.test_durations
@@ -9676,33 +9676,6 @@
"tests/unit/pipelex/tools/misc/test_diff.py::TestDiff::test_make_diff_dirs_pretty_recursive": 0.0063,
"tests/unit/pipelex/tools/misc/test_diff.py::TestDiff::test_make_diff_dirs_pretty_shows_update_direction": 0.2344,
"tests/unit/pipelex/tools/misc/test_diff.py::TestDiff::test_make_diff_dirs_pretty_with_differences": 0.0042,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_as_file_extension[docx-docx]": 0.0009,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_as_file_extension[pdf-pdf]": 0.0011,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_as_file_extension[pptx-pptx]": 0.0005,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_as_mime_type[docx-application/vnd.openxmlformats-officedocument.wordprocessingml.document]": 0.0008,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_as_mime_type[pdf-application/pdf]": 0.0009,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_as_mime_type[pptx-application/vnd.openxmlformats-officedocument.presentationml.presentation]": 0.0029,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_format_predicates[docx-False-True-False]": 0.0014,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_format_predicates[pdf-True-False-False]": 0.7869,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_format_predicates[pptx-False-False-True]": 0.0013,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_from_mime_type_raises_on_unknown[application/msword]": 0.0011,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_from_mime_type_raises_on_unknown[garbage]": 0.0642,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_from_mime_type_raises_on_unknown[image/png]": 0.0007,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_from_mime_type_round_trip[docx]": 0.0006,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_from_mime_type_round_trip[pdf]": 0.001,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_from_mime_type_round_trip[pptx]": 0.0006,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_get_supported_mime_types": 0.0004,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_is_supported_mime_type_false_for_unsupported[]": 0.0003,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_is_supported_mime_type_false_for_unsupported[application/PDF]": 0.0004,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_is_supported_mime_type_false_for_unsupported[image/png]": 0.0008,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_is_supported_mime_type_false_for_unsupported[not-a-mime-type]": 0.0009,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_is_supported_mime_type_true_for_members[docx]": 0.0003,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_is_supported_mime_type_true_for_members[pdf]": 0.0003,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_is_supported_mime_type_true_for_members[pptx]": 0.001,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_raise_if_unsupported_mime_type_passes_on_valid[docx]": 0.0004,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_raise_if_unsupported_mime_type_passes_on_valid[pdf]": 0.0011,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_raise_if_unsupported_mime_type_passes_on_valid[pptx]": 0.0007,
- "tests/unit/pipelex/tools/misc/test_document_utils.py::TestDocumentFormat::test_raise_if_unsupported_mime_type_raises_with_supported_list": 0.0009,
"tests/unit/pipelex/tools/misc/test_filetype_utils.py::TestDetectFileTypeFromBase64::test_detect_file_type_from_base64_binascii_error_chain": 0.1751,
"tests/unit/pipelex/tools/misc/test_filetype_utils.py::TestDetectFileTypeFromBase64::test_detect_file_type_from_base64_bytes_success": 0.0513,
"tests/unit/pipelex/tools/misc/test_filetype_utils.py::TestDetectFileTypeFromBase64::test_detect_file_type_from_base64_data_url_no_comma": 0.0893,
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b0007aecc..572d4de6c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,10 @@
- **`kajson` version**: The pin moves to `kajson==0.7.1`, the release making `ClassRegistry.register_classes_dict({})` a no-op instead of raising `IndexError` — its logging branch for the single-class case indexed into an empty collection. This engine seeds a fresh per-run or per-library registry from a snapshot of the process-global one, so a snapshot that happens to be empty used to crash the seeding rather than register nothing; both seeding sites (distributed-run rehydration and the scoped-registry test fixture) are now safe unconditionally. The release changes nothing in the encoder or decoder, so the serialized wire format is untouched in both directions. Everyone downstream inherits that exact version.
+### Removed
+
+- **`DocumentFormat`**: the `pipelex/tools/misc/document_utils.py` module and the `DocumentFormat` enum it held are gone. Nothing in the engine ever imported them — the only reference outside the module was its own unit test — and the MIME-type and file-extension knowledge they duplicated already lives in `pipelex/tools/misc/filetype_utils.py`, which is what the runtime actually calls. (Breaking for anyone importing the symbol from outside: use `filetype_utils` instead.)
+
### Fixed
- **The projection corpus's divergence gate sees every engine/projection difference**: `pipelex-dev generate-projection-corpus` states that every difference between the reference projection and the engine's own renderer lands in a declared class, and that an undeclared one fails the command — but the walk missed differences in one direction and absorbed regressions into existing classes in the other, so a projection defect could pass generation green and be committed into `mthds-js` and `mthds-python` as contract bytes. The dict walk iterated only the projected keys, so a field the projection stopped rendering was never compared at all; it is now recorded under an id deliberately absent from the declared reasons, which makes the record refuse rather than pass. The file-leaf arm returned on the expansion without ever comparing the URL both sides carry, where plain recursion would have handed a regressed placeholder to the url-named-text class that absorbs it; the shared keys are now compared strictly. And `fixed-count-honoured` fired on any list longer than the engine's single element, which cannot tell an honoured `Concept[N]` from a wrong count or from a variable `[]` slot wrongly duplicated; it now consults the slot's declared `item_count`, taken from the descriptor. Separately, a pipe declaring no inputs used to abort the whole capture — an empty input form is valid and the projection renders it as `{}`, but the engine's renderer refuses one — and is now captured from the projection alone, with no engine half and nothing compared. Re-measuring the same corpus produces bytes identical to the committed capture, with the same classes at the same counts. See [Projection Fixture Corpus](contribute/generate-projection-corpus.md).
diff --git a/pipelex/tools/misc/document_utils.py b/pipelex/tools/misc/document_utils.py
deleted file mode 100644
index f1453ba52..000000000
--- a/pipelex/tools/misc/document_utils.py
+++ /dev/null
@@ -1,97 +0,0 @@
-from enum import StrEnum
-
-
-class DocumentFormat(StrEnum):
- PDF = "pdf"
- DOCX = "docx"
- PPTX = "pptx"
-
- @property
- def is_pdf(self) -> bool:
- match self:
- case DocumentFormat.PDF:
- return True
- case DocumentFormat.DOCX | DocumentFormat.PPTX:
- return False
-
- @property
- def is_docx(self) -> bool:
- match self:
- case DocumentFormat.DOCX:
- return True
- case DocumentFormat.PDF | DocumentFormat.PPTX:
- return False
-
- @property
- def is_pptx(self) -> bool:
- match self:
- case DocumentFormat.PPTX:
- return True
- case DocumentFormat.PDF | DocumentFormat.DOCX:
- return False
-
- @property
- def as_file_extension(self) -> str:
- match self:
- case DocumentFormat.PDF:
- return "pdf"
- case DocumentFormat.DOCX:
- return "docx"
- case DocumentFormat.PPTX:
- return "pptx"
-
- @property
- def as_mime_type(self) -> str:
- match self:
- case DocumentFormat.PDF:
- return "application/pdf"
- case DocumentFormat.DOCX:
- return "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
- case DocumentFormat.PPTX:
- return "application/vnd.openxmlformats-officedocument.presentationml.presentation"
-
- @classmethod
- def get_supported_mime_types(cls) -> frozenset[str]:
- """Return the set of supported document MIME types."""
- return frozenset(fmt.as_mime_type for fmt in cls)
-
- @classmethod
- def is_supported_mime_type(cls, mime_type: str) -> bool:
- """Check if a string is a supported document MIME type."""
- return mime_type in cls.get_supported_mime_types()
-
- @classmethod
- def raise_if_unsupported_mime_type(cls, mime_type: str) -> None:
- """Validate that a MIME type is supported.
-
- Args:
- mime_type: The MIME type to validate.
-
- Raises:
- ValueError: If the MIME type is not supported.
- """
- if not cls.is_supported_mime_type(mime_type):
- supported = ", ".join(sorted(cls.get_supported_mime_types()))
- msg = f"Unsupported document MIME type: {mime_type}. Supported types are: {supported}"
- raise ValueError(msg)
-
- @classmethod
- def from_mime_type(cls, mime_type: str) -> "DocumentFormat":
- """Get DocumentFormat from a MIME type string.
-
- Args:
- mime_type: The MIME type to convert.
-
- Returns:
- The corresponding DocumentFormat.
-
- Raises:
- ValueError: If the MIME type is not supported.
- """
- for fmt in cls:
- if fmt.as_mime_type == mime_type:
- return fmt
- cls.raise_if_unsupported_mime_type(mime_type)
- # This line is unreachable but needed for type checker
- msg = f"Unsupported MIME type: {mime_type}"
- raise ValueError(msg)
diff --git a/subject_grants.toml b/subject_grants.toml
index 3f561d48a..8c50afbaf 100644
--- a/subject_grants.toml
+++ b/subject_grants.toml
@@ -6240,18 +6240,6 @@ rationale = "Inner helper: collects diffs from the dir comparison; single operan
param = "file_list"
rationale = "Inner helper: filters the file list; single operand."
-["pipelex/tools/misc/document_utils.py::DocumentFormat.from_mime_type"]
-param = "mime_type"
-rationale = "Factory from source: builds the result from the mime_type; single operand."
-
-["pipelex/tools/misc/document_utils.py::DocumentFormat.is_supported_mime_type"]
-param = "mime_type"
-rationale = "Predicate on the mime_type; single operand."
-
-["pipelex/tools/misc/document_utils.py::DocumentFormat.raise_if_unsupported_mime_type"]
-param = "mime_type"
-rationale = "Validates/checks the mime_type; single operand."
-
["pipelex/tools/misc/exceptions.py::TomlError.from_tomli_error"]
param = "exc"
rationale = "Factory from source: builds the result from the exc; single operand."
diff --git a/tests/unit/pipelex/tools/misc/test_document_utils.py b/tests/unit/pipelex/tools/misc/test_document_utils.py
deleted file mode 100644
index 318ee79de..000000000
--- a/tests/unit/pipelex/tools/misc/test_document_utils.py
+++ /dev/null
@@ -1,111 +0,0 @@
-import pytest
-
-from pipelex.tools.misc.document_utils import DocumentFormat
-
-
-class TestDocumentFormat:
- @pytest.mark.parametrize(
- ("document_format", "expected_is_pdf", "expected_is_docx", "expected_is_pptx"),
- [
- (DocumentFormat.PDF, True, False, False),
- (DocumentFormat.DOCX, False, True, False),
- (DocumentFormat.PPTX, False, False, True),
- ],
- )
- def test_format_predicates(
- self,
- document_format: DocumentFormat,
- expected_is_pdf: bool,
- expected_is_docx: bool,
- expected_is_pptx: bool,
- ):
- """Each member answers the full is_pdf/is_docx/is_pptx predicate matrix."""
- assert document_format.is_pdf is expected_is_pdf
- assert document_format.is_docx is expected_is_docx
- assert document_format.is_pptx is expected_is_pptx
-
- @pytest.mark.parametrize(
- ("document_format", "expected_extension"),
- [
- (DocumentFormat.PDF, "pdf"),
- (DocumentFormat.DOCX, "docx"),
- (DocumentFormat.PPTX, "pptx"),
- ],
- )
- def test_as_file_extension(self, document_format: DocumentFormat, expected_extension: str):
- """as_file_extension returns the exact extension string for each member."""
- assert document_format.as_file_extension == expected_extension
-
- @pytest.mark.parametrize(
- ("document_format", "expected_mime_type"),
- [
- (DocumentFormat.PDF, "application/pdf"),
- (DocumentFormat.DOCX, "application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
- (DocumentFormat.PPTX, "application/vnd.openxmlformats-officedocument.presentationml.presentation"),
- ],
- )
- def test_as_mime_type(self, document_format: DocumentFormat, expected_mime_type: str):
- """as_mime_type returns the exact MIME type string for each member."""
- assert document_format.as_mime_type == expected_mime_type
-
- def test_get_supported_mime_types(self):
- """get_supported_mime_types returns the exact frozenset of document MIME types."""
- supported = DocumentFormat.get_supported_mime_types()
- assert isinstance(supported, frozenset)
- assert supported == frozenset(
- {
- "application/pdf",
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
- "application/vnd.openxmlformats-officedocument.presentationml.presentation",
- }
- )
-
- @pytest.mark.parametrize("document_format", list(DocumentFormat))
- def test_is_supported_mime_type_true_for_members(self, document_format: DocumentFormat):
- """Every member's MIME type is reported as supported."""
- assert DocumentFormat.is_supported_mime_type(document_format.as_mime_type) is True
-
- @pytest.mark.parametrize(
- "mime_type",
- [
- "image/png",
- "not-a-mime-type",
- "",
- "application/PDF",
- ],
- )
- def test_is_supported_mime_type_false_for_unsupported(self, mime_type: str):
- """Non-document MIME types and garbage are reported as unsupported."""
- assert DocumentFormat.is_supported_mime_type(mime_type) is False
-
- @pytest.mark.parametrize("document_format", list(DocumentFormat))
- def test_raise_if_unsupported_mime_type_passes_on_valid(self, document_format: DocumentFormat):
- """Supported MIME types do not raise."""
- DocumentFormat.raise_if_unsupported_mime_type(document_format.as_mime_type)
-
- def test_raise_if_unsupported_mime_type_raises_with_supported_list(self):
- """Unsupported MIME types raise ValueError naming the offender and listing supported types."""
- with pytest.raises(ValueError, match="Unsupported document MIME type: image/png") as exc_info:
- DocumentFormat.raise_if_unsupported_mime_type("image/png")
- error_message = str(exc_info.value)
- assert "application/pdf" in error_message
- assert "application/vnd.openxmlformats-officedocument.wordprocessingml.document" in error_message
- assert "application/vnd.openxmlformats-officedocument.presentationml.presentation" in error_message
-
- @pytest.mark.parametrize("document_format", list(DocumentFormat))
- def test_from_mime_type_round_trip(self, document_format: DocumentFormat):
- """from_mime_type returns the exact member for its own MIME type."""
- assert DocumentFormat.from_mime_type(document_format.as_mime_type) is document_format
-
- @pytest.mark.parametrize(
- "mime_type",
- [
- "image/png",
- "application/msword",
- "garbage",
- ],
- )
- def test_from_mime_type_raises_on_unknown(self, mime_type: str):
- """from_mime_type raises ValueError for unknown MIME types."""
- with pytest.raises(ValueError, match=f"Unsupported document MIME type: {mime_type}"):
- DocumentFormat.from_mime_type(mime_type)