feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes
This commit is contained in:
parent
01ef3293cf
commit
66b6b45ba9
399 changed files with 17828 additions and 11330 deletions
|
|
@ -6,9 +6,12 @@ import {
|
|||
applySpeakerLabels,
|
||||
buildTranscriptFromSegments,
|
||||
chunkTranscriptByLines,
|
||||
extractDistinctSpeakers,
|
||||
formatPyannoteSpeakerLabel,
|
||||
formatTranscriptLines,
|
||||
looksTruncatedRewrite,
|
||||
parseTranscriptLines,
|
||||
resolveSpeakerColorIndex,
|
||||
} from '../src/meeting-transcript'
|
||||
|
||||
const START = 1_790_000_000_000 // epoch ms
|
||||
|
|
@ -101,3 +104,36 @@ describe('chunkTranscriptByLines / looksTruncatedRewrite', () => {
|
|||
expect(looksTruncatedRewrite('시각 없는 아주 긴 문장입니다 정말로', '시각')).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('화자 라벨 정규화·색상 인덱스·목록 추출', () => {
|
||||
it('화자변환_pyannote원시ID입력_1기반표시라벨로바꾼다', () => {
|
||||
expect(formatPyannoteSpeakerLabel('SPEAKER_00')).toBe('화자 1')
|
||||
expect(formatPyannoteSpeakerLabel('SPEAKER_01')).toBe('화자 2')
|
||||
expect(formatPyannoteSpeakerLabel('SPEAKER_09', 'Speaker')).toBe('Speaker 10')
|
||||
expect(formatPyannoteSpeakerLabel('윤찬')).toBe('윤찬')
|
||||
})
|
||||
|
||||
it('색상인덱스_번호기반및이름기반화자_일관된팔레트인덱스를반환한다', () => {
|
||||
expect(resolveSpeakerColorIndex('화자 1', 5)).toBe(0)
|
||||
expect(resolveSpeakerColorIndex('Speaker 2', 5)).toBe(1)
|
||||
expect(resolveSpeakerColorIndex('SPEAKER_00', 5)).toBe(0)
|
||||
expect(resolveSpeakerColorIndex('SPEAKER_01', 5)).toBe(1)
|
||||
expect(resolveSpeakerColorIndex('화자 6', 5)).toBe(0)
|
||||
const customIdx = resolveSpeakerColorIndex('김민수', 5)
|
||||
expect(customIdx).toBeGreaterThanOrEqual(0)
|
||||
expect(customIdx).toBeLessThan(5)
|
||||
expect(resolveSpeakerColorIndex('김민수', 5)).toBe(customIdx)
|
||||
})
|
||||
|
||||
it('화자목록_전사세그먼트배열_첫등장순서로중복없이추출한다', () => {
|
||||
expect(
|
||||
extractDistinctSpeakers([
|
||||
{ speaker: null },
|
||||
{ speaker: '화자 2' },
|
||||
{ speaker: ' ' },
|
||||
{ speaker: '화자 1' },
|
||||
{ speaker: '화자 2' },
|
||||
]),
|
||||
).toEqual(['화자 2', '화자 1'])
|
||||
})
|
||||
})
|
||||
|
|
|
|||
66
packages/core/__tests__/pii-redactor.test.ts
Normal file
66
packages/core/__tests__/pii-redactor.test.ts
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
redactPII,
|
||||
redactPIIMessages,
|
||||
rehydrateText,
|
||||
} from '../src/utils/pii-redactor'
|
||||
|
||||
describe('PII Redactor 및 Rehydrate 경계 조건', () => {
|
||||
it('redactPII_원문에기존토큰문자열포함시_충돌없이유니크토큰을할당하고원본을복원한다', () => {
|
||||
const input = '리터럴 [REDACTED_EMAIL_1] 과 실제 이메일 alice@example.com'
|
||||
const result = redactPII(input, 'tokenize')
|
||||
|
||||
expect(result.redactionCount).toBe(1)
|
||||
expect(result.redactedText).toBe('리터럴 [REDACTED_EMAIL_1] 과 실제 이메일 [REDACTED_EMAIL_2]')
|
||||
expect(result.tokens.get('[REDACTED_EMAIL_1]')).toBe(undefined)
|
||||
expect(result.tokens.get('[REDACTED_EMAIL_2]')).toBe('alice@example.com')
|
||||
expect(rehydrateText(result.redactedText, result.tokens)).toBe(input)
|
||||
})
|
||||
|
||||
it('redactPIIMessages_메시지배열내기존토큰포함시_충돌을피해고유플레이스홀더를생성한다', () => {
|
||||
const messages = [
|
||||
{ role: 'user', content: '이전 토큰 [REDACTED_PHONE_NUMBER_1] 유지' },
|
||||
{ role: 'assistant', content: '새 번호 010-1234-5678 안내' },
|
||||
]
|
||||
const result = redactPIIMessages(messages)
|
||||
|
||||
expect(result.redactionCount).toBe(1)
|
||||
expect(result.messages[0]?.content).toBe('이전 토큰 [REDACTED_PHONE_NUMBER_1] 유지')
|
||||
expect(result.messages[1]?.content).toBe('새 번호 [REDACTED_PHONE_NUMBER_2] 안내')
|
||||
expect(rehydrateText(result.messages[0]!.content, result.tokens)).toBe(
|
||||
'이전 토큰 [REDACTED_PHONE_NUMBER_1] 유지',
|
||||
)
|
||||
expect(rehydrateText(result.messages[1]!.content, result.tokens)).toBe(
|
||||
'새 번호 010-1234-5678 안내',
|
||||
)
|
||||
})
|
||||
|
||||
it('rehydrateText_복원값안에다른플레이스홀더가포함되어도_단일패스로치환해이중복원하지않는다', () => {
|
||||
const tokens = new Map<string, string>([
|
||||
['[REDACTED_EMAIL_1]', 'user+[REDACTED_PHONE_NUMBER_2]@example.com'],
|
||||
['[REDACTED_PHONE_NUMBER_2]', '010-9999-8888'],
|
||||
])
|
||||
|
||||
const restored = rehydrateText('결과: [REDACTED_EMAIL_1] / [REDACTED_PHONE_NUMBER_2]', tokens)
|
||||
expect(restored).toBe('결과: user+[REDACTED_PHONE_NUMBER_2]@example.com / 010-9999-8888')
|
||||
})
|
||||
|
||||
it('rehydrateText_정규식메타문자키가포함돼도_안전하게치환한다', () => {
|
||||
const tokens = new Map<string, string>([
|
||||
['[REDACTED_A.B+1]', 'real-value'],
|
||||
])
|
||||
expect(rehydrateText('값=[REDACTED_A.B+1] 끝=[REDACTED_AXB]', tokens)).toBe(
|
||||
'값=real-value 끝=[REDACTED_AXB]',
|
||||
)
|
||||
})
|
||||
|
||||
it('redactPII_mask모드_반복호출해도lastIndex오염없이모든민감정보를마스킹한다', () => {
|
||||
const first = redactPII('번호 010-1111-2222 / 이메일 dev@d3ro.ai', 'mask')
|
||||
const second = redactPII('번호 010-3333-4444 / 카드 1234-5678-9012-3456', 'mask')
|
||||
|
||||
expect(first.redactedText).toBe('번호 010-****-2222 / 이메일 de***@d3ro.ai')
|
||||
expect(first.matchedCategories).toEqual(['전화번호', '이메일'])
|
||||
expect(second.redactedText).toBe('번호 010-****-4444 / 카드 1234-****-****-3456')
|
||||
expect(second.redactionCount).toBe(2)
|
||||
})
|
||||
})
|
||||
45
packages/core/__tests__/ports.test.ts
Normal file
45
packages/core/__tests__/ports.test.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
createFakeClock,
|
||||
createSeededRandom,
|
||||
systemClock,
|
||||
systemRandom
|
||||
} from '../src/ports'
|
||||
|
||||
describe('결정성 포트 Clock / Random (TDD v2.0 Phase 4)', () => {
|
||||
it('FakeClock_초기시각고정및advance호출_정확한밀리초만큼만전진한다', () => {
|
||||
const clock = createFakeClock(1_700_000_000_000)
|
||||
expect(clock.now()).toBe(1_700_000_000_000)
|
||||
expect(clock.advance(250)).toBe(1_700_000_000_250)
|
||||
expect(clock.now()).toBe(1_700_000_000_250)
|
||||
clock.set(1_700_000_010_000)
|
||||
expect(clock.now()).toBe(1_700_000_010_000)
|
||||
})
|
||||
|
||||
it('SeededRandom_동일시드생성시_동일한난수열과RFC4122v4형식UUID를재현한다', () => {
|
||||
const left = createSeededRandom(42)
|
||||
const right = createSeededRandom(42)
|
||||
|
||||
const seqLeft = [left.next(), left.next(), left.next()]
|
||||
const seqRight = [right.next(), right.next(), right.next()]
|
||||
expect(seqLeft).toEqual(seqRight)
|
||||
for (const sample of seqLeft) {
|
||||
expect(sample).toBeGreaterThanOrEqual(0)
|
||||
expect(sample).toBeLessThan(1)
|
||||
}
|
||||
|
||||
const uuidLeft = left.uuid()
|
||||
const uuidRight = right.uuid()
|
||||
expect(uuidLeft).toBe(uuidRight)
|
||||
expect(uuidLeft).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/)
|
||||
})
|
||||
|
||||
it('시스템기본포트_실행시유효한양수정수시각과표준UUID를반환한다', () => {
|
||||
const t = systemClock.now()
|
||||
expect(Number.isSafeInteger(t)).toBe(true)
|
||||
expect(t).toBeGreaterThan(1_600_000_000_000)
|
||||
|
||||
const u = systemRandom.uuid()
|
||||
expect(u).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/)
|
||||
})
|
||||
})
|
||||
123
packages/core/__tests__/shared-utilities.test.ts
Normal file
123
packages/core/__tests__/shared-utilities.test.ts
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
escapeLikePattern,
|
||||
escapePostgrestLikePattern,
|
||||
isRecord,
|
||||
isUuid,
|
||||
} from '../src/guards'
|
||||
import { csvCell, parseCsvRows } from '../src/csv'
|
||||
import {
|
||||
formatBytes,
|
||||
formatDurationClockFromMs,
|
||||
formatDurationClockFromSeconds,
|
||||
} from '../src/format'
|
||||
import {
|
||||
createUnifiedSearchExcerpt,
|
||||
includesSearchQuery,
|
||||
mergeUnifiedSearchResults,
|
||||
} from '../src/unified-search'
|
||||
import {
|
||||
ADMIN_ROLE_RANK,
|
||||
hasMinimumAdminRole,
|
||||
normalizeAdminRoleAlias,
|
||||
} from '../src/admin-roles'
|
||||
import { formatTranscriptTimestamp } from '../src/meeting-transcript'
|
||||
import { formatDateFile, formatDateRange, formatTime } from '../src/utils/meeting-markdown'
|
||||
|
||||
describe('코어 공용 유틸리티 계약 (W5-05~07)', () => {
|
||||
it('isRecord_객체와비객체구분_일반객체만참을반환한다', () => {
|
||||
expect(isRecord({ a: 1 })).toBe(true)
|
||||
expect(isRecord(null)).toBe(false)
|
||||
expect(isRecord(undefined)).toBe(false)
|
||||
expect(isRecord([1, 2])).toBe(false)
|
||||
expect(isRecord('text')).toBe(false)
|
||||
})
|
||||
|
||||
it('isUuid_유효한UUID와비정상문자열_표준RFC4122형식만참을반환한다', () => {
|
||||
expect(isUuid('550e8400-e29b-41d4-a716-446655440000')).toBe(true)
|
||||
expect(isUuid('00000000-0000-0000-0000-000000000000')).toBe(false)
|
||||
expect(isUuid('not-a-uuid')).toBe(false)
|
||||
expect(isUuid(123)).toBe(false)
|
||||
})
|
||||
|
||||
it('escapeLikePattern_와일드카드포함검색어_퍼센트와언더스코어를이스케이프한다', () => {
|
||||
expect(escapeLikePattern('100%_test\\ok')).toBe('100\\%\\_test\\\\ok')
|
||||
expect(escapePostgrestLikePattern('100%_*ok')).toBe('*100\\%\\_\\*ok*')
|
||||
})
|
||||
|
||||
it('csvCell과parseCsvRows_수식주입과줄바꿈포함_안전하게직렬화하고복원한다', () => {
|
||||
expect(csvCell('=CMD()')).toBe('"=CMD()"')
|
||||
expect(csvCell('hello, "world"')).toBe('"hello, ""world"""')
|
||||
const csv = `${csvCell('word')},${csvCell('pronunciation')}\r\n${csvCell('D3RO')},${csvCell('디에로, "보이스"')}\r\n`
|
||||
expect(parseCsvRows(csv)).toEqual([
|
||||
['word', 'pronunciation'],
|
||||
['D3RO', '디에로, "보이스"'],
|
||||
])
|
||||
})
|
||||
|
||||
it('formatDurationClock_밀리초와초입력_시분초규칙에맞게포맷한다', () => {
|
||||
expect(formatDurationClockFromMs(65_000)).toBe('1:05')
|
||||
expect(formatDurationClockFromMs(5_000, { padMinutes: true })).toBe('00:05')
|
||||
expect(formatDurationClockFromSeconds(3_665, { showHours: true })).toBe('1:01:05')
|
||||
expect(formatDurationClockFromSeconds(125, { showHours: true })).toBe('2:05')
|
||||
expect(formatBytes(1536)).toBe('1.5 KB')
|
||||
})
|
||||
|
||||
it('unifiedSearch_발췌및병합_검색어주변문맥을추출하고최신순정렬한다', () => {
|
||||
expect(includesSearchQuery('Hello D3RO World', 'd3ro')).toBe(true)
|
||||
const excerpt = createUnifiedSearchExcerpt(
|
||||
`${'앞문장 '.repeat(30)}핵심키워드 등장 구간${' 뒷문장'.repeat(30)}`,
|
||||
'핵심키워드',
|
||||
60,
|
||||
)
|
||||
expect(excerpt).toContain('핵심키워드')
|
||||
expect(excerpt.startsWith('…')).toBe(true)
|
||||
|
||||
const merged = mergeUnifiedSearchResults(
|
||||
[{ source: 'record', id: 'b', title: 'R', excerpt: 'r', matchedField: 'title', occurredAt: 100 }],
|
||||
[{ source: 'meeting', id: 'a', title: 'M', excerpt: 'm', matchedField: 'title', occurredAt: 200 }],
|
||||
10,
|
||||
)
|
||||
expect(merged.map((item) => item.id)).toEqual(['a', 'b'])
|
||||
})
|
||||
|
||||
it('adminRoles_권한계층비교_super_admin별칭과최소권한순서를일관되게판정한다', () => {
|
||||
expect(normalizeAdminRoleAlias('super_admin')).toBe('super_admin')
|
||||
expect(normalizeAdminRoleAlias('superadmin')).toBe('super_admin')
|
||||
expect(ADMIN_ROLE_RANK.manager).toBeLessThan(ADMIN_ROLE_RANK.admin)
|
||||
expect(ADMIN_ROLE_RANK.admin).toBeLessThan(ADMIN_ROLE_RANK.super_admin)
|
||||
expect(hasMinimumAdminRole('admin', 'manager')).toBe(true)
|
||||
expect(hasMinimumAdminRole('manager', 'admin')).toBe(false)
|
||||
expect(hasMinimumAdminRole('superadmin', 'super_admin')).toBe(true)
|
||||
})
|
||||
|
||||
it('parseCsvRows_단독CR줄바꿈과BOM포함입력_행으로정확히분리한다', () => {
|
||||
expect(parseCsvRows('\uFEFFword,note\rD3RO,"line1\r\nline2"')).toEqual([
|
||||
['word', 'note'],
|
||||
['D3RO', 'line1\r\nline2'],
|
||||
])
|
||||
})
|
||||
|
||||
it('unifiedSearch_비정상limit와maxLength입력_음수slice나예외없이안전하게동작한다', () => {
|
||||
expect(createUnifiedSearchExcerpt('긴 본문 텍스트', '본문', 0)).toBe('')
|
||||
expect(createUnifiedSearchExcerpt('긴 본문 텍스트', '본문', -5)).toBe('')
|
||||
expect(createUnifiedSearchExcerpt('Hello world', ' ', 5)).toBe('Hell…')
|
||||
|
||||
const r = [{ source: 'record' as const, id: '1', title: 'A', excerpt: 'a', matchedField: 'title', occurredAt: 100 }]
|
||||
const m = [{ source: 'meeting' as const, id: '2', title: 'B', excerpt: 'b', matchedField: 'title', occurredAt: 200 }]
|
||||
expect(mergeUnifiedSearchResults(r, m, 0)).toEqual([])
|
||||
expect(mergeUnifiedSearchResults(r, m, -1)).toEqual([])
|
||||
expect(mergeUnifiedSearchResults(r, m, Number.NaN)).toEqual([])
|
||||
})
|
||||
|
||||
it('시간및날짜포맷터_음수와비유한수입력_NaN이나음수시각을노출하지않는다', () => {
|
||||
expect(formatDurationClockFromSeconds(-5)).toBe('0:00')
|
||||
expect(formatDurationClockFromSeconds(59.9, { rounding: 'round' })).toBe('1:00')
|
||||
expect(formatDurationClockFromMs(Number.NaN)).toBe('0:00')
|
||||
expect(formatTime(-500)).toBe('00:00')
|
||||
expect(formatTime(Number.NaN)).toBe('00:00')
|
||||
expect(formatTranscriptTimestamp(Number.NaN)).toBe('00:00')
|
||||
expect(formatDateFile(Number.NaN)).toBe('')
|
||||
expect(formatDateRange(Number.NaN, 1_700_000_000_000)).toBe('')
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue