범인찾기 v1.3.1: OP.GG 세션 재시작 · 조회 실패 구분 · LOL.PS 라인전 10/15분
- opgg.ts: 세션 404 → 새 initialize 후 한 번 다시 (MCP 규격), 실패를 '경기 없음'과 나눠 meta.opgg.error · 화면 · 지시문에 반영 - rating.ts: 라인전을 LOL.PS 원문 정의대로 10 · 15분 맞라이너 CS · 골드 · 경험치 차로 - tools/opscore-fit/README.md: OP.GG(롤 · 발로란트) · LOL.PS 원문 인용과 구현 대응 - 테스트: 세션 재시작 · 503 · 일부 실패 · 서버 메타, 라인전 10/15분 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,7 @@ import { buildServer } from '../src/app.ts';
|
||||
import type { Config } from '../src/config.ts';
|
||||
import { checkResult, costOf, normRef, type ModelCall } from '../src/culprit.ts';
|
||||
import { buildSystemPrompt, KnowledgeAuto, outputSchema, replaceAutoSection } from '../src/culprit-prompt.ts';
|
||||
import { lookupOpgg, parseOpgg, type ToolCaller } from '../src/opgg.ts';
|
||||
import { lookupOpgg, opggCaller, parseOpgg, type ToolCaller } from '../src/opgg.ts';
|
||||
|
||||
const tmp = () => fs.mkdtempSync(path.join(process.env.TMPDIR || os.tmpdir(), 'gvr-culprit-srv-'));
|
||||
|
||||
@@ -291,6 +291,27 @@ test('범인찾기: 결과 확인 규칙 · 비용 계산 · 프롬프트 조립
|
||||
assert.deepEqual(schema.required, ['summary', 'confidence', 'confidence_note', 'teams', 'players']);
|
||||
});
|
||||
|
||||
test('범인찾기 서버: OP.GG 조회 실패는 "경기 없음"과 따로 저장하고 기록 점수로 분석을 마친다', async () => {
|
||||
const h = await harness({
|
||||
calls: [(i) => ok(i)],
|
||||
opgg: async () => {
|
||||
throw new Error('OP.GG 503');
|
||||
},
|
||||
});
|
||||
try {
|
||||
assert.equal((await h.post(h.login('user1'))).status, 202);
|
||||
await waitFor(() => h.stages().includes('done') || h.stages().includes('failed'));
|
||||
assert.deepEqual(h.stages(), ['collect', 'thinking', 'verify', 'done']);
|
||||
assert.ok(!h.seen[0].user.includes('# OP.GG 실제 OP스코어'));
|
||||
const info = (await (await fetch(`${h.base}/api/culprit/matches/${h.matchId}`, { headers: { cookie: h.login('member1') } })).json()) as CulpritMatchInfo;
|
||||
assert.equal(info.analysis!.meta.opgg!.found, false);
|
||||
assert.equal(info.analysis!.meta.opgg!.error, true);
|
||||
assert.match(info.analysis!.meta.opgg!.note!, /조회 실패/);
|
||||
} finally {
|
||||
await h.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('범인찾기 서버: OP.GG 에 경기가 있으면 실제 OP스코어를 자료 · 결과에 붙인다', async () => {
|
||||
const puuidOf: Record<string, string> = {};
|
||||
const calls: string[] = [];
|
||||
@@ -372,9 +393,56 @@ test('OP.GG: 응답 해석 · 롤 경기 찾기 (시작 시각 · 길이) · 못
|
||||
const miss = await lookupOpgg({ ...input, lookup: { ...input.lookup!, startedAt: Date.parse('2026-10-14T10:00:00+09:00') } }, caller);
|
||||
assert.equal(miss.found, false);
|
||||
assert.match(miss.note!, /OP\.GG 에 이 경기가 없습니다/);
|
||||
// 연결 실패도 분석을 멈추지 않는다 (찾지 못함으로)
|
||||
// 조회가 실패하면 "경기 없음"이 아니라 "확인 못 함" (분석은 멈추지 않는다)
|
||||
const down = await lookupOpgg(input, async () => {
|
||||
throw new Error('down');
|
||||
throw new Error('OP.GG 503');
|
||||
});
|
||||
assert.equal(down.found, false);
|
||||
assert.equal(down.error, true);
|
||||
assert.match(down.note!, /OP\.GG 조회 실패로 이 경기를 확인하지 못했습니다 \(3번 중 3번 실패: OP\.GG 503\)/);
|
||||
assert.equal(miss.error, undefined, '조회는 됐는데 없으면 error 아님');
|
||||
const vMiss = await lookupOpgg({ ...input, game: 'valorant' }, async () => []);
|
||||
assert.deepEqual([vMiss.found, vMiss.error, /이 경기가 없습니다/.test(vMiss.note!)], [false, undefined, true]);
|
||||
// 일부만 실패하고 못 찾았으면 확인 못 함
|
||||
let k = 0;
|
||||
const vHalf = await lookupOpgg({ ...input, game: 'valorant' }, async () => {
|
||||
if (k++ % 2) throw new Error('OP.GG 503');
|
||||
return [];
|
||||
});
|
||||
assert.equal(vHalf.error, true);
|
||||
});
|
||||
|
||||
test('OP.GG 클라이언트: 세션이 끝나면(404) 새로 initialize 하고 다시 부른다', async () => {
|
||||
let serverSid = 's1';
|
||||
let inits = 0;
|
||||
const seen: { method: string; sid: string | null }[] = [];
|
||||
const fetchFn = (async (_url: string, init: any) => {
|
||||
const body = JSON.parse(init.body);
|
||||
const sid = init.headers['mcp-session-id'] ?? null;
|
||||
seen.push({ method: body.method, sid });
|
||||
if (body.method === 'initialize') {
|
||||
inits++;
|
||||
if (sid) return new Response('bad', { status: 400 });
|
||||
return new Response(JSON.stringify({ jsonrpc: '2.0', id: body.id, result: {} }), { status: 200, headers: { 'mcp-session-id': serverSid } });
|
||||
}
|
||||
if (sid !== serverSid) return new Response('session not found', { status: 404 });
|
||||
if (body.params.name === 'boom') return new Response('unavailable', { status: 503 });
|
||||
// SSE 로 줄 때도 읽는다
|
||||
const msg = JSON.stringify({ jsonrpc: '2.0', id: body.id, result: { content: [{ type: 'text', text: JSON.stringify({ ok: body.params.name, sid }) }] } });
|
||||
return new Response(`event: message\ndata: ${msg}\n\n`, { status: 200, headers: { 'content-type': 'text/event-stream' } });
|
||||
}) as typeof fetch;
|
||||
const call = opggCaller({ url: 'http://opgg.test/mcp', fetchFn });
|
||||
assert.deepEqual(await call('a', {}), { ok: 'a', sid: 's1' });
|
||||
// 서버가 재시작해 세션이 사라졌다
|
||||
serverSid = 's2';
|
||||
assert.deepEqual(await call('b', {}), { ok: 'b', sid: 's2' });
|
||||
assert.deepEqual(await call('c', {}), { ok: 'c', sid: 's2' }, '새 세션을 계속 쓴다');
|
||||
assert.equal(inits, 2);
|
||||
assert.deepEqual(
|
||||
seen.map((x) => `${x.method}:${x.sid ?? '-'}`),
|
||||
['initialize:-', 'tools/call:s1', 'tools/call:s1', 'initialize:-', 'tools/call:s2', 'tools/call:s2'],
|
||||
);
|
||||
// 세션 문제가 아닌 실패(503)는 다시 initialize 하지 않고 그대로 실패
|
||||
await assert.rejects(call('boom', {}), /OP\.GG 503/);
|
||||
assert.equal(inits, 2);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user