Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

docs(common): render_criterion's docstring must name the separators it passes

aashish2548fed1e06914c
diff --git a/laya/common.py b/laya/common.py
index 45b5e2a4..65b13e0c 100644
--- a/laya/common.py
+++ b/laya/common.py
@@ -100,8 +100,9 @@ def serialize_state(state: Union[str, dict, list]) -> str:
def render_criterion(value) -> str:
"""Render one criterion value as text.
- Strings pass through; anything structured (dict, list, number) becomes compact JSON, so a
- rubric reads as JSON rather than a Python repr. Without this a dict-valued criterion
+ Strings pass through; anything structured (dict, list, number) becomes a single-line JSON
+ document with the default separators -- ``", "`` between members, ``": "`` before a value --
+ so a rubric reads as JSON rather than a Python repr. Without this a dict-valued criterion
crashed `noul` outright and leaked `{'desc': ...}` into `choice` and `score` prompts.
"""
if isinstance(value, str):
diff --git a/tests/test_criteria.py b/tests/test_criteria.py
index 21ddab5e..0955fd0a 100644
--- a/tests/test_criteria.py
+++ b/tests/test_criteria.py
@@ -606,6 +606,57 @@ for room, kept in [(0, []), (2, ["two", "three"]), (10, ["one", "two", "three"])
[_tok.vocab[w] for w in kept] + [_tok.sep_token_id])
+# --------------------------------------------------------------- render_criterion's separators
+# The docstring claimed structured values become "compact JSON". Compact JSON is
+# separators=(",", ":"); the implementation passes separators=(", ", ": "), the default spelling.
+# The docstring now names the separators, and this gate holds it to the bytes the code emits.
+import ast # noqa: E402
+
+_common_src_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
+ "laya", "common.py")
+with open(_common_src_path) as _common_f:
+ _common_src = _common_f.read()
+_criterion_doc = ""
+for _node in ast.parse(_common_src).body:
+ if isinstance(_node, ast.FunctionDef) and _node.name == "render_criterion":
+ _criterion_doc = ast.get_docstring(_node) or ""
+check_true("criterion/docstring found", len(_criterion_doc) > 0, "no docstring on render_criterion")
+check_true("criterion/docstring drops the compact-JSON claim",
+ "compact" not in _criterion_doc.lower(),
+ "the pre-fix wording is still on the function: %r" % _criterion_doc)
+check_true("criterion/docstring names the member separator",
+ '", "' in _criterion_doc,
+ "the docstring must spell the separator the code passes: %r" % _criterion_doc)
+check_true("criterion/docstring names the key separator",
+ '": "' in _criterion_doc,
+ "the docstring must spell the separator the code passes: %r" % _criterion_doc)
+check_true("criterion/docstring still promises single-line JSON",
+ "single-line JSON" in _criterion_doc,
+ "the one property 'compact' was reaching for must stay stated: %r" % _criterion_doc)
+
+# The implementation's own spelling, read out of the AST rather than retyped here.
+_criterion_sep = None
+for _fn in [n for n in ast.parse(_common_src).body
+ if isinstance(n, ast.FunctionDef) and n.name == "render_criterion"]:
+ for _call in ast.walk(_fn):
+ if isinstance(_call, ast.Call) and getattr(_call.func, "attr", None) == "dumps":
+ for _kw in _call.keywords:
+ if _kw.arg == "separators":
+ _criterion_sep = tuple(ast.literal_eval(_e) for _e in _kw.value.elts)
+check("criterion/code passes the default separators", _criterion_sep, (", ", ": "))
+
+# Live witness: multi-member values carry the space-padded separators, so the docstring's spelling
+# is what the bytes look like -- and a genuinely compact dump would differ.
+_two = render_criterion({"a": 1, "b": 2})
+check("criterion/dict renders default separators", _two, '{"a": 1, "b": 2}')
+check_true("criterion/dict is not compact",
+ _two != json.dumps({"a": 1, "b": 2}, separators=(",", ":")),
+ "the bytes match a compact dump, so the docstring should say compact: %r" % _two)
+check_true("criterion/dict stays on one line", "\n" not in _two, repr(_two))
+check("criterion/list renders default separators", render_criterion(["a", "b", "c"]),
+ '["a", "b", "c"]')
+
+
print("\n%d passed, %d failed" % (len(PASS), len(FAIL)))
for f in FAIL:
print(" FAIL " + f)