This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow-steward.git
The following commit(s) were added to refs/heads/main by this push:
new ec86184 tests(sandbox-lint): cover deep_diff edge cases, missing
invariant paths, and CLI error handling (#236)
ec86184 is described below
commit ec8618491582fedb01baca7a84e3e14f2b4140c5
Author: Justin Mclean <[email protected]>
AuthorDate: Wed May 20 18:20:20 2026 +1000
tests(sandbox-lint): cover deep_diff edge cases, missing invariant paths,
and CLI error handling (#236)
* tests(sandbox-lint): cover deep_diff edge cases, missing invariant paths,
and CLI error handling
11 new tests filling the remaining gaps:
deep_diff:
- type mismatch between actual and expected
- key missing in settings but present in expected
- extra key in settings not in expected
- deeply nested scalar change reported with correct path
- non-SET_LIST_KEYS list mismatch uses positional comparison
- identical trees return empty diff
- empty dicts match
check_invariants:
- missing sandbox key entirely
- missing filesystem key
- missing permissions key
main CLI:
- missing settings file raises SystemExit
- missing expected file raises SystemExit
- malformed JSON raises SystemExit
- top-level non-object value raises SystemExit
https://claude.ai/code/session_01WEx58ofmTyCe2YhCppV3qN
* revert changes tolock.uv
* Revert "revert changes tolock.uv"
This reverts commit 7ec5ae906746c5968d2ca19d7625b197647e5263.
---------
Co-authored-by: Claude <[email protected]>
---
tools/sandbox-lint/tests/test_validator.py | 106 +++++++++++++++++++++++++++++
1 file changed, 106 insertions(+)
diff --git a/tools/sandbox-lint/tests/test_validator.py
b/tools/sandbox-lint/tests/test_validator.py
index 3c6d1d9..1521ff4 100644
--- a/tools/sandbox-lint/tests/test_validator.py
+++ b/tools/sandbox-lint/tests/test_validator.py
@@ -236,3 +236,109 @@ def test_cli_passes_on_match(tmp_path: Path, baseline:
dict[str, Any]) -> None:
_write_json(expected_path, baseline)
rc = main(["--settings", str(settings_path), "--expected",
str(expected_path)])
assert rc == 0
+
+
+# ---------------------------------------------------------------------------
+# deep_diff: additional structural cases
+# ---------------------------------------------------------------------------
+
+
+def test_diff_type_mismatch_reported() -> None:
+ diffs = deep_diff({"key": "string"}, {"key": 42})
+ assert any("type mismatch" in d for d in diffs)
+
+
+def test_diff_key_missing_in_settings_reported() -> None:
+ diffs = deep_diff({}, {"key": "value"})
+ assert any("missing in settings" in d for d in diffs)
+
+
+def test_diff_extra_key_in_settings_reported() -> None:
+ diffs = deep_diff({"extra": "value"}, {})
+ assert any("extra in settings" in d for d in diffs)
+
+
+def test_diff_nested_scalar_change_reported() -> None:
+ actual = {"a": {"b": {"c": 1}}}
+ expected = {"a": {"b": {"c": 2}}}
+ diffs = deep_diff(actual, expected)
+ assert len(diffs) == 1
+ assert "$.a.b.c" in diffs[0]
+
+
+def test_diff_non_set_list_mismatch_reported() -> None:
+ # Lists whose key is not in SET_LIST_KEYS are compared positionally.
+ actual = {"hooks": [1, 2, 3]}
+ expected = {"hooks": [1, 2, 4]}
+ diffs = deep_diff(actual, expected)
+ assert any("list mismatch" in d for d in diffs)
+
+
+def test_diff_identical_trees_return_empty() -> None:
+ data = {"sandbox": {"enabled": True, "network": {"allowedDomains": ["a",
"b"]}}}
+ assert deep_diff(data, data) == []
+
+
+def test_diff_empty_dicts_match() -> None:
+ assert deep_diff({}, {}) == []
+
+
+# ---------------------------------------------------------------------------
+# check_invariants: missing top-level keys
+# ---------------------------------------------------------------------------
+
+
+def test_invariant_missing_sandbox_key() -> None:
+ errors = check_invariants({})
+ assert any("sandbox" in e for e in errors)
+
+
+def test_invariant_missing_filesystem_key(baseline: dict[str, Any]) -> None:
+ settings = copy.deepcopy(baseline)
+ del settings["sandbox"]["filesystem"]
+ errors = check_invariants(settings)
+ assert any("filesystem" in e for e in errors)
+
+
+def test_invariant_missing_permissions_key(baseline: dict[str, Any]) -> None:
+ settings = copy.deepcopy(baseline)
+ del settings["permissions"]
+ errors = check_invariants(settings)
+ assert any("permissions" in e for e in errors)
+
+
+# ---------------------------------------------------------------------------
+# CLI: malformed / missing file error paths
+# ---------------------------------------------------------------------------
+
+
+def test_cli_exits_on_missing_settings_file(tmp_path: Path, baseline:
dict[str, Any]) -> None:
+ expected_path = tmp_path / "expected.json"
+ _write_json(expected_path, baseline)
+ with pytest.raises(SystemExit):
+ main(["--settings", str(tmp_path / "nonexistent.json"), "--expected",
str(expected_path)])
+
+
+def test_cli_exits_on_missing_expected_file(tmp_path: Path, baseline:
dict[str, Any]) -> None:
+ settings_path = tmp_path / "settings.json"
+ _write_json(settings_path, baseline)
+ with pytest.raises(SystemExit):
+ main(["--settings", str(settings_path), "--expected", str(tmp_path /
"nonexistent.json")])
+
+
+def test_cli_exits_on_malformed_json(tmp_path: Path, baseline: dict[str, Any])
-> None:
+ settings_path = tmp_path / "settings.json"
+ settings_path.write_text("{ not valid json }")
+ expected_path = tmp_path / "expected.json"
+ _write_json(expected_path, baseline)
+ with pytest.raises(SystemExit):
+ main(["--settings", str(settings_path), "--expected",
str(expected_path)])
+
+
+def test_cli_exits_when_top_level_value_is_not_object(tmp_path: Path,
baseline: dict[str, Any]) -> None:
+ settings_path = tmp_path / "settings.json"
+ settings_path.write_text("[1, 2, 3]")
+ expected_path = tmp_path / "expected.json"
+ _write_json(expected_path, baseline)
+ with pytest.raises(SystemExit):
+ main(["--settings", str(settings_path), "--expected",
str(expected_path)])