턴 대상의 원본 이름과 누락값 표시를 분리해 검색 정확도 개선

This commit is contained in:
2026-09-14 14:24:59 +00:00
parent 8760eab1a9
commit 7522f5100e
11 changed files with 220 additions and 29 deletions
@@ -0,0 +1,29 @@
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { commandTargetDescription } from '../src/utils/commandTargetDescription.ts';
void test('nullable troop names receive display-only fallbacks and preserve leader and member information', () => {
const base = { value: 1, label: '관우', description: '금 100', targetNames: { name: '관우', troopName: null } };
assert.equal(commandTargetDescription('che_증여', base), '금 100 · 탑승 부대 없음');
assert.equal(commandTargetDescription('che_발령', base), '탑승 부대 없음\n금 100');
assert.equal(commandTargetDescription('che_포상', base), '금 100');
assert.equal(commandTargetDescription('che_몰수', base), '금 100');
assert.equal(commandTargetDescription('che_증여', { ...base, troopId: 99 }), '금 100 · 탑승 부대 #99');
assert.equal(
commandTargetDescription('che_증여', {
...base,
troopId: 1,
targetNames: { name: '관우', troopName: '청룡대' },
}),
'금 100 · 탑승 부대 청룡대 (부대장)'
);
assert.equal(
commandTargetDescription('che_증여', {
...base,
targetNames: undefined,
description: '금 100 · 탑승 부대 없음',
}),
'금 100 · 탑승 부대 없음'
);
assert.equal(commandTargetDescription('che_증여'), '');
});
@@ -1,6 +1,10 @@
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { buildCommandTargetSearchIndex, matchesCommandTargetSearch } from '../src/utils/commandTargetSearch.ts';
import {
buildCommandTargetSearchIndex,
buildCommandOptionSearchIndex,
matchesCommandTargetSearch,
} from '../src/utils/commandTargetSearch.ts';
void test('Ref name index includes keyboard initials and both IME compound levels', () => {
assert.deepEqual(buildCommandTargetSearchIndex('강서'), ['강서', 'rt', 'ㄱㅅ', 'ㄳ']);
@@ -19,3 +23,34 @@ void test('literal, initial, keyboard and normalized queries preserve meaningful
assert.equal(matchesCommandTargetSearch(buildCommandTargetSearchIndex('쌍성'), 'ㅆㅅ'), true);
assert.equal(matchesCommandTargetSearch(buildCommandTargetSearchIndex('쌍성'), 'ㅅㅅ'), false);
});
void test('explicit names exclude descriptive copy and placeholders without blacklisting genuine names', () => {
const option = {
label: '관우 (무소속 · 재야)',
targetNames: { name: '관우', troopName: '청룡대', nationName: null, cityName: null },
description: '탑승 부대 없음 · 현재 불가 · 금 100',
};
const index = buildCommandOptionSearchIndex(option);
for (const query of ['ㅇㅇ', '없음', '무소속', '재야', '현재', '100'])
assert.equal(matchesCommandTargetSearch(index, query), false, query);
for (const query of ['관우', 'ㄱㅇ', '청룡대', 'ㅊㄹㄷ'])
assert.equal(matchesCommandTargetSearch(index, query), true, query);
assert.equal(
matchesCommandTargetSearch(
buildCommandOptionSearchIndex({ label: '별명', targetNames: { name: '없음', troopName: null } }),
'ㅇㅇ'
),
true
);
assert.equal(
matchesCommandTargetSearch(
buildCommandOptionSearchIndex({ label: '관우', ...{ description: '부대 없음' } }),
'ㅇㅇ'
),
false
);
assert.deepEqual(
buildCommandOptionSearchIndex({ label: '누락 안내', targetNames: { name: '', troopName: null } }),
[]
);
});