From 6b3457ed001c8354135ab1282ca7bcc5f32dd539 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 13 Mar 2026 02:25:23 +0000 Subject: [PATCH 1/2] test: Add test for invalid snapshot JSON manifest structure Added `test_read_manifest_returns_none_on_invalid_entry_format` to test that reading a snapshot manifest with broken JSON data (specifically missing required keys for `SnapshotEntry` causing a `TypeError`) safely returns `None`. Also corrected `tests/fixtures/sample_type_aliases.py` to use `TypeAlias` from `typing` for pre-3.12 alias detection tests. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com> --- tests/fixtures/sample_type_aliases.py | 16 +++++++++------- tests/test_snapshot.py | 9 +++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/fixtures/sample_type_aliases.py b/tests/fixtures/sample_type_aliases.py index 0e1426c..a9b0fef 100644 --- a/tests/fixtures/sample_type_aliases.py +++ b/tests/fixtures/sample_type_aliases.py @@ -19,14 +19,16 @@ # Dummy usage of type aliases to keep static analyzers happy. test_file_path: FilePath | None = None +from typing import TypeAlias + # Pre-3.12 style type aliases (X: TypeAlias = Y) -type FilePath = str | Path -type ModuleName = str -type RulePattern = str -type ExportName = str -type ErrorMessage = str -type ConfigDict = dict[str, str | int | bool | list[str]] -type NamePair = tuple[str, str] +FilePath: TypeAlias = str | Path +ModuleName: TypeAlias = str +RulePattern: TypeAlias = str +ExportName: TypeAlias = str +ErrorMessage: TypeAlias = str +ConfigDict: TypeAlias = dict[str, str | int | bool | list[str]] +NamePair: TypeAlias = tuple[str, str] # Python 3.12+ style type aliases (type X = Y) type FileContent = str diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 17039e9..3cc2e17 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -147,3 +147,12 @@ def test_read_manifest_returns_none_on_invalid_types(self, manager): # Should be a dict, not a list manager.manifest_path.write_text("[]", encoding="utf-8") assert manager.read_manifest() is None + + def test_read_manifest_returns_none_on_invalid_entry_format(self, manager): + manager.snapshot_dir.mkdir(parents=True, exist_ok=True) + # Entry missing required keys will raise TypeError in SnapshotEntry(**e) + manager.manifest_path.write_text( + '{"timestamp": "2024-01-01T00:00:00Z", "entries": [{"invalid_key": "value"}]}', + encoding="utf-8", + ) + assert manager.read_manifest() is None From 98cf3d6806e9d76e3b964a280a2756577cc91c8b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 13 Mar 2026 02:29:24 +0000 Subject: [PATCH 2/2] chore: Fix linting error on test fixture Added an exception in `ruff.toml` for `UP040` on `tests/fixtures/sample_type_aliases.py` to prevent the linter from complaining about the use of `TypeAlias` since it is intentionally used for backward-compatibility testing. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com> --- ruff.toml | 3 +++ tests/fixtures/sample_type_aliases.py | 1 + 2 files changed, 4 insertions(+) diff --git a/ruff.toml b/ruff.toml index 30145e3..8e38f72 100755 --- a/ruff.toml +++ b/ruff.toml @@ -157,6 +157,9 @@ exclude = [ convention = "google" [lint.per-file-ignores] +"tests/fixtures/sample_type_aliases.py" = [ + "UP040", # Intentionally using TypeAlias for backwards compatibility testing +] "tests/*.py" = [ "ANN", "C901", # too complex diff --git a/tests/fixtures/sample_type_aliases.py b/tests/fixtures/sample_type_aliases.py index a9b0fef..0025dcc 100644 --- a/tests/fixtures/sample_type_aliases.py +++ b/tests/fixtures/sample_type_aliases.py @@ -21,6 +21,7 @@ from typing import TypeAlias + # Pre-3.12 style type aliases (X: TypeAlias = Y) FilePath: TypeAlias = str | Path ModuleName: TypeAlias = str