fix: red-team round 3 hardening across desktop, mobile, core and server

Batch of red-team r3 fixes that were in the working tree before the
2026-09-28 design overhaul, committed as one unit with their tests.

- desktop main: STT timeouts and sidecar, voice recording store, sync
  (credentials, audio, knowledge reindex, push gates), runtime
  provisioner, update policy, AltGr keybindings, voice-command policy,
  dictionary file codec/limits, meeting transcript condensing and a
  local recording ledger so interrupted-session recovery only closes
  meetings this device recorded (a phone's live meeting is left alone).
- mobile: login CSRF via implicit token callbacks rejected, account
  deletion/retention, durable queue retention, knowledge realtime
  without unfiltered DELETE, meeting re-record failure paths, cloud STT
  client, preferences store/resync.
- core: text chunking splits long unbroken transcripts to fit, template
  field policy, dictionary limits, meeting markdown inline handling.
- server: payple webhook policy and cancellation order scope, meeting
  document generation quota, team RPC null-role guard, unified LLM
  quota in-flight accounting, knowledge chunk vector index, meeting
  re-record failure paths (migrations 20260929*).
- ci: portable/runtime feed gates, update-policy schema, Forgejo file
  delete and alias planning.

Four older tests are updated to the new contracts rather than the old
behavior: token-pair auth callbacks are rejected, knowledge realtime no
longer subscribes to DELETE, long transcript lines are split, and
meeting recovery requires the local recording ledger for empty rows.
This commit is contained in:
Yun Chan 2026-09-28 20:45:52 +09:00
parent 2428ede03d
commit ba9ef9741e
161 changed files with 17056 additions and 2379 deletions

View file

@ -3,6 +3,8 @@
// 데스크톱은 전사를 `[MM:SS] [화자] 내용` 줄로 저장하고, Supabase `transcripts` 는 구간 행으로 저장한다
// (모바일은 구간이 있으면 구간을 우선 표시한다). 두 표현을 이 한 곳에서만 바꾼다.
import { splitTextToFit } from './text-chunking'
export interface TranscriptLine {
/** 회의 시작 기준 ms. 시각 표기가 없는 줄은 앞 줄의 시각을 이어받는다(처음이면 0). */
timestampMs: number
@ -113,20 +115,40 @@ export function applySpeakerLabels(
})
}
/** 줄 앞의 `[MM:SS] [화자] ` 머리 — 긴 줄을 자를 때 이어지는 조각에도 붙여 시각·화자를 잃지 않는다 */
const LINE_PREFIX = /^\[\d{1,3}:\d{2}\]\s*(?:\[[^\]]+\]\s*)?/
/**
* 전사를 줄 경계에서 끊어 LLM 한 번에 보낼 크기의 조각들로 나눈다.
* 한 줄이 maxChars 보다 길면 그 줄 하나로 한 조각을 만든다(줄 중간은 자르지 않는다).
* maxChars 보다 긴 한 줄을 maxChars 이하 줄들로 자른다(문장 경계 → 공백 → 글자 수).
* `[MM:SS] [화자]` 머리가 있으면 조각마다 붙인다 — 단, 머리가 한도의 절반을 넘으면 붙이지 않는다.
*/
function splitLongLine(line: string, maxChars: number): string[] {
if (line.length <= maxChars) return [line]
const prefix = LINE_PREFIX.exec(line)?.[0] ?? ''
if (!prefix || prefix.length * 2 > maxChars) return splitTextToFit(line, maxChars)
const body = line.slice(prefix.length)
return splitTextToFit(body, maxChars - prefix.length).map((piece) => `${prefix}${piece}`)
}
/**
* 전사를 줄 경계에서 끊어 LLM 한 번에 보낼 크기(maxChars 이하)의 조각들로 나눈다.
* 한 줄이 maxChars 보다 길면(줄바꿈 없는 자막·파일·폰 전사) 그 줄을 문장 경계 → 공백 → 글자 수
* 순으로 잘라 여러 줄로 만든다 — 예전엔 줄 하나가 통째로 한 조각이 되어 LLM 입력·출력 한도를 넘었다.
* 빈 줄은 버린다.
*/
export function chunkTranscriptByLines(text: string | null | undefined, maxChars: number): string[] {
if (!text) return []
const limit = Math.max(1, Math.floor(maxChars))
const chunks: string[] = []
let current: string[] = []
let size = 0
for (const raw of text.split('\n')) {
const line = raw.trimEnd()
if (!line.trim()) continue
if (current.length > 0 && size + line.length + 1 > maxChars) {
const lines = text
.split('\n')
.map((raw) => raw.trimEnd())
.filter((line) => line.trim().length > 0)
.flatMap((line) => splitLongLine(line, limit))
for (const line of lines) {
if (current.length > 0 && size + line.length + 1 > limit) {
chunks.push(current.join('\n'))
current = []
size = 0