@devries-cameron20 / composio Mirror · read-only / commits / e1e30b420
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 07:15 UTC

fix(py): decode schema test corpora as UTF-8 (#5118)

This PR: - Closes #5104 - passes `encoding="utf-8"` to `load_object_cases()` and `load_strict_cases()` in `python/tests/fixtures/json_schema_conversion_corpus.py`, so the shared UTF-8 corpus decodes the same way on every locale (Windows cp936 turned `𝄞` into two code points and failed `primitive-unicode-code-point-length`) - adds `tests/test_json_schema_corpus.py`, which simulates a cp936 or cp1252 default encoding for `Path.read_text()` and checks both loaders keep a non-ASCII glyph intact - uses the patch @gtdd123 posted on their fork (https://github.com/gtdd123/composio/commit/e7de06642d0cbc5b259b69551af901bac07c96d1); they are credited as co-author - test-only change: no SDK behavior, fixture bytes, or release metadata change, so no changelog entry Other `read_text()`/`open()` calls under `python/tests` either already pass UTF-8 or read the webhook fixtures, which are not this corpus. Verification (from `python/`, `composio.__file__` checked to be this checkout): - before the fix, the new regression fails (4 failed); after, 4 passed - `LC_ALL=C PYTHONCOERCECLOCALE=0 PYTHONUTF8=0 pytest tests/test_json_schema_corpus.py tests/test_schema_primitive_parity.py tests/test_schema_composition_parity.py tests/test_schema_parser.py`: 274 passed (on `next` the primitive parity file alone fails 22/22 in this locale) - `pytest` over every corpus consumer (`test_cross_sdk_compatibility`, `test_provider`, `test_schema_*`, `test_strict_schema_corpus`, `test_json_schema_corpus`): 598 passed, 11 skipped - `ruff check` and `ruff format --check` (`config/ruff.toml`) clean; `mypy==2.3.1 --config-file config/mypy.ini` on both touched files: no issues Co-authored-by: gtdd123 <230968026+gtdd123@users.noreply.github.com>

Alberto Schiabel committed Oct 27, 2026 at 16:36 UTC e1e30b420c22df44dc1b081b3532e527269a0e43
2 files changed +59 -2
python/tests/fixtures/json_schema_conversion_corpus.py
+4 -2
@@ -116,7 +116,9 @@ def load_object_cases() -> t.List[CorpusCase]:
116 """Decode the shared corpus and enforce its cross-language invariants."""
117 global _cached
118 if _cached is None:
119 - cases = Corpus.model_validate(json.loads(CORPUS_PATH.read_text())).cases
119 + cases = Corpus.model_validate(
120 + json.loads(CORPUS_PATH.read_text(encoding="utf-8"))
121 + ).cases
122 assert_corpus_invariants(cases)
123 _cached = cases
124 return _cached
@@ -187,7 +189,7 @@ def load_strict_cases() -> t.List[StrictCase]:
189 global _cached_strict
190 if _cached_strict is None:
191 cases = StrictCorpus.model_validate(
190 - json.loads(STRICT_CORPUS_PATH.read_text())
192 + json.loads(STRICT_CORPUS_PATH.read_text(encoding="utf-8"))
193 ).cases
194 seen: t.Set[str] = set()
195 for case in cases:
python/tests/test_json_schema_corpus.py new
+55
@@ -0,0 +1,55 @@
1 +"""Checks for decoding the shared JSON Schema fixtures."""
2 +
3 +import json
4 +from pathlib import Path
5 +from unittest.mock import patch
6 +
7 +import pytest
8 +
9 +from tests.fixtures import json_schema_conversion_corpus as corpus
10 +
11 +
12 +@pytest.mark.parametrize("default_encoding", ["cp936", "cp1252"])
13 +@pytest.mark.parametrize("strict", [False, True], ids=["object", "strict"])
14 +def test_corpus_uses_utf8_independently_of_locale(
15 + tmp_path: Path, monkeypatch: pytest.MonkeyPatch, default_encoding: str, strict: bool
16 +) -> None:
17 + glyph = "\U0001d11e"
18 + case: dict[str, object] = {
19 + "id": "unicode-fixture",
20 + "description": glyph,
21 + "schema": {"type": "object"},
22 + }
23 + if strict:
24 + case["strict"] = {"schema": {"type": "object"}}
25 + path_attribute = "STRICT_CORPUS_PATH"
26 + cache_attribute = "_cached_strict"
27 + else:
28 + case["instances"] = [{"input": {"glyph": glyph}, "accepted": True}]
29 + path_attribute = "CORPUS_PATH"
30 + cache_attribute = "_cached"
31 +
32 + load = corpus.load_strict_cases if strict else corpus.load_object_cases
33 +
34 + fixture_path = tmp_path / "corpus.json"
35 + fixture_path.write_text(
36 + json.dumps({"cases": [case]}, ensure_ascii=False), encoding="utf-8"
37 + )
38 + monkeypatch.setattr(corpus, path_attribute, fixture_path)
39 + monkeypatch.setattr(corpus, cache_attribute, None)
40 +
41 + original_read_text = Path.read_text
42 +
43 + def read_text_with_locale_default(path, encoding=None, errors=None):
44 + # Emulate a Windows locale without changing the host's global locale.
45 + if path == fixture_path and encoding is None:
46 + encoding = default_encoding
47 + return original_read_text(path, encoding=encoding, errors=errors)
48 +
49 + with patch.object(Path, "read_text", read_text_with_locale_default):
50 + cases = load()
51 +
52 + assert cases[0].description == glyph
53 + if not strict:
54 + assert corpus.load_object_cases()[0].instances[0].input == {"glyph": glyph}
55 + assert load() is cases