feat(robot): per-game display names from a wide name corpus
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 15s
CI / ui (pull_request) Successful in 48s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m10s
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 15s
CI / ui (pull_request) Successful in 48s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m10s
Decouple the displayed opponent name from the small pool of durable robot accounts: the disguised auto-match robot now gets a freshly composed name each game, stamped on a new game_players.display_name seat snapshot. The snapshot also captures humans' names, freezing what an opponent sees for the life of a game (a later rename no longer rewrites past games); readers fall back to the account's current name for pre-migration rows. Names come from a wide composed corpus (internal/robot/namevariety.go): Western locales (EN/DE/ES/IT/FR/PT), native Japanese/Chinese names, a gender-agreed Russian pool, and human-style handles. Routing keeps Pick's spirit -- a Russian game draws Cyrillic + <=20% Latin and never a CJK script; an English game the full corpus -- via robot.PickNamed. Loosen account.ValidateDisplayName (and the UI mirror) to admit a trailing run of up to five digits, so "Player2007"-style handles are valid for humans too and the disguised robot stays indistinguishable. Migration 00007 adds game_players.display_name (additive, NOT NULL DEFAULT ''); jet regenerated. Docs (ARCHITECTURE 7, FUNCTIONAL + _ru, PLAN, README) updated.
This commit is contained in:
@@ -16,7 +16,16 @@ describe('validDisplayName', () => {
|
||||
['Name.', true],
|
||||
['Name..', false],
|
||||
['Name_', false],
|
||||
['Name2', false],
|
||||
['Name2', true], // a trailing digit is allowed
|
||||
['Аня2007', true], // a trailing year
|
||||
['Player12345', true], // 5 trailing digits — the max
|
||||
['Player123456', false], // 6 trailing digits — over the limit
|
||||
['Dark2Wolf', false], // a digit in the middle
|
||||
['12345', false], // must start with a letter
|
||||
['Name2.', false], // digits and a trailing dot cannot combine
|
||||
['Anna B.2', false], // a trailing dot and digits cannot combine
|
||||
['Night.Fox2007', true], // one "." special; digits do not count
|
||||
['a.a.a.a.a.a2007', true], // 5 dots + a digit run still passes
|
||||
['', false],
|
||||
['a'.repeat(33), false],
|
||||
['a.a.a.a.a.a', true], // 5 dots — at the special-char limit
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
/** maxDisplayName caps the editable display name in runes. */
|
||||
export const maxDisplayName = 32;
|
||||
|
||||
/** maxDisplayNameSpecials caps the total special characters (the "." / "_" separators — every
|
||||
* rune that is neither a letter nor a space) a display name may carry. Mirrors the Go rule. */
|
||||
/** maxDisplayNameSpecials caps the total special characters (every rune that is neither a
|
||||
* letter, a space, nor a digit — i.e. the "." / "_" separators) a display name may carry.
|
||||
* A trailing digit run is bounded separately by displayNameRe. Mirrors the Go rule. */
|
||||
export const maxDisplayNameSpecials = 5;
|
||||
|
||||
/** maxAwayMinutes bounds the daily away window's length (12 h). */
|
||||
@@ -14,16 +15,17 @@ export const maxAwayMinutes = 12 * 60;
|
||||
|
||||
// Unicode letters joined by single space / "." / "_" separators, where a "." or "_"
|
||||
// may be followed by a single space. No leading separator and no adjacent separators
|
||||
// except "<dot|underscore> <space>"; a single trailing "." is allowed. Same
|
||||
// rule as the Go displayNameRe.
|
||||
const displayNameRe = /^\p{L}+(?:(?:[._] ?| )\p{L}+)*\.?$/u;
|
||||
// except "<dot|underscore> <space>". The name may end with EITHER a single trailing "."
|
||||
// (an initial) OR a run of 1–5 digits (a number or year), but not both; digits never
|
||||
// appear elsewhere. Same rule as the Go displayNameRe.
|
||||
const displayNameRe = /^\p{L}+(?:(?:[._] ?| )\p{L}+)*(?:\.|[0-9]{1,5})?$/u;
|
||||
|
||||
/** displayNameError returns true when the trimmed name is a valid display name. */
|
||||
export function validDisplayName(raw: string): boolean {
|
||||
const name = raw.trim();
|
||||
const chars = [...name];
|
||||
if (name.length === 0 || chars.length > maxDisplayName || !displayNameRe.test(name)) return false;
|
||||
const specials = chars.filter((c) => c !== ' ' && !/\p{L}/u.test(c)).length;
|
||||
const specials = chars.filter((c) => c !== ' ' && !/\p{L}/u.test(c) && !/[0-9]/.test(c)).length;
|
||||
return specials <= maxDisplayNameSpecials;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user