litmus-cli 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,119 @@
1
+ """Structural code transforms.
2
+
3
+ Character-level normalizations are gated by token/AST equality, but a
4
+ structural transform changes the tree *by design*, so it needs a different
5
+ proof. Each structural operation has a dedicated validator
6
+ (``validate/structural.py``) and the pipeline discards the change whenever
7
+ that proof does not pass — ``--force`` does not override this, because an
8
+ unproven structural edit is simply never made.
9
+
10
+ First operation: removal of provably-unreferenced module-level Python imports.
11
+ "Unreferenced" is deliberately conservative: a binding counts as referenced if
12
+ its name appears anywhere as an identifier *or inside any string literal*,
13
+ which keeps imports named in ``__all__``, quoted annotations,
14
+ ``getattr``/``globals`` lookups and doctests. Only whole statements that own
15
+ their line(s) are removed — never a single alias out of a multi-name import —
16
+ and ``from __future__`` imports, star imports, function/class-level imports
17
+ and lines marked ``noqa`` are never touched.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import ast
23
+ import re
24
+
25
+ from .base import Transform
26
+
27
+ _IDENTIFIER = re.compile(r"[A-Za-z_][A-Za-z0-9_]*")
28
+ _NOQA = re.compile(r"#\s*noqa", re.IGNORECASE)
29
+
30
+
31
+ def import_bindings(stmt: ast.Import | ast.ImportFrom) -> list[str] | None:
32
+ """Names the statement binds, or ``None`` when unknowable (star import)."""
33
+ if isinstance(stmt, ast.ImportFrom) and any(a.name == "*" for a in stmt.names):
34
+ return None
35
+ return [a.asname or a.name.split(".")[0] for a in stmt.names]
36
+
37
+
38
+ def referenced_names(tree: ast.AST) -> frozenset[str]:
39
+ """Every name the module could plausibly reference at runtime.
40
+
41
+ Identifiers (``ast.Name``), ``global``/``nonlocal`` targets, and every
42
+ identifier-shaped word inside every string constant. Strings count so
43
+ that ``__all__`` entries, quoted annotations and dynamic lookups keep
44
+ their imports. Comments cannot affect runtime, so they do not count.
45
+ ``ast.alias`` nodes produce no ``Name`` nodes, so an import statement is
46
+ not a reference to itself.
47
+ """
48
+ names: set[str] = set()
49
+ for node in ast.walk(tree):
50
+ if isinstance(node, ast.Name):
51
+ names.add(node.id)
52
+ elif isinstance(node, ast.Global | ast.Nonlocal):
53
+ names.update(node.names)
54
+ elif isinstance(node, ast.Constant) and isinstance(node.value, str):
55
+ names.update(_IDENTIFIER.findall(node.value))
56
+ return frozenset(names)
57
+
58
+
59
+ def _own_lines_span(stmt: ast.stmt, lines: list[str]) -> tuple[int, int] | None:
60
+ """0-based inclusive line span, if deleting those lines deletes exactly ``stmt``.
61
+
62
+ The statement must start its first line (so ``x = 1; import os`` is out),
63
+ nothing but whitespace or a plain comment may follow it on its last line
64
+ (so ``import os; x = 1`` is out), and no line may carry a ``noqa`` marker
65
+ (a deliberate keep, e.g. an ``__init__.py`` re-export).
66
+ """
67
+ if stmt.end_lineno is None or stmt.end_col_offset is None or stmt.col_offset != 0:
68
+ return None
69
+ start, end = stmt.lineno - 1, stmt.end_lineno - 1
70
+ # ast column offsets count UTF-8 bytes, so slice the tail in bytes.
71
+ tail = lines[end].encode("utf-8")[stmt.end_col_offset :].decode("utf-8").strip()
72
+ if tail and not tail.startswith("#"):
73
+ return None
74
+ if any(_NOQA.search(lines[i]) for i in range(start, end + 1)):
75
+ return None
76
+ return start, end
77
+
78
+
79
+ def _remove_unused_imports(text: str) -> str:
80
+ try:
81
+ tree = ast.parse(text)
82
+ except SyntaxError:
83
+ return text
84
+ referenced = referenced_names(tree)
85
+ lines = text.splitlines(keepends=True)
86
+ dead: set[int] = set()
87
+ for stmt in tree.body:
88
+ if not isinstance(stmt, ast.Import | ast.ImportFrom):
89
+ continue
90
+ if isinstance(stmt, ast.ImportFrom) and stmt.module == "__future__":
91
+ continue
92
+ bindings = import_bindings(stmt)
93
+ if bindings is None or any(name in referenced for name in bindings):
94
+ continue
95
+ span = _own_lines_span(stmt, lines)
96
+ if span is not None:
97
+ dead.update(range(span[0], span[1] + 1))
98
+ if not dead:
99
+ return text
100
+ return "".join(line for i, line in enumerate(lines) if i not in dead)
101
+
102
+
103
+ REMOVE_UNUSED_IMPORTS = Transform(
104
+ "remove_unused_imports",
105
+ "Remove module-level Python imports that nothing references",
106
+ False,
107
+ _remove_unused_imports,
108
+ note=(
109
+ "Structural: importing a module runs its top-level code, so removing even an "
110
+ "unreferenced import can change behaviour when it was imported for side "
111
+ "effects. Proof-gated: the change is discarded (even under --force) unless "
112
+ "the removal is proven to be the only difference and every removed name is "
113
+ "unreferenced, including inside string literals."
114
+ ),
115
+ )
116
+
117
+ #: Operations the pipeline routes through a dedicated structural proof instead
118
+ #: of the token/AST-equality proof (which structural edits fail by design).
119
+ STRUCTURAL_CODE_OPS = frozenset({REMOVE_UNUSED_IMPORTS.id})
@@ -0,0 +1,148 @@
1
+ """Deterministic metadata removal for image containers, standard library only.
2
+
3
+ This is the capability that turns the tool from *inspect-only* into
4
+ *inspect-and-remove* for the formats it already understands, without depending
5
+ on ``exiftool`` or ``c2patool``.
6
+
7
+ The design decision that makes removal safe to claim: **only ancillary metadata
8
+ is dropped; the pixel-bearing bytes are copied verbatim.** For PNG that is the
9
+ ``IDAT`` stream; for JPEG it is everything from the start-of-scan marker to the
10
+ end of the file. ``image_data_digest`` hashes exactly those bytes, so a caller
11
+ can *prove* the image did not change — see ``validate/binary.py``.
12
+
13
+ Colour-affecting chunks/segments (ICC profiles, gamma, palette, transparency)
14
+ are deliberately kept: dropping them would change how the image renders, which
15
+ would violate the quality-preservation contract.
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ import hashlib
21
+ import re
22
+ import struct
23
+
24
+ PNG_SIGNATURE = b"\x89PNG\r\n\x1a\n"
25
+ JPEG_SOI = b"\xff\xd8"
26
+
27
+ # PNG ancillary chunks that carry metadata rather than image or colour data.
28
+ PNG_STRIP_CHUNKS = frozenset({b"tEXt", b"iTXt", b"zTXt", b"eXIf", b"tIME", b"caBX"})
29
+
30
+ # JPEG APPn/COM markers that carry metadata. APP0 (JFIF) is structural and
31
+ # APP2 (ICC) / APP14 (Adobe colour transform) affect rendering, so they stay.
32
+ JPEG_STRIP_MARKERS = frozenset({0xE1, 0xED, 0xEB, 0xEF, 0xFE})
33
+
34
+ _SVG_METADATA = re.compile(r"<metadata\b.*?</metadata\s*>", re.DOTALL | re.IGNORECASE)
35
+ _SVG_METADATA_EMPTY = re.compile(r"<metadata\b[^>]*/>", re.IGNORECASE)
36
+ _SVG_XMP = re.compile(r"<x:xmpmeta\b.*?</x:xmpmeta\s*>", re.DOTALL | re.IGNORECASE)
37
+ _SVG_XPACKET = re.compile(r"<\?xpacket\b.*?\?>", re.DOTALL | re.IGNORECASE)
38
+
39
+
40
+ def _sha256(data: bytes) -> str:
41
+ return hashlib.sha256(data).hexdigest()
42
+
43
+
44
+ # --- PNG --------------------------------------------------------------------
45
+
46
+
47
+ def _iter_png_raw(data: bytes) -> list[tuple[bytes, bytes]]:
48
+ """Yield (chunk_type, full_chunk_bytes) including length prefix and CRC."""
49
+ chunks: list[tuple[bytes, bytes]] = []
50
+ offset = len(PNG_SIGNATURE)
51
+ while offset + 8 <= len(data):
52
+ (length,) = struct.unpack(">I", data[offset : offset + 4])
53
+ ctype = data[offset + 4 : offset + 8]
54
+ end = offset + 12 + length # length(4)+type(4)+data(length)+crc(4)
55
+ if end > len(data):
56
+ break
57
+ chunks.append((ctype, data[offset:end]))
58
+ offset = end
59
+ if ctype == b"IEND":
60
+ break
61
+ return chunks
62
+
63
+
64
+ def strip_png_metadata(data: bytes) -> tuple[bytes, list[str], str]:
65
+ """Return (new_bytes, removed_chunk_types, image_data_digest)."""
66
+ chunks = _iter_png_raw(data)
67
+ kept: list[bytes] = [PNG_SIGNATURE]
68
+ removed: list[str] = []
69
+ idat = bytearray()
70
+ for ctype, raw in chunks:
71
+ if ctype == b"IDAT":
72
+ idat += raw[8 : len(raw) - 4] # payload only, excluding length/type/crc
73
+ if ctype in PNG_STRIP_CHUNKS:
74
+ removed.append(ctype.decode("ascii", "replace"))
75
+ continue
76
+ kept.append(raw)
77
+ return b"".join(kept), removed, _sha256(bytes(idat))
78
+
79
+
80
+ def png_image_data_digest(data: bytes) -> str:
81
+ idat = bytearray()
82
+ for ctype, raw in _iter_png_raw(data):
83
+ if ctype == b"IDAT":
84
+ idat += raw[8 : len(raw) - 4]
85
+ return _sha256(bytes(idat))
86
+
87
+
88
+ # --- JPEG -------------------------------------------------------------------
89
+
90
+
91
+ def strip_jpeg_metadata(data: bytes) -> tuple[bytes, list[str], str]:
92
+ """Return (new_bytes, removed_marker_names, scan_data_digest).
93
+
94
+ Segments before the start-of-scan are filtered; the scan (pixel data) is
95
+ copied byte-for-byte and hashed for the identity proof.
96
+ """
97
+ out = bytearray(JPEG_SOI)
98
+ removed: list[str] = []
99
+ offset = 2
100
+ n = len(data)
101
+ while offset + 4 <= n:
102
+ if data[offset] != 0xFF:
103
+ break
104
+ marker = data[offset + 1]
105
+ if marker == 0xDA: # start of scan: copy the remainder verbatim
106
+ scan = data[offset:]
107
+ out += scan
108
+ return bytes(out), removed, _sha256(scan)
109
+ (length,) = struct.unpack(">H", data[offset + 2 : offset + 4])
110
+ end = offset + 2 + length
111
+ if length < 2 or end > n:
112
+ break
113
+ if marker in JPEG_STRIP_MARKERS:
114
+ removed.append(f"APP{marker - 0xE0}" if marker >= 0xE0 else "COM")
115
+ else:
116
+ out += data[offset:end]
117
+ offset = end
118
+ # No SOS found (unusual/truncated): return input unchanged, no proof.
119
+ return data, [], ""
120
+
121
+
122
+ def jpeg_scan_digest(data: bytes) -> str:
123
+ offset = 2
124
+ n = len(data)
125
+ while offset + 4 <= n:
126
+ if data[offset] != 0xFF:
127
+ return ""
128
+ marker = data[offset + 1]
129
+ if marker == 0xDA:
130
+ return _sha256(data[offset:])
131
+ (length,) = struct.unpack(">H", data[offset + 2 : offset + 4])
132
+ end = offset + 2 + length
133
+ if length < 2 or end > n:
134
+ return ""
135
+ offset = end
136
+ return ""
137
+
138
+
139
+ # --- SVG --------------------------------------------------------------------
140
+
141
+
142
+ def strip_svg_metadata(text: str) -> tuple[str, int]:
143
+ """Remove <metadata>, XMP and xpacket blocks. Return (new_text, removed_count)."""
144
+ removed = 0
145
+ for pattern in (_SVG_METADATA, _SVG_METADATA_EMPTY, _SVG_XMP, _SVG_XPACKET):
146
+ text, count = pattern.subn("", text)
147
+ removed += count
148
+ return text, removed
@@ -0,0 +1,257 @@
1
+ """Deterministic text normalization transforms.
2
+
3
+ These operations remove or normalize content that carries no visible meaning.
4
+ They are the honest core of the transformation engine: each one is small,
5
+ inspectable, reversible in intent, and validated afterwards.
6
+
7
+ What is deliberately absent: any "rewrite this so it reads as human" step. It
8
+ would be non-deterministic, unverifiable, and is ruled out by the brief (§8).
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import re
14
+ import unicodedata
15
+ from collections.abc import Callable
16
+
17
+ from ..inspectors.unicode_scan import (
18
+ BIDI_CONTROLS,
19
+ BOM,
20
+ EXOTIC_SPACES,
21
+ OTHER_INVISIBLE,
22
+ ZERO_WIDTH,
23
+ is_tag_char,
24
+ is_variation_selector,
25
+ )
26
+ from .base import Transform
27
+ from .code_structural import REMOVE_UNUSED_IMPORTS
28
+
29
+ _ZERO_WIDTH_NO_BOM = frozenset(ZERO_WIDTH) - {BOM}
30
+ _TRAILING_WS = re.compile(r"[ \t]+$", re.MULTILINE)
31
+ _MANY_BLANK_LINES = re.compile(r"\n{4,}")
32
+
33
+
34
+ def _drop(text: str, predicate: Callable[[str], bool]) -> str:
35
+ return "".join(ch for ch in text if not predicate(ch))
36
+
37
+
38
+ def _strip_zero_width(text: str) -> str:
39
+ head, rest = (text[0], text[1:]) if text.startswith(BOM) else ("", text)
40
+ return head + _drop(rest, lambda ch: ch in _ZERO_WIDTH_NO_BOM or ch == BOM)
41
+
42
+
43
+ def _strip_bidi(text: str) -> str:
44
+ return _drop(text, lambda ch: ch in BIDI_CONTROLS)
45
+
46
+
47
+ def _strip_variation_selectors(text: str) -> str:
48
+ return _drop(text, is_variation_selector)
49
+
50
+
51
+ def _strip_tag_characters(text: str) -> str:
52
+ return _drop(text, is_tag_char)
53
+
54
+
55
+ def _strip_other_invisible(text: str) -> str:
56
+ return _drop(text, lambda ch: ch in OTHER_INVISIBLE)
57
+
58
+
59
+ def _strip_control_characters(text: str) -> str:
60
+ return _drop(
61
+ text,
62
+ lambda ch: unicodedata.category(ch) == "Cc" and ch not in "\n\r\t",
63
+ )
64
+
65
+
66
+ def _normalize_spaces(text: str) -> str:
67
+ return "".join(" " if ch in EXOTIC_SPACES else ch for ch in text)
68
+
69
+
70
+ def _strip_bom(text: str) -> str:
71
+ return text[1:] if text.startswith(BOM) else text
72
+
73
+
74
+ def _normalize_nfc(text: str) -> str:
75
+ return unicodedata.normalize("NFC", text)
76
+
77
+
78
+ def _normalize_line_endings(text: str) -> str:
79
+ return text.replace("\r\n", "\n").replace("\r", "\n")
80
+
81
+
82
+ def _strip_trailing_whitespace(text: str) -> str:
83
+ return _TRAILING_WS.sub("", text)
84
+
85
+
86
+ def _collapse_blank_lines(text: str) -> str:
87
+ return _MANY_BLANK_LINES.sub("\n\n\n", text)
88
+
89
+
90
+ def _ensure_final_newline(text: str) -> str:
91
+ if not text or text.endswith("\n"):
92
+ return text
93
+ return text + "\n"
94
+
95
+
96
+ TRANSFORMS: dict[str, Transform] = {
97
+ t.id: t
98
+ for t in [
99
+ Transform(
100
+ "strip_zero_width",
101
+ "Remove zero-width and word-joiner characters",
102
+ True,
103
+ _strip_zero_width,
104
+ ),
105
+ Transform(
106
+ "strip_tag_characters",
107
+ "Remove deprecated Unicode tag characters (U+E0000-U+E007F)",
108
+ True,
109
+ _strip_tag_characters,
110
+ note="These carry hidden ASCII payloads; inspect before removing.",
111
+ ),
112
+ Transform(
113
+ "strip_bidi_controls",
114
+ "Remove bidirectional formatting controls",
115
+ True,
116
+ _strip_bidi,
117
+ note="Removing these changes display order in genuinely right-to-left text.",
118
+ ),
119
+ Transform(
120
+ "strip_variation_selectors",
121
+ "Remove variation selectors",
122
+ True,
123
+ _strip_variation_selectors,
124
+ note="Can change emoji presentation (text vs emoji style).",
125
+ ),
126
+ Transform(
127
+ "strip_other_invisible",
128
+ "Remove soft hyphens, combining grapheme joiners and blank Braille",
129
+ True,
130
+ _strip_other_invisible,
131
+ ),
132
+ Transform(
133
+ "strip_control_characters",
134
+ "Remove C0/C1 control characters other than tab, CR and LF",
135
+ True,
136
+ _strip_control_characters,
137
+ ),
138
+ Transform(
139
+ "normalize_spaces",
140
+ "Replace non-standard space characters with U+0020",
141
+ True,
142
+ _normalize_spaces,
143
+ note="Changes line-breaking behaviour where NO-BREAK SPACE was intentional.",
144
+ ),
145
+ Transform("strip_bom", "Remove a leading UTF-8 byte order mark", True, _strip_bom),
146
+ Transform(
147
+ "normalize_nfc",
148
+ "Normalize to Unicode NFC",
149
+ True,
150
+ _normalize_nfc,
151
+ note="Canonical-equivalence only; NFKC (which is lossy) is not used.",
152
+ ),
153
+ Transform(
154
+ "normalize_line_endings", "Convert CRLF and CR to LF", True, _normalize_line_endings
155
+ ),
156
+ Transform(
157
+ "strip_trailing_whitespace",
158
+ "Remove trailing spaces and tabs from each line",
159
+ True,
160
+ _strip_trailing_whitespace,
161
+ note="In Markdown, two trailing spaces are a hard line break.",
162
+ ),
163
+ Transform(
164
+ "collapse_blank_lines",
165
+ "Collapse runs of more than two blank lines",
166
+ True,
167
+ _collapse_blank_lines,
168
+ ),
169
+ Transform(
170
+ "ensure_final_newline",
171
+ "Ensure the file ends with a newline",
172
+ True,
173
+ _ensure_final_newline,
174
+ ),
175
+ REMOVE_UNUSED_IMPORTS,
176
+ ]
177
+ }
178
+
179
+ PROFILES: dict[str, list[str]] = {
180
+ # Removes only content that has no visible rendering at all.
181
+ "minimal": [
182
+ "strip_zero_width",
183
+ "strip_tag_characters",
184
+ "strip_bidi_controls",
185
+ "strip_variation_selectors",
186
+ "strip_other_invisible",
187
+ "strip_control_characters",
188
+ "strip_bom",
189
+ ],
190
+ # Adds whitespace and Unicode normalization.
191
+ "standard": [
192
+ "strip_zero_width",
193
+ "strip_tag_characters",
194
+ "strip_bidi_controls",
195
+ "strip_variation_selectors",
196
+ "strip_other_invisible",
197
+ "strip_control_characters",
198
+ "strip_bom",
199
+ "normalize_nfc",
200
+ "normalize_spaces",
201
+ "normalize_line_endings",
202
+ "strip_trailing_whitespace",
203
+ "ensure_final_newline",
204
+ ],
205
+ # Standard plus proof-gated structural code operations (Python only today).
206
+ # On non-code files the structural step is skipped, so this degrades to
207
+ # exactly the standard profile.
208
+ "code": [
209
+ "remove_unused_imports",
210
+ "strip_zero_width",
211
+ "strip_tag_characters",
212
+ "strip_bidi_controls",
213
+ "strip_variation_selectors",
214
+ "strip_other_invisible",
215
+ "strip_control_characters",
216
+ "strip_bom",
217
+ "normalize_nfc",
218
+ "normalize_spaces",
219
+ "normalize_line_endings",
220
+ "strip_trailing_whitespace",
221
+ "ensure_final_newline",
222
+ ],
223
+ # Adds structural tidying that changes the byte layout more visibly.
224
+ "tidy": [
225
+ "strip_zero_width",
226
+ "strip_tag_characters",
227
+ "strip_bidi_controls",
228
+ "strip_variation_selectors",
229
+ "strip_other_invisible",
230
+ "strip_control_characters",
231
+ "strip_bom",
232
+ "normalize_nfc",
233
+ "normalize_spaces",
234
+ "normalize_line_endings",
235
+ "strip_trailing_whitespace",
236
+ "collapse_blank_lines",
237
+ "ensure_final_newline",
238
+ ],
239
+ }
240
+
241
+
242
+ def resolve_operations(profile: str | None, operations: list[str] | None) -> list[Transform]:
243
+ """Resolve a profile name or an explicit operation list into transforms.
244
+
245
+ Order is the profile's declared order, which is significant: invisible
246
+ characters are removed before whitespace normalization so that a
247
+ zero-width character between two spaces does not survive as a gap.
248
+ """
249
+ if operations:
250
+ unknown = [op for op in operations if op not in TRANSFORMS]
251
+ if unknown:
252
+ raise KeyError(f"unknown operation(s): {', '.join(sorted(unknown))}")
253
+ return [TRANSFORMS[op] for op in operations]
254
+ name = profile or "standard"
255
+ if name not in PROFILES:
256
+ raise KeyError(f"unknown profile '{name}'; choose from {', '.join(sorted(PROFILES))}")
257
+ return [TRANSFORMS[op] for op in PROFILES[name]]
@@ -0,0 +1,3 @@
1
+ from .text import DEFAULT_MIN_LEXICAL_SIMILARITY, validate_text
2
+
3
+ __all__ = ["DEFAULT_MIN_LEXICAL_SIMILARITY", "validate_text"]
@@ -0,0 +1,75 @@
1
+ """Validation for image metadata stripping.
2
+
3
+ The claim we can make here is unusually strong for a watermark/metadata tool:
4
+ metadata was removed *and the pixels are provably unchanged*. We prove it by
5
+ hashing the pixel-bearing bytes (PNG ``IDAT`` / JPEG scan) before and after and
6
+ requiring byte-for-byte equality. A competitor that strips metadata without
7
+ this check cannot distinguish "removed the label" from "corrupted the image".
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from ..model import Check, ValidationReport
13
+ from ..transform.file_strip import (
14
+ JPEG_SOI,
15
+ PNG_SIGNATURE,
16
+ jpeg_scan_digest,
17
+ png_image_data_digest,
18
+ )
19
+
20
+
21
+ def validate_image_strip(before: bytes, after: bytes) -> ValidationReport:
22
+ checks: list[Check] = []
23
+
24
+ if after.startswith(PNG_SIGNATURE):
25
+ digest_before = png_image_data_digest(before)
26
+ digest_after = png_image_data_digest(after)
27
+ parsed = bool(digest_after)
28
+ elif after.startswith(JPEG_SOI):
29
+ digest_before = jpeg_scan_digest(before)
30
+ digest_after = jpeg_scan_digest(after)
31
+ parsed = bool(digest_after)
32
+ else:
33
+ return ValidationReport(
34
+ performed=True,
35
+ all_passed=None,
36
+ checks=[
37
+ Check(
38
+ name="image_recognized",
39
+ passed=None,
40
+ detail="Output is not a recognized PNG or JPEG; cannot prove preservation.",
41
+ )
42
+ ],
43
+ )
44
+
45
+ checks.append(
46
+ Check(
47
+ name="image_parses_after",
48
+ passed=parsed,
49
+ detail="Output still parses as a valid image container."
50
+ if parsed
51
+ else "Output no longer parses; the strip corrupted the container.",
52
+ )
53
+ )
54
+
55
+ identical = parsed and digest_before == digest_after and bool(digest_after)
56
+ checks.append(
57
+ Check(
58
+ name="pixel_data_identical",
59
+ passed=identical,
60
+ detail=(
61
+ "Pixel-bearing bytes are byte-for-byte identical to the original; "
62
+ "only metadata was removed."
63
+ if identical
64
+ else "Pixel-bearing bytes changed; the image content was not preserved."
65
+ ),
66
+ measurements={"digest_before": digest_before, "digest_after": digest_after},
67
+ )
68
+ )
69
+
70
+ decided = [c.passed for c in checks if c.passed is not None]
71
+ return ValidationReport(
72
+ performed=True,
73
+ all_passed=all(decided) if decided else None,
74
+ checks=checks,
75
+ )