feat(lookup): 用户前缀查找放宽至单字符——中文姓氏单字搜索(全链路)
契约 minLength 2→1 + 服务端 bounds 1..64 + admin 两处/App 一处前端门槛 同步放宽;防抖测试基线更新('s' 与合并后 'sta' 共两条)。 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -37,12 +37,13 @@ import { UsersLookupService, type AdminUserListResponse } from './users-lookup.s
|
||||
export const DEFAULT_LIST_LIMIT = 20;
|
||||
export const MAX_LIST_LIMIT = 100;
|
||||
|
||||
/** accountPrefix 查询参数(前缀模式):2..64(契约 bounds)。 */
|
||||
/** accountPrefix 查询参数(前缀模式):1..64(契约 bounds;2026-09-29 自 2
|
||||
* 放宽——中文姓氏单字搜索合理,用户拍板)。 */
|
||||
export function parseAccountPrefix(raw: string | undefined): string {
|
||||
// 双模式收口后 undefined 不再到达此函数(分流在 listAdminUsers);防御性
|
||||
// 保留同一校验出口。空串/1 字符/超长 → 400。
|
||||
if (raw === undefined || raw.length < 2 || raw.length > 64) {
|
||||
throw validationFailed('accountPrefix 须为 2-64 字符');
|
||||
// 保留同一校验出口。空串/超长 → 400;单字符合法。
|
||||
if (raw === undefined || raw.length < 1 || raw.length > 64) {
|
||||
throw validationFailed('accountPrefix 须为 1-64 字符');
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
|
||||
@@ -258,9 +258,17 @@ describe('账号查询 GET /admin/users (e2e)', () => {
|
||||
expect(empty.status).toBe(400);
|
||||
expect(empty.body.code).toBe(ErrorCodes.VALIDATION_FAILED);
|
||||
|
||||
const short = await lookup(staffToken, { accountPrefix: 'a' });
|
||||
expect(short.status).toBe(400);
|
||||
expect(short.body.code).toBe(ErrorCodes.VALIDATION_FAILED);
|
||||
// 单字符已合法(2026-09-29 自 2 放宽——中文姓氏单字搜索):'a' 命中
|
||||
// alice/albert(displayName 前缀并入后 '爱' 亦单字可用)。
|
||||
const single = await lookup(staffToken, { accountPrefix: 'a' });
|
||||
expect(single.status).toBe(200);
|
||||
expect(single.body.items.map((i: { account: string }) => i.account)).toEqual([
|
||||
'albert',
|
||||
'alice',
|
||||
]);
|
||||
const singleName = await lookup(staffToken, { accountPrefix: '爱' });
|
||||
expect(singleName.status).toBe(200);
|
||||
expect(singleName.body.items).toHaveLength(1);
|
||||
|
||||
const long = await lookup(staffToken, { accountPrefix: 'a'.repeat(65) });
|
||||
expect(long.status).toBe(400);
|
||||
|
||||
Reference in New Issue
Block a user