diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-10-02 11:54:56 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-10-02 11:54:56 +0200 |
| commit | d7b7f1049d95e45e6316ac419cb434088c15bd5e (patch) | |
| tree | 77da46e2fe3cb70af5fb2eebcbb1d69dad410b88 /packages/meshbay-common/tests | |
| parent | 56a8cf9167e8c7b0f2df15afed88031608adf782 (diff) | |
| parent | 754387590fa1754436b4648f969915888c6f6c9e (diff) | |
| download | meshbay-d7b7f1049d95e45e6316ac419cb434088c15bd5e.tar.gz | |
Diffstat (limited to 'packages/meshbay-common/tests')
| -rw-r--r-- | packages/meshbay-common/tests/test_admin_subject_parity.py | 47 | ||||
| -rw-r--r-- | packages/meshbay-common/tests/test_js_python_parity.py | 2 |
2 files changed, 19 insertions, 30 deletions
diff --git a/packages/meshbay-common/tests/test_admin_subject_parity.py b/packages/meshbay-common/tests/test_admin_subject_parity.py index 7a229a9..59deaab 100644 --- a/packages/meshbay-common/tests/test_admin_subject_parity.py +++ b/packages/meshbay-common/tests/test_admin_subject_parity.py @@ -18,9 +18,7 @@ from pathlib import Path import pytest from meshbay_common.adminop import ( - group_attach_subject, invite_create_subject, - root_add_subject, secret_digest, structured_subject, tmdb_config_subject, @@ -34,16 +32,13 @@ pytestmark = pytest.mark.skipif( reason="node or crypto.js unavailable — parity cannot be checked", ) -ROOT_ADD = [ - ("/srv/Films", "", "generic", False, False), - ("/srv/Films", "Films", "video", True, True), - ("C:\\Users\\me\\Share", "Partagé", "photo", True, False), - ('/srv/a "quoted", odd:name|x', "名前", "audio", False, True), - ("/srv/tab\there\nnewline\x01ctl", "é", "generic", True, False), -] -GROUP_ATTACH = [ - ("photos", "/srv/photos", True), - ("famille-été", "/mnt/disque externe/Photos", False), +# The canonical JSON itself, on the values that are hard to get identical: +# separators, quotes, control characters, non-ASCII, and null/""/false. +STRUCTURED = [ + {"path": "/srv/Films", "name": "", "writable": False, "n": None}, + {"path": "C:\\Users\\me\\Share", "name": "Partagé", "kind": "photo"}, + {"path": '/srv/a "quoted", odd:name|x', "name": "名前", "removable": True}, + {"path": "/srv/tab\there\nnewline\x01ctl", "name": "é", "z": "", "a": 0}, ] INVITE_CREATE = [ ("0f8fad5b-d9cb-469f-a165-70867728950e", ""), @@ -59,13 +54,12 @@ _HARNESS = r""" const fs = require('fs'); globalThis.window = {}; const src = fs.readFileSync(process.argv[2], 'utf8'); -const M = new Function(src + '\nreturn { rootAddSubject, groupAttachSubject, ' +const M = new Function(src + '\nreturn { adminSubject, ' + 'inviteCreateSubject, tmdbConfigSubject };')(); const v = JSON.parse(fs.readFileSync(process.argv[3], 'utf8')); (async () => { const out = { - root_add: v.root_add.map((a) => M.rootAddSubject(...a)), - group_attach: v.group_attach.map((a) => M.groupAttachSubject(...a)), + structured: v.structured.map((f) => M.adminSubject(f)), invite_create: v.invite_create.map((a) => M.inviteCreateSubject(...a)), tmdb_config: [], }; @@ -80,7 +74,7 @@ def js(tmp_path_factory): d = tmp_path_factory.mktemp("subject-parity") (d / "harness.js").write_text(_HARNESS, encoding="utf-8") (d / "vectors.json").write_text(json.dumps({ - "root_add": ROOT_ADD, "group_attach": GROUP_ATTACH, + "structured": STRUCTURED, "invite_create": INVITE_CREATE, "tmdb_config": TMDB_CONFIG, }), encoding="utf-8") proc = subprocess.run( @@ -95,14 +89,9 @@ def _bytes(s: str) -> bytes: return s.encode("utf-8") -@pytest.mark.parametrize("i,args", list(enumerate(ROOT_ADD))) -def test_root_add_subject_parity(i, args, js): - assert _bytes(js["root_add"][i]) == _bytes(root_add_subject(*args)) - - -@pytest.mark.parametrize("i,args", list(enumerate(GROUP_ATTACH))) -def test_group_attach_subject_parity(i, args, js): - assert _bytes(js["group_attach"][i]) == _bytes(group_attach_subject(*args)) +@pytest.mark.parametrize("i,fields", list(enumerate(STRUCTURED))) +def test_structured_subject_parity(i, fields, js): + assert _bytes(js["structured"][i]) == _bytes(structured_subject(fields)) @pytest.mark.parametrize("i,args", list(enumerate(INVITE_CREATE))) @@ -116,13 +105,13 @@ def test_tmdb_config_subject_parity(i, args, js): def test_every_value_changes_the_subject(): - base = ("/srv/Films", "Films", "video", False, False) - variants = {root_add_subject(*base)} - for i, other in enumerate(("/srv/Other", "Other", "audio", True, True)): + base = ("0f8fad5b-d9cb-469f-a165-70867728950e", "Someone") + variants = {invite_create_subject(*base)} + for i, other in enumerate(("6a2f41a3-c54c-fce8-32d2-0324e1c32e22", "Somebody")): args = list(base) args[i] = other - variants.add(root_add_subject(*args)) - assert len(variants) == 6 + variants.add(invite_create_subject(*args)) + assert len(variants) == 3 def test_unchanged_cleared_and_set_are_three_subjects(): diff --git a/packages/meshbay-common/tests/test_js_python_parity.py b/packages/meshbay-common/tests/test_js_python_parity.py index f75d60a..bb52742 100644 --- a/packages/meshbay-common/tests/test_js_python_parity.py +++ b/packages/meshbay-common/tests/test_js_python_parity.py @@ -668,7 +668,7 @@ _KIND_FIELDS = { "chat": {"groupId": "g" * 32, "epoch": 4, "nonce": base64.b64encode(b"\x01" * 12).decode(), "ct": base64.b64encode(b"ciphertext").decode()}, - "admin": {"op": "root_add", "nodePk": "Tk9ERVBL", "groupId": "g" * 32, + "admin": {"op": "root_remove", "nodePk": "Tk9ERVBL", "groupId": "g" * 32, "subject": '{"path":"/café"}', "nonce": _NONCE, "ts": 1_700_000_000}, } |