사이트: 모르는 유저 다시 받기가 한 번 실패하면 영영 안 받던 문제

받는 중 중복만 막고, 실패하면 다음 이벤트에서 다시 받는다 (성공한 아이디만 기억).
lib/unknown-users.ts 로 빼고 테스트 추가, 목 서버에 /mock/users-fail · latejoin?again=1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-16 22:56:45 +09:00
parent 0b8789c895
commit a4511a8eaf
5 changed files with 98 additions and 17 deletions

View File

@@ -261,3 +261,5 @@ VOICE E2E PASS
- 사이트(목 서버 `/mock/latejoin`, 브라우저): 고치기 전 화면은 새 발화 2곳이 "알 수 없음", 고친 화면은 이름이 바로 뜨고 왼쪽 유저 목록에도 추가
- 테스트: 앱 63 · 사이트 서버 16 통과, 앱 · 화면 · 서버 타입 검사 · 화면 빌드 통과
- 배포: 사이트 서버 다시 배포 (배포된 화면 번들 `index-Cbz_E9Kc.js` 에 모르는 아이디 다시 받기 확인), Windows CI (79d6bb2, full) 7개 모두 PASS · 앱 버전 1.4.2 → Gitea 릴리스 v1.4.2 (v1.4.1 에 새 버전 안내)
- 보완 (사이트만): 모르는 아이디를 받기 전에 영구히 기억해서 `/api/users` 가 한 번 실패하면 그 사람은 계속 "알 수 없음"이었다. `site/web/src/lib/unknown-users.ts` 로 빼서, 받는 중에는 또 부르지 않고 실패하면 다음 이벤트에서 다시 받는다 (성공한 아이디만 기억). 테스트 `site/server/test/unknown-users.test.ts` 2개. 목 서버 `/mock/users-fail?n=1` + `/mock/latejoin?again=1`: 고치기 전 화면은 요청 1번에 이름 없음, 고친 화면은 다음 발화에서 다시 받아 이름 표시
- 테스트: 앱 63 · 사이트 서버 18 통과, 앱 · 화면 · 서버 타입 검사 · 화면 빌드 통과. 앱 코드는 그대로라 v1.4.2 릴리스는 그대로

View File

@@ -0,0 +1,51 @@
// 사이트 화면: 처음 보는 유저 아이디가 오면 유저 목록을 다시 받는 규칙 (site/web/src/lib/unknown-users.ts)
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { makeUnknownUserCheck } from '../../web/src/lib/unknown-users.ts';
const tick = () => new Promise((r) => setTimeout(r, 0));
test('모르는 유저: 받는 중에는 또 부르지 않고, 실패하면 다음 이벤트에서 다시 받는다', async () => {
const known = new Set(['a']);
let calls = 0;
let fail = true;
let release!: () => void;
const check = makeUnknownUserCheck(() => {
calls++;
return new Promise<void>((ok, no) => {
release = () => (fail ? no(new Error('500')) : (known.add('late'), ok()));
});
});
const has = (id: string) => known.has(id);
check(['a'], has);
assert.equal(calls, 0, '아는 사람은 부르지 않음');
check(['late'], has);
check(['late'], has);
assert.equal(calls, 1, '받는 중에는 한 번만');
release(); // 500
await tick();
check(['late'], has);
assert.equal(calls, 2, '실패 뒤 다음 발화에서 다시 받음');
fail = false;
release();
await tick();
assert.ok(known.has('late'));
check(['late'], has);
assert.equal(calls, 2, '받은 뒤에는 부르지 않음');
});
test('모르는 유저: 받았는데도 목록에 없는 아이디는 발화마다 다시 부르지 않는다', async () => {
let calls = 0;
const check = makeUnknownUserCheck(async () => {
calls++;
});
const has = () => false;
check(['ghost'], has);
await tick();
check(['ghost'], has);
check(['ghost', ''], has);
assert.equal(calls, 1);
check(['other'], has);
assert.equal(calls, 2, '다른 새 아이디는 다시 받음');
});

View File

@@ -6,7 +6,8 @@
// GET /mock/device?registered=0|1 등록 안 된 상태 흉내
// GET /mock/live?on=0|1 주기적 가짜 실시간 발화 켜기/끄기
// GET /mock/emit 가짜 실시간 발화 하나 즉시 만들기
// GET /mock/latejoin 녹음 중에 새 사람이 들어와 말함 (v1.4.1 이하 앱처럼 users.updated 없이 발화만 보냄)
// GET /mock/latejoin 녹음 중에 새 사람이 들어와 말함 (v1.4.1 이하 앱처럼 users.updated 없이 발화만 보냄). ?again=1 이면 마지막에 들어온 사람이 또 말함
// GET /mock/users-fail?n=1 다음 n 번 /api/users 를 500 으로 실패
// GET /auth/discord?as=notmember 길드 멤버가 아닌 계정으로 로그인 흉내 (403 not_member)
import http from 'node:http';
import fs from 'node:fs';
@@ -167,10 +168,14 @@ async function handle(req, res) {
return json(res, 200, { live: state.live });
}
if (p === '/mock/emit') return json(res, 200, emitLive() ?? { error: 'device_offline' });
if (p === '/mock/users-fail') {
state.usersFail = Number(q.get('n') ?? 1);
return json(res, 200, { usersFail: state.usersFail });
}
if (p === '/mock/latejoin') {
const n = db.users.length;
const u = { id: `41000000000000${String(n).padStart(4, '0')}`, name: `늦게온사람${n}`, color: '#d4537e', avatar: null, excluded: false, riot: [] };
db.users.push(u);
const u = q.get('again') === '1' ? db.users[n - 1] : { id: `41000000000000${String(n).padStart(4, '0')}`, name: `늦게온사람${n}`, color: '#d4537e', avatar: null, excluded: false, riot: [] };
if (q.get('again') !== '1') db.users.push(u);
const it = db.addLiveUtterance(u, '나 지금 들어왔어');
broadcast({ type: 'utterance.created', data: it });
return json(res, 200, { user: u, utterance: it.id });
@@ -243,7 +248,13 @@ async function handle(req, res) {
version: '1.0.0',
});
}
if (p === '/api/users') return json(res, 200, db.users);
if (p === '/api/users') {
if (state.usersFail > 0) {
state.usersFail--;
return json(res, 500, { error: 'mock_fail' });
}
return json(res, 200, db.users);
}
let m;
if ((m = p.match(/^\/api\/users\/([^/]+)$/))) {
const prof = userProfile(decodeURIComponent(m[1]));

View File

@@ -0,0 +1,24 @@
/**
* 처음 보는 유저 아이디가 오면 유저 목록을 다시 받아 온다 (v1.4.1 이하 앱은 녹음 중에 들어온 사람을 알려 주지 않아 "알 수 없음"으로 뜸).
* - 받는 중에는 또 부르지 않는다
* - 받기에 성공한 아이디는 다시 묻지 않는다 (목록에 없어도 매 발화마다 부르지 않게)
* - 실패하면 기억하지 않아 다음 이벤트에서 다시 받는다
*/
export function makeUnknownUserCheck(load: () => Promise<unknown>) {
const done = new Set<string>();
let busy = false;
return (ids: string[], known: (id: string) => boolean): void => {
if (busy) return;
const fresh = ids.filter((id) => id && !known(id) && !done.has(id));
if (!fresh.length) return;
busy = true;
load()
.then(
() => fresh.forEach((id) => done.add(id)),
() => {},
)
.finally(() => {
busy = false;
});
};
}

View File

@@ -2,6 +2,7 @@ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, use
import type { DeviceStatus, LiveEvent, Overview, User } from '@gvr/shared';
import { api, onApiSignal, type Me } from '../lib/api';
import { live, type LiveConn } from '../lib/live';
import { makeUnknownUserCheck } from '../lib/unknown-users';
// ── 로그인 ───────────────────────────────────────────
type AuthState = { status: 'loading' } | { status: 'anon' } | { status: 'not_member' } | { status: 'ok'; me: Me };
@@ -139,22 +140,14 @@ export function DataProvider({ children }: { children: ReactNode }) {
alive = false;
};
}, [epoch, locked]);
const reloadUsers = useCallback(() => {
api
.users()
.then((users) => setOverview((o) => (o ? { ...o, users } : o)))
.catch(() => {});
}, []);
const fetchUsers = useCallback(() => api.users().then((users) => setOverview((o) => (o ? { ...o, users } : o))), []);
const reloadUsers = useCallback(() => void fetchUsers().catch(() => {}), [fetchUsers]);
const users = overview?.users ?? [];
const map = useMemo(() => new Map(users.map((u) => [u.id, u])), [users]);
// 처음 보는 사람 아이디는 한 번만 유저 목록을 다시 받아 온다 (v1.4.1 이하 앱은 녹음 중에 들어온 사람을 알려 주지 않아 "알 수 없음"으로 뜸)
const asked = useRef(new Set<string>());
// 처음 보는 사람 아이디가 오면 유저 목록을 다시 받아 온다 (실패하면 다음 이벤트에서 다시)
const unknownCheck = useRef(makeUnknownUserCheck(fetchUsers));
const checkUnknown = (ids: string[]) => {
if (!overview) return;
const fresh = ids.filter((id) => id && !map.has(id) && !asked.current.has(id));
if (!fresh.length) return;
fresh.forEach((id) => asked.current.add(id));
reloadUsers();
if (overview) unknownCheck.current(ids, (id) => map.has(id));
};
useLive((e) => {
if (e.type === 'users.updated') {