Skip to content

fix(laya-ts): match min_confidence bucket-key error text to Python and Java (#1100) - #1106

Merged
NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
bhargavmehta01:fix/ts-min-confidence-key-message
Oct 11, 2026
Merged

NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
bhargavmehta01:fix/ts-min-confidence-key-message

Conversation

@bhargavmehta01

@bhargavmehta01 bhargavmehta01 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What

Aligns the laya-ts bucket-key error text in checkMinConfidenceMap with the reference text in Python (laya/confidence.py) and Java (ConfidenceGate.java):

  • min_confidence map keys must be strings like 'choice:3-5', got ...
  • min_confidence map keys must be a bucket like 'choice:3-5' or 'default', got ...

The test regex in laya-ts/tests/confidence-gating.test.ts is updated and anchored to the full prefix, so the wording is now pinned on the TypeScript side too, the way ConfidenceGateBucketKeyTest.java already pins it for Java.

Why

As described in #1100, the TypeScript message never mentions default, even though the validator accepts it and it decides whether unnamed buckets get gated at all. A caller who hits this error should learn that default is a legal key. This also brings the message prefix (everything up to , got ) to character-for-character parity with Python and Java. The quoted key after it still differs: TypeScript renders got "choice:3_5" where Python and Java render got 'choice:3_5', because pyRepr's string branch uses JSON.stringify.

This PR covers only the wording half of #1100. The pyRepr quote-style question (single vs. double quotes across the 10 repr-bearing messages in common.ts) is a separate decision and is deliberately left alone here.

How it was verified

cd laya-ts
npm ci
npx vitest run tests/confidence-gating.test.ts

Test Files 1 passed (1) | Tests 22 passed (22)

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 (n/a: no docs quote this message)

Fixes #1100

@aashish254

Copy link
Copy Markdown
Contributor

Short answer: the wording change is exactly what #1100 asked for and I'd merge it as-is. One character of the rendered key still differs from Python and Java, and the new regex cannot see it because it stops at got .

I filed #1100, so I checked your build rather than re-deriving it. laya-ts has no node_modules here, so npm test cannot run locally, but Node 24 strips the types on import and src/common.ts only has an import type dependency, so the validator is directly executable:

node --input-type=module -e "import { checkMinConfidenceMap } from '/abs/path/to/common1106.ts'; try { checkMinConfidenceMap({'choice:2-5': 0.5}) } catch (e) { console.log(JSON.stringify(e.message)) }"

(the import path has to be absolute — a relative one resolves against the -e string's cwd and dies with ERR_MODULE_NOT_FOUND before it proves anything).

What that printed, with your line applied to main's common.ts:

  • All 13 keys Python accepts are accepted by your build — the set is laya.confidence.bucket_keys() plus default, i.e. choice|score|noul x 2|3-5|6-10|11+. So the new sentence is true for every key it can name; that was the first thing I wanted to rule out.
  • Your message: min_confidence map keys must be a bucket like 'choice:3-5' or 'default', got "choice:2-5"
  • Python (laya/confidence.py:143, same key): ... or 'default', got 'choice:2-5'
  • Java (ConfidenceGate.java:197) routes the key through PythonJson.repr(String), and json/PythonJson.java:245 picks the single quote the way CPython does, so Java and Python agree with each other and with your wording.

So the divergence left is the quoting of the offending key, and for this message the offending value is always a string, so it appears on every throw. ConfidenceGate.java:194-195 is the reason to care: "Message matched to laya/confidence.py character for character, including the %r spelling of the offending key, because a caller greps for this line."

Your anchored regex /^min_confidence map keys must be a bucket like 'choice:3-5' or 'default', got / matches both spellings, which is why the test can't catch it. The smallest fix is pyRepr's string branch (common.ts:230, currently JSON.stringify(v)) -- the function clearly means to mirror CPython's repr, since common.ts:222-228 already spells True/False/None/nan/inf the Python way, but no test in laya-ts/tests/ pins the text against Python, so nothing enforces the last half of it. Changing pyRepr backs 10 messages in that file, though, so it is a wider decision than this PR and I would not fold it into yours -- better as its own issue if the maintainer wants the grep-exact contract in TypeScript too.

Either way: this is the fix #1100 describes. Flagging the quoting so whoever closes the issue decides deliberately whether it closes on this PR.

@aashish254

Copy link
Copy Markdown
Contributor

Short answer: this is exactly the wording half of #1100 and it is correct — I ran your head against the suite and against two mutants, and laya-java's reference really does now match character-for-character. One thing your description overstates, and it is in the half #1100 deliberately left alone.

What I measured on your head c5b4fa7f:

  • The replacement string is byte-identical to Python once you join the two literals at laya/confidence.py:143-144. Executed, not read: check_min_confidence_map({'choice:3_5': 0.5}) raises min_confidence map keys must be a bucket like 'choice:3-5' or 'default', got 'choice:3_5', and yours emits the same prefix.
  • Suite: npm test -- --run in laya-ts and npm run test:package — the two run: steps the TypeScript (node${{ matrix.node }}) lane actually executes (.github/workflows/ci.yml:26 and :28, working-directory: laya-ts) — both pass on your head: rc=0 with 34 files / 654 tests, plus the packed e2e (✔ the packed module installs and works in an external ESM TypeScript project, 1 pass / 0 fail). tsc --noEmit is the first half of npm test, so the type check is clean on my Node v24.21.0. Main's own copy of the suite is also 34 / 654 — your diff edits one assertion rather than adding one, so the equal count is the expected result, not a sign the test didn't change.
  • Your two edits each carry their own weight, checked by mutation. Message reverted, new regex kept -> 1 failed | 21 passed. Regex reverted, new message kept -> 1 failed | 21 passed. Neither edit is decoration.
  • default really is a legal key in your validator (key !== "default" && !BUCKET_KEY.test(key)), which is the whole point of [bug]: laya-ts's min_confidence error text diverges from the Python/Java reference the repo pins #1100 — the caller who files a threshold under choice:99 believes they gated something and gated nothing, and the old text never told them default exists.

The overstatement: "character-for-character parity on this line" holds for the prefix, but not for the whole line. Your , got ${pyRepr(key)} renders a bad key as "choice:3_5" — pyRepr's string branch is JSON.stringify, which always double-quotes. Measured side by side, same key:

python  ... or 'default', got 'choice:3_5'        (executed)
ts      ... or 'default', got "choice:3_5"        (executed)
java    ConfidenceGateBucketKeyTest.java:34-35 asserts "got '" + key + "'", i.e. single quotes
        (I read this assertion and the `PythonJson.repr(String)` it tests at :241-247 — first
        quote is `'` unless the value contains one and no `"`. I did not run the Java suite.)

So Python and Java agree on the quoting and TypeScript is the odd one out — that is #1100's second half, which you correctly scoped out (it is a pyRepr decision touching every repr-bearing message in src/common.ts — 10 of them by grep -n 'Error(' | grep pyRepr— not a one-line fix). ButConfidenceGateBucketKeyTest.java:34pins its *entire* message including the quoted offender, while your regex stops at, got ` — so the tails are pinned on one side of the comparison and nowhere on the other.

Witness that this is live rather than theoretical: I replaced pyRepr's string branch with Python's style (return "'" + v + "'", src/common.ts:230, verified as the only line in the diff), which changes all ten repr-bearing messages to match CPython, and got 34 files / 654 tests passed — the suite cannot see it. Before you touch it, note that #1100's deconfliction still holds for that region: #340's hunks in laya-ts/src/common.ts are @@ -58, @@ -118, @@ -140, and pyRepr sits at 221-239 on main, so nobody is editing those lines. If you want to claim full parity in the description, the version that closes it without a pyRepr decision is to extend your regex past , got and assert the single-quoted key, the way the Java test does.

No action needed on the wording half either way — it is done and it is good. Also FYI: your head has 0 check runs attached (gh api .../commits/c5b4fa7f/check-runs returns n=0), so nothing above came from CI; it is a local npm ci from your lockfile. For the record, I am not opening my own branch for #1100, so this stays yours.

@bhargavmehta01

Copy link
Copy Markdown
Contributor Author

Thanks @aashish254, that's a really thorough check, and the mutation runs are a nice touch.

You're right that "character-for-character parity" overstates it. The prefix through , got now matches Python and Java, but the offending key is still rendered "choice:3_5" instead of 'choice:3_5', because pyRepr's string branch uses JSON.stringify. I've corrected the description to say so.

I'll leave the pyRepr quoting out of this PR, since it touches all ten repr-bearing messages in common.ts. Happy to open a follow-up that switches the string branch to CPython-style quoting and pins the full message in the tests, the way ConfidenceGateBucketKeyTest.java does, if @NandhaKishorM wants that contract in TypeScript too.

@NandhaKishorM
NandhaKishorM merged commit d0fe9a8 into NandhaKishorM:main Oct 11, 2026
@NandhaKishorM

Copy link
Copy Markdown
Owner

Merged in 0.4.3, and closing #1100 with it.

Two lines, and the reason they matter is in the error's job: it is what a caller reads when they have got the bucket key wrong, and it listed one legal shape while omitting the one that decides whether unnamed buckets get gated at all. A caller told that keys must look like choice:3-5 has no way to learn from that message that default exists.

Anchoring the test regex to the full prefix rather than matching a fragment is the part that makes this stick, and it brings TypeScript in line with how ConfidenceGateBucketKeyTest.java already pins the Java wording. Three implementations with one error text is only true if all three pin it.

Verified on the merged tree: laya-ts runs 870 tests across 35 files with your updated regex, npx tsc --noEmit is clean, and the text now matches laya/confidence.py and ConfidenceGate.java character for character.

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.

[bug]: laya-ts's min_confidence error text diverges from the Python/Java reference the repo pins

3 participants