Skip to content

docs(lang): say that mixed_segment is filled only by the segment scan - #1123

Merged
NandhaKishorM merged 2 commits into
NandhaKishorM:mainfrom
aashish254:fix-mixed-segment-leaf-pass
Oct 12, 2026
Merged

NandhaKishorM merged 2 commits into
NandhaKishorM:mainfrom
aashish254:fix-mixed-segment-leaf-pass

Conversation

@aashish254

Copy link
Copy Markdown
Contributor

What

analyse() advertises mixed_segment as "the line or field that made a mostly English state
non-English, else None", but two different reads can flip a state non-English and only one of them
reports which line it was. This says so in the docstring and leaves three checks at that seam.
laya/lang.py moves by 4 added / 2 removed lines of docstring and nothing else; no behaviour changes
and no prediction differs.

Why

So a foreign field sitting past the scan's cumulative 4,000-character budget is named by language and
reported with mixed_segment still None. A caller cannot tell the two provenances apart from the
result, and the docstring described only one of them. The fix is prose plus a test that makes the
difference visible; changing the behaviour instead would invent a second meaning for a field the router's
reason string already reads.

How it was verified

python tests/test_router.py
python scripts/test_suites.py
ruff check laya/ --select=E9,F63,F7,F82,F401,F811 --line-length=120
python -m compileall -q laya/ tests/
  • tests/test_router.py on main at c4a805b5: 804 passed, 0 failed. On this branch:
    807 passed, 0 failed.
  • scripts/test_suites.py on this branch: 497 passed, 1 skipped -- all 87 suites passed, rc=0.
  • ruff: All checks passed!, rc=0. compileall: rc=0.

Mutation witness. Replacing the scan's cumulative budget with a per-leaf one -- if seen >= max_chars: return None at laya/lang.py:655-656 to if False: and the slice at :657 to seg = seg[:max_chars] --
turns three checks red:

804 passed, 3 failed
  FAIL mixed/segment budget exhausted before the foreign field: got ('de', 'WIE SPAET IST ES IN KOELN HEUTE ABEND'), want None
  FAIL mixed/and leaves mixed_segment None:                   got 'WIE SPAET IST ES IN KOELN HEUTE ABEND', want None
  FAIL mixed/segment check reads at most the cap:             got 'Quero cancelar meu plano agora mesmo', want None

mixed/segment check reads at most the cap is main's own check, so I ran main's tests/test_router.py
against the same mutant: 803 passed, 1 failed -- only the cap check. The two mixed_segment checks
above are therefore net-new witnesses, not a restatement of an existing one. The converse detail is worth
noting: mutating only the slice line, leaving the stop, keeps the branch green at 807, because with a
5,000-character first field the stop is what ends the scan. Both lines have to move for the budget to
become per-leaf.

The middle check's label was proved, not assumed. It claims the per-value read is what names the
language. Printed from the branch for {"note": <5,000 English chars>, "body": <German line>}:
state_text(state) returns exactly 4000 characters and does not contain the German body at all;
_analyse_text on it gives language 'en', is_english True; _leaf_non_english(body) gives
language 'de'; _non_english_segment(state) gives None; analyse(state) gives
language 'de', is_english False, mixed_segment None. The per-value read is the only one that saw the
field, which is the case the docstring now names.

Deconfliction. Four open PRs touch these two files: #1089 (tests/test_router.py -562,7), #600
(laya/lang.py up to -587,11, tests/test_router.py -572,16), #286 (laya/lang.py up to -587,9),
and #91 (laya/lang.py up to -164,18, tests/test_router.py up to -219,7). My hunks are
laya/lang.py @@ -809,8, tests/test_router.py @@ -9,6 and @@ -532,6, and the block is placed before
#1089's region rather than inside it. Rebased on c4a805b5, on which neither file has changed since
68804629. The diff was scanned for credentials and for absolute local paths: no matches (rc=1 from the
pattern scan).

Checklist

  • Focused on one change (split unrelated work into another PR)
  • Rebased on the latest main
  • Tests pass locally
  • Docs or examples updated when the public API changed

Fixes: no open issue. Found while reading analyse's docstring against the two reads it describes. The
public API does not change, so no docs/ page needed editing.

analyse() documents mixed_segment as "the line or field that made a mostly English
state non-English", but the per-value read added for NandhaKishorM#384 sets language and
is_english from a local and never writes the value back, so a state flipped
non-English past the 4,000-character segment cap reports mixed_segment None while
still naming the language. The docstring now states which of the two reads is
reporting, since no caller can tell the provenances apart from the result alone.
Three checks at the seam: _non_english_segment returns None once a long English
first field has spent the cumulative 4,000-character budget, _leaf_non_english
still names the foreign field's language, and analyse reports it with
mixed_segment None. Mutating the cumulative guard (laya/lang.py:655-657) to a
per-leaf budget turns both new mixed_segment checks red; running main's suite
under the same mutant fails only its own cap check, so these two are the net-new
witnesses. tests/test_router.py goes 804 -> 807 checks.
@NandhaKishorM
NandhaKishorM merged commit f67db0b into NandhaKishorM:main Oct 12, 2026
40 checks passed
@NandhaKishorM

Copy link
Copy Markdown
Owner

Merged. The distinction is real and invisible from the outside: analyse can report language: 'de' with mixed_segment: None, because the per-value read that caught it keeps the offending leaf in a local and never writes it back, while only the segment scan fills the field.

The test earns its place by constructing the budget exhaustion rather than asserting the current behaviour: 5,000 English characters in the first leaf spend _non_english_segment's 4,000-character budget before it reaches the German one, so the scan returns None and the leaf-level read is what names de. That is the #384 path, and no caller can tell the two provenances apart from the result alone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants