Files
game_voice_recorder/site/server/test/reconnect.test.ts
EJClaw c2a5547a68 앱 v1.2.0: exe 디스코드 로그인 · 유저 등록 · 관리자 페이지
- 사이트 서버: 앱 로그인(/auth/app/begin·start·poll, 기존 OAuth 콜백 재사용), 앱 토큰(/app/me, 해시 저장),
  유저 등록 API(/app/admin/users, 등록·역할·해제는 최고 관리자만, 목록은 관리자도). 최고 관리자 2명 고정
- 앱: 등록된 계정으로 로그인해야 코어(봇·녹음·사이트 연결)를 띄운다. 미등록이면 "등록되지 않은 아이디" + 아이디 표시.
  10분마다 재확인, 등록 해제 시 즉시 잠금. 서버 연결 실패 시 마지막 확인 후 3일 유예
- 겜녹이 봇 토큰을 exe 에 넣지 않고 로그인한 등록 유저에게 서버가 내려준다 (잠기면 삭제). win-ci 토큰 주입 제거
- 관리자 탭(유저 등록·목록·접속 기록), 관리자 전용 설정(봇 변경·TTS 안내·보관 기간·사이트·학습 데이터·파인튜닝)은
  일반 유저에게 잠금 표시 + 메인 프로세스에서 차단
- 테스트: 서버 앱 로그인 2건, 앱↔서버 통합 3건, Electron 로그인 E2E 스크립트(scripts/login-e2e.mts)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 08:08:44 +09:00

51 lines
2.6 KiB
TypeScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { buildServer } from '../src/app.ts';
import type { Config } from '../src/config.ts';
// M7 안정화: 사이트 서버가 재시작(배포)돼도 게임 PC 연결이 자동으로 돌아오는지
test('사이트 서버 재시작 → 게임 PC 자동 재연결', async () => {
const dataDir = fs.mkdtempSync(path.join(process.env.TMPDIR || os.tmpdir(), 'gvr-rc-'));
const cfg = (port: number): Config => ({
port, host: '127.0.0.1', publicUrl: 'http://127.0.0.1', clientId: 'x', clientSecret: 'x', botToken: 'x', allowedGuilds: [], owners: [], superAdmins: [],
sessionSecret: 'y'.repeat(32), dataDir, webDir: '/nonexistent', version: 't', discordApi: 'http://127.0.0.1:1', assetUpstream: {},
});
let s = await buildServer(cfg(0));
s.app.log.level = 'silent';
await s.app.listen({ host: '127.0.0.1', port: 0 });
const port = (s.app.server.address() as any).port;
const base = `http://127.0.0.1:${port}`;
const code = s.store.createCode('t');
const reg = (await (await fetch(base + '/device/register', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ code: code.code, name: 'PC' }) })).json()) as any;
const { RelayClient } = await import('../../../app/src/core/relay/client.ts');
const { Bus } = await import('../../../app/src/core/util/events.ts');
const Fastify = (await import('fastify')).default;
const local = Fastify();
const rc = new RelayClient(local as any, new Bus(), () => ({ serverUrl: base, deviceId: reg.deviceId, deviceKey: reg.deviceKey, name: 'PC', version: '1', guildId: null }));
rc.start();
const wait = async (fn: () => boolean, ms: number, label: string) => {
const t = Date.now();
while (!fn()) {
if (Date.now() - t > ms) throw new Error('timeout ' + label);
await new Promise((r) => setTimeout(r, 50));
}
};
await wait(() => rc.status.state === 'online', 5000, 'first');
await s.app.close();
await wait(() => rc.status.state !== 'online', 5000, 'drop');
const dropAt = Date.now();
await new Promise((r) => setTimeout(r, 1500));
s = await buildServer(cfg(port));
s.app.log.level = 'silent';
await s.app.listen({ host: '127.0.0.1', port });
await wait(() => rc.status.state === 'online', 20000, 'reconnect');
console.log(`재연결까지 ${((Date.now() - dropAt) / 1000).toFixed(1)}초`);
assert.equal(s.hub.status().online, true, '서버도 기기를 온라인으로 본다');
rc.stop();
await s.app.close();
await local.close();
});