v1.1.0 리뷰 반영: 봇 전환 중 늦은 연결 결과 무시, win-ci 토큰 자동 정리, smoke 에 봇 ready 확인
- DiscordTab: 연결 테스트에 요청 번호를 두어 봇을 바꾼 뒤 도착한 이전 응답(성공·서버 목록·오류·진행 표시)을 버린다 - 다른 봇으로 바꿨는데 토큰이 아직 없으면 오류 대신 안내 문구를 보인다 - mock-gvr: testBotToken 이 부를 때의 모드로 토큰을 고르게 (실제 IPC 와 같게) - win-ci: run.sh 가 토큰 형식 검사 후 systemd 사용자 유닛으로 자동 복원(restore.sh --wait)을 띄운다 - gvr.ps1: 토큰 환경변수 제거를 finally 로, 끝나면 게스트의 stage2 사본과 빌드 산출물을 지운다 - smoke: 봇 로그인이 끝나길 최대 30초 기다리고, 기본 봇이 든 빌드는 ready 여야 통과 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -134,7 +134,6 @@ async function smoke(): Promise<void> {
|
||||
out.codec = c.settings.codecName;
|
||||
out.builtinBot = c.settings.hasBuiltinBot;
|
||||
out.botMode = c.settings.get().discord.botMode;
|
||||
out.bot = { status: c.bot.state.status, user: c.bot.state.user?.name ?? null, error: c.bot.state.error };
|
||||
const ready = await new Promise<any>((res) => {
|
||||
if (c.worker.ready) return res(true);
|
||||
const t = setTimeout(() => res(false), 120000);
|
||||
@@ -144,6 +143,10 @@ async function smoke(): Promise<void> {
|
||||
});
|
||||
});
|
||||
out.worker = ready;
|
||||
// 봇: 로그인이 끝나(ready/error) 길 최대 30초 기다린다. 기본 봇이 들어 있는 빌드면 ready 여야 통과
|
||||
for (let i = 0; i < 60 && c.bot.state.status === 'connecting'; i++) await new Promise((r) => setTimeout(r, 500));
|
||||
out.bot = { status: c.bot.state.status, user: c.bot.state.user?.name ?? null, guilds: c.bot.state.guilds.length, error: c.bot.state.error };
|
||||
const botOk = !c.settings.hasBuiltinBot || c.bot.state.status === 'ready';
|
||||
out.gpu = await c.worker.request('gpu_info', {}, 30000).catch((e) => String(e));
|
||||
c.settings.setSecret('riotApiKey', 'smoke-test');
|
||||
out.secretRoundTrip = c.settings.getSecret('riotApiKey') === 'smoke-test';
|
||||
@@ -151,7 +154,7 @@ async function smoke(): Promise<void> {
|
||||
out.dict = c.store.listDict().length;
|
||||
out.renderer = fs.existsSync(path.join(rendererDir(), 'index.html'));
|
||||
out.tray = fs.existsSync(path.join(brandDir(), 'tray.png'));
|
||||
code = ready && out.secretRoundTrip && out.renderer && out.tray ? 0 : 1;
|
||||
code = ready && botOk && out.secretRoundTrip && out.renderer && out.tray ? 0 : 1;
|
||||
await c.stop();
|
||||
} catch (e: any) {
|
||||
out.error = e.stack || e.message;
|
||||
|
||||
@@ -232,9 +232,11 @@ export function createMockGvr(): GvrApi {
|
||||
emit();
|
||||
},
|
||||
async testBotToken(token) {
|
||||
// 실제 IPC 처럼 부를 때의 모드로 토큰을 고른다 (응답은 늦게 온다)
|
||||
const noSaved = state.settings.discord.botMode === 'builtin' ? !state.builtinBot : !state.secrets.botToken;
|
||||
await sleep(900);
|
||||
if (token !== undefined && token.length < 20) return { ok: false, error: '토큰이 올바르지 않습니다 (401 Unauthorized)' };
|
||||
if (token === undefined && (state.settings.discord.botMode === 'builtin' ? !state.builtinBot : !state.secrets.botToken)) return { ok: false, error: '저장된 토큰이 없습니다' };
|
||||
if (token === undefined && noSaved) return { ok: false, error: '저장된 토큰이 없습니다' };
|
||||
return {
|
||||
ok: true,
|
||||
bot: { id: 'b1', name: '겜녹이#4821', avatar: null },
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react';
|
||||
import type { GvrApi } from '../../main/api-types';
|
||||
import { gvr, useAction, useApp, useLoad } from '../store';
|
||||
import { Avatar, Btn, DraftInput, Err, Line, Ok, Page, Section, Select, ToggleLine } from '../ui';
|
||||
import { fmtClock, fmtDuration } from '../util';
|
||||
import { errMsg, fmtClock, fmtDuration } from '../util';
|
||||
|
||||
type TestResult = Awaited<ReturnType<GvrApi['testBotToken']>>;
|
||||
|
||||
@@ -20,7 +20,8 @@ export function BotTokenSection({ wizard, onResult }: { wizard?: boolean; onResu
|
||||
const [token, setToken] = useState('');
|
||||
const [show, setShow] = useState(false);
|
||||
const [result, setResult] = useState<TestResult | null>(null);
|
||||
const test = useAction();
|
||||
const [testing, setTesting] = useState(false);
|
||||
const [testError, setTestError] = useState<string | null>(null);
|
||||
const saver = useAction();
|
||||
|
||||
const report = (r: TestResult) => {
|
||||
@@ -39,9 +40,33 @@ export function BotTokenSection({ wizard, onResult }: { wizard?: boolean; onResu
|
||||
}
|
||||
};
|
||||
|
||||
// 연결 테스트 요청 번호. 봇을 바꾸거나 새 테스트를 시작하면 올라가고, 늦게 온 이전 응답(결과 · 오류 · 진행 표시)은 버린다
|
||||
const testSeq = useRef(0);
|
||||
const cancelTest = () => {
|
||||
testSeq.current++;
|
||||
setTesting(false);
|
||||
setTestError(null);
|
||||
};
|
||||
const testBot = async (t?: string): Promise<TestResult | undefined> => {
|
||||
const id = ++testSeq.current;
|
||||
setTesting(true);
|
||||
setTestError(null);
|
||||
try {
|
||||
const r = await gvr.testBotToken(t);
|
||||
if (id !== testSeq.current) return undefined;
|
||||
if (!r.ok) setTestError(r.error ?? '실패했습니다');
|
||||
return r;
|
||||
} catch (e) {
|
||||
if (id === testSeq.current) setTestError(errMsg(e));
|
||||
return undefined;
|
||||
} finally {
|
||||
if (id === testSeq.current) setTesting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const runTest = async () => {
|
||||
const t = custom ? token.trim() : '';
|
||||
const r = await test.run(() => gvr.testBotToken(t || undefined));
|
||||
const r = await testBot(t || undefined);
|
||||
if (!r) return;
|
||||
report(r);
|
||||
if (r.ok && wizard && t) await saveToken(t);
|
||||
@@ -50,16 +75,19 @@ export function BotTokenSection({ wizard, onResult }: { wizard?: boolean; onResu
|
||||
// 봇 바꾸기: 모드를 저장하고 봇을 새 토큰으로 다시 띄운다 (다른 봇인데 토큰이 아직 없으면 봇은 꺼진 채로 둔다)
|
||||
const switchMode = async (m: 'builtin' | 'custom') => {
|
||||
if (m === mode || saver.busy) return;
|
||||
cancelTest();
|
||||
setResult(null);
|
||||
setToken('');
|
||||
onResult?.({ ok: false });
|
||||
const r = await saver.run(async () => {
|
||||
await save({ discord: { botMode: m } });
|
||||
return gvr.restartBot();
|
||||
const res = await gvr.restartBot();
|
||||
// 다른 봇인데 토큰을 아직 안 넣었으면 봇이 꺼진 채인 게 정상이다 (오류로 보이지 않게)
|
||||
return m === 'custom' && !state.secrets.botToken ? { ok: true as const } : res;
|
||||
});
|
||||
if (m === 'builtin') {
|
||||
if (r?.ok) toast('겜녹이 봇으로 연결');
|
||||
const t = await test.run(() => gvr.testBotToken());
|
||||
const t = await testBot();
|
||||
if (t) report(t);
|
||||
} else if (state.secrets.botToken) {
|
||||
if (r?.ok) toast('저장된 다른 봇으로 연결');
|
||||
@@ -114,7 +142,7 @@ export function BotTokenSection({ wizard, onResult }: { wizard?: boolean; onResu
|
||||
저장
|
||||
</Btn>
|
||||
)}
|
||||
<Btn primary onClick={runTest} busy={test.busy} disabled={!token.trim() && !state.secrets.botToken}>
|
||||
<Btn primary onClick={runTest} busy={testing} disabled={!token.trim() && !state.secrets.botToken}>
|
||||
연결 테스트
|
||||
</Btn>
|
||||
</div>
|
||||
@@ -122,7 +150,7 @@ export function BotTokenSection({ wizard, onResult }: { wizard?: boolean; onResu
|
||||
)}
|
||||
{!custom && (
|
||||
<div className="field">
|
||||
<Btn primary onClick={runTest} busy={test.busy || saver.busy} disabled={!state.builtinBot}>
|
||||
<Btn primary onClick={runTest} busy={testing || saver.busy} disabled={!state.builtinBot}>
|
||||
연결 확인
|
||||
</Btn>
|
||||
{inviteId && (
|
||||
@@ -137,8 +165,8 @@ export function BotTokenSection({ wizard, onResult }: { wizard?: boolean; onResu
|
||||
</div>
|
||||
)}
|
||||
<div className="result">
|
||||
{test.error || saver.error ? (
|
||||
<Err>{test.error || saver.error}</Err>
|
||||
{testError || saver.error ? (
|
||||
<Err>{testError || saver.error}</Err>
|
||||
) : result ? (
|
||||
result.ok ? (
|
||||
<Ok>
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
# ==================================================================
|
||||
$TargetRev = '__REV__'
|
||||
$Phase = '__PHASE__'
|
||||
# 겜녹이 기본 봇 토큰 (run.sh 가 full 빌드에만 박는다. 빈 값이면 기본 봇 없는 빌드). 끝나면 finally 에서 이 스크립트 사본째 지운다
|
||||
$BuiltinBot = '__BUILTIN_BOT__'
|
||||
$Repo = 'C:\win-ci\gvr'
|
||||
$OutDir = 'C:\win-ci\gvr-out'
|
||||
New-Item -ItemType Directory -Force -Path $OutDir | Out-Null
|
||||
@@ -131,11 +133,13 @@ try {
|
||||
Push-Location (Join-Path $Repo 'app')
|
||||
& npm.cmd ci --no-audit --no-fund
|
||||
if ($LASTEXITCODE -ne 0) { Pop-Location; throw "npm ci exit $LASTEXITCODE" }
|
||||
# 겜녹이 기본 봇 토큰 (run.sh 가 이번 실행에만 박는다. 빈 값이면 기본 봇 없는 빌드)
|
||||
$env:GVR_BUILTIN_BOT_TOKEN = '__BUILTIN_BOT__'
|
||||
& npm.cmd run dist:win
|
||||
$c = $LASTEXITCODE
|
||||
Remove-Item Env:GVR_BUILTIN_BOT_TOKEN -ErrorAction SilentlyContinue
|
||||
try {
|
||||
$env:GVR_BUILTIN_BOT_TOKEN = $BuiltinBot
|
||||
& npm.cmd run dist:win
|
||||
$c = $LASTEXITCODE
|
||||
} finally {
|
||||
Remove-Item Env:GVR_BUILTIN_BOT_TOKEN -ErrorAction SilentlyContinue
|
||||
}
|
||||
Pop-Location
|
||||
if ($c -ne 0) { throw "electron-builder exit $c" }
|
||||
Get-ChildItem app\release -File | ForEach-Object { "$($_.Name) $([math]::Round($_.Length / 1MB, 1)) MB" }
|
||||
@@ -164,6 +168,14 @@ try {
|
||||
} catch {
|
||||
Log "gvr 검증 준비 실패: $($_.Exception.Message)"
|
||||
try { Pop-Location } catch {}
|
||||
} finally {
|
||||
if ($BuiltinBot) {
|
||||
# 성공·실패와 상관없이 게스트에 토큰을 남기지 않는다: 이 스크립트 사본(평문), 빌드 산출물(감춘 값. exe 는 이미 호스트로 보냄)
|
||||
Remove-Item Env:GVR_BUILTIN_BOT_TOKEN -ErrorAction SilentlyContinue
|
||||
Remove-Item (Join-Path $Repo 'app\dist'), (Join-Path $Repo 'app\release') -Recurse -Force -ErrorAction SilentlyContinue
|
||||
Remove-Item $PSCommandPath -Force -ErrorAction SilentlyContinue
|
||||
Log "기본 봇 토큰 정리: stage2 사본 삭제=$(-not (Test-Path $PSCommandPath)), 빌드 산출물 삭제=$(-not (Test-Path (Join-Path $Repo 'app\release')))"
|
||||
}
|
||||
}
|
||||
Log "=== gvr 끝 ==="
|
||||
exit 0
|
||||
|
||||
@@ -1,4 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
# 공용 win-ci VM 의 stage2.ps1 을 겜녹이 작업 전 상태로 되돌린다
|
||||
# 공용 win-ci VM 의 stage2.ps1 을 겜녹이 작업 전 상태로 되돌린다.
|
||||
# restore.sh 지금 바로 되돌린다
|
||||
# restore.sh --wait gvr-summary.log 가 생길 때까지(최대 3시간) 기다렸다가 되돌린다 (run.sh 가 자동으로 띄운다)
|
||||
# full 빌드의 stage2 에는 겜녹이 기본 봇 토큰이 평문으로 들어 있으므로, 성공·실패와 상관없이 반드시 지워야 한다.
|
||||
D=/home/claude/win-ci
|
||||
[ -f $D/serve/stage2.ps1.bak-gvr ] && mv $D/serve/stage2.ps1.bak-gvr $D/serve/stage2.ps1 && echo "복원 완료"
|
||||
if [ "${1:-}" = --wait ]; then
|
||||
for _ in $(seq 1 1080); do
|
||||
[ -f $D/results/gvr-summary.log ] && break
|
||||
sleep 10
|
||||
done
|
||||
fi
|
||||
if [ ! -f $D/serve/stage2.ps1.bak-gvr ]; then
|
||||
echo "되돌릴 것 없음 (stage2.ps1.bak-gvr 없음)"
|
||||
elif grep -q 'game_voice_recorder' $D/serve/stage2.ps1 2>/dev/null; then
|
||||
mv $D/serve/stage2.ps1.bak-gvr $D/serve/stage2.ps1 && echo "복원 완료"
|
||||
else
|
||||
# 그 사이 다른 작업이 stage2 를 바꿨다 - 그것은 건드리지 않고 보관본만 지운다 (겜녹이 토큰은 이미 없다)
|
||||
rm -f $D/serve/stage2.ps1.bak-gvr && echo "stage2 는 다른 작업 것이라 그대로 두고 보관본만 삭제"
|
||||
fi
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# win-ci VM 에서 겜녹이 검증·빌드를 돌린다. tools/win-ci/run.sh <worker|full> [rev]
|
||||
# - 공용 VM 이다. 기존 stage2.ps1 은 serve/stage2.ps1.bak-gvr 로 보관하고, 끝나면 restore.sh 로 되돌린다.
|
||||
# - 공용 VM 이다. 기존 stage2.ps1 은 serve/stage2.ps1.bak-gvr 로 보관하고, 끝나면 restore.sh 가 자동으로 되돌린다.
|
||||
# - 결과: /home/claude/win-ci/results/gvr-summary.log, gvr-*.log, 산출물(exe/zip)
|
||||
set -euo pipefail
|
||||
PHASE=${1:-worker}
|
||||
@@ -10,12 +10,19 @@ HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
[ -f $D/serve/stage2.ps1.bak-gvr ] || cp $D/serve/stage2.ps1 $D/serve/stage2.ps1.bak-gvr
|
||||
rm -f $D/results/gvr-summary.log
|
||||
# full 빌드: 겜녹이 기본 봇 토큰을 secrets.json 에서 읽어 이번 stage2 에만 넣는다 (저장소·로그에는 남기지 않는다.
|
||||
# stage2 는 127.0.0.1 로만 내려주고, 끝나면 restore.sh 로 지운다)
|
||||
# stage2 는 127.0.0.1 로만 내려주고, 끝나면 아래 자동 복원이 지운다. 게스트 쪽 사본은 gvr.ps1 이 스스로 지운다)
|
||||
BOT=''
|
||||
if [ "$PHASE" = full ]; then
|
||||
BOT=$(python3 -c "import json;print(json.load(open('/home/claude/.config/ejclaw/secrets.json'))['credentials']['discord.com/bot/game-voice-recorder']['token'])")
|
||||
# sed 치환과 PowerShell '...' 문자열에 그대로 넣으므로 디스코드 토큰 글자(영숫자 . _ -)만 허용한다
|
||||
[[ "$BOT" =~ ^[A-Za-z0-9._-]+$ ]] || { echo "기본 봇 토큰 형식이 이상하다 (secrets.json 확인)" >&2; exit 1; }
|
||||
fi
|
||||
umask 077
|
||||
{ cat "$HERE/preamble.ps1"; sed "s/__REV__/$REV/; s/__PHASE__/$PHASE/; s|__BUILTIN_BOT__|$BOT|" "$HERE/gvr.ps1"; } > $D/serve/stage2.ps1.new
|
||||
mv $D/serve/stage2.ps1.new $D/serve/stage2.ps1
|
||||
echo "stage2 배포: phase=$PHASE rev=$REV 기본 봇=$([ -n "$BOT" ] && echo 포함 || echo 없음) (게스트가 20초 안에 받아간다)"
|
||||
# 자동 복원: gvr-summary.log 가 오면(성공·실패 모두 마지막에 보낸다) 또는 3시간이 지나면 stage2 를 되돌린다.
|
||||
# 이 셸이 끝나도 살아 있게 systemd 사용자 유닛으로 띄운다
|
||||
systemctl --user stop gvr-ci-restore.service 2>/dev/null || true
|
||||
systemd-run --user --quiet --collect --unit gvr-ci-restore "$HERE/restore.sh" --wait
|
||||
echo "자동 복원 대기 중 (systemctl --user status gvr-ci-restore)"
|
||||
|
||||
Reference in New Issue
Block a user