0d5c6650a3
Move the inline ADD_SCRIPT string into add.lua beside its module in both languages, matching cas.lua and append.lua: python reads it through importlib.resources and registers it (EVALSHA), typescript reads it relative to import.meta.url and tsup copies it beside the bundle. Registering the script drops the cast around the raw eval call. The two inline copies had already drifted on indentation, so add a tests/test_lua_parity.py guard over every lua pair in the repo: same basename set, unique basenames (dist copies land flat), byte-identical contents. cas.lua had no drift guard before; append.lua's now-redundant one is removed. Also fold the repeated data/meta key joins into helpers on both stores.
58 lines
2.3 KiB
Python
58 lines
2.3 KiB
Python
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
|
|
|
|
import pathlib
|
|
|
|
REPO = pathlib.Path(__file__).resolve().parents[2]
|
|
PY_LUA = sorted((REPO / "python" / "mirage").rglob("*.lua"))
|
|
TS_LUA = sorted(
|
|
(REPO / "typescript" / "packages" / "node" / "src").rglob("*.lua"))
|
|
|
|
|
|
def _by_name(paths: list[pathlib.Path]) -> dict[str, pathlib.Path]:
|
|
return {path.name: path for path in paths}
|
|
|
|
|
|
def test_every_lua_script_exists_in_both_languages():
|
|
"""A server-side script is one wire contract with two copies.
|
|
|
|
Neither language can import the other's file, so each ships its own;
|
|
the pair is what keeps a Redis-side behavior from having two
|
|
meanings. A script added to one tree and forgotten in the other
|
|
fails here rather than at runtime on whichever host is missing it.
|
|
"""
|
|
assert PY_LUA, "no lua scripts found under python/mirage"
|
|
assert sorted(_by_name(PY_LUA)) == sorted(_by_name(TS_LUA))
|
|
|
|
|
|
def test_lua_basenames_are_unique_within_each_tree():
|
|
"""tsup copies each script to a flat `dist/<name>.lua`.
|
|
|
|
Two scripts sharing a basename would silently overwrite each other
|
|
in the bundle, so the name has to be unique even though the source
|
|
directories differ.
|
|
"""
|
|
for tree in (PY_LUA, TS_LUA):
|
|
names = [path.name for path in tree]
|
|
assert len(names) == len(set(names))
|
|
|
|
|
|
def test_each_lua_pair_is_byte_identical():
|
|
"""One wire schema, two copies: the two files must never drift."""
|
|
ts = _by_name(TS_LUA)
|
|
for path in PY_LUA:
|
|
twin = ts[path.name]
|
|
assert path.read_text(encoding="utf-8") == twin.read_text(
|
|
encoding="utf-8"), f"{path.name} differs between python and ts"
|