// 범인찾기 테스트용: 앱 코어 일부(기록 DB · 타임라인 · 게임 관리 · 범인찾기)와 시연 경기 (앱 · 사이트 서버 테스트가 같이 쓴다) import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { Store } from '../../src/core/db/db.ts'; import { Timeline } from '../../src/core/timeline.ts'; import { GameAssets } from '../../src/core/games/assets.ts'; import { GameManager } from '../../src/core/games/manager.ts'; import { Culprit } from '../../src/core/culprit.ts'; import { buildApi } from '../../src/core/api/server.ts'; import { Bus } from '../../src/core/util/events.ts'; import { makeDemoValorant, AGENT } from './demo-matches.ts'; export const MIN = 60000; export function setup() { const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gvr-culprit-')); const store = new Store(path.join(dir, 'db.sqlite')); const timeline = new Timeline(store); const assets = new GameAssets(path.join(dir, 'cache')); // 네트워크 없이: 요원 이름 · 역할만 넣어 둔다 assets.val = { at: Date.now(), agents: { [AGENT.jett]: { name: '제트', icon: '', role: '타격대', abilities: {} }, [AGENT.sage]: { name: '세이지', icon: '', role: '감시자', abilities: {} }, }, maps: {}, weapons: {}, tiers: {}, modes: {}, clientVersion: null, } as any; const bus = new Bus(); const stt: any = { onMatchStart: async () => undefined, onMatchEnd: async () => undefined }; const worker: any = { on: () => undefined, off: () => undefined }; const games = new GameManager(store, assets, worker, stt, timeline, bus, () => ({}) as any, () => null); const culprit = new Culprit(store, timeline, games); return { dir, store, timeline, assets, bus, games, culprit }; } /** 발로란트 시연 경기 + 녹음 세션 + 대화 4문장 */ export function seedValorant(ctx: ReturnType, opts: { sessionStartOffsetMs?: number; pending?: boolean } = {}) { const { store, games } = ctx; const VS = Date.now() - 3 * 3600_000; const md = makeDemoValorant(VS); const id = 'val-demo'; const users = [ { id: 'u1', name: '하늘', puuid: 'p-sh' }, { id: 'u2', name: '민수', puuid: 'p-ms' }, { id: 'u9', name: '도윤', puuid: null }, ]; for (const u of users) { store.upsertUser({ id: u.id, name: u.name, avatar: null }); if (u.puuid) store.setAccounts(u.id, [{ puuid: u.puuid, riotId: `${u.name}#X` }]); } store.startSession('s1', 'g', 'c', '음성', VS - 5 * MIN + (opts.sessionStartOffsetMs ?? 0)); games.matchStarted({ id, game: 'valorant', startedAt: VS, map: md.matchInfo.mapId, mode: 'competitive', queue: 'competitive', detail: { live: true } }); games.matchEnded(id, VS + md.matchInfo.gameLengthMillis); (games.adapters[0] as any).applyDetails(id, md, 'p-sh', VS); const rounds = store.rounds(id); const say = (uid: string, round: number, sec: number, text: string, status = 'realtime') => { const ts = rounds[round - 1].combat_at + sec * 1000; const uid2 = `${uid}-${round}-${sec}`; store.insertUtterance({ id: uid2, session_id: 's1', user_id: uid, started_at: ts, ended_at: ts + 1500, audio_path: null, match_id: id }); if (status !== 'pending') store.updateUtteranceResult(uid2, { text, raw_text: text, words: [], noise: false, noise_reason: null, confidence: 0.9, lufs: -20, gain_db: 0, model: 'small', status: status as any }); }; say('u1', 3, 5, '현우야 같이 가 기다려 둘 있어'); say('u2', 3, 9, '아 그냥 간다 내가 뚫을게'); say('u9', 5, 2, '나 돈 없어 세이브할게'); say('u1', 7, 4, '스파이크 설치됐어 해체 들어가', opts.pending ? 'pending' : 'realtime'); store.endSession('s1', VS + md.matchInfo.gameLengthMillis + 5 * MIN); return { id, VS, md }; } /** 앱 로컬 API (사이트 서버가 중계로 부르는 것과 같은 Fastify) */ export function culpritApi(ctx: ReturnType) { return buildApi({ store: ctx.store, timeline: ctx.timeline, games: ctx.games, dict: {} as any, culprit: ctx.culprit, bus: ctx.bus, settings: () => ({}) as any, trainingDir: () => ctx.dir, overviewExtra: () => ({ guild: null, recording: { active: false, channel: null, since: null, participants: [] } }), version: 'test', }); }