From 0f92737a4cb9cfac0e5d2ac9c92d210572f9b2c5 Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Mon, 30 Mar 2026 04:29:18 +0300 Subject: [PATCH 1/4] add test for tl parsing --- tests/python/tests/tl_primitives/__init__.py | 0 .../php/data/component-config.yaml | 7 +++ .../python/tests/tl_primitives/php/index.php | 37 +++++++++++++++ .../tests/tl_primitives/test_tl_primitives.py | 47 +++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 tests/python/tests/tl_primitives/__init__.py create mode 100644 tests/python/tests/tl_primitives/php/data/component-config.yaml create mode 100644 tests/python/tests/tl_primitives/php/index.php create mode 100644 tests/python/tests/tl_primitives/test_tl_primitives.py diff --git a/tests/python/tests/tl_primitives/__init__.py b/tests/python/tests/tl_primitives/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/python/tests/tl_primitives/php/data/component-config.yaml b/tests/python/tests/tl_primitives/php/data/component-config.yaml new file mode 100644 index 0000000000..5ec7d22c4e --- /dev/null +++ b/tests/python/tests/tl_primitives/php/data/component-config.yaml @@ -0,0 +1,7 @@ +entry: script +components: + script: + image: KPHP + scope: Request + args: {} + links: {} diff --git a/tests/python/tests/tl_primitives/php/index.php b/tests/python/tests/tl_primitives/php/index.php new file mode 100644 index 0000000000..5dd19a3058 --- /dev/null +++ b/tests/python/tests/tl_primitives/php/index.php @@ -0,0 +1,37 @@ + Date: Tue, 31 Mar 2026 09:56:29 +0300 Subject: [PATCH 2/4] add _assert prefix --- .../tests/tl_primitives/test_tl_primitives.py | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/python/tests/tl_primitives/test_tl_primitives.py b/tests/python/tests/tl_primitives/test_tl_primitives.py index 73317ed377..2bbc2a20e3 100644 --- a/tests/python/tests/tl_primitives/test_tl_primitives.py +++ b/tests/python/tests/tl_primitives/test_tl_primitives.py @@ -11,23 +11,23 @@ def _operation(kind: str, kwargs: typing.Dict[str, typing.Any], expected_result: } -def _rpc_parse(new_rpc_data: str, expected_result: bool): +def _assert_rpc_parse(new_rpc_data: str, expected_result: bool): return _operation('rpc_parse', dict(new_rpc_data=new_rpc_data), expected_result) -def _fetch_int(expected_result: int): +def _assert_fetch_int(expected_result: int): return _operation('fetch_int', dict(), expected_result) -def _fetch_long(expected_result: int): +def _assert_fetch_long(expected_result: int): return _operation('fetch_long', dict(), expected_result) -def _fetch_double(expected_result: float): +def _assert_fetch_double(expected_result: float): return _operation('fetch_double', dict(), expected_result) -def _fetch_string(expected_result: str): +def _assert_fetch_string(expected_result: str): return _operation('fetch_string', dict(), expected_result) @@ -39,9 +39,11 @@ def call(self, *operations): def test_rpc_parse(self): self.call( - _rpc_parse('\x12\x34\x56\x78\x42\x00\x00\x00\x00\x00\x00\x00\x68\x56\x5b\x56\x06\x22\x09\x40\x03abc', True), - _fetch_int(0x78563412), - _fetch_long(0x42), - _fetch_double(3.14161365), - _fetch_string('abc'), + _assert_rpc_parse( + '\x12\x34\x56\x78\x42\x00\x00\x00\x00\x00\x00\x00\x68\x56\x5b\x56\x06\x22\x09\x40\x03abc', True + ), + _assert_fetch_int(0x78563412), + _assert_fetch_long(0x42), + _assert_fetch_double(3.14161365), + _assert_fetch_string('abc'), ) From e9ba925a37aeea926e7a9e22bd67b51b8f8199e4 Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Tue, 31 Mar 2026 10:22:56 +0300 Subject: [PATCH 3/4] add rpc_clean test --- .../python/tests/tl_primitives/php/index.php | 69 +++++++++++-------- .../tests/tl_primitives/test_tl_primitives.py | 40 +++++++---- 2 files changed, 68 insertions(+), 41 deletions(-) diff --git a/tests/python/tests/tl_primitives/php/index.php b/tests/python/tests/tl_primitives/php/index.php index 5dd19a3058..41118af9ab 100644 --- a/tests/python/tests/tl_primitives/php/index.php +++ b/tests/python/tests/tl_primitives/php/index.php @@ -3,35 +3,46 @@ $operations = json_decode(file_get_contents('php://input')); foreach ($operations as $op) { - switch ($op['kind']) { - case 'rpc_parse': - if (rpc_parse($op['new_rpc_data']) != $op['expected']) { - critical_error('error'); - } - break; - case 'fetch_int': - if (fetch_int() != $op['expected']) { - critical_error('error'); - } - break; - case 'fetch_long': - if (fetch_long() != $op['expected']) { - critical_error('error'); - } - break; - case 'fetch_double': - if (fetch_double() != $op['expected']) { - critical_error('error'); - } - break; - case 'fetch_string': - if (fetch_string() != $op['expected']) { - critical_error('error'); - } - break; - default: - critical_error('unknown op ' . $op['kind']); - }; + try { + switch ($op['kind']) { + case 'rpc_parse': + if (rpc_parse($op['new_rpc_data']) != $op['expected']) { + critical_error('error'); + } + break; + case 'rpc_clean': + if (rpc_clean() != $op['expected']) { + critical_error('error'); + } + break; + case 'fetch_int': + if (fetch_int() != $op['expected']) { + critical_error('error'); + } + break; + case 'fetch_long': + if (fetch_long() != $op['expected']) { + critical_error('error'); + } + break; + case 'fetch_double': + if (fetch_double() != $op['expected']) { + critical_error('error'); + } + break; + case 'fetch_string': + if (fetch_string() != $op['expected']) { + critical_error('error'); + } + break; + default: + critical_error('unknown op ' . $op['kind']); + } + } catch (Exception $e) { + if (!$op['expected_exception']) { + throw $e; + } + } } echo 'ok'; diff --git a/tests/python/tests/tl_primitives/test_tl_primitives.py b/tests/python/tests/tl_primitives/test_tl_primitives.py index 2bbc2a20e3..210f7ae4a5 100644 --- a/tests/python/tests/tl_primitives/test_tl_primitives.py +++ b/tests/python/tests/tl_primitives/test_tl_primitives.py @@ -3,32 +3,41 @@ from python.lib.testcase import WebServerAutoTestCase -def _operation(kind: str, kwargs: typing.Dict[str, typing.Any], expected_result: typing.Any): +def _operation( + kind: str, kwargs: typing.Dict[str, typing.Any], expected_result: typing.Any, expected_exception: bool = False +): return { "kind": kind, **kwargs, "expected": expected_result, + "expected_exception": expected_exception, } -def _assert_rpc_parse(new_rpc_data: str, expected_result: bool): - return _operation('rpc_parse', dict(new_rpc_data=new_rpc_data), expected_result) +def _assert_rpc_parse(new_rpc_data: str, expected_result: bool, expected_exception: bool = False): + return _operation( + 'rpc_parse', dict(new_rpc_data=new_rpc_data), expected_result, expected_exception=expected_exception + ) -def _assert_fetch_int(expected_result: int): - return _operation('fetch_int', dict(), expected_result) +def _assert_rpc_clean(expected_result: bool): + return _operation('rpc_clean', dict(), expected_result) -def _assert_fetch_long(expected_result: int): - return _operation('fetch_long', dict(), expected_result) +def _assert_fetch_int(expected_result: int, expected_exception: bool = False): + return _operation('fetch_int', dict(), expected_result, expected_exception=expected_exception) -def _assert_fetch_double(expected_result: float): - return _operation('fetch_double', dict(), expected_result) +def _assert_fetch_long(expected_result: int, expected_exception: bool = False): + return _operation('fetch_long', dict(), expected_result, expected_exception=expected_exception) -def _assert_fetch_string(expected_result: str): - return _operation('fetch_string', dict(), expected_result) +def _assert_fetch_double(expected_result: float, expected_exception: bool = False): + return _operation('fetch_double', dict(), expected_result, expected_exception=expected_exception) + + +def _assert_fetch_string(expected_result: str, expected_exception: bool = False): + return _operation('fetch_string', dict(), expected_result, expected_exception=expected_exception) class TestTlPrimitives(WebServerAutoTestCase): @@ -37,7 +46,7 @@ def call(self, *operations): self.assertEqual(response.status_code, 200) self.assertEqual(response.text, "ok") - def test_rpc_parse(self): + def test_fetch(self): self.call( _assert_rpc_parse( '\x12\x34\x56\x78\x42\x00\x00\x00\x00\x00\x00\x00\x68\x56\x5b\x56\x06\x22\x09\x40\x03abc', True @@ -47,3 +56,10 @@ def test_rpc_parse(self): _assert_fetch_double(3.14161365), _assert_fetch_string('abc'), ) + + def test_rpc_clean(self): + self.call( + _assert_rpc_parse('\x12\x34\x56\x78', True), + _assert_rpc_clean(True), + _assert_fetch_int(0x777, expected_exception=True), + ) From d67a5d29bfc29141390a0594a0f5411e8f6daea3 Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Tue, 31 Mar 2026 12:57:05 +0300 Subject: [PATCH 4/4] split test for kphp --- .../python/tests/tl_primitives/php/index.php | 30 +++++++++++-------- .../tests/tl_primitives/test_tl_primitives.py | 13 +++++++- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/tests/python/tests/tl_primitives/php/index.php b/tests/python/tests/tl_primitives/php/index.php index 41118af9ab..310e851a61 100644 --- a/tests/python/tests/tl_primitives/php/index.php +++ b/tests/python/tests/tl_primitives/php/index.php @@ -6,33 +6,39 @@ try { switch ($op['kind']) { case 'rpc_parse': - if (rpc_parse($op['new_rpc_data']) != $op['expected']) { - critical_error('error'); + $res = rpc_parse($op['new_rpc_data']); + if ($res != $op['expected']) { + critical_error('expected ' . $op['expected'] . ' but ' . $res . ' found'); } break; case 'rpc_clean': - if (rpc_clean() != $op['expected']) { - critical_error('error'); + $res = rpc_clean(); + if ($res != $op['expected']) { + critical_error('expected ' . $op['expected'] . ' but ' . $res . ' found'); } break; case 'fetch_int': - if (fetch_int() != $op['expected']) { - critical_error('error'); + $res = fetch_int(); + if ($res != $op['expected']) { + critical_error('expected ' . $op['expected'] . ' but ' . $res . ' found'); } break; case 'fetch_long': - if (fetch_long() != $op['expected']) { - critical_error('error'); + $res = fetch_long(); + if ($res != $op['expected']) { + critical_error('expected ' . $op['expected'] . ' but ' . $res . ' found'); } break; case 'fetch_double': - if (fetch_double() != $op['expected']) { - critical_error('error'); + $res = fetch_double(); + if ($res != $op['expected']) { + critical_error('expected ' . $op['expected'] . ' but ' . $res . ' found'); } break; case 'fetch_string': - if (fetch_string() != $op['expected']) { - critical_error('error'); + $res = fetch_string(); + if ($res != $op['expected']) { + critical_error('expected ' . $op['expected'] . ' but ' . $res . ' found'); } break; default: diff --git a/tests/python/tests/tl_primitives/test_tl_primitives.py b/tests/python/tests/tl_primitives/test_tl_primitives.py index 210f7ae4a5..c5de676e51 100644 --- a/tests/python/tests/tl_primitives/test_tl_primitives.py +++ b/tests/python/tests/tl_primitives/test_tl_primitives.py @@ -1,5 +1,7 @@ import typing +import pytest + from python.lib.testcase import WebServerAutoTestCase @@ -57,9 +59,18 @@ def test_fetch(self): _assert_fetch_string('abc'), ) - def test_rpc_clean(self): + @pytest.mark.kphp_skip + def test_rpc_clean_k2(self): self.call( _assert_rpc_parse('\x12\x34\x56\x78', True), _assert_rpc_clean(True), _assert_fetch_int(0x777, expected_exception=True), ) + + @pytest.mark.k2_skip + def test_rpc_clean_kphp(self): + self.call( + _assert_rpc_parse('\x12\x34\x56\x78', True), + _assert_rpc_clean(True), + _assert_fetch_int(0x78563412, expected_exception=False), + )